Class MockOorianHttpRequest

java.lang.Object
com.oorian.testing.MockOorianHttpRequest
All Implemented Interfaces:
OorianHttpRequest

public class MockOorianHttpRequest extends Object implements 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 Details

    • MockOorianHttpRequest

      public MockOorianHttpRequest()
      Constructs a new MockOorianHttpRequest with default values.
    • MockOorianHttpRequest

      public MockOorianHttpRequest(String requestURI)
      Constructs a new MockOorianHttpRequest with the specified URI.
      Parameters:
      requestURI - the request URI
  • Method Details

    • setRequestURI

      public MockOorianHttpRequest setRequestURI(String requestURI)
      Sets the request URI.
      Parameters:
      requestURI - the request URI
      Returns:
      this request for chaining
    • setContextPath

      public MockOorianHttpRequest setContextPath(String contextPath)
      Sets the context path.
      Parameters:
      contextPath - the context path
      Returns:
      this request for chaining
    • setServletPath

      public MockOorianHttpRequest setServletPath(String servletPath)
      Sets the servlet path.
      Parameters:
      servletPath - the servlet path
      Returns:
      this request for chaining
    • setPathInfo

      public MockOorianHttpRequest setPathInfo(String pathInfo)
      Sets the path info.
      Parameters:
      pathInfo - the path info
      Returns:
      this request for chaining
    • setQueryString

      public MockOorianHttpRequest setQueryString(String queryString)
      Sets the query string.
      Parameters:
      queryString - the query string
      Returns:
      this request for chaining
    • setMethod

      public MockOorianHttpRequest setMethod(String method)
      Sets the HTTP method.
      Parameters:
      method - the HTTP method (GET, POST, PUT, DELETE, etc.)
      Returns:
      this request for chaining
    • setContentType

      public MockOorianHttpRequest setContentType(String contentType)
      Sets the content type.
      Parameters:
      contentType - the content type
      Returns:
      this request for chaining
    • setCharacterEncoding

      public MockOorianHttpRequest setCharacterEncoding(String characterEncoding)
      Sets the character encoding.
      Parameters:
      characterEncoding - the character encoding
      Returns:
      this request for chaining
    • setRemoteAddr

      public MockOorianHttpRequest setRemoteAddr(String remoteAddr)
      Sets the remote address.
      Parameters:
      remoteAddr - the remote IP address
      Returns:
      this request for chaining
    • setServerName

      public MockOorianHttpRequest setServerName(String serverName)
      Sets the server name.
      Parameters:
      serverName - the server name
      Returns:
      this request for chaining
    • setScheme

      public MockOorianHttpRequest setScheme(String scheme)
      Sets the scheme (http or https).
      Parameters:
      scheme - the scheme
      Returns:
      this request for chaining
    • setServerPort

      public MockOorianHttpRequest setServerPort(int serverPort)
      Sets the server port.
      Parameters:
      serverPort - the server port
      Returns:
      this request for chaining
    • setContentLength

      public MockOorianHttpRequest setContentLength(int contentLength)
      Sets the content length.
      Parameters:
      contentLength - the content length in bytes
      Returns:
      this request for chaining
    • setSecure

      public MockOorianHttpRequest setSecure(boolean secure)
      Sets whether this request uses a secure channel (HTTPS).
      Parameters:
      secure - true for HTTPS
      Returns:
      this request for chaining
    • setLocale

      public MockOorianHttpRequest setLocale(Locale locale)
      Sets the preferred locale.
      Parameters:
      locale - the locale
      Returns:
      this request for chaining
    • setBody

      public MockOorianHttpRequest setBody(String body)
      Sets the request body content.
      Parameters:
      body - the body content
      Returns:
      this request for chaining
    • setSession

      public MockOorianHttpRequest setSession(OorianHttpSession session)
      Sets the session associated with this request.
      Parameters:
      session - the mock session
      Returns:
      this request for chaining
    • addHeader

      public MockOorianHttpRequest addHeader(String name, String value)
      Adds a request header. Multiple values for the same header are supported.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this request for chaining
    • addParameter

      public MockOorianHttpRequest addParameter(String name, String value)
      Adds a request parameter with a single value.
      Parameters:
      name - the parameter name
      value - the parameter value
      Returns:
      this request for chaining
    • addParameter

      public MockOorianHttpRequest addParameter(String name, String... values)
      Adds a request parameter with multiple values.
      Parameters:
      name - the parameter name
      values - the parameter values
      Returns:
      this request for chaining
    • addCookie

      public MockOorianHttpRequest addCookie(OorianCookie cookie)
      Adds a cookie to this request.
      Parameters:
      cookie - the cookie to add
      Returns:
      this request for chaining
    • getHeader

      public String getHeader(String name)
      Description copied from interface: OorianHttpRequest
      Returns the value of the specified request header.
      Specified by:
      getHeader in interface OorianHttpRequest
      Parameters:
      name - the header name
      Returns:
      the header value, or null if not present
    • getHeaderNames

      public Enumeration<String> getHeaderNames()
      Description copied from interface: OorianHttpRequest
      Returns an enumeration of all header names in this request.
      Specified by:
      getHeaderNames in interface OorianHttpRequest
      Returns:
      an enumeration of header names
    • getHeaders

      public Enumeration<String> getHeaders(String name)
      Description copied from interface: OorianHttpRequest
      Returns all values of the specified request header as an enumeration.
      Specified by:
      getHeaders in interface OorianHttpRequest
      Parameters:
      name - the header name
      Returns:
      an enumeration of header values
    • getPathInfo

      public String getPathInfo()
      Description copied from interface: OorianHttpRequest
      Returns the path info portion of the request URL.
      Specified by:
      getPathInfo in interface OorianHttpRequest
      Returns:
      the path info, or null if none
    • getQueryString

      public String getQueryString()
      Description copied from interface: OorianHttpRequest
      Returns the query string portion of the request URL.
      Specified by:
      getQueryString in interface OorianHttpRequest
      Returns:
      the query string, or null if none
    • getRequestURL

      public StringBuffer getRequestURL()
      Description copied from interface: OorianHttpRequest
      Returns the request URL as a StringBuffer.
      Specified by:
      getRequestURL in interface OorianHttpRequest
      Returns:
      the request URL
    • getRequestURI

      public String getRequestURI()
      Description copied from interface: OorianHttpRequest
      Returns the request URI.
      Specified by:
      getRequestURI in interface OorianHttpRequest
      Returns:
      the request URI
    • getServletPath

      public String getServletPath()
      Description copied from interface: OorianHttpRequest
      Returns the servlet path portion of the request URL.
      Specified by:
      getServletPath in interface OorianHttpRequest
      Returns:
      the servlet path
    • getParameter

      public String getParameter(String name)
      Description copied from interface: OorianHttpRequest
      Returns the value of a request parameter.
      Specified by:
      getParameter in interface OorianHttpRequest
      Parameters:
      name - the parameter name
      Returns:
      the parameter value, or null if not present
    • getParameterMap

      public Map<String,String[]> getParameterMap()
      Description copied from interface: OorianHttpRequest
      Returns a map of all request parameters.
      Specified by:
      getParameterMap in interface OorianHttpRequest
      Returns:
      the parameter map
    • getContentType

      public String getContentType()
      Description copied from interface: OorianHttpRequest
      Returns the content type of the request body.
      Specified by:
      getContentType in interface OorianHttpRequest
      Returns:
      the content type, or null if not specified
    • getCharacterEncoding

      public String getCharacterEncoding()
      Description copied from interface: OorianHttpRequest
      Returns the character encoding of the request body.
      Specified by:
      getCharacterEncoding in interface OorianHttpRequest
      Returns:
      the character encoding, or null if not specified
    • getRemoteAddr

      public String getRemoteAddr()
      Description copied from interface: OorianHttpRequest
      Returns the IP address of the client that sent the request.
      Specified by:
      getRemoteAddr in interface OorianHttpRequest
      Returns:
      the remote address
    • getContextPath

      public String getContextPath()
      Description copied from interface: OorianHttpRequest
      Returns the context path of the web application.
      Specified by:
      getContextPath in interface OorianHttpRequest
      Returns:
      the context path
    • getCookies

      public OorianCookie[] getCookies()
      Description copied from interface: OorianHttpRequest
      Returns the cookies sent with this request.
      Specified by:
      getCookies in interface OorianHttpRequest
      Returns:
      an array of cookies, or null if no cookies were sent
    • getParts

      public Collection<OorianUploadPart> getParts() throws IOException
      Description copied from interface: OorianHttpRequest
      Returns the multipart parts of this request.
      Specified by:
      getParts in interface OorianHttpRequest
      Returns:
      a collection of upload parts
      Throws:
      IOException - if an I/O error occurs
    • getSession

      public OorianHttpSession getSession(boolean create)
      Description copied from interface: OorianHttpRequest
      Returns the session associated with this request.
      Specified by:
      getSession in interface OorianHttpRequest
      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

      public String getServerName()
      Description copied from interface: OorianHttpRequest
      Returns the name of the server that received the request.
      Specified by:
      getServerName in interface OorianHttpRequest
      Returns:
      the server name
    • getMethod

      public String getMethod()
      Description copied from interface: OorianHttpRequest
      Returns the HTTP method of this request (GET, POST, PUT, DELETE, etc.).
      Specified by:
      getMethod in interface OorianHttpRequest
      Returns:
      the HTTP method name
    • getReader

      public BufferedReader getReader() throws IOException
      Description copied from interface: OorianHttpRequest
      Returns a BufferedReader for reading the request body as character data.
      Specified by:
      getReader in interface OorianHttpRequest
      Returns:
      a BufferedReader for reading the request body
      Throws:
      IOException - if an I/O error occurs
    • getInputStream

      public InputStream getInputStream() throws IOException
      Description copied from interface: OorianHttpRequest
      Returns an input stream for reading the request body as binary data.
      Specified by:
      getInputStream in interface OorianHttpRequest
      Returns:
      the input stream
      Throws:
      IOException - if an I/O error occurs
    • getScheme

      public String getScheme()
      Description copied from interface: OorianHttpRequest
      Returns the scheme (protocol) used for the request (e.g., "http" or "https").
      Specified by:
      getScheme in interface OorianHttpRequest
      Returns:
      the scheme
    • getServerPort

      public int getServerPort()
      Description copied from interface: OorianHttpRequest
      Returns the port number on which the request was received.
      Specified by:
      getServerPort in interface OorianHttpRequest
      Returns:
      the server port
    • isSecure

      public boolean isSecure()
      Description copied from interface: OorianHttpRequest
      Returns whether this request was made using a secure channel (HTTPS).
      Specified by:
      isSecure in interface OorianHttpRequest
      Returns:
      true if the request is secure
    • getContentLength

      public int getContentLength()
      Description copied from interface: OorianHttpRequest
      Returns the length of the request body in bytes, or -1 if not known.
      Specified by:
      getContentLength in interface OorianHttpRequest
      Returns:
      the content length, or -1
    • getAttribute

      public Object getAttribute(String name)
      Description copied from interface: OorianHttpRequest
      Returns the value of the specified request attribute.
      Specified by:
      getAttribute in interface OorianHttpRequest
      Parameters:
      name - the attribute name
      Returns:
      the attribute value, or null if not set
    • setAttribute

      public void setAttribute(String name, Object value)
      Description copied from interface: OorianHttpRequest
      Sets a request attribute.
      Specified by:
      setAttribute in interface OorianHttpRequest
      Parameters:
      name - the attribute name
      value - the attribute value
    • getLocale

      public Locale getLocale()
      Description copied from interface: OorianHttpRequest
      Returns the preferred locale of the client, based on the Accept-Language header.
      Specified by:
      getLocale in interface OorianHttpRequest
      Returns:
      the preferred locale
    • changeSessionId

      public String changeSessionId()
      Description copied from interface: OorianHttpRequest
      Changes 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:
      changeSessionId in interface OorianHttpRequest
      Returns:
      the new session ID