net.sf.click.servlet
Class MockSession

java.lang.Object
  extended bynet.sf.click.servlet.MockSession
All Implemented Interfaces:
HttpSession

public class MockSession
extends Object
implements HttpSession

Mock implementation of HttpSession.

Implements all of the methods from the standard HttpSession class plus helper methods to aid setting up a session.

Author:
Bob Schellink

Constructor Summary
MockSession()
          Create a default MockSession.
MockSession(ServletContext servletContext)
          Create a MockSession for the specified servletContext.
MockSession(String id)
          Create a MockSession for the specified session identifier.
MockSession(String id, ServletContext servletContext)
          Create a MockSession for the specified id and servletContext.
 
Method Summary
 Object getAttribute(String name)
           
 Enumeration getAttributeNames()
           
 long getCreationTime()
           
 String getId()
           
 long getLastAccessedTime()
          This method will return the current time by invoking System.currentTimeMillis().
 int getMaxInactiveInterval()
           
 ServletContext getServletContext()
           
 HttpSessionContext getSessionContext()
           
 Object getValue(String name)
           
 String[] getValueNames()
           
 void invalidate()
           
 boolean isNew()
           
 void putValue(String name, Object value)
           
 void removeAttribute(String name)
           
 void removeValue(String name)
           
 void setAttribute(String name, Object value)
           
 void setId(String id)
          Sets session unique identifier.
 void setMaxInactiveInterval(int maxInterval)
           
 void setServletContext(ServletContext servletContext)
          Sets the servletContext to which the session belong.
 String toString()
          Return a string representation of the session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MockSession

public MockSession()
Create a default MockSession.


MockSession

public MockSession(String id)
Create a MockSession for the specified session identifier.

Parameters:
id - session unique identifier.

MockSession

public MockSession(ServletContext servletContext)
Create a MockSession for the specified servletContext.

Parameters:
servletContext - the servletContext to which this session belong

MockSession

public MockSession(String id,
                   ServletContext servletContext)
Create a MockSession for the specified id and servletContext.

Parameters:
id - session unique identifier.
servletContext - the servletContext to which this session belong
Method Detail

setId

public void setId(String id)
Sets session unique identifier.

Parameters:
id - a unique session identifier

setServletContext

public void setServletContext(ServletContext servletContext)
Sets the servletContext to which the session belong.

Parameters:
servletContext - the servletContext to which this session belong

getAttributeNames

public Enumeration getAttributeNames()
Specified by:
getAttributeNames in interface HttpSession
Returns:
an Enumeration of String objects specifying the names of all the objects bound to this session
See Also:
HttpSession.getAttributeNames()

getCreationTime

public long getCreationTime()
Specified by:
getCreationTime in interface HttpSession
Returns:
a long specifying when this session was created, expressed in milliseconds since 1/1/1970 GMT
See Also:
HttpSession.getCreationTime()

getId

public String getId()
Specified by:
getId in interface HttpSession
Returns:
a string specifying the identifier assigned to this session
See Also:
HttpSession.getId()

getLastAccessedTime

public long getLastAccessedTime()
This method will return the current time by invoking System.currentTimeMillis().

Specified by:
getLastAccessedTime in interface HttpSession
Returns:
a long representing the last time the client sent a request associated with this session, expressed in milliseconds since 1/1/1970 GMT
See Also:
HttpSession.getLastAccessedTime()

getMaxInactiveInterval

public int getMaxInactiveInterval()
Specified by:
getMaxInactiveInterval in interface HttpSession
Returns:
an integer specifying the number of seconds this session remains open between client requests
See Also:
HttpSession.getMaxInactiveInterval()

getServletContext

public ServletContext getServletContext()
Specified by:
getServletContext in interface HttpSession
Returns:
the session servletContext
See Also:
HttpSession.getServletContext()

getSessionContext

public HttpSessionContext getSessionContext()
Specified by:
getSessionContext in interface HttpSession
Returns:
the session sessionContext
See Also:
HttpSession.getSessionContext()

getValueNames

public String[] getValueNames()
Specified by:
getValueNames in interface HttpSession
Returns:
an array of String objects specifying the names of all the objects bound to this session
See Also:
HttpSession.getValueNames()

invalidate

public void invalidate()
Specified by:
invalidate in interface HttpSession
See Also:
HttpSession.invalidate()

isNew

public boolean isNew()
Specified by:
isNew in interface HttpSession
Returns:
true if the server has created a session, but the client has not yet joined
See Also:
HttpSession.isNew()

setMaxInactiveInterval

public void setMaxInactiveInterval(int maxInterval)
Specified by:
setMaxInactiveInterval in interface HttpSession
Parameters:
maxInterval - an integer specifying the number of seconds
See Also:
HttpSession.setMaxInactiveInterval(int)

removeValue

public void removeValue(String name)
Specified by:
removeValue in interface HttpSession
Parameters:
name - the name of the object to remove from this session
See Also:
HttpSession.removeValue(java.lang.String)

removeAttribute

public void removeAttribute(String name)
Specified by:
removeAttribute in interface HttpSession
Parameters:
name - the name of the object to remove from this session
See Also:
HttpSession.removeAttribute(java.lang.String)

getAttribute

public Object getAttribute(String name)
Specified by:
getAttribute in interface HttpSession
Parameters:
name - a string specifying the name of the object
Returns:
the object with the specified name
See Also:
HttpSession.getAttribute(java.lang.String)

getValue

public Object getValue(String name)
Specified by:
getValue in interface HttpSession
Parameters:
name - a string specifying the name of the object
Returns:
the object with the specified name
See Also:
HttpSession.getValue(java.lang.String)

setAttribute

public void setAttribute(String name,
                         Object value)
Specified by:
setAttribute in interface HttpSession
Parameters:
name - the name to which the object is bound; cannot be null
value - the object to be bound
See Also:
HttpSession.setAttribute(java.lang.String, java.lang.Object)

putValue

public void putValue(String name,
                     Object value)
Specified by:
putValue in interface HttpSession
Parameters:
name - the name to which the object is bound; cannot be null
value - the object to be bound; cannot be null
See Also:
HttpSession.putValue(java.lang.String, java.lang.Object)

toString

public String toString()
Return a string representation of the session.

The string will print all attributes of the session.

Returns:
string representation of the session