Package com.oorian.testing
Class MockOorianHttpSession
java.lang.Object
com.oorian.testing.MockOorianHttpSession
- All Implemented Interfaces:
OorianHttpSession
Mock implementation of
OorianHttpSession for testing without a servlet container.
This mock uses an in-memory HashMap for session attributes and provides
configurable session metadata (ID, creation time, etc.). It can be used directly
or via OorianTestContext for setting up a complete test environment.
Usage:
MockOorianHttpSession session = new MockOorianHttpSession();
session.setAttribute("userId", 12345);
Object value = session.getAttribute("userId");
assert value.equals(12345);
- Since:
- 2.1
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new MockOorianHttpSession with a random UUID as the session ID.MockOorianHttpSession(String sessionId) Constructs a new MockOorianHttpSession with the specified session ID. -
Method Summary
Modifier and TypeMethodDescriptiongetAttribute(String name) Returns the session attribute with the specified name.Returns the underlying attribute map for direct inspection in tests.Returns an enumeration of all attribute names in this session.longReturns the time the session was created.getId()Returns the unique session identifier.longReturns the time of last client access.intReturns the maximum inactive interval for this session.voidInvalidates this session.booleanReturns whether this session has been invalidated.booleanisNew()Checks if the session was newly created.voidremoveAttribute(String name) Removes a session attribute.voidsetAttribute(String name, Object value) Sets a session attribute.voidSets the session ID.voidsetMaxInactiveInterval(int interval) Sets the maximum time interval between requests before the session expires.voidsetNew(boolean isNew) Sets the new-session flag.
-
Constructor Details
-
MockOorianHttpSession
public MockOorianHttpSession()Constructs a new MockOorianHttpSession with a random UUID as the session ID. -
MockOorianHttpSession
Constructs a new MockOorianHttpSession with the specified session ID.- Parameters:
sessionId- the session ID to use
-
-
Method Details
-
setId
Sets the session ID.- Parameters:
id- the new session ID
-
setNew
public void setNew(boolean isNew) Sets the new-session flag.- Parameters:
isNew- true to mark this session as new
-
getId
Description copied from interface:OorianHttpSessionReturns the unique session identifier.- Specified by:
getIdin interfaceOorianHttpSession- Returns:
- the session ID
-
getCreationTime
public long getCreationTime()Description copied from interface:OorianHttpSessionReturns the time the session was created.- Specified by:
getCreationTimein interfaceOorianHttpSession- Returns:
- the creation time in milliseconds since epoch
-
getLastAccessedTime
public long getLastAccessedTime()Description copied from interface:OorianHttpSessionReturns the time of last client access.- Specified by:
getLastAccessedTimein interfaceOorianHttpSession- Returns:
- the last access time in milliseconds since epoch
-
setMaxInactiveInterval
public void setMaxInactiveInterval(int interval) Description copied from interface:OorianHttpSessionSets the maximum time interval between requests before the session expires.- Specified by:
setMaxInactiveIntervalin interfaceOorianHttpSession- Parameters:
interval- the interval in seconds
-
getMaxInactiveInterval
public int getMaxInactiveInterval()Description copied from interface:OorianHttpSessionReturns the maximum inactive interval for this session.- Specified by:
getMaxInactiveIntervalin interfaceOorianHttpSession- Returns:
- the interval in seconds
-
getAttribute
Description copied from interface:OorianHttpSessionReturns the session attribute with the specified name.- Specified by:
getAttributein interfaceOorianHttpSession- Parameters:
name- the attribute name- Returns:
- the attribute value, or null if not found
-
getAttributeNames
Description copied from interface:OorianHttpSessionReturns an enumeration of all attribute names in this session.- Specified by:
getAttributeNamesin interfaceOorianHttpSession- Returns:
- enumeration of attribute names
-
setAttribute
Description copied from interface:OorianHttpSessionSets a session attribute.- Specified by:
setAttributein interfaceOorianHttpSession- Parameters:
name- the attribute namevalue- the attribute value
-
removeAttribute
Description copied from interface:OorianHttpSessionRemoves a session attribute.- Specified by:
removeAttributein interfaceOorianHttpSession- Parameters:
name- the attribute name to remove
-
invalidate
public void invalidate()Description copied from interface:OorianHttpSessionInvalidates this session.- Specified by:
invalidatein interfaceOorianHttpSession
-
isNew
public boolean isNew()Description copied from interface:OorianHttpSessionChecks if the session was newly created.- Specified by:
isNewin interfaceOorianHttpSession- Returns:
- true if the session is new
-
isInvalidated
public boolean isInvalidated()Returns whether this session has been invalidated.- Returns:
- true if
invalidate()has been called
-
getAttributeMap
Returns the underlying attribute map for direct inspection in tests.- Returns:
- an unmodifiable view of the attribute map
-