Fish & Chips Club 4.10.0.0

hirondelle.fish.test.doubles
Class FakeServletContext

Object
  extended by hirondelle.fish.test.doubles.FakeServletContext
All Implemented Interfaces:
ServletContext

public class FakeServletContext
extends Object
implements ServletContext

Fake implementation of ServletContext, used only for testing outside the regular runtime environment.

This class requires that a System property be set correctly. See ROOT_DIRECTORY for more information.


Field Summary
static String ROOT_DIRECTORY
          Name of a System property ("rootDirectory") that holds the root directory for this web application (with no trailing separator).
static String SERVER_INFO
          Value - "Fake ServletContext For Testing/1.0".
static String SERVLET_CONTEXT_NAME
          Value - "Fake ServletContext For Testing".
 
Constructor Summary
FakeServletContext()
          Constructor
 
Method Summary
 Object getAttribute(String aName)
           
 Enumeration getAttributeNames()
           
 ServletContext getContext(String aPath)
          Not implemented - returns null.
 String getContextPath()
          Not implemented - returns null.
 String getInitParameter(String aParamName)
           
 Enumeration getInitParameterNames()
           
 int getMajorVersion()
          Returns 2.
 String getMimeType(String aFileName)
          Not implemented - returns null.
 int getMinorVersion()
          Returns 4.
 RequestDispatcher getNamedDispatcher(String aServletName)
          Not implemented - returns null.
 String getRealPath(String aPath)
          Return the full path to an underlying file or directory.
 RequestDispatcher getRequestDispatcher(String aPath)
          Not implemented - returns null.
 URL getResource(String aPath)
          Not implemented - returns null.
 InputStream getResourceAsStream(String aPath)
           
 Set getResourcePaths(String aPathPattern)
          Returns paths to items under the root directory.
static String getRootDirectory()
          Return the non-empty value of the System property identified by ROOT_DIRECTORY.
 String getServerInfo()
          Returns "Fake ServletContext For Testing/1.0".
 Servlet getServlet(String aName)
          Not implemented - returns null.
 String getServletContextName()
          Returns "Fake ServletContext For Testing".
 Enumeration getServletNames()
          Not implemented - returns null.
 Enumeration getServlets()
          Not implemented - returns null.
 void log(Exception aException, String aMessage)
           
 void log(String aMessage)
           
 void log(String aMessage, Throwable aThrowable)
           
 void removeAttribute(String aName)
           
 void setAttribute(String aName, Object aObject)
           
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROOT_DIRECTORY

public static final String ROOT_DIRECTORY
Name of a System property ("rootDirectory") that holds the root directory for this web application (with no trailing separator).

This item exists because ServletContext needs to translate request paths into explicit file system paths.

When using fake objects for testing, this System property must be set to a non-empty value, for example :

 'rootDirectory=C:\myname\myprojects\blah'.

There are various ways of setting this property :

'java ... -DrootDirectory=C:\myname\myprojects\blah ...'.

See Also:
Constant Field Values

SERVER_INFO

public static final String SERVER_INFO
Value - "Fake ServletContext For Testing/1.0".

See Also:
Constant Field Values

SERVLET_CONTEXT_NAME

public static final String SERVLET_CONTEXT_NAME
Value - "Fake ServletContext For Testing".

See Also:
Constant Field Values
Constructor Detail

FakeServletContext

public FakeServletContext()
                   throws FileNotFoundException
Constructor

Throws:
FileNotFoundException
Method Detail

getRootDirectory

public static String getRootDirectory()
Return the non-empty value of the System property identified by ROOT_DIRECTORY.


getInitParameter

public String getInitParameter(String aParamName)
Specified by:
getInitParameter in interface ServletContext

getInitParameterNames

public Enumeration getInitParameterNames()
Specified by:
getInitParameterNames in interface ServletContext

getResourcePaths

public Set getResourcePaths(String aPathPattern)

Returns paths to items under the root directory.

Example return value, given path patern of "/catalog/":

   "/catalog/blah.html" 
   "/catalog/xyz.html" 
   "/catalog/specials/"
   
Note that '/catalog/' itself if not returned.

Specified by:
getResourcePaths in interface ServletContext
Parameters:
aPathPattern - starts with "/", path to which items are matched; usually ends with '/' , to indicate a directory.

getRealPath

public String getRealPath(String aPath)
Return the full path to an underlying file or directory. The returned String uses file separators of the underlying operating system.

Specified by:
getRealPath in interface ServletContext
Parameters:
aPath - such as '/index.html'; directories end in a separator.

getResourceAsStream

public InputStream getResourceAsStream(String aPath)
Specified by:
getResourceAsStream in interface ServletContext

setAttribute

public void setAttribute(String aName,
                         Object aObject)
Specified by:
setAttribute in interface ServletContext

getAttribute

public Object getAttribute(String aName)
Specified by:
getAttribute in interface ServletContext

removeAttribute

public void removeAttribute(String aName)
Specified by:
removeAttribute in interface ServletContext

getAttributeNames

public Enumeration getAttributeNames()
Specified by:
getAttributeNames in interface ServletContext

getServerInfo

public String getServerInfo()
Returns "Fake ServletContext For Testing/1.0".

Specified by:
getServerInfo in interface ServletContext

getServletContextName

public String getServletContextName()
Returns "Fake ServletContext For Testing".

Specified by:
getServletContextName in interface ServletContext

log

public void log(String aMessage)
Specified by:
log in interface ServletContext

log

public void log(Exception aException,
                String aMessage)
Specified by:
log in interface ServletContext

log

public void log(String aMessage,
                Throwable aThrowable)
Specified by:
log in interface ServletContext

getMajorVersion

public int getMajorVersion()
Returns 2.

Specified by:
getMajorVersion in interface ServletContext

getMinorVersion

public int getMinorVersion()
Returns 4.

Specified by:
getMinorVersion in interface ServletContext

getResource

public URL getResource(String aPath)
                throws MalformedURLException
Not implemented - returns null.

Specified by:
getResource in interface ServletContext
Throws:
MalformedURLException

getContext

public ServletContext getContext(String aPath)
Not implemented - returns null.

Specified by:
getContext in interface ServletContext

getContextPath

public String getContextPath()
Not implemented - returns null.

Specified by:
getContextPath in interface ServletContext

getMimeType

public String getMimeType(String aFileName)
Not implemented - returns null.

Specified by:
getMimeType in interface ServletContext

getRequestDispatcher

public RequestDispatcher getRequestDispatcher(String aPath)
Not implemented - returns null.

Specified by:
getRequestDispatcher in interface ServletContext

getNamedDispatcher

public RequestDispatcher getNamedDispatcher(String aServletName)
Not implemented - returns null.

Specified by:
getNamedDispatcher in interface ServletContext

getServlet

public Servlet getServlet(String aName)
                   throws ServletException
Not implemented - returns null.

Specified by:
getServlet in interface ServletContext
Throws:
ServletException

getServlets

public Enumeration getServlets()
Not implemented - returns null.

Specified by:
getServlets in interface ServletContext

getServletNames

public Enumeration getServletNames()
Not implemented - returns null.

Specified by:
getServletNames in interface ServletContext

Fish & Chips Club 4.10.0.0

Copyright Hirondelle Systems - Generated 2013Oct19.12.26