Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable WireMock banner in the CLI output by default #42

Merged
Show file tree
Hide file tree
Changes from 6 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
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
*/
package org.wiremock.integrations.testcontainers;

import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.containers.wait.strategy.WaitStrategy;
import org.testcontainers.images.builder.Transferable;
import org.testcontainers.shaded.com.google.common.io.Resources;
import org.testcontainers.utility.MountableFile;

import java.io.File;
import java.io.IOException;
import java.net.URL;
Expand All @@ -30,13 +37,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.containers.wait.strategy.WaitStrategy;
import org.testcontainers.images.builder.Transferable;
import org.testcontainers.shaded.com.google.common.io.Resources;
import org.testcontainers.utility.MountableFile;

/**
* Provisions WireMock standalone server as a container.
* Designed to follow the WireMock Docker image ({@code wiremock/wiremock}) structure and configuration,
Expand All @@ -50,19 +50,16 @@ public class WireMockContainer extends GenericContainer<WireMockContainer> {
private static final String FILES_DIR = "/home/wiremock/__files/";

private static final String EXTENSIONS_DIR = "/var/wiremock/extensions/";

private static final WaitStrategy DEFAULT_WAITER = Wait
.forHttp("/__admin/mappings")
.withMethod("GET")
.forStatusCode(200);

private static final int PORT = 8080;

private final StringBuilder wireMockArgs;

private final Map<String, Stub> mappingStubs = new HashMap<>();
private final Map<String, MountableFile> mappingFiles = new HashMap<>();
private final Map<String, Extension> extensions = new HashMap<>();
private boolean isBannerDisabled = true;

public WireMockContainer() {
this(DEFAULT_TAG);
Expand All @@ -77,7 +74,16 @@ public WireMockContainer(String image, String version) {
wireMockArgs = new StringBuilder();
setWaitStrategy(DEFAULT_WAITER);
}


/**
* Enables the banner when starting WireMock container.
* @return this instance
*/
public WireMockContainer withBanner() {
isBannerDisabled = false;
julian-michelmann marked this conversation as resolved.
Show resolved Hide resolved
return this;
}

/**
* Adds CLI argument to the WireMock call.
* @param arg Argument
Expand Down Expand Up @@ -223,6 +229,10 @@ protected void configure() {
wireMockArgs.append(String.join(",", extensionClassNames));
}

if (isBannerDisabled) {
this.withCliArg("--disable-banner");
}

// Add CLI arguments
withCommand(wireMockArgs.toString());
}
Expand All @@ -231,7 +241,7 @@ private static final class Stub {
final String name;
final String json;

public Stub (String name, String json) {
public Stub(String name, String json) {
this.name = name;
this.json = json;
}
Expand All @@ -246,5 +256,4 @@ public Extension(String id) {
this.id = id;
}
}

}
Original file line number Diff line number Diff line change
@@ -1,55 +1,59 @@
package org.wiremock.integrations.testcontainers;

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

import java.net.http.HttpResponse;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.Mockito;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.wiremock.integrations.testcontainers.testsupport.http.TestHttpClient;

import java.net.http.HttpResponse;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

@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<String> response = TestHttpClient.newInstance().get(url);

// then
assertThat(response.body())
.as("Wrong response body")
.contains("Hello, world!");
}

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

// when
HttpResponse<String> response = TestHttpClient.newInstance().get(url);

// then
assertThat(response.body())
.as("Wrong response body")
.contains("Hello, world!");
}
@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<String> response = TestHttpClient.newInstance().get(url);

// then
assertThat(response.body())
.as("Wrong response body")
.contains("Hello, world!");
}

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

// when
HttpResponse<String> response = TestHttpClient.newInstance().get(url);

// then
assertThat(response.body())
.as("Wrong response body")
.contains("Hello, world!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.wiremock.integrations.testcontainers;

import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

public class WireMockContainerUnitTest {

@Test
public void defaultBannerDisabled() {
WireMockContainer wireMockContainerSpy = Mockito.spy(new WireMockContainer("2.35.0"));

wireMockContainerSpy.configure();

verify(wireMockContainerSpy).withCliArg("--disable-banner");
}

@Test
public void enableBanner() {
WireMockContainer wireMockContainerSpy = Mockito.spy(new WireMockContainer("2.35.0")).withBanner();

wireMockContainerSpy.configure();

verify(wireMockContainerSpy, times(0)).withCliArg("--disable-banner");
}
}