Mockserver Module

Mock Server can be used to mock HTTP services by matching requests against user-defined expectations.

Usage example

The following example shows how to start Mockserver.

@Rule
public MockServerContainer mockServer = new MockServerContainer();

And how to set a simple expectation using the Java MockServerClient.

new MockServerClient(mockServer.getContainerIpAddress(), mockServer.getServerPort())
    .when(request()
        .withPath("/person")
        .withQueryStringParameter("name", "peter"))
    .respond(response()
        .withBody("Peter the person!"));

// ...a GET request to '/person?name=peter' returns "Peter the person!"

Adding this module to your project dependencies

Add the following dependency to your pom.xml/build.gradle file:

testCompile "org.testcontainers:mockserver:1.14.1"
<dependency>
    <groupId>org.testcontainers</groupId>
    <artifactId>mockserver</artifactId>
    <version>1.14.1</version>
    <scope>test</scope>
</dependency>