public class MockHttpSession extends java.lang.Object implements HttpSession
HttpSession
interface.
As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline.
Used for testing the web framework; also useful for testing application controllers.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
SESSION_COOKIE_NAME |
Constructor and Description |
---|
MockHttpSession()
Create a new MockHttpSession with a default
MockServletContext . |
MockHttpSession(ServletContext servletContext)
Create a new MockHttpSession.
|
MockHttpSession(ServletContext servletContext,
java.lang.String id)
Create a new MockHttpSession.
|
Modifier and Type | Method and Description |
---|---|
void |
access() |
java.lang.String |
changeSessionId()
As of Servlet 3.1, the id of a session can be changed.
|
void |
clearAttributes()
Clear all of this session's attributes.
|
void |
deserializeState(java.io.Serializable state)
Deserialize the attributes of this session from a state object created by
serializeState() . |
java.lang.Object |
getAttribute(java.lang.String name) |
java.util.Enumeration<java.lang.String> |
getAttributeNames() |
long |
getCreationTime() |
java.lang.String |
getId() |
long |
getLastAccessedTime() |
int |
getMaxInactiveInterval() |
ServletContext |
getServletContext() |
HttpSessionContext |
getSessionContext() |
java.lang.Object |
getValue(java.lang.String name) |
java.lang.String[] |
getValueNames() |
void |
invalidate()
Invalidates this session then unbinds any objects bound to it.
|
boolean |
isInvalid() |
boolean |
isNew() |
void |
putValue(java.lang.String name,
java.lang.Object value) |
void |
removeAttribute(java.lang.String name) |
void |
removeValue(java.lang.String name) |
java.io.Serializable |
serializeState()
Serialize the attributes of this session into an object that can be
turned into a byte array with standard Java serialization.
|
void |
setAttribute(java.lang.String name,
java.lang.Object value) |
void |
setMaxInactiveInterval(int interval) |
void |
setNew(boolean value) |
public static final java.lang.String SESSION_COOKIE_NAME
public MockHttpSession()
MockServletContext
.MockServletContext
public MockHttpSession(ServletContext servletContext)
servletContext
- the ServletContext that the session runs inpublic MockHttpSession(ServletContext servletContext, java.lang.String id)
servletContext
- the ServletContext that the session runs inid
- a unique identifier for this sessionpublic long getCreationTime()
getCreationTime
in interface HttpSession
public java.lang.String getId()
getId
in interface HttpSession
public java.lang.String changeSessionId()
public void access()
public long getLastAccessedTime()
getLastAccessedTime
in interface HttpSession
public ServletContext getServletContext()
getServletContext
in interface HttpSession
public void setMaxInactiveInterval(int interval)
setMaxInactiveInterval
in interface HttpSession
public int getMaxInactiveInterval()
getMaxInactiveInterval
in interface HttpSession
public HttpSessionContext getSessionContext()
getSessionContext
in interface HttpSession
public java.lang.Object getAttribute(java.lang.String name)
getAttribute
in interface HttpSession
public java.lang.Object getValue(java.lang.String name)
getValue
in interface HttpSession
public java.util.Enumeration<java.lang.String> getAttributeNames()
getAttributeNames
in interface HttpSession
public java.lang.String[] getValueNames()
getValueNames
in interface HttpSession
public void setAttribute(java.lang.String name, java.lang.Object value)
setAttribute
in interface HttpSession
public void putValue(java.lang.String name, java.lang.Object value)
putValue
in interface HttpSession
public void removeAttribute(java.lang.String name)
removeAttribute
in interface HttpSession
public void removeValue(java.lang.String name)
removeValue
in interface HttpSession
public void clearAttributes()
public void invalidate()
invalidate
in interface HttpSession
java.lang.IllegalStateException
- if this method is called on an already invalidated sessionpublic boolean isInvalid()
public void setNew(boolean value)
public boolean isNew()
isNew
in interface HttpSession
public java.io.Serializable serializeState()
public void deserializeState(java.io.Serializable state)
serializeState()
.state
- a representation of this session's serialized state