@@ -21,6 +21,8 @@ A common example is using Wiremock 3.x with Java 1.8.
2121
2222## Compatibility
2323
24+ ### WireMock
25+
2426The 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:
3032Other WireMock implementations may work but have not been tested yet.
3133Please 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
114126P.S: Javadoc is coming soon!
115127
116128#### Sample Code using JUnit 5
117129
118130``` java
119131import org.junit.jupiter.api.* ;
120- import org.testcontainers.junit.jupiter.* ;
121132import org.wiremock.integrations.testcontainers.testsupport.http.* ;
122133
123134import 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
258240import org.junit.jupiter.api.* ;
259- import org.testcontainers.junit.jupiter.* ;
260241import org.wiremock.integrations.testcontainers.testsupport.http.* ;
261242
262243import java.nio.file.Paths ;
263244import java.util.Collections ;
264245
265246import static org.assertj.core.api.Assertions.assertThat ;
266247
267- @Testcontainers
268248class 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
0 commit comments