diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/WiremockRequestStubStrategy.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/WiremockRequestStubStrategy.groovy index c0dfe0c43c..36f7ec1ab5 100755 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/WiremockRequestStubStrategy.groovy +++ b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/WiremockRequestStubStrategy.groovy @@ -1,5 +1,4 @@ package io.codearte.accurest.dsl - import groovy.transform.PackageScope import groovy.transform.TypeChecked import io.codearte.accurest.dsl.internal.ClientRequest @@ -7,8 +6,6 @@ import io.codearte.accurest.dsl.internal.Request import java.util.regex.Pattern -import static groovy.json.StringEscapeUtils.escapeJava - @TypeChecked @PackageScope class WiremockRequestStubStrategy extends BaseWiremockStubStrategy { @@ -41,10 +38,10 @@ class WiremockRequestStubStrategy extends BaseWiremockStubStrategy { return [:] } if (containsRegex(body)) { - return [bodyPatterns: [matches: parseBody(body)]] + return [bodyPatterns: [[matches: parseBody(body)]]] } - return [bodyPatterns: [equalTo: parseBody(body)]] + return [bodyPatterns: [[equalTo: parseBody(body)]]] } boolean containsRegex(Object bodyObject) { diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WiremockGroovyDslSpec.groovy b/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WiremockGroovyDslSpec.groovy index 5f1684ec7d..4ff7fa09f5 100755 --- a/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WiremockGroovyDslSpec.groovy +++ b/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WiremockGroovyDslSpec.groovy @@ -1,8 +1,7 @@ package io.codearte.accurest.dsl import groovy.json.JsonSlurper -import spock.lang.Specification -class WiremockGroovyDslSpec extends Specification { +class WiremockGroovyDslSpec extends WiremockSpec { def 'should convert groovy dsl stub to wiremock stub for the client side'() { given: @@ -48,6 +47,8 @@ class WiremockGroovyDslSpec extends Specification { } } ''') + and: + stubMappingIsValidWiremockStub(wiremockStub) } def 'should convert groovy dsl stub with Body as String to wiremock stub for the client side'() { @@ -91,6 +92,8 @@ class WiremockGroovyDslSpec extends Specification { } } ''') + and: + stubMappingIsValidWiremockStub(wiremockStub) } def 'should convert groovy dsl stub with simple Body as String to wiremock stub for the client side'() { @@ -141,12 +144,14 @@ class WiremockGroovyDslSpec extends Specification { } } ''') + and: + stubMappingIsValidWiremockStub(wiremockStub) } def 'should convert groovy dsl stub with regexp Body as String to wiremock stub for the client side'() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + GroovyDsl groovyDsl = GroovyDsl.make { request { method('GET') url $(client(regex('/[0-9]{2}')), server('/12')) @@ -170,28 +175,30 @@ class WiremockGroovyDslSpec extends Specification { } } when: - String wiremockStub = new WiremockStubStrategy(groovyDsl).toWiremockClientStub() + String wiremockStub = new WiremockStubStrategy(groovyDsl).toWiremockClientStub() then: - new JsonSlurper().parseText(wiremockStub) == new JsonSlurper().parseText(''' + new JsonSlurper().parseText(wiremockStub) == new JsonSlurper().parseText(''' { "request": { "method": "GET", "urlPattern": "/[0-9]{2}", - "bodyPatterns": { - "matches":"{\\"personalId\\":\\"^[0-9]{11}$\\"}" - } + "bodyPatterns": [ + { + "matches":"{\\"personalId\\":\\"^[0-9]{11}$\\"}" + } + ] }, "response": { "status": 200, - "body": { - "name": "Jan" - }, + "body": "{\\"name\\":\\"Jan\\"}", "headers": { "Content-Type": "text/plain" } } } ''') + and: + stubMappingIsValidWiremockStub(wiremockStub) } diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WiremockSpec.groovy b/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WiremockSpec.groovy new file mode 100644 index 0000000000..2a6237d89d --- /dev/null +++ b/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WiremockSpec.groovy @@ -0,0 +1,12 @@ +package io.codearte.accurest.dsl + +import com.github.tomakehurst.wiremock.stubbing.StubMapping +import spock.lang.Specification + +class WiremockSpec extends Specification { + + void stubMappingIsValidWiremockStub(String mappingDefinition) { + StubMapping.buildFrom(mappingDefinition) + } + +} diff --git a/build.gradle b/build.gradle index e0a87bd555..c2d42cfdf1 100644 --- a/build.gradle +++ b/build.gradle @@ -89,6 +89,7 @@ project(':accurest-core') { compile 'commons-io:commons-io:2.4' testCompile 'cglib:cglib-nodep:2.2' testCompile 'org.objenesis:objenesis:2.1' + testCompile 'com.github.tomakehurst:wiremock:1.53' } }