Package io.github.cdiunit
Class ContextController
java.lang.Object
io.github.cdiunit.ContextController
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. } }
- Author:
- Bryn Cooke, Lars-Fredrik Smedberg
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Close the currently active request.void
Close the currently active session.jakarta.servlet.http.HttpServletRequest
jakarta.servlet.http.HttpSession
jakarta.servlet.http.HttpServletRequest
Start a 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()
-