Package org.apache.juneau.rest.mock
Class MockRestClient
java.lang.Object
org.apache.juneau.rest.mock.MockRestClient
- All Implemented Interfaces:
Closeable,AutoCloseable
Next-generation mock REST client that routes requests in-process to a Juneau
RestContext.
Use this class to write serverless unit tests for @Rest-annotated
resource classes. Requests are dispatched directly to the RestContext without any network activity,
making tests fast and self-contained.
Example:
See Also:
- Since:
- 9.2.1
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic MockRestClient.BuilderReturns a newMockRestClient.Builderfor the given REST bean or bean class.voidclose()static MockRestClientCreates anMockRestClientbacked by the given REST bean or bean class.Creates a DELETE request to the given path.Creates a GET request to the given path.Returns the underlyingRestClient.Creates a HEAD request to the given path.Creates a PATCH request to the given path.Creates a POST request to the given path.Creates a PUT request to the given path.Creates a request with the given HTTP method and path.
-
Method Details
-
create
Creates anMockRestClientbacked by the given REST bean or bean class.RestContextinstances are cached per class for performance when aClassis passed; a supplied bean instance always gets its own context. -
builder
Returns a newMockRestClient.Builderfor the given REST bean or bean class. -
get
Creates a GET request to the given path.- Parameters:
path- The request path (relative to the resource's servlet path). Must not benull .- Returns:
- A new
RestRequest. Nevernull .
-
post
Creates a POST request to the given path.- Parameters:
path- The request path. Must not benull .- Returns:
- A new
RestRequest. Nevernull .
-
put
Creates a PUT request to the given path.- Parameters:
path- The request path. Must not benull .- Returns:
- A new
RestRequest. Nevernull .
-
patch
Creates a PATCH request to the given path.- Parameters:
path- The request path. Must not benull .- Returns:
- A new
RestRequest. Nevernull .
-
delete
Creates a DELETE request to the given path.- Parameters:
path- The request path. Must not benull .- Returns:
- A new
RestRequest. Nevernull .
-
head
Creates a HEAD request to the given path.- Parameters:
path- The request path. Must not benull .- Returns:
- A new
RestRequest. Nevernull .
-
request
Creates a request with the given HTTP method and path.- Parameters:
method- The HTTP method. Must not benull .path- The request path. Must not benull .- Returns:
- A new
RestRequest. Nevernull .
-
getClient
Returns the underlyingRestClient.- Returns:
- The client. Never
null .
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-