From 7d39ef49b46eac2878c14a416d38b10b292905ef Mon Sep 17 00:00:00 2001 From: Adam Wojszczyk Date: Mon, 17 Aug 2015 15:48:06 +0200 Subject: [PATCH 1/3] Allow fields' values to be empty lists during searching for patterns --- .../dsl/WireMockRequestStubStrategy.groovy | 2 +- .../accurest/dsl/WireMockGroovyDslSpec.groovy | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) 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 d0bb325bb1..d540069484 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 @@ -139,7 +139,7 @@ class WireMockRequestStubStrategy extends BaseWireMockStubStrategy { } private boolean containsPattern(Collection collection) { - return collection.collect(this.&containsPattern).inject { a, b -> a || b } + return collection.collect(this.&containsPattern).inject('') { a, b -> a || b } } private boolean containsPattern(Object[] objects) { 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 ced69beeb1..23d8f65f35 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 @@ -1192,4 +1192,39 @@ class WireMockGroovyDslSpec extends WireMockSpec { String toWireMockClientJsonStub(groovyDsl) { new WireMockStubStrategy(groovyDsl).toWireMockClientStub() } + + def 'should generate stub with empty list as a value of a field'() { + given: + GroovyDsl groovyDsl = GroovyDsl.make { + request { + method('POST') + body( + values: [] + ) + } + response { + status 200 + } + } + when: + String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub() + then: + new JsonSlurper().parseText(wireMockStub) == new JsonSlurper().parseText(''' + { + "request": { + "method": "POST", + "bodyPatterns": [ + { + "equalToJson": "{\\"values\\":[]}" + } + ] + }, + "response": { + "status": 200 + } + } + ''') + and: + stubMappingIsValidWireMockStub(wireMockStub) + } } From b3b9dced26c7de1ee228a0613256164a46a7c611 Mon Sep 17 00:00:00 2001 From: Adam Wojszczyk Date: Mon, 17 Aug 2015 16:03:33 +0200 Subject: [PATCH 2/3] [#121] Allow fields' values to be empty lists during searching for patterns --- .../groovy/io/codearte/accurest/dsl/WireMockGroovyDslSpec.groovy | 1 + 1 file changed, 1 insertion(+) 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 23d8f65f35..d38124d532 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 @@ -1193,6 +1193,7 @@ class WireMockGroovyDslSpec extends WireMockSpec { new WireMockStubStrategy(groovyDsl).toWireMockClientStub() } + @Issue("#121") def 'should generate stub with empty list as a value of a field'() { given: GroovyDsl groovyDsl = GroovyDsl.make { From ee87decf82a43adba091149a9ea6ace0df5a3eef Mon Sep 17 00:00:00 2001 From: Adam Wojszczyk Date: Mon, 17 Aug 2015 16:05:32 +0200 Subject: [PATCH 3/3] [#121] Allow fields' values to be empty lists during searching for patterns - reformat --- .../accurest/dsl/WireMockGroovyDslSpec.groovy | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) 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 d38124d532..1867c49eda 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 @@ -1181,18 +1181,6 @@ class WireMockGroovyDslSpec extends WireMockSpec { ''') } - String toJsonString(value) { - new JsonBuilder(value).toPrettyString() - } - - Object parseJson(json) { - new JsonSlurper().parseText(json) - } - - String toWireMockClientJsonStub(groovyDsl) { - new WireMockStubStrategy(groovyDsl).toWireMockClientStub() - } - @Issue("#121") def 'should generate stub with empty list as a value of a field'() { given: @@ -1200,7 +1188,7 @@ class WireMockGroovyDslSpec extends WireMockSpec { request { method('POST') body( - values: [] + values: [] ) } response { @@ -1228,4 +1216,16 @@ class WireMockGroovyDslSpec extends WireMockSpec { and: stubMappingIsValidWireMockStub(wireMockStub) } + + String toJsonString(value) { + new JsonBuilder(value).toPrettyString() + } + + Object parseJson(json) { + new JsonSlurper().parseText(json) + } + + String toWireMockClientJsonStub(groovyDsl) { + new WireMockStubStrategy(groovyDsl).toWireMockClientStub() + } }