Merge branch '2.1.x'
This commit is contained in:
@@ -152,7 +152,7 @@ class JsonBodyVerificationBuilder implements BodyMethodGeneration, ClassVerifier
|
||||
retrievedValue = retrievedValue instanceof RegexProperty ?
|
||||
((RegexProperty) retrievedValue).getPattern().pattern() : retrievedValue
|
||||
String valueAsParam = retrievedValue instanceof String ?
|
||||
quotedAndEscaped(retrievedValue.toString()) : retrievedValue.toString()
|
||||
quotedAndEscaped(retrievedValue.toString()) : objectToString(retrievedValue)
|
||||
if (arrayRelated(path) && MatchingType.regexRelated(bodyMatcher.matchingType())) {
|
||||
buildCustomMatchingConditionForEachElement(bb, path, valueAsParam)
|
||||
}
|
||||
@@ -166,6 +166,11 @@ class JsonBodyVerificationBuilder implements BodyMethodGeneration, ClassVerifier
|
||||
addColonIfRequired(lineSuffix, bb)
|
||||
}
|
||||
|
||||
private String objectToString(Object value) {
|
||||
return value instanceof Long
|
||||
? String.valueOf(value).concat("L") : String.valueOf(value)
|
||||
}
|
||||
|
||||
protected String processIfTemplateIsPresent(String method, DocumentContext parsedRequestBody) {
|
||||
if (textContainsJsonPathTemplate(method) && contract.request?.body) {
|
||||
// Unquoting the values of non strings
|
||||
|
||||
@@ -27,6 +27,7 @@ import spock.lang.Specification
|
||||
import org.springframework.boot.test.rule.OutputCapture
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
import org.springframework.cloud.contract.verifier.converter.YamlContractConverter
|
||||
import org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockStubVerifier
|
||||
import org.springframework.cloud.contract.verifier.util.ContractVerifierDslConverter
|
||||
import org.springframework.cloud.contract.verifier.util.SyntaxChecker
|
||||
@@ -1356,4 +1357,54 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, classDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue("#1052")
|
||||
def "should work with large numbers [#methodBuilderName]"() {
|
||||
given:
|
||||
String yaml = '''\
|
||||
request:
|
||||
url: /numbers
|
||||
queryParameters:
|
||||
page: 0
|
||||
size: 2
|
||||
method: GET
|
||||
headers:
|
||||
Content-Type: application/json
|
||||
|
||||
response:
|
||||
status: 200
|
||||
headers:
|
||||
Content-Type: application/json;charset=UTF-8
|
||||
body:
|
||||
- number: 1541609556000
|
||||
- number: 1541609316000
|
||||
matchers:
|
||||
body:
|
||||
- path: $.[0].number
|
||||
type: by_equality
|
||||
- path: $.[1].number
|
||||
type: by_equality
|
||||
'''
|
||||
File tmpFile = File.createTempFile("foo", ".yml")
|
||||
tmpFile.createNewFile()
|
||||
tmpFile.text = yaml
|
||||
Contract contractDsl = new YamlContractConverter().convertFrom(tmpFile).first()
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
then:
|
||||
String test = blockBuilder.toString()
|
||||
SyntaxChecker.tryToCompileWithoutCompileStatic(methodBuilderName, test)
|
||||
!test.contains('''(1541609556000)''')
|
||||
test.contains('''(1541609556000L)''')
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, classDataForMethod) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, classDataForMethod) }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, classDataForMethod) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, classDataForMethod) }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
request:
|
||||
url: /numbers
|
||||
queryParameters:
|
||||
page: 0
|
||||
size: 2
|
||||
method: GET
|
||||
headers:
|
||||
Content-Type: application/json
|
||||
|
||||
response:
|
||||
status: 200
|
||||
headers:
|
||||
Content-Type: application/json;charset=UTF-8
|
||||
body:
|
||||
- number: 1541609556000
|
||||
- number: 1541609316000
|
||||
matchers:
|
||||
body:
|
||||
- path: $.[0].number
|
||||
type: by_equality
|
||||
- path: $.[1].number
|
||||
type: by_equality
|
||||
Reference in New Issue
Block a user