Package com.oorian.testing
Class MockOorianHttpRequest
java.lang.Object
com.oorian.testing.MockOorianHttpRequest
- All Implemented Interfaces:
OorianHttpRequest
Mock implementation of
OorianHttpRequest for testing without a servlet container.
This mock provides configurable request properties including headers, parameters,
cookies, locale, and URL components. All properties can be set via fluent setter
methods that return this for chaining.
Usage:
MockOorianHttpRequest request = new MockOorianHttpRequest()
.setRequestURI("/app/users/123")
.setContextPath("/app")
.setMethod("GET")
.setLocale(Locale.US);
request.addParameter("page", "1");
request.addHeader("Accept-Language", "en-US");
- Since:
- 2.1
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new MockOorianHttpRequest with default values.MockOorianHttpRequest(String requestURI) Constructs a new MockOorianHttpRequest with the specified URI. -
Method Summary
Modifier and TypeMethodDescriptionaddCookie(OorianCookie cookie) Adds a cookie to this request.Adds a request header.addParameter(String name, String value) Adds a request parameter with a single value.addParameter(String name, String... values) Adds a request parameter with multiple values.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.setCharacterEncoding(String characterEncoding) Sets the character encoding.setContentLength(int contentLength) Sets the content length.setContentType(String contentType) Sets the content type.setContextPath(String contextPath) Sets the context path.Sets the preferred locale.Sets the HTTP method.setPathInfo(String pathInfo) Sets the path info.setQueryString(String queryString) Sets the query string.setRemoteAddr(String remoteAddr) Sets the remote address.setRequestURI(String requestURI) Sets the request URI.Sets the scheme (http or https).setSecure(boolean secure) Sets whether this request uses a secure channel (HTTPS).setServerName(String serverName) Sets the server name.setServerPort(int serverPort) Sets the server port.setServletPath(String servletPath) Sets the servlet path.setSession(OorianHttpSession session) Sets the session associated with this request.
-
Constructor Details
-
MockOorianHttpRequest
public MockOorianHttpRequest()Constructs a new MockOorianHttpRequest with default values. -
MockOorianHttpRequest
Constructs a new MockOorianHttpRequest with the specified URI.- Parameters:
requestURI- the request URI
-
-
Method Details
-
setRequestURI
Sets the request URI.- Parameters:
requestURI- the request URI- Returns:
- this request for chaining
-
setContextPath
Sets the context path.- Parameters:
contextPath- the context path- Returns:
- this request for chaining
-
setServletPath
Sets the servlet path.- Parameters:
servletPath- the servlet path- Returns:
- this request for chaining
-
setPathInfo
Sets the path info.- Parameters:
pathInfo- the path info- Returns:
- this request for chaining
-
setQueryString
Sets the query string.- Parameters:
queryString- the query string- Returns:
- this request for chaining
-
setMethod
Sets the HTTP method.- Parameters:
method- the HTTP method (GET, POST, PUT, DELETE, etc.)- Returns:
- this request for chaining
-
setContentType
Sets the content type.- Parameters:
contentType- the content type- Returns:
- this request for chaining
-
setCharacterEncoding
Sets the character encoding.- Parameters:
characterEncoding- the character encoding- Returns:
- this request for chaining
-
setRemoteAddr
Sets the remote address.- Parameters:
remoteAddr- the remote IP address- Returns:
- this request for chaining
-
setServerName
Sets the server name.- Parameters:
serverName- the server name- Returns:
- this request for chaining
-
setScheme
Sets the scheme (http or https).- Parameters:
scheme- the scheme- Returns:
- this request for chaining
-
setServerPort
Sets the server port.- Parameters:
serverPort- the server port- Returns:
- this request for chaining
-
setContentLength
Sets the content length.- Parameters:
contentLength- the content length in bytes- Returns:
- this request for chaining
-
setSecure
Sets whether this request uses a secure channel (HTTPS).- Parameters:
secure- true for HTTPS- Returns:
- this request for chaining
-
setLocale
Sets the preferred locale.- Parameters:
locale- the locale- Returns:
- this request for chaining
-
setBody
Sets the request body content.- Parameters:
body- the body content- Returns:
- this request for chaining
-
setSession
Sets the session associated with this request.- Parameters:
session- the mock session- Returns:
- this request for chaining
-
addHeader
Adds a request header. Multiple values for the same header are supported.- Parameters:
name- the header namevalue- the header value- Returns:
- this request for chaining
-
addParameter
Adds a request parameter with a single value.- Parameters:
name- the parameter namevalue- the parameter value- Returns:
- this request for chaining
-
addParameter
Adds a request parameter with multiple values.- Parameters:
name- the parameter namevalues- the parameter values- Returns:
- this request for chaining
-
addCookie
Adds a cookie to this request.- Parameters:
cookie- the cookie to add- Returns:
- this request for 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
- Throws:
IOException- if an I/O error occurs
-
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
- Throws:
IOException- if an I/O error occurs
-
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
- Throws:
IOException- if an I/O error occurs
-
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
-
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
-