Skip to content
Merged
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
109 changes: 26 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ A common example is using Wiremock 3.x with Java 1.8.

## Compatibility

### WireMock

The module is compatible with the following WireMock versions:

- WireMock (aka WireMock Java) `2.0.0` and above
Expand All @@ -30,6 +32,16 @@ The module is compatible with the following WireMock versions:
Other WireMock implementations may work but have not been tested yet.
Please feel free to contribute the integration tests and compatibility layers!

### Test Frameworks

Versions before `1.0-alpha-3` were tested with JUnit 4 and JUnit 5.
Newer versions were updates to Testcontainers 2 and hence require JUnit 5.
All JUnit 5 compatible test frameworks should work.

### Java

The module is compatible with Java 8 and above.s

## Usage

### Importing the dependency
Expand Down Expand Up @@ -109,15 +121,14 @@ JitPack / Gradle

</details>

### Using the test container in JUnit 4/5
### Using the test container in JUnit 5

P.S: Javadoc is coming soon!

#### Sample Code using JUnit 5

```java
import org.junit.jupiter.api.*;
import org.testcontainers.junit.jupiter.*;
import org.wiremock.integrations.testcontainers.testsupport.http.*;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -129,6 +140,12 @@ class WireMockContainerJunit5Test {
WireMockContainer wiremockServer = new WireMockContainer("wiremock/wiremock:2.35.0")
.withMapping("hello", WireMockContainerJunit5Test.class, "hello-world.json");

@BeforeEach
public void setup() {
wiremockServer.start();
assertThat(wiremockServer.isRunning()).isTrue();
}

@Test
void helloWorld() throws Exception {
// given
Expand All @@ -145,41 +162,6 @@ class WireMockContainerJunit5Test {
}
```

#### Sample Code using JUnit 4

<details>
<summary>
Show Code
</summary>

```java
import org.junit.*;
import org.wiremock.integrations.testcontainers.testsupport.http.*;

import static org.assertj.core.api.Assertions.assertThat;

public class WireMockContainerJunit4Test {

@Rule
public WireMockContainer wiremockServer = new WireMockContainer("wiremock/wiremock:2.35.0")
.withMapping("hello", WireMockContainerJunit4Test.class, "hello-world.json");

@Test
public void helloWorld() throws Exception {
// given
String url = wiremockServer.getUrl("/hello");

// when
HttpResponse response = new TestHttpClient().get(url);

// then
assertThat(response.getBody())
.as("Wrong response body")
.contains("Hello, world!");
}
}
```
</details>

### Using WireMock extensions

Expand Down Expand Up @@ -256,67 +238,29 @@ Test sample:

```java
import org.junit.jupiter.api.*;
import org.testcontainers.junit.jupiter.*;
import org.wiremock.integrations.testcontainers.testsupport.http.*;

import java.nio.file.Paths;
import java.util.Collections;

import static org.assertj.core.api.Assertions.assertThat;

@Testcontainers
class WireMockContainerExtensionJunit5Test {

@Container

WireMockContainer wiremockServer = new WireMockContainer("wiremock/wiremock:2.35.0")
.withMapping("json-body-transformer", WireMockContainerExtensionJunit5Test.class, "json-body-transformer.json")
.withExtension("JSON Body Transformer",
Collections.singleton("com.ninecookies.wiremock.extensions.JsonBodyTransformer"),
Collections.singleton(Paths.get("target", "test-wiremock-extension", "wiremock-extensions-0.4.1-jar-with-dependencies.jar").toFile()));

@Test
void testJSONBodyTransformer() throws Exception {
// given
String url = wiremockServer.getUrl("/json-body-transformer");
String body = "{\"name\":\"John Doe\"}";

// when
HttpResponse response = new TestHttpClient().post(url, body);

// then
assertThat(response.getBody()).as("Wrong response body")
.contains("Hello, John Doe!");
@BeforeEach
public void setup() {
wiremockServer.start();
assertThat(wiremockServer.isRunning()).isTrue();
}
}
```

##### Sample code using JUnit 4

<details>
<summary>
Show Code
</summary>

```java
import org.junit.*;
import org.wiremock.integrations.testcontainers.testsupport.http.*;

import java.nio.file.Paths;
import java.util.Collections;

import static org.assertj.core.api.Assertions.assertThat;

public class WireMockContainerExtensionJunit4Test {

@Rule
public WireMockContainer wiremockServer = new WireMockContainer("wiremock/wiremock:2.35.0")
.withMapping("json-body-transformer", WireMockContainerExtensionJunit4Test.class, "json-body-transformer.json")
.withExtension("JSON Body Transformer",
Collections.singleton("com.ninecookies.wiremock.extensions.JsonBodyTransformer"),
Collections.singleton(Paths.get("target", "test-wiremock-extension", "wiremock-extensions-0.4.1-jar-with-dependencies.jar").toFile()));

@Test
public void testJSONBodyTransformer() throws Exception {
void testJSONBodyTransformer() throws Exception {
// given
String url = wiremockServer.getUrl("/json-body-transformer");
String body = "{\"name\":\"John Doe\"}";
Expand All @@ -329,8 +273,7 @@ public class WireMockContainerExtensionJunit4Test {
.contains("Hello, John Doe!");
}
}
```
</details>
```

## Contributing

Expand Down
5 changes: 2 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {

description = "This Testcontainers module allows provisioning the WireMock server as a standalone container within your unit tests, based on WireMock Docker"
group = "org.wiremock.integrations.testcontainers"
version = "1.0-alpha-12-SNAPSHOT"
version = "1.0-alpha-13-SNAPSHOT"

java {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -15,7 +15,7 @@ java {
withJavadocJar()
}

val testcontainersVersion = "1.20.6"
val testcontainersVersion = "2.0.5"
val junitVersion = "5.12.1"
val assertjVersion = "3.26.3"
val awaitilityVersion = "4.2.2"
Expand All @@ -37,7 +37,6 @@ dependencies {
compileOnly("ch.qos.logback:logback-classic:${logbackClassicVersion}")

testImplementation(platform("org.junit:junit-bom:$junitVersion"))
testImplementation("org.testcontainers:junit-jupiter")
testImplementation("org.junit.jupiter:junit-jupiter-params")
testImplementation("org.junit.jupiter:junit-jupiter-engine")
testImplementation("org.junit.vintage:junit-vintage-engine")
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Sat Apr 05 15:01:27 CEST 2025
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
47 changes: 32 additions & 15 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading