From f6b716bad54bc32fb80f20d9681ad8ec74f9b723 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Fri, 13 Nov 2015 17:58:21 +0100 Subject: [PATCH] [#171] Added upercase method for JaxRs, fixes #171 --- .../JaxRsClientSpockMethodBodyBuilder.groovy | 4 +-- .../JaxRsClientSpockMethodBuilderSpec.groovy | 33 +++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/builder/JaxRsClientSpockMethodBodyBuilder.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/builder/JaxRsClientSpockMethodBodyBuilder.groovy index d17b8a4b84..abf43d77fc 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/builder/JaxRsClientSpockMethodBodyBuilder.groovy +++ b/accurest-core/src/main/groovy/io/codearte/accurest/builder/JaxRsClientSpockMethodBodyBuilder.groovy @@ -66,9 +66,9 @@ class JaxRsClientSpockMethodBodyBuilder extends SpockMethodBodyBuilder { String method = request.method.serverValue.toString().toLowerCase() if (request.body) { String contentType = getHeader('Content-Type') ?: getRequestContentType().mimeType - bb.addLine(".method('$method', entity('$bodyAsString', '$contentType'))") + bb.addLine(".method('${method.toUpperCase()}', entity('$bodyAsString', '$contentType'))") } else { - bb.addLine(".method('$method')") + bb.addLine(".method('${method.toUpperCase()}')") } } diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/builder/JaxRsClientSpockMethodBuilderSpec.groovy b/accurest-core/src/test/groovy/io/codearte/accurest/builder/JaxRsClientSpockMethodBuilderSpec.groovy index e93e9e5035..d8d13e124f 100644 --- a/accurest-core/src/test/groovy/io/codearte/accurest/builder/JaxRsClientSpockMethodBuilderSpec.groovy +++ b/accurest-core/src/test/groovy/io/codearte/accurest/builder/JaxRsClientSpockMethodBuilderSpec.groovy @@ -450,16 +450,45 @@ class JaxRsClientSpockMethodBuilderSpec extends Specification implements WireMoc body "test" } } - MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl) + JaxRsClientSpockMethodBodyBuilder builder = new JaxRsClientSpockMethodBodyBuilder(contractDsl) BlockBuilder blockBuilder = new BlockBuilder(" ") when: builder.appendTo(blockBuilder) def spockTest = blockBuilder.toString() then: - spockTest.contains('def responseBody = (response.body.asString())') + spockTest.contains('String responseAsString = response.readEntity(String)') spockTest.contains('responseBody == "test"') and: stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) } + @Issue('#171') + def "should generate test with uppercase method name"() { + given: + GroovyDsl contractDsl = GroovyDsl.make { + request { + method "get" + url "/v1/some_cool_requests/e86df6f693de4b35ae648464c5b0dc08" + } + response { + status 200 + headers { + header('Content-Type': 'application/json;charset=UTF-8') + } + body """ +{"id":"789fgh","other_data":1268} +""" + } + } + JaxRsClientSpockMethodBodyBuilder builder = new JaxRsClientSpockMethodBodyBuilder(contractDsl) + BlockBuilder blockBuilder = new BlockBuilder(" ") + when: + builder.appendTo(blockBuilder) + def spockTest = blockBuilder.toString() + then: + spockTest.contains(".method('GET')") + and: + stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + } + }