Merge branch '2.0.x'

This commit is contained in:
Marcin Grzejszczak
2018-10-24 22:45:15 +02:00
2 changed files with 13 additions and 3 deletions

View File

@@ -15,7 +15,6 @@ import org.yaml.snakeyaml.Yaml
import java.nio.file.Files
import java.util.regex.Pattern
/**
* @author Marcin Grzejszczak
*/
@@ -63,7 +62,7 @@ class YamlToContracts {
request {
method(yamlContract.request?.method)
if (yamlContract.request?.url) {
url(yamlContract.request?.url) {
url(urlValue(yamlContract.request?.url, yamlContract.request?.matchers?.url)) {
if (yamlContract.request.queryParameters) {
queryParameters {
yamlContract.request.queryParameters.each { String key, Object value ->
@@ -80,7 +79,7 @@ class YamlToContracts {
}
}
if (yamlContract.request?.urlPath) {
urlPath(yamlContract.request?.urlPath) {
urlPath(urlValue(yamlContract.request?.urlPath, yamlContract.request?.matchers?.url)) {
if (yamlContract.request.queryParameters) {
queryParameters {
yamlContract.request.queryParameters.each { String key, Object value ->
@@ -408,6 +407,15 @@ class YamlToContracts {
}
}
protected DslProperty urlValue(String url, YamlContract.KeyValueMatcher urlMatcher) {
if (urlMatcher) {
return new DslProperty(urlMatcher.regex ? Pattern.compile(urlMatcher.regex) :
urlMatcher.command ? new ExecutionProperty(urlMatcher.command) :
urlMatcher.predefined ? predefinedToPattern(urlMatcher.predefined) : url, url)
}
return new DslProperty(url)
}
protected List<YamlContract> convert(ObjectMapper mapper, Object o) {
try {
return Arrays.asList(mapper.convertValue(o, YamlContract[].class))

View File

@@ -189,6 +189,8 @@ class YamlContractConverterSpec extends Specification {
RegexPatterns patterns = new RegexPatterns()
contract.request.headers.entries.find { it.name == "Content-Type" &&
((Pattern) it.clientValue).pattern == "application/json.*" && it.serverValue == "application/json" }
((Pattern) contract.request.urlPath.clientValue).pattern() == "/get/[0-9]"
contract.request.urlPath.serverValue == "/get/1"
contract.request.urlPath.queryParameters.parameters.size() == 8
QueryParameters queryParameters = contract.request.urlPath.queryParameters
assertQueryParam(queryParameters, "limit", 10,