DslProperty doesn't get resolved in WireMock stub headers

without this change we're using directly the clientSide value of the DslProperty, whereas it can be nested
with this change we resolve the final value of the DslProperty

fixes #408
This commit is contained in:
Marcin Grzejszczak
2017-09-01 16:46:56 +02:00
parent 38028b5b07
commit 4c08408e66
2 changed files with 6 additions and 5 deletions

View File

@@ -26,6 +26,7 @@ import org.springframework.cloud.contract.spec.Contract
import org.springframework.cloud.contract.spec.internal.Request
import org.springframework.cloud.contract.spec.internal.Response
import org.springframework.cloud.contract.verifier.util.ContentType
import org.springframework.cloud.contract.verifier.util.MapConverter
import static org.springframework.cloud.contract.verifier.util.ContentUtils.recognizeContentTypeFromContent
import static org.springframework.cloud.contract.verifier.util.ContentUtils.recognizeContentTypeFromHeader
@@ -51,7 +52,7 @@ class WireMockResponseStubStrategy extends BaseWireMockStubStrategy {
return null
}
ResponseDefinitionBuilder builder = new ResponseDefinitionBuilder()
.withStatus(response.status.clientValue as Integer)
.withStatus(MapConverter.getStubSideValues(response.status) as Integer)
appendHeaders(builder)
appendBody(builder)
appendResponseDelayTime(builder)
@@ -62,7 +63,7 @@ class WireMockResponseStubStrategy extends BaseWireMockStubStrategy {
private void appendHeaders(ResponseDefinitionBuilder builder) {
if (response.headers) {
builder.withHeaders(new HttpHeaders(response.headers.entries?.collect {
new HttpHeader(it.name, it.clientValue.toString())
new HttpHeader(it.name, MapConverter.getStubSideValues(it.clientValue).toString())
}))
}
}

View File

@@ -1755,7 +1755,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
response {
status 200
headers {
header(authorization(), fromRequest().header(authorization()))
header(authorization(), "${fromRequest().header(authorization())};foo")
}
body(
url: fromRequest().url(),
@@ -1798,7 +1798,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
"status" : 200,
"body" : "{\\"url\\":\\"{{{request.url}}}\\",\\"param\\":\\"{{{request.query.foo.[0]}}}\\",\\"paramIndex\\":\\"{{{request.query.foo.[1]}}}\\",\\"authorization\\":\\"{{{request.headers.Authorization.[0]}}}\\",\\"authorization2\\":\\"{{{request.headers.Authorization.[1]}}}\\",\\"fullBody\\":\\"{{{escapejsonbody}}}\\",\\"responseFoo\\":\\"{{{jsonpath this '$.foo'}}}\\",\\"responseBaz\\":{{{jsonpath this '$.baz'}}} ,\\"responseBaz2\\":\\"Bla bla {{{jsonpath this '$.foo'}}} bla bla\\"}",
"headers" : {
"Authorization" : "{{{request.headers.Authorization.[0]}}}"
"Authorization" : "{{{request.headers.Authorization.[0]}}};foo"
},
"transformers" : [ "response-template" ]
}
@@ -1813,7 +1813,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
server.addStubMapping(WireMockStubMapping.buildFrom(json))
then:
ResponseEntity<String> entity = call(port)
entity.headers.find { it.key == "Authorization" && it.value.contains("secret") }
entity.headers.find { it.key == "Authorization" && it.value.contains("secret;foo") }
and:
AssertionUtil.assertThatJsonsAreEqual(('''
{