From ce42dd5e85c3aa91ae8e4884893bb265ca897cd0 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Mon, 11 May 2015 18:17:06 +0200 Subject: [PATCH] [#55] Fixed regex processing on the server side --- .../builder/SpockMethodBodyBuilder.groovy | 7 +++++++ .../accurest/dsl/internal/Common.groovy | 4 ++++ .../dsl/internal/MethodProperty.groovy | 13 ++++++++++++ .../pairId/moreComplexVersion.groovy | 20 +++++++++++++++++++ .../ofg/twitter/place/PairIdController.groovy | 7 ++++++- 5 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/MethodProperty.groovy create mode 100644 accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/repository/mappings/com/ofg/twitter-places-analyzer/pairId/moreComplexVersion.groovy diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/builder/SpockMethodBodyBuilder.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/builder/SpockMethodBodyBuilder.groovy index 25ebd02b99..babee4264c 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/builder/SpockMethodBodyBuilder.groovy +++ b/accurest-core/src/main/groovy/io/codearte/accurest/builder/SpockMethodBodyBuilder.groovy @@ -5,6 +5,8 @@ import groovy.transform.PackageScope import io.codearte.accurest.dsl.GroovyDsl import io.codearte.accurest.dsl.internal.Header +import java.util.regex.Pattern + /** * @author Jakub Kubrynski */ @@ -73,6 +75,8 @@ class SpockMethodBodyBuilder { processMapElement(value, blockBuilder, property) } else if (value instanceof List) { processArrayElements(value, property, blockBuilder) + } else if (value instanceof Pattern) { + blockBuilder.addLine("responseBody$property ==~ java.util.regex.Pattern.compile('${value}')") } else { blockBuilder.addLine("responseBody$property == ${value}") } @@ -90,4 +94,7 @@ class SpockMethodBodyBuilder { } } } + private void processClosure(Closure value, BlockBuilder blockBuilder, String property) { + blockBuilder.addLine() + } } 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 f6eb65ab9e..864c52efe4 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 @@ -66,6 +66,10 @@ class Common { return Pattern.compile(regex) } + MethodProperty execute(String closureDefinition) { + return new MethodProperty(closureDefinition) + } + ClientDslProperty client(Object clientValue) { return new ClientDslProperty(clientValue) } diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/MethodProperty.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/MethodProperty.groovy new file mode 100644 index 0000000000..b707a8a7c1 --- /dev/null +++ b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/MethodProperty.groovy @@ -0,0 +1,13 @@ +package io.codearte.accurest.dsl.internal + +import groovy.transform.CompileStatic + +@CompileStatic +class MethodProperty { + + final String closureDefinition + + MethodProperty(String closureDefinition) { + this.closureDefinition = closureDefinition + } +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/repository/mappings/com/ofg/twitter-places-analyzer/pairId/moreComplexVersion.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/repository/mappings/com/ofg/twitter-places-analyzer/pairId/moreComplexVersion.groovy new file mode 100644 index 0000000000..9937b43721 --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/repository/mappings/com/ofg/twitter-places-analyzer/pairId/moreComplexVersion.groovy @@ -0,0 +1,20 @@ +io.codearte.accurest.dsl.GroovyDsl.make { + request { + method 'PUT' + url $(client(regex('^/api/[0-9]{2}$')), server('/api/12')) + headers { + header 'Content-Type': 'application/json' + } + body '''\ + [{ + "text": "Gonna see you at Warsaw" + }] +''' + } + response { + body ( + path: $(client('/api/12'), server(regex('^/api/[0-9]{2}$'))) + ) + status 200 + } +} \ No newline at end of file diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/main/groovy/com/ofg/twitter/place/PairIdController.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/main/groovy/com/ofg/twitter/place/PairIdController.groovy index 8a4e1e2e63..ee02469454 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/main/groovy/com/ofg/twitter/place/PairIdController.groovy +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/main/groovy/com/ofg/twitter/place/PairIdController.groovy @@ -21,10 +21,15 @@ class PairIdController { method = PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - void getPlacesFromTweets(@PathVariable long pairId, @RequestBody List tweets) { + String getPlacesFromTweets(@PathVariable long pairId, @RequestBody List tweets) { log.info("Inside PairIdController, doing very important logic") if (tweets?.text != ["Gonna see you at Warsaw"]) { throw new IllegalArgumentException("Wrong text in tweet: ${tweets?.text}") } + return """ + { + "path" : "/api/$pairId" + } + """ } }