diff --git a/README.md b/README.md index dd7d2d8..882eab3 100644 --- a/README.md +++ b/README.md @@ -39,38 +39,32 @@ P.S: Javadoc is coming soon! #### Sample Code using JUnit 5 ```java -import static org.assertj.core.api.Assertions.assertThat; - -import java.net.http.*; -import java.time.Duration; -import org.junit.jupiter.api.Test; +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; @Testcontainers -public class WireMockContainerJUnit5Test { - - @Container - public WireMockContainer wiremockServer = new WireMockContainer("2.35.0") - .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"); - - @Test - public void helloWorld() throws Exception { - final HttpClient client = HttpClient.newBuilder().build(); - final HttpRequest request = HttpRequest.newBuilder() - .uri(URI.create(wiremockServer.getUrl("/hello"))) - .timeout(Duration.ofSeconds(10)) - .header("Content-Type", "application/json") - .GET().build(); - - HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); - - assertThat(response.body()) - .as("Wrong response body") - .contains("Hello, world!"); - } +class WireMockContainerJunit5Test { + + @Container + WireMockContainer wiremockServer = new WireMockContainer("2.35.0") + .withMapping("hello", WireMockContainerJunit5Test.class, "hello-world.json"); + + @Test + 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!"); + } } ``` @@ -82,31 +76,27 @@ Show Code ```java -import org.wiremock.integrations.testcontainers.WireMockContainer; import org.junit.*; -import java.net.URI; -import java.net.http.*; -import java.time.Duration; +import org.wiremock.integrations.testcontainers.testsupport.http.*; -public class WireMockContainerTest { +import static org.assertj.core.api.Assertions.assertThat; + +public class WireMockContainerJunit4Test { @Rule public WireMockContainer wiremockServer = new WireMockContainer("2.35.0") - .withMapping("hello", WireMockContainerTest.class, "hello-world.json"); + .withMapping("hello", WireMockContainerJunit4Test.class, "hello-world.json"); @Test public void helloWorld() throws Exception { - final HttpClient client = HttpClient.newBuilder().build(); - final HttpRequest request = HttpRequest.newBuilder() - .uri(URI.create(wiremockServer.getUrl("/hello"))) - .timeout(Duration.ofSeconds(10)) - .header("Content-Type", "application/json") - .GET().build(); + // given + String url = wiremockServer.getUrl("/hello"); - HttpResponse response = - client.send(request, HttpResponse.BodyHandlers.ofString()); + // when + HttpResponse response = new TestHttpClient().get(url); - assertThat(response.body()) + // then + assertThat(response.getBody()) .as("Wrong response body") .contains("Hello, world!"); } @@ -188,29 +178,38 @@ Test sample: ##### Sample code using JUnit 5 ```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 -public class WireMockContainerExtensionJUnit5Test { - - @Container - public WireMockContainer wiremockServer = new WireMockContainer("2.35.0") - .withMapping("json-body-transformer", WireMockContainerExtensionTest.class, "json-body-transformer.json") - .withExtension("JSON Body Transformer", Collections.singleton("com.ninecookies.wiremock.extensions.JsonBodyTransformer"), - Collections.singleton(Paths.get("target", "test-wiremock-extension", "9cookies-wiremock-extensions.jar").toFile())); - - @Test - public void testJSONBodyTransformer() throws Exception { - final HttpClient client = HttpClient.newBuilder().build(); - final HttpRequest request = HttpRequest.newBuilder() - .uri(URI.create(wiremockServer.getUrl("/json-body-transformer"))) - .timeout(Duration.ofSeconds(10)) - .header("Content-Type", "application/json") - .POST(HttpRequest.BodyPublishers.ofString("{\"name\":\"John Doe\"}")).build(); - - HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); - - assertThat(response.body()).as("Wrong response body") - .contains("Hello, John Doe!"); - } +class WireMockContainerExtensionJunit5Test { + + @Container + WireMockContainer wiremockServer = new WireMockContainer("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!"); + } } ``` @@ -222,26 +221,34 @@ 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 { -public class WireMockContainerExtensionTest { @Rule public WireMockContainer wiremockServer = new WireMockContainer("2.35.0") - .withMapping("json-body-transformer", WireMockContainerExtensionTest.class, "json-body-transformer.json") - .withExtension("JSON Body Transformer", Collections.singleton("com.ninecookies.wiremock.extensions.JsonBodyTransformer"), - Collections.singleton(Paths.get("target", "test-wiremock-extension", "9cookies-wiremock-extensions.jar").toFile())); + .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 { - final HttpClient client = HttpClient.newBuilder().build(); - final HttpRequest request = HttpRequest.newBuilder() - .uri(URI.create(wiremockServer.getUrl("/json-body-transformer"))) - .timeout(Duration.ofSeconds(10)) - .header("Content-Type", "application/json") - .POST(HttpRequest.BodyPublishers.ofString("{\"name\":\"John Doe\"}")).build(); + // given + String url = wiremockServer.getUrl("/json-body-transformer"); + String body = "{\"name\":\"John Doe\"}"; - HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); + // when + HttpResponse response = new TestHttpClient().post(url, body); - assertThat(response.body()).as("Wrong response body") + // then + assertThat(response.getBody()).as("Wrong response body") .contains("Hello, John Doe!"); } } diff --git a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerBannerTest.java b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerBannerTest.java new file mode 100644 index 0000000..9b14add --- /dev/null +++ b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerBannerTest.java @@ -0,0 +1,61 @@ +/* + * 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.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class WireMockContainerBannerTest { + + WireMockContainer wireMockContainer = new WireMockContainer("2.35.0"); + + @Test + void bannerIsByDefaultDisabled() { + // when + wireMockContainer.configure(); + + // then + assertThat(wireMockContainer.getCommandParts()) + .contains("--disable-banner"); + } + + @Test + void enableBanner() { + // given + wireMockContainer.withBanner(); + + // when + wireMockContainer.configure(); + + // then + assertThat(wireMockContainer.getCommandParts()) + .doesNotContain("--disable-banner"); + } + + @Test + void disableBanner() { + // given + wireMockContainer.withoutBanner(); + + // when + wireMockContainer.configure(); + + // then + assertThat(wireMockContainer.getCommandParts()) + .contains("--disable-banner"); + } +} diff --git a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerExtensionTest.java b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerExtensionTest.java index 977e17d..825fb8f 100644 --- a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerExtensionTest.java +++ b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerExtensionTest.java @@ -15,12 +15,12 @@ */ package org.wiremock.integrations.testcontainers; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +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,25 +34,22 @@ * Tests the WireMock extension loading. * It uses the external Jar supplied by the Maven Dependency Plugin. */ -public class WireMockContainerExtensionTest { +@Testcontainers +class WireMockContainerExtensionTest { - public static final Logger LOGGER = LoggerFactory.getLogger(WireMockContainerExtensionTest.class); + private static final Logger LOGGER = LoggerFactory.getLogger(WireMockContainerExtensionTest.class); - @Rule - public WireMockContainer wiremockServer = new WireMockContainer("2.35.0") + @Container + WireMockContainer wiremockServer = new WireMockContainer("2.35.0") + .withLogConsumer(new Slf4jLogConsumer(LOGGER)) .withStartupTimeout(Duration.ofSeconds(60)) .withMapping("json-body-transformer", WireMockContainerExtensionTest.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())); - @Before - public void before() { - wiremockServer.followOutput(new Slf4jLogConsumer(LOGGER)); - } - @Test - public void testJSONBodyTransformer() throws Exception { + void testJSONBodyTransformer() throws Exception { // given String url = wiremockServer.getUrl("/json-body-transformer"); String body = "{\"name\":\"John Doe\"}"; diff --git a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerExtensionsCombinationTest.java b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerExtensionsCombinationTest.java index 139b3a6..686487a 100644 --- a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerExtensionsCombinationTest.java +++ b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerExtensionsCombinationTest.java @@ -15,18 +15,17 @@ */ package org.wiremock.integrations.testcontainers; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +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; import java.nio.file.Paths; import java.util.Collections; -import java.util.concurrent.TimeUnit; import static org.assertj.core.api.Assertions.assertThat; @@ -34,12 +33,14 @@ * Tests the WireMock extension loading. * It uses multiple external Jars supplied by the Maven Dependency Plugin. */ -public class WireMockContainerExtensionsCombinationTest { +@Testcontainers +class WireMockContainerExtensionsCombinationTest { - public static final Logger LOGGER = LoggerFactory.getLogger(WireMockContainerExtensionsCombinationTest.class); + private static final Logger LOGGER = LoggerFactory.getLogger(WireMockContainerExtensionsCombinationTest.class); - @Rule - public WireMockContainer wiremockServer = new WireMockContainer("2.35.0") + @Container + WireMockContainer wiremockServer = new WireMockContainer("2.35.0") + .withLogConsumer(new Slf4jLogConsumer(LOGGER)) .withMapping("json-body-transformer", WireMockContainerExtensionsCombinationTest.class, "json-body-transformer.json") .withExtension("Webhook", Collections.singleton("org.wiremock.webhooks.Webhooks"), @@ -48,13 +49,8 @@ public 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())); - @Before - public void before() { - wiremockServer.followOutput(new Slf4jLogConsumer(LOGGER)); - } - @Test - public void testJSONBodyTransformer() throws Exception { + void testJSONBodyTransformer() throws Exception { // given String url = wiremockServer.getUrl("/json-body-transformer"); String body = "{\"name\":\"John Doe\"}"; diff --git a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerExtensionsWebhookTest.java b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerExtensionsWebhookTest.java index df87e5a..3b80727 100644 --- a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerExtensionsWebhookTest.java +++ b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerExtensionsWebhookTest.java @@ -15,13 +15,13 @@ */ package org.wiremock.integrations.testcontainers; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testcontainers.Testcontainers; 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; @@ -31,6 +31,7 @@ import java.util.Collections; import static org.assertj.core.api.Assertions.assertThat; +import static org.testcontainers.Testcontainers.exposeHostPorts; import static org.testcontainers.shaded.org.awaitility.Awaitility.await; /** @@ -39,22 +40,23 @@ *

* Use {@link GenericContainer#withAccessToHost(boolean)} to force the host access mechanism *

- * Use {@link Testcontainers#exposeHostPorts(int...)} to expose host machine ports to containers + * Use {@link org.testcontainers.Testcontainers#exposeHostPorts(int...)} to expose host machine ports to containers *

* Use {@link GenericContainer#INTERNAL_HOST_HOSTNAME} to calculate hostname for callback * * @see Testcontainers Networking */ -public class WireMockContainerExtensionsWebhookTest { +@Testcontainers +class WireMockContainerExtensionsWebhookTest { - public static final Logger LOGGER = LoggerFactory.getLogger(WireMockContainerExtensionsWebhookTest.class); - public static final String WIREMOCK_PATH = "/wiremock/callback-trigger"; - public static final String APPLICATION_PATH = "/application/callback-receiver"; + private static final Logger LOGGER = LoggerFactory.getLogger(WireMockContainerExtensionsWebhookTest.class); + private static final String WIREMOCK_PATH = "/wiremock/callback-trigger"; + private static final String APPLICATION_PATH = "/application/callback-receiver"; - public TestHttpServer applicationServer = TestHttpServer.newInstance(); - @Rule - public WireMockContainer wiremockServer = new WireMockContainer("2.35.0") + TestHttpServer applicationServer = TestHttpServer.newInstance(); + @Container + WireMockContainer wiremockServer = new WireMockContainer("2.35.0") .withLogConsumer(new Slf4jLogConsumer(LOGGER)) .withCliArg("--global-response-templating") .withMapping("webhook-callback-template", WireMockContainerExtensionsWebhookTest.class, "webhook-callback-template.json") @@ -65,9 +67,9 @@ public class WireMockContainerExtensionsWebhookTest { @Test - public void callbackUsingJsonStub() throws Exception { + void callbackUsingJsonStub() throws Exception { // given - Testcontainers.exposeHostPorts(applicationServer.getPort()); // Exposing host ports to the container + exposeHostPorts(applicationServer.getPort()); // Exposing host ports to the container String wiremockUrl = wiremockServer.getUrl(WIREMOCK_PATH); String applicationCallbackUrl = String.format("http://%s:%d%s", GenericContainer.INTERNAL_HOST_HOSTNAME, applicationServer.getPort(), APPLICATION_PATH); diff --git a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerJUnit5Test.java b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerJUnit5Test.java deleted file mode 100644 index 1149927..0000000 --- a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerJUnit5Test.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.wiremock.integrations.testcontainers; - -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 -public class WireMockContainerJUnit5Test { - - @Container - public WireMockContainer wiremockServer = new WireMockContainer("2.35.0") - .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"); - - - @ParameterizedTest - @ValueSource(strings = { - "hello", - "/hello" - }) - public void helloWorld(String path) throws Exception { - // given - String url = wiremockServer.getUrl(path); - - // 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!"); - } -} diff --git a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerJunit4Test.java b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerJunit4Test.java new file mode 100644 index 0000000..9672c06 --- /dev/null +++ b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerJunit4Test.java @@ -0,0 +1,74 @@ +/* + * 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 { + + @Rule + public WireMockContainer wiremockServer = new WireMockContainer("2.35.0") + .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"); + + @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!"); + } +} diff --git a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerTest.java b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerTest.java index b4d0bbc..32c5690 100644 --- a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerTest.java +++ b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerTest.java @@ -15,39 +15,35 @@ */ package org.wiremock.integrations.testcontainers; -import org.junit.Rule; -import org.junit.Test; +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; -public class WireMockContainerTest { +@Testcontainers(parallel = true) +class WireMockContainerTest { - @Rule - public WireMockContainer wiremockServer = new WireMockContainer("2.35.0") + @Container + WireMockContainer wiremockServer = new WireMockContainer("2.35.0") .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"); + .withFileFromResource("hello-world-resource-response.xml", WireMockContainerTest.class, + "hello-world-resource-response.xml"); - @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 { + @ParameterizedTest + @ValueSource(strings = { + "hello", + "/hello" + }) + void helloWorld(String path) throws Exception { // given - String url = wiremockServer.getUrl("hello"); + String url = wiremockServer.getUrl(path); // when HttpResponse response = new TestHttpClient().get(url); @@ -59,7 +55,7 @@ public void helloWorldWithoutLeadingSlashInPath() throws Exception { } @Test - public void helloWorldFromFile() throws Exception { + void helloWorldFromFile() throws Exception { // given String url = wiremockServer.getUrl("/hello-from-file"); diff --git a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerUnitTest.java b/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerUnitTest.java deleted file mode 100644 index 5efebd9..0000000 --- a/src/test/java/org/wiremock/integrations/testcontainers/WireMockContainerUnitTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.wiremock.integrations.testcontainers; - -import org.junit.jupiter.api.Test; - -import java.util.Arrays; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class WireMockContainerUnitTest { - - @Test - public void bannerIsByDefaultDisabled() { - WireMockContainer wireMockContainer = new WireMockContainer("2.35.0"); - wireMockContainer.configure(); - - String[] startUpArgs = wireMockContainer.getCommandParts(); - - assertTrue(Arrays.asList(startUpArgs).contains("--disable-banner")); - } - - @Test - public void enableBanner() { - WireMockContainer wireMockContainerSpy = new WireMockContainer("2.35.0") - .withBanner(); - wireMockContainerSpy.configure(); - - String[] startUpArgs = wireMockContainerSpy.getCommandParts(); - - assertFalse(Arrays.asList(startUpArgs).contains("--disable-banner")); - } - - @Test - public void disableBanner() { - WireMockContainer wireMockContainerSpy = new WireMockContainer("2.35.0") - .withBanner() - .withoutBanner(); - wireMockContainerSpy.configure(); - - String[] startUpArgs = wireMockContainerSpy.getCommandParts(); - - assertTrue(Arrays.asList(startUpArgs).contains("--disable-banner")); - } -}