Class TestAppContext

java.lang.Object
com.oorian.test.TestAppContext
All Implemented Interfaces:
AppContext

public class TestAppContext extends Object implements AppContext
In-memory implementation of AppContext for headless testing.

Provides a lightweight application context that does not require a servlet container. Attributes and init parameters are stored in memory and can be pre-configured before running tests.

Since:
2.1
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • TestAppContext

      public TestAppContext()
      Creates a new TestAppContext with an empty context path.
    • TestAppContext

      public TestAppContext(String contextPath)
      Creates a new TestAppContext with the specified context path.
      Parameters:
      contextPath - the application context path (e.g., "/myapp")
  • Method Details

    • setContextPath

      public TestAppContext setContextPath(String contextPath)
      Sets the context path.
      Parameters:
      contextPath - the application context path
      Returns:
      this instance for method chaining
    • setInitParameter

      public TestAppContext setInitParameter(String name, String value)
      Sets an init parameter.
      Parameters:
      name - the parameter name
      value - the parameter value
      Returns:
      this instance for method chaining
    • getContextPath

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

      public InputStream getResourceAsStream(String path)
      Description copied from interface: AppContext
      Returns an input stream for reading the specified resource.
      Specified by:
      getResourceAsStream in interface AppContext
      Parameters:
      path - the resource path (e.g., "/WEB-INF/config.xml")
      Returns:
      an input stream for the resource, or null if not found
    • getRealPath

      public String getRealPath(String path)
      Description copied from interface: AppContext
      Returns the real filesystem path for the specified virtual path.
      Specified by:
      getRealPath in interface AppContext
      Parameters:
      path - the virtual path (e.g., "/WEB-INF/config.xml")
      Returns:
      the real path, or null if the translation cannot be performed
    • getAttribute

      public Object getAttribute(String name)
      Description copied from interface: AppContext
      Returns the value of the named context attribute.
      Specified by:
      getAttribute in interface AppContext
      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: AppContext
      Sets a context attribute.
      Specified by:
      setAttribute in interface AppContext
      Parameters:
      name - the attribute name
      value - the attribute value
    • getInitParameter

      public String getInitParameter(String name)
      Description copied from interface: AppContext
      Returns the value of the named context initialization parameter.
      Specified by:
      getInitParameter in interface AppContext
      Parameters:
      name - the parameter name
      Returns:
      the parameter value, or null if not defined
    • getMimeType

      public String getMimeType(String file)
      Description copied from interface: AppContext
      Returns the MIME type of the specified file, or null if unknown.
      Specified by:
      getMimeType in interface AppContext
      Parameters:
      file - the file name
      Returns:
      the MIME type, or null