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-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" + } + """ } }