From 23446397ba8e2e292a6b24500141e5310b1ac899 Mon Sep 17 00:00:00 2001 From: Adam Wojszczyk Date: Mon, 24 Aug 2015 16:13:04 +0200 Subject: [PATCH] [#127] Add stub as an alias for client and test as an alias for server --- .../accurest/dsl/internal/Common.groovy | 8 +++++ .../MockMvcSpockMethodBuilderSpec.groovy | 31 ++++++++++++++++ .../accurest/dsl/WireMockGroovyDslSpec.groovy | 36 +++++++++++++++++++ 3 files changed, 75 insertions(+) diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Common.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Common.groovy index 9030d9b9f3..6cb78b67ba 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Common.groovy +++ b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Common.groovy @@ -78,10 +78,18 @@ class Common { return new ClientDslProperty(clientValue) } + ClientDslProperty stub(Object clientValue) { + return new ClientDslProperty(clientValue) + } + ServerDslProperty server(Object serverValue) { return new ServerDslProperty(serverValue) } + ServerDslProperty test(Object serverValue) { + return new ServerDslProperty(serverValue) + } + void assertThatSidesMatch(Pattern pattern, String value) { assert value ==~ pattern } diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcSpockMethodBuilderSpec.groovy b/accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcSpockMethodBuilderSpec.groovy index 6d2ed106d1..4875a1f744 100644 --- a/accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcSpockMethodBuilderSpec.groovy +++ b/accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcSpockMethodBuilderSpec.groovy @@ -329,6 +329,37 @@ class MockMvcSpockMethodBuilderSpec extends Specification { spockTest.contains('responseBody == "test"') } + @Issue("#127") + def 'should use "stub" as an alias for "client"'() { + given: + GroovyDsl contractDsl = GroovyDsl.make { + request { + method "GET" + url "test" + } + response { + status 200 + body( + property: value( + stub(123), + test(123) + ) + ) + headers { + header('Content-Type': 'application/json') + + } + + } + } + MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl) + BlockBuilder blockBuilder = new BlockBuilder(" ") + when: + builder.appendTo(blockBuilder) + then: + blockBuilder.toString().contains("responseBody.property == 123") + } + @Issue('113') def "should generate regex test for String in response header"() { given: 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 1867c49eda..cb0a75255a 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,6 +1181,42 @@ class WireMockGroovyDslSpec extends WireMockSpec { ''') } + @Issue("#127") + def 'should use "test" as an alias for "server"'() { + given: + GroovyDsl groovyDsl = GroovyDsl.make { + request { + method('POST') + body( + property: value(stub("value"), test("value")) + ) + } + response { + status 200 + } + } + when: + String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub() + then: + new JsonSlurper().parseText(wireMockStub) == new JsonSlurper().parseText(''' + { + "request": { + "method": "POST", + "bodyPatterns": [ + { + "equalToJson": "{\\"property\\":\\"value\\"}" + } + ] + }, + "response": { + "status": 200 + } + } + ''') + and: + stubMappingIsValidWireMockStub(wireMockStub) + } + @Issue("#121") def 'should generate stub with empty list as a value of a field'() { given: