Package org.springframework.mock.web
Class MockHttpSession
java.lang.Object
org.springframework.mock.web.MockHttpSession
- All Implemented Interfaces:
- HttpSession
Mock implementation of the 
HttpSession interface.
 As of Spring 5.0, this set of mocks is designed on a Servlet 4.0 baseline.
- Since:
- 1.0.2
- Author:
- Juergen Hoeller, Rod Johnson, Mark Fisher, Sam Brannen, Vedran Pavic
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionCreate a new MockHttpSession with a defaultMockServletContext.MockHttpSession(ServletContext servletContext) Create a new MockHttpSession.MockHttpSession(ServletContext servletContext, 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().getAttribute(String name) longgetId()longintString[]voidInvalidates this session then unbinds any objects bound to it.booleanbooleanisNew()voidvoidremoveAttribute(String name) voidremoveValue(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, Object value) voidsetMaxInactiveInterval(int interval) voidsetNew(boolean value) 
- 
Field Details- 
SESSION_COOKIE_NAMEThe session cookie name.- See Also:
 
 
- 
- 
Constructor Details- 
MockHttpSessionpublic MockHttpSession()Create a new MockHttpSession with a defaultMockServletContext.- See Also:
 
- 
MockHttpSessionCreate a new MockHttpSession.- Parameters:
- servletContext- the ServletContext that the session runs in
 
- 
MockHttpSessionCreate a new MockHttpSession.- Parameters:
- servletContext- the ServletContext that the session runs in
- id- a unique identifier for this session
 
 
- 
- 
Method Details- 
getCreationTimepublic long getCreationTime()- Specified by:
- getCreationTimein interface- HttpSession
 
- 
getId- Specified by:
- getIdin interface- 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- HttpSession
 
- 
getServletContext- Specified by:
- getServletContextin interface- HttpSession
 
- 
setMaxInactiveIntervalpublic void setMaxInactiveInterval(int interval) - Specified by:
- setMaxInactiveIntervalin interface- HttpSession
 
- 
getMaxInactiveIntervalpublic int getMaxInactiveInterval()- Specified by:
- getMaxInactiveIntervalin interface- HttpSession
 
- 
getSessionContext- Specified by:
- getSessionContextin interface- HttpSession
 
- 
getAttribute- Specified by:
- getAttributein interface- HttpSession
 
- 
getValue- Specified by:
- getValuein interface- HttpSession
 
- 
getAttributeNames- Specified by:
- getAttributeNamesin interface- HttpSession
 
- 
getValueNames- Specified by:
- getValueNamesin interface- HttpSession
 
- 
setAttribute- Specified by:
- setAttributein interface- HttpSession
 
- 
putValue- Specified by:
- putValuein interface- HttpSession
 
- 
removeAttribute- Specified by:
- removeAttributein interface- HttpSession
 
- 
removeValue- Specified by:
- removeValuein interface- 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- 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- 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
 
 
-