org.apache.tapestry5.internal.test
Class TestableRequestImpl

java.lang.Object
  extended by org.apache.tapestry5.internal.test.TestableRequestImpl
All Implemented Interfaces:
TestableRequest, Request

public class TestableRequestImpl
extends Object
implements TestableRequest


Constructor Summary
TestableRequestImpl()
           
TestableRequestImpl(String contextPath)
           
 
Method Summary
 TestableRequest clear()
          Clears the internal parameters map.
 Object getAttribute(String name)
          Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.
 String getContextPath()
          Returns the context path.
 long getDateHeader(String name)
          Returns the value of the specified request header as a long value that represents a Date object.
 String getHeader(String name)
          Returns null.
 List<String> getHeaderNames()
          Returns an empty list.
 Locale getLocale()
          Returns the locale of the client as determined from the request headers.
 int getLocalPort()
          Always returns 80.
 String getMethod()
          Always returns POST, to keep the Form component happy.
 String getParameter(String name)
          Returns the query parameter value for the given name.
 List<String> getParameterNames()
          Returns a list of query parameter names, in alphabetical order.
 String[] getParameters(String name)
          Returns the parameter values for the given name.
 String getPath()
          Returns the path portion of the request, which starts with a "/" and contains everything up to the start of the query parameters.
 String getRemoteHost()
          Always returns "localhost".
 String getServerName()
          Returns "localhost" which is sufficient for testing purposes.
 int getServerPort()
          Always returns 80.
 Session getSession(boolean create)
          Gets the Session.
 boolean isRequestedSessionIdValid()
          Always returns true.
 boolean isSecure()
          Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.
 boolean isXHR()
          Always returns false.
 TestableRequest loadParameter(String parameterName, String parameterValue)
          Loads a single parameter/value pair.
 TestableRequest overrideParameter(String parameterName, String parameterValue)
          Overrides a parameter to the specific value, regardless of how the parameter was previously set.
 void setAttribute(String name, Object value)
          Stores an attribute in this request.
 void setEncoding(String requestEncoding)
           
 TestableRequest setLocale(Locale locale)
          Sets the locale requested by "the browser".
 TestableRequest setPath(String path)
          Sets the path; the path should begin with a "/" character and contain everything from there to the start of query parameters (if any).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TestableRequestImpl

@Inject
public TestableRequestImpl()

TestableRequestImpl

public TestableRequestImpl(String contextPath)
Method Detail

clear

public TestableRequest clear()
Description copied from interface: TestableRequest
Clears the internal parameters map.

Specified by:
clear in interface TestableRequest
Returns:
the request for further configuration

setPath

public TestableRequest setPath(String path)
Description copied from interface: TestableRequest
Sets the path; the path should begin with a "/" character and contain everything from there to the start of query parameters (if any).

Specified by:
setPath in interface TestableRequest
Returns:
the request for further configuration

setLocale

public TestableRequest setLocale(Locale locale)
Description copied from interface: TestableRequest
Sets the locale requested by "the browser".

Specified by:
setLocale in interface TestableRequest
Returns:
the request for further configuration

loadParameter

public TestableRequest loadParameter(String parameterName,
                                     String parameterValue)
Description copied from interface: TestableRequest
Loads a single parameter/value pair. This may define a new parameter, or add a value to a list of parameters.

Specified by:
loadParameter in interface TestableRequest
Returns:
the request for further configuration

overrideParameter

public TestableRequest overrideParameter(String parameterName,
                                         String parameterValue)
Description copied from interface: TestableRequest
Overrides a parameter to the specific value, regardless of how the parameter was previously set.

Specified by:
overrideParameter in interface TestableRequest

getDateHeader

public long getDateHeader(String name)
Description copied from interface: Request
Returns the value of the specified request header as a long value that represents a Date object. Use this method with headers that contain dates, such as If-Modified-Since .

The date is returned as the number of milliseconds since January 1, 1970 GMT. The header name is case insensitive.

If the request did not have a header of the specified name, this method returns -1. If the header can't be converted to a date, the method throws an IllegalArgumentException.

Specified by:
getDateHeader in interface Request
Parameters:
name - a String specifying the name of the header
Returns:
a long value representing the date specified in the header expressed as the number of milliseconds since January 1, 1970 GMT, or -1 if the named header was not included with the reqest

getHeader

public String getHeader(String name)
Returns null.

Specified by:
getHeader in interface Request

getHeaderNames

public List<String> getHeaderNames()
Returns an empty list.

Specified by:
getHeaderNames in interface Request

getLocale

public Locale getLocale()
Description copied from interface: Request
Returns the locale of the client as determined from the request headers.

Specified by:
getLocale in interface Request

getParameterNames

public List<String> getParameterNames()
Description copied from interface: Request
Returns a list of query parameter names, in alphabetical order.

Specified by:
getParameterNames in interface Request

getParameters

public String[] getParameters(String name)
Description copied from interface: Request
Returns the parameter values for the given name. Returns null if no such parameter is in the request.

Specified by:
getParameters in interface Request

getPath

public String getPath()
Description copied from interface: Request
Returns the path portion of the request, which starts with a "/" and contains everything up to the start of the query parameters. It doesn't include the context path.

Specified by:
getPath in interface Request

getContextPath

public String getContextPath()
Description copied from interface: Request
Returns the context path. This always starts with a "/" character and does not end with one, with the exception of servlets in the root context, which return the empty string.

Specified by:
getContextPath in interface Request

getParameter

public String getParameter(String name)
Description copied from interface: Request
Returns the query parameter value for the given name. Returns null if no such parameter is in the request. For a multi-valued parameter, returns just the first value.

Specified by:
getParameter in interface Request

getSession

public Session getSession(boolean create)
Description copied from interface: Request
Gets the Session. If create is false and the session has not be created previously, returns null. Also, if the session is invalidated and create is false, returns null.

Specified by:
getSession in interface Request
Parameters:
create - true to force the creation of the session
Returns:
the session (or null if create is false the session has not been previously created)

setEncoding

public void setEncoding(String requestEncoding)

isXHR

public boolean isXHR()
Always returns false. If you need to test Ajax functionality, you need to be using Selenium.

Specified by:
isXHR in interface Request
Returns:
true if the request has an XmlHttpRequest origin

isSecure

public boolean isSecure()
Description copied from interface: Request
Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.

Specified by:
isSecure in interface Request
Returns:
a boolean indicating if the request was made using a secure channel

isRequestedSessionIdValid

public boolean isRequestedSessionIdValid()
Always returns true.

Specified by:
isRequestedSessionIdValid in interface Request
Returns:
true if the request included a session id that is still active, false if the included session id has expired

getAttribute

public Object getAttribute(String name)
Description copied from interface: Request
Returns the value of the named attribute as an Object, or null if no attribute of the given name exists. Because this method is a wrapper around ServletRequest.getAttribute(String), it is case sensitive (unlike most of Tapestry).

Specified by:
getAttribute in interface Request
Parameters:
name - a String specifying the name of the attribute
Returns:
an Object containing the value of the attribute, or null if the attribute does not exist

setAttribute

public void setAttribute(String name,
                         Object value)
Description copied from interface: Request
Stores an attribute in this request. Attributes are reset between requests (and remember that in Tapestry, there is usually two requests per operation: the action request that redirects to a render request).

Specified by:
setAttribute in interface Request
Parameters:
name - a String specifying the name of the attribute
value - the Object to be stored, or null to remove the attribute

getServerName

public String getServerName()
Returns "localhost" which is sufficient for testing purposes.

Specified by:
getServerName in interface Request
Returns:
the name of the server

getMethod

public String getMethod()
Always returns POST, to keep the Form component happy.

Specified by:
getMethod in interface Request
Returns:
a string specifying the name of the method with which this request was made

getLocalPort

public int getLocalPort()
Always returns 80.

Specified by:
getLocalPort in interface Request
Returns:
an integer specifying the port number

getServerPort

public int getServerPort()
Always returns 80.

Specified by:
getServerPort in interface Request
Returns:
an integer specifying the port number
Since:
5.2.5

getRemoteHost

public String getRemoteHost()
Always returns "localhost".

Specified by:
getRemoteHost in interface Request
Returns:
a String containing the fully qualified name of the client
Since:
5.3


Copyright © 2003-2012 The Apache Software Foundation.