Bumped WireMock to 2.7.1 and added debug option for WireMock

fixes #374 #369
This commit is contained in:
Marcin Grzejszczak
2017-07-31 16:09:35 +02:00
parent 5a37733878
commit b431f1b788
14 changed files with 73 additions and 13 deletions

View File

@@ -868,6 +868,20 @@ The generated tests all boil down to RestAssured in some form or fashion which r
logging.level.org.apache.http.wire=DEBUG
----
==== How can I debug the mapping/request/response being sent by WireMock?
Starting from version `1.2.0` we turn on WireMock logging to
info and the WireMock notifier to being verbose. Now you will
exactly know what request was received by WireMock server and which
matching response definition was picked.
To turn off this feature just bump WireMock logging to `ERROR`
[source,properties,indent=0]
----
logging.level.com.github.tomakehurst.wiremock=ERROR
----
==== How can I see what got registered in the HTTP server stub?
You can use the `mappingsOutputFolder` property on `@AutoConfigureStubRunner` or `StubRunnerRule`

View File

@@ -14,7 +14,7 @@
<name>spring-cloud-contract-dependencies</name>
<description>Spring Cloud Contract Dependencies</description>
<properties>
<wiremock.version>2.6.0</wiremock.version>
<wiremock.version>2.7.1</wiremock.version>
<jsonassert.version>0.4.9</jsonassert.version>
<aether.version>1.0.2.v20150114</aether.version>
</properties>

View File

@@ -12,6 +12,7 @@ import java.util.Map;
import com.github.jknack.handlebars.Helper;
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.core.WireMockConfiguration;
import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer;
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
@@ -84,7 +85,8 @@ public class WireMockHttpServerStub implements HttpServerStub {
@Override
public HttpServerStub start(int port) {
this.wireMockServer = new WireMockServer(config().port(port));
this.wireMockServer = new WireMockServer(config().port(port)
.notifier(new Slf4jNotifier(true)));
this.wireMockServer.start();
return this;
}

View File

@@ -18,12 +18,18 @@ package org.springframework.cloud.contract.stubrunner.provider.wiremock
import com.github.tomakehurst.wiremock.http.RequestMethod
import com.github.tomakehurst.wiremock.stubbing.StubMapping
import org.junit.Rule
import spock.lang.Specification
import org.springframework.boot.test.rule.OutputCapture
import org.springframework.boot.test.web.client.TestRestTemplate
class WireMockHttpServerStubSpec extends Specification {
public static
final File MAPPING_DESCRIPTOR = new File('src/test/resources/repository/mappings/spring/cloud/ping/ping.json')
@Rule OutputCapture capture = new OutputCapture()
def 'should describe stub mapping'() {
given:
WireMockHttpServerStub mappingDescriptor = new WireMockHttpServerStub().start() as WireMockHttpServerStub
@@ -39,5 +45,26 @@ class WireMockHttpServerStubSpec extends Specification {
assert response.body == 'pong'
assert response.headers.contentTypeHeader.mimeTypePart() == 'text/plain'
}
cleanup:
mappingDescriptor.stop()
}
def 'should make WireMock print out logs on INFO'() {
given:
WireMockHttpServerStub mappingDescriptor = new WireMockHttpServerStub().start() as WireMockHttpServerStub
mappingDescriptor.registerMappings([
new File(WireMockHttpServerStubSpec.classLoader.getResource("simple.json").toURI())
])
when:
String response = new TestRestTemplate().getForObject("http://localhost:${mappingDescriptor.port()}/foobar", String)
then:
response == "foo"
capture.toString().contains("Matched response definition")
cleanup:
mappingDescriptor.stop()
}
}

View File

@@ -0,0 +1,13 @@
{
"id" : "77514bd4-a102-4478-a3c0-0fda8b905591",
"request" : {
"method" : "GET",
"url": "/foobar"
},
"response" : {
"status" : 200,
"body" : "foo",
"transformers": ["response-template"]
},
"uuid" : "77514bd4-a102-4478-a3c0-0fda8b905591"
}

View File

@@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
wiremockVersion=2.6.0
wiremockVersion=2.7.1
jsonAssertVersion=0.4.8
verifierVersion=1.2.0.BUILD-SNAPSHOT

View File

@@ -83,7 +83,7 @@ configure([project(':fraudDetectionService'), project(':loanApplicationService')
testCompile "org.mockito:mockito-core"
testCompile "org.springframework:spring-test"
testCompile "org.springframework.boot:spring-boot-test"
testCompile("com.github.tomakehurst:wiremock:2.6.0") {
testCompile("com.github.tomakehurst:wiremock:2.7.1") {
exclude group: 'org.eclipse.jetty'
}
}

View File

@@ -13,6 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
wiremockVersion=2.6.0
wiremockVersion=2.7.1
jsonAssertVersion=0.4.8
verifierVersion=1.2.0.BUILD-SNAPSHOT

View File

@@ -13,6 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
wiremockVersion=2.6.0
wiremockVersion=2.7.1
jsonAssertVersion=0.4.8
verifierVersion=1.2.0.BUILD-SNAPSHOT

View File

@@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
wiremockVersion=2.6.0
wiremockVersion=2.7.1
jsonAssertVersion=0.4.8
verifierVersion=1.2.0.BUILD-SNAPSHOT

View File

@@ -47,12 +47,12 @@ class WireMockStubMappingSpec extends Specification {
WireMockStubMapping.buildFrom(stub_2_1_7)
}
def "should successfully parse a WireMock 2.6.0 stub"() {
def "should successfully parse a WireMock 2.5.0 stub"() {
expect:
WireMockStubMapping.buildFrom(stub_2_5_1)
}
def "should successfully parse a WireMock 2.6.0 stub that contains transformers"() {
def "should successfully parse a WireMock 2.5.0 stub that contains transformers"() {
expect:
WireMockStubMapping.buildFrom(stub_2_5_1_with_transformer)
}

View File

@@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import com.github.tomakehurst.wiremock.common.Slf4jNotifier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -81,6 +82,7 @@ public class WireMockConfiguration implements SmartLifecycle {
factory.httpsPort(this.wireMock.getHttpsPort());
}
registerFiles(factory);
factory.notifier(new Slf4jNotifier(true));
this.options = factory;
}
this.server = new WireMockServer(this.options);

View File

@@ -25,6 +25,7 @@ import java.util.Comparator;
import java.util.List;
import javax.xml.xpath.XPathExpressionException;
import com.github.tomakehurst.wiremock.matching.ContentPattern;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.MatcherAssert;
@@ -55,7 +56,6 @@ import com.github.tomakehurst.wiremock.matching.MatchesJsonPathPattern;
import com.github.tomakehurst.wiremock.matching.MatchesXPathPattern;
import com.github.tomakehurst.wiremock.matching.MultiValuePattern;
import com.github.tomakehurst.wiremock.matching.RequestPattern;
import com.github.tomakehurst.wiremock.matching.StringValuePattern;
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.header;
@@ -214,7 +214,7 @@ public class WireMockRestServiceServer {
if (request.getBodyPatterns() == null) {
return;
}
for (final StringValuePattern pattern : request.getBodyPatterns()) {
for (final ContentPattern<?> pattern : request.getBodyPatterns()) {
if (pattern instanceof MatchesJsonPathPattern) {
expect.andExpect(MockRestRequestMatchers.jsonPath(((MatchesJsonPathPattern) pattern).getMatchesJsonPath()).exists());
} else if (pattern instanceof MatchesXPathPattern) {
@@ -224,7 +224,7 @@ public class WireMockRestServiceServer {
}
}
private RequestMatcher matchContents(final StringValuePattern pattern) {
private RequestMatcher matchContents(final ContentPattern pattern) {
return new RequestMatcher() {
@Override public void match(ClientHttpRequest request)
throws IOException, AssertionError {

View File

@@ -11,6 +11,7 @@ import com.github.tomakehurst.wiremock.extension.Parameters;
import com.github.tomakehurst.wiremock.http.Request;
import com.github.tomakehurst.wiremock.http.RequestMethod;
import com.github.tomakehurst.wiremock.http.ResponseDefinition;
import com.github.tomakehurst.wiremock.matching.ContentPattern;
import com.github.tomakehurst.wiremock.matching.RequestPattern;
import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder;
import com.github.tomakehurst.wiremock.matching.StringValuePattern;
@@ -75,7 +76,8 @@ class BasicMappingBuilder implements ScenarioMappingBuilder {
return this;
}
@Override public BasicMappingBuilder withRequestBody(StringValuePattern bodyPattern) {
@Override public ScenarioMappingBuilder withRequestBody(
ContentPattern<?> bodyPattern) {
this.requestPatternBuilder.withRequestBody(bodyPattern);
return this;
}