Package com.oorian.testing
Class OorianTestContext
java.lang.Object
com.oorian.testing.OorianTestContext
Helper class for setting up a complete Oorian test environment without a servlet container.
OorianTestContext creates and wires together a MockOorianHttpSession,
MockOorianHttpRequest, and MockWebsocketConnection, and registers
the session to the current thread via OorianSession.register(com.oorian.OorianHttpSession).
This enables unit testing of components that rely on OorianSession.get().
Usage:
// Set up test context
OorianTestContext ctx = OorianTestContext.create();
// Access mock objects for verification
MockWebsocketConnection ws = ctx.getWebsocketConnection();
MockOorianHttpRequest request = ctx.getRequest();
// OorianSession.get() now works
OorianSession session = OorianSession.get();
session.setAttribute("userId", 12345);
// Clean up after test
ctx.tearDown();
- Since:
- 2.1
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic OorianTestContextcreate()Creates a new test context with default mock objects and registers the session to the current thread.static OorianTestContextCreates a new test context with a specific request URI and HTTP method.static OorianTestContextCreates a new test context configured for the specified locale.Returns the mock HTTP session.Returns the registered OorianSession.Returns the mock HTTP request.Returns the mock WebSocket connection.voidtearDown()Cleans up the test context by removing the session from the current thread.
-
Method Details
-
create
Creates a new test context with default mock objects and registers the session to the current thread.After calling this method,
OorianSession.get()will return a valid session on the current thread.- Returns:
- a new OorianTestContext
-
create
Creates a new test context configured for the specified locale.- Parameters:
locale- the locale to set on the mock request- Returns:
- a new OorianTestContext
-
create
Creates a new test context with a specific request URI and HTTP method.- Parameters:
requestURI- the request URImethod- the HTTP method (GET, POST, etc.)- Returns:
- a new OorianTestContext
-
getHttpSession
Returns the mock HTTP session.- Returns:
- the mock session
-
getRequest
Returns the mock HTTP request.- Returns:
- the mock request
-
getWebsocketConnection
Returns the mock WebSocket connection.- Returns:
- the mock WebSocket connection
-
getOorianSession
Returns the registered OorianSession.- Returns:
- the OorianSession
-
tearDown
public void tearDown()Cleans up the test context by removing the session from the current thread.This should be called in a test's teardown/cleanup method to prevent thread-local session leaks between tests.
-