[#79] Fixed the way wiremock stubs are built
This commit is contained in:
@@ -3,8 +3,10 @@ import groovy.json.JsonOutput
|
||||
import groovy.json.JsonSlurper
|
||||
import groovy.transform.TypeChecked
|
||||
import groovy.xml.XmlUtil
|
||||
import io.codearte.accurest.dsl.internal.DslProperty
|
||||
import io.codearte.accurest.dsl.internal.Header
|
||||
import io.codearte.accurest.dsl.internal.Headers
|
||||
import io.codearte.accurest.util.JsonConverter
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
@@ -12,6 +14,11 @@ import static groovy.json.StringEscapeUtils.escapeJava
|
||||
|
||||
@TypeChecked
|
||||
abstract class BaseWiremockStubStrategy {
|
||||
|
||||
private static Closure transform = {
|
||||
it instanceof DslProperty ? JsonConverter.transformValues(it.clientValue, transform) : it
|
||||
}
|
||||
|
||||
protected Map buildClientRequestHeadersSection(Headers headers) {
|
||||
if (!headers) {
|
||||
return null
|
||||
@@ -62,6 +69,7 @@ abstract class BaseWiremockStubStrategy {
|
||||
}
|
||||
|
||||
protected String parseBody(Map body) {
|
||||
return JsonOutput.toJson(body)
|
||||
def transformedMap = JsonConverter.transformValues(body, transform)
|
||||
return JsonOutput.toJson(transformedMap)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.codearte.accurest.dsl
|
||||
|
||||
import groovy.json.JsonBuilder
|
||||
import groovy.json.JsonSlurper
|
||||
import spock.lang.Issue
|
||||
|
||||
class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
|
||||
@@ -53,6 +54,53 @@ class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
}
|
||||
|
||||
@Issue("#79")
|
||||
def 'should convert groovy dsl stub to wiremock stub for the client side with a body containing a map'() {
|
||||
given:
|
||||
GroovyDsl groovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
method 'GET'
|
||||
url '/ingredients'
|
||||
headers {
|
||||
header 'Content-Type': 'application/vnd.pl.devoxx.aggregatr.v1+json'
|
||||
}
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body(
|
||||
ingredients: [
|
||||
[type: 'MALT', quantity: 100],
|
||||
[type: 'WATER', quantity: 200],
|
||||
[type: 'HOP', quantity: 300],
|
||||
[type: 'YIEST', quantity: 400]
|
||||
]
|
||||
)
|
||||
}
|
||||
}
|
||||
when:
|
||||
String wiremockStub = new WiremockStubStrategy(groovyDsl).toWiremockClientStub()
|
||||
then:
|
||||
new JsonSlurper().parseText(wiremockStub) == new JsonSlurper().parseText('''
|
||||
{
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"headers": {
|
||||
"Content-Type": {
|
||||
"equalTo": "application/vnd.pl.devoxx.aggregatr.v1+json"
|
||||
}
|
||||
},
|
||||
"url": "/ingredients"
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"body": "{\\"ingredients\\":[{\\"type\\":\\"MALT\\",\\"quantity\\":100},{\\"type\\":\\"WATER\\",\\"quantity\\":200},{\\"type\\":\\"HOP\\",\\"quantity\\":300},{\\"type\\":\\"YIEST\\",\\"quantity\\":400}]}"
|
||||
}
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
}
|
||||
|
||||
def 'should convert groovy dsl stub with Body as String to wiremock stub for the client side'() {
|
||||
given:
|
||||
GroovyDsl groovyDsl = GroovyDsl.make {
|
||||
|
||||
Reference in New Issue
Block a user