Class ContextController

java.lang.Object
io.github.cdiunit.ContextController

@ApplicationScoped public class ContextController extends Object
Use to explicitly open and close Request, Session and Conversation scopes.

If you are testing code that runs over several requests then you may want to explicitly control activation and deactivation of scopes. Use ContextController to do this.


 @RunWith(CdiRunner.class)
 @AdditionalClasses(RequestScopedWarpDrive.class)
 class TestStarship {

     @Inject
     ContextController contextController; // Obtain an instance of the context
                                          // controller.

     @Inject
     Starship starship;

     @Test
     void testStart() {
         contextController.openRequest(); // Start a new request.

         starship.start();
         contextController.closeRequest(); // Close the current request.
     }
 }
 
  • Constructor Details

    • ContextController

      public ContextController()
  • Method Details

    • openRequest

      public jakarta.servlet.http.HttpServletRequest openRequest()
      Start a request.
      Returns:
      The request opened.
    • currentRequest

      public jakarta.servlet.http.HttpServletRequest currentRequest()
      Returns:
      Returns the current in progress request or throws an exception if the request was not active
    • closeRequest

      public void closeRequest()
      Close the currently active request.
    • closeSession

      public void closeSession()
      Close the currently active session.
    • getSession

      public jakarta.servlet.http.HttpSession getSession()