Merge branch '2.1.x'

# Conflicts:
#	docker/pom.xml
#	docker/spring-cloud-contract-docker/pom.xml
#	docker/spring-cloud-contract-docker/project/gradle.properties
#	docker/spring-cloud-contract-stub-runner-docker/pom.xml
#	docs/pom.xml
#	pom.xml
#	samples/pom.xml
#	samples/standalone/contracts/com/example/server/pom.xml
#	samples/standalone/dsl/http-client/pom.xml
#	samples/standalone/dsl/http-server/gradle.properties
#	samples/standalone/dsl/http-server/pom.xml
#	samples/standalone/dsl/pom.xml
#	samples/standalone/messaging/pom.xml
#	samples/standalone/messaging/stream-sink/gradle.properties
#	samples/standalone/messaging/stream-sink/pom.xml
#	samples/standalone/messaging/stream-source/gradle.properties
#	samples/standalone/messaging/stream-source/pom.xml
#	samples/standalone/pact/pact-http-client/pom.xml
#	samples/standalone/pact/pact-http-server/gradle.properties
#	samples/standalone/pact/pact-http-server/pom.xml
#	samples/standalone/pact/pom.xml
#	samples/standalone/pom.xml
#	samples/standalone/restdocs/http-client/gradle.properties
#	samples/standalone/restdocs/http-client/pom.xml
#	samples/standalone/restdocs/http-server/gradle.properties
#	samples/standalone/restdocs/http-server/pom.xml
#	samples/standalone/restdocs/pom.xml
#	samples/standalone/webclient/http-client/gradle.properties
#	samples/standalone/webclient/http-client/pom.xml
#	samples/standalone/webclient/http-server/gradle.properties
#	samples/standalone/webclient/http-server/pom.xml
#	samples/standalone/webclient/pom.xml
#	samples/standalone/yml/http-client/pom.xml
#	samples/standalone/yml/http-server/gradle.properties
#	samples/standalone/yml/http-server/pom.xml
#	samples/standalone/yml/pom.xml
#	samples/wiremock-jetty/pom.xml
#	samples/wiremock-native/pom.xml
#	samples/wiremock-tomcat/pom.xml
#	samples/wiremock-undertow-ssl/pom.xml
#	samples/wiremock-undertow/pom.xml
#	samples/wiremock/pom.xml
#	spring-cloud-contract-dependencies/pom.xml
#	spring-cloud-contract-shade/pom.xml
#	spring-cloud-contract-spec/pom.xml
#	spring-cloud-contract-starters/pom.xml
#	spring-cloud-contract-starters/spring-cloud-starter-contract-stub-runner-jetty/pom.xml
#	spring-cloud-contract-starters/spring-cloud-starter-contract-stub-runner/pom.xml
#	spring-cloud-contract-starters/spring-cloud-starter-contract-verifier/pom.xml
#	spring-cloud-contract-stub-runner-boot/pom.xml
#	spring-cloud-contract-stub-runner/pom.xml
#	spring-cloud-contract-tools/pom.xml
#	spring-cloud-contract-tools/spring-cloud-contract-converters/pom.xml
#	spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradle.properties
#	spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/pom.xml
#	spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradle.properties
#	spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/gradle.properties
#	spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/sampleProject/gradle.properties
#	spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradle.properties
#	spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/pom.xml
#	spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/complex-configuration/pom.xml
#	spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/different-module-configuration/module/pom.xml
#	spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/plugin-extension/pom.xml
#	spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/spring-boot-groovy/pom.xml
#	spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/spring-boot-java/pom.xml
#	spring-cloud-contract-tools/spring-cloud-contract-pact/pom.xml
#	spring-cloud-contract-verifier/pom.xml
#	spring-cloud-contract-wiremock/pom.xml
#	tests/pom.xml
#	tests/samples-messaging-amqp/pom.xml
#	tests/samples-messaging-camel/pom.xml
#	tests/samples-messaging-integration/pom.xml
#	tests/samples-messaging-stream/pom.xml
#	tests/spring-cloud-contract-stub-runner-amqp/pom.xml
#	tests/spring-cloud-contract-stub-runner-boot-eureka/pom.xml
#	tests/spring-cloud-contract-stub-runner-boot-zookeeper/pom.xml
#	tests/spring-cloud-contract-stub-runner-camel/pom.xml
#	tests/spring-cloud-contract-stub-runner-context-path/pom.xml
#	tests/spring-cloud-contract-stub-runner-integration/pom.xml
#	tests/spring-cloud-contract-stub-runner-moco-contract-jar/pom.xml
#	tests/spring-cloud-contract-stub-runner-moco/pom.xml
#	tests/spring-cloud-contract-stub-runner-stream/pom.xml
This commit is contained in:
Olga Maciaszek-Sharma
2019-06-27 15:26:56 +02:00
3 changed files with 1075 additions and 816 deletions

View File

@@ -57,7 +57,8 @@ import org.springframework.util.StringUtils;
*/
@Configuration
@ConditionalOnClass({ IntegrationFlows.class, EnableBinding.class })
@ConditionalOnProperty(name = "stubrunner.stream.enabled", havingValue = "true", matchIfMissing = true)
@ConditionalOnProperty(name = "stubrunner.stream.enabled", havingValue = "true",
matchIfMissing = true)
@AutoConfigureBefore(StubRunnerIntegrationConfiguration.class)
public class StubRunnerStreamConfiguration {

View File

@@ -115,24 +115,31 @@ class WireMockRequestStubStrategy extends BaseWireMockStubStrategy {
if (!request.body) {
return
}
boolean bodyHasMatchingStrategy = request.body.clientValue instanceof MatchingStrategy
MatchingStrategy matchingStrategy = getMatchingStrategyFromBody(request.body)
if (contentType == ContentType.JSON) {
def originalBody = matchingStrategy?.clientValue
def body = JsonToJsonPathsConverter.
removeMatchingJsonPaths(originalBody, request.bodyMatchers)
JsonPaths values = JsonToJsonPathsConverter.
transformToJsonPathWithStubsSideValuesAndNoArraySizeCheck(body)
if ((values.empty && !request.bodyMatchers?.hasMatchers())
||
onlySizeAssertionsArePresent(values)) {
requestPattern.withRequestBody(WireMock.equalToJson(JsonOutput.toJson(
getMatchingStrategy(request.body.clientValue).clientValue),
false, false))
if (bodyHasMatchingStrategy) {
requestPattern.withRequestBody(
convertToValuePattern(matchingStrategy))
}
else {
values.findAll { !it.assertsSize() }.each {
requestPattern.withRequestBody(WireMock.
matchingJsonPath(it.jsonPath().replace("\\\\", "\\")))
def body = JsonToJsonPathsConverter.
removeMatchingJsonPaths(originalBody, request.bodyMatchers)
JsonPaths values = JsonToJsonPathsConverter.
transformToJsonPathWithStubsSideValuesAndNoArraySizeCheck(body)
if ((values.empty && !request.bodyMatchers?.hasMatchers())
||
onlySizeAssertionsArePresent(values)) {
requestPattern.withRequestBody(WireMock.equalToJson(JsonOutput.toJson(
getMatchingStrategy(request.body.clientValue).clientValue),
false, false))
}
else {
values.findAll { !it.assertsSize() }.each {
requestPattern.withRequestBody(WireMock.
matchingJsonPath(it.jsonPath().replace("\\\\", "\\")))
}
}
}
request.bodyMatchers?.matchers()?.each {
@@ -144,12 +151,18 @@ class WireMockRequestStubStrategy extends BaseWireMockStubStrategy {
}
else if (contentType == ContentType.XML) {
Object originalBody = matchingStrategy?.clientValue
Object body = XmlToXPathsConverter
.removeMatchingXPaths(originalBody, request.bodyMatchers)
List<BodyMatcher> byEqualityMatchersFromXml = new XmlToXPathsConverter()
.mapToMatchers(body)
byEqualityMatchersFromXml.each {
addWireMockStubMatchingSection(it, requestPattern, originalBody)
if (bodyHasMatchingStrategy) {
requestPattern.withRequestBody(
convertToValuePattern(matchingStrategy))
}
else {
Object body = XmlToXPathsConverter
.removeMatchingXPaths(originalBody, request.bodyMatchers)
List<BodyMatcher> byEqualityMatchersFromXml = new XmlToXPathsConverter()
.mapToMatchers(body)
byEqualityMatchersFromXml.each {
addWireMockStubMatchingSection(it, requestPattern, originalBody)
}
}
request.bodyMatchers?.matchers()?.each {
addWireMockStubMatchingSection(it, requestPattern, originalBody)
@@ -191,7 +204,7 @@ class WireMockRequestStubStrategy extends BaseWireMockStubStrategy {
requestPattern.withRequestBody(WireMock.matchingXPath(pathMatcher.path(),
XPathBodyMatcherToWireMockValuePatternConverter
.mapToPattern(pathMatcher.matchingType(),
String.valueOf(retrievedValue))))
String.valueOf(retrievedValue))))
}
private boolean onlySizeAssertionsArePresent(JsonPaths values) {
@@ -301,31 +314,31 @@ class WireMockRequestStubStrategy extends BaseWireMockStubStrategy {
@TypeChecked(TypeCheckingMode.SKIP)
private ContentPattern convertToValuePattern(Object object) {
switch (object) {
case Pattern:
case RegexProperty:
return WireMock.matching(new RegexProperty(object).pattern())
case OptionalProperty:
OptionalProperty value = object as OptionalProperty
return WireMock.matching(value.optionalPattern())
case MatchingStrategy:
MatchingStrategy value = object as MatchingStrategy
switch (value.type) {
case MatchingStrategy.Type.NOT_MATCHING:
return WireMock.notMatching(value.clientValue.toString())
case MatchingStrategy.Type.ABSENT:
return WireMock.absent()
case Pattern:
case RegexProperty:
return WireMock.matching(new RegexProperty(object).pattern())
case OptionalProperty:
OptionalProperty value = object as OptionalProperty
return WireMock.matching(value.optionalPattern())
case MatchingStrategy:
MatchingStrategy value = object as MatchingStrategy
switch (value.type) {
case MatchingStrategy.Type.NOT_MATCHING:
return WireMock.notMatching(value.clientValue.toString())
case MatchingStrategy.Type.ABSENT:
return WireMock.absent()
default:
try {
return WireMock."${value.type.name}"(
clientBody(value.clientValue, contentType))
}
catch (Throwable t) {
log.error("Exception occurred while trying to call WireMock.${value.type.name}(${value.clientValue})", t)
throw t
}
}
default:
try {
return WireMock."${value.type.name}"(
clientBody(value.clientValue, contentType))
}
catch (Throwable t) {
log.error("Exception occurred while trying to call WireMock.${value.type.name}(${value.clientValue})", t)
throw t
}
}
default:
return WireMock.equalTo(object.toString())
return WireMock.equalTo(object.toString())
}
}
@@ -404,14 +417,14 @@ class WireMockRequestStubStrategy extends BaseWireMockStubStrategy {
private MatchingStrategy appendBodyRegexpMatchPattern(Object value, ContentType contentType) {
switch (contentType) {
case ContentType.JSON:
return new MatchingStrategy(
buildJSONRegexpMatch(value), MatchingStrategy.Type.MATCHING)
case ContentType.UNKNOWN:
return new MatchingStrategy(
buildGStringRegexpForStubSide(value), MatchingStrategy.Type.MATCHING)
case ContentType.XML:
throw new IllegalStateException("XML pattern matching is not implemented yet")
case ContentType.JSON:
return new MatchingStrategy(
buildJSONRegexpMatch(value), MatchingStrategy.Type.MATCHING)
case ContentType.UNKNOWN:
return new MatchingStrategy(
buildGStringRegexpForStubSide(value), MatchingStrategy.Type.MATCHING)
case ContentType.XML:
throw new IllegalStateException("XML pattern matching is not implemented yet")
}
}