Added fixedDelayMilliseconds in yaml and docs; fixes gh-788

This commit is contained in:
Marcin Grzejszczak
2018-11-08 17:18:20 +01:00
parent e01af34151
commit 182aa430b5
5 changed files with 32 additions and 0 deletions

View File

@@ -1036,6 +1036,31 @@ response:
async: true
----
You can also use the `fixedDelayMilliseconds` method / property to add delay to your stubs.
.Groovy DSL
[source,groovy,indent=0]
----
org.springframework.cloud.contract.spec.Contract.make {
request {
method GET()
url '/get'
}
response {
status 200
body 'Passed'
fixedDelayMilliseconds 1000
}
}
----
.YAML
[source,yml,indent=0]
----
response:
fixedDelayMilliseconds: 1000
----
=== Working with Context Paths
Spring Cloud Contract supports context paths.

View File

@@ -157,6 +157,7 @@ class YamlContract {
public String bodyFromFile
public TestMatchers matchers = new TestMatchers()
public Boolean async
public Integer fixedDelayMilliseconds
}
@CompileStatic

View File

@@ -236,6 +236,7 @@ class YamlContractConverter implements ContractConverter<List<YamlContract>> {
if (yamlContract.response.body) body(yamlContract.response.body)
if (yamlContract.response.bodyFromFile) body(file(yamlContract.response.bodyFromFile))
if (yamlContract.response.async) async()
if (yamlContract.response.fixedDelayMilliseconds) fixedDelayMilliseconds(yamlContract.response.fixedDelayMilliseconds)
testMatchers {
yamlContract.response?.matchers?.body?.each { BodyTestMatcher testMatcher ->
MatchingTypeValue value = null
@@ -522,6 +523,7 @@ class YamlContractConverter implements ContractConverter<List<YamlContract>> {
maxOccurrence: matcher.maxTypeOccurrence()
)
}
fixedDelayMilliseconds = contract?.response?.delay?.clientValue as Integer
}
}
if (contract.input) {

View File

@@ -118,6 +118,7 @@ class YamlContractConverterSpec extends Specification {
contract.request.matchers.jsonPathRegexMatchers[0].value() == 'bar'
and:
contract.response.status.clientValue == 200
if (yamlFile == ymlWithRest) contract.response.delay.clientValue == 1000 else !contract.response.delay
contract.response.headers.entries.find { it.name == "foo2" &&
((Pattern) it.serverValue).pattern == "bar" && it.clientValue == "bar" }
contract.response.headers.entries.find { it.name == "foo3" &&
@@ -533,6 +534,7 @@ class YamlContractConverterSpec extends Specification {
body([foo: "bar"])
}
response {
fixedDelayMilliseconds 1000
status(200)
headers {
header("foo2", "bar")
@@ -560,5 +562,6 @@ class YamlContractConverterSpec extends Specification {
yamlContract.response.body == [foo2: "bar"]
yamlContract.response.cookies.find { it.key == "foo" && it.value == "client" }
yamlContract.response.cookies.find { it.key == "bar" && it.value == "client" }
yamlContract.response.fixedDelayMilliseconds == 1000
}
}

View File

@@ -52,6 +52,7 @@ response:
#tag::response_obligatory[]
status: 200
#end::response_obligatory[]
fixedDelayMilliseconds: 1000
headers:
foo2: bar
foo3: foo33