diff --git a/README.md b/README.md index bf19214..548ef9e 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -109,7 +121,7 @@ JitPack / Gradle -### Using the test container in JUnit 4/5 +### Using the test container in JUnit 5 P.S: Javadoc is coming soon! @@ -117,7 +129,6 @@ P.S: Javadoc is coming soon! ```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; @@ -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 @@ -145,41 +162,6 @@ class WireMockContainerJunit5Test { } ``` -#### Sample Code using JUnit 4 - -
- -Show Code - - -```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!"); - } -} -``` -
### Using WireMock extensions @@ -256,7 +238,6 @@ 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; @@ -264,59 +245,22 @@ 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 - -
- -Show Code - -```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\"}"; @@ -329,8 +273,7 @@ public class WireMockContainerExtensionJunit4Test { .contains("Hello, John Doe!"); } } -``` -
+``` ## Contributing diff --git a/build.gradle.kts b/build.gradle.kts index 2c75a3c..ab031b7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 @@ -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" @@ -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") diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 249e583..1b33c55 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e79257a..aaaabb3 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/gradlew b/gradlew index 1b6c787..23d15a9 100755 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +82,11 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -114,7 +114,7 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar +CLASSPATH="\\\"\\\"" # Determine the Java command to use to start the JVM. @@ -133,22 +133,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,18 +200,28 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index ac1b06f..5eed7ee 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,8 +13,10 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +27,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,13 +43,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -56,32 +59,34 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar +set CLASSPATH= @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/pom.xml b/pom.xml index 6838d97..39608b4 100644 --- a/pom.xml +++ b/pom.xml @@ -33,9 +33,7 @@ ${java.version} ${java.version} 3.5.4 - 1.21.3 - 5.13.1 - 3.27.6 + 2.0.5 5.13.4 3.27.6 4.3.0 @@ -79,11 +77,6 @@ org.testcontainers testcontainers - - org.testcontainers - junit-jupiter - test - org.junit.jupiter junit-jupiter-engine diff --git a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerExtensionTest.java b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerExtensionTest.java index 7a6e4e4..f6595a1 100644 --- a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerExtensionTest.java +++ b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerExtensionTest.java @@ -15,12 +15,11 @@ */ package org.wiremock.integrations.testcontainers; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testcontainers.containers.output.Slf4jLogConsumer; -import org.testcontainers.junit.jupiter.Container; -import org.testcontainers.junit.jupiter.Testcontainers; import org.wiremock.integrations.testcontainers.testsupport.http.HttpResponse; import org.wiremock.integrations.testcontainers.testsupport.http.TestHttpClient; @@ -34,12 +33,10 @@ * Tests the WireMock extension loading. * It uses the external Jar supplied by the Maven Dependency Plugin. */ -@Testcontainers class WireMockContainerExtensionTest { private static final Logger LOGGER = LoggerFactory.getLogger(WireMockContainerExtensionTest.class); - @Container WireMockContainer wiremockServer = new WireMockContainer(TestConfig.WIREMOCK_DEFAULT_IMAGE) .withLogConsumer(new Slf4jLogConsumer(LOGGER)) .withStartupTimeout(Duration.ofSeconds(60)) @@ -48,6 +45,12 @@ class WireMockContainerExtensionTest { 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())); + @BeforeEach + public void setup() { + wiremockServer.start(); + assertThat(wiremockServer.isRunning()).isTrue(); + } + @Test void testJSONBodyTransformer() throws Exception { // given diff --git a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerExtensionsCombinationTest.java b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerExtensionsCombinationTest.java index e11e236..3bba2b8 100644 --- a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerExtensionsCombinationTest.java +++ b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerExtensionsCombinationTest.java @@ -15,12 +15,11 @@ */ package org.wiremock.integrations.testcontainers; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testcontainers.containers.output.Slf4jLogConsumer; -import org.testcontainers.junit.jupiter.Container; -import org.testcontainers.junit.jupiter.Testcontainers; import org.wiremock.integrations.testcontainers.testsupport.http.HttpResponse; import org.wiremock.integrations.testcontainers.testsupport.http.TestHttpClient; @@ -33,12 +32,10 @@ * Tests the WireMock extension loading. * It uses multiple external Jars supplied by the Maven Dependency Plugin. */ -@Testcontainers class WireMockContainerExtensionsCombinationTest { private static final Logger LOGGER = LoggerFactory.getLogger(WireMockContainerExtensionsCombinationTest.class); - @Container WireMockContainer wiremockServer = new WireMockContainer(TestConfig.WIREMOCK_DEFAULT_IMAGE) .withLogConsumer(new Slf4jLogConsumer(LOGGER)) .withMapping("json-body-transformer", WireMockContainerExtensionsCombinationTest.class, "json-body-transformer.json") @@ -49,6 +46,12 @@ class WireMockContainerExtensionsCombinationTest { 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())); + @BeforeEach + public void setup() { + wiremockServer.start(); + assertThat(wiremockServer.isRunning()).isTrue(); + } + @Test void testJSONBodyTransformer() throws Exception { // given diff --git a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerJunit4Test.java b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerJunit4Test.java deleted file mode 100644 index 292a3ca..0000000 --- a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerJunit4Test.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2023 WireMock Inc, Oleg Nenashev and all project contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.wiremock.integrations.testcontainers; - -import org.junit.Rule; -import org.junit.Test; -import org.wiremock.integrations.testcontainers.testsupport.http.HttpResponse; -import org.wiremock.integrations.testcontainers.testsupport.http.TestHttpClient; - -import static org.assertj.core.api.Assertions.assertThat; - -public class WireMockContainerJunit4Test { - - private static final int WIREMOCK_DEFAULT_PORT = 8080; - private static final int ADDITIONAL_MAPPED_PORT = 8443; - - @Rule - public WireMockContainer wiremockServer = new WireMockContainer(TestConfig.WIREMOCK_DEFAULT_IMAGE) - .withMapping("hello", WireMockContainerTest.class, "hello-world.json") - .withMapping("hello-resource", WireMockContainerTest.class, "hello-world-resource.json") - .withFileFromResource("hello-world-resource-response.xml", WireMockContainerTest.class, "hello-world-resource-response.xml") - .withExposedPorts(ADDITIONAL_MAPPED_PORT); - - @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!"); - } - - @Test - public void helloWorldWithoutLeadingSlashInPath() 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!"); - } - - @Test - public void helloWorldFromFile() throws Exception { - // given - String url = wiremockServer.getUrl("/hello-from-file"); - - // when - HttpResponse response = new TestHttpClient().get(url); - - // then - assertThat(response.getBody()) - .as("Wrong response body") - .contains("Hello, world!"); - } - - @Test - public void customPortsAreExposed() { - //given - - //when - - //then - assertThat(wiremockServer.getExposedPorts()) - .contains(WIREMOCK_DEFAULT_PORT, ADDITIONAL_MAPPED_PORT); - } -} diff --git a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerRootDirTest.java b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerRootDirTest.java index b66b044..c4820ec 100644 --- a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerRootDirTest.java +++ b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerRootDirTest.java @@ -15,9 +15,8 @@ */ package org.wiremock.integrations.testcontainers; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.testcontainers.junit.jupiter.Container; -import org.testcontainers.junit.jupiter.Testcontainers; import org.wiremock.integrations.testcontainers.testsupport.http.HttpResponse; import org.wiremock.integrations.testcontainers.testsupport.http.TestHttpClient; @@ -25,14 +24,19 @@ import static org.assertj.core.api.Assertions.assertThat; -@Testcontainers(parallel = true) class WireMockContainerRootDirTest { - @Container + WireMockContainer wiremockServer = new WireMockContainer(TestConfig.WIREMOCK_DEFAULT_IMAGE) .withMapping("hello", WireMockContainerRootDirTest.class, "hello.json") .withFileFromResource("file.json", WireMockContainerRootDirTest.class, "file.json") .withRootDir(new File("src/test/resources/root-dir")); + @BeforeEach + public void setup() { + wiremockServer.start(); + assertThat(wiremockServer.isRunning()).isTrue(); + } + @Test void testThatLoadsMappingFromRootDirectory() throws Exception { // given diff --git a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerTest.java b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerTest.java index 9a636b8..a997315 100644 --- a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerTest.java +++ b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerTest.java @@ -15,23 +15,20 @@ */ package org.wiremock.integrations.testcontainers; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import org.testcontainers.junit.jupiter.Container; -import org.testcontainers.junit.jupiter.Testcontainers; import org.wiremock.integrations.testcontainers.testsupport.http.HttpResponse; import org.wiremock.integrations.testcontainers.testsupport.http.TestHttpClient; import static org.assertj.core.api.Assertions.assertThat; -@Testcontainers(parallel = true) class WireMockContainerTest { private static final int WIREMOCK_DEFAULT_PORT = 8080; private static final int ADDITIONAL_MAPPED_PORT = 8443; - @Container WireMockContainer wiremockServer = new WireMockContainer(TestConfig.WIREMOCK_DEFAULT_IMAGE) .withMapping("hello", WireMockContainerTest.class, "hello-world.json") .withMapping("hello-resource", WireMockContainerTest.class, "hello-world-resource.json") @@ -40,6 +37,12 @@ class WireMockContainerTest { .withExposedPorts(ADDITIONAL_MAPPED_PORT); + @BeforeEach + public void setup() { + wiremockServer.start(); + assertThat(wiremockServer.isRunning()).isTrue(); + } + @ParameterizedTest @ValueSource(strings = { "hello", @@ -74,6 +77,7 @@ void helloWorldFromFile() throws Exception { @Test void customPortsAreExposed() { + //given //when diff --git a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerWebhooksTest.java b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerWebhooksTest.java index a39b665..4b531ea 100644 --- a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerWebhooksTest.java +++ b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerWebhooksTest.java @@ -15,13 +15,12 @@ */ package org.wiremock.integrations.testcontainers; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.output.Slf4jLogConsumer; -import org.testcontainers.junit.jupiter.Container; -import org.testcontainers.junit.jupiter.Testcontainers; import org.wiremock.integrations.testcontainers.testsupport.http.HttpResponse; import org.wiremock.integrations.testcontainers.testsupport.http.TestHttpClient; import org.wiremock.integrations.testcontainers.testsupport.http.TestHttpServer; @@ -46,7 +45,6 @@ * * @see Testcontainers Networking */ -@Testcontainers class WireMockContainerWebhooksTest { private static final Logger LOGGER = LoggerFactory.getLogger(WireMockContainerWebhooksTest.class); @@ -55,13 +53,18 @@ class WireMockContainerWebhooksTest { TestHttpServer applicationServer = TestHttpServer.newInstance(); - @Container WireMockContainer wiremockServer = new WireMockContainer(TestConfig.WIREMOCK_DEFAULT_IMAGE) .withLogConsumer(new Slf4jLogConsumer(LOGGER)) .withCliArg("--global-response-templating") .withMapping("webhook-callback-template", WireMockContainerWebhooksTest.class, "webhook-callback-template.json") .withAccessToHost(true); // Force the host access mechanism + @BeforeEach + public void setup() { + wiremockServer.start(); + assertThat(wiremockServer.isRunning()).isTrue(); + } + @Test void callbackUsingJsonStub() throws Exception { // given diff --git a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerWithWireMockVersionThreeTest.java b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerWithWireMockVersionThreeTest.java index 3d1710b..78f3778 100644 --- a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerWithWireMockVersionThreeTest.java +++ b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerWithWireMockVersionThreeTest.java @@ -1,24 +1,27 @@ package org.wiremock.integrations.testcontainers; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import org.testcontainers.junit.jupiter.Container; -import org.testcontainers.junit.jupiter.Testcontainers; import org.wiremock.integrations.testcontainers.testsupport.http.HttpResponse; import org.wiremock.integrations.testcontainers.testsupport.http.TestHttpClient; import static org.assertj.core.api.Assertions.assertThat; -@Testcontainers public class WireMockContainerWithWireMockVersionThreeTest { - @Container + WireMockContainer wiremockServer = new WireMockContainer("wiremock/wiremock:" + WireMockContainer.WIREMOCK_HEALTH_CHECK_SUPPORT_MINIMUM_VERSION) .withMapping("hello", WireMockContainerTest.class, "hello-world.json") .withMapping("hello-resource", WireMockContainerTest.class, "hello-world-resource.json") .withFileFromResource("hello-world-resource-response.xml", WireMockContainerTest.class, "hello-world-resource-response.xml"); + @BeforeEach + public void setup() { + wiremockServer.start(); + assertThat(wiremockServer.isRunning()).isTrue(); + } @ParameterizedTest @ValueSource(strings = { diff --git a/src/test/java/org/wiremock/integrations/testcontainers/wiremock2/WebhooksExtensionTest.java b/src/test/java/org/wiremock/integrations/testcontainers/wiremock2/WebhooksExtensionTest.java index eb047b6..bf1ab27 100644 --- a/src/test/java/org/wiremock/integrations/testcontainers/wiremock2/WebhooksExtensionTest.java +++ b/src/test/java/org/wiremock/integrations/testcontainers/wiremock2/WebhooksExtensionTest.java @@ -22,13 +22,13 @@ import java.nio.file.Paths; import java.time.Duration; import java.util.Collections; + +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.output.Slf4jLogConsumer; -import org.testcontainers.junit.jupiter.Container; -import org.testcontainers.junit.jupiter.Testcontainers; import org.wiremock.integrations.testcontainers.TestConfig; import org.wiremock.integrations.testcontainers.WireMockContainer; import org.wiremock.integrations.testcontainers.testsupport.http.HttpResponse; @@ -47,7 +47,6 @@ * * @see Testcontainers Networking */ -@Testcontainers class WebhooksExtensionTest { private static final Logger LOGGER = LoggerFactory.getLogger(WebhooksExtensionTest.class); @@ -56,7 +55,6 @@ class WebhooksExtensionTest { TestHttpServer applicationServer = TestHttpServer.newInstance(); - @Container WireMockContainer wiremockServer = new WireMockContainer(TestConfig.WIREMOCK_2_IMAGE) .withLogConsumer(new Slf4jLogConsumer(LOGGER)) .withCliArg("--global-response-templating") @@ -66,6 +64,12 @@ class WebhooksExtensionTest { Collections.singleton(Paths.get("target", "test-wiremock-extension", "wiremock-webhooks-extension-2.35.0.jar").toFile())) .withAccessToHost(true); // Force the host access mechanism + @BeforeEach + public void setup() { + wiremockServer.start(); + assertThat(wiremockServer.isRunning()).isTrue(); + } + @Test void callbackUsingJsonStub() throws Exception { // given diff --git a/src/test/java/org/wiremock/integrations/testcontainers/wiremock2/WireMockContainerExtensionsCombinationTest.java b/src/test/java/org/wiremock/integrations/testcontainers/wiremock2/WireMockContainerExtensionsCombinationTest.java index 1bc30ca..ea8804a 100644 --- a/src/test/java/org/wiremock/integrations/testcontainers/wiremock2/WireMockContainerExtensionsCombinationTest.java +++ b/src/test/java/org/wiremock/integrations/testcontainers/wiremock2/WireMockContainerExtensionsCombinationTest.java @@ -15,12 +15,11 @@ */ package org.wiremock.integrations.testcontainers.wiremock2; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testcontainers.containers.output.Slf4jLogConsumer; -import org.testcontainers.junit.jupiter.Container; -import org.testcontainers.junit.jupiter.Testcontainers; import org.wiremock.integrations.testcontainers.TestConfig; import org.wiremock.integrations.testcontainers.WireMockContainer; import org.wiremock.integrations.testcontainers.testsupport.http.HttpResponse; @@ -35,12 +34,10 @@ * Tests the WireMock extension loading. * It uses multiple external Jars supplied by the Maven Dependency Plugin. */ -@Testcontainers class WireMockContainerExtensionsCombinationTest { private static final Logger LOGGER = LoggerFactory.getLogger(WireMockContainerExtensionsCombinationTest.class); - @Container WireMockContainer wiremockServer = new WireMockContainer(TestConfig.WIREMOCK_2_IMAGE) .withLogConsumer(new Slf4jLogConsumer(LOGGER)) .withMapping("json-body-transformer", WireMockContainerExtensionsCombinationTest.class, "json-body-transformer.json") @@ -51,6 +48,12 @@ class WireMockContainerExtensionsCombinationTest { 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())); + @BeforeEach + public void setup() { + wiremockServer.start(); + assertThat(wiremockServer.isRunning()).isTrue(); + } + @Test void testJSONBodyTransformer() throws Exception { // given