Class MockHttpSession

java.lang.Object
org.apache.juneau.rest.mock.MockHttpSession
All Implemented Interfaces:
jakarta.servlet.http.HttpSession

public class MockHttpSession extends Object implements jakarta.servlet.http.HttpSession
An implementation of HttpSession for mocking purposes.

Session-based tests can use this API to create customized instances of HttpSession objects that can be passed to the MockRestRequest.httpSession(HttpSession) method.

See Also:
  • Constructor Details

  • Method Details

    • create

      public static MockHttpSession create()
      Creates a new HTTP session.
      Returns:
      A new HTTP session.
    • creationTime

      public MockHttpSession creationTime(long value)
      Sets the creation time on this session.

      Affects the results of calling HttpSession.getCreationTime().

      Parameters:
      value - The new value for this setting.
      Returns:
      This object.
    • lastAccessedTime

      public MockHttpSession lastAccessedTime(long value)
      Sets the last-accessed time on this session.

      Affects the results of calling HttpSession.getLastAccessedTime().

      Parameters:
      value - The new value for this setting.
      Returns:
      This object.
    • maxInactiveInterval

      Sets the max-inactive interval time on this session.

      Affects the results of calling HttpSession.getMaxInactiveInterval().

      Parameters:
      value - The new value for this setting.
      Returns:
      This object.
    • id

      public MockHttpSession id(String value)
      Sets the id on this session.

      Affects the results of calling HttpSession.getId().

      Parameters:
      value - The new value for this setting.
      Returns:
      This object.
    • servletContext

      public MockHttpSession servletContext(jakarta.servlet.ServletContext value)
      Sets the servlet context on this session.

      Affects the results of calling HttpSession.getServletContext().

      Parameters:
      value - The new value for this setting.
      Returns:
      This object.
    • isNew

      public MockHttpSession isNew(boolean value)
      Sets the is-new value on this session.

      Affects the results of calling HttpSession.isNew().

      Parameters:
      value - The new value for this setting.
      Returns:
      This object.
    • getCreationTime

      public long getCreationTime()
      Specified by:
      getCreationTime in interface jakarta.servlet.http.HttpSession
    • getId

      public String getId()
      Specified by:
      getId in interface jakarta.servlet.http.HttpSession
    • getLastAccessedTime

      public long getLastAccessedTime()
      Specified by:
      getLastAccessedTime in interface jakarta.servlet.http.HttpSession
    • getServletContext

      public jakarta.servlet.ServletContext getServletContext()
      Specified by:
      getServletContext in interface jakarta.servlet.http.HttpSession
    • setMaxInactiveInterval

      public void setMaxInactiveInterval(int value)
      Specified by:
      setMaxInactiveInterval in interface jakarta.servlet.http.HttpSession
    • getMaxInactiveInterval

      public int getMaxInactiveInterval()
      Specified by:
      getMaxInactiveInterval in interface jakarta.servlet.http.HttpSession
    • getAttribute

      public Object getAttribute(String name)
      Specified by:
      getAttribute in interface jakarta.servlet.http.HttpSession
    • getAttributeNames

      Specified by:
      getAttributeNames in interface jakarta.servlet.http.HttpSession
    • setAttribute

      public void setAttribute(String name, Object value)
      Specified by:
      setAttribute in interface jakarta.servlet.http.HttpSession
    • removeAttribute

      public void removeAttribute(String name)
      Specified by:
      removeAttribute in interface jakarta.servlet.http.HttpSession
    • invalidate

      public void invalidate()
      Specified by:
      invalidate in interface jakarta.servlet.http.HttpSession
    • isNew

      public boolean isNew()
      Specified by:
      isNew in interface jakarta.servlet.http.HttpSession