Skip to main content

juneau-rest-mock

Maven
<dependency>
<groupId>org.apache.juneau</groupId>
<artifactId>juneau-rest-mock</artifactId>
<version>${juneau.version}</version>
</dependency>
Jarjuneau-rest-mock-10.0.0.jar
OSGiorg.apache.juneau.rest.mock_10.0.0.jar
LinksMaven Central · Javadocs · Source

Contents/Features​

The juneau-rest-mock module contains convenience APIs for performing serverless unit testing of your REST APIs. Each of the APIs provides the ability to fully test your server and client REST interfaces without the need for a running servlet container.

See the guide: Test an endpoint with MockRestClient

Tests run entirely in-process. The mock client performs full serialization and parsing of the HTTP request and response, then dispatches the request directly to the resource's RestOpInvoker rather than sending it over the wire. This makes tests fast and self-contained while still exercising nearly all of the client- and server-side code paths — the actual over-the-wire transmission is the only aspect being bypassed.

The module ships two flavors of mock client:

Both clients live in the same Maven module and can be mixed in a single project.

Mock Testing ClassesMockRestClient (classic) extends RestClient, creates MockServletRequest and MockServletResponse objectsMockRestClient (next-generation) routes requests in-process to the target resource's RestContextMockHttpTransport — programmable in-process transport for the next-generation RestClient

In This Section​