public class MockHttpSession extends Object implements javax.servlet.http.HttpSession
HttpSession interface.
Compatible with Servlet 2.5 as well as Servlet 3.0.
Used for testing the web framework; also useful for testing application controllers.
| Modifier and Type | Field and Description |
|---|---|
static String |
SESSION_COOKIE_NAME |
| Constructor and Description |
|---|
MockHttpSession()
Create a new MockHttpSession with a default
MockServletContext. |
MockHttpSession(javax.servlet.ServletContext servletContext)
Create a new MockHttpSession.
|
MockHttpSession(javax.servlet.ServletContext servletContext,
String id)
Create a new MockHttpSession.
|
| Modifier and Type | Method and Description |
|---|---|
void |
access() |
void |
clearAttributes()
Clear all of this session's attributes.
|
void |
deserializeState(Serializable state)
Deserialize the attributes of this session from a state object created by
serializeState(). |
Object |
getAttribute(String name) |
Enumeration<String> |
getAttributeNames() |
long |
getCreationTime() |
String |
getId() |
long |
getLastAccessedTime() |
int |
getMaxInactiveInterval() |
javax.servlet.ServletContext |
getServletContext() |
javax.servlet.http.HttpSessionContext |
getSessionContext() |
Object |
getValue(String name) |
String[] |
getValueNames() |
void |
invalidate()
Invalidates this session then unbinds any objects bound to it.
|
boolean |
isInvalid() |
boolean |
isNew() |
void |
putValue(String name,
Object value) |
void |
removeAttribute(String name) |
void |
removeValue(String name) |
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(String name,
Object value) |
void |
setMaxInactiveInterval(int interval) |
void |
setNew(boolean value) |
public static final String SESSION_COOKIE_NAME
public MockHttpSession()
MockServletContext.MockServletContextpublic MockHttpSession(javax.servlet.ServletContext servletContext)
servletContext - the ServletContext that the session runs inpublic MockHttpSession(javax.servlet.ServletContext servletContext,
String id)
servletContext - the ServletContext that the session runs inid - a unique identifier for this sessionpublic long getCreationTime()
getCreationTime in interface javax.servlet.http.HttpSessionpublic String getId()
getId in interface javax.servlet.http.HttpSessionpublic void access()
public long getLastAccessedTime()
getLastAccessedTime in interface javax.servlet.http.HttpSessionpublic javax.servlet.ServletContext getServletContext()
getServletContext in interface javax.servlet.http.HttpSessionpublic void setMaxInactiveInterval(int interval)
setMaxInactiveInterval in interface javax.servlet.http.HttpSessionpublic int getMaxInactiveInterval()
getMaxInactiveInterval in interface javax.servlet.http.HttpSessionpublic javax.servlet.http.HttpSessionContext getSessionContext()
getSessionContext in interface javax.servlet.http.HttpSessionpublic Object getAttribute(String name)
getAttribute in interface javax.servlet.http.HttpSessionpublic Object getValue(String name)
getValue in interface javax.servlet.http.HttpSessionpublic Enumeration<String> getAttributeNames()
getAttributeNames in interface javax.servlet.http.HttpSessionpublic String[] getValueNames()
getValueNames in interface javax.servlet.http.HttpSessionpublic void setAttribute(String name, Object value)
setAttribute in interface javax.servlet.http.HttpSessionpublic void putValue(String name, Object value)
putValue in interface javax.servlet.http.HttpSessionpublic void removeAttribute(String name)
removeAttribute in interface javax.servlet.http.HttpSessionpublic void removeValue(String name)
removeValue in interface javax.servlet.http.HttpSessionpublic void clearAttributes()
public void invalidate()
invalidate in interface javax.servlet.http.HttpSessionIllegalStateException - if this method is called on an already invalidated sessionpublic boolean isInvalid()
public void setNew(boolean value)
public boolean isNew()
isNew in interface javax.servlet.http.HttpSessionpublic Serializable serializeState()
public void deserializeState(Serializable state)
serializeState().state - a representation of this session's serialized stateCopyright © 2015. All rights reserved.