Introduced adding of custom WireMock extensions (#429)
without this change we set only a single extension "response-transformer" without an option to provide any other ones with this change we introduce the "spring.factories" based extension model. It's enough to provide your own implementation of `org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockExtensions` and register it in `spring.factories`. That way you can control all extensions (request / response). fixes #425
This commit is contained in:
committed by
GitHub
parent
4a46760ee2
commit
0758f4ec38
@@ -536,6 +536,31 @@ proper values. Additionally, it registers two helper functions:
|
||||
* `escapejsonbody`: Escapes the request body in a format that can be embedded in a JSON.
|
||||
* `jsonpath`: For a given parameter, find an object in the request body.
|
||||
|
||||
==== Registering Your Own WireMock Extension
|
||||
|
||||
WireMock lets you register custom extensions. By default, Spring Cloud Contract registers
|
||||
the transformer, which lets you reference a request from a response. If you want to
|
||||
provide your own extensions, you can register an implementation of the
|
||||
`org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockExtensions` interface.
|
||||
Since we use the spring.factories extension approach, you can create an entry in
|
||||
`META-INF/spring.factories` file similar to the following:
|
||||
|
||||
[source,groovy,indent=0]
|
||||
----
|
||||
include::{stubrunner_core_path}/src/test/resources/META-INF/spring.factories[indent=0]
|
||||
----
|
||||
|
||||
The following is an example of a custom extension:
|
||||
|
||||
.TestWireMockExtensions.groovy
|
||||
[source,groovy,indent=0]
|
||||
----
|
||||
include::{stubrunner_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/wiremock/TestWireMockExtensions.groovy[indent=0]
|
||||
----
|
||||
|
||||
IMPORTANT: Remember to override the `applyGlobally()` method and set it to `false` if you
|
||||
want the transformation to be applied only for a mapping that explicitly requires it.
|
||||
|
||||
==== Dynamic Properties in the Matchers Sections
|
||||
|
||||
If you work with https://docs.pact.io/[Pact], the following discussion may seem familiar.
|
||||
|
||||
@@ -8,27 +8,28 @@ import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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.extension.Extension;
|
||||
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.cloud.contract.stubrunner.HttpServerStub;
|
||||
import org.springframework.cloud.contract.verifier.builder.handlebars.HandlebarsEscapeHelper;
|
||||
import org.springframework.cloud.contract.verifier.builder.handlebars.HandlebarsJsonPathHelper;
|
||||
import org.springframework.cloud.contract.verifier.dsl.wiremock.DefaultResponseTransformer;
|
||||
import org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockExtensions;
|
||||
import org.springframework.cloud.contract.wiremock.WireMockSpring;
|
||||
import org.springframework.core.io.support.SpringFactoriesLoader;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.SocketUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import wiremock.com.github.jknack.handlebars.Helper;
|
||||
|
||||
/**
|
||||
@@ -47,18 +48,32 @@ public class WireMockHttpServerStub implements HttpServerStub {
|
||||
private WireMockConfiguration config() {
|
||||
if (ClassUtils.isPresent("org.springframework.cloud.contract.wiremock.WireMockSpring", null)) {
|
||||
return WireMockSpring.options()
|
||||
.extensions(responseTemplateTransformer());
|
||||
.extensions(responseTransformers());
|
||||
}
|
||||
return new WireMockConfiguration().extensions(responseTemplateTransformer());
|
||||
return new WireMockConfiguration().extensions(responseTransformers());
|
||||
}
|
||||
|
||||
private ResponseTemplateTransformer responseTemplateTransformer() {
|
||||
return new ResponseTemplateTransformer(false, helpers());
|
||||
private Extension[] responseTransformers() {
|
||||
List<WireMockExtensions> wireMockExtensions = SpringFactoriesLoader
|
||||
.loadFactories(WireMockExtensions.class, null);
|
||||
List<Extension> extensions = new ArrayList<>();
|
||||
if (!wireMockExtensions.isEmpty()) {
|
||||
for (WireMockExtensions wireMockExtension : wireMockExtensions) {
|
||||
extensions.addAll(wireMockExtension.extensions());
|
||||
}
|
||||
} else {
|
||||
extensions.add(new DefaultResponseTransformer(false, helpers()));
|
||||
}
|
||||
return extensions.toArray(new Extension[extensions.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this if you want to register your own helpers
|
||||
*
|
||||
* @deprecated - please use the {@link WireMockExtensions} mechanism and pass
|
||||
* the helpers in your implementation
|
||||
*/
|
||||
@Deprecated
|
||||
protected Map<String, Helper> helpers() {
|
||||
Map<String, Helper> helpers = new HashMap<>();
|
||||
helpers.put(HandlebarsJsonPathHelper.NAME, new HandlebarsJsonPathHelper());
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package org.springframework.cloud.contract.stubrunner.provider.wiremock
|
||||
|
||||
import com.github.tomakehurst.wiremock.common.FileSource
|
||||
import com.github.tomakehurst.wiremock.extension.Extension
|
||||
import com.github.tomakehurst.wiremock.extension.Parameters
|
||||
import com.github.tomakehurst.wiremock.extension.ResponseTransformer
|
||||
import com.github.tomakehurst.wiremock.http.Request
|
||||
import com.github.tomakehurst.wiremock.http.Response
|
||||
|
||||
import org.springframework.cloud.contract.verifier.dsl.wiremock.DefaultResponseTransformer
|
||||
import org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockExtensions
|
||||
|
||||
/**
|
||||
* Extension that registers the default response transformer and a custom one too
|
||||
*/
|
||||
class TestWireMockExtensions implements WireMockExtensions {
|
||||
@Override
|
||||
List<Extension> extensions() {
|
||||
return [
|
||||
new DefaultResponseTransformer(),
|
||||
new CustomExtension()
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
class CustomExtension extends ResponseTransformer {
|
||||
|
||||
/**
|
||||
* We expect the mapping to contain "foo-transformer" in the list
|
||||
* of "response-transformers" in the stub mapping
|
||||
*/
|
||||
@Override
|
||||
String getName() {
|
||||
return "foo-transformer"
|
||||
}
|
||||
|
||||
/**
|
||||
* Transformer returns the "surprise!" body regardless of what you
|
||||
* the stub mapping returns
|
||||
*/
|
||||
@Override
|
||||
Response transform(Request request, Response response, FileSource files, Parameters parameters) {
|
||||
return new Response(response.status, response.statusMessage,
|
||||
"surprise!", response.headers, response.wasConfigured(), response.fault, response.fromProxy)
|
||||
}
|
||||
|
||||
/**
|
||||
* We don't want this extension to be applied to every single mapping.
|
||||
* We just want this to take place when a mapping explicitly expresses that in the
|
||||
* "response-transformers" section
|
||||
*/
|
||||
@Override
|
||||
boolean applyGlobally() {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -23,31 +23,35 @@ import spock.lang.Specification
|
||||
|
||||
import org.springframework.boot.test.rule.OutputCapture
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate
|
||||
import org.springframework.web.client.RestTemplate
|
||||
|
||||
class WireMockHttpServerStubSpec extends Specification {
|
||||
public static
|
||||
final File MAPPING_DESCRIPTOR = new File('src/test/resources/repository/mappings/spring/cloud/ping/ping.json')
|
||||
final File MAPPING_DESCRIPTOR = new File('src/test/resources/transformers.json')
|
||||
|
||||
@Rule OutputCapture capture = new OutputCapture()
|
||||
|
||||
def 'should describe stub mapping'() {
|
||||
given:
|
||||
WireMockHttpServerStub mappingDescriptor = new WireMockHttpServerStub().start() as WireMockHttpServerStub
|
||||
|
||||
WireMockHttpServerStub mappingDescriptor = new WireMockHttpServerStub().start() as WireMockHttpServerStub
|
||||
when:
|
||||
StubMapping mapping = mappingDescriptor.getMapping(MAPPING_DESCRIPTOR)
|
||||
|
||||
StubMapping mapping = mappingDescriptor.getMapping(MAPPING_DESCRIPTOR)
|
||||
then:
|
||||
with(mapping) {
|
||||
assert request.method == RequestMethod.GET
|
||||
assert request.url == '/ping'
|
||||
assert response.status == 200
|
||||
assert response.body == 'pong'
|
||||
assert response.headers.contentTypeHeader.mimeTypePart() == 'text/plain'
|
||||
}
|
||||
|
||||
with(mapping) {
|
||||
assert request.method == RequestMethod.GET
|
||||
assert request.url == '/ping'
|
||||
assert response.status == 200
|
||||
assert response.body == 'pong'
|
||||
assert response.headers.contentTypeHeader.mimeTypePart() == 'text/plain'
|
||||
}
|
||||
when:
|
||||
mappingDescriptor.registerMappings([MAPPING_DESCRIPTOR])
|
||||
then:
|
||||
noExceptionThrown()
|
||||
expect:
|
||||
"surprise!" == new RestTemplate().getForObject("http://localhost:" + mappingDescriptor.port() + "/ping", String.class)
|
||||
cleanup:
|
||||
mappingDescriptor.stop()
|
||||
mappingDescriptor.stop()
|
||||
}
|
||||
|
||||
def 'should make WireMock print out logs on INFO'() {
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockExtensions=\
|
||||
org.springframework.cloud.contract.stubrunner.provider.wiremock.TestWireMockExtensions
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"url": "/ping"
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"body": "pong",
|
||||
"headers": {
|
||||
"Content-Type": "text/plain"
|
||||
},
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.springframework.cloud.contract.verifier.dsl.wiremock
|
||||
|
||||
import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer
|
||||
import wiremock.com.github.jknack.handlebars.Helper
|
||||
|
||||
import org.springframework.cloud.contract.verifier.builder.handlebars.HandlebarsEscapeHelper
|
||||
import org.springframework.cloud.contract.verifier.builder.handlebars.HandlebarsJsonPathHelper
|
||||
|
||||
/**
|
||||
* Default implementation of {@link ResponseTemplateTransformer} that contains
|
||||
* default set of handlebars helpers
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
* @since 1.2.0
|
||||
*/
|
||||
class DefaultResponseTransformer extends ResponseTemplateTransformer {
|
||||
DefaultResponseTransformer() {
|
||||
super(false, defaultHelpers())
|
||||
}
|
||||
|
||||
DefaultResponseTransformer(boolean global) {
|
||||
super(global)
|
||||
}
|
||||
|
||||
DefaultResponseTransformer(boolean global, String helperName, Helper helper) {
|
||||
super(global, helperName, helper)
|
||||
}
|
||||
|
||||
DefaultResponseTransformer(boolean global, Map<String, Helper> helpers) {
|
||||
super(global, helpers)
|
||||
}
|
||||
|
||||
private static Map<String, Helper> defaultHelpers() {
|
||||
Map<String, Helper> helpers = new HashMap<>()
|
||||
helpers.put(HandlebarsJsonPathHelper.NAME, new HandlebarsJsonPathHelper())
|
||||
helpers.put(HandlebarsEscapeHelper.NAME, new HandlebarsEscapeHelper())
|
||||
return helpers
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.springframework.cloud.contract.verifier.dsl.wiremock;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.github.tomakehurst.wiremock.extension.Extension;
|
||||
|
||||
/**
|
||||
* Contract that describes a list of {@link Extension} extensions
|
||||
* that should be applied to the response
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
* @since 1.2.0
|
||||
*/
|
||||
public interface WireMockExtensions {
|
||||
List<Extension> extensions();
|
||||
}
|
||||
@@ -17,16 +17,19 @@
|
||||
package org.springframework.cloud.contract.verifier.dsl.wiremock
|
||||
|
||||
import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder
|
||||
import com.github.tomakehurst.wiremock.extension.Extension
|
||||
import com.github.tomakehurst.wiremock.http.HttpHeader
|
||||
import com.github.tomakehurst.wiremock.http.HttpHeaders
|
||||
import com.github.tomakehurst.wiremock.http.ResponseDefinition
|
||||
import groovy.transform.PackageScope
|
||||
import groovy.transform.TypeChecked
|
||||
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.spec.internal.Request
|
||||
import org.springframework.cloud.contract.spec.internal.Response
|
||||
import org.springframework.cloud.contract.verifier.util.ContentType
|
||||
import org.springframework.cloud.contract.verifier.util.MapConverter
|
||||
import org.springframework.core.io.support.SpringFactoriesLoader
|
||||
|
||||
import static org.springframework.cloud.contract.verifier.util.ContentUtils.recognizeContentTypeFromContent
|
||||
import static org.springframework.cloud.contract.verifier.util.ContentUtils.recognizeContentTypeFromHeader
|
||||
@@ -56,10 +59,21 @@ class WireMockResponseStubStrategy extends BaseWireMockStubStrategy {
|
||||
appendHeaders(builder)
|
||||
appendBody(builder)
|
||||
appendResponseDelayTime(builder)
|
||||
builder.withTransformers("response-template")
|
||||
builder.withTransformers(responseTransformerNames())
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
private String[] responseTransformerNames() {
|
||||
List<WireMockExtensions> wireMockExtensions = SpringFactoriesLoader.loadFactories(WireMockExtensions, null)
|
||||
if (wireMockExtensions) {
|
||||
return ((List<Extension>) wireMockExtensions
|
||||
.collect { WireMockExtensions extension -> extension.extensions() }
|
||||
.flatten())
|
||||
.collect { Extension e -> e.getName()} as String[]
|
||||
}
|
||||
return [new DefaultResponseTransformer().getName()] as String[]
|
||||
}
|
||||
|
||||
private void appendHeaders(ResponseDefinitionBuilder builder) {
|
||||
if (response.headers) {
|
||||
builder.withHeaders(new HttpHeaders(response.headers.entries?.collect {
|
||||
|
||||
@@ -78,7 +78,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"headers" : {
|
||||
"Content-Type" : "application/json"
|
||||
},
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
''', wireMockStub)
|
||||
@@ -126,7 +126,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"response" : {
|
||||
"status" : 200,
|
||||
"body" : "{\\"ingredients\\":[{\\"quantity\\":100,\\"type\\":\\"MALT\\"},{\\"quantity\\":200,\\"type\\":\\"WATER\\"},{\\"quantity\\":300,\\"type\\":\\"HOP\\"},{\\"quantity\\":400,\\"type\\":\\"YIEST\\"}]}",
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
''', wireMockStub)
|
||||
@@ -180,7 +180,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"response": {
|
||||
"status": 204,
|
||||
"body": "{\\"foundExistingPayment\\":false,\\"paymentId\\":\\"4\\"}",
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
''', wireMockStub)
|
||||
@@ -227,7 +227,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"headers" : {
|
||||
"Content-Type" : "application/json"
|
||||
},
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
''')
|
||||
@@ -284,7 +284,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"headers" : {
|
||||
"Content-Type" : "application/json"
|
||||
},
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
''', wireMockStub)
|
||||
@@ -335,7 +335,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
},
|
||||
"response" : {
|
||||
"status" : 200,
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), wireMockStub)
|
||||
@@ -381,7 +381,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
},
|
||||
"response" : {
|
||||
"status" : 200,
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), json)
|
||||
@@ -427,7 +427,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), json)
|
||||
@@ -465,7 +465,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), json)
|
||||
@@ -499,7 +499,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"response": {
|
||||
"status": 200,
|
||||
"body":"<user><name>Jozo</name><jobId><test></jobId></user>",
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), json)
|
||||
@@ -535,7 +535,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), json)
|
||||
@@ -573,7 +573,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), json)
|
||||
@@ -624,7 +624,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"headers" : {
|
||||
"Content-Type" : "application/json"
|
||||
},
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), wireMockStub)
|
||||
@@ -687,7 +687,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"headers" : {
|
||||
"Content-Type" : "application/vnd.fraud.v1+json"
|
||||
},
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), wireMockStub)
|
||||
@@ -754,7 +754,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), json)
|
||||
@@ -793,7 +793,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
},
|
||||
"response" : {
|
||||
"status" : 200,
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), json)
|
||||
@@ -834,7 +834,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), json)
|
||||
@@ -865,7 +865,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), json)
|
||||
@@ -895,7 +895,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), json)
|
||||
@@ -1049,7 +1049,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), json)
|
||||
@@ -1123,7 +1123,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"headers" : {
|
||||
"Content-Type" : "application/json"
|
||||
},
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), wireMockStub)
|
||||
@@ -1184,7 +1184,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"headers" : {
|
||||
"Content-Type" : "application/json"
|
||||
},
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), json)
|
||||
@@ -1218,7 +1218,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
},
|
||||
"response": {
|
||||
"status": 406,
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), json)
|
||||
@@ -1248,7 +1248,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
},
|
||||
"response": {
|
||||
"status": 406,
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), json)
|
||||
@@ -1282,7 +1282,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
},
|
||||
"response" : {
|
||||
"status" : 200,
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), wireMockStub)
|
||||
@@ -1320,7 +1320,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), wireMockStub)
|
||||
@@ -1379,7 +1379,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"headers" : {
|
||||
"Content-Type" : "application/json"
|
||||
},
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
},
|
||||
"priority" : 1
|
||||
}
|
||||
@@ -1425,7 +1425,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
},
|
||||
"response" : {
|
||||
"status" : 422,
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), wireMockStub)
|
||||
@@ -1460,7 +1460,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"headers" : {
|
||||
"Content-Type" : "application/json"
|
||||
},
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
},
|
||||
"priority" : 1
|
||||
}
|
||||
@@ -1592,7 +1592,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
},
|
||||
"response" : {
|
||||
"status" : 200,
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''
|
||||
@@ -1673,7 +1673,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"response" : {
|
||||
"status" : 200,
|
||||
"body" : "{\\"number\\":0,\\"last\\":true,\\"numberOfElements\\":1,\\"size\\":1,\\"totalPages\\":1,\\"sort\\":[{\\"nullHandling\\":\\"NATIVE\\",\\"ignoreCase\\":false,\\"property\\":\\"id\\",\\"ascending\\":true,\\"direction\\":\\"ASC\\"}],\\"content\\":[{\\"id\\":\\"00000000-0000-0000-0000-000000000000\\",\\"state\\":\\"ACTIVE\\",\\"type\\":\\"Extraordinary\\"}],\\"first\\":true,\\"totalElements\\":1}",
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), json)
|
||||
@@ -1802,7 +1802,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"headers" : {
|
||||
"Authorization" : "{{{request.headers.Authorization.[0]}}};foo"
|
||||
},
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
'''), json)
|
||||
@@ -1994,7 +1994,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"response" : {
|
||||
"status" : 200,
|
||||
"body" : "{\\"code\\":91015,\\"payload\\":null,\\"description\\":\\"订单已失效\\",\\"lastUpdateTime\\":\\"0\\"}",
|
||||
"transformers" : [ "response-template" ]
|
||||
"transformers" : [ "response-template", "foo-transformer" ]
|
||||
}
|
||||
}
|
||||
''', wireMockStub)
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.springframework.cloud.contract.verifier.dsl.wiremock
|
||||
|
||||
import com.github.tomakehurst.wiremock.extension.Extension
|
||||
|
||||
/**
|
||||
* Extension that registers the default transformer and the custom one
|
||||
*/
|
||||
class TestWireMockExtensions implements WireMockExtensions {
|
||||
@Override
|
||||
List<Extension> extensions() {
|
||||
return [
|
||||
new DefaultResponseTransformer(),
|
||||
new CustomExtension()
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
class CustomExtension implements Extension {
|
||||
|
||||
@Override
|
||||
String getName() {
|
||||
return "foo-transformer"
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,8 @@
|
||||
# Converters
|
||||
org.springframework.cloud.contract.spec.ContractConverter=\
|
||||
org.springframework.cloud.contract.verifier.converter.YamlContractConverter
|
||||
org.springframework.cloud.contract.verifier.converter.YamlContractConverter
|
||||
|
||||
# tag::extension[]
|
||||
org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockExtensions=\
|
||||
org.springframework.cloud.contract.verifier.dsl.wiremock.TestWireMockExtensions
|
||||
# end::extension[]
|
||||
Reference in New Issue
Block a user