Skip to content

Commit 78f7a42

Browse files
Merge pull request #235 from wiremock/testcontainers2
Update to Testcontainers 2.0.5, Gradle 8.14.4, Drop JUnit 4 support
2 parents 2765fae + da558b9 commit 78f7a42

16 files changed

Lines changed: 146 additions & 250 deletions

README.md

Lines changed: 26 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ A common example is using Wiremock 3.x with Java 1.8.
2121

2222
## Compatibility
2323

24+
### WireMock
25+
2426
The module is compatible with the following WireMock versions:
2527

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

35+
### Test Frameworks
36+
37+
Versions before `1.0-alpha-3` were tested with JUnit 4 and JUnit 5.
38+
Newer versions were updates to Testcontainers 2 and hence require JUnit 5.
39+
All JUnit 5 compatible test frameworks should work.
40+
41+
### Java
42+
43+
The module is compatible with Java 8 and above.s
44+
3345
## Usage
3446

3547
### Importing the dependency
@@ -109,15 +121,14 @@ JitPack / Gradle
109121

110122
</details>
111123

112-
### Using the test container in JUnit 4/5
124+
### Using the test container in JUnit 5
113125

114126
P.S: Javadoc is coming soon!
115127

116128
#### Sample Code using JUnit 5
117129

118130
```java
119131
import org.junit.jupiter.api.*;
120-
import org.testcontainers.junit.jupiter.*;
121132
import org.wiremock.integrations.testcontainers.testsupport.http.*;
122133

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

143+
@BeforeEach
144+
public void setup() {
145+
wiremockServer.start();
146+
assertThat(wiremockServer.isRunning()).isTrue();
147+
}
148+
132149
@Test
133150
void helloWorld() throws Exception {
134151
// given
@@ -145,41 +162,6 @@ class WireMockContainerJunit5Test {
145162
}
146163
```
147164

148-
#### Sample Code using JUnit 4
149-
150-
<details>
151-
<summary>
152-
Show Code
153-
</summary>
154-
155-
```java
156-
import org.junit.*;
157-
import org.wiremock.integrations.testcontainers.testsupport.http.*;
158-
159-
import static org.assertj.core.api.Assertions.assertThat;
160-
161-
public class WireMockContainerJunit4Test {
162-
163-
@Rule
164-
public WireMockContainer wiremockServer = new WireMockContainer("wiremock/wiremock:2.35.0")
165-
.withMapping("hello", WireMockContainerJunit4Test.class, "hello-world.json");
166-
167-
@Test
168-
public void helloWorld() throws Exception {
169-
// given
170-
String url = wiremockServer.getUrl("/hello");
171-
172-
// when
173-
HttpResponse response = new TestHttpClient().get(url);
174-
175-
// then
176-
assertThat(response.getBody())
177-
.as("Wrong response body")
178-
.contains("Hello, world!");
179-
}
180-
}
181-
```
182-
</details>
183165

184166
### Using WireMock extensions
185167

@@ -256,67 +238,29 @@ Test sample:
256238

257239
```java
258240
import org.junit.jupiter.api.*;
259-
import org.testcontainers.junit.jupiter.*;
260241
import org.wiremock.integrations.testcontainers.testsupport.http.*;
261242

262243
import java.nio.file.Paths;
263244
import java.util.Collections;
264245

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

267-
@Testcontainers
268248
class WireMockContainerExtensionJunit5Test {
269-
270-
@Container
249+
271250
WireMockContainer wiremockServer = new WireMockContainer("wiremock/wiremock:2.35.0")
272251
.withMapping("json-body-transformer", WireMockContainerExtensionJunit5Test.class, "json-body-transformer.json")
273252
.withExtension("JSON Body Transformer",
274253
Collections.singleton("com.ninecookies.wiremock.extensions.JsonBodyTransformer"),
275254
Collections.singleton(Paths.get("target", "test-wiremock-extension", "wiremock-extensions-0.4.1-jar-with-dependencies.jar").toFile()));
276255

277-
@Test
278-
void testJSONBodyTransformer() throws Exception {
279-
// given
280-
String url = wiremockServer.getUrl("/json-body-transformer");
281-
String body = "{\"name\":\"John Doe\"}";
282-
283-
// when
284-
HttpResponse response = new TestHttpClient().post(url, body);
285-
286-
// then
287-
assertThat(response.getBody()).as("Wrong response body")
288-
.contains("Hello, John Doe!");
256+
@BeforeEach
257+
public void setup() {
258+
wiremockServer.start();
259+
assertThat(wiremockServer.isRunning()).isTrue();
289260
}
290-
}
291-
```
292-
293-
##### Sample code using JUnit 4
294-
295-
<details>
296-
<summary>
297-
Show Code
298-
</summary>
299261

300-
```java
301-
import org.junit.*;
302-
import org.wiremock.integrations.testcontainers.testsupport.http.*;
303-
304-
import java.nio.file.Paths;
305-
import java.util.Collections;
306-
307-
import static org.assertj.core.api.Assertions.assertThat;
308-
309-
public class WireMockContainerExtensionJunit4Test {
310-
311-
@Rule
312-
public WireMockContainer wiremockServer = new WireMockContainer("wiremock/wiremock:2.35.0")
313-
.withMapping("json-body-transformer", WireMockContainerExtensionJunit4Test.class, "json-body-transformer.json")
314-
.withExtension("JSON Body Transformer",
315-
Collections.singleton("com.ninecookies.wiremock.extensions.JsonBodyTransformer"),
316-
Collections.singleton(Paths.get("target", "test-wiremock-extension", "wiremock-extensions-0.4.1-jar-with-dependencies.jar").toFile()));
317-
318262
@Test
319-
public void testJSONBodyTransformer() throws Exception {
263+
void testJSONBodyTransformer() throws Exception {
320264
// given
321265
String url = wiremockServer.getUrl("/json-body-transformer");
322266
String body = "{\"name\":\"John Doe\"}";
@@ -329,8 +273,7 @@ public class WireMockContainerExtensionJunit4Test {
329273
.contains("Hello, John Doe!");
330274
}
331275
}
332-
```
333-
</details>
276+
```
334277

335278
## Contributing
336279

build.gradle.kts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66

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

1111
java {
1212
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -15,7 +15,7 @@ java {
1515
withJavadocJar()
1616
}
1717

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

3939
testImplementation(platform("org.junit:junit-bom:$junitVersion"))
40-
testImplementation("org.testcontainers:junit-jupiter")
4140
testImplementation("org.junit.jupiter:junit-jupiter-params")
4241
testImplementation("org.junit.jupiter:junit-jupiter-engine")
4342
testImplementation("org.junit.vintage:junit-vintage-engine")

gradle/wrapper/gradle-wrapper.jar

-16.6 KB
Binary file not shown.
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#Sat Apr 05 15:01:27 CEST 2025
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.4-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
56
zipStoreBase=GRADLE_USER_HOME
67
zipStorePath=wrapper/dists

gradlew

Lines changed: 32 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)