org.springframework.mock.web
Class MockHttpSession

java.lang.Object
  extended by org.springframework.mock.web.MockHttpSession

public class MockHttpSession
extends java.lang.Object

Mock implementation of the javax.servlet.http.HttpSession interface. Supports the Servlet 2.4 API level.

Used for testing the web framework; also useful for testing application controllers.

Since:
1.0.2
Author:
Juergen Hoeller, Rod Johnson, Mark Fisher

Field Summary
private  java.util.Map<java.lang.String,java.lang.Object> attributes
           
private  long creationTime
           
private  java.lang.String id
           
private  boolean invalid
           
private  boolean isNew
           
private  long lastAccessedTime
           
private  int maxInactiveInterval
           
private static int nextId
           
private  ServletContext servletContext
           
static java.lang.String SESSION_COOKIE_NAME
           
 
Constructor Summary
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.
 
Method Summary
 void access()
           
 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()
           
 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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SESSION_COOKIE_NAME

public static final java.lang.String SESSION_COOKIE_NAME
See Also:
Constant Field Values

nextId

private static int nextId

id

private final java.lang.String id

creationTime

private final long creationTime

maxInactiveInterval

private int maxInactiveInterval

lastAccessedTime

private long lastAccessedTime

servletContext

private final ServletContext servletContext

attributes

private final java.util.Map<java.lang.String,java.lang.Object> attributes

invalid

private boolean invalid

isNew

private boolean isNew
Constructor Detail

MockHttpSession

public MockHttpSession()
Create a new MockHttpSession with a default MockServletContext.

See Also:
MockServletContext

MockHttpSession

public MockHttpSession(ServletContext servletContext)
Create a new MockHttpSession.

Parameters:
servletContext - the ServletContext that the session runs in

MockHttpSession

public MockHttpSession(ServletContext servletContext,
                       java.lang.String id)
Create a new MockHttpSession.

Parameters:
servletContext - the ServletContext that the session runs in
id - a unique identifier for this session
Method Detail

getCreationTime

public long getCreationTime()

getId

public java.lang.String getId()

access

public void access()

getLastAccessedTime

public long getLastAccessedTime()

getServletContext

public ServletContext getServletContext()

setMaxInactiveInterval

public void setMaxInactiveInterval(int interval)

getMaxInactiveInterval

public int getMaxInactiveInterval()

getSessionContext

public HttpSessionContext getSessionContext()

getAttribute

public java.lang.Object getAttribute(java.lang.String name)

getValue

public java.lang.Object getValue(java.lang.String name)

getAttributeNames

public java.util.Enumeration<java.lang.String> getAttributeNames()

getValueNames

public java.lang.String[] getValueNames()

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)

putValue

public void putValue(java.lang.String name,
                     java.lang.Object value)

removeAttribute

public void removeAttribute(java.lang.String name)

removeValue

public void removeValue(java.lang.String name)

clearAttributes

public void clearAttributes()
Clear all of this session's attributes.


invalidate

public void invalidate()

isInvalid

public boolean isInvalid()

setNew

public void setNew(boolean value)

isNew

public boolean isNew()

serializeState

public 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.

Returns:
a representation of this session's serialized state

deserializeState

public void deserializeState(java.io.Serializable state)
Deserialize the attributes of this session from a state object created by serializeState().

Parameters:
state - a representation of this session's serialized state