Merge branch '2.2.x'

This commit is contained in:
Marcin Grzejszczak
2020-05-21 13:51:56 +02:00
13 changed files with 91 additions and 134 deletions

View File

@@ -40,7 +40,7 @@ dependencyManagement {
}
dependencies {
testCompile("org.springframework.cloud:spring-cloud-starter-contract-verifier")
testImplementation("org.springframework.cloud:spring-cloud-starter-contract-verifier")
}
test {

View File

@@ -82,6 +82,7 @@ esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@@ -129,6 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath

View File

@@ -84,6 +84,7 @@ set CMD_LINE_ARGS=%*
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

View File

@@ -23,9 +23,9 @@ targetCompatibility = 1.8
repositories { mavenCentral() }
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.cloud:spring-cloud-starter-contract-stub-runner')
implementation('org.springframework.boot:spring-boot-starter-web')
testImplementation('org.springframework.boot:spring-boot-starter-test')
testImplementation('org.springframework.cloud:spring-cloud-starter-contract-stub-runner')
}
dependencyManagement {
@@ -41,3 +41,7 @@ eclipse {
}
}
task wrapper(type: Wrapper){
gradleVersion = '6.4'
}

View File

@@ -31,20 +31,20 @@ repositories {
}
dependencies {
compile "org.springframework:spring-web"
compile "org.springframework:spring-context-support"
compile "org.codehaus.groovy:groovy-all:${groovyVersion}"
compile 'com.jayway.jsonpath:json-path-assert:2.2.0'
implementation "org.springframework:spring-web"
implementation "org.springframework:spring-context-support"
implementation "org.codehaus.groovy:groovy-all:${groovyVersion}"
implementation 'com.jayway.jsonpath:json-path-assert:2.2.0'
testCompile "com.github.tomakehurst:wiremock:${wiremockVersion}"
testCompile "com.toomuchcoding.jsonassert:jsonassert:${jsonAssertVersion}"
testCompile("org.spockframework:spock-spring:1.0-groovy-2.4") {
testImplementation "com.github.tomakehurst:wiremock:${wiremockVersion}"
testImplementation "com.toomuchcoding.jsonassert:jsonassert:${jsonAssertVersion}"
testImplementation("org.spockframework:spock-spring:1.0-groovy-2.4") {
exclude(group: 'org.codehaus.groovy')
}
testCompile "io.restassured:rest-assured:$restAssuredVersion"
testCompile "io.restassured:spring-mock-mvc:$restAssuredVersion"
testCompile "ch.qos.logback:logback-classic:1.1.2"
testCompile "org.springframework.cloud:spring-cloud-contract-verifier:${verifierVersion}"
testImplementation "io.restassured:rest-assured:$restAssuredVersion"
testImplementation "io.restassured:spring-mock-mvc:$restAssuredVersion"
testImplementation "ch.qos.logback:logback-classic:1.1.2"
testImplementation "org.springframework.cloud:spring-cloud-contract-verifier:${verifierVersion}"
}
contracts {

View File

@@ -45,15 +45,15 @@ subprojects {
}
dependencies {
testCompile "org.codehaus.groovy:groovy"
testCompile("org.spockframework:spock-core:$spockVersion") {
testImplementation "org.codehaus.groovy:groovy"
testImplementation("org.spockframework:spock-core:$spockVersion") {
exclude(group: 'org.codehaus.groovy')
}
testCompile "junit:junit:4.12"
testCompile "com.github.tomakehurst:wiremock:${wiremockVersion}"
testCompile "com.toomuchcoding.jsonassert:jsonassert:${jsonAssertVersion}"
testCompile "org.assertj:assertj-core:2.4.1"
testCompile "org.springframework.cloud:spring-cloud-contract-verifier:${verifierVersion}"
testImplementation "junit:junit:4.12"
testImplementation "com.github.tomakehurst:wiremock:${wiremockVersion}"
testImplementation "com.toomuchcoding.jsonassert:jsonassert:${jsonAssertVersion}"
testImplementation "org.assertj:assertj-core:2.4.1"
testImplementation "org.springframework.cloud:spring-cloud-contract-verifier:${verifierVersion}"
}
}
@@ -106,20 +106,20 @@ configure([project(':fraudDetectionService'), project(':loanApplicationService')
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web") {
implementation("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
compile("org.springframework.boot:spring-boot-starter-jetty")
compile("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-jetty")
implementation("org.springframework.boot:spring-boot-starter-actuator")
testRuntime("org.spockframework:spock-spring:$spockVersion") {
exclude(group: 'org.codehaus.groovy')
}
testCompile "org.mockito:mockito-core"
testCompile "org.springframework:spring-test"
testCompile "org.springframework.boot:spring-boot-test"
testCompile "io.rest-assured:rest-assured:$restAssuredVersion"
testCompile "io.rest-assured:spring-mock-mvc:$restAssuredVersion"
testImplementation "org.mockito:mockito-core"
testImplementation "org.springframework:spring-test"
testImplementation "org.springframework.boot:spring-boot-test"
testImplementation "io.rest-assured:rest-assured:$restAssuredVersion"
testImplementation "io.rest-assured:spring-mock-mvc:$restAssuredVersion"
}
task cleanup(type: Delete) {

View File

@@ -1,23 +0,0 @@
{
"request": {
"method": "PUT",
"headers": {
"Content-Type": {
"equalTo": "application/vnd.fraud.v1+json"
}
},
"url": "/fraudcheck",
"bodyPatterns": [
{
"matches": "{\"clientPesel\":\"[0-9]{10}\",\"loanAmount\":\"99999\"}"
}
]
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/vnd.fraud.v1+json"
},
"body": "{\"fraudCheckStatus\":\"FRAUD\",\"rejectionReason\":\"Amount too high\"}"
}
}

View File

@@ -1,23 +0,0 @@
{
"request": {
"method": "PUT",
"headers": {
"Content-Type": {
"equalTo": "application/vnd.fraud.v1+json"
}
},
"url": "/fraudcheck",
"bodyPatterns": [
{
"matches": "{\"clientPesel\":\"[0-9]{10}\",\"loanAmount\":\"123.123\"}"
}
]
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/vnd.fraud.v1+json"
},
"body": "{\"fraudCheckStatus\":\"OK\",\"rejectionReason\":null}"
}
}

View File

@@ -1,23 +0,0 @@
{
"request": {
"method": "PUT",
"headers": {
"Content-Type": {
"equalTo": "application/vnd.fraud.v1+json"
}
},
"url": "/fraudcheck",
"bodyPatterns": [
{
"matches": "{\"clientPesel\":\"[0-9]{10}\",\"loanAmount\":\"99999\"}"
}
]
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/vnd.fraud.v1+json"
},
"body": "{\"fraudCheckStatus\":\"FRAUD\",\"rejectionReason\":\"Amount too high\"}"
}
}

View File

@@ -1,23 +0,0 @@
{
"request": {
"method": "PUT",
"headers": {
"Content-Type": {
"equalTo": "application/vnd.fraud.v1+json"
}
},
"url": "/fraudcheck",
"bodyPatterns": [
{
"matches": "{\"clientPesel\":\"[0-9]{10}\",\"loanAmount\":\"123.123\"}"
}
]
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/vnd.fraud.v1+json"
},
"body": "{\"fraudCheckStatus\":\"OK\",\"rejectionReason\":null}"
}
}

View File

@@ -18,7 +18,6 @@ package org.springframework.cloud.contract.verifier.builder;
import org.springframework.cloud.contract.spec.internal.ExecutionProperty;
import org.springframework.cloud.contract.spec.internal.FromFileProperty;
import org.springframework.cloud.contract.spec.internal.Header;
import org.springframework.cloud.contract.spec.internal.Request;
import org.springframework.cloud.contract.verifier.file.SingleContractMetadata;
import org.springframework.cloud.contract.verifier.util.ContentType;
@@ -46,9 +45,8 @@ class JaxRsRequestMethodWhen implements When, JaxRsBodyParser {
ContentType type = metadata.getInputTestContentType();
String method = request.getMethod().getServerValue().toString().toLowerCase();
if (request.getBody() != null) {
String contentType = type.getMimeType();
contentType = StringUtils.hasText(contentType) ? contentType
: getContentType(request);
String contentType = StringUtils.hasText(metadata.getDefinedInputTestContentType())
? metadata.getDefinedInputTestContentType() : type.getMimeType();
Object body = request.getBody().getServerValue();
String value;
if (body instanceof ExecutionProperty) {
@@ -73,13 +71,6 @@ class JaxRsRequestMethodWhen implements When, JaxRsBodyParser {
}
}
private String getContentType(Request request) {
Header contentType = request.getHeaders().getEntries().stream()
.filter(header -> "Content-Type".equalsIgnoreCase(header.getName()))
.findFirst().orElse(null);
return contentType != null ? contentType.getServerValue().toString() : "";
}
@Override
public boolean accept(SingleContractMetadata metadata) {
return true;

View File

@@ -26,12 +26,12 @@ import org.apache.commons.logging.LogFactory
import org.springframework.cloud.contract.spec.Contract
import org.springframework.cloud.contract.spec.internal.DslProperty
import org.springframework.cloud.contract.spec.internal.Header
import org.springframework.cloud.contract.spec.internal.Headers
import org.springframework.cloud.contract.verifier.util.ContentType
import org.springframework.cloud.contract.verifier.util.ContentUtils
import org.springframework.cloud.contract.verifier.util.NamesUtil
import org.springframework.util.Assert
/**
* Contains metadata for a particular file with a DSL
*
@@ -103,12 +103,16 @@ class SingleContractMetadata {
private final File stubsFile
final Contract contract
private final Collection<Contract> allContracts
final String definedInputStubContentType
final ContentType inputStubContentType
final ContentType evaluatedInputStubContentType
final String definedOutputStubContentType
final ContentType outputStubContentType
final ContentType evaluatedOutputStubContentType
final String definedInputTestContentType
final ContentType inputTestContentType
final ContentType evaluatedInputTestContentType
final String definedOutputTestContentType
final ContentType outputTestContentType
final ContentType evaluatedOutputTestContentType
private final boolean http
@@ -121,12 +125,18 @@ class SingleContractMetadata {
DslProperty inputBody = inputBody(currentContract)
Headers outputHeaders = outputHeaders(currentContract)
DslProperty outputBody = outputBody(currentContract)
Header inputContentType = contentTypeHeader(inputHeaders)
Header outputContentType = contentTypeHeader(outputHeaders)
this.definedInputTestContentType = inputContentType != null ? inputContentType.getServerValue() : ""
this.evaluatedInputTestContentType = tryToEvaluateTestContentType(inputHeaders, inputBody)
this.inputTestContentType = inputBody != null ? this.evaluatedInputTestContentType : ContentType.UNKNOWN
this.definedOutputTestContentType = outputContentType != null ? outputContentType.getServerValue() : ""
this.evaluatedOutputTestContentType = tryToEvaluateTestContentType(outputHeaders, outputBody)
this.outputTestContentType = outputBody != null ? this.evaluatedOutputTestContentType : ContentType.UNKNOWN
this.definedInputStubContentType = inputContentType != null ? inputContentType.getClientValue() : ""
this.evaluatedInputStubContentType = tryToEvaluateStubContentType(inputHeaders, inputBody)
this.inputStubContentType = inputBody != null ? this.evaluatedInputStubContentType : ContentType.UNKNOWN
this.definedOutputStubContentType = outputContentType != null ? outputContentType.getClientValue() : ""
this.evaluatedOutputStubContentType = tryToEvaluateStubContentType(outputHeaders, outputBody)
this.outputStubContentType = outputBody != null ? this.evaluatedOutputStubContentType : ContentType.UNKNOWN
this.http = currentContract.request != null
@@ -134,6 +144,12 @@ class SingleContractMetadata {
this.stubsFile = contractMetadata.getPath() != null ? contractMetadata.getPath().toFile() : null
}
private Header contentTypeHeader(Headers headers) {
return headers == null ? null : headers.getEntries().stream()
.filter({ header -> "Content-Type".equalsIgnoreCase(header.getName()) })
.findFirst().orElse(null)
}
private ContentType tryToEvaluateStubContentType(Headers mainHeaders, DslProperty body) {
ContentType contentType = ContentUtils.evaluateClientSideContentType(mainHeaders, body?.getClientValue())
if (contentType == ContentType.DEFINED || contentType == ContentType.UNKNOWN) {

View File

@@ -1338,6 +1338,41 @@ public class FooTest {
}
}
@Issue('#1388')
@Unroll
def "should keep the custom content type that includes the +json suffix [#methodBuilderName]"() {
given:
Contract contractDsl = Contract.make {
request {
method("POST")
url("/ping")
headers {
header('Content-Type': 'application/my-content-type+json')
}
body($(test(value: "test"), stub(anyNonEmptyString())))
}
response {
status 200
}
}
methodBuilder()
when:
String test = singleTestGenerator(contractDsl)
then:
test.contains('"application/my-content-type+json")')
!test.contains('"application/json")')
and:
SyntaxChecker.tryToCompile(methodBuilderName, test)
where:
methodBuilderName | methodBuilder
"jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
}
"jaxrs" | {
properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT
}
}
@Issue('#261')
@Unroll
def "should not produce any additional quotes for [#methodBuilderName]"() {