WIP on the Wiremock stubs fix with bodyPattern matches

This commit is contained in:
Marcin Grzejszczak
2015-05-14 00:35:00 +02:00
parent 9b9bca3161
commit ad2c8b23e3
2 changed files with 65 additions and 2 deletions

View File

@@ -39,7 +39,9 @@ class WiremockRequestStubStrategy extends BaseWiremockStubStrategy {
return [:]
}
if (containsRegex(body)) {
return [bodyPatterns: [[matches: parseBody(JsonConverter.transformValues(body, { it.toString() }))]]]
return [bodyPatterns: [[matches: parseBody(JsonConverter.transformValues(body, {
it instanceof Pattern ? it.toString() : it
}))]]]
}
return [bodyPatterns: [[equalTo: parseBody(body)]]]
}

View File

@@ -148,7 +148,6 @@ class WiremockGroovyDslSpec extends WiremockSpec {
stubMappingIsValidWiremockStub(wiremockStub)
}
def 'should convert groovy dsl stub with regexp Body as String to wiremock stub for the client side'() {
given:
GroovyDsl groovyDsl = GroovyDsl.make {
@@ -201,6 +200,68 @@ class WiremockGroovyDslSpec extends WiremockSpec {
stubMappingIsValidWiremockStub(wiremockStub)
}
def 'should convert groovy dsl stub with a regexp and an integer in request body'() {
given:
GroovyDsl groovyDsl = GroovyDsl.make {
request {
method 'PUT'
url '/fraudcheck'
body("""
{
"clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}",
"loanAmount":123.123
}
"""
)
headers {
header('Content-Type', 'application/vnd.fraud.v1+json')
}
}
response {
status 200
body(
fraudCheckStatus: "OK",
rejectionReason: $(client(null), server(execute('assertThatRejectionReasonIsNull($it)')))
)
headers {
header('Content-Type': 'application/vnd.fraud.v1+json')
}
}
}
when:
String wiremockStub = new WiremockStubStrategy(groovyDsl).toWiremockClientStub()
then:
new JsonSlurper().parseText(wiremockStub) == new JsonSlurper().parseText('''
{
"request": {
"method": "PUT",
"headers": {
"Content-Type": {
"equalTo": "application/vnd.fraud.v1+json"
}
},
"url": "/fraudcheck",
"bodyPatterns": [
{
"matches": "\\\\{\\"clientPesel\\":\\"[0-9]{10}\\",\\"loanAmount\\":123.123\\\\}"
}
]
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/vnd.fraud.v1+json"
},
"body": "{\\"fraudCheckStatus\\":\\"OK\\",\\"rejectionReason\\":null}"
}
}
''')
and:
stubMappingIsValidWiremockStub(wiremockStub)
}
def "should generate stub with GET"() {
given: