Merge branch '3.1.x' into 4.0.x
This commit is contained in:
@@ -176,12 +176,17 @@ class ContractsToYaml {
|
||||
}
|
||||
|
||||
private void mapRequestMatchersUrl(YamlContract.Request yamlContractRequest, Request request) {
|
||||
Object url = Optional.ofNullable(request.getUrl()).map(Url::getClientValue).orElse(null);
|
||||
Object url = Optional.ofNullable(request.getUrl()).map(Url::getClientValue)
|
||||
.orElse(Optional.ofNullable(request.getUrlPath()).map(Url::getClientValue).orElse(null));
|
||||
YamlContract.KeyValueMatcher keyValueMatcher = new YamlContract.KeyValueMatcher();
|
||||
if (url instanceof RegexProperty) {
|
||||
keyValueMatcher.regex = ((RegexProperty) url).pattern();
|
||||
yamlContractRequest.matchers.url = keyValueMatcher;
|
||||
}
|
||||
else if (url instanceof Pattern) {
|
||||
keyValueMatcher.regex = ((Pattern) url).pattern();
|
||||
yamlContractRequest.matchers.url = keyValueMatcher;
|
||||
}
|
||||
else if (url instanceof ExecutionProperty) {
|
||||
keyValueMatcher.command = url.toString();
|
||||
yamlContractRequest.matchers.url = keyValueMatcher;
|
||||
@@ -189,19 +194,6 @@ class ContractsToYaml {
|
||||
else {
|
||||
yamlContractRequest.matchers.url = null;
|
||||
}
|
||||
|
||||
Object urlPath = Optional.ofNullable(request.getUrlPath()).map(Url::getClientValue).orElse(null);
|
||||
if (urlPath instanceof RegexProperty) {
|
||||
keyValueMatcher.regex = ((RegexProperty) urlPath).pattern();
|
||||
yamlContractRequest.matchers.url = keyValueMatcher;
|
||||
}
|
||||
else if (urlPath instanceof ExecutionProperty) {
|
||||
keyValueMatcher.command = urlPath.toString();
|
||||
yamlContractRequest.matchers.url = keyValueMatcher;
|
||||
}
|
||||
else {
|
||||
yamlContractRequest.matchers.url = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void mapRequestMatchersBody(YamlContract.Request yamlContractRequest, Request request) {
|
||||
@@ -557,7 +549,7 @@ class ContractsToYaml {
|
||||
|
||||
protected YamlContract.StubMatcherType stubMatcherType(MatchingType matchingType) {
|
||||
if (matchingType == MatchingType.COMMAND || matchingType == MatchingType.TYPE) {
|
||||
throw new UnsupportedOperationException("No type or command for client side");
|
||||
return null;
|
||||
}
|
||||
return STUB_MATCHER_TYPE.getOrDefault(matchingType, null);
|
||||
}
|
||||
|
||||
@@ -389,6 +389,41 @@ class YamlContractConverterSpec extends Specification {
|
||||
urlPropertyName << ['url', 'urlPath']
|
||||
}
|
||||
|
||||
@Issue('#1921')
|
||||
def 'should convert YAML to Contract and back to YAML without losing url information'() {
|
||||
given:
|
||||
File ymlMatchers = File.createTempFile('contract_matchers_url', '.yml').with {
|
||||
write YamlContractConverterSpec.getResource('/yml/contract_matchers_url.yml')
|
||||
.text
|
||||
return it
|
||||
}
|
||||
expect:
|
||||
converter.isAccepted(ymlMatchers)
|
||||
when:
|
||||
Collection<Contract> contracts = converter.convertFrom(ymlMatchers)
|
||||
List<YamlContract> convertedBack = converter.convertTo(contracts)
|
||||
then:
|
||||
convertedBack.size() == 1
|
||||
convertedBack[0].request.matchers.url.regex == "/get/[0-9]"
|
||||
}
|
||||
|
||||
@Issue('#1921')
|
||||
def 'should convert YAML to Contract and back to YAML without exceptions'() {
|
||||
given:
|
||||
File ymlMatchers = File.createTempFile('contract_matchers', '.yml').with {
|
||||
write YamlContractConverterSpec.getResource('/yml/contract_matchers.yml')
|
||||
.text
|
||||
return it
|
||||
}
|
||||
expect:
|
||||
converter.isAccepted(ymlMatchers)
|
||||
when:
|
||||
Collection<Contract> contracts = converter.convertFrom(ymlMatchers)
|
||||
List<YamlContract> convertedBack = converter.convertTo(contracts)
|
||||
then:
|
||||
convertedBack.size() == 1
|
||||
}
|
||||
|
||||
protected Object assertQueryParam(QueryParameters queryParameters, String queryParamName, Object serverValue,
|
||||
MatchingStrategy.Type clientType, Object clientValue) {
|
||||
if (clientType == MatchingStrategy.Type.ABSENT) {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
request:
|
||||
method: GET
|
||||
urlPath: /get/1
|
||||
matchers:
|
||||
url:
|
||||
regex: /get/[0-9]
|
||||
response:
|
||||
status: 200
|
||||
Reference in New Issue
Block a user