Fix StackOverflow exception when stubTrigger runs contract with body based on json file (#1311)
* Fix StackOverflow exception when stubTrigger runs contract with body based on json file * Add test for extracting body value from json file * Extract value from file to map only in case file content is String
This commit is contained in:
committed by
Marcin Grzejszczak
parent
f849dc40c9
commit
d6098bbf2d
@@ -24,6 +24,7 @@ import groovy.transform.CompileStatic
|
||||
|
||||
import org.springframework.cloud.contract.spec.internal.CanBeDynamic
|
||||
import org.springframework.cloud.contract.spec.internal.DslProperty
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty
|
||||
import org.springframework.cloud.contract.spec.internal.RegexProperty
|
||||
|
||||
import static ContentUtils.extractValue
|
||||
@@ -89,6 +90,9 @@ class BodyExtractor {
|
||||
else if (bodyValue instanceof DslProperty) {
|
||||
return extractClientValueFromBody(bodyValue.clientValue)
|
||||
}
|
||||
else if (bodyValue instanceof FromFileProperty && bodyValue.isString()) {
|
||||
return MapConverter.transformValues(bodyValue.asString(), Closure.IDENTITY)
|
||||
}
|
||||
else {
|
||||
return MapConverter.transformValues(bodyValue, {
|
||||
Object prop = it instanceof DslProperty ? it.clientValue : it
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.springframework.cloud.contract.verifier.util
|
||||
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty
|
||||
import spock.lang.Specification
|
||||
|
||||
/**
|
||||
* @author Adam Białas
|
||||
*/
|
||||
class BodyExtractorSpec extends Specification {
|
||||
|
||||
def "should extract body from json file"() {
|
||||
given:
|
||||
def uri = BodyExtractorSpec.getResource("/classpath/response.json").toURI()
|
||||
def jsonFromFile = new FromFileProperty(new File(uri), String.class)
|
||||
expect:
|
||||
["status" : "RESPONSE"] == BodyExtractor.extractClientValueFromBody(jsonFromFile)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user