Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/modules/mockserver.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Mockserver Module

!!! note "Deprecated — use the MockServer-maintained module for new projects"
This bundled module is deprecated. For new projects, prefer the MockServer-maintained
module [`org.mock-server:mockserver-testcontainers`](https://www.mock-server.com/mock_server/mockserver_testcontainers.html)
(class `org.mockserver.testcontainers.MockServerContainer`). It tracks current MockServer
releases, derives its image tag from the client library so the container and client stay in
lockstep, and adds configuration helpers (DNS, transparent proxy, HTTP/3, initialization JSON,
log level, arbitrary properties) plus direct `MockServerClient` wiring. This page documents the
legacy bundled module.

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

## Usage example
Expand Down
4 changes: 3 additions & 1 deletion modules/mockserver/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ description = "Testcontainers :: MockServer"
dependencies {
api project(':testcontainers')

testImplementation 'org.mock-server:mockserver-client-java:5.15.0'
// Single source of truth for the MockServer version: the test derives its container image
// tag from this client jar's implementation version, so bumping here updates both in lockstep.
testImplementation 'org.mock-server:mockserver-client-java:7.1.0'
testImplementation 'io.rest-assured:rest-assured:5.5.7'
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@
import org.testcontainers.utility.DockerImageName;

/**
* @deprecated use {@link org.testcontainers.mockserver.MockServerContainer} instead.
* @deprecated Use the MockServer-maintained module instead:
* {@code org.mock-server:mockserver-testcontainers}
* (class {@code org.mockserver.testcontainers.MockServerContainer}). It tracks current MockServer
* releases, derives its image tag from the client library so the two stay in lockstep, and adds
* configuration helpers (DNS, transparent proxy, HTTP/3, initialization JSON, log level, arbitrary
* properties) plus direct {@code MockServerClient} wiring.
*
* @see <a href="https://www.mock-server.com/mock_server/mockserver_testcontainers.html">MockServer Testcontainers module</a>
*/
@Slf4j
@Deprecated
public class MockServerContainer extends GenericContainer<MockServerContainer> {

// Intentionally frozen at this legacy image/tag: this superseded redirect stub keeps its original
// jamesdbloom/mockserver default for backwards compatibility. New code should use the
// MockServer-maintained module referenced in the deprecation notice above.
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("jamesdbloom/mockserver");

private static final String DEFAULT_TAG = "mockserver-5.5.4";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,25 @@
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.DockerImageName;

/**
* @deprecated Use the MockServer-maintained module instead:
* {@code org.mock-server:mockserver-testcontainers}
* (class {@code org.mockserver.testcontainers.MockServerContainer}). It tracks current MockServer
* releases, derives its image tag from the client library so the two stay in lockstep, and adds
* configuration helpers (DNS, transparent proxy, HTTP/3, initialization JSON, log level, arbitrary
* properties) plus direct {@code MockServerClient} wiring.
*
* @see <a href="https://www.mock-server.com/mock_server/mockserver_testcontainers.html">MockServer Testcontainers module</a>
*/
@Slf4j
@Deprecated
public class MockServerContainer extends GenericContainer<MockServerContainer> {

private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("jamesdbloom/mockserver");
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("mockserver/mockserver");

private static final String DEFAULT_TAG = "mockserver-5.5.4";
// Keep this tag aligned with the mockserver-client-java version in build.gradle: the tests derive
// their image tag from that client jar, so the default here must track the same MockServer release.
private static final String DEFAULT_TAG = "mockserver-7.1.0";

@Deprecated
public static final String VERSION = DEFAULT_TAG;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static org.mockserver.model.HttpRequest.request;
import static org.mockserver.model.HttpResponse.response;

@SuppressWarnings("deprecation") // testing the deprecated bundled module
class MockServerContainerTest {

public static final DockerImageName MOCKSERVER_IMAGE = DockerImageName
Expand All @@ -34,7 +35,9 @@ void shouldCallActualMockserverVersion() {
try (MockServerClient client = new MockServerClient(mockServer.getHost(), mockServer.getServerPort())) {
assertThat(client.hasStarted()).as("Mockserver running").isTrue();

// testSimpleExpectation {
client.when(request().withPath("/hello")).respond(response().withBody(expectedBody));
// }

assertThat(given().when().get(mockServer.getEndpoint() + "/hello").then().extract().body().asString())
.as("MockServer returns correct result")
Expand Down