类 MockHttpSession
- java.lang.Object
- org.springframework.mock.web.MockHttpSession
- 所有已实现的接口:
HttpSession
public class MockHttpSession extends Object implements HttpSession
Mock implementation of theHttpSessioninterface.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.
- 从以下版本开始:
- 1.0.2
- 作者:
- Juergen Hoeller, Rod Johnson, Mark Fisher, Sam Brannen
字段概要
字段 修饰符和类型 字段 说明 static StringSESSION_COOKIE_NAME
构造器概要
构造器 构造器 说明 MockHttpSession()Create a new MockHttpSession with a defaultMockServletContext.MockHttpSession(ServletContext servletContext)Create a new MockHttpSession.MockHttpSession(ServletContext servletContext, String id)Create a new MockHttpSession.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidaccess()StringchangeSessionId()As of Servlet 3.1, the id of a session can be changed.voidclearAttributes()Clear all of this session's attributes.voiddeserializeState(Serializable state)Deserialize the attributes of this session from a state object created byserializeState().ObjectgetAttribute(String name)Enumeration<String>getAttributeNames()longgetCreationTime()StringgetId()longgetLastAccessedTime()intgetMaxInactiveInterval()ServletContextgetServletContext()HttpSessionContextgetSessionContext()ObjectgetValue(String name)String[]getValueNames()voidinvalidate()Invalidates this session then unbinds any objects bound to it.booleanisInvalid()booleanisNew()voidputValue(String name, Object value)voidremoveAttribute(String name)voidremoveValue(String name)SerializableserializeState()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)
字段详细资料
SESSION_COOKIE_NAME
public static final String SESSION_COOKIE_NAME
- 另请参阅:
- 常量字段值
构造器详细资料
MockHttpSession
public MockHttpSession()
Create a new MockHttpSession with a defaultMockServletContext.- 另请参阅:
MockServletContext
MockHttpSession
public MockHttpSession(ServletContext servletContext)
Create a new MockHttpSession.- 参数:
servletContext- the ServletContext that the session runs in
MockHttpSession
public MockHttpSession(ServletContext servletContext, String id)
Create a new MockHttpSession.- 参数:
servletContext- the ServletContext that the session runs inid- a unique identifier for this session
方法详细资料
getCreationTime
public long getCreationTime()
- 指定者:
getCreationTime在接口中HttpSession
getId
public String getId()
- 指定者:
getId在接口中HttpSession
changeSessionId
public String changeSessionId()
As of Servlet 3.1, the id of a session can be changed.- 返回:
- the new session id
- 从以下版本开始:
- 4.0.3
access
public void access()
getLastAccessedTime
public long getLastAccessedTime()
- 指定者:
getLastAccessedTime在接口中HttpSession
getServletContext
public ServletContext getServletContext()
- 指定者:
getServletContext在接口中HttpSession
setMaxInactiveInterval
public void setMaxInactiveInterval(int interval)
- 指定者:
setMaxInactiveInterval在接口中HttpSession
getMaxInactiveInterval
public int getMaxInactiveInterval()
- 指定者:
getMaxInactiveInterval在接口中HttpSession
getSessionContext
public HttpSessionContext getSessionContext()
- 指定者:
getSessionContext在接口中HttpSession
getAttribute
public Object getAttribute(String name)
- 指定者:
getAttribute在接口中HttpSession
getValue
public Object getValue(String name)
- 指定者:
getValue在接口中HttpSession
getAttributeNames
public Enumeration<String> getAttributeNames()
- 指定者:
getAttributeNames在接口中HttpSession
getValueNames
public String[] getValueNames()
- 指定者:
getValueNames在接口中HttpSession
setAttribute
public void setAttribute(String name, Object value)
- 指定者:
setAttribute在接口中HttpSession
putValue
public void putValue(String name, Object value)
- 指定者:
putValue在接口中HttpSession
removeAttribute
public void removeAttribute(String name)
- 指定者:
removeAttribute在接口中HttpSession
removeValue
public void removeValue(String name)
- 指定者:
removeValue在接口中HttpSession
clearAttributes
public void clearAttributes()
Clear all of this session's attributes.
invalidate
public void invalidate()
Invalidates this session then unbinds any objects bound to it.- 指定者:
invalidate在接口中HttpSession- 抛出:
IllegalStateException- if this method is called on an already invalidated session
isInvalid
public boolean isInvalid()
setNew
public void setNew(boolean value)
isNew
public boolean isNew()
- 指定者:
isNew在接口中HttpSession
serializeState
public Serializable serializeState()
Serialize the attributes of this session into an object that can be turned into a byte array with standard Java serialization.- 返回:
- a representation of this session's serialized state
deserializeState
public void deserializeState(Serializable state)
Deserialize the attributes of this session from a state object created byserializeState().- 参数:
state- a representation of this session's serialized state