A lightweight rewrite of the abandoned MockServer project with focus on simplicity, maintainability and Testcontainers.
[!NOTE] The full list of changes can be found in the changelog.
You may also have a look at the comparison with other frameworks.
Besides a few differences the usage is mostly identical to the original project.
try(MockServerContainer container = new MockServerContainer())
{
container.start();
try(MockServerClient client = new MockServerClient(
container.getHost(),
container.getServerPort()))
{
String expectedResponse = "Test";
// Setup expectation
client.when(request("/test").withMethod("GET"))
.respond(response().withBody(expectedResponse));
HttpClient httpClient = HttpClient.newHttpClient();
// Execute request
HttpResponse<String> resp = httpClient.send(
HttpRequest.newBuilder()
.uri(URI.create(container.getEndpoint() + "/test"))
.GET()
.build(),
HttpResponse.BodyHandlers.ofString());
assertEquals(expectedResponse, resp.body());
}
}
pom.xml
MockServer also works really well together with a network failure simulation tools such as ToxiProxy.
Installation guide for the latest release
Module | Distribution via |
---|---|
client | |
server |
|
testcontainers |
If you need support as soon as possible and you can't wait for any pull request, feel free to use our support.
See the contributing guide for detailed instructions on how to get started with our project.
View the license of the current project or the docs that contain a dependency summary (per module)