diff --git a/docker/spring-cloud-contract-docker/project/build.gradle b/docker/spring-cloud-contract-docker/project/build.gradle index 833f2e7f23..fd857a5639 100644 --- a/docker/spring-cloud-contract-docker/project/build.gradle +++ b/docker/spring-cloud-contract-docker/project/build.gradle @@ -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 { diff --git a/docker/spring-cloud-contract-docker/project/gradlew b/docker/spring-cloud-contract-docker/project/gradlew index 2fe81a7d95..fbd7c51583 100755 --- a/docker/spring-cloud-contract-docker/project/gradlew +++ b/docker/spring-cloud-contract-docker/project/gradlew @@ -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 diff --git a/docker/spring-cloud-contract-docker/project/gradlew.bat b/docker/spring-cloud-contract-docker/project/gradlew.bat index 9109989e3c..a9f778a7a9 100644 --- a/docker/spring-cloud-contract-docker/project/gradlew.bat +++ b/docker/spring-cloud-contract-docker/project/gradlew.bat @@ -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% diff --git a/guides/gs-contract-rest/complete/contract-rest-client/build.gradle b/guides/gs-contract-rest/complete/contract-rest-client/build.gradle index a974f49e7e..30acb24f9b 100644 --- a/guides/gs-contract-rest/complete/contract-rest-client/build.gradle +++ b/guides/gs-contract-rest/complete/contract-rest-client/build.gradle @@ -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' +} + diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/bootSimple/build.gradle b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/bootSimple/build.gradle index e9a09d84bc..549b0fdb7a 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/bootSimple/build.gradle +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/bootSimple/build.gradle @@ -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 { diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProject/build.gradle b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProject/build.gradle index 77ddd66e37..21c9c7db7d 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProject/build.gradle +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProject/build.gradle @@ -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) { diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsFraud.json b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsFraud.json deleted file mode 100644 index fe037dc7ef..0000000000 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsFraud.json +++ /dev/null @@ -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\"}" - } -} diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.json b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.json deleted file mode 100644 index 8b89b6d54e..0000000000 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.json +++ /dev/null @@ -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}" - } -} diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProjectKotlin/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsFraud.json b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProjectKotlin/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsFraud.json deleted file mode 100644 index fe037dc7ef..0000000000 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProjectKotlin/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsFraud.json +++ /dev/null @@ -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\"}" - } -} diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProjectKotlin/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.json b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProjectKotlin/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.json deleted file mode 100644 index 8b89b6d54e..0000000000 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProjectKotlin/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.json +++ /dev/null @@ -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}" - } -} diff --git a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JaxRsRequestMethodWhen.java b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JaxRsRequestMethodWhen.java index ec0ba3bd30..7e4f163440 100644 --- a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JaxRsRequestMethodWhen.java +++ b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JaxRsRequestMethodWhen.java @@ -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; diff --git a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/file/ContractMetadata.groovy b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/file/ContractMetadata.groovy index c06b40b9e8..20eeb7a2c4 100644 --- a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/file/ContractMetadata.groovy +++ b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/file/ContractMetadata.groovy @@ -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 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) { diff --git a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/JaxRsClientMethodBuilderSpec.groovy b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/JaxRsClientMethodBuilderSpec.groovy index bf32e5025f..62d111283d 100644 --- a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/JaxRsClientMethodBuilderSpec.groovy +++ b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/JaxRsClientMethodBuilderSpec.groovy @@ -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]"() {