Merge branch '2.1.x'
This commit is contained in:
@@ -357,7 +357,12 @@ class DslToYamlContractConverterSpec extends Specification {
|
||||
List<Contract> contracts = [Contract.make {
|
||||
request { // (1)
|
||||
method 'PUT' // (2)
|
||||
url '/fraudcheck' // (3)
|
||||
urlPath('/fraudcheck') {
|
||||
queryParameters {
|
||||
parameter("foo", "bar")
|
||||
parameter("foo2", $(c(equalToJson('''{"foo":"bar"}''')), p("foo3")))
|
||||
}
|
||||
}
|
||||
body([ // (4)
|
||||
"client.id": $(regex('[0-9]{10}')),
|
||||
loanAmount : 99999
|
||||
@@ -384,11 +389,15 @@ class DslToYamlContractConverterSpec extends Specification {
|
||||
yamlContracts.size() == 1
|
||||
YamlContract yamlContract = yamlContracts.first()
|
||||
yamlContract.request.method == "PUT"
|
||||
yamlContract.request.url == "/fraudcheck"
|
||||
yamlContract.request.urlPath == "/fraudcheck"
|
||||
yamlContract.request.queryParameters == [
|
||||
foo2: "foo3",
|
||||
foo : "bar"
|
||||
]
|
||||
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 == [
|
||||
@@ -402,6 +411,9 @@ class DslToYamlContractConverterSpec extends Specification {
|
||||
value: "[0-9]{10}",
|
||||
regexType: YamlContract.RegexType.as_string),
|
||||
]
|
||||
yamlContract.request.matchers.queryParameters == [
|
||||
new YamlContract.QueryParameterMatcher(key: "foo2", type: YamlContract.MatchingType.equal_to_json, value: '''{"foo":"bar"}'''),
|
||||
]
|
||||
yamlContract.response.status == 200
|
||||
yamlContract.response.body == [fraudCheckStatus : "FRAUD",
|
||||
"rejection.reason": "Amount too high"]
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2013-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.contract.verifier.converter
|
||||
|
||||
import spock.lang.Specification
|
||||
|
||||
class YamlContractSpec extends Specification {
|
||||
|
||||
def "should convert to matching type from string"() {
|
||||
when:
|
||||
YamlContract.MatchingType type = YamlContract.MatchingType.from(string)
|
||||
then:
|
||||
type == expectedType
|
||||
where:
|
||||
string || expectedType
|
||||
"equalTo" || YamlContract.MatchingType.equal_to
|
||||
"equalToJson" || YamlContract.MatchingType.equal_to_json
|
||||
"containing" || YamlContract.MatchingType.containing
|
||||
"unknown" || null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user