From 6ace68284c80ce024c6fab7ce8b93d339379ef6c Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Wed, 11 Apr 2018 12:34:23 +0200 Subject: [PATCH] Added docs --- docs/src/main/asciidoc/verifier_contract.adoc | 19 ++++++++++++++-- .../builder/ContractHttpDocsSpec.groovy | 22 +++++++++++++++++++ .../src/test/resources/yml/contract.yml | 12 +++++++++- .../yml/contract_broken_request_headers.yml | 14 +++++++++++- 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/docs/src/main/asciidoc/verifier_contract.adoc b/docs/src/main/asciidoc/verifier_contract.adoc index f60565e9c6..d41b2c6b16 100644 --- a/docs/src/main/asciidoc/verifier_contract.adoc +++ b/docs/src/main/asciidoc/verifier_contract.adoc @@ -257,6 +257,22 @@ include::{verifier_core_path}/src/test/resources/yml/contract.yml[tags=request,i include::{verifier_core_path}/src/test/resources/yml/contract.yml[tags=headers,indent=0] ---- +`request` may contain additional **request cookies**, as shown in the following example: + +.Groovy DSL +[source,groovy,indent=0] +---- +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/ContractHttpDocsSpec.groovy[tags=cookies,indent=0] +---- + +.YAML +[source,yml,indent=0] +---- +include::{verifier_core_path}/src/test/resources/yml/contract.yml[tags=request,indent=0] +... +include::{verifier_core_path}/src/test/resources/yml/contract.yml[tags=cookies,indent=0] +---- + `request` may contain a **request body**: .Groovy DSL @@ -357,8 +373,7 @@ include::{verifier_core_path}/src/test/resources/yml/contract.yml[tags=response, include::{verifier_core_path}/src/test/resources/yml/contract.yml[tags=response_obligatory,indent=0] ---- - -Besides status, the response may contain **headers** and a **body**, both of which are +Besides status, the response may contain **headers**, **cookies** and a **body**, both of which are specified the same way as in the request (see the previous paragraph). === Dynamic properties diff --git a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/ContractHttpDocsSpec.groovy b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/ContractHttpDocsSpec.groovy index 81935cdf3f..7683e1c78b 100644 --- a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/ContractHttpDocsSpec.groovy +++ b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/ContractHttpDocsSpec.groovy @@ -153,6 +153,28 @@ class ContractHttpDocsSpec extends Specification { } // end::headers[] + org.springframework.cloud.contract.spec.Contract cookies = + // tag::cookies[] + org.springframework.cloud.contract.spec.Contract.make { + request { + //... + + // Each Cookies is added in form `'Cookie-Key' : 'Cookie-Value'`. + // there are also some helper methods + cookies { + cookie 'key': 'value' + cookie('another_key', 'another_value') + } + + //... + } + + response { + //... + } + } + // end::cookies[] + org.springframework.cloud.contract.spec.Contract body = // tag::body[] org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-verifier/src/test/resources/yml/contract.yml b/spring-cloud-contract-verifier/src/test/resources/yml/contract.yml index 0e25f7399a..2d88b73c9b 100644 --- a/spring-cloud-contract-verifier/src/test/resources/yml/contract.yml +++ b/spring-cloud-contract-verifier/src/test/resources/yml/contract.yml @@ -27,6 +27,11 @@ request: foo: bar fooReq: baz #end::headers[] +#tag::cookies[] + cookies: + foo: bar + fooReq: baz +#end::cookies[] #tag::body[] body: foo: bar @@ -66,4 +71,9 @@ response: - key: foo2 regex: bar - key: foo3 - command: andMeToo($it) \ No newline at end of file + command: andMeToo($it) + cookies: + - key: foo2 + regex: bar + - key: foo3 + predefined: \ No newline at end of file diff --git a/spring-cloud-contract-verifier/src/test/resources/yml/contract_broken_request_headers.yml b/spring-cloud-contract-verifier/src/test/resources/yml/contract_broken_request_headers.yml index 75bacd859d..ce29c2173e 100644 --- a/spring-cloud-contract-verifier/src/test/resources/yml/contract_broken_request_headers.yml +++ b/spring-cloud-contract-verifier/src/test/resources/yml/contract_broken_request_headers.yml @@ -24,6 +24,11 @@ response: fooRes: baz body: foo2: bar + cookies: + foo: baz + fooRegex: 123 + source: ip_address + fooPredefinedRegex: true matchers: body: - path: $.foo2 @@ -31,4 +36,11 @@ response: value: bar headers: - key: foo2 - regex: bar \ No newline at end of file + regex: bar + cookies: + - key: fooRegex + regex: "[0-9]+" + - key: source + regex: ip_address + - key: fooPredefinedRegex + predefined: any_boolean \ No newline at end of file