java.lang.Object
io.jooby.test.MockRouter
Utility class that allows us to execute routes using a
MockContext.
App.java
{
get("/", ctx -> "OK");
}
UnitTest:
MockRouter router = new MockRouter(new App());
assertEquals("OK", router.get("/"));
- Since:
- 2.0.0
- Author:
- edgar
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionExecute a PATCH request to the target application.call(String method, String path, MockContext ctx, Consumer<MockResponse> consumer) Execute a PATCH request to the target application.call(String method, String path, Consumer<MockResponse> consumer) Execute a PATCH request to the target application.Execute a DELETE request to the target application.Execute a DELETE request to the target application.delete(String path, MockContext context, Consumer<MockResponse> consumer) Execute a DELETE request to the target application.delete(String path, Consumer<MockResponse> consumer) Execute a DELETE request to the target application.Execute a GET request to the target application.Execute a GET request to the target application.get(String path, MockContext context, Consumer<MockResponse> consumer) Execute a GET request to the target application.get(String path, Consumer<MockResponse> consumer) Execute a GET request to the target application.Get the worker executor for running test.Execute a PATCH request to the target application.Execute a PATCH request to the target application.patch(String path, MockContext context, Consumer<MockResponse> consumer) Execute a PATCH request to the target application.patch(String path, Consumer<MockResponse> consumer) Execute a PATCH request to the target application.Execute a POST request to the target application.Execute a POST request to the target application.post(String path, MockContext context, Consumer<MockResponse> consumer) Execute a POST request to the target application.post(String path, Consumer<MockResponse> consumer) Execute a POST request to the target application.Execute a PUT request to the target application.Execute a PUT request to the target application.put(String path, MockContext context, Consumer<MockResponse> consumer) Execute a PUT request to the target application.put(String path, Consumer<MockResponse> consumer) Execute a PUT request to the target application.setFullExecution(boolean enabled) Set whenever to execute the entire pipeline (decorators + handler) or just the handler.setSession(MockSession session) Set a global session.Set the worker executor to use.voidInvoke an error handler that matches the given exception.voidtryError(Throwable cause, Consumer<MockResponse> consumer) Invoke an error handler that matches the given exception.ws(String path, Consumer<MockWebSocketClient> callback) Execute a GET request and find a websocket, perform the upgrade and produces a websocket client.
-
Constructor Details
-
MockRouter
public MockRouter(io.jooby.Jooby application) Creates a new mock router.- Parameters:
application- Source application.
-
-
Method Details
-
setSession
Set a global session. So all route invocations are going to shared the same session as long as they don't use a custom context per invocation.- Parameters:
session- Global session.- Returns:
- This router.
-
getWorker
Get the worker executor for running test.- Returns:
- Worker executor or
null.
-
setWorker
Set the worker executor to use.- Parameters:
worker- Worker executor.- Returns:
- This router.
-
get
Execute a GET request to the target application.- Parameters:
path- Path to match. Might includes the queryString.- Returns:
- Route response.
-
ws
Execute a GET request and find a websocket, perform the upgrade and produces a websocket client.App:
Test:ws("/path", (ctx, initializer) -> { initializer.onConnect(ws -> { ws.send("OnConnect"); }); });MockRouter router = new MockRouter(new App()); router.ws("/path", ws -> { ws.onMessage(message -> { System.out.println("Got: " + message); }); ws.send("Another message"); })- Parameters:
path- Path to match.callback- Websocket client callback.- Returns:
- Web socket client.
-
get
Execute a GET request to the target application.- Parameters:
path- Path to match. Might includes the queryString.context- Context to use.- Returns:
- Route response.
-
get
Execute a GET request to the target application.- Parameters:
path- Path to match. Might includes the queryString.consumer- Response metadata callback.- Returns:
- Route response.
-
get
Execute a GET request to the target application.- Parameters:
path- Path to match. Might includes the queryString.context- Context to use.consumer- Response metadata callback.- Returns:
- Route response.
-
post
Execute a POST request to the target application.- Parameters:
path- Path to match. Might includes the queryString.- Returns:
- Route response.
-
post
Execute a POST request to the target application.- Parameters:
path- Path to match. Might includes the queryString.context- Context to use.- Returns:
- Route response.
-
post
Execute a POST request to the target application.- Parameters:
path- Path to match. Might includes the queryString.consumer- Response metadata callback.- Returns:
- Route response.
-
post
Execute a POST request to the target application.- Parameters:
path- Path to match. Might includes the queryString.context- Context to use.consumer- Response metadata callback.- Returns:
- Route response.
-
delete
Execute a DELETE request to the target application.- Parameters:
path- Path to match. Might includes the queryString.- Returns:
- Route response.
-
delete
Execute a DELETE request to the target application.- Parameters:
path- Path to match. Might includes the queryString.context- Context to use.- Returns:
- Route response.
-
delete
Execute a DELETE request to the target application.- Parameters:
path- Path to match. Might includes the queryString.consumer- Response metadata callback.- Returns:
- Route response.
-
delete
Execute a DELETE request to the target application.- Parameters:
path- Path to match. Might includes the queryString.context- Context to use.consumer- Response metadata callback.- Returns:
- Route response.
-
put
Execute a PUT request to the target application.- Parameters:
path- Path to match. Might includes the queryString.- Returns:
- Route response.
-
put
Execute a PUT request to the target application.- Parameters:
path- Path to match. Might includes the queryString.context- Context to use.- Returns:
- Route response.
-
put
Execute a PUT request to the target application.- Parameters:
path- Path to match. Might includes the queryString.consumer- Response metadata callback.- Returns:
- Route response.
-
put
Execute a PUT request to the target application.- Parameters:
path- Path to match. Might includes the queryString.context- Context to use.consumer- Response metadata callback.- Returns:
- Route response.
-
patch
Execute a PATCH request to the target application.- Parameters:
path- Path to match. Might includes the queryString.- Returns:
- Route response.
-
patch
Execute a PATCH request to the target application.- Parameters:
path- Path to match. Might includes the queryString.context- Context to use.- Returns:
- Route response.
-
patch
Execute a PATCH request to the target application.- Parameters:
path- Path to match. Might includes the queryString.consumer- Response metadata callback.- Returns:
- Route response.
-
patch
Execute a PATCH request to the target application.- Parameters:
path- Path to match. Might includes the queryString.context- Context to use.consumer- Response metadata callback.- Returns:
- Route response.
-
call
Execute a PATCH request to the target application.- Parameters:
method- HTTP method.path- Path to match. Might includes the queryString.context- Web context.- Returns:
- Route response.
-
call
Execute a PATCH request to the target application.- Parameters:
method- HTTP method.path- Path to match. Might includes the queryString.consumer- Response metadata callback.- Returns:
- Route response.
-
call
Execute a PATCH request to the target application.- Parameters:
method- HTTP method.path- Path to match. Might includes the queryString.ctx- Context to use.consumer- Response metadata callback.- Returns:
- Route response.
-
setFullExecution
Set whenever to execute the entire pipeline (decorators + handler) or just the handler. This flag is off by default, so only the handlers is executed.- Parameters:
enabled- True for enabled the entire pipeline.- Returns:
- This mock router.
-
tryError
Invoke an error handler that matches the given exception.- Parameters:
cause- Exception type.consumer- Callback.
-
tryError
Invoke an error handler that matches the given exception.- Parameters:
cause- Exception type.ctx- Context.
-