Merge branch '4.0.x'

This commit is contained in:
Marcin Grzejszczak
2023-09-05 18:56:40 +02:00
4 changed files with 72 additions and 29 deletions

28
pom.xml
View File

@@ -548,6 +548,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.5.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -615,15 +616,6 @@
<repositories>
<repository>
<!-- TODO: We're adding it only because a dependency is using http instead of https -->
<id>maven-restlet</id>
<name>Maven Restlet</name>
<url>https://maven.restlet.org</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<!-- Rest Assured -->
<repository>
<id>sonatype-snapshots</id>
@@ -632,16 +624,6 @@
<enabled>true</enabled>
</snapshots>
</repository>
<!-- FIXME: 4.0 -->
<!-- Netflix -->
<!--<repository>
<id>netflix-snapshots</id>
<name>Netflix Snapshots</name>
<url>https://artifactory-oss.prod.netflix.net/artifactory/maven-oss-snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>-->
<repository>
<id>netflix-candidates</id>
<name>Netflix Candidates</name>
@@ -675,14 +657,6 @@
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>https://repo.spring.io/release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>

View File

@@ -32,7 +32,7 @@ import java.util.concurrent.ConcurrentHashMap;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.common.JsonException;
import com.github.tomakehurst.wiremock.common.Slf4jNotifier;
import com.github.tomakehurst.wiremock.common.Notifier;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import com.github.tomakehurst.wiremock.extension.Extension;
import com.github.tomakehurst.wiremock.security.ClientAuthenticator;
@@ -40,6 +40,8 @@ import com.github.tomakehurst.wiremock.security.NoClientAuthenticator;
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import wiremock.com.github.jknack.handlebars.Helper;
import org.springframework.cloud.contract.stubrunner.HttpServerStub;
@@ -274,6 +276,35 @@ public class WireMockHttpServerStub implements HttpServerStub {
WireMock.get(WireMock.urlEqualTo(url)).willReturn(WireMock.aResponse().withBody(body).withStatus(200)));
}
static class Slf4jNotifier implements Notifier {
private static final Logger log = LoggerFactory.getLogger("WireMock");
private final boolean verbose;
Slf4jNotifier(boolean verbose) {
this.verbose = verbose;
}
@Override
public void info(String message) {
if (verbose) {
log.info(message);
}
}
@Override
public void error(String message) {
log.error(message);
}
@Override
public void error(String message, Throwable t) {
log.error(message, t);
}
}
}
class PortAndMappings {

View File

@@ -24,13 +24,15 @@ import java.util.List;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.common.Slf4jNotifier;
import com.github.tomakehurst.wiremock.common.Notifier;
import com.github.tomakehurst.wiremock.core.Options;
import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer;
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
import jakarta.annotation.PostConstruct;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
@@ -321,6 +323,35 @@ public class WireMockConfiguration implements SmartLifecycle {
callback.run();
}
static class Slf4jNotifier implements Notifier {
private static final Logger log = LoggerFactory.getLogger("WireMock");
private final boolean verbose;
Slf4jNotifier(boolean verbose) {
this.verbose = verbose;
}
@Override
public void info(String message) {
if (verbose) {
log.info(message);
}
}
@Override
public void error(String message) {
log.error(message);
}
@Override
public void error(String message, Throwable t) {
log.error(message, t);
}
}
}
@ConfigurationProperties("wiremock")

View File

@@ -16,12 +16,14 @@
package org.springframework.cloud.contract.wiremock;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.system.OutputCaptureRule;
import org.springframework.test.context.junit4.SpringRunner;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
@@ -36,6 +38,9 @@ import static org.assertj.core.api.Assertions.assertThat;
@AutoConfigureWireMock(port = 26384)
public class AutoConfigureWireMockApplicationTests {
@Rule
public OutputCaptureRule output = new OutputCaptureRule();
@Autowired
private Service service;
@@ -47,6 +52,8 @@ public class AutoConfigureWireMockApplicationTests {
stubFor(get(urlEqualTo("/test"))
.willReturn(aResponse().withHeader("Content-Type", "text/plain").withBody("Hello World!")));
assertThat(this.service.go()).isEqualTo("Hello World!");
assertThat(this.output.getOut()).as("Must contain debug logging for WireMock")
.contains("Matched response definition:");
}
@Test