Class TestableRequestImpl
- java.lang.Object
-
- org.apache.tapestry5.internal.test.TestableRequestImpl
-
- All Implemented Interfaces:
Request,TestableRequest
public class TestableRequestImpl extends java.lang.Object implements TestableRequest
-
-
Field Summary
-
Fields inherited from interface org.apache.tapestry5.http.services.Request
REQUESTED_WITH_HEADER, X_FORWARDED_PROTO_HEADER
-
-
Constructor Summary
Constructors Constructor Description TestableRequestImpl(java.lang.String contextPath)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TestableRequestclear()Clears the internal parameters map.java.lang.ObjectgetAttribute(java.lang.String name)Returns the value of the named attribute as anObject, ornullif no attribute of the given name exists.java.util.List<java.lang.String>getAttributeNames()Returns a sorted list of attribute names.java.lang.StringgetContextPath()Returns the context path.longgetDateHeader(java.lang.String name)Returns the value of the specified request header as alongvalue that represents aDateobject.java.lang.StringgetHeader(java.lang.String name)Returns null.java.util.List<java.lang.String>getHeaderNames()Returns an empty list.java.util.LocalegetLocale()Returns the locale of the client as determined from the request headers.intgetLocalPort()Always returns 80.java.lang.StringgetMethod()Always returns POST, to keep the Form component happy.java.lang.StringgetParameter(java.lang.String name)Returns the query parameter value for the given name.java.util.List<java.lang.String>getParameterNames()Returns a list of query parameter names, in alphabetical order.java.lang.String[]getParameters(java.lang.String name)Returns the parameter values for the given name.java.lang.StringgetPath()Returns the path portion of the request, which starts with a "/" and contains everything up to the start of the query parameters.java.lang.StringgetRemoteHost()Always returns "localhost".java.lang.StringgetServerName()Returns "localhost" which is sufficient for testing purposes.intgetServerPort()Always returns 80.SessiongetSession(boolean create)Gets theSession.booleanisRequestedSessionIdValid()Always returns true.booleanisSecure()Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.booleanisSessionInvalidated()Returns true if the request specified a session, and that session has been invalidated.booleanisXHR()Always returns false.TestableRequestloadParameter(java.lang.String parameterName, java.lang.String parameterValue)Loads a single parameter/value pair.TestableRequestoverrideParameter(java.lang.String parameterName, java.lang.String parameterValue)Overrides a parameter to the specific value, regardless of how the parameter was previously set.voidsetAttribute(java.lang.String name, java.lang.Object value)Stores an attribute in this request.voidsetEncoding(java.lang.String requestEncoding)TestableRequestsetLocale(java.util.Locale locale)Sets the locale requested by "the browser".TestableRequestsetPath(java.lang.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).
-
-
-
Constructor Detail
-
TestableRequestImpl
@Inject public TestableRequestImpl(@Symbol("tapestry.context-path") java.lang.String contextPath)
-
-
Method Detail
-
clear
public TestableRequest clear()
Description copied from interface:TestableRequestClears the internal parameters map.- Specified by:
clearin interfaceTestableRequest- Returns:
- the request for further configuration
-
setPath
public TestableRequest setPath(java.lang.String path)
Description copied from interface:TestableRequestSets the path; the path should begin with a "/" character and contain everything from there to the start of query parameters (if any).- Specified by:
setPathin interfaceTestableRequest- Returns:
- the request for further configuration
-
setLocale
public TestableRequest setLocale(java.util.Locale locale)
Description copied from interface:TestableRequestSets the locale requested by "the browser".- Specified by:
setLocalein interfaceTestableRequest- Returns:
- the request for further configuration
-
loadParameter
public TestableRequest loadParameter(java.lang.String parameterName, java.lang.String parameterValue)
Description copied from interface:TestableRequestLoads a single parameter/value pair. This may define a new parameter, or add a value to a list of parameters.- Specified by:
loadParameterin interfaceTestableRequest- Returns:
- the request for further configuration
-
overrideParameter
public TestableRequest overrideParameter(java.lang.String parameterName, java.lang.String parameterValue)
Description copied from interface:TestableRequestOverrides a parameter to the specific value, regardless of how the parameter was previously set.- Specified by:
overrideParameterin interfaceTestableRequest
-
getDateHeader
public long getDateHeader(java.lang.String name)
Description copied from interface:RequestReturns the value of the specified request header as alongvalue that represents aDateobject. Use this method with headers that contain dates, such asIf-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 anIllegalArgumentException.- Specified by:
getDateHeaderin interfaceRequest- Parameters:
name- aStringspecifying the name of the header- Returns:
- a
longvalue 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 java.lang.String getHeader(java.lang.String name)
Returns null.
-
getHeaderNames
public java.util.List<java.lang.String> getHeaderNames()
Returns an empty list.- Specified by:
getHeaderNamesin interfaceRequest
-
getLocale
public java.util.Locale getLocale()
Description copied from interface:RequestReturns the locale of the client as determined from the request headers.
-
getParameterNames
public java.util.List<java.lang.String> getParameterNames()
Description copied from interface:RequestReturns a list of query parameter names, in alphabetical order.- Specified by:
getParameterNamesin interfaceRequest
-
getParameters
public java.lang.String[] getParameters(java.lang.String name)
Description copied from interface:RequestReturns the parameter values for the given name. Returns null if no such parameter is in the request.- Specified by:
getParametersin interfaceRequest
-
getPath
public java.lang.String getPath()
Description copied from interface:RequestReturns 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.
-
getContextPath
public java.lang.String getContextPath()
Description copied from interface:RequestReturns 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:
getContextPathin interfaceRequest
-
getParameter
public java.lang.String getParameter(java.lang.String name)
Description copied from interface:RequestReturns 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:
getParameterin interfaceRequest
-
getSession
public Session getSession(boolean create)
Description copied from interface:RequestGets theSession. 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. Invoking this method with true, when the session exists but has been invalidated, will force the creation of a new session.- Specified by:
getSessionin interfaceRequest- 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(java.lang.String requestEncoding)
-
isXHR
public boolean isXHR()
Always returns false. If you need to test Ajax functionality, you need to be using Selenium.
-
isSecure
public boolean isSecure()
Description copied from interface:RequestReturns a boolean indicating whether this request was made using a secure channel, such as HTTPS.
-
isRequestedSessionIdValid
public boolean isRequestedSessionIdValid()
Always returns true.- Specified by:
isRequestedSessionIdValidin interfaceRequest- Returns:
- true if the request included a session id that is still active, false if the included session id has expired
-
getAttribute
public java.lang.Object getAttribute(java.lang.String name)
Description copied from interface:RequestReturns the value of the named attribute as anObject, ornullif no attribute of the given name exists. Because this method is a wrapper aroundServletRequest.getAttribute(String), it is case sensitive (unlike most of Tapestry).- Specified by:
getAttributein interfaceRequest- Parameters:
name- aStringspecifying the name of the attribute- Returns:
- an
Objectcontaining the value of the attribute, ornullif the attribute does not exist
-
getAttributeNames
public java.util.List<java.lang.String> getAttributeNames()
Description copied from interface:RequestReturns a sorted list of attribute names.- Specified by:
getAttributeNamesin interfaceRequest
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Object value)
Description copied from interface:RequestStores 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:
setAttributein interfaceRequest- Parameters:
name- aStringspecifying the name of the attributevalue- theObjectto be stored, or null to remove the attribute
-
getServerName
public java.lang.String getServerName()
Returns "localhost" which is sufficient for testing purposes.- Specified by:
getServerNamein interfaceRequest- Returns:
- the name of the server
-
getMethod
public java.lang.String getMethod()
Always returns POST, to keep the Form component happy.
-
getLocalPort
public int getLocalPort()
Always returns 80.- Specified by:
getLocalPortin interfaceRequest- Returns:
- an integer specifying the port number
-
getServerPort
public int getServerPort()
Always returns 80.- Specified by:
getServerPortin interfaceRequest- Returns:
- an integer specifying the port number
- Since:
- 5.2.5
-
getRemoteHost
public java.lang.String getRemoteHost()
Always returns "localhost".- Specified by:
getRemoteHostin interfaceRequest- Returns:
- a
Stringcontaining the fully qualified name of the client - Since:
- 5.3
-
isSessionInvalidated
public boolean isSessionInvalidated()
Description copied from interface:RequestReturns true if the request specified a session, and that session has been invalidated.- Specified by:
isSessionInvalidatedin interfaceRequest- Returns:
- true if session was invalidated during this request
-
-