diff --git a/README.adoc b/README.adoc index 19bb993915..ea8cd37eb6 100644 --- a/README.adoc +++ b/README.adoc @@ -224,7 +224,7 @@ org.springframework.cloud.contract.spec.Contract.make { } ---- -The Contract is written using a statically typed Groovy DSL. You might be wondering what are those `${value(client(...), server(...))}` parts. So the `${}` is a String interpolation in Groovy. You can resolve a variable inside a String. In other words `"concat ${foo} and ${bar}"` is the same as `"concat " + foo + " and " + bar`. The `value(client(...), server(...))` allows you to define parts of a JSON which are dynamic. In case of an identifier or a timestamp you don't want to hardcode a value. You want to allow some different ranges of values. That's why for the consumer side you can set regular expressions matching those values. You can provide the body either by means of String with interpolations or with a map notation. https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract.html#_contract_dsl[Consult the docs for more information.] +The Contract is written using a statically typed Groovy DSL. You might be wondering what are those `${value(consumer(...), producer(...))}` parts. So the `${}` is a String interpolation in Groovy. You can resolve a variable inside a String. In other words `"concat ${foo} and ${bar}"` is the same as `"concat " + foo + " and " + bar`. The `value(consumer(...), producer(...))` allows you to define parts of a JSON which are dynamic. In case of an identifier or a timestamp you don't want to hardcode a value. You want to allow some different ranges of values. That's why for the consumer side you can set regular expressions matching those values. You can provide the body either by means of String with interpolations or with a map notation. https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract.html#_contract_dsl[Consult the docs for more information.] The aforementioned contract is an agreement between two sides that: @@ -503,7 +503,7 @@ public void validate_shouldMarkClientAsFraud() throws Exception { } ---- -As you can see all the `server()` parts of the Contract that were present in the `value(client(...), server(...))` blocks got injected into the test. +As you can see all the `producer()` parts of the Contract that were present in the `value(consumer(...), producer(...))` blocks got injected into the test. What's important here to note is that on the producer side we also are doing TDD. We have expectations in form of a test. This test is shooting a request to our own application to an URL, headers and body defined in the contract. It also is expecting very precisely defined values in the response. In other words you have is your `red` part of `red`, `green` and `refactor`. Time to convert the `red` into the `green`. diff --git a/docs/src/main/asciidoc/verifier/contract.adoc b/docs/src/main/asciidoc/verifier/contract.adoc index bdcbc9ef3c..337ef0f2f7 100644 --- a/docs/src/main/asciidoc/verifier/contract.adoc +++ b/docs/src/main/asciidoc/verifier/contract.adoc @@ -97,7 +97,35 @@ include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract Besides status response may contain **headers** and **body**, which are specified the same way as in the request (see previous paragraph). +==== Dynamic properties + +The contract can contain some dynamic properties - timestamps / ids etc. You don't want to enforce the consumers to stub their +clocks to always return the same value of time so that it gets matched by the stub. That's why we allow you to provide the dynamic +parts in your contracts in the following way + +either via the `value` method + +[source,groovy,indent=0] +---- +value(consumer(...), producer(...)) +value(stub(...), test(...)) +value(client(...), server(...)) +---- + +or if you're using the Groovy map notation for body you can use the `$()` method + +[source,groovy,indent=0] +---- +$(consumer(...), producer(...)) +$(stub(...), test(...)) +$(client(...), server(...)) +---- + +All of the aforementioned approaches are equal. That means that `stub` and `client` methods are aliases over the `consumer` +method. Let's take a closer look at what we can do with those values in the subsequent sections. + ==== Regular expressions + You can use regular expressions to write your requests in Contract DSL. It is particularly useful when you want to indicate that a given response should be provided for requests that follow a given pattern. Also, you can use it when you need to use patterns and not exact values both for your test and your server side tests. @@ -119,6 +147,20 @@ include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract In this example for request and response the opposite side of the communication will have the respective data generated. +Spring Cloud Contract comes with a series of predefined regular expressions that you can use in your contracts. + +[source,groovy,indent=0] +---- +include::{contract_spec_path}/src/main/groovy/org/springframework/cloud/contract/spec/internal/RegexPatterns.groovy[tags=regexps,indent=0] +---- + +so in your contract you can use it like this + +[source,groovy,indent=0] +---- +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcMethodBodyBuilderSpec.groovy[tags=contract_with_regex,indent=0] +---- + ==== Passing optional parameters diff --git a/docs/src/main/asciidoc/verifier/introduction.adoc b/docs/src/main/asciidoc/verifier/introduction.adoc index 8b4375bb56..36ceb92bba 100644 --- a/docs/src/main/asciidoc/verifier/introduction.adoc +++ b/docs/src/main/asciidoc/verifier/introduction.adoc @@ -160,7 +160,7 @@ As consumers we need to define what exactly we want to achieve. We need to formu include::{introduction_url}/samples/standalone/http-server/src/test/resources/contracts/shouldMarkClientAsFraud.groovy[] ---- -The Contract is written using a statically typed Groovy DSL. You might be wondering what are those `${value(client(...), server(...))}` parts. So the `${}` is a String interpolation in Groovy. You can resolve a variable inside a String. In other words `"concat ${foo} and ${bar}"` is the same as `"concat " + foo + " and " + bar`. The `value(client(...), server(...))` allows you to define parts of a JSON which are dynamic. In case of an identifier or a timestamp you don't want to hardcode a value. You want to allow some different ranges of values. That's why for the consumer side you can set regular expressions matching those values. You can provide the body either by means of String with interpolations or with a map notation. https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract.html#_contract_dsl[Consult the docs for more information.] +The Contract is written using a statically typed Groovy DSL. You might be wondering what are those `${value(consumer(...), producer(...))}` parts. So the `${}` is a String interpolation in Groovy. You can resolve a variable inside a String. In other words `"concat ${foo} and ${bar}"` is the same as `"concat " + foo + " and " + bar`. The `value(consumer(...), producer(...))` allows you to define parts of a JSON which are dynamic. In case of an identifier or a timestamp you don't want to hardcode a value. You want to allow some different ranges of values. That's why for the consumer side you can set regular expressions matching those values. You can provide the body either by means of String with interpolations or with a map notation. https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract.html#_contract_dsl[Consult the docs for more information.] The aforementioned contract is an agreement between two sides that: @@ -363,7 +363,7 @@ public void validate_shouldMarkClientAsFraud() throws Exception { } ---- -As you can see all the `server()` parts of the Contract that were present in the `value(client(...), server(...))` blocks got injected into the test. +As you can see all the `producer()` parts of the Contract that were present in the `value(consumer(...), producer(...))` blocks got injected into the test. What's important here to note is that on the producer side we also are doing TDD. We have expectations in form of a test. This test is shooting a request to our own application to an URL, headers and body defined in the contract. It also is expecting very precisely defined values in the response. In other words you have is your `red` part of `red`, `green` and `refactor`. Time to convert the `red` into the `green`. diff --git a/docs/src/main/asciidoc/verifier/spring-cloud-contract-verifier.adoc b/docs/src/main/asciidoc/verifier/spring-cloud-contract-verifier.adoc index 135982dc17..772c1821b4 100644 --- a/docs/src/main/asciidoc/verifier/spring-cloud-contract-verifier.adoc +++ b/docs/src/main/asciidoc/verifier/spring-cloud-contract-verifier.adoc @@ -1,6 +1,7 @@ :core_path: ../../../../.. :plugins_path: ../../../../../spring-cloud-contract-tools :verifier_root_path: {core_path}/spring-cloud-contract-verifier +:contract_spec_path: {core_path}/spring-cloud-contract-spec :samples_path: {core_path}/samples :verifier_core_path: {verifier_root_path} :stubrunner_core_path: {core_path}/spring-cloud-contract-stub-runner diff --git a/samples/standalone/http-server/src/test/resources/contracts/shouldMarkClientAsFraud.groovy b/samples/standalone/http-server/src/test/resources/contracts/shouldMarkClientAsFraud.groovy index 4115912c22..5b2e408b7b 100644 --- a/samples/standalone/http-server/src/test/resources/contracts/shouldMarkClientAsFraud.groovy +++ b/samples/standalone/http-server/src/test/resources/contracts/shouldMarkClientAsFraud.groovy @@ -6,7 +6,7 @@ org.springframework.cloud.contract.spec.Contract.make { url '/fraudcheck' body(""" { - "clientId":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", + "clientId":"${value(consumer(regex('[0-9]{10}')), producer('1234567890'))}", "loanAmount":99999} """ ) @@ -18,11 +18,11 @@ org.springframework.cloud.contract.spec.Contract.make { response { status 200 body( """{ - "fraudCheckStatus": "${value(client('FRAUD'), server(regex('[A-Z]{5}')))}", + "fraudCheckStatus": "${value(consumer('FRAUD'), producer(regex('[A-Z]{5}')))}", "rejectionReason": "Amount too high" }""") headers { - header('Content-Type': value(server(regex('application/vnd.fraud.v1.json.*')), client('application/vnd.fraud.v1+json'))) + header('Content-Type': value(producer(regex('application/vnd.fraud.v1.json.*')), consumer('application/vnd.fraud.v1+json'))) } } diff --git a/samples/standalone/http-server/src/test/resources/contracts/shouldMarkClientAsNotFraud.groovy b/samples/standalone/http-server/src/test/resources/contracts/shouldMarkClientAsNotFraud.groovy index 6507fee91b..46d989296e 100644 --- a/samples/standalone/http-server/src/test/resources/contracts/shouldMarkClientAsNotFraud.groovy +++ b/samples/standalone/http-server/src/test/resources/contracts/shouldMarkClientAsNotFraud.groovy @@ -6,7 +6,7 @@ org.springframework.cloud.contract.spec.Contract.make { url '/fraudcheck' body(""" { - "clientId":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", + "clientId":"${value(consumer(regex('[0-9]{10}')), producer('1234567890'))}", "loanAmount":123.123 } """ @@ -20,10 +20,10 @@ org.springframework.cloud.contract.spec.Contract.make { status 200 body( fraudCheckStatus: "OK", - rejectionReason: $(client(null), server(execute('assertThatRejectionReasonIsNull($it)'))) + rejectionReason: $(consumer(null), producer(execute('assertThatRejectionReasonIsNull($it)'))) ) headers { - header('Content-Type': value(test(regex('application/vnd.fraud.v1.json.*')), stub('application/vnd.fraud.v1+json'))) + header('Content-Type': value(producer(regex('application/vnd.fraud.v1.json.*')), consumer('application/vnd.fraud.v1+json'))) } } diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Common.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Common.groovy index a403f4d1e9..33332b29cc 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Common.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Common.groovy @@ -118,18 +118,38 @@ class Common { return new ClientDslProperty(clientValue) } + /** + * Helper method to provide a better name for the consumer side + */ ClientDslProperty stub(Object clientValue) { return new ClientDslProperty(clientValue) } + /** + * Helper method to provide a better name for the consumer side + */ + ClientDslProperty consumer(Object clientValue) { + return new ClientDslProperty(clientValue) + } + ServerDslProperty server(Object serverValue) { return new ServerDslProperty(serverValue) } + /** + * Helper method to provide a better name for the producer side + */ ServerDslProperty test(Object serverValue) { return new ServerDslProperty(serverValue) } + /** + * Helper method to provide a better name for the producer side + */ + ServerDslProperty producer(Object clientValue) { + return new ServerDslProperty(clientValue) + } + void assertThatSidesMatch(OptionalProperty stubSide, Object testSide) { assert testSide ==~ Pattern.compile(stubSide.optionalPattern()) } diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Input.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Input.groovy index 124b25ce50..ce5c95a457 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Input.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Input.groovy @@ -46,20 +46,6 @@ class Input extends Common { this.messageBody = input.messageBody } - /** - * Helper method to provide a better name for the producer side - */ - ServerDslProperty producer(Object clientValue) { - return new ServerDslProperty(clientValue) - } - - /** - * Helper method to provide a better name for the consumer side - */ - ClientDslProperty consumer(Object clientValue) { - return new ClientDslProperty(clientValue) - } - /** * Name of a destination from which message would come to trigger action in the system */ diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RegexPatterns.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RegexPatterns.groovy index 7177ecf7c0..bfa234ecbc 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RegexPatterns.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RegexPatterns.groovy @@ -28,6 +28,7 @@ import java.util.regex.Pattern @CompileStatic class RegexPatterns { + // tag::regexps[] private static final Pattern TRUE_OR_FALSE = Pattern.compile(/(true|false)/) private static final Pattern ONLY_ALPHA_UNICODE = Pattern.compile(/[\p{L}]*/) private static final Pattern NUMBER = Pattern.compile('-?\\d*(\\.\\d+)?') @@ -63,6 +64,7 @@ class RegexPatterns { String url() { return URL.pattern() } + // end::regexps[] static String multipartParam(Object name, Object value) { return ".*--(.*)\r\nContent-Disposition: form-data; name=\"$name\"\r\n(Content-Type: .*\r\n)?(Content-Length: \\d+\r\n)?\r\n$value\r\n--\\1.*" diff --git a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/RequestSpec.groovy b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/RequestSpec.groovy index 2e3e8fecc7..caf7522f62 100644 --- a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/RequestSpec.groovy +++ b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/RequestSpec.groovy @@ -11,13 +11,13 @@ class RequestSpec extends Specification { Request request = new Request() when: request.with { - value(client("foo"), server(regex("foo"))) + value(consumer("foo"), producer(regex("foo"))) } then: thrown(IllegalStateException) when: request.with { - value(server(regex("foo")), client("foo")) + value(producer(regex("foo")), consumer("foo")) } then: thrown(IllegalStateException) @@ -29,7 +29,7 @@ class RequestSpec extends Specification { DslProperty property when: request.with { - property = value(client(regex("[0-9]{5}"))) + property = value(consumer(regex("[0-9]{5}"))) } then: (property.serverValue as String).matches(/[0-9]{5}/) diff --git a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/ResponseSpec.groovy b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/ResponseSpec.groovy index f22f855f4a..6d565f071b 100644 --- a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/ResponseSpec.groovy +++ b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/ResponseSpec.groovy @@ -11,13 +11,13 @@ class ResponseSpec extends Specification { Response response = new Response() when: response.with { - value(server("foo"), client(regex("foo"))) + value(producer("foo"), consumer(regex("foo"))) } then: thrown(IllegalStateException) when: response.with { - value(client(regex("foo")), server("foo")) + value(consumer(regex("foo")), producer("foo")) } then: thrown(IllegalStateException) @@ -29,7 +29,7 @@ class ResponseSpec extends Specification { DslProperty property when: request.with { - property = value(server(regex("[0-9]{5}"))) + property = value(producer(regex("[0-9]{5}"))) } then: (property.serverValue as String).matches(/[0-9]{5}/) diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/HttpStubsController.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/HttpStubsController.java index bb02bb26aa..38335ca5ee 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/HttpStubsController.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/HttpStubsController.java @@ -46,7 +46,7 @@ public class HttpStubsController { } @RequestMapping(path = "/{ivy:.*}") - public ResponseEntity stub(@PathVariable String ivy) { + public ResponseEntity consumer(@PathVariable String ivy) { Integer port = stubRunning.runStubs().getPort(ivy); if (port!=null) { return ResponseEntity.ok(port); diff --git a/spring-cloud-contract-stub-runner/src/test/resources/repository/contracts/contract1.groovy b/spring-cloud-contract-stub-runner/src/test/resources/repository/contracts/contract1.groovy index 6fb7fed055..c47a0a6fc8 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/repository/contracts/contract1.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/repository/contracts/contract1.groovy @@ -4,7 +4,7 @@ org.springframework.cloud.contract.spec.Contract.make { url """/fraudcheck""" body(""" { - "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", + "clientPesel":"${value(consumer(regex('[0-9]{10}')), producer('1234567890'))}", "loanAmount":99999} """ ) @@ -16,11 +16,11 @@ org.springframework.cloud.contract.spec.Contract.make { response { status 200 body( """{ - "fraudCheckStatus": "${value(client('FRAUD'), server(regex('[A-Z]{5}')))}", + "fraudCheckStatus": "${value(consumer('FRAUD'), producer(regex('[A-Z]{5}')))}", "rejectionReason": "Amount too high" }""") headers { - header('Content-Type': value(server(regex('application/vnd.fraud.v1.json.*')), client('application/vnd.fraud.v1+json'))) + header('Content-Type': value(producer(regex('application/vnd.fraud.v1.json.*')), consumer('application/vnd.fraud.v1+json'))) } } diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/WireMockToDslConverter.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/WireMockToDslConverter.groovy index fdccd95ba5..a9a869fb70 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/WireMockToDslConverter.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/WireMockToDslConverter.groovy @@ -59,8 +59,8 @@ class WireMockToDslConverter { request { ${request.method ? "method \"\"\"$request.method\"\"\"" : ""} ${request.url ? "url \"\"\"$request.url\"\"\"" : ""} - ${urlPattern ? "url \$(client(regex('${escapeJava(urlPattern)}')), server('${new Xeger(escapeJava(urlPattern)).generate()}'))" : ""} - ${urlPathPattern ? "urlPath \$(client(regex('${escapeJava(urlPattern)}')), server('${new Xeger(escapeJava(urlPattern)).generate()}'))" : ""} + ${urlPattern ? "url \$(consumer(regex('${escapeJava(urlPattern)}')), producer('${new Xeger(escapeJava(urlPattern)).generate()}'))" : ""} + ${urlPathPattern ? "urlPath \$(consumer(regex('${escapeJava(urlPattern)}')), producer('${new Xeger(escapeJava(urlPattern)).generate()}'))" : ""} ${request.urlPath ? "url \"\"\"$request.urlPath\"\"\"" : ""} ${ request.headers ? """headers { @@ -77,7 +77,7 @@ class WireMockToDslConverter { } ${bodyPatterns?.equalTo?.every { it } ? "body('''${bodyPatterns.equalTo[0]}''')" : ''} ${bodyPatterns?.equalToJson?.every { it } ? "body('''${bodyPatterns.equalToJson[0]}''')" : ''} - ${bodyPatterns?.matches?.every { it } ? "body \$(client(regex('${escapeJava(bodyPatterns.matches[0])}')), server('${new Xeger(escapeJava(bodyPatterns.matches[0])).generate()}'))" : ""} + ${bodyPatterns?.matches?.every { it } ? "body \$(consumer(regex('${escapeJava(bodyPatterns.matches[0])}')), producer('${new Xeger(escapeJava(bodyPatterns.matches[0])).generate()}'))" : ""} } response { ${response.status ? "status $response.status" : ""} diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockClientConverterSpec.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockClientConverterSpec.groovy index 5ce9fd3e60..ca92044928 100755 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockClientConverterSpec.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockClientConverterSpec.groovy @@ -37,7 +37,7 @@ class DslToWireMockClientConverterSpec extends Specification { org.springframework.cloud.contract.spec.Contract.make { request { method('PUT') - url \$(client(~/\\/[0-9]{2}/), server('/12')) + url \$(consumer(~/\\/[0-9]{2}/), producer('/12')) } response { status 200 @@ -203,11 +203,11 @@ class DslToWireMockClientConverterSpec extends Specification { response { status 200 body([[id: value( - client('123'), - server(regex('[0-9]+')) + consumer('123'), + producer(regex('[0-9]+')) )], [id: value( - client('567'), - server(regex('[0-9]+')) + consumer('567'), + producer(regex('[0-9]+')) )]]) headers { header 'Content-Type': 'application/json' @@ -238,8 +238,8 @@ class DslToWireMockClientConverterSpec extends Specification { header 'Content-Type': 'application/json' } body( - email: $(stub(optional(regex(email()))), test('abc@abc.com')), - callback_url: $(stub(regex(hostname())), test('http://partners.com')) + email: $(consumer(optional(regex(email()))), producer('abc@abc.com')), + callback_url: $(consumer(regex(hostname())), producer('http://partners.com')) ) } response { @@ -248,8 +248,8 @@ class DslToWireMockClientConverterSpec extends Specification { header 'Content-Type': 'application/json' } body( - code: value(stub("123123"), test(optional("123123"))), - message: "User not found by email == [${value(test(regex(email())), stub('not.existing@user.com'))}]" + code: value(consumer("123123"), producer(optional("123123"))), + message: "User not found by email == [${value(producer(regex(email())), consumer('not.existing@user.com'))}]" ) } } diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/WireMockToDslConverterSpec.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/WireMockToDslConverterSpec.groovy index 9b1e4c2367..32d39a2874 100755 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/WireMockToDslConverterSpec.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/WireMockToDslConverterSpec.groovy @@ -57,12 +57,12 @@ class WireMockToDslConverterSpec extends Specification { url '/path' headers { header('Accept': $( - client(regex('text/.*')), - server('text/plain') + consumer(regex('text/.*')), + producer('text/plain') )) header('X-Custom-Header': $( - client(regex('^.*2134.*$')), - server('121345') + consumer(regex('^.*2134.*$')), + producer('121345') )) } @@ -119,7 +119,7 @@ class WireMockToDslConverterSpec extends Specification { Contract expectedGroovyDsl = Contract.make { request { method 'DELETE' - url $(client(~/\/credit-card-verification-data\/[0-9]+/), server('/credit-card-verification-data/1')) + url $(consumer(~/\/credit-card-verification-data\/[0-9]+/), producer('/credit-card-verification-data/1')) headers { header('Content-Type': 'application/vnd.mymoid-adapter.v2+json; charset=UTF-8') } @@ -377,7 +377,7 @@ class WireMockToDslConverterSpec extends Specification { request { method 'POST' url '/test' - body $(client(~/[0-9]{5}/), server('12345')) + body $(consumer(~/[0-9]{5}/), producer('12345')) } response { status 200 @@ -498,7 +498,7 @@ class WireMockToDslConverterSpec extends Specification { request { method 'POST' url '/test' - body $(client(~/[0-9]{2}/), server('12')) + body $(consumer(~/[0-9]{2}/), producer('12')) } response { status 200 diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1.groovy index c724017ffd..f79eabfe33 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1.groovy @@ -22,7 +22,7 @@ Contract.make { headers { header 'Content-Type': 'application/json' } - url $(client('/[0-9]{2}'), server('/12')) + url $(consumer('/[0-9]{2}'), producer('/12')) } response { status 200 diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1b.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1b.groovy index daaf2950e8..dc232211e4 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1b.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1b.groovy @@ -22,7 +22,7 @@ Contract.make { headers { header 'Content-Type': 'application/json' } - urlPattern $(client('/[0-9]{2}'), server('/12')) + urlPattern $(consumer('/[0-9]{2}'), producer('/12')) } response { status 200 diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir2/dsl2.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir2/dsl2.groovy index c724017ffd..f79eabfe33 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir2/dsl2.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir2/dsl2.groovy @@ -22,7 +22,7 @@ Contract.make { headers { header 'Content-Type': 'application/json' } - url $(client('/[0-9]{2}'), server('/12')) + url $(consumer('/[0-9]{2}'), producer('/12')) } response { status 200 diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dslRoot.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dslRoot.groovy index c724017ffd..f79eabfe33 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dslRoot.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dslRoot.groovy @@ -22,7 +22,7 @@ Contract.make { headers { header 'Content-Type': 'application/json' } - url $(client('/[0-9]{2}'), server('/12')) + url $(consumer('/[0-9]{2}'), producer('/12')) } response { status 200 diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/bootSimple/repository/mappings/spring/cloud/twitter-places-analyzer/pairId/moreComplexVersion.groovy b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/bootSimple/repository/mappings/spring/cloud/twitter-places-analyzer/pairId/moreComplexVersion.groovy index 887e54edf7..75149e8762 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/bootSimple/repository/mappings/spring/cloud/twitter-places-analyzer/pairId/moreComplexVersion.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/bootSimple/repository/mappings/spring/cloud/twitter-places-analyzer/pairId/moreComplexVersion.groovy @@ -19,7 +19,7 @@ import org.springframework.cloud.contract.spec.Contract Contract.make { request { method 'PUT' - url $(client(regex('^/api/[0-9]{2}$')), server('/api/12')) + url $(consumer(regex('^/api/[0-9]{2}$')), producer('/api/12')) headers { header 'Content-Type': 'application/json' } @@ -31,12 +31,12 @@ Contract.make { } response { headers { - header 'Content-Type': $(client('application/json'), server(regex('application/json.*'))) - header 'Location': $(client('https://localhost:8080'), server(execute('isEmpty($it)'))) + header 'Content-Type': $(consumer('application/json'), producer(regex('application/json.*'))) + header 'Location': $(consumer('https://localhost:8080'), producer(execute('isEmpty($it)'))) } body ( - path: $(client('/api/12'), server(regex('^/api/[0-9]{2}$'))), - correlationId: $(client('1223456'), server(execute('isProperCorrelationId($it)'))) + path: $(consumer('/api/12'), producer(regex('^/api/[0-9]{2}$'))), + correlationId: $(consumer('1223456'), producer(execute('isProperCorrelationId($it)'))) ) status 200 } diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsFraud.groovy b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsFraud.groovy index 1fc39340b5..046279c554 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsFraud.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsFraud.groovy @@ -22,7 +22,7 @@ Contract.make { url """/fraudcheck""" body(""" { - "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", + "clientPesel":"${value(consumer(regex('[0-9]{10}')), producer('1234567890'))}", "loanAmount":99999} """ ) @@ -34,7 +34,7 @@ Contract.make { response { status 200 body( """{ - "fraudCheckStatus": "${value(client('FRAUD'), server(regex('[A-Z]{5}')))}", + "fraudCheckStatus": "${value(consumer('FRAUD'), producer(regex('[A-Z]{5}')))}", "rejectionReason": "Amount too high" }""") headers { diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.groovy b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.groovy index 94026415f3..5322c6079d 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.groovy @@ -22,7 +22,7 @@ Contract.make { url '/fraudcheck' body(""" { - "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", + "clientPesel":"${value(consumer(regex('[0-9]{10}')), producer('1234567890'))}", "loanAmount":123.123 } """ @@ -36,7 +36,7 @@ Contract.make { status 200 body( fraudCheckStatus: "OK", - rejectionReason: $(client(null), server(execute('assertThatRejectionReasonIsNull($it)'))) + rejectionReason: $(consumer(null), producer(execute('assertThatRejectionReasonIsNull($it)'))) ) headers { header('Content-Type': 'application/vnd.fraud.v1+json') diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsFraud.groovy b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsFraud.groovy index a2e6875fd9..fcd23de64f 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsFraud.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsFraud.groovy @@ -21,7 +21,7 @@ Contract.make { url """/fraudcheck""" body(""" { - "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", + "clientPesel":"${value(consumer(regex('[0-9]{10}')), producer('1234567890'))}", "loanAmount":99999} """ ) @@ -33,7 +33,7 @@ Contract.make { response { status 200 body( """{ - "fraudCheckStatus": "${value(client('FRAUD'), server(regex('[A-Z]{5}')))}", + "fraudCheckStatus": "${value(consumer('FRAUD'), producer(regex('[A-Z]{5}')))}", "rejectionReason": "Amount too high" }""") headers { diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.groovy b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.groovy index 76df090cd6..25e9ded9b2 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.groovy @@ -21,7 +21,7 @@ Contract.make { url '/fraudcheck' body(""" { - "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", + "clientPesel":"${value(consumer(regex('[0-9]{10}')), producer('1234567890'))}", "loanAmount":123.123 } """ @@ -35,7 +35,7 @@ Contract.make { status 200 body( fraudCheckStatus: "OK", - rejectionReason: $(client(null), server(execute('assertThatRejectionReasonIsNull($it)'))) + rejectionReason: $(consumer(null), producer(execute('assertThatRejectionReasonIsNull($it)'))) ) headers { header('Content-Type': 'application/vnd.fraud.v1+json') diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/1_shouldMarkClientAsNotFraud.groovy b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/1_shouldMarkClientAsNotFraud.groovy index 76df090cd6..25e9ded9b2 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/1_shouldMarkClientAsNotFraud.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/1_shouldMarkClientAsNotFraud.groovy @@ -21,7 +21,7 @@ Contract.make { url '/fraudcheck' body(""" { - "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", + "clientPesel":"${value(consumer(regex('[0-9]{10}')), producer('1234567890'))}", "loanAmount":123.123 } """ @@ -35,7 +35,7 @@ Contract.make { status 200 body( fraudCheckStatus: "OK", - rejectionReason: $(client(null), server(execute('assertThatRejectionReasonIsNull($it)'))) + rejectionReason: $(consumer(null), producer(execute('assertThatRejectionReasonIsNull($it)'))) ) headers { header('Content-Type': 'application/vnd.fraud.v1+json') diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/2_shouldMarkClientAsFraud.groovy b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/2_shouldMarkClientAsFraud.groovy index 1fc39340b5..046279c554 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/2_shouldMarkClientAsFraud.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/2_shouldMarkClientAsFraud.groovy @@ -22,7 +22,7 @@ Contract.make { url """/fraudcheck""" body(""" { - "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", + "clientPesel":"${value(consumer(regex('[0-9]{10}')), producer('1234567890'))}", "loanAmount":99999} """ ) @@ -34,7 +34,7 @@ Contract.make { response { status 200 body( """{ - "fraudCheckStatus": "${value(client('FRAUD'), server(regex('[A-Z]{5}')))}", + "fraudCheckStatus": "${value(consumer('FRAUD'), producer(regex('[A-Z]{5}')))}", "rejectionReason": "Amount too high" }""") headers { diff --git a/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/complex-configuration/src/test/contracts/brokenContract.groovy b/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/complex-configuration/src/test/contracts/brokenContract.groovy index 48435cb1a2..fee0c90424 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/complex-configuration/src/test/contracts/brokenContract.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/complex-configuration/src/test/contracts/brokenContract.groovy @@ -20,7 +20,7 @@ org.springframework.cloud.contract.spec.Contract.make { url '/fraudcheck' body(""" { - "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", + "clientPesel":"${value(consumer(regex('[0-9]{10}')), producer('1234567890'))}", "loanAmount":123.123 } """ @@ -34,7 +34,7 @@ org.springframework.cloud.contract.spec.Contract.make { status 999 body( fraudCheckStatus: "OK", - rejectionReason: $(client(null), server(execute('assertThatRejectionReasonIsNull($it)'))) + rejectionReason: $(consumer(null), producer(execute('assertThatRejectionReasonIsNull($it)'))) ) headers { header('Content-Type': 'application/vnd.fraud.v1+json') diff --git a/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/complex-configuration/src/test/contracts/shouldMarkClientAsFraud.groovy b/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/complex-configuration/src/test/contracts/shouldMarkClientAsFraud.groovy index 9cd6dec8b1..f25a6ac47b 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/complex-configuration/src/test/contracts/shouldMarkClientAsFraud.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/complex-configuration/src/test/contracts/shouldMarkClientAsFraud.groovy @@ -20,7 +20,7 @@ org.springframework.cloud.contract.spec.Contract.make { url """/fraudcheck""" body(""" { - "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", + "clientPesel":"${value(consumer(regex('[0-9]{10}')), producer('1234567890'))}", "loanAmount":99999} """ ) @@ -32,7 +32,7 @@ org.springframework.cloud.contract.spec.Contract.make { response { status 200 body( """{ - "fraudCheckStatus": "${value(client('FRAUD'), server(regex('[A-Z]{5}')))}", + "fraudCheckStatus": "${value(consumer('FRAUD'), producer(regex('[A-Z]{5}')))}", "rejectionReason": "Amount too high" }""") headers { diff --git a/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/complex-configuration/src/test/contracts/shouldMarkClientAsNotFraud.groovy b/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/complex-configuration/src/test/contracts/shouldMarkClientAsNotFraud.groovy index 92b2646567..dbab134206 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/complex-configuration/src/test/contracts/shouldMarkClientAsNotFraud.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/complex-configuration/src/test/contracts/shouldMarkClientAsNotFraud.groovy @@ -20,7 +20,7 @@ org.springframework.cloud.contract.spec.Contract.make { url '/fraudcheck' body(""" { - "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", + "clientPesel":"${value(consumer(regex('[0-9]{10}')), producer('1234567890'))}", "loanAmount":123.123 } """ @@ -34,7 +34,7 @@ org.springframework.cloud.contract.spec.Contract.make { status 200 body( fraudCheckStatus: "OK", - rejectionReason: $(client(null), server(execute('assertThatRejectionReasonIsNull($it)'))) + rejectionReason: $(consumer(null), producer(execute('assertThatRejectionReasonIsNull($it)'))) ) headers { header('Content-Type': 'application/vnd.fraud.v1+json') 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 1c23b37367..6e2178a9e7 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 @@ -110,15 +110,15 @@ class ContractHttpDocsSpec extends Specification { // `containing` function matches strings // that contains passed substring. - parameter 'gender': value(stub(containing("[mf]")), server('mf')) + parameter 'gender': value(consumer(containing("[mf]")), producer('mf')) // `matching` function tests parameter // against passed regular expression. - parameter 'offset': value(stub(matching("[0-9]+")), server(123)) + parameter 'offset': value(consumer(matching("[0-9]+")), producer(123)) // `notMatching` functions tests if parameter // does not match passed regular expression. - parameter 'loginStartsWith': value(stub(notMatching(".{0,2}")), server(3)) + parameter 'loginStartsWith': value(consumer(notMatching(".{0,2}")), producer(3)) } } @@ -205,23 +205,23 @@ class ContractHttpDocsSpec extends Specification { org.springframework.cloud.contract.spec.Contract.make { request { method('GET') - url $(client(~/\/[0-9]{2}/), server('/12')) + url $(consumer(~/\/[0-9]{2}/), producer('/12')) } response { status 200 body( id: value( - client('123'), - server(regex('[0-9]+')) + consumer('123'), + producer(regex('[0-9]+')) ), surname: $( - client('Kowalsky'), - server('Lewandowski') + consumer('Kowalsky'), + producer('Lewandowski') ), name: 'Jan', - created: $(client('2014-02-02 12:23:43'), server(execute('currentDate(it)'))), - correlationId: value(client('5d1f9fef-e0dc-4f3d-a7e4-72d2220dd827'), - server(regex('[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}')) + created: $(consumer('2014-02-02 12:23:43'), producer(execute('currentDate(it)'))), + correlationId: value(consumer('5d1f9fef-e0dc-4f3d-a7e4-72d2220dd827'), + producer(regex('[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}')) ) ) headers { @@ -242,8 +242,8 @@ class ContractHttpDocsSpec extends Specification { header 'Content-Type': 'application/json' } body( - email: $(stub(optional(regex(email()))), test('abc@abc.com')), - callback_url: $(stub(regex(hostname())), test('http://partners.com')) + email: $(consumer(optional(regex(email()))), producer('abc@abc.com')), + callback_url: $(consumer(regex(hostname())), producer('http://partners.com')) ) } response { @@ -252,7 +252,7 @@ class ContractHttpDocsSpec extends Specification { header 'Content-Type': 'application/json' } body( - code: value(stub("123123"), test(optional("123123"))) + code: value(consumer("123123"), producer(optional("123123"))) ) } } @@ -291,7 +291,7 @@ class ContractHttpDocsSpec extends Specification { org.springframework.cloud.contract.spec.Contract.make { request { method 'PUT' - url $(client(regex('^/api/[0-9]{2}$')), server('/api/12')) + url $(consumer(regex('^/api/[0-9]{2}$')), producer('/api/12')) headers { header 'Content-Type': 'application/json' } @@ -303,8 +303,8 @@ class ContractHttpDocsSpec extends Specification { } response { body ( - path: $(client('/api/12'), server(regex('^/api/[0-9]{2}$'))), - correlationId: $(client('1223456'), server(execute('isProperCorrelationId($it)'))) + path: $(consumer('/api/12'), producer(regex('^/api/[0-9]{2}$'))), + correlationId: $(consumer('1223456'), producer(execute('isProperCorrelationId($it)'))) ) status 200 } diff --git a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/JaxRsClientMethodBuilderSpec.groovy b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/JaxRsClientMethodBuilderSpec.groovy index 777c28a59c..849c06591d 100644 --- a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/JaxRsClientMethodBuilderSpec.groovy +++ b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/JaxRsClientMethodBuilderSpec.groovy @@ -294,8 +294,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub body( property1: "a", property2: value( - client('123'), - server(regex('[0-9]{3}')) + consumer('123'), + producer(regex('[0-9]{3}')) ) ) headers { @@ -329,7 +329,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub } response { status 200 - body("""{"property1":"a","property2":"${value(client('123'), server(regex('[0-9]{3}')))}"}""") + body("""{"property1":"a","property2":"${value(consumer('123'), producer(regex('[0-9]{3}')))}"}""") headers { header('Content-Type': 'application/json') @@ -420,15 +420,15 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub method 'GET' urlPath('/users') { queryParameters { - parameter 'limit': $(client(equalTo("20")), server(equalTo("10"))) - parameter 'offset': $(client(containing("20")), server(equalTo("20"))) + parameter 'limit': $(consumer(equalTo("20")), producer(equalTo("10"))) + parameter 'offset': $(consumer(containing("20")), producer(equalTo("20"))) parameter 'filter': "email" parameter 'sort': equalTo("name") - parameter 'search': $(client(notMatching(~/^\/[0-9]{2}$/)), server("55")) - parameter 'age': $(client(notMatching("^\\w*\$")), server("99")) - parameter 'name': $(client(matching("Denis.*")), server("Denis.Stepanov")) + parameter 'search': $(consumer(notMatching(~/^\/[0-9]{2}$/)), producer("55")) + parameter 'age': $(consumer(notMatching("^\\w*\$")), producer("99")) + parameter 'name': $(consumer(matching("Denis.*")), producer("Denis.Stepanov")) parameter 'email': "bob@email.com" - parameter 'hello': $(client(matching("Denis.*")), server(absent())) + parameter 'hello': $(consumer(matching("Denis.*")), producer(absent())) parameter 'hello': absent() } } @@ -473,17 +473,17 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub org.springframework.cloud.contract.spec.Contract contractDsl = org.springframework.cloud.contract.spec.Contract.make { request { method 'GET' - url($(stub(regex('/foo/[0-9]+')), test('/foo/123456'))) { + url($(consumer(regex('/foo/[0-9]+')), producer('/foo/123456'))) { queryParameters { - parameter 'limit': $(client(equalTo("20")), server(equalTo("10"))) - parameter 'offset': $(client(containing("20")), server(equalTo("20"))) + parameter 'limit': $(consumer(equalTo("20")), producer(equalTo("10"))) + parameter 'offset': $(consumer(containing("20")), producer(equalTo("20"))) parameter 'filter': "email" parameter 'sort': equalTo("name") - parameter 'search': $(client(notMatching(~/^\/[0-9]{2}$/)), server("55")) - parameter 'age': $(client(notMatching("^\\w*\$")), server("99")) - parameter 'name': $(client(matching("Denis.*")), server("Denis.Stepanov")) + parameter 'search': $(consumer(notMatching(~/^\/[0-9]{2}$/)), producer("55")) + parameter 'age': $(consumer(notMatching("^\\w*\$")), producer("99")) + parameter 'name': $(consumer(matching("Denis.*")), producer("Denis.Stepanov")) parameter 'email': "bob@email.com" - parameter 'hello': $(client(matching("Denis.*")), server(absent())) + parameter 'hello': $(consumer(matching("Denis.*")), producer(absent())) parameter 'hello': absent() } } @@ -618,15 +618,15 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub method 'GET' urlPath('/users') { queryParameters { - parameter 'limit': $(client(equalTo("20")), server(equalTo("10"))) - parameter 'offset': $(client(containing("20")), server(equalTo("20"))) + parameter 'limit': $(consumer(equalTo("20")), producer(equalTo("10"))) + parameter 'offset': $(consumer(containing("20")), producer(equalTo("20"))) parameter 'filter': "email" parameter 'sort': equalTo("name") - parameter 'search': $(client(notMatching(~/^\/[0-9]{2}$/)), server("55")) - parameter 'age': $(client(notMatching("^\\w*\$")), server("99")) - parameter 'name': $(client(matching("Denis.*")), server("Denis.Stepanov")) + parameter 'search': $(consumer(notMatching(~/^\/[0-9]{2}$/)), producer("55")) + parameter 'age': $(consumer(notMatching("^\\w*\$")), producer("99")) + parameter 'name': $(consumer(matching("Denis.*")), producer("Denis.Stepanov")) parameter 'email': "bob@email.com" - parameter 'hello': $(client(matching("Denis.*")), server(absent())) + parameter 'hello': $(consumer(matching("Denis.*")), producer(absent())) parameter 'hello': absent() } } diff --git a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcMethodBodyBuilderSpec.groovy b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcMethodBodyBuilderSpec.groovy index ed35d0348e..7cd56f8c8d 100644 --- a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcMethodBodyBuilderSpec.groovy +++ b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcMethodBodyBuilderSpec.groovy @@ -30,8 +30,9 @@ import java.util.regex.Pattern class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStubVerifier { @Shared ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(assertJsonSize: true) - + @Shared + // tag::contract_with_regex[] Contract dslWithOptionalsInString = Contract.make { priority 1 request { @@ -41,8 +42,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub header 'Content-Type': 'application/json' } body( - email: $(stub(optional(regex(email()))), test('abc@abc.com')), - callback_url: $(stub(regex(hostname())), test('http://partners.com')) + email: $(consumer(optional(regex(email()))), producer('abc@abc.com')), + callback_url: $(consumer(regex(hostname())), producer('http://partners.com')) ) } response { @@ -51,11 +52,12 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub header 'Content-Type': 'application/json' } body( - code: value(stub("123123"), test(optional("123123"))), - message: "User not found by email = [${value(test(regex(email())), stub('not.existing@user.com'))}]" + code: value(consumer("123123"), producer(optional("123123"))), + message: "User not found by email = [${value(producer(regex(email())), consumer('not.existing@user.com'))}]" ) } } + // end::contract_with_regex[] @Shared Contract dslWithOptionals = Contract.make { @@ -69,10 +71,10 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub body( """ { "email" : "${ - value(stub(optional(regex(email()))), test('abc@abc.com')) + value(consumer(optional(regex(email()))), producer('abc@abc.com')) }", "callback_url" : "${ - value(client(regex(hostname())), server('http://partners.com')) + value(consumer(regex(hostname())), producer('http://partners.com')) }" } """ @@ -85,9 +87,9 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub } body( """ { - "code" : "${value(stub(123123), test(optional(123123)))}", + "code" : "${value(consumer(123123), producer(optional(123123)))}", "message" : "User not found by email = [${ - value(server(regex(email())), client('not.existing@user.com')) + value(producer(regex(email())), consumer('not.existing@user.com')) }]" } """ @@ -394,8 +396,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub body( property1: "a", property2: value( - client('123'), - server(regex('[0-9]{3}')) + consumer('123'), + producer(regex('[0-9]{3}')) ) ) headers { @@ -428,7 +430,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub response { status 200 body("""{"property1":"a","property2":"${ - value(client('123'), server(regex('[0-9]{3}'))) + value(consumer('123'), producer(regex('[0-9]{3}'))) }"}""") headers { header('Content-Type': 'application/json') @@ -461,7 +463,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub response { status 200 body("""{"property":" ${ - value(client('123'), server(regex('\\d+'))) + value(consumer('123'), producer(regex('\\d+'))) }"}""") headers { header('Content-Type': 'application/json') @@ -489,15 +491,15 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub method 'GET' urlPath('/users') { queryParameters { - parameter 'limit': $(client(equalTo("20")), server(equalTo("10"))) - parameter 'offset': $(client(containing("20")), server(equalTo("20"))) + parameter 'limit': $(consumer(equalTo("20")), producer(equalTo("10"))) + parameter 'offset': $(consumer(containing("20")), producer(equalTo("20"))) parameter 'filter': "email" parameter 'sort': equalTo("name") - parameter 'search': $(client(notMatching(~/^\/[0-9]{2}$/)), server("55")) - parameter 'age': $(client(notMatching("^\\w*\$")), server("99")) - parameter 'name': $(client(matching("Denis.*")), server("Denis.Stepanov")) + parameter 'search': $(consumer(notMatching(~/^\/[0-9]{2}$/)), producer("55")) + parameter 'age': $(consumer(notMatching("^\\w*\$")), producer("99")) + parameter 'name': $(consumer(matching("Denis.*")), producer("Denis.Stepanov")) parameter 'email': "bob@email.com" - parameter 'hello': $(client(matching("Denis.*")), server(absent())) + parameter 'hello': $(consumer(matching("Denis.*")), producer(absent())) parameter 'hello': absent() } } @@ -535,17 +537,17 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub Contract contractDsl = Contract.make { request { method 'GET' - url($(stub(regex('/foo/[0-9]+')), test('/foo/123456'))) { + url($(consumer(regex('/foo/[0-9]+')), producer('/foo/123456'))) { queryParameters { - parameter 'limit': $(client(equalTo("20")), server(equalTo("10"))) - parameter 'offset': $(client(containing("20")), server(equalTo("20"))) + parameter 'limit': $(consumer(equalTo("20")), producer(equalTo("10"))) + parameter 'offset': $(consumer(containing("20")), producer(equalTo("20"))) parameter 'filter': "email" parameter 'sort': equalTo("name") - parameter 'search': $(client(notMatching(~/^\/[0-9]{2}$/)), server("55")) - parameter 'age': $(client(notMatching("^\\w*\$")), server("99")) - parameter 'name': $(client(matching("Denis.*")), server("Denis.Stepanov")) + parameter 'search': $(consumer(notMatching(~/^\/[0-9]{2}$/)), producer("55")) + parameter 'age': $(consumer(notMatching("^\\w*\$")), producer("99")) + parameter 'name': $(consumer(matching("Denis.*")), producer("Denis.Stepanov")) parameter 'email': "bob@email.com" - parameter 'hello': $(client(matching("Denis.*")), server(absent())) + parameter 'hello': $(consumer(matching("Denis.*")), producer(absent())) parameter 'hello': absent() } } @@ -638,7 +640,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub Contract contractDsl = Contract.make { request { method 'POST' - url $(client(regex('/partners/[0-9]+/users')), server('/partners/1000/users')) + url $(consumer(regex('/partners/[0-9]+/users')), producer('/partners/1000/users')) headers { header 'Content-Type': 'application/json' } body( first_name: 'John', @@ -652,7 +654,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub response { status 201 headers { - header 'Location': $(client('http://localhost/partners/1000/users/1001'), server(regex('http://localhost/partners/[0-9]+/users/[0-9]+'))) + header 'Location': $(consumer('http://localhost/partners/1000/users/1001'), producer(regex('http://localhost/partners/[0-9]+/users/[0-9]+'))) } } } @@ -677,7 +679,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub Contract contractDsl = Contract.make { request { method 'POST' - url $(client(regex('/partners/[0-9]+/users')), server('/partners/1000/users')) + url $(consumer(regex('/partners/[0-9]+/users')), producer('/partners/1000/users')) headers { header 'Content-Type': 'application/json' } body( first_name: 'John', @@ -691,7 +693,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub response { status 201 headers { - header 'Location': $(client('http://localhost/partners/1000/users/1001'), server(regex("^${hostname()}/partners/[0-9]+/users/[0-9]+"))) + header 'Location': $(consumer('http://localhost/partners/1000/users/1001'), producer(regex("^${hostname()}/partners/[0-9]+/users/[0-9]+"))) } } } @@ -757,7 +759,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub request { method 'PUT' - url "/partners/${value(client(regex('^[0-9]*$')), server('11'))}/agents/11/customers/09665703Z" + url "/partners/${value(consumer(regex('^[0-9]*$')), producer('11'))}/agents/11/customers/09665703Z" headers { header 'Content-Type': 'application/json' } @@ -795,8 +797,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub header 'Content-Type': 'application/json' } body( - email: $(client(regex(email())), server('not.existing@user.com')), - callback_url: $(client(regex(hostname())), server('http://partners.com')) + email: $(consumer(regex(email())), producer('not.existing@user.com')), + callback_url: $(consumer(regex(hostname())), producer('http://partners.com')) ) } response { @@ -806,7 +808,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub } body( code: 4, - message: "User not found by email = [${value(server(regex(email())), client('not.existing@user.com'))}]" + message: "User not found by email = [${value(producer(regex(email())), consumer('not.existing@user.com'))}]" ) } } @@ -869,7 +871,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub body(""" { "clientPesel":"${ - value(client(regex('[0-9]{10}')), server('1234567890')) + value(consumer(regex('[0-9]{10}')), producer('1234567890')) }", "loanAmount":123.123 } @@ -885,14 +887,14 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub body("""{ "fraudCheckStatus": "OK", "rejectionReason": ${ - value(client(null), server(execute('assertThatRejectionReasonIsNull($it)'))) + value(consumer(null), producer(execute('assertThatRejectionReasonIsNull($it)'))) } }""") headers { header('Content-Type': 'application/vnd.fraud.v1+json') header 'Location': value( - stub(null), - test(execute('assertThatLocationIsNull($it)')) + consumer(null), + producer(execute('assertThatLocationIsNull($it)')) ) } } @@ -929,31 +931,31 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub } body( client: [ - first_name : $(stub(regex(onlyAlphaUnicode())), test('Denis')), - last_name : $(stub(regex(onlyAlphaUnicode())), test('FakeName')), - email : $(stub(regex(email())), test('fakemail@fakegmail.com')), - fax : $(stub(PHONE_NUMBER), test('+xx001213214')), - phone : $(stub(PHONE_NUMBER), test('2223311')), - data_of_birth: $(stub(DATETIME), test('2002-10-22T00:00:00Z')) + first_name : $(consumer(regex(onlyAlphaUnicode())), producer('Denis')), + last_name : $(consumer(regex(onlyAlphaUnicode())), producer('FakeName')), + email : $(consumer(regex(email())), producer('fakemail@fakegmail.com')), + fax : $(consumer(PHONE_NUMBER), producer('+xx001213214')), + phone : $(consumer(PHONE_NUMBER), producer('2223311')), + data_of_birth: $(consumer(DATETIME), producer('2002-10-22T00:00:00Z')) ], client_id_card: [ - id : $(stub(ANYSTRING), test('ABC12345')), - date_of_issue: $(stub(ANYSTRING), test('2002-10-02T00:00:00Z')), + id : $(consumer(ANYSTRING), producer('ABC12345')), + date_of_issue: $(consumer(ANYSTRING), producer('2002-10-02T00:00:00Z')), address : [ - street : $(stub(ANYSTRING), test('Light Street')), - city : $(stub(ANYSTRING), test('Fire')), - region : $(stub(ANYSTRING), test('Skys')), - country: $(stub(ANYSTRING), test('HG')), - zip : $(stub(NUMBERS), test('658965')) + street : $(consumer(ANYSTRING), producer('Light Street')), + city : $(consumer(ANYSTRING), producer('Fire')), + region : $(consumer(ANYSTRING), producer('Skys')), + country: $(consumer(ANYSTRING), producer('HG')), + zip : $(consumer(NUMBERS), producer('658965')) ] ], incomes_and_expenses: [ - monthly_income : $(stub(NUMBERS), test('0.0')), - monthly_loan_repayments: $(stub(NUMBERS), test('100')), - monthly_living_expenses: $(stub(NUMBERS), test('22')) + monthly_income : $(consumer(NUMBERS), producer('0.0')), + monthly_loan_repayments: $(consumer(NUMBERS), producer('100')), + monthly_living_expenses: $(consumer(NUMBERS), producer('22')) ], additional_info: [ - allow_to_contact: $(stub(optional(regex(anyBoolean()))), test('true')) + allow_to_contact: $(consumer(optional(regex(anyBoolean()))), producer('true')) ] ) } @@ -993,8 +995,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub } body( client: [ - first_name: $(stub(ONLY_ALPHA_UNICODE), test('Пенева')), - last_name : $(stub(ONLY_ALPHA_UNICODE), test('Пенева')) + first_name: $(consumer(ONLY_ALPHA_UNICODE), producer('Пенева')), + last_name : $(consumer(ONLY_ALPHA_UNICODE), producer('Пенева')) ] ) } @@ -1057,9 +1059,9 @@ World.'''""" header('content-type', 'multipart/form-data;boundary=AaB03x') } multipart( - formParameter: value(client(regex('.+')), server('"formParameterValue"')), - someBooleanParameter: value(client(regex('(true|false)')), server('true')), - file: named(value(client(regex('.+')), server('filename.csv')), value(client(regex('.+')), server('file content'))) + formParameter: value(consumer(regex('.+')), producer('"formParameterValue"')), + someBooleanParameter: value(consumer(regex('(true|false)')), producer('true')), + file: named(value(consumer(regex('.+')), producer('filename.csv')), value(consumer(regex('.+')), producer('file content'))) ) } response { @@ -1095,11 +1097,11 @@ World.'''""" method "PUT" url "/multipart" multipart( - formParameter: value(client(regex('".+"')), server('"formParameterValue"')), - someBooleanParameter: value(client(regex('(true|false)')), server('true')), + formParameter: value(consumer(regex('".+"')), producer('"formParameterValue"')), + someBooleanParameter: value(consumer(regex('(true|false)')), producer('true')), file: named( - name: value(client(regex('.+')), server('filename.csv')), - content: value(client(regex('.+')), server('file content'))) + name: value(consumer(regex('.+')), producer('filename.csv')), + content: value(consumer(regex('.+')), producer('file content'))) ) } response { @@ -1129,8 +1131,8 @@ World.'''""" queryParameters { parameter 'token': value( - client(regex('^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}')), - server('6973b31d-7140-402a-bca6-1cdb954e03a7') + consumer(regex('^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}')), + producer('6973b31d-7140-402a-bca6-1cdb954e03a7') ) } } @@ -1139,7 +1141,7 @@ World.'''""" status 200 body( authorities: [ - value(stub('ROLE_ADMIN'), test(regex('^[a-zA-Z0-9_\\- ]+$'))) + value(consumer('ROLE_ADMIN'), producer(regex('^[a-zA-Z0-9_\\- ]+$'))) ] ) } @@ -1163,8 +1165,8 @@ World.'''""" queryParameters { parameter 'token': value( - client(regex('^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}')), - server('6973b31d-7140-402a-bca6-1cdb954e03a7') + consumer(regex('^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}')), + producer('6973b31d-7140-402a-bca6-1cdb954e03a7') ) } } @@ -1173,7 +1175,7 @@ World.'''""" status 200 body( authorities: [ - value(stub('ROLE_ADMIN'), test(regex('^[a-zA-Z0-9_\\- ]+$'))) + value(consumer('ROLE_ADMIN'), producer(regex('^[a-zA-Z0-9_\\- ]+$'))) ] ) } @@ -1198,7 +1200,7 @@ World.'''""" status 200 body( fraudCheckStatus: "OK", - rejectionReason: $(client(null), server(execute('assertThatRejectionReasonIsNull($it)'))) + rejectionReason: $(consumer(null), producer(execute('assertThatRejectionReasonIsNull($it)'))) ) } @@ -1228,11 +1230,11 @@ World.'''""" response { status 200 body([[id: value( - client('123'), - server(regex('[0-9]+')) + consumer('123'), + producer(regex('[0-9]+')) )], [id: value( - client('567'), - server(regex('[0-9]+')) + consumer('567'), + producer(regex('[0-9]+')) )]]) headers { header('Content-Type': 'application/json;charset=UTF-8') @@ -1386,7 +1388,7 @@ World.'''""" } response { status 200 - body( code: 9, message: $(client('Wrong credentials'), server(regex('^(?!\\s*$).+'))) ) + body( code: 9, message: $(consumer('Wrong credentials'), producer(regex('^(?!\\s*$).+'))) ) } } MethodBodyBuilder builder = new MockMvcSpockMethodRequestProcessingBodyBuilder(contractDsl, properties) @@ -1451,13 +1453,13 @@ World.'''""" method 'PUT' url '/foo' body([ - requestElement: value(client(regex('[0-9]{5}'))) + requestElement: value(consumer(regex('[0-9]{5}'))) ]) } response { status 200 body([ - responseElement: value(server(regex('[0-9]{7}'))) + responseElement: value(producer(regex('[0-9]{7}'))) ]) } } diff --git a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/WireMockGroovyDslSpec.groovy b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/WireMockGroovyDslSpec.groovy index 04e0a36783..92cc74640a 100755 --- a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/WireMockGroovyDslSpec.groovy +++ b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/WireMockGroovyDslSpec.groovy @@ -31,21 +31,21 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie org.springframework.cloud.contract.spec.Contract groovyDsl = org.springframework.cloud.contract.spec.Contract.make { request { method('GET') - url $(client(~/\/[0-9]{2}/), server('/12')) + url $(consumer(~/\/[0-9]{2}/), producer('/12')) } response { status 200 body( id: value( - client('123'), - server(regex('[0-9]+')) + consumer('123'), + producer(regex('[0-9]+')) ), surname: $( - client('Kowalsky'), - server('Lewandowski') + consumer('Kowalsky'), + producer('Lewandowski') ), name: 'Jan', - created: $(client('2014-02-02 12:23:43'), server({ currentDate(it) })) + created: $(consumer('2014-02-02 12:23:43'), producer({ currentDate(it) })) ) headers { header 'Content-Type': 'text/plain' @@ -132,15 +132,15 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie header("Content-Type": 'application/x-www-form-urlencoded') } body("""paymentType=INCOMING&transferType=BANK&amount=${ - value(client(regex('[0-9]{3}\\.[0-9]{2}')), server(500.00)) + value(consumer(regex('[0-9]{3}\\.[0-9]{2}')), producer(500.00)) }&bookingDate=${ - value(client(regex('[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])')), server('2015-05-18')) + value(consumer(regex('[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])')), producer('2015-05-18')) }""") } response { status 204 body( - paymentId: value(client('4'), server(regex('[1-9][0-9]*'))), + paymentId: value(consumer('4'), producer(regex('[1-9][0-9]*'))), foundExistingPayment: false ) } @@ -179,16 +179,16 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie org.springframework.cloud.contract.spec.Contract groovyDsl = org.springframework.cloud.contract.spec.Contract.make { request { method('GET') - url $(client(~/\/[0-9]{2}/), server('/12')) + url $(consumer(~/\/[0-9]{2}/), producer('/12')) } response { status 200 body("""\ { - "id": "${value(client('123'), server('321'))}", - "surname": "${value(client('Kowalsky'), server('Lewandowski'))}", + "id": "${value(consumer('123'), producer('321'))}", + "surname": "${value(consumer('Kowalsky'), producer('Lewandowski'))}", "name": "Jan", - "created" : "${$(client('2014-02-02 12:23:43'), server('2999-09-09 01:23:45'))}" + "created" : "${$(consumer('2014-02-02 12:23:43'), producer('2999-09-09 01:23:45'))}" } """ ) @@ -224,7 +224,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie org.springframework.cloud.contract.spec.Contract groovyDsl = org.springframework.cloud.contract.spec.Contract.make { request { method('GET') - url $(client(regex('/[0-9]{2}')), server('/12')) + url $(consumer(regex('/[0-9]{2}')), producer('/12')) body """ { "name": "Jan" @@ -274,18 +274,18 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie org.springframework.cloud.contract.spec.Contract groovyDsl = org.springframework.cloud.contract.spec.Contract.make { request { method('GET') - url $(client(~/\/[0-9]{2}/), server('/12')) + url $(consumer(~/\/[0-9]{2}/), producer('/12')) body( id: value( - client('123'), - server({ regex('[0-9]+') }) + consumer('123'), + producer({ regex('[0-9]+') }) ), surname: $( - client('Kowalsky'), - server('Lewandowski') + consumer('Kowalsky'), + producer('Lewandowski') ), name: 'Jan', - created: $(client('2014-02-02 12:23:43'), server({ currentDate(it) })) + created: $(consumer('2014-02-02 12:23:43'), producer({ currentDate(it) })) ) } response { @@ -373,8 +373,8 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie headers { header "Content-Type", "customtype/xml" } - body """${value(client('Jozo'), server('Denis'))}${ - value(client(""), server('1234567890')) + body """${value(consumer('Jozo'), producer('Denis'))}${ + value(consumer(""), producer('1234567890')) }""" } response { @@ -415,8 +415,8 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie request { method 'GET' url "/users" - body """${value(client('Jozo'), server('Denis'))}${ - value(client(""), server('1234567890')) + body """${value(consumer('Jozo'), producer('Denis'))}${ + value(consumer(""), producer('1234567890')) }""" } response { @@ -455,8 +455,8 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } response { status 200 - body """${value(client('Jozo'), server('Denis'))}${ - value(client(""), server('1234567890')) + body """${value(consumer('Jozo'), producer('Denis'))}${ + value(consumer(""), producer('1234567890')) }""" } } @@ -520,8 +520,8 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie request { method 'GET' url "/users" - body equalToXml("""${value(client('Jozo'), server('Denis'))}${ - value(client(""), server('1234567890')) + body equalToXml("""${value(consumer('Jozo'), producer('Denis'))}${ + value(consumer(""), producer('1234567890')) }""") } response { @@ -556,10 +556,10 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie org.springframework.cloud.contract.spec.Contract groovyDsl = org.springframework.cloud.contract.spec.Contract.make { request { method('GET') - url $(client(regex('/[0-9]{2}')), server('/12')) + url $(consumer(regex('/[0-9]{2}')), producer('/12')) body """ { - "personalId": "${value(client(regex('^[0-9]{11}$')), server('57593728525'))}" + "personalId": "${value(consumer(regex('^[0-9]{11}$')), producer('57593728525'))}" } """ } @@ -609,7 +609,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie url '/fraudcheck' body(""" { - "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", + "clientPesel":"${value(consumer(regex('[0-9]{10}')), producer('1234567890'))}", "loanAmount":123.123 } """ @@ -623,7 +623,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie status 200 body( fraudCheckStatus: "OK", - rejectionReason: $(client(null), server(execute('assertThatRejectionReasonIsNull($it)'))) + rejectionReason: $(consumer(null), producer(execute('assertThatRejectionReasonIsNull($it)'))) ) headers { header('Content-Type': 'application/vnd.fraud.v1+json') @@ -668,15 +668,15 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie org.springframework.cloud.contract.spec.Contract groovyDsl = org.springframework.cloud.contract.spec.Contract.make { request { method 'GET' - urlPath($(client("users"), server("items"))) { + urlPath($(consumer("users"), producer("items"))) { queryParameters { - parameter 'limit': $(client(equalTo("20")), server("10")) - parameter 'offset': $(client(containing("10")), server("10")) + parameter 'limit': $(consumer(equalTo("20")), producer("10")) + parameter 'offset': $(consumer(containing("10")), producer("10")) parameter 'filter': "email" - parameter 'sort': $(client(~/^[0-9]{10}$/), server("1234567890")) - parameter 'search': $(client(notMatching(~/^\/[0-9]{2}$/)), server("10")) - parameter 'age': $(client(notMatching("^\\w*\$")), server(10)) - parameter 'name': $(client(matching("Denis.*")), server("Denis")) + parameter 'sort': $(consumer(~/^[0-9]{10}$/), producer("1234567890")) + parameter 'search': $(consumer(notMatching(~/^\/[0-9]{2}$/)), producer("10")) + parameter 'age': $(consumer(notMatching("^\\w*\$")), producer(10)) + parameter 'name': $(consumer(matching("Denis.*")), producer("Denis")) parameter 'credit': absent() } } @@ -736,9 +736,9 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie org.springframework.cloud.contract.spec.Contract groovyDsl = org.springframework.cloud.contract.spec.Contract.make { request { method 'GET' - urlPath($(client(regex("/users/[0-9]+")), server("/users/1"))) { + urlPath($(consumer(regex("/users/[0-9]+")), producer("/users/1"))) { queryParameters { - parameter 'search': $(client(notMatching(~/^\/[0-9]{2}$/)), server("10")) + parameter 'search': $(consumer(notMatching(~/^\/[0-9]{2}$/)), producer("10")) } } } @@ -775,7 +775,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie org.springframework.cloud.contract.spec.Contract groovyDsl = org.springframework.cloud.contract.spec.Contract.make { request { method 'GET' - urlPath $(client("boxes"), server("items")) + urlPath $(consumer("boxes"), producer("items")) } response { status 200 @@ -856,7 +856,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie method 'GET' url("abc") { queryParameters { - parameter 'age': $(client(notMatching("^\\w*\$")), server(regex(".*"))) + parameter 'age': $(consumer(notMatching("^\\w*\$")), producer(regex(".*"))) } } } @@ -902,7 +902,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie method 'GET' urlPath("users") { queryParameters { - parameter 'name': $(client(absent()), server("")) + parameter 'name': $(consumer(absent()), producer("")) } } } @@ -915,7 +915,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie method 'GET' urlPath("users") { queryParameters { - parameter 'name': $(client(""), server(absent())) + parameter 'name': $(consumer(""), producer(absent())) } } } @@ -928,7 +928,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie method 'GET' urlPath("users") { queryParameters { - parameter 'name': $(client(absent()), server(matching("abc"))) + parameter 'name': $(consumer(absent()), producer(matching("abc"))) } } } @@ -944,10 +944,10 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie org.springframework.cloud.contract.spec.Contract groovyDsl = org.springframework.cloud.contract.spec.Contract.make { request { method 'GET' - url($(client(regex(/users\/[0-9]*/)), server("users/123"))) { + url($(consumer(regex(/users\/[0-9]*/)), producer("users/123"))) { queryParameters { - parameter 'age': $(client(notMatching("^\\w*\$")), server(10)) - parameter 'name': $(client(matching("Denis.*")), server("Denis")) + parameter 'age': $(consumer(notMatching("^\\w*\$")), producer(10)) + parameter 'name': $(consumer(matching("Denis.*")), producer("Denis")) } } } @@ -986,20 +986,20 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie org.springframework.cloud.contract.spec.Contract groovyDsl = org.springframework.cloud.contract.spec.Contract.make { request { method('GET') - url $(client(~/\/[0-9]{2}/), server('/12')) + url $(consumer(~/\/[0-9]{2}/), producer('/12')) body """\ { - "personalId": "${value(client(regex('[0-9]{11}')), server('57593728525'))}", - "firstName": "${value(client(regex('.*')), server('Bruce'))}", - "lastName": "${value(client(regex('.*')), server('Lee'))}", - "birthDate": "${value(client(regex('[0-9]{4}-[0-9]{2}-[0-9]{2}')), server('1985-12-12'))}", + "personalId": "${value(consumer(regex('[0-9]{11}')), producer('57593728525'))}", + "firstName": "${value(consumer(regex('.*')), producer('Bruce'))}", + "lastName": "${value(consumer(regex('.*')), producer('Lee'))}", + "birthDate": "${value(consumer(regex('[0-9]{4}-[0-9]{2}-[0-9]{2}')), producer('1985-12-12'))}", "errors": [ { - "propertyName": "${value(client(regex('[0-9]{2}')), server('04'))}", + "propertyName": "${value(consumer(regex('[0-9]{2}')), producer('04'))}", "providerValue": "Test" }, { - "propertyName": "${value(client(regex('[0-9]{2}')), server('08'))}", + "propertyName": "${value(consumer(regex('[0-9]{2}')), producer('08'))}", "providerValue": "Test" } ] @@ -1060,10 +1060,10 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie url '/reissue-payment-order' body( loanNumber: "999997001", - amount: value(client(regex('[0-9.]+')), server('100.00')), + amount: value(consumer(regex('[0-9.]+')), producer('100.00')), currency: "DKK", - applicationName: value(client(regex('.*')), server("Auto-Repayments")), - username: value(client(regex('.*')), server("scheduler")), + applicationName: value(consumer(regex('.*')), producer("Auto-Repayments")), + username: value(consumer(regex('.*')), producer("scheduler")), cardId: 1 ) } @@ -1182,7 +1182,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie method('POST') url("foo") body( - property: value(stub("value"), test("value")) + property: value(consumer("value"), producer("value")) ) } response { @@ -1257,8 +1257,8 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie header 'Content-Type': 'application/json' } body( - email: $(client(regex(email())), server('not.existing@user.com')), - callback_url: $(client(regex(hostname())), server('http://partners.com')) + email: $(consumer(regex(email())), producer('not.existing@user.com')), + callback_url: $(consumer(regex(hostname())), producer('http://partners.com')) ) } response { @@ -1268,7 +1268,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } body( code: 4, - message: "User not found by email = [${value(server(regex(email())), client('not.existing@user.com'))}]" + message: "User not found by email = [${value(producer(regex(email())), consumer('not.existing@user.com'))}]" ) } } @@ -1311,7 +1311,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie request { method 'PUT' - url "/partners/${value(client(regex('^[0-9]*$')), server('11'))}/agents/11/customers/09665703Z" + url "/partners/${value(consumer(regex('^[0-9]*$')), producer('11'))}/agents/11/customers/09665703Z" headers { header 'Content-Type': 'application/json' } @@ -1393,8 +1393,8 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie header 'Content-Type': 'application/json' } body( - email: $(stub(optional(regex(email()))), test('abc@abc.com')), - callback_url: $(stub(regex(hostname())), test('http://partners.com')) + email: $(consumer(optional(regex(email()))), producer('abc@abc.com')), + callback_url: $(consumer(regex(hostname())), producer('http://partners.com')) ) } response { @@ -1403,8 +1403,8 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie header 'Content-Type': 'application/json' } body( - code: $(stub("123123"), test(optional("123123"))), - message: "User not found by email = [${value(test(regex(email())), stub('not.existing@user.com'))}]" + code: $(consumer("123123"), producer(optional("123123"))), + message: "User not found by email = [${value(producer(regex(email())), consumer('not.existing@user.com'))}]" ) } }, @@ -1418,8 +1418,8 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } body( """ { - "email" : "${value(stub(optional(regex(email()))), test('abc@abc.com'))}", - "callback_url" : "${value(client(regex(hostname())), server('http://partners.com'))}" + "email" : "${value(consumer(optional(regex(email()))), producer('abc@abc.com'))}", + "callback_url" : "${value(consumer(regex(hostname())), producer('http://partners.com'))}" } """ ) @@ -1431,8 +1431,8 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } body( """ { - "code" : "${value(stub(123123), test(optional(123123)))}", - "message" : "User not found by email = [${value(server(regex(email())), client('not.existing@user.com'))}]" + "code" : "${value(consumer(123123), producer(optional(123123)))}", + "message" : "User not found by email = [${value(producer(regex(email())), consumer('not.existing@user.com'))}]" } """ ) @@ -1461,11 +1461,11 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie method "PUT" url "/multipart" multipart( - formParameter: value(client(regex('".+"')), server('"formParameterValue"')), - someBooleanParameter: value(client(regex('(true|false)')), server('true')), + formParameter: value(consumer(regex('".+"')), producer('"formParameterValue"')), + someBooleanParameter: value(consumer(regex('(true|false)')), producer('true')), file: named( - name: value(client(regex('.+')), server('filename.csv')), - content: value(client(regex('.+')), server('file content'))) + name: value(consumer(regex('.+')), producer('filename.csv')), + content: value(consumer(regex('.+')), producer('file content'))) ) } response { @@ -1507,16 +1507,16 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie urlPath ('/some/api') { queryParameters { parameter 'size': value( - client(regex('[0-9]+')), - server(1) + consumer(regex('[0-9]+')), + producer(1) ) parameter 'page': value( - client(regex('[0-9]+')), - server(0) + consumer(regex('[0-9]+')), + producer(0) ) parameter sort: value( - client(optional(regex('^[a-z]+$'))), - server('id') + consumer(optional(regex('^[a-z]+$'))), + producer('id') ) } } diff --git a/spring-cloud-contract-verifier/src/test/resources/dsl/basic/sampleDsl.groovy b/spring-cloud-contract-verifier/src/test/resources/dsl/basic/sampleDsl.groovy index a24fc9fb0a..7cf9bdc0e6 100644 --- a/spring-cloud-contract-verifier/src/test/resources/dsl/basic/sampleDsl.groovy +++ b/spring-cloud-contract-verifier/src/test/resources/dsl/basic/sampleDsl.groovy @@ -25,19 +25,19 @@ Contract.make { body("""\ { "name": "Jan", - "id": "${value(client('abc'), server('def'))}", + "id": "${value(consumer('abc'), producer('def'))}", } """ ) - url $(client('/[0-9]{2}'), server('/12')) + url $(consumer('/[0-9]{2}'), producer('/12')) } response { status 200 body("""\ { "name": "Jan", - "id": "${value(client('123'), server('321'))}", - "surname": "${value(client('Kowalsky'), server('$checkIfSurnameValid($value)'))}" + "id": "${value(consumer('123'), producer('321'))}", + "surname": "${value(consumer('Kowalsky'), producer('$checkIfSurnameValid($value)'))}" } """ )