Package com.oorian.test
Class TestAppContext
java.lang.Object
com.oorian.test.TestAppContext
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionCreates a new TestAppContext with an empty context path.TestAppContext(String contextPath) Creates a new TestAppContext with the specified context path. -
Method Summary
Modifier and TypeMethodDescriptiongetAttribute(String name) Returns the value of the named context attribute.Returns the context path of the web application.getInitParameter(String name) Returns the value of the named context initialization parameter.getMimeType(String file) Returns the MIME type of the specified file, or null if unknown.getRealPath(String path) Returns the real filesystem path for the specified virtual path.getResourceAsStream(String path) Returns an input stream for reading the specified resource.voidsetAttribute(String name, Object value) Sets a context attribute.setContextPath(String contextPath) Sets the context path.setInitParameter(String name, String value) Sets an init parameter.
-
Constructor Details
-
TestAppContext
public TestAppContext()Creates a new TestAppContext with an empty context path. -
TestAppContext
Creates a new TestAppContext with the specified context path.- Parameters:
contextPath- the application context path (e.g., "/myapp")
-
-
Method Details
-
setContextPath
Sets the context path.- Parameters:
contextPath- the application context path- Returns:
- this instance for method chaining
-
setInitParameter
Sets an init parameter.- Parameters:
name- the parameter namevalue- the parameter value- Returns:
- this instance for method chaining
-
getContextPath
Description copied from interface:AppContextReturns the context path of the web application.- Specified by:
getContextPathin interfaceAppContext- Returns:
- the context path
-
getResourceAsStream
Description copied from interface:AppContextReturns an input stream for reading the specified resource.- Specified by:
getResourceAsStreamin interfaceAppContext- Parameters:
path- the resource path (e.g., "/WEB-INF/config.xml")- Returns:
- an input stream for the resource, or null if not found
-
getRealPath
Description copied from interface:AppContextReturns the real filesystem path for the specified virtual path.- Specified by:
getRealPathin interfaceAppContext- Parameters:
path- the virtual path (e.g., "/WEB-INF/config.xml")- Returns:
- the real path, or null if the translation cannot be performed
-
getAttribute
Description copied from interface:AppContextReturns the value of the named context attribute.- Specified by:
getAttributein interfaceAppContext- Parameters:
name- the attribute name- Returns:
- the attribute value, or null if not set
-
setAttribute
Description copied from interface:AppContextSets a context attribute.- Specified by:
setAttributein interfaceAppContext- Parameters:
name- the attribute namevalue- the attribute value
-
getInitParameter
Description copied from interface:AppContextReturns the value of the named context initialization parameter.- Specified by:
getInitParameterin interfaceAppContext- Parameters:
name- the parameter name- Returns:
- the parameter value, or null if not defined
-
getMimeType
Description copied from interface:AppContextReturns the MIME type of the specified file, or null if unknown.- Specified by:
getMimeTypein interfaceAppContext- Parameters:
file- the file name- Returns:
- the MIME type, or null
-