From 8e44c3a9e2de3435573ed94aa37121045777dd18 Mon Sep 17 00:00:00 2001 From: Olga Maciaszek-Sharma Date: Mon, 19 Aug 2019 14:49:21 +0200 Subject: [PATCH] Fix test. --- ...vcMethodBodyBuilderWithMatchersSpec.groovy | 85 ++++++++++--------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcMethodBodyBuilderWithMatchersSpec.groovy b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcMethodBodyBuilderWithMatchersSpec.groovy index a00e82d841..07eb8557ea 100644 --- a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcMethodBodyBuilderWithMatchersSpec.groovy +++ b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcMethodBodyBuilderWithMatchersSpec.groovy @@ -635,8 +635,8 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements contentType(applicationJson()) } } - response { - status OK() + response { + status OK() body(''' { "prices": [ @@ -645,35 +645,39 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements "originalPrice": "1500" } ] - } - -''' - ) - bodyMatchers { + } + ''') + bodyMatchers { jsonPath('$.prices[0].country', byRegex(nonBlank())) jsonPath('$.prices[0].originalPrice', byRegex(number())) - } + } headers { contentType(applicationJsonUtf8()) } - } + } } - MethodBodyBuilder builder = methodBuilder(contractDsl) - BlockBuilder blockBuilder = new BlockBuilder(" ") - and: - builder.appendTo(blockBuilder) - String test = blockBuilder.toString() + methodBuilder() when: + String test = singleTestGenerator(contractDsl) SyntaxChecker.tryToCompileWithoutCompileStatic(methodBuilderName, test) then: !test.contains('isEmpty()') where: - methodBuilderName | methodBuilder - HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } - MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } - JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } - JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } - WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } + methodBuilderName | methodBuilder + "spock" | { properties.testFramework = TestFramework.SPOCK } + "testng" | { properties.testFramework = TestFramework.TESTNG } + "mockmvc" | { properties.testMode = TestMode.MOCKMVC } + "jaxrs-spock" | { + properties.testFramework = TestFramework.SPOCK; + properties.testMode = TestMode.JAXRSCLIENT + } + "jaxrs" | { + properties.testFramework = TestFramework.JUNIT; + properties.testMode = TestMode.JAXRSCLIENT + } + "webclient" | { + properties.testMode = TestMode.WEBTESTCLIENT + } } @Issue('#1091') @@ -691,21 +695,19 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements response { status OK() body(''' - { + { "test": [ { "prices": [ { "country" : "ES", "originalPrice": 1500 + } + ] } ] - } - ] - } - -''' - ) + } + ''') bodyMatchers { jsonPath('$.test[0].barcode', byRegex(nonBlank())) jsonPath('$.test[0].id', byRegex(nonBlank())) @@ -719,22 +721,27 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements } } } - MethodBodyBuilder builder = methodBuilder(contractDsl) - BlockBuilder blockBuilder = new BlockBuilder(" ") - and: - builder.appendTo(blockBuilder) - String test = blockBuilder.toString() + methodBuilder() when: + String test = singleTestGenerator(contractDsl) SyntaxChecker.tryToCompileWithoutCompileStatic(methodBuilderName, test) then: !test.contains('isEmpty()') where: - methodBuilderName | methodBuilder - HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } - MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } - JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } - JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } - WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } + methodBuilderName | methodBuilder + "spock" | { properties.testFramework = TestFramework.SPOCK } + "testng" | { properties.testFramework = TestFramework.TESTNG } + "mockmvc" | { properties.testMode = TestMode.MOCKMVC } + "jaxrs-spock" | { + properties.testFramework = TestFramework.SPOCK; + properties.testMode = TestMode.JAXRSCLIENT + } + "jaxrs" | { + properties.testFramework = TestFramework.JUNIT; + properties.testMode = TestMode.JAXRSCLIENT + } + "webclient" | { + properties.testMode = TestMode.WEBTESTCLIENT + } } - }