Class MockHttpSession
java.lang.Object
org.springframework.mock.web.MockHttpSession
- All Implemented Interfaces:
- jakarta.servlet.http.HttpSession
Mock implementation of the 
HttpSession interface.
As of Spring 7.0, this set of mocks is designed on a Servlet 6.1 baseline.
- Since:
- 1.0.2
- Author:
- Juergen Hoeller, Rod Johnson, Mark Fisher, Sam Brannen, Vedran Pavic
- 
Nested Class SummaryNested classes/interfaces inherited from interface jakarta.servlet.http.HttpSessionjakarta.servlet.http.HttpSession.Accessor
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionCreate a new MockHttpSession with a defaultMockServletContext.MockHttpSession(@Nullable jakarta.servlet.ServletContext servletContext) Create a new MockHttpSession.MockHttpSession(@Nullable jakarta.servlet.ServletContext servletContext, @Nullable String id) Create a new MockHttpSession.
- 
Method SummaryModifier and TypeMethodDescriptionvoidaccess()As of Servlet 3.1, the id of a session can be changed.voidClear all of this session's attributes.voiddeserializeState(Serializable state) Deserialize the attributes of this session from a state object created byserializeState().jakarta.servlet.http.HttpSession.AccessorgetAttribute(String name) longgetId()longintjakarta.servlet.ServletContextvoidInvalidates this session then unbinds any objects bound to it.booleanbooleanisNew()voidremoveAttribute(String name) Serialize the attributes of this session into an object that can be turned into a byte array with standard Java serialization.voidsetAttribute(String name, @Nullable Object value) voidsetMaxInactiveInterval(int interval) voidsetNew(boolean value) 
- 
Field Details- 
SESSION_COOKIE_NAME
 
- 
- 
Constructor Details- 
MockHttpSession
- 
MockHttpSessionCreate a new MockHttpSession.- Parameters:
- servletContext- the ServletContext that the session runs in
 
- 
MockHttpSession
 
- 
- 
Method Details- 
getCreationTimepublic long getCreationTime()- Specified by:
- getCreationTimein interface- jakarta.servlet.http.HttpSession
 
- 
getId- Specified by:
- getIdin interface- jakarta.servlet.http.HttpSession
 
- 
changeSessionIdAs of Servlet 3.1, the id of a session can be changed.- Returns:
- the new session id
- Since:
- 4.0.3
 
- 
accesspublic void access()
- 
getLastAccessedTimepublic long getLastAccessedTime()- Specified by:
- getLastAccessedTimein interface- jakarta.servlet.http.HttpSession
 
- 
getServletContextpublic jakarta.servlet.ServletContext getServletContext()- Specified by:
- getServletContextin interface- jakarta.servlet.http.HttpSession
 
- 
setMaxInactiveIntervalpublic void setMaxInactiveInterval(int interval) - Specified by:
- setMaxInactiveIntervalin interface- jakarta.servlet.http.HttpSession
 
- 
getMaxInactiveIntervalpublic int getMaxInactiveInterval()- Specified by:
- getMaxInactiveIntervalin interface- jakarta.servlet.http.HttpSession
 
- 
getAttribute
- 
getAttributeNames- Specified by:
- getAttributeNamesin interface- jakarta.servlet.http.HttpSession
 
- 
setAttribute
- 
removeAttribute- Specified by:
- removeAttributein interface- jakarta.servlet.http.HttpSession
 
- 
clearAttributespublic void clearAttributes()Clear all of this session's attributes.
- 
invalidatepublic void invalidate()Invalidates this session then unbinds any objects bound to it.- Specified by:
- invalidatein interface- jakarta.servlet.http.HttpSession
- Throws:
- IllegalStateException- if this method is called on an already invalidated session
 
- 
isInvalidpublic boolean isInvalid()
- 
setNewpublic void setNew(boolean value) 
- 
isNewpublic boolean isNew()- Specified by:
- isNewin interface- jakarta.servlet.http.HttpSession
 
- 
getAccessorpublic jakarta.servlet.http.HttpSession.Accessor getAccessor()- Specified by:
- getAccessorin interface- jakarta.servlet.http.HttpSession
 
- 
serializeStateSerialize the attributes of this session into an object that can be turned into a byte array with standard Java serialization.- Returns:
- a representation of this session's serialized state
 
- 
deserializeStateDeserialize the attributes of this session from a state object created byserializeState().- Parameters:
- state- a representation of this session's serialized state
 
 
-