From 614f5438a887f6f67e4a190f1b5f5171b3814cd7 Mon Sep 17 00:00:00 2001 From: Jakub Kubrynski Date: Sat, 21 Feb 2015 13:16:04 +0100 Subject: [PATCH] Fix #24 - GroovyDSL -> JSON - issue with new lines --- .../accurest/dsl/internal/Body.groovy | 2 +- .../accurest/dsl/WiremockGroovyDslSpec.groovy | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/Body.groovy b/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/Body.groovy index 76723f7fac..f9442d0a8a 100644 --- a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/Body.groovy +++ b/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/Body.groovy @@ -26,7 +26,7 @@ class Body { } Body(Object bodyAsValue) { - this.bodyAsValue = new DslProperty(bodyAsValue) + this("${bodyAsValue}") } Body(GString bodyAsValue) { 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 c68b5643ec..6022b95d4d 100644 --- a/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WiremockGroovyDslSpec.groovy +++ b/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WiremockGroovyDslSpec.groovy @@ -108,6 +108,48 @@ class WiremockGroovyDslSpec extends Specification { ''') } + def 'should convert groovy dsl stub with simple Body as String to wiremock stub for the client side'() { + given: + GroovyDsl groovyDsl = GroovyDsl.make { + request { + method('GET') + urlPattern $(client('/[0-9]{2}'), server('/12')) + } + response { + status 200 + body("""\ + { + "name": "Jan" + } + """ + ) + headers { + header 'Content-Type': 'text/plain' + } + } + } + when: + String wiremockStub = new WiremockStubStrategy(groovyDsl).toWiremockClientStub() + then: + new JsonSlurper().parseText(wiremockStub) == new JsonSlurper().parseText(''' +{ + "request": { + "method": "GET", + "urlPattern": "/[0-9]{2}" + }, + "response": { + "status": 200, + "body": { + "name": "Jan" + }, + "headers": { + "Content-Type": "text/plain" + } + } +} +''') + } + def 'should convert groovy dsl stub with Body as String to wiremock stub for the server side'() { given: GroovyDsl groovyDsl = GroovyDsl.make {