Package com.oorian.test
Class TestHttpRequest
java.lang.Object
com.oorian.test.TestHttpRequest
- All Implemented Interfaces:
OorianHttpRequest
In-memory implementation of
OorianHttpRequest for headless testing.
Provides a configurable HTTP request object that does not require a servlet container. All request properties (headers, parameters, path, cookies, etc.) can be set before the request is used in a test.
Usage:
TestHttpRequest request = new TestHttpRequest("/my-page");
request.setParameter("id", "42");
request.setHeader("Accept-Language", "en-US");
- Since:
- 2.1
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionTestHttpRequest(String pathInfo) Creates a new TestHttpRequest for the specified path. -
Method Summary
Modifier and TypeMethodDescriptionaddCookie(OorianCookie cookie) Adds a cookie to the request.Adds a value to a request header (supports multi-value headers).Changes the session ID associated with this request.getAttribute(String name) Returns the value of the specified request attribute.Returns the character encoding of the request body.intReturns the length of the request body in bytes, or -1 if not known.Returns the content type of the request body.Returns the context path of the web application.Returns the cookies sent with this request.Returns the value of the specified request header.Returns an enumeration of all header names in this request.getHeaders(String name) Returns all values of the specified request header as an enumeration.Returns an input stream for reading the request body as binary data.Returns the preferred locale of the client, based on the Accept-Language header.Returns the HTTP method of this request (GET, POST, PUT, DELETE, etc.).getParameter(String name) Returns the value of a request parameter.Returns a map of all request parameters.getParts()Returns the multipart parts of this request.Returns the path info portion of the request URL.Returns the query string portion of the request URL.Returns aBufferedReaderfor reading the request body as character data.Returns the IP address of the client that sent the request.Returns the request URI.Returns the request URL as a StringBuffer.Returns the scheme (protocol) used for the request (e.g., "http" or "https").Returns the name of the server that received the request.intReturns the port number on which the request was received.Returns the servlet path portion of the request URL.getSession(boolean create) Returns the session associated with this request.booleanisSecure()Returns whether this request was made using a secure channel (HTTPS).voidsetAttribute(String name, Object value) Sets a request attribute.Sets the request body content.setContentType(String contentType) Sets the content type.setContextPath(String contextPath) Sets the application context path.Sets a request header.Sets the preferred locale for this request.Sets the HTTP method.setParameter(String name, String value) Sets a single-valued request parameter.setParameter(String name, String... values) Sets a multi-valued request parameter.setPathInfo(String pathInfo) Sets the path info (page path).setQueryString(String queryString) Sets the query string.Sets the HTTP scheme (http or https).setServerName(String serverName) Sets the server name.setServerPort(int serverPort) Sets the server port.setServletPath(String servletPath) Sets the servlet path.setSession(TestHttpSession session) Sets the session for this request.
-
Constructor Details
-
TestHttpRequest
Creates a new TestHttpRequest for the specified path.- Parameters:
pathInfo- the request path (e.g., "/my-page")
-
-
Method Details
-
setScheme
Sets the HTTP scheme (http or https).- Parameters:
scheme- the scheme- Returns:
- this instance for method chaining
-
setServerName
Sets the server name.- Parameters:
serverName- the server name- Returns:
- this instance for method chaining
-
setServerPort
Sets the server port.- Parameters:
serverPort- the server port- Returns:
- this instance for method chaining
-
setContextPath
Sets the application context path.- Parameters:
contextPath- the context path (e.g., "/myapp")- Returns:
- this instance for method chaining
-
setServletPath
Sets the servlet path.- Parameters:
servletPath- the servlet path- Returns:
- this instance for method chaining
-
setPathInfo
Sets the path info (page path).- Parameters:
pathInfo- the path info- Returns:
- this instance for method chaining
-
setQueryString
Sets the query string.- Parameters:
queryString- the query string (without the leading '?')- Returns:
- this instance for method chaining
-
setMethod
Sets the HTTP method.- Parameters:
method- the HTTP method (e.g., "GET", "POST")- Returns:
- this instance for method chaining
-
setContentType
Sets the content type.- Parameters:
contentType- the content type- Returns:
- this instance for method chaining
-
setBody
Sets the request body content.- Parameters:
body- the body content- Returns:
- this instance for method chaining
-
setSession
Sets the session for this request.- Parameters:
session- the test session- Returns:
- this instance for method chaining
-
setHeader
Sets a request header. Replaces any existing values for the header name.- Parameters:
name- the header namevalue- the header value- Returns:
- this instance for method chaining
-
addHeader
Adds a value to a request header (supports multi-value headers).- Parameters:
name- the header namevalue- the header value to add- Returns:
- this instance for method chaining
-
setParameter
Sets a single-valued request parameter.- Parameters:
name- the parameter namevalue- the parameter value- Returns:
- this instance for method chaining
-
setParameter
Sets a multi-valued request parameter.- Parameters:
name- the parameter namevalues- the parameter values- Returns:
- this instance for method chaining
-
addCookie
Adds a cookie to the request.- Parameters:
cookie- the cookie to add- Returns:
- this instance for method chaining
-
getHeader
Description copied from interface:OorianHttpRequestReturns the value of the specified request header.- Specified by:
getHeaderin interfaceOorianHttpRequest- Parameters:
name- the header name- Returns:
- the header value, or null if not present
-
getHeaderNames
Description copied from interface:OorianHttpRequestReturns an enumeration of all header names in this request.- Specified by:
getHeaderNamesin interfaceOorianHttpRequest- Returns:
- an enumeration of header names
-
getHeaders
Description copied from interface:OorianHttpRequestReturns all values of the specified request header as an enumeration.- Specified by:
getHeadersin interfaceOorianHttpRequest- Parameters:
name- the header name- Returns:
- an enumeration of header values
-
getPathInfo
Description copied from interface:OorianHttpRequestReturns the path info portion of the request URL.- Specified by:
getPathInfoin interfaceOorianHttpRequest- Returns:
- the path info, or null if none
-
getQueryString
Description copied from interface:OorianHttpRequestReturns the query string portion of the request URL.- Specified by:
getQueryStringin interfaceOorianHttpRequest- Returns:
- the query string, or null if none
-
getRequestURL
Description copied from interface:OorianHttpRequestReturns the request URL as a StringBuffer.- Specified by:
getRequestURLin interfaceOorianHttpRequest- Returns:
- the request URL
-
getRequestURI
Description copied from interface:OorianHttpRequestReturns the request URI.- Specified by:
getRequestURIin interfaceOorianHttpRequest- Returns:
- the request URI
-
getServletPath
Description copied from interface:OorianHttpRequestReturns the servlet path portion of the request URL.- Specified by:
getServletPathin interfaceOorianHttpRequest- Returns:
- the servlet path
-
getParameter
Description copied from interface:OorianHttpRequestReturns the value of a request parameter.- Specified by:
getParameterin interfaceOorianHttpRequest- Parameters:
name- the parameter name- Returns:
- the parameter value, or null if not present
-
getParameterMap
Description copied from interface:OorianHttpRequestReturns a map of all request parameters.- Specified by:
getParameterMapin interfaceOorianHttpRequest- Returns:
- the parameter map
-
getContentType
Description copied from interface:OorianHttpRequestReturns the content type of the request body.- Specified by:
getContentTypein interfaceOorianHttpRequest- Returns:
- the content type, or null if not specified
-
getCharacterEncoding
Description copied from interface:OorianHttpRequestReturns the character encoding of the request body.- Specified by:
getCharacterEncodingin interfaceOorianHttpRequest- Returns:
- the character encoding, or null if not specified
-
getRemoteAddr
Description copied from interface:OorianHttpRequestReturns the IP address of the client that sent the request.- Specified by:
getRemoteAddrin interfaceOorianHttpRequest- Returns:
- the remote address
-
getContextPath
Description copied from interface:OorianHttpRequestReturns the context path of the web application.- Specified by:
getContextPathin interfaceOorianHttpRequest- Returns:
- the context path
-
getCookies
Description copied from interface:OorianHttpRequestReturns the cookies sent with this request.- Specified by:
getCookiesin interfaceOorianHttpRequest- Returns:
- an array of cookies, or null if no cookies were sent
-
getParts
Description copied from interface:OorianHttpRequestReturns the multipart parts of this request.- Specified by:
getPartsin interfaceOorianHttpRequest- Returns:
- a collection of upload parts
-
getSession
Description copied from interface:OorianHttpRequestReturns the session associated with this request.- Specified by:
getSessionin interfaceOorianHttpRequest- Parameters:
create- whether to create a new session if one doesn't exist- Returns:
- the web session, or null if create is false and no session exists
-
getServerName
Description copied from interface:OorianHttpRequestReturns the name of the server that received the request.- Specified by:
getServerNamein interfaceOorianHttpRequest- Returns:
- the server name
-
getMethod
Description copied from interface:OorianHttpRequestReturns the HTTP method of this request (GET, POST, PUT, DELETE, etc.).- Specified by:
getMethodin interfaceOorianHttpRequest- Returns:
- the HTTP method name
-
getReader
Description copied from interface:OorianHttpRequestReturns aBufferedReaderfor reading the request body as character data.- Specified by:
getReaderin interfaceOorianHttpRequest- Returns:
- a BufferedReader for reading the request body
-
getInputStream
Description copied from interface:OorianHttpRequestReturns an input stream for reading the request body as binary data.- Specified by:
getInputStreamin interfaceOorianHttpRequest- Returns:
- the input stream
-
getScheme
Description copied from interface:OorianHttpRequestReturns the scheme (protocol) used for the request (e.g., "http" or "https").- Specified by:
getSchemein interfaceOorianHttpRequest- Returns:
- the scheme
-
getServerPort
public int getServerPort()Description copied from interface:OorianHttpRequestReturns the port number on which the request was received.- Specified by:
getServerPortin interfaceOorianHttpRequest- Returns:
- the server port
-
isSecure
public boolean isSecure()Description copied from interface:OorianHttpRequestReturns whether this request was made using a secure channel (HTTPS).- Specified by:
isSecurein interfaceOorianHttpRequest- Returns:
- true if the request is secure
-
getContentLength
public int getContentLength()Description copied from interface:OorianHttpRequestReturns the length of the request body in bytes, or -1 if not known.- Specified by:
getContentLengthin interfaceOorianHttpRequest- Returns:
- the content length, or -1
-
getAttribute
Description copied from interface:OorianHttpRequestReturns the value of the specified request attribute.- Specified by:
getAttributein interfaceOorianHttpRequest- Parameters:
name- the attribute name- Returns:
- the attribute value, or null if not set
-
setAttribute
Description copied from interface:OorianHttpRequestSets a request attribute.- Specified by:
setAttributein interfaceOorianHttpRequest- Parameters:
name- the attribute namevalue- the attribute value
-
getLocale
Description copied from interface:OorianHttpRequestReturns the preferred locale of the client, based on the Accept-Language header.- Specified by:
getLocalein interfaceOorianHttpRequest- Returns:
- the preferred locale
-
setLocale
Sets the preferred locale for this request.- Parameters:
locale- the locale- Returns:
- this instance for method chaining
-
changeSessionId
Description copied from interface:OorianHttpRequestChanges the session ID associated with this request.This method generates a new session ID for the current session while preserving all session attributes. It is used for session fixation protection after authentication.
- Specified by:
changeSessionIdin interfaceOorianHttpRequest- Returns:
- the new session ID
-