Class OorianTestContext

java.lang.Object
com.oorian.testing.OorianTestContext

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

    • create

      public static OorianTestContext 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

      public static OorianTestContext create(Locale locale)
      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

      public static OorianTestContext create(String requestURI, String method)
      Creates a new test context with a specific request URI and HTTP method.
      Parameters:
      requestURI - the request URI
      method - the HTTP method (GET, POST, etc.)
      Returns:
      a new OorianTestContext
    • getHttpSession

      public MockOorianHttpSession getHttpSession()
      Returns the mock HTTP session.
      Returns:
      the mock session
    • getRequest

      public MockOorianHttpRequest getRequest()
      Returns the mock HTTP request.
      Returns:
      the mock request
    • getWebsocketConnection

      public MockWebsocketConnection getWebsocketConnection()
      Returns the mock WebSocket connection.
      Returns:
      the mock WebSocket connection
    • getOorianSession

      public OorianSession 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.