Return the actual object instead of the String used for matching the pattern (#654)

This commit is contained in:
Tim Ysewyn
2018-05-11 01:54:20 +02:00
committed by Marcin Grzejszczak
parent abecf1fc83
commit 3fe82362a8
2 changed files with 32 additions and 1 deletions

View File

@@ -37,7 +37,7 @@ abstract class PatternValueDslProperty<T extends DslProperty> {
if (!matches) {
throw new IllegalStateException("The generated value [${generatedValue}] doesn't match the pattern [${pattern.pattern()}]")
}
return createProperty(pattern, generatedValue)
return createProperty(pattern, object)
}
return createProperty(pattern, object)
}

View File

@@ -1,9 +1,12 @@
package org.springframework.cloud.contract.verifier.dsl.wiremock
import groovy.json.JsonSlurper
import org.springframework.cloud.contract.spec.Contract
import spock.lang.Issue
import spock.lang.Specification
class WireMockResponseStubStrategySpec extends Specification {
def "should not quote floating point numbers"() {
given:
def irrelevantStatus = 200
@@ -23,4 +26,32 @@ class WireMockResponseStubStrategySpec extends Specification {
then:
'{"value":1.5}'.equals(content.body)
}
@Issue("#468")
def "should not quote generated numbers"() {
given:
def irrelevantStatus = 200
def contract = Contract.make {
request {
}
response {
status irrelevantStatus
body([
number: anyNumber(),
integer: anyInteger(),
positiveInt: anyPositiveInt(),
double: anyDouble(),
])
}
}
when:
def subject = new WireMockResponseStubStrategy(contract)
def content = subject.buildClientResponseContent()
then:
Map body = new JsonSlurper().parseText(content.body) as Map
assert body.get("number") instanceof Number
assert body.get("integer") instanceof Integer
assert body.get("positiveInt") instanceof Integer
assert body.get("double") instanceof BigDecimal
}
}