[#55] Fixed regex processing on the server side
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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<Tweet> tweets) {
|
||||
String getPlacesFromTweets(@PathVariable long pairId, @RequestBody List<com.ofg.twitter.place.Tweet> 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"
|
||||
}
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user