From c139851901e20df22343108d238663447e27a94d Mon Sep 17 00:00:00 2001 From: Olga Maciaszek-Sharma Date: Mon, 3 Jun 2019 19:43:36 +0200 Subject: [PATCH 1/6] Fix gh branch in docs. --- README.adoc | 2 +- docs/src/main/asciidoc/README.adoc | 2 +- docs/src/main/asciidoc/spring-cloud-contract.adoc | 2 +- spring-cloud-contract-stub-runner/README.adoc | 4 ++-- .../src/site/asciidoc/index.adoc | 2 +- .../src/site/asciidoc/junit.adoc | 2 +- .../src/site/asciidoc/spock.adoc | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.adoc b/README.adoc index 3a0dc74c7e..e307964a1c 100644 --- a/README.adoc +++ b/README.adoc @@ -4,7 +4,7 @@ Manual changes to this file will be lost when it is generated again. Edit the files in the src/main/asciidoc/ directory instead. //// -:branch: master +:branch: 2.1.x image::https://badges.gitter.im/Join%20Chat.svg[Gitter, link="https://gitter.im/spring-cloud/spring-cloud-contract?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"] image::https://codecov.io/gh/spring-cloud/spring-cloud-contract/branch/{branch}/graph/badge.svg["codecov", link="https://codecov.io/gh/spring-cloud/spring-cloud-contract"] image::https://circleci.com/gh/spring-cloud/spring-cloud-contract.svg?style=svg["CircleCI", link="https://circleci.com/gh/spring-cloud/spring-cloud-contract"] diff --git a/docs/src/main/asciidoc/README.adoc b/docs/src/main/asciidoc/README.adoc index cf91eb0f74..5e0d0c0da9 100644 --- a/docs/src/main/asciidoc/README.adoc +++ b/docs/src/main/asciidoc/README.adoc @@ -1,4 +1,4 @@ -:branch: master +:branch: 2.1.x image::https://badges.gitter.im/Join%20Chat.svg[Gitter, link="https://gitter.im/spring-cloud/spring-cloud-contract?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"] image::https://codecov.io/gh/spring-cloud/spring-cloud-contract/branch/{branch}/graph/badge.svg["codecov", link="https://codecov.io/gh/spring-cloud/spring-cloud-contract"] image::https://circleci.com/gh/spring-cloud/spring-cloud-contract.svg?style=svg["CircleCI", link="https://circleci.com/gh/spring-cloud/spring-cloud-contract"] diff --git a/docs/src/main/asciidoc/spring-cloud-contract.adoc b/docs/src/main/asciidoc/spring-cloud-contract.adoc index a0b79b8813..63de66c217 100644 --- a/docs/src/main/asciidoc/spring-cloud-contract.adoc +++ b/docs/src/main/asciidoc/spring-cloud-contract.adoc @@ -5,7 +5,7 @@ :numbered: :icons: font :sectlinks: true -:branch: master +:branch: 2.1.x = Spring Cloud Contract diff --git a/spring-cloud-contract-stub-runner/README.adoc b/spring-cloud-contract-stub-runner/README.adoc index d13c12b64f..f06b5fdd0a 100644 --- a/spring-cloud-contract-stub-runner/README.adoc +++ b/spring-cloud-contract-stub-runner/README.adoc @@ -1,5 +1,5 @@ -:branch: master -:samples_branch: 2.0.x +:branch: 2.1.x +:samples_branch: 2.1.x === Stub Runner Core diff --git a/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/site/asciidoc/index.adoc b/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/site/asciidoc/index.adoc index f3ae38d84b..098a7df5d8 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/site/asciidoc/index.adoc +++ b/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/site/asciidoc/index.adoc @@ -1,4 +1,4 @@ -:samples_branch: 2.0.x +:samples_branch: 2.1.x = Spring Cloud Contract Maven Plugin diff --git a/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/site/asciidoc/junit.adoc b/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/site/asciidoc/junit.adoc index 71a077f97b..8afd158e40 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/site/asciidoc/junit.adoc +++ b/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/site/asciidoc/junit.adoc @@ -1,4 +1,4 @@ -:branch: master +:branch: 2.1.x == Java Project with JUnit Tests diff --git a/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/site/asciidoc/spock.adoc b/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/site/asciidoc/spock.adoc index 2b5f0b7e55..fbfeb50792 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/site/asciidoc/spock.adoc +++ b/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/site/asciidoc/spock.adoc @@ -1,4 +1,4 @@ -:branch: master +:branch: 2.1.x == Groovy Project with Spock Specifications From 60b9e9e1f02ae49ee73828f774957151b4336510 Mon Sep 17 00:00:00 2001 From: Artem Ptushkin Date: Wed, 19 Jun 2019 11:16:41 +0300 Subject: [PATCH 2/6] Fixed MissingMethodExceptionNoStack at creating assertion for spock test (#1110) * Created test for the issue #1089 - failed with MissingMethodExceptionNoStack * Created groovy unit test for the issue #1089 - failed with MissingMethodExceptionNoStack * Fixed MissingMethodExceptionNoStack (#1089) * Changed SpringCloudContractAssertions to groovy with compileStatic fixes gh-1089 --- .../main/java/hello/GreetingController.java | 24 +- .../src/main/java/hello/GreetingResponse.java | 47 +++ .../contracts/greetings_post_ok.groovy | 53 +-- .../SpringCloudContractAssertions.groovy | 19 + .../assertion/CollectionAssertSpec.groovy | 360 ++++++++++++++++++ 5 files changed, 475 insertions(+), 28 deletions(-) create mode 100644 spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/spring-boot-groovy/src/main/java/hello/GreetingResponse.java rename spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/assertion/SpringCloudContractAssertions.java => spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/spring-boot-groovy/src/test/resources/contracts/greetings_post_ok.groovy (50%) create mode 100644 spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/assertion/SpringCloudContractAssertions.groovy create mode 100644 spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/assertion/CollectionAssertSpec.groovy diff --git a/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/spring-boot-groovy/src/main/java/hello/GreetingController.java b/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/spring-boot-groovy/src/main/java/hello/GreetingController.java index ac5feb3e39..a6bb8747a2 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/spring-boot-groovy/src/main/java/hello/GreetingController.java +++ b/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/spring-boot-groovy/src/main/java/hello/GreetingController.java @@ -14,12 +14,15 @@ * limitations under the License. */package hello; -import java.util.concurrent.atomic.AtomicLong; - -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.util.ArrayList; +import java.util.concurrent.atomic.AtomicLong; + +import static java.util.Arrays.asList; + @RestController public class GreetingController { @@ -27,10 +30,23 @@ public class GreetingController { private final AtomicLong counter = new AtomicLong(); - @RequestMapping("/greeting") + @GetMapping("/greeting") public Greeting greeting( @RequestParam(value = "name", defaultValue = "World") String name) { return new Greeting(counter.incrementAndGet(), String.format(template, name)); } + @GetMapping(value = "/accounts") + public GreetingResponse accounts( + @RequestParam(value = "name", defaultValue = "World") String name) { + return new GreetingResponse( + name, + new ArrayList<>( + asList( + new GreetingResponse.Account("account1"), + new GreetingResponse.Account("account2")) + ) + ); + } + } diff --git a/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/spring-boot-groovy/src/main/java/hello/GreetingResponse.java b/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/spring-boot-groovy/src/main/java/hello/GreetingResponse.java new file mode 100644 index 0000000000..5510787a85 --- /dev/null +++ b/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/spring-boot-groovy/src/main/java/hello/GreetingResponse.java @@ -0,0 +1,47 @@ +package hello; + +import java.util.List; + +public class GreetingResponse { + String name; + List accounts; + + public GreetingResponse(String name, List accounts) { + this.name = name; + this.accounts = accounts; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getAccounts() { + return accounts; + } + + public void setAccounts(List accounts) { + this.accounts = accounts; + } + + static class Account { + + String key; + + public Account(String key) { + this.key = key; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + } +} diff --git a/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/assertion/SpringCloudContractAssertions.java b/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/spring-boot-groovy/src/test/resources/contracts/greetings_post_ok.groovy similarity index 50% rename from spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/assertion/SpringCloudContractAssertions.java rename to spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/spring-boot-groovy/src/test/resources/contracts/greetings_post_ok.groovy index cd4cf90f32..ff871765c0 100644 --- a/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/assertion/SpringCloudContractAssertions.java +++ b/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/spring-boot-groovy/src/test/resources/contracts/greetings_post_ok.groovy @@ -12,29 +12,34 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -package org.springframework.cloud.contract.verifier.assertion; - -import org.assertj.core.api.Assertions; - -/** - * Assertions used by the generated tests. - * - * @author Marcin Grzejszczak - * @since 1.1.0 - */ -public class SpringCloudContractAssertions extends Assertions { - - /** - * Creates a new instance of {@link CollectionAssert}. - * @param type to assert - * @param actual the actual value. - * @return the created assertion object. - */ - public static CollectionAssert assertThat( - Iterable actual) { - return new CollectionAssert<>(actual); + */ org.springframework.cloud.contract.spec.Contract.make { + priority 2 + request { + method 'GET' + urlPath('/accounts') { + queryParameters { + parameter 'name': 'Something' + } + } + headers { + header 'Content-Type': 'application/json' + } + } + response { + status OK() + body ( + name: fromRequest().query('name'), + accounts: [ + [ + key: 'account1' + ], + [ + key: 'account2' + ] + ] + ) + bodyMatchers { + jsonPath('$.accounts[*].key', byRegex('account.*')) + } } - } diff --git a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/assertion/SpringCloudContractAssertions.groovy b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/assertion/SpringCloudContractAssertions.groovy new file mode 100644 index 0000000000..0f25773135 --- /dev/null +++ b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/assertion/SpringCloudContractAssertions.groovy @@ -0,0 +1,19 @@ +package org.springframework.cloud.contract.verifier.assertion + +import groovy.transform.CompileStatic +import org.assertj.core.api.Assertions + +@CompileStatic +public class SpringCloudContractAssertions extends Assertions { + + /** + * Creates a new instance of {@link CollectionAssert}. + * @param type to assert + * @param actual the actual value. + * @return the created assertion object. + */ + public static CollectionAssert assertThat( + Iterable actual) { + return new CollectionAssert<>(actual); + } +} diff --git a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/assertion/CollectionAssertSpec.groovy b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/assertion/CollectionAssertSpec.groovy new file mode 100644 index 0000000000..69b244b978 --- /dev/null +++ b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/assertion/CollectionAssertSpec.groovy @@ -0,0 +1,360 @@ +package org.springframework.cloud.contract.verifier.assertion + +import org.assertj.core.api.Assertions +import spock.lang.Specification + +/** + * @author Marcin Grzejszczak, Artem Ptushkin + */ +class CollectionAssertSpec extends Specification { + + def should_not_throw_an_exception_when_all_elements_match_regex() { + setup: + Collection collection = collection() + + when: + SpringCloudContractAssertions.assertThat(collection).allElementsMatch("[a-z]") + + then: + noExceptionThrown() + } + + def should_throw_an_exception_when_at_least_one_element_doesnt_match_regex() { + setup: + Collection collection = collection() + + when: + SpringCloudContractAssertions.assertThat(collection) + .allElementsMatch("[0-9]") + + then: + AssertionError e = thrown() + Assertions.assertThat(e).hasMessageContaining( + "The value doesn't match the regex <[0-9]>") + } + + def should_throw_an_exception_when_element_is_null() { + setup: + Collection collection = collectionWithNulls() + + when: + SpringCloudContractAssertions.assertThat(collection) + .allElementsMatch("[0-9]") + + then: + AssertionError e = thrown() + Assertions.assertThat(e).hasMessageContaining( + "The value doesn't match the regex <[0-9]>") + + } + + def should_throw_an_exception_when_collection_is_null() { + setup: + Collection collection = null + + when: + SpringCloudContractAssertions.assertThat(collection).allElementsMatch("foo") + + then: + AssertionError e = thrown() + Assertions.assertThat(e) + .hasMessageContaining("Expecting actual not to be null") + } + + def should_throw_an_exception_when_collection_is_empty() { + setup: + Collection collection = new ArrayList() + + when: + SpringCloudContractAssertions.assertThat(collection).allElementsMatch("foo") + + then: + AssertionError e = thrown() + Assertions.assertThat(e) + .hasMessageContaining("Expecting actual not to be empty") + } + + def should_not_throw_an_exception_when_flattened_size_is_greater_than_or_equal_to_provided_size() { + setup: + Collection collection = nestedCollection() + + when: + SpringCloudContractAssertions.assertThat(collection) + .hasFlattenedSizeGreaterThanOrEqualTo(0) + .hasFlattenedSizeGreaterThanOrEqualTo(4) + + then: + noExceptionThrown() + } + + def should_throw_an_exception_when_flattened_size_is_not_greater_than_or_equal_to_provided_size() { + setup: + Collection collection = nestedCollection() + + when: + SpringCloudContractAssertions.assertThat(collection) + .hasFlattenedSizeGreaterThanOrEqualTo(5) + + then: + AssertionError e = thrown() + Assertions.assertThat(e).hasMessageContaining( + "The flattened size <4> is not greater or equal to <5>") + } + + def should_throw_an_exception_when_collection_is_null_for_flattened_greater_than_or_equal() { + setup: + Collection collection = null + + when: + SpringCloudContractAssertions.assertThat(collection) + .hasFlattenedSizeGreaterThanOrEqualTo(1) + then: + AssertionError e = thrown() + Assertions.assertThat(e) + .hasMessageContaining("Expecting actual not to be null") + } + + def should_not_throw_an_exception_when_flattened_size_is_less_than_or_equal_to_provided_size() { + setup: + Collection collection = nestedCollection() + + when: + SpringCloudContractAssertions.assertThat(collection) + .hasFlattenedSizeLessThanOrEqualTo(5) + .hasFlattenedSizeLessThanOrEqualTo(4) + + then: + noExceptionThrown() + } + + def should_throw_an_exception_when_flattened_size_is_not_less_than_or_equal_to_provided_size() { + setup: + Collection collection = nestedCollection() + + when: + SpringCloudContractAssertions.assertThat(collection) + .hasFlattenedSizeLessThanOrEqualTo(1) + + then: + AssertionError e = thrown() + Assertions.assertThat(e).hasMessageContaining( + "The flattened size <4> is not less or equal to <1>") + } + + def should_throw_an_exception_when_collection_is_null_for_flattened_less_than_or_equal() { + setup: + Collection collection = null + + when: + SpringCloudContractAssertions.assertThat(collection) + .hasFlattenedSizeLessThanOrEqualTo(1) + + then: + AssertionError e = thrown() + Assertions.assertThat(e) + .hasMessageContaining("Expecting actual not to be null") + } + + def should_not_throw_an_exception_when_flattened_size_is_between_the_provided_sizes() { + setup: + Collection collection = nestedCollection() + + when: + SpringCloudContractAssertions.assertThat(collection).hasFlattenedSizeBetween(1, 5) + .hasFlattenedSizeBetween(4, 4) + + then: + noExceptionThrown() + } + + def should_throw_an_exception_when_flattened_size_is_not_between_the_provided_sizes() { + setup: + Collection collection = nestedCollection() + + when: + SpringCloudContractAssertions.assertThat(collection) + .hasFlattenedSizeBetween(5, 7) + + then: + AssertionError e = thrown() + Assertions.assertThat(e).hasMessageContaining( + "The flattened size <4> is not between <5> and <7>") + } + + def should_throw_an_exception_when_collection_is_null_for_flattened_between() { + setup: + Collection collection = null + + when: + SpringCloudContractAssertions.assertThat(collection) + .hasFlattenedSizeBetween(1, 2) + + then: + AssertionError e = thrown() + Assertions.assertThat(e) + .hasMessageContaining("Expecting actual not to be null") + } + + def should_not_throw_an_exception_when_size_is_greater_than_or_equal_to_provided_size() { + setup: + Collection collection = collection() + + when: + SpringCloudContractAssertions.assertThat(collection) + .hasSizeGreaterThanOrEqualTo(0).hasSizeGreaterThanOrEqualTo(3) + + then: + noExceptionThrown() + } + + def should_throw_an_exception_when_size_is_not_greater_than_or_equal_to_provided_size() { + setup: + Collection collection = collection() + + when: + SpringCloudContractAssertions.assertThat(collection) + .hasSizeGreaterThanOrEqualTo(5) + + then: + AssertionError e = thrown() + Assertions.assertThat(e) + .hasMessageContaining("The size <3> is not greater or equal to <5>") + } + + def should_throw_an_exception_when_collection_is_null_for_greater_than_or_equal() { + setup: + Collection collection = null + + when: + SpringCloudContractAssertions.assertThat(collection) + .hasSizeGreaterThanOrEqualTo(1) + then: + AssertionError e = thrown() + Assertions.assertThat(e) + .hasMessageContaining("Expecting actual not to be null") + } + + def should_not_throw_an_exception_when_size_is_less_than_or_equal_to_provided_size() { + setup: + Collection collection = collection() + + when: + SpringCloudContractAssertions.assertThat(collection).hasSizeLessThanOrEqualTo(4) + .hasSizeLessThanOrEqualTo(3) + + then: + noExceptionThrown() + } + + def should_throw_an_exception_when_size_is_not_less_than_or_equal_to_provided_size() { + setup: + Collection collection = collection() + + when: + SpringCloudContractAssertions.assertThat(collection) + .hasSizeLessThanOrEqualTo(1) + + then: + AssertionError e = thrown() + Assertions.assertThat(e) + .hasMessageContaining("The size <3> is not less or equal to <1>") + } + + def should_throw_an_exception_when_collection_is_null_for_less_than_or_equal() { + setup: + Collection collection = null + + when: + SpringCloudContractAssertions.assertThat(collection) + .hasSizeLessThanOrEqualTo(1) + + then: + AssertionError e = thrown() + Assertions.assertThat(e) + .hasMessageContaining("Expecting actual not to be null") + } + + def should_not_throw_an_exception_when_size_is_between_the_provided_sizes() { + setup: + Collection collection = collection() + + when: + SpringCloudContractAssertions.assertThat(collection).hasSizeBetween(1, 4) + .hasSizeBetween(3, 3) + + then: + noExceptionThrown() + } + + def should_throw_an_exception_when_size_is_not_between_the_provided_sizes() { + setup: + Collection collection = collection() + + when: + SpringCloudContractAssertions.assertThat(collection).hasSizeBetween(5, 7) + + then: + AssertionError e = thrown() + Assertions.assertThat(e) + .hasMessageContaining("The size <3> is not between <5> and <7>") + } + + def should_not_break_compilation_when_using_as() { + setup: + Collection collection = collection() + + when: + SpringCloudContractAssertions.assertThat(collection).as("for jsonpath x.y.z") + .hasSizeBetween(5, 7) + + then: + AssertionError e = thrown() + Assertions.assertThat(e).hasMessageContaining( + "[for jsonpath x.y.z] The size <3> is not between <5> and <7>") + } + + def should_throw_an_exception_when_collection_is_null_for_between() { + setup: + Collection collection = null + + when: + SpringCloudContractAssertions.assertThat(collection).hasSizeBetween( 1, 2) + + then: + AssertionError e = thrown() + Assertions.assertThat(e) + .hasMessageContaining("Expecting actual not to be null") + } + + Collection collection() { + List list = new ArrayList<>() + list.add("a") + list.add("b") + list.add("c") + return list + } + + Collection collectionWithNulls() { + List list = new ArrayList<>() + list.add(null) + return list + } + + Collection nestedCollection() { + List list = new ArrayList<>() + List list1 = new ArrayList<>() + Map map1 = new HashMap<>() + map1.put("a", "1") + map1.put("b", "2") + map1.put("c", "3") + List list2 = new ArrayList<>() + Map map2 = new HashMap<>() + map2.put("d", "4") + list.add(list1) + list.add(list2) + list1.add(map1) + list2.add(map2) + return list + } +} + From b46463e0d38a026ec45340d96011191f0e20a504 Mon Sep 17 00:00:00 2001 From: Artem Ptushkin Date: Fri, 14 Jun 2019 16:55:13 +0300 Subject: [PATCH 3/6] Fixed issue with content is not allowed in prolog for body from the xml file (#1107) * Created test 'should create stub with body from the file' - failed * Fixed 'Content is not allowed in prolog' for body from the xml file; fixes issue #1105 --- .../spec/internal/FromFileProperty.groovy | 4 ++ .../dsl/wiremock/WireMockGroovyDslSpec.groovy | 48 +++++++++++++++++++ .../src/test/resources/classpath/request.xml | 5 ++ 3 files changed, 57 insertions(+) create mode 100644 spring-cloud-contract-verifier/src/test/resources/classpath/request.xml diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/FromFileProperty.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/FromFileProperty.groovy index fd5edc7783..85456c1363 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/FromFileProperty.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/FromFileProperty.groovy @@ -66,4 +66,8 @@ class FromFileProperty implements Serializable { return this.file.bytes } + @Override + String toString() { + return asString() + } } diff --git a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/wiremock/WireMockGroovyDslSpec.groovy b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/wiremock/WireMockGroovyDslSpec.groovy index 8dabae12fa..e4164fefe7 100755 --- a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/wiremock/WireMockGroovyDslSpec.groovy +++ b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/wiremock/WireMockGroovyDslSpec.groovy @@ -606,6 +606,54 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie stubMappingIsValidWireMockStub(json) } + def 'should create stub with body from the file'() { + given: + org.springframework.cloud.contract.spec.Contract groovyDsl = org.springframework.cloud.contract.spec.Contract.make { + request { + method 'GET' + headers { + header 'Content-Type': 'application/xml' + } + url "/users" + body file('classpath/request.xml') + } + response { + status OK() + } + } + when: + String json = toWireMockClientJsonStub(groovyDsl) + then: + AssertionUtil.assertThatJsonsAreEqual((''' + { + "request": { + "method": "GET", + "url": "/users", + "bodyPatterns": [ + { + "matchesXPath": { + "expression": "/foo/name/text()", + "equalTo": "Jozo" + } + }, + { + "matchesXPath": { + "expression": "/foo/jobId/text()", + "equalTo": "123" + } + } + ] + }, + "response": { + "status": 200, + "transformers" : [ "response-template", "foo-transformer" ] + } + } + '''), json) + and: + stubMappingIsValidWireMockStub(json) + } + def 'should convert groovy dsl stub with regexp Body as String to wireMock stub for the client side'() { given: org.springframework.cloud.contract.spec.Contract groovyDsl = org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-verifier/src/test/resources/classpath/request.xml b/spring-cloud-contract-verifier/src/test/resources/classpath/request.xml new file mode 100644 index 0000000000..850972c082 --- /dev/null +++ b/spring-cloud-contract-verifier/src/test/resources/classpath/request.xml @@ -0,0 +1,5 @@ + + + Jozo + 123 + \ No newline at end of file From 03c556df045ffc30da8fe509ffac48bae88e21fe Mon Sep 17 00:00:00 2001 From: Olga Maciaszek-Sharma Date: Thu, 20 Jun 2019 14:37:59 +0200 Subject: [PATCH 4/6] Ignore flaky test. --- .../contract/verifier/plugin/SampleJerseyProjectSpec.groovy | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/SampleJerseyProjectSpec.groovy b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/SampleJerseyProjectSpec.groovy index 7cd0e49bac..c8f2785824 100755 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/SampleJerseyProjectSpec.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/SampleJerseyProjectSpec.groovy @@ -18,8 +18,10 @@ package org.springframework.cloud.contract.verifier.plugin import org.gradle.testkit.runner.BuildResult import spock.lang.Stepwise +import spock.lang.Ignore @Stepwise +@Ignore("Flaky") class SampleJerseyProjectSpec extends ContractVerifierIntegrationSpec { def setup() { From d7dbe0ccdc209a2096071d3ffbeded156500e56d Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Thu, 20 Jun 2019 18:08:11 -0400 Subject: [PATCH 5/6] Bumps spring cloud build to 2.1.6.BUILD-SNAPSHOT Also other spring deps --- pom.xml | 12 ++++++------ spring-cloud-contract-dependencies/pom.xml | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index bf10c7a65c..dd08b830ff 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.springframework.cloud spring-cloud-build - 2.1.3.BUILD-SNAPSHOT + 2.1.6.BUILD-SNAPSHOT @@ -28,13 +28,13 @@ 2.17 3.5.13 0.0.9 - 2.1.3.BUILD-SNAPSHOT - 2.1.1.BUILD-SNAPSHOT + 2.1.6.BUILD-SNAPSHOT + 2.1.2.BUILD-SNAPSHOT Fishtown.BUILD-SNAPSHOT - 2.1.1.BUILD-SNAPSHOT - 2.1.1.BUILD-SNAPSHOT - 2.1.1.BUILD-SNAPSHOT + 2.1.2.BUILD-SNAPSHOT + 2.1.2.BUILD-SNAPSHOT + 2.1.2.BUILD-SNAPSHOT 5.0.3 3.2.9 1.0-groovy-2.4 diff --git a/spring-cloud-contract-dependencies/pom.xml b/spring-cloud-contract-dependencies/pom.xml index 3e16a82115..64a37b26a8 100644 --- a/spring-cloud-contract-dependencies/pom.xml +++ b/spring-cloud-contract-dependencies/pom.xml @@ -6,7 +6,7 @@ spring-cloud-dependencies-parent org.springframework.cloud - 2.1.3.BUILD-SNAPSHOT + 2.1.6.BUILD-SNAPSHOT spring-cloud-contract-dependencies From 0f2c01148c4a122c4d198d05e9af2ce0010a75b7 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Fri, 21 Jun 2019 12:52:35 +0200 Subject: [PATCH 6/6] Fixing stream and itegration issus --- .../StubRunnerIntegrationConfiguration.java | 12 +----------- .../StubRunnerIntegrationTransformer.java | 5 +---- .../stream/StubRunnerStreamConfiguration.java | 13 +------------ .../stream/StubRunnerStreamTransformer.java | 4 +--- 4 files changed, 4 insertions(+), 30 deletions(-) diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationConfiguration.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationConfiguration.java index 602f800f90..1069243a9e 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationConfiguration.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationConfiguration.java @@ -33,10 +33,8 @@ import org.springframework.context.Lifecycle; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.integration.dsl.FilterEndpointSpec; -import org.springframework.integration.dsl.GenericEndpointSpec; import org.springframework.integration.dsl.IntegrationFlowBuilder; import org.springframework.integration.dsl.IntegrationFlows; -import org.springframework.integration.transformer.MessageTransformingHandler; import org.springframework.messaging.Message; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -95,19 +93,11 @@ public class StubRunnerIntegrationConfiguration { } }) .transform( - new StubRunnerIntegrationTransformer(entries.getValue()), - new Consumer>() { - @Override - public void accept( - GenericEndpointSpec e) { - e.id(flowName + ".transformer"); - } - }) + new StubRunnerIntegrationTransformer(entries.getValue())) .route(new StubRunnerIntegrationRouter(entries.getValue(), beanFactory)); beanFactory.initializeBean(builder.get(), flowName); beanFactory.getBean(flowName + ".filter", Lifecycle.class).start(); - beanFactory.getBean(flowName + ".transformer", Lifecycle.class).start(); } } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationTransformer.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationTransformer.java index 0e42f31169..56f7bdcfd8 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationTransformer.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationTransformer.java @@ -23,7 +23,6 @@ import java.util.Map; import org.springframework.cloud.contract.spec.Contract; import org.springframework.cloud.contract.spec.internal.FromFileProperty; import org.springframework.cloud.contract.verifier.util.BodyExtractor; -import org.springframework.integration.transformer.GenericTransformer; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.support.MessageBuilder; @@ -33,8 +32,7 @@ import org.springframework.messaging.support.MessageBuilder; * * @author Marcin Grzejszczak */ -class StubRunnerIntegrationTransformer - implements GenericTransformer, Message> { +class StubRunnerIntegrationTransformer { private final StubRunnerIntegrationMessageSelector selector; @@ -46,7 +44,6 @@ class StubRunnerIntegrationTransformer this.selector = new StubRunnerIntegrationMessageSelector(groovyDsls); } - @Override public Message transform(Message source) { Contract groovyDsl = matchingContract(source); if (groovyDsl == null || groovyDsl.getOutputMessage() == null) { diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamConfiguration.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamConfiguration.java index e609b17342..c7bb4a00f6 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamConfiguration.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamConfiguration.java @@ -37,17 +37,14 @@ import org.springframework.cloud.contract.stubrunner.BatchStubRunner; import org.springframework.cloud.contract.stubrunner.StubConfiguration; import org.springframework.cloud.contract.stubrunner.messaging.integration.StubRunnerIntegrationConfiguration; import org.springframework.cloud.stream.annotation.EnableBinding; -import org.springframework.cloud.stream.binding.BinderAwareChannelResolver; import org.springframework.cloud.stream.config.BindingProperties; import org.springframework.cloud.stream.config.BindingServiceProperties; import org.springframework.context.Lifecycle; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.integration.dsl.FilterEndpointSpec; -import org.springframework.integration.dsl.GenericEndpointSpec; import org.springframework.integration.dsl.IntegrationFlowBuilder; import org.springframework.integration.dsl.IntegrationFlows; -import org.springframework.integration.transformer.MessageTransformingHandler; import org.springframework.messaging.Message; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -130,19 +127,11 @@ public class StubRunnerStreamConfiguration { e.id(flowName + ".filter"); } }) - .transform(new StubRunnerStreamTransformer(entries.getValue()), - new Consumer>() { - @Override - public void accept( - GenericEndpointSpec e) { - e.id(flowName + ".transformer"); - } - }) + .transform(new StubRunnerStreamTransformer(entries.getValue())) .route(new StubRunnerMessageRouter(entries.getValue(), beanFactory)); beanFactory.initializeBean(builder.get(), flowName); beanFactory.getBean(flowName + ".filter", Lifecycle.class).start(); - beanFactory.getBean(flowName + ".transformer", Lifecycle.class).start(); } } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamTransformer.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamTransformer.java index e581a95698..25188f47b5 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamTransformer.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamTransformer.java @@ -23,7 +23,6 @@ import java.util.Map; import org.springframework.cloud.contract.spec.Contract; import org.springframework.cloud.contract.spec.internal.FromFileProperty; import org.springframework.cloud.contract.verifier.util.BodyExtractor; -import org.springframework.integration.transformer.GenericTransformer; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.support.MessageBuilder; @@ -33,7 +32,7 @@ import org.springframework.messaging.support.MessageBuilder; * * @author Marcin Grzejszczak */ -class StubRunnerStreamTransformer implements GenericTransformer, Message> { +class StubRunnerStreamTransformer { private final StubRunnerStreamMessageSelector selector; @@ -45,7 +44,6 @@ class StubRunnerStreamTransformer implements GenericTransformer, Mess this.selector = new StubRunnerStreamMessageSelector(groovyDsls); } - @Override public Message transform(Message source) { Contract groovyDsl = matchingContract(source); if (groovyDsl == null || groovyDsl.getOutputMessage() == null) {