Ensures that execute(...) is resolved properly for YAML conversion; fixes gh-1129
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.contract.verifier.converter
|
||||
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
@@ -41,7 +42,6 @@ import org.springframework.cloud.contract.verifier.util.MapConverter
|
||||
|
||||
import static org.springframework.cloud.contract.verifier.util.ContentType.XML
|
||||
import static org.springframework.cloud.contract.verifier.util.ContentUtils.evaluateContentType
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
* @author Olga Maciaszek-Sharma
|
||||
@@ -141,7 +141,11 @@ class ContractsToYaml {
|
||||
request.urlPath = contract.request?.urlPath?.serverValue
|
||||
request.headers = (contract.request?.headers as Headers)?.asMap {
|
||||
String headerName, DslProperty prop ->
|
||||
MapConverter.getTestSideValues(prop).toString()
|
||||
def testSideValue = MapConverter.getTestSideValues(prop)
|
||||
if (testSideValue instanceof ExecutionProperty) {
|
||||
return MapConverter.getStubSideValuesForNonBody(prop).toString()
|
||||
}
|
||||
return testSideValue.toString()
|
||||
}
|
||||
request.cookies = (contract.request?.cookies as Cookies)?.asTestSideMap()
|
||||
Object body = contract.request?.body?.serverValue
|
||||
|
||||
@@ -25,7 +25,8 @@ import org.springframework.cloud.contract.spec.ContractConverter
|
||||
/**
|
||||
* Simple converter from and to a {@link YamlContract} to a collection of {@link Contract}
|
||||
*
|
||||
* @since 1.2.1* @author Marcin Grzejszczak
|
||||
* @since 1.2.1
|
||||
* @author Marcin Grzejszczak
|
||||
* @author Tim Ysewyn
|
||||
*/
|
||||
@CompileStatic
|
||||
|
||||
@@ -361,6 +361,7 @@ class DslToYamlContractConverterSpec extends Specification {
|
||||
])
|
||||
headers { // (5)
|
||||
contentType('application/json')
|
||||
header(authorization(), $(c('Bearer SOMETOKEN'), p(execute('authToken()'))))
|
||||
}
|
||||
}
|
||||
response { // (6)
|
||||
@@ -384,7 +385,8 @@ class DslToYamlContractConverterSpec extends Specification {
|
||||
yamlContract.request.body["client.id"] =~ /[0-9]{10}/
|
||||
yamlContract.request.body["loanAmount"] == 99999
|
||||
yamlContract.request.headers == [
|
||||
"Content-Type": "application/json"
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": 'Bearer SOMETOKEN'
|
||||
]
|
||||
yamlContract.request.matchers.headers == [
|
||||
new YamlContract.KeyValueMatcher(
|
||||
@@ -553,8 +555,8 @@ class DslToYamlContractConverterSpec extends Specification {
|
||||
yamlContract.request.method == 'GET'
|
||||
yamlContract.request.url == '/get'
|
||||
yamlContract.request.body.replaceAll("\n", "")
|
||||
.replaceAll(' ', '') == xmlContractBody.replaceAll("\n", "")
|
||||
.replaceAll(' ', '')
|
||||
.replaceAll(' ', '') == xmlContractBody.replaceAll("\n", "")
|
||||
.replaceAll(' ', '')
|
||||
yamlContract.request.headers == [
|
||||
"Content-Type": "application/xml"
|
||||
]
|
||||
@@ -566,8 +568,8 @@ class DslToYamlContractConverterSpec extends Specification {
|
||||
]
|
||||
yamlContract.response.status == 200
|
||||
yamlContract.response.body.replaceAll("\n", "")
|
||||
.replaceAll(' ', '') == xmlContractBody.replaceAll("\n", "")
|
||||
.replaceAll(' ', '')
|
||||
.replaceAll(' ', '') == xmlContractBody.replaceAll("\n", "")
|
||||
.replaceAll(' ', '')
|
||||
yamlContract.response.matchers.body == [
|
||||
new YamlContract.BodyTestMatcher(
|
||||
path: '/test/duck/xxx',
|
||||
|
||||
Reference in New Issue
Block a user