diff --git a/.travis.yml b/.travis.yml index 599d7dc7f0..b63ed069cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,25 +4,9 @@ dist: trusty before_install: - "export JAVA_OPTS='-Xmx1024m -XX:MaxPermSize=256m'" - - "rm -rf $HOME/.m2/repository/io/codearte/accurest/stubs" - - "mkdir $HOME/.m2/repository/io/codearte/accurest/ --parents" - - "cp -r stub-runner/stub-runner-spring/src/test/resources/m2repo/repository/io/codearte/accurest/stubs $HOME/.m2/repository/io/codearte/accurest/" jdk: - oraclejdk8 install: ./gradlew assemble -s -script: ./gradlew check funcTest install -s --continue && jdk_switcher use oraclejdk8 && ./scripts/runTests.sh && jdk_switcher use $TRAVIS_JDK_VERSION && ./gradlew uploadSnapshotArchives -x check -s - -matrix: - include: - # Automatic snapshot release only in Java 7 build - - jdk: oraclejdk7 - env: - - DO_RELEASE=true - -env: - global: - - secure: NbEQ9t5nGKW0LKmOSV4rTiEbYJARM2rynQBdSXkoILbp+nNaCD6uN41tUu8HrjgbjUDMepFUU+hmGQ47Q2vz5L3NzvW+oHBLgrIu6uAimpdR8qyBE899MBKPE19LsvUOeE9B9TydJgYlY+UEYgxwssUwxsN0RqyY4EErQWMNC8k= - - secure: zCjkMhjF5TbZehNmOK7EV68J35tuc0etWG/ia0eVTjgIv2kp9islJZ3+Jm/gDgkcv2Ydq3oAU2jFbVkUPSSstV3L5KANsighm2qn9tVzRrbTCfM55zcBhnoE0oZHTPNrLoScz0X5sM8Xuvi6ChjGf+lqAxnFW6tFMjx+1uhUIXU= - +script: ./gradlew check funcTest install -s --continue && jdk_switcher use oraclejdk8 && ./scripts/runTests.sh diff --git a/README.adoc b/README.adoc new file mode 100644 index 0000000000..98061ed476 --- /dev/null +++ b/README.adoc @@ -0,0 +1,190 @@ +// Do not edit this file (e.g. go instead to src/main/asciidoc) + +:core_path: ../../../.. +:verifier_root_path: {core_path}/spring-cloud-contract-verifier +:verifier_core_path: {verifier_root_path}/spring-cloud-contract-verifier-core +:stubrunner_core_path: {core_path}/spring-cloud-contract-stub-runner +:documentation_url: http://codearte.github.io/accurest + += Spring Cloud Contract Verifier + +== Introduction + +Just to make long story short - Spring Cloud Contract Verifier is a tool that enables Consumer Driven Contract (CDC) development of JVM-based applications. It is shipped +with __Contract Definition Language__ (DSL). Contract definitions are used to produce following resources: + +* JSON stub definitions to be used by Wiremock when doing integration testing on the client code (__client tests__). +Test code must still be written by hand, test data is produced by Spring Cloud Contract Verifier. +* Messaging routes if you're using one. We're integrating with Spring Integration, Spring Cloud Stream and Apache Camel. You can however set your own integrations if you want to +* Acceptance tests (in JUnit or Spock) used to verify if server-side implementation of the API is compliant with the contract (__server tests__). +Full test is generated by Spring Cloud Contract Verifier. + +Spring Cloud Contract Verifier moves TDD to the level of software architecture. + +=== Why? + +Let us assume that we have a system comprising of multiple microservices: + +image::Deps.png[Microservices Architecture] + +==== Testing issues + +If we wanted to test the application in top left corner if it can communicate with other services then we could do one of two things: + +- deploy all microservices and perform end to end tests +- mock other microservices in unit / integration tests + +Both have their advantages but also a lot of disadvantages. Let's focus on the latter. + +*Deploy all microservices and perform end to end tests* + +Advantages: + +- simulates production +- tests real communication between services + +Disadvantages: + +- to test one microservice we would have to deploy 6 microservices, a couple of databases etc. +- the environment where the tests would be conducted would be locked for a single suite of tests (i.e. nobody else would be able to run the tests in the meantime). +- long to run +- very late feedback +- extremely hard to debug + +*Mock other microservices in unit / integration tests* + +Advantages: + +- very fast feedback +- no infrastructure requirements + +Disadvantages: + +- the implementor of the service creates stubs thus they might have nothing to do with the reality +- you can go to production with passing tests and failing production + +To solve the aforementioned issues Spring Cloud Contract Verifier with Stub Runner were created. Their main idea is to give you very fast feedback, without the need +to set up the whole world of microservices. + +image::Stubs1.png[Stubbed Services] + +If you work on stubs then the only applications you need are those that your application is using directly. + +image::Stubs2.png[Stubbed Services] + +Spring Cloud Contract Verifier gives you the certainty that the stubs that you're using were created by the service that you're calling. Also if you can use them it means that they were +tested against the producer's side. In other words - you can trust those stubs. + + +=== Purposes + +The main purposes of Spring Cloud Contract Verifier with Stub Runner are: + + - to ensure that WireMock / Messaging stubs (used when developing the client) are doing exactly what actual server-side implementation will do, + - to promote ATDD method and Microservices architectural style, + - to provide a way to publish changes in contracts that are immediately visible on both sides, + - to generate boilerplate test code used on the server side. + +=== Client Side + +During the tests you want to have a Wiremock instance / Messaging route up and running that simulates the service Y. +You would like to feed that instance with a proper stub definition. That stub definition would need +to be valid and should also be reusable on the server side. + +__Summing it up:__ On this side, in the stub definition, you can use patterns for request stubbing and you need exact +values for responses. + +=== Server Side + +Being a service Y since you are developing your stub, you need to be sure that it's actually resembling your +concrete implementation. You can't have a situation where your stub acts in one way and your application on +production behaves in a different way. + +That's why from the provided stub acceptance tests will be generated that will ensure +that your application behaves in the same way as you define in your stub. + +__Summing it up:__ On this side, in the stub definition, you need exact values as request and can use patterns/methods +for response verification. + +=== Dependencies + +Spring Cloud Contract Verifier and Stub Runner are using the following libraries + +- http://wiremock.org/[WireMock] +- https://github.com/jayway/JsonPath[Jayway JSONPath] +- https://github.com/marcingrzejszczak/jsonassert[JSONAssert from Marcin Grzejszczak] + +=== Additional links + +Below you can find some resources related to Spring Cloud Contract Verifier and Stub Runner. Note that some can be outdated since the Spring Cloud Contract Verifier project +is under constant development. + +==== Videos + +*Olga Maciaszek-Sharma talking about Accurest (Spring Cloud Contract Verifier predecessor)* + +video::daafmTYFoDU[youtube] + +*Marcin Grzejszczak and Jakub KubryƄski talking about Accurest (Spring Cloud Contract Verifier predecessor)* + +video::130779882[vimeo] + +==== Readings + +- http://www.slideshare.net/MarcinGrzejszczak/stick-to-the-rules-consumer-driven-contracts-201507-confitura[Slides from Marcin Grzejszczak's talk about Accurest] +- http://toomuchcoding.com/blog/categories/accurest/[Accurest related articles from Marcin Grzejszczak's blog] + +=== Samples + +Here you can find some https://github.com/Codearte/accurest-samples[working samples]. Check the readme of each project for more information. + +== Documentation + +You can read more about Spring Cloud Contract Verifier by reading the {documentation_url}[docs] + +== Contributing + +Spring Cloud is released under the non-restrictive Apache 2.0 license, +and follows a very standard Github development process, using Github +tracker for issues and merging pull requests into master. If you want +to contribute even something trivial please do not hesitate, but +follow the guidelines below. + +=== Sign the Contributor License Agreement +Before we accept a non-trivial patch or pull request we will need you to sign the +https://support.springsource.com/spring_committer_signup[contributor's agreement]. +Signing the contributor's agreement does not grant anyone commit rights to the main +repository, but it does mean that we can accept your contributions, and you will get an +author credit if we do. Active contributors might be asked to join the core team, and +given the ability to merge pull requests. + +=== Code of Conduct +This project adheres to the Contributor Covenant https://github.com/spring-cloud/spring-cloud-build/blob/master/docs/src/main/asciidoc/code-of-conduct.adoc[code of +conduct]. By participating, you are expected to uphold this code. Please report +unacceptable behavior to spring-code-of-conduct@pivotal.io. + +=== Code Conventions and Housekeeping +None of these is essential for a pull request, but they will all help. They can also be +added after the original pull request but before a merge. + +* Use the Spring Framework code format conventions. If you use Eclipse + you can import formatter settings using the + `eclipse-code-formatter.xml` file from the + https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-dependencies-parent/eclipse-code-formatter.xml[Spring + Cloud Build] project. If using IntelliJ, you can use the + http://plugins.jetbrains.com/plugin/6546[Eclipse Code Formatter + Plugin] to import the same file. +* Make sure all new `.java` files to have a simple Javadoc class comment with at least an + `@author` tag identifying you, and preferably at least a paragraph on what the class is + for. +* Add the ASF license header comment to all new `.java` files (copy from existing files + in the project) +* Add yourself as an `@author` to the .java files that you modify substantially (more + than cosmetic changes). +* Add some Javadocs and, if you change the namespace, some XSD doc elements. +* A few unit tests would help a lot as well -- someone has to do it. +* If no-one else is using your branch, please rebase it against the current master (or + other target branch in the main project). +* When writing a commit message please follow http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html[these conventions], + if you are fixing an existing issue please add `Fixes gh-XXXX` at the end of the commit + message (where XXXX is the issue number). \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index e74e3047a0..0000000000 --- a/README.md +++ /dev/null @@ -1,47 +0,0 @@ -Accurest -======== - -[![Build Status](https://travis-ci.org/Codearte/accurest.svg?branch=master)](https://travis-ci.org/Codearte/accurest) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.codearte.accurest/accurest-gradle-plugin/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.codearte.accurest/accurest-gradle-plugin) -[![Join the chat at https://gitter.im/Codearte/accurest](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Codearte/accurest?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) - -Consumer Driven Contracts verifier for Java - -To make a long story short - Accurest is a tool for Consumer Driven Contract (CDC) development. Accurest ships an easy DSL for describing REST contracts for JVM-based applications. - Since version 1.0.7 it also supports messaging. - -The contract DSL is used by Accurest for two things: - -1. generating WireMock's JSON stub definitions / stubbed messaging endpoints, allowing rapid development of the consumer side, -generating JUnit / Spock's acceptance tests for the server - to verify if your API implementation is compliant with the contract. -2. moving TDD to an architecture level. - -For more information please go to the [Documentation](http://codearte.github.io/accurest/) - -## Requirements - -### Wiremock - -In order to use Accurest with Wiremock you have to have __Wiremock in version at least 2.0.0-beta__ . Of course the higher the better :) - -## Additional projects - -### Stub Runner - -Allows you to download WireMock stubs from the provided Maven repository and runs them in WireMock servers. - -### Stub Runner JUnit - -Stub Runner with JUnit rules - -### Stub Runner Spring - -Spring Configuration that automatically starts stubs upon Spring Context build up - -### Stub Runner Spring Cloud - -Spring Cloud AutoConfiguration that automatically starts stubs upon Spring Context build up and allows you to call the stubs -as if they were registered in your service discovery - -### [Accurest Maven Plugin](https://github.com/Codearte/accurest-maven-plugin) - -Maven project support with standalone Accurest Stub Runner and Accurest Contracts to Wiremock mappings converter diff --git a/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/ConversionAccurestException.groovy b/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/ConversionAccurestException.groovy deleted file mode 100644 index d4b35175a8..0000000000 --- a/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/ConversionAccurestException.groovy +++ /dev/null @@ -1,12 +0,0 @@ -package io.codearte.accurest.wiremock - -import groovy.transform.CompileStatic -import io.codearte.accurest.AccurestException - -@CompileStatic -class ConversionAccurestException extends AccurestException { - - ConversionAccurestException(String message, Throwable cause) { - super(message, cause) - } -} diff --git a/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverter.groovy b/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverter.groovy deleted file mode 100644 index 616595e8bb..0000000000 --- a/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverter.groovy +++ /dev/null @@ -1,17 +0,0 @@ -package io.codearte.accurest.wiremock - -import groovy.transform.CompileStatic -import io.codearte.accurest.dsl.WireMockStubStrategy -import io.codearte.accurest.file.Contract - -import java.nio.charset.StandardCharsets - -@CompileStatic -class DslToWireMockClientConverter extends DslToWireMockConverter { - - @Override - String convertContent(String rootName, Contract contract) { - String dslContent = contract.path.getText(StandardCharsets.UTF_8.toString()) - return new WireMockStubStrategy(rootName, contract, createGroovyDSLfromStringContent(dslContent)).toWireMockClientStub() - } -} diff --git a/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/DslToWireMockConverter.groovy b/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/DslToWireMockConverter.groovy deleted file mode 100644 index 0279bbcebe..0000000000 --- a/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/DslToWireMockConverter.groovy +++ /dev/null @@ -1,23 +0,0 @@ -package io.codearte.accurest.wiremock - -import groovy.transform.CompileStatic -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.util.AccurestDslConverter - -@CompileStatic -abstract class DslToWireMockConverter implements SingleFileConverter { - - @Override - boolean canHandleFileName(String fileName) { - return fileName.endsWith('.groovy') - } - - @Override - String generateOutputFileNameForInput(String inputFileName) { - return inputFileName.replaceAll('.groovy', '.json') - } - - protected GroovyDsl createGroovyDSLfromStringContent(String groovyDslAsString) { - return AccurestDslConverter.convert(groovyDslAsString) - } -} diff --git a/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/SingleFileConverter.groovy b/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/SingleFileConverter.groovy deleted file mode 100644 index fda8aa2e82..0000000000 --- a/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/SingleFileConverter.groovy +++ /dev/null @@ -1,14 +0,0 @@ -package io.codearte.accurest.wiremock - -import groovy.transform.CompileStatic -import io.codearte.accurest.file.Contract - -@CompileStatic -interface SingleFileConverter { - - boolean canHandleFileName(String fileName) - - String convertContent(String rootName, Contract content) - - String generateOutputFileNameForInput(String inputFileName) -} \ No newline at end of file diff --git a/accurest-converters/src/test/resources/converter/scenario/main_scenario/01_login.groovy b/accurest-converters/src/test/resources/converter/scenario/main_scenario/01_login.groovy deleted file mode 100644 index 1a30790fc3..0000000000 --- a/accurest-converters/src/test/resources/converter/scenario/main_scenario/01_login.groovy +++ /dev/null @@ -1,9 +0,0 @@ -io.codearte.accurest.dsl.GroovyDsl.make { - request { - method('POST') - url '/login' - } - response { - status 200 - } -} diff --git a/accurest-converters/src/test/resources/converter/scenario/main_scenario/02_showCart.groovy b/accurest-converters/src/test/resources/converter/scenario/main_scenario/02_showCart.groovy deleted file mode 100644 index 712c7ef584..0000000000 --- a/accurest-converters/src/test/resources/converter/scenario/main_scenario/02_showCart.groovy +++ /dev/null @@ -1,9 +0,0 @@ -io.codearte.accurest.dsl.GroovyDsl.make { - request { - method('GET') - url '/cart' - } - response { - status 200 - } -} diff --git a/accurest-converters/src/test/resources/converter/scenario/main_scenario/03_logout.groovy b/accurest-converters/src/test/resources/converter/scenario/main_scenario/03_logout.groovy deleted file mode 100644 index 33e948e602..0000000000 --- a/accurest-converters/src/test/resources/converter/scenario/main_scenario/03_logout.groovy +++ /dev/null @@ -1,9 +0,0 @@ -io.codearte.accurest.dsl.GroovyDsl.make { - request { - method('POST') - url '/logout' - } - response { - status 200 - } -} diff --git a/accurest-converters/src/test/resources/converter/source/dir1/dsl1.groovy b/accurest-converters/src/test/resources/converter/source/dir1/dsl1.groovy deleted file mode 100644 index d72463cde2..0000000000 --- a/accurest-converters/src/test/resources/converter/source/dir1/dsl1.groovy +++ /dev/null @@ -1,12 +0,0 @@ -io.codearte.accurest.dsl.GroovyDsl.make { - request { - method('PUT') - headers { - header 'Content-Type': 'application/json' - } - urlPattern $(client('/[0-9]{2}'), server('/12')) - } - response { - status 200 - } -} diff --git a/accurest-converters/src/test/resources/converter/source/dir1/dsl1b.groovy b/accurest-converters/src/test/resources/converter/source/dir1/dsl1b.groovy deleted file mode 100644 index d72463cde2..0000000000 --- a/accurest-converters/src/test/resources/converter/source/dir1/dsl1b.groovy +++ /dev/null @@ -1,12 +0,0 @@ -io.codearte.accurest.dsl.GroovyDsl.make { - request { - method('PUT') - headers { - header 'Content-Type': 'application/json' - } - urlPattern $(client('/[0-9]{2}'), server('/12')) - } - response { - status 200 - } -} diff --git a/accurest-converters/src/test/resources/converter/source/dir2/dsl2.groovy b/accurest-converters/src/test/resources/converter/source/dir2/dsl2.groovy deleted file mode 100644 index d72463cde2..0000000000 --- a/accurest-converters/src/test/resources/converter/source/dir2/dsl2.groovy +++ /dev/null @@ -1,12 +0,0 @@ -io.codearte.accurest.dsl.GroovyDsl.make { - request { - method('PUT') - headers { - header 'Content-Type': 'application/json' - } - urlPattern $(client('/[0-9]{2}'), server('/12')) - } - response { - status 200 - } -} diff --git a/accurest-converters/src/test/resources/converter/source/dslRoot.groovy b/accurest-converters/src/test/resources/converter/source/dslRoot.groovy deleted file mode 100644 index d72463cde2..0000000000 --- a/accurest-converters/src/test/resources/converter/source/dslRoot.groovy +++ /dev/null @@ -1,12 +0,0 @@ -io.codearte.accurest.dsl.GroovyDsl.make { - request { - method('PUT') - headers { - header 'Content-Type': 'application/json' - } - urlPattern $(client('/[0-9]{2}'), server('/12')) - } - response { - status 200 - } -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/AccurestException.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/AccurestException.groovy deleted file mode 100644 index b9fac01145..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/AccurestException.groovy +++ /dev/null @@ -1,15 +0,0 @@ -package io.codearte.accurest - -/** - * @author Jakub Kubrynski - */ -class AccurestException extends RuntimeException { - - AccurestException(String message) { - super(message) - } - - AccurestException(String message, Throwable cause) { - super(message, cause) - } -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/builder/MethodBuilder.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/builder/MethodBuilder.groovy deleted file mode 100644 index 71c76b7f86..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/builder/MethodBuilder.groovy +++ /dev/null @@ -1,65 +0,0 @@ -package io.codearte.accurest.builder - -import groovy.util.logging.Slf4j -import io.codearte.accurest.config.AccurestConfigProperties -import io.codearte.accurest.config.TestFramework -import io.codearte.accurest.config.TestMode -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.file.Contract -import io.codearte.accurest.util.NamesUtil -/** - * @author Jakub Kubrynski - */ -@Slf4j -class MethodBuilder { - - private final String methodName - private final GroovyDsl stubContent - private final AccurestConfigProperties configProperties - private final boolean ignored - - private MethodBuilder(String methodName, GroovyDsl stubContent, AccurestConfigProperties configProperties, boolean ignored) { - this.ignored = ignored - this.stubContent = stubContent - this.methodName = methodName - this.configProperties = configProperties - } - - static MethodBuilder createTestMethod(Contract contract, File stubsFile, GroovyDsl stubContent, AccurestConfigProperties configProperties) { - log.debug("Stub content Groovy DSL [$stubContent]") - String methodName = NamesUtil.camelCase(NamesUtil.toLastDot(NamesUtil.afterLast(stubsFile.path, File.separator))) - return new MethodBuilder(methodName, stubContent, configProperties, contract.ignored) - } - - void appendTo(BlockBuilder blockBuilder) { - if (configProperties.targetFramework == TestFramework.JUNIT) { - blockBuilder.addLine('@Test') - } - if (ignored) { - blockBuilder.addLine('@Ignore') - } - blockBuilder.addLine(configProperties.targetFramework.methodModifier + "validate_$methodName() throws Exception {") - getMethodBodyBuilder().appendTo(blockBuilder) - blockBuilder.addLine('}') - } - - private MethodBodyBuilder getMethodBodyBuilder() { - if (stubContent.input || stubContent.outputMessage) { - if (configProperties.targetFramework == TestFramework.JUNIT){ - return new JUnitMessagingMethodBodyBuilder(stubContent) - } - return new SpockMessagingMethodBodyBuilder(stubContent) - } - if (configProperties.testMode == TestMode.MOCKMVC && configProperties.targetFramework == TestFramework.JUNIT){ - return new MockMvcJUnitMethodBodyBuilder(stubContent) - } - if (configProperties.testMode == TestMode.JAXRSCLIENT) { - if (configProperties.targetFramework == TestFramework.JUNIT){ - return new JaxRsClientJUnitMethodBodyBuilder(stubContent) - } - return new JaxRsClientSpockMethodRequestProcessingBodyBuilder(stubContent) - } - return new MockMvcSpockMethodRequestProcessingBodyBuilder(stubContent) - } - -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/builder/MockMvcJUnitMethodBodyBuilder.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/builder/MockMvcJUnitMethodBodyBuilder.groovy deleted file mode 100644 index d3bd3acbe7..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/builder/MockMvcJUnitMethodBodyBuilder.groovy +++ /dev/null @@ -1,46 +0,0 @@ -package io.codearte.accurest.builder - -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.dsl.internal.ExecutionProperty -import io.codearte.accurest.dsl.internal.Header - -import java.util.regex.Pattern - -/** - * @author Olga Maciaszek-Sharma - * @since 2016-02-17 - */ -class MockMvcJUnitMethodBodyBuilder extends JUnitMethodBodyBuilder { - - MockMvcJUnitMethodBodyBuilder(GroovyDsl stubDefinition) { - super(stubDefinition) - } - - @Override - protected void validateResponseCodeBlock(BlockBuilder bb) { - bb.addLine("assertThat(response.statusCode()).isEqualTo($response.status.serverValue);") - } - - @Override - protected void validateResponseHeadersBlock(BlockBuilder bb) { - response.headers?.collect { Header header ->\ - processHeaderElement(bb, header.name, header.serverValue) - } - } - - @Override - protected void processHeaderElement(BlockBuilder blockBuilder, String property, String value) { - blockBuilder.addLine("assertThat(response.header(\"$property\")).${createHeaderComparison(value)}") - } - - @Override - protected void processHeaderElement(BlockBuilder blockBuilder, String property, Pattern pattern) { - blockBuilder.addLine("assertThat(response.header(\"$property\")).${createHeaderComparison(pattern)}") - } - - @Override - protected void processHeaderElement(BlockBuilder blockBuilder, String property, ExecutionProperty exec) { - blockBuilder.addLine("${exec.insertValue("response.header(\"$property\")")};") - } - -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/config/TestMode.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/config/TestMode.groovy deleted file mode 100644 index 5d1f339bc8..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/config/TestMode.groovy +++ /dev/null @@ -1,21 +0,0 @@ -package io.codearte.accurest.config - -/** - * @author Jakub Kubrynski - */ -enum TestMode { - /** - * Uses Spring's MockMvc - */ - MOCKMVC, - - /** - * Uses direct HTTP invocations - */ - EXPLICIT, - - /** - * Uses JAX-RS client - */ - JAXRSCLIENT -} \ No newline at end of file diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/Accurest.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/Accurest.groovy deleted file mode 100644 index ee5c0392c7..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/Accurest.groovy +++ /dev/null @@ -1,15 +0,0 @@ -package io.codearte.accurest.dsl - -import groovy.transform.EqualsAndHashCode -import groovy.transform.ToString -import groovy.transform.TypeChecked -/** - * A better name for GroovyDsl - * - * @author Marcin Grzejszczak - */ -@TypeChecked -@EqualsAndHashCode -@ToString(includeFields = true, includePackage = false, includeNames = true, includeSuper = true) -class Accurest extends GroovyDsl { -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/BaseWireMockStubStrategy.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/BaseWireMockStubStrategy.groovy deleted file mode 100755 index ac7376dc38..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/BaseWireMockStubStrategy.groovy +++ /dev/null @@ -1,109 +0,0 @@ -package io.codearte.accurest.dsl - -import groovy.json.JsonBuilder -import groovy.transform.TypeChecked -import io.codearte.accurest.dsl.internal.DslProperty -import io.codearte.accurest.dsl.internal.Header -import io.codearte.accurest.dsl.internal.Headers -import io.codearte.accurest.util.ContentType -import io.codearte.accurest.util.ContentUtils -import io.codearte.accurest.util.MapConverter - -import java.util.regex.Pattern - -import static io.codearte.accurest.util.ContentUtils.extractValue -import static io.codearte.accurest.util.MapConverter.transformValues - -@TypeChecked -abstract class BaseWireMockStubStrategy { - - protected getStubSideValue(Object object) { - return MapConverter.getStubSideValues(object) - } - - private static Closure transform = { - it instanceof DslProperty ? transformValues(it.clientValue, transform) : it - } - - protected Map buildClientRequestHeadersSection(Headers headers) { - if (!headers) { - return null - } - return headers.entries.collectEntries { Header entry -> - parseHeader(entry.name, entry.clientValue) - } - } - - protected Map buildClientResponseHeadersSection(Headers headers) { - if (!headers) { - return null - } - return headers.entries.collectEntries { Header entry -> - [(entry.name): entry.clientValue] - } - } - - protected Map parseHeader(String entryKey, Object entry) { - return [(entryKey): [equalTo: entry]] - } - - protected Map parseHeader(String entryKey, String entry) { - return [(entryKey): [equalTo: entry]] - } - - protected Map parseHeader(String entryKey, Pattern entry) { - return [(entryKey): [matches: entry.pattern()]] - } - - public String parseBody(Object value, ContentType contentType) { - return parseBody(value.toString(), contentType) - } - - public Boolean parseBody(Boolean value, ContentType contentType) { - return value - } - - public String parseBody(Map map, ContentType contentType) { - def transformedMap = MapConverter.getStubSideValues(map) - return parseBody(toJson(transformedMap), contentType) - } - - public String parseBody(List list, ContentType contentType) { - List result = [] - list.each { - if (it instanceof Map) { - result += MapConverter.getStubSideValues(it) - } else { - result += parseBody(it, contentType) - } - } - return parseBody(toJson(result), contentType) - } - - public String parseBody(GString value, ContentType contentType) { - Object processedValue = extractValue(value, contentType, { DslProperty dslProperty -> dslProperty.clientValue }) - if (processedValue instanceof GString) { - return parseBody(processedValue.toString(), contentType) - } - return parseBody(processedValue, contentType) - } - - public String parseBody(String value, ContentType contentType) { - return value - } - - private static toJson(Object value) { - return new JsonBuilder(value).toString() - } - - protected ContentType tryToGetContentType(Object body, Headers headers) { - ContentType contentType = ContentUtils.recognizeContentTypeFromHeader(headers) - if (contentType == ContentType.UNKNOWN) { - if (!body) { - return ContentType.UNKNOWN - } - return ContentUtils.getClientContentType(body) - } - return contentType - } -} \ No newline at end of file diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/GroovyDsl.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/GroovyDsl.groovy deleted file mode 100644 index 3cd0e993ed..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/GroovyDsl.groovy +++ /dev/null @@ -1,67 +0,0 @@ -package io.codearte.accurest.dsl - -import groovy.transform.EqualsAndHashCode -import groovy.transform.ToString -import groovy.transform.TypeChecked -import io.codearte.accurest.dsl.internal.Input -import io.codearte.accurest.dsl.internal.OutputMessage -import io.codearte.accurest.dsl.internal.Request -import io.codearte.accurest.dsl.internal.Response - -@TypeChecked -@EqualsAndHashCode -@ToString(includeFields = true, includePackage = false, includeNames = true) -class GroovyDsl { - - Integer priority - Request request - Response response - String label - String description - Input input - OutputMessage outputMessage - - static GroovyDsl make(Closure closure) { - GroovyDsl dsl = new GroovyDsl() - closure.delegate = dsl - closure() - return dsl - } - - void priority(int priority) { - this.priority = priority - } - - void label(String label) { - this.label = label - } - - void description(String description) { - this.description = description - } - - void request(@DelegatesTo(Request) Closure closure) { - this.request = new Request() - closure.delegate = request - closure() - } - - void response(@DelegatesTo(Response) Closure closure) { - this.response = new Response() - closure.delegate = response - closure() - } - - void input(@DelegatesTo(Input) Closure closure) { - this.input = new Input() - closure.delegate = input - closure() - } - - void outputMessage(@DelegatesTo(OutputMessage) Closure closure) { - this.outputMessage = new OutputMessage() - closure.delegate = outputMessage - closure() - } - -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/ClientDslProperty.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/ClientDslProperty.groovy deleted file mode 100644 index 007550b890..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/ClientDslProperty.groovy +++ /dev/null @@ -1,11 +0,0 @@ -package io.codearte.accurest.dsl.internal - -import groovy.transform.CompileStatic - -@CompileStatic -class ClientDslProperty extends DslProperty { - - ClientDslProperty(Object singleValue) { - super(singleValue) - } -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/DslProperty.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/DslProperty.groovy deleted file mode 100644 index f9da9227e5..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/DslProperty.groovy +++ /dev/null @@ -1,24 +0,0 @@ -package io.codearte.accurest.dsl.internal - -import groovy.transform.CompileStatic -import groovy.transform.EqualsAndHashCode -import groovy.transform.ToString - -@CompileStatic -@EqualsAndHashCode(includeFields = true) -@ToString(includePackage = false, includeNames = true) -class DslProperty { - - final T clientValue - final T serverValue - - DslProperty(T clientValue, T serverValue) { - this.clientValue = clientValue - this.serverValue = serverValue - } - - DslProperty(T singleValue) { - this.clientValue = singleValue - this.serverValue = singleValue - } -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/ExecutionProperty.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/ExecutionProperty.groovy deleted file mode 100644 index 866afdc18c..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/ExecutionProperty.groovy +++ /dev/null @@ -1,19 +0,0 @@ -package io.codearte.accurest.dsl.internal - -import groovy.transform.CompileStatic - -@CompileStatic -class ExecutionProperty { - - private static final String PLACEHOLDER_VALUE = '\\$it' - - final String executionCommand - - ExecutionProperty(String executionCommand) { - this.executionCommand = executionCommand - } - - String insertValue(String valueToInsert) { - return executionCommand.replaceAll(PLACEHOLDER_VALUE, valueToInsert) - } -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Header.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Header.groovy deleted file mode 100644 index b72037cd03..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Header.groovy +++ /dev/null @@ -1,23 +0,0 @@ -package io.codearte.accurest.dsl.internal -import groovy.transform.CompileStatic -import groovy.transform.EqualsAndHashCode -import groovy.transform.ToString - -@EqualsAndHashCode(includeFields = true) -@ToString(includePackage = false, includeFields = true, ignoreNulls = true, includeNames = true) -@CompileStatic -class Header extends DslProperty { - - String name - - Header(String name, DslProperty dslProperty) { - super(dslProperty.clientValue, dslProperty.serverValue) - this.name = name - } - - Header(String name, Object value) { - super(value) - this.name = name - } - -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/JSONCompareMode.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/JSONCompareMode.groovy deleted file mode 100644 index 8929aa9bdc..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/JSONCompareMode.groovy +++ /dev/null @@ -1,5 +0,0 @@ -package io.codearte.accurest.dsl.internal - -enum JSONCompareMode { - STRICT, LENIENT, NON_EXTENSIBLE, STRICT_ORDER -} \ No newline at end of file diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/JsonStructureConverter.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/JsonStructureConverter.groovy deleted file mode 100644 index b6b6f79eee..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/JsonStructureConverter.groovy +++ /dev/null @@ -1,32 +0,0 @@ -package io.codearte.accurest.dsl.internal - -import groovy.json.JsonOutput -import groovy.transform.CompileStatic -import io.codearte.accurest.util.MapConverter - -import java.util.regex.Pattern - -@CompileStatic -class JsonStructureConverter { - - public static final String TEMPORARY_PLACEHOLDER = '###PLACEHOLDER###' - public static final Pattern TEMPORARY_PATTERN_HOLDER = Pattern.compile(TEMPORARY_PLACEHOLDER) - - static Object convertJsonStructureToObjectUnderstandingStructure(Object parsedJson, - Closure retrievePlaceholders, - Closure performAdditionalLogicOnSerializedJson, - Closure convertSerializedJsonToSth) { - LinkedList queue = new LinkedList<>() - def transformedJson = MapConverter.transformValues(parsedJson, { - if(retrievePlaceholders(it)) { - queue.push(it) - return TEMPORARY_PLACEHOLDER - } - return it - }) - String jsonAsString = JsonOutput.toJson(transformedJson) - String transformedJsonAsString = performAdditionalLogicOnSerializedJson(jsonAsString) - return convertSerializedJsonToSth(queue, transformedJsonAsString) - } - -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/NamedProperty.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/NamedProperty.groovy deleted file mode 100644 index 70c6d30879..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/NamedProperty.groovy +++ /dev/null @@ -1,25 +0,0 @@ -package io.codearte.accurest.dsl.internal - -import groovy.transform.CompileStatic -import groovy.transform.EqualsAndHashCode -import groovy.transform.ToString - -@ToString(includePackage = false, includeFields = true, includeNames = true) -@EqualsAndHashCode(includeFields = true) -@CompileStatic -class NamedProperty { - - private static final String NAME = 'name' - private static final String CONTENT = 'content' - DslProperty name - DslProperty value - - NamedProperty(DslProperty name, DslProperty value) { - this.name = name - this.value = value - } - - NamedProperty(Map namedMap) { - this(namedMap?.get(NAME), namedMap?.get(CONTENT)) - } -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/OptionalProperty.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/OptionalProperty.groovy deleted file mode 100644 index 877c31c661..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/OptionalProperty.groovy +++ /dev/null @@ -1,13 +0,0 @@ -package io.codearte.accurest.dsl.internal - -class OptionalProperty { - final Object value - - OptionalProperty(Object value) { - this.value = value - } - - String optionalPattern() { - return "($value)?" - } -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/QueryParameters.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/QueryParameters.groovy deleted file mode 100644 index b4cc1d74c4..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/QueryParameters.groovy +++ /dev/null @@ -1,23 +0,0 @@ -package io.codearte.accurest.dsl.internal - -import groovy.transform.EqualsAndHashCode -import groovy.transform.ToString -import groovy.transform.TypeChecked - -@EqualsAndHashCode(includeFields = true) -@ToString(includePackage = false, includeFields = true, ignoreNulls = true, includeNames = true) -@TypeChecked -class QueryParameters { - - List parameters = [] - - void parameter(Map singleParameter) { - Map.Entry first = singleParameter.entrySet().first() - parameters << new QueryParameter(first?.key, first?.value) - } - - void parameter(String parameterName, Object parameterValue) { - parameters << new QueryParameter(parameterName, parameterValue) - } - -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/ServerDslProperty.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/ServerDslProperty.groovy deleted file mode 100644 index 659fba901e..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/ServerDslProperty.groovy +++ /dev/null @@ -1,15 +0,0 @@ -package io.codearte.accurest.dsl.internal - -import groovy.transform.CompileStatic -import groovy.transform.EqualsAndHashCode -import groovy.transform.ToString - -@CompileStatic -@EqualsAndHashCode(includeFields = true) -@ToString(includePackage = false) -class ServerDslProperty extends DslProperty { - - ServerDslProperty(Object singleValue) { - super(singleValue) - } -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Url.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Url.groovy deleted file mode 100644 index 09eae6d094..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Url.groovy +++ /dev/null @@ -1,32 +0,0 @@ -package io.codearte.accurest.dsl.internal - -import groovy.transform.CompileStatic -import groovy.transform.EqualsAndHashCode -import groovy.transform.ToString - -import static io.codearte.accurest.util.ValidateUtils.validateServerValueIsAvailable - -@ToString(includePackage = false, includeFields = true, includeNames = true) -@EqualsAndHashCode(includeFields = true) -@CompileStatic -class Url extends DslProperty { - - QueryParameters queryParameters - - Url(DslProperty prop) { - super(prop.clientValue, prop.serverValue) - validateServerValueIsAvailable(prop.serverValue, "Url") - } - - Url(Object url) { - super(url) - validateServerValueIsAvailable(url, "Url") - } - - void queryParameters(@DelegatesTo(QueryParameters) Closure closure) { - this.queryParameters = new QueryParameters() - closure.delegate = queryParameters - closure() - } - -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/UrlPath.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/UrlPath.groovy deleted file mode 100644 index 4b77520cc3..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/UrlPath.groovy +++ /dev/null @@ -1,20 +0,0 @@ -package io.codearte.accurest.dsl.internal - -import groovy.transform.CompileStatic -import groovy.transform.EqualsAndHashCode -import groovy.transform.ToString - -@ToString(includePackage = false, includeFields = true, includeNames = true) -@EqualsAndHashCode(includeFields = true) -@CompileStatic -class UrlPath extends Url { - - UrlPath(String path) { - super(path) - } - - UrlPath(DslProperty path) { - super(path) - } - -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/file/Contract.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/file/Contract.groovy deleted file mode 100644 index d5cbcfea1c..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/file/Contract.groovy +++ /dev/null @@ -1,30 +0,0 @@ -package io.codearte.accurest.file - -import java.nio.file.Path - -/** - * @author Jakub Kubrynski - */ -class Contract { - final Path path; - final boolean ignored; - final int groupSize - final Integer order; - - Contract(Path path, boolean ignored, int groupSize, Integer order) { - this.groupSize = groupSize - this.path = path - this.ignored = ignored - this.order = order - } - - @Override - public String toString() { - return "Contract{" + - "fileName=" + path.fileName + - ", ignored=" + ignored + - ", groupSize=" + groupSize + - ", order=" + order + - '}'; - } -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/util/AccurestDslConverter.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/util/AccurestDslConverter.groovy deleted file mode 100644 index 5f865ba24b..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/util/AccurestDslConverter.groovy +++ /dev/null @@ -1,26 +0,0 @@ -package io.codearte.accurest.util - -import groovy.transform.CompileStatic -import io.codearte.accurest.dsl.GroovyDsl -import org.codehaus.groovy.control.CompilerConfiguration - -/** - * Converts to Groovy DSL - * - * @author Marcin Grzejszczak - */ -@CompileStatic -class AccurestDslConverter { - - static GroovyDsl convert(String dsl) { - return groovyShell().evaluate(dsl) as GroovyDsl - } - - static GroovyDsl convert(File dsl) { - return groovyShell().evaluate(dsl) as GroovyDsl - } - - private static GroovyShell groovyShell() { - return new GroovyShell(AccurestDslConverter.classLoader, new Binding(), new CompilerConfiguration(sourceEncoding: 'UTF-8')) - } -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/util/ContentType.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/util/ContentType.groovy deleted file mode 100644 index a9243058af..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/util/ContentType.groovy +++ /dev/null @@ -1,15 +0,0 @@ -package io.codearte.accurest.util - -enum ContentType { - - JSON("application/json"), - XML("application/xml"), - UNKNOWN("application/octet-stream") - - final String mimeType - - ContentType(String mimeType) { - this.mimeType = mimeType - } - -} \ No newline at end of file diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/util/FinishedDelegatingJsonVerifiable.java b/accurest-core/src/main/groovy/io/codearte/accurest/util/FinishedDelegatingJsonVerifiable.java deleted file mode 100644 index 8b89f4ea4b..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/util/FinishedDelegatingJsonVerifiable.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.codearte.accurest.util; - -import java.util.LinkedList; - -import com.toomuchcoding.jsonassert.JsonVerifiable; - -/** - * @author Marcin Grzejszczak - */ -class FinishedDelegatingJsonVerifiable extends DelegatingJsonVerifiable { - - FinishedDelegatingJsonVerifiable(JsonVerifiable delegate, - LinkedList methodsBuffer) { - super(delegate, methodsBuffer); - } - -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/util/JsonPaths.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/util/JsonPaths.groovy deleted file mode 100644 index d3786b757e..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/util/JsonPaths.groovy +++ /dev/null @@ -1,6 +0,0 @@ -package io.codearte.accurest.util - -class JsonPaths extends HashSet { - -} - diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/util/MethodBuffering.java b/accurest-core/src/main/groovy/io/codearte/accurest/util/MethodBuffering.java deleted file mode 100644 index 606ae4518e..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/util/MethodBuffering.java +++ /dev/null @@ -1,9 +0,0 @@ -package io.codearte.accurest.util; - -/** - * @author Marcin Grzejszczak - */ -public interface MethodBuffering { - - String method(); -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/util/NamesUtil.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/util/NamesUtil.groovy deleted file mode 100644 index 8e4d9037ee..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/util/NamesUtil.groovy +++ /dev/null @@ -1,60 +0,0 @@ -package io.codearte.accurest.util - -/** - * @author Jakub Kubrynski - */ -class NamesUtil { - - static String beforeLast(String string, String separator) { - if (string?.indexOf(separator) > -1) { - return string.substring(0, string.lastIndexOf(separator)) - } - return '' - } - - static String afterLast(String string, String separator) { - if (string?.indexOf(separator) > -1) { - return string.substring(string.lastIndexOf(separator) + 1) - } - return string - } - - static String afterLastDot(String string) { - return afterLast(string, '.') - } - - static String camelCase(String className) { - if (!className) { - return className - } - String firstChar = className.charAt(0).toLowerCase() as String - return firstChar + className.substring(1) - } - - static String capitalize(String className) { - if (!className) { - return className - } - String firstChar = className.charAt(0).toUpperCase() as String - return firstChar + className.substring(1) - } - - static String toLastDot(String string) { - if (string?.indexOf('.') > -1) { - return string.substring(0, string.lastIndexOf('.')) - } - return string - } - - static String packageToDirectory(String packageName) { - return packageName.replace('.' as char, File.separatorChar) - } - - static String directoryToPackage(String directory) { - return directory.replace(File.separator, '.') - } - - static String convertIllegalPackageChars(String packageName) { - return packageName.replace('-', '_') - } -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/util/RegexpBuilders.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/util/RegexpBuilders.groovy deleted file mode 100644 index 6c8b703fca..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/util/RegexpBuilders.groovy +++ /dev/null @@ -1,91 +0,0 @@ -package io.codearte.accurest.util - -import io.codearte.accurest.dsl.internal.DslProperty -import org.codehaus.groovy.runtime.GStringImpl - -import java.util.regex.Pattern - -import static io.codearte.accurest.util.ContentUtils.extractValue -import static org.apache.commons.lang3.StringEscapeUtils.escapeJson - -public class RegexpBuilders { - - public static String buildGStringRegexpForStubSide(GString gString) { - new GStringImpl( - gString.values.collect(this.&buildGStringRegexpForStubSide) as Object[], - gString.strings.collect(this.&escapeSpecialRegexChars) as String[] - ) - } - - public static String buildGStringRegexpForStubSide(Pattern pattern) { - return pattern.pattern() - } - - public static String buildGStringRegexpForStubSide(DslProperty dslProperty) { - return buildGStringRegexpForStubSide(dslProperty.clientValue) - } - - public static String buildGStringRegexpForStubSide(Object o) { - return escapeSpecialRegexChars(o.toString()) - } - - public static String buildGStringRegexpForTestSide(GString gString) { - new GStringImpl( - gString.values.collect(this.&buildGStringRegexpForTestSide) as Object[], - gString.strings.collect(this.&escapeSpecialRegexChars) as String[] - ) - } - - public static String buildGStringRegexpForTestSide(Pattern pattern) { - return pattern.pattern() - } - - public static String buildGStringRegexpForTestSide(DslProperty dslProperty) { - return buildGStringRegexpForTestSide(dslProperty.clientValue) - } - - public static String buildGStringRegexpForTestSide(Object o) { - return o.toString().replaceAll('\\\\', '\\\\\\\\') - } - - private final static Pattern SPECIAL_REGEX_CHARS = Pattern.compile('[{}()\\[\\].+*?^$\\\\|]') - - private static String escapeSpecialRegexChars(String str) { - return SPECIAL_REGEX_CHARS.matcher(str).replaceAll('\\\\\\\\$0') - } - - private final static String WS = /\s*/ - - public static String buildJSONRegexpMatch(GString gString) { - return buildJSONRegexpMatch(extractValue(gString, ContentType.JSON, { DslProperty dslProperty -> dslProperty.clientValue })) - } - - public static String buildJSONRegexpMatch(Map jsonMap) { - return WS + "\\{" + jsonMap.collect(this.&buildJSONRegexpMatch).join(",") + "\\}" + WS - } - - public static String buildJSONRegexpMatch(List jsonList) { - return WS + "\\[" + jsonList.collect(this.&buildJSONRegexpMatch).join(",") + "\\]" + WS - } - - public static String buildJSONRegexpMatch(Map.Entry entry) { - return buildJSONRegexpMatchString(escapeJson(entry.key)) + ":" + buildJSONRegexpMatch(entry.value) - } - - public static String buildJSONRegexpMatch(Object value) { - return buildJSONRegexpMatchStringOptionalQuotes(escapeJson(value.toString())) - } - - public static String buildJSONRegexpMatch(Pattern pattern) { - return buildJSONRegexpMatchStringOptionalQuotes(pattern.pattern()) - } - - public static String buildJSONRegexpMatchString(String value) { - return WS + '"' + value + '"' + WS - } - - public static String buildJSONRegexpMatchStringOptionalQuotes(String value) { - return WS + '"?' + value + '"?' + WS - } - -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/util/ShouldTraverse.java b/accurest-core/src/main/groovy/io/codearte/accurest/util/ShouldTraverse.java deleted file mode 100644 index a4590e504e..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/util/ShouldTraverse.java +++ /dev/null @@ -1,12 +0,0 @@ -package io.codearte.accurest.util; - -/** - * @author Marcin Grzejszczak - */ -class ShouldTraverse { - final Object value; - - ShouldTraverse(Object value) { - this.value = value; - } -} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/util/ValidateUtils.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/util/ValidateUtils.groovy deleted file mode 100644 index 46e9706cfe..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/util/ValidateUtils.groovy +++ /dev/null @@ -1,46 +0,0 @@ -package io.codearte.accurest.util - -import groovy.transform.TypeChecked -import io.codearte.accurest.dsl.internal.DslProperty -import io.codearte.accurest.dsl.internal.MatchingStrategy - -import java.util.regex.Pattern - -import static io.codearte.accurest.dsl.internal.MatchingStrategy.Type.ABSENT -import static io.codearte.accurest.dsl.internal.MatchingStrategy.Type.EQUAL_TO - -@TypeChecked -class ValidateUtils { - - static Object validateServerValueIsAvailable(Object value) { - validateServerValueIsAvailable(value, "Server value") - return value - } - - static Object validateServerValueIsAvailable(Object value, String msg) { - validateServerValue(value, msg) - return value - } - - static void validateServerValue(Pattern pattern, String msg) { - throw new IllegalStateException("$msg can't be a pattern for the server side") - } - - static List ALLOWED_MATCHING_TYPES_ON_SERVER_SIDE = [EQUAL_TO, ABSENT] - - static void validateServerValue(MatchingStrategy matchingStrategy, String msg) { - if (!ALLOWED_MATCHING_TYPES_ON_SERVER_SIDE.contains(matchingStrategy.type)) { - throw new IllegalStateException("$msg can't be of a matching type: $matchingStrategy.type for the server side") - } - validateServerValue(matchingStrategy.serverValue, msg) - } - - static void validateServerValue(DslProperty value, String msg) { - validateServerValue(value.serverValue, msg) - } - - static void validateServerValue(Object value, String msg) { - // OK - } - -} diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/GeneratorScannerSpec.groovy b/accurest-core/src/test/groovy/io/codearte/accurest/GeneratorScannerSpec.groovy deleted file mode 100644 index 77e2804805..0000000000 --- a/accurest-core/src/test/groovy/io/codearte/accurest/GeneratorScannerSpec.groovy +++ /dev/null @@ -1,36 +0,0 @@ -package io.codearte.accurest - -import io.codearte.accurest.config.AccurestConfigProperties -import io.codearte.accurest.config.TestFramework -import spock.lang.Specification - -class GeneratorScannerSpec extends Specification { - - private SingleTestGenerator classGenerator = Mock(SingleTestGenerator) - - def "should find all .json files and generate 6 classes for them"() { - given: - File resource = new File(this.getClass().getResource("/directory/with/stubs/stubsRepositoryIndicator").toURI()) - AccurestConfigProperties properties = new AccurestConfigProperties() - properties.contractsDslDir = resource.parentFile - TestGenerator testGenerator = new TestGenerator(properties, classGenerator, Stub(FileSaver)) - when: - testGenerator.generateTestClasses("com.ofg") - then: - 6 * classGenerator.buildClass(_, _, _) >> "qwerty" - } - - def "should create class with full package"() { - given: - AccurestConfigProperties properties = new AccurestConfigProperties(targetFramework: TestFramework.SPOCK) - properties.contractsDslDir = new File(this.getClass().getResource("/directory/with/stubs/package").toURI()) - TestGenerator testGenerator = new TestGenerator(properties, classGenerator, Stub(FileSaver)) - when: - testGenerator.generateTestClasses("com.ofg") - then: - 1 * classGenerator.buildClass(_, 'exceptionsSpec', 'com.ofg') >> "spec" - 1 * classGenerator.buildClass(_, 'exceptionsSpec', 'com.ofg.v1') >> "spec1" - 1 * classGenerator.buildClass(_, 'exceptionsSpec', 'com.ofg.v2') >> "spec2" - } - -} diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/MainTest.groovy b/accurest-core/src/test/groovy/io/codearte/accurest/MainTest.groovy deleted file mode 100644 index dd0ab8cf10..0000000000 --- a/accurest-core/src/test/groovy/io/codearte/accurest/MainTest.groovy +++ /dev/null @@ -1,16 +0,0 @@ -package io.codearte.accurest - -import io.codearte.accurest.config.AccurestConfigProperties -import io.codearte.accurest.config.TestFramework -import io.codearte.accurest.config.TestMode - -class MainTest { - public static void main(String[] args) { - AccurestConfigProperties properties = new AccurestConfigProperties( - contractsDslDir: new File('/home/devel/projects/codearte/accurest/accurest-core/src/test/resources/dsl'), - generatedTestSourcesDir: new File('/tmp/accurest'), - targetFramework: TestFramework.SPOCK, testMode: TestMode.MOCKMVC, basePackageForTests: 'io.test', - staticImports: ['com.pupablada.Test.*'], imports: ['org.innapypa.Test'], excludedFiles: ["**/other"]) - println new TestGenerator(properties).generate() - } -} diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/builder/BookReturned.groovy b/accurest-core/src/test/groovy/io/codearte/accurest/builder/BookReturned.groovy deleted file mode 100644 index 9c2656d426..0000000000 --- a/accurest-core/src/test/groovy/io/codearte/accurest/builder/BookReturned.groovy +++ /dev/null @@ -1,14 +0,0 @@ -package io.codearte.accurest.builder - -import com.fasterxml.jackson.annotation.JsonCreator -import groovy.transform.CompileStatic - -@CompileStatic -class BookReturned implements Serializable { - final String bookName - - @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) - BookReturned(String bookName) { - this.bookName = bookName - } -} diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WireMockStubVerifier.groovy b/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WireMockStubVerifier.groovy deleted file mode 100644 index bb4ec0e18d..0000000000 --- a/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WireMockStubVerifier.groovy +++ /dev/null @@ -1,22 +0,0 @@ -package io.codearte.accurest.dsl - -import com.github.tomakehurst.wiremock.stubbing.StubMapping -import io.codearte.accurest.file.Contract - -import java.util.regex.Pattern - -trait WireMockStubVerifier { - - void stubMappingIsValidWireMockStub(String mappingDefinition) { - StubMapping stubMapping = StubMapping.buildFrom(mappingDefinition) - stubMapping.request.bodyPatterns.findAll { it.matches }.every { - Pattern.compile(it.matches) - } - assert !mappingDefinition.contains('io.codearte.accurest.dsl.internal') - } - - void stubMappingIsValidWireMockStub(GroovyDsl contractDsl) { - stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) - } - -} diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/dsl/internal/ExecutionPropertySpec.groovy b/accurest-core/src/test/groovy/io/codearte/accurest/dsl/internal/ExecutionPropertySpec.groovy deleted file mode 100644 index 35e0fbe83a..0000000000 --- a/accurest-core/src/test/groovy/io/codearte/accurest/dsl/internal/ExecutionPropertySpec.groovy +++ /dev/null @@ -1,19 +0,0 @@ -package io.codearte.accurest.dsl.internal - -import spock.lang.Specification - -class ExecutionPropertySpec extends Specification { - - def 'should insert passed value in place of $it placeholder'() { - given: - String commandToExecute = 'commandToExecute($it)' - ExecutionProperty executionProperty = new ExecutionProperty(commandToExecute) - and: - String valueToInsert = 'someObject.itsValue' - when: - String commandWithInsertedValue = executionProperty.insertValue(valueToInsert) - then: - 'commandToExecute(someObject.itsValue)' == commandWithInsertedValue - } - -} diff --git a/accurest-core/src/test/resources/directory/with/scenario/01_login.groovy b/accurest-core/src/test/resources/directory/with/scenario/01_login.groovy deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/accurest-core/src/test/resources/directory/with/scenario/02_showCart.groovy b/accurest-core/src/test/resources/directory/with/scenario/02_showCart.groovy deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/accurest-core/src/test/resources/directory/with/scenario/03_logout.groovy b/accurest-core/src/test/resources/directory/with/scenario/03_logout.groovy deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/accurest-core/src/test/resources/directory/with/stubs/different/diff.groovy b/accurest-core/src/test/resources/directory/with/stubs/different/diff.groovy deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/accurest-core/src/test/resources/directory/with/stubs/other/different/diff.groovy b/accurest-core/src/test/resources/directory/with/stubs/other/different/diff.groovy deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/accurest-core/src/test/resources/directory/with/stubs/other/other.groovy b/accurest-core/src/test/resources/directory/with/stubs/other/other.groovy deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/accurest-core/src/test/resources/directory/with/stubs/other/sample.groovy b/accurest-core/src/test/resources/directory/with/stubs/other/sample.groovy deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/accurest-core/src/test/resources/directory/with/stubs/package/exceptions/test.groovy b/accurest-core/src/test/resources/directory/with/stubs/package/exceptions/test.groovy deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/accurest-core/src/test/resources/directory/with/stubs/package/v1/exceptions/testv1.groovy b/accurest-core/src/test/resources/directory/with/stubs/package/v1/exceptions/testv1.groovy deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/accurest-core/src/test/resources/directory/with/stubs/package/v2/exceptions/testv2.groovy b/accurest-core/src/test/resources/directory/with/stubs/package/v2/exceptions/testv2.groovy deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/accurest-core/src/test/resources/dsl/basic/sampleDsl.groovy b/accurest-core/src/test/resources/dsl/basic/sampleDsl.groovy deleted file mode 100644 index 4405a9920e..0000000000 --- a/accurest-core/src/test/resources/dsl/basic/sampleDsl.groovy +++ /dev/null @@ -1,30 +0,0 @@ -io.codearte.accurest.dsl.GroovyDsl.make { - request { - method('PUT') - headers { - header 'Content-Type': 'application/json' - } - body("""\ - { - "name": "Jan", - "id": "${value(client('abc'), server('def'))}", - } - """ - ) - url $(client('/[0-9]{2}'), server('/12')) - } - response { - status 200 - body("""\ - { - "name": "Jan", - "id": "${value(client('123'), server('321'))}", - "surname": "${value(client('Kowalsky'), server('$checkIfSurnameValid($value)'))}" - } - """ - ) - headers { - header 'Content-Type': 'text/plain' - } - } -} diff --git a/accurest-core/src/test/resources/strange_[3.3.3]_directory/02_login.groovy b/accurest-core/src/test/resources/strange_[3.3.3]_directory/02_login.groovy deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/accurest-core/src/test/resources/strange_[3.3.3]_directory/bar/03_login.groovy b/accurest-core/src/test/resources/strange_[3.3.3]_directory/bar/03_login.groovy deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/accurest-core/src/test/resources/strange_[3.3.3]_directory/foo/01_login.groovy b/accurest-core/src/test/resources/strange_[3.3.3]_directory/foo/01_login.groovy deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/accurest-gradle-plugin/src/main/groovy/io/codearte/accurest/plugin/AccurestGradlePlugin.groovy b/accurest-gradle-plugin/src/main/groovy/io/codearte/accurest/plugin/AccurestGradlePlugin.groovy deleted file mode 100644 index 658f63bb30..0000000000 --- a/accurest-gradle-plugin/src/main/groovy/io/codearte/accurest/plugin/AccurestGradlePlugin.groovy +++ /dev/null @@ -1,89 +0,0 @@ -package io.codearte.accurest.plugin - -import io.codearte.accurest.config.AccurestConfigProperties -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.api.Task -/** - * @author Jakub Kubrynski - */ -class AccurestGradlePlugin implements Plugin { - - private static final String GENERATE_SERVER_TESTS_TASK_NAME = 'generateAccurest' - private static final String DSL_TO_WIREMOCK_CLIENT_TASK_NAME = 'generateWireMockClientStubs' - - private static final Class IDEA_PLUGIN_CLASS = org.gradle.plugins.ide.idea.IdeaPlugin - private static final String GROUP_NAME = "Verification" - - private Project project - - @Override - void apply(Project project) { - this.project = project - AccurestConfigProperties extension = project.extensions.create('accurest', AccurestConfigProperties) - - project.check.dependsOn(GENERATE_SERVER_TESTS_TASK_NAME) - - setConfigurationDefaults(extension) - createGenerateTestsTask(extension) - createAndConfigureGenerateWireMockClientStubsFromDslTask(extension) - deprecatedCreateAndConfigureGenerateWiremockClientStubsFromDslTask() - project.dependencies.add("testCompile", "com.github.tomakehurst:wiremock:2.0.10-beta") - project.dependencies.add("testCompile", "com.toomuchcoding.jsonassert:jsonassert:${extension.getJsonAssertVersion()}") - project.dependencies.add("testCompile", "org.assertj:assertj-core:2.3.0") - - project.afterEvaluate { - def hasIdea = project.plugins.findPlugin(IDEA_PLUGIN_CLASS) - if (hasIdea) { - project.idea { - module { - testSourceDirs += extension.generatedTestSourcesDir - testSourceDirs += extension.contractsDslDir - } - } - } - } - } - - void setConfigurationDefaults(AccurestConfigProperties extension) { - extension.with { - generatedTestSourcesDir = project.file("${project.buildDir}/generated-test-sources/accurest") - contractsDslDir = defaultAccurestContractsDir() //TODO: Use sourceset - basePackageForTests = 'io.codearte.accurest.tests' - } - } - - private File defaultAccurestContractsDir() { - project.file("${project.rootDir}/src/test/resources/accurest") - } - - private void createGenerateTestsTask(AccurestConfigProperties extension) { - Task task = project.tasks.create(GENERATE_SERVER_TESTS_TASK_NAME, GenerateServerTestsTask) - task.description = "Generate server tests from GroovyDSL" - task.group = GROUP_NAME - task.conventionMapping.with { - contractsDslDir = { extension.contractsDslDir } - generatedTestSourcesDir = { extension.generatedTestSourcesDir } - configProperties = { extension } - } - } - - private void createAndConfigureGenerateWireMockClientStubsFromDslTask(AccurestConfigProperties extension) { - Task task = project.tasks.create(DSL_TO_WIREMOCK_CLIENT_TASK_NAME, GenerateWireMockClientStubsFromDslTask) - task.description = "Generate WireMock client stubs from GroovyDSL" - task.group = GROUP_NAME - task.conventionMapping.with { - contractsDslDir = { extension.contractsDslDir } - stubsOutputDir = { extension.stubsOutputDir } - configProperties = { extension } - } - } - - private void deprecatedCreateAndConfigureGenerateWiremockClientStubsFromDslTask() { - Task task = project.tasks.create('generateWiremockClientStubs') - task.dependsOn('generateWireMockClientStubs') - task.description = "DEPRECATED - Generates WireMock client stubs. - DEPRECATED - use 'generateWireMockClientStubs' task" - task.group = GROUP_NAME - task.doFirst {logger.warn("DEPRECATION WARNING. Task 'generateWiremockClientStubs' is deprecated. Use 'generateWireMockClientStubs' task instead.")} - } -} diff --git a/accurest-gradle-plugin/src/main/groovy/io/codearte/accurest/plugin/GenerateServerTestsTask.groovy b/accurest-gradle-plugin/src/main/groovy/io/codearte/accurest/plugin/GenerateServerTestsTask.groovy deleted file mode 100644 index d6fe06a9fd..0000000000 --- a/accurest-gradle-plugin/src/main/groovy/io/codearte/accurest/plugin/GenerateServerTestsTask.groovy +++ /dev/null @@ -1,40 +0,0 @@ -package io.codearte.accurest.plugin - -import io.codearte.accurest.AccurestException -import io.codearte.accurest.TestGenerator -import io.codearte.accurest.config.AccurestConfigProperties -import org.gradle.api.GradleException -import org.gradle.api.internal.ConventionTask -import org.gradle.api.tasks.InputDirectory -import org.gradle.api.tasks.OutputDirectory -import org.gradle.api.tasks.TaskAction - -class GenerateServerTestsTask extends ConventionTask { - - @InputDirectory - File contractsDslDir - @OutputDirectory - File generatedTestSourcesDir - - //TODO: How to deal with @Input*, @Output* and that domain object? - AccurestConfigProperties configProperties - - @TaskAction - void generate() { - project.logger.info("Accurest Plugin: Invoking test sources generation") - - project.sourceSets.test.groovy { - project.logger.info("Registering ${getConfigProperties().generatedTestSourcesDir} as test source directory") - srcDir getConfigProperties().generatedTestSourcesDir - } - - try { - //TODO: What with that? How to pass? - TestGenerator generator = new TestGenerator(getConfigProperties()) - int generatedClasses = generator.generate() - project.logger.info("Generated {} test classes", generatedClasses) - } catch (AccurestException e) { - throw new GradleException("Accurest Plugin exception: ${e.message}", e) - } - } -} diff --git a/accurest-gradle-plugin/src/main/groovy/io/codearte/accurest/plugin/GenerateWireMockClientStubsFromDslTask.groovy b/accurest-gradle-plugin/src/main/groovy/io/codearte/accurest/plugin/GenerateWireMockClientStubsFromDslTask.groovy deleted file mode 100644 index 3a7825fbda..0000000000 --- a/accurest-gradle-plugin/src/main/groovy/io/codearte/accurest/plugin/GenerateWireMockClientStubsFromDslTask.groovy +++ /dev/null @@ -1,28 +0,0 @@ -package io.codearte.accurest.plugin - -import io.codearte.accurest.config.AccurestConfigProperties -import io.codearte.accurest.wiremock.DslToWireMockClientConverter -import io.codearte.accurest.wiremock.RecursiveFilesConverter -import org.gradle.api.internal.ConventionTask -import org.gradle.api.tasks.InputDirectory -import org.gradle.api.tasks.OutputDirectory -import org.gradle.api.tasks.TaskAction - -//TODO: Implement as an incremental task: https://gradle.org/docs/current/userguide/custom_tasks.html#incremental_tasks ? -class GenerateWireMockClientStubsFromDslTask extends ConventionTask { - - @InputDirectory - File contractsDslDir - @OutputDirectory - File stubsOutputDir - - AccurestConfigProperties configProperties - - @TaskAction - void generate() { - logger.info("Accurest Plugin: Invoking GroovyDSL to WireMock client stubs conversion") - logger.debug("From '${getContractsDslDir()}' to '${getStubsOutputDir()}'") - RecursiveFilesConverter converter = new RecursiveFilesConverter(new DslToWireMockClientConverter(), getConfigProperties()) - converter.processFiles() - } -} diff --git a/accurest-gradle-plugin/src/main/resources/META-INF/gradle-plugins/accurest.properties b/accurest-gradle-plugin/src/main/resources/META-INF/gradle-plugins/accurest.properties deleted file mode 100644 index edfd566c2c..0000000000 --- a/accurest-gradle-plugin/src/main/resources/META-INF/gradle-plugins/accurest.properties +++ /dev/null @@ -1 +0,0 @@ -implementation-class=io.codearte.accurest.plugin.AccurestGradlePlugin \ No newline at end of file diff --git a/accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/AccurestGradlePluginTest.groovy b/accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/AccurestGradlePluginTest.groovy deleted file mode 100644 index e5ef0640ff..0000000000 --- a/accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/AccurestGradlePluginTest.groovy +++ /dev/null @@ -1,22 +0,0 @@ -package io.codearte.accurest.plugin - -import org.gradle.api.Project -import org.gradle.testfixtures.ProjectBuilder -import spock.lang.Ignore -import spock.lang.Specification - -/** - * @author Jakub Kubrynski - */ -@Ignore -class AccurestGradlePluginTest extends Specification { - - def void greeterPluginAddsGreetingTaskToProject() { - when: - Project project = ProjectBuilder.builder().build() - project.apply plugin: 'accurest' - - then: - project.tasks.generateAccurest - } -} diff --git a/accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/MessagingProjectSpec.groovy b/accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/MessagingProjectSpec.groovy deleted file mode 100755 index 0bb8b9697b..0000000000 --- a/accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/MessagingProjectSpec.groovy +++ /dev/null @@ -1,31 +0,0 @@ -package io.codearte.accurest.plugin - -import spock.lang.Stepwise - -@Stepwise -class MessagingProjectSpec extends AccurestIntegrationSpec { - - def setup() { - setupForProject("functionalTest/messagingProject") - runTasksSuccessfully('clean') //delete accidental output when previously importing SimpleBoot into Idea to tweak it - } - - def "should pass basic flow for Spock"() { - given: - assert fileExists('build.gradle') - expect: - runTasksSuccessfully('check', "publishToMavenLocal") - jarContainsAccurestContracts('build/libs') - } - - def "should pass basic flow for JUnit"() { - given: - runTasksSuccessfully('clean') - assert fileExists('build.gradle') - expect: - switchToJunitTestFramework('io.codearte.accurest.samples.book.MessagingBaseSpec', 'io.codearte.accurest.samples.book.MessagingBaseTest') - runTasksSuccessfully('check', "publishToMavenLocal") - jarContainsAccurestContracts('build/libs') - } - -} diff --git a/accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/SampleJerseyProjectSpec.groovy b/accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/SampleJerseyProjectSpec.groovy deleted file mode 100755 index 6a44c37fa1..0000000000 --- a/accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/SampleJerseyProjectSpec.groovy +++ /dev/null @@ -1,30 +0,0 @@ -package io.codearte.accurest.plugin - -import spock.lang.Stepwise - -@Stepwise -class SampleJerseyProjectSpec extends AccurestIntegrationSpec { - - def setup() { - setupForProject("functionalTest/sampleJerseyProject") - runTasksSuccessfully('clean') //delete accidental output when previously importing SimpleBoot into Idea to tweak it - } - - def "should pass basic flow for Spock"() { - given: - assert fileExists('build.gradle') - expect: - runTasksSuccessfully('check', "publishToMavenLocal") - jarContainsAccurestContracts('fraudDetectionService/build/libs') - } - - def "should pass basic flow for JUnit"() { - given: - switchToJunitTestFramework() - assert fileExists('build.gradle') - expect: - runTasksSuccessfully('check', "publishToMavenLocal") - jarContainsAccurestContracts('fraudDetectionService/build/libs') - } - -} diff --git a/accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/SampleProjectSpec.groovy b/accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/SampleProjectSpec.groovy deleted file mode 100755 index 140a9d898a..0000000000 --- a/accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/SampleProjectSpec.groovy +++ /dev/null @@ -1,30 +0,0 @@ -package io.codearte.accurest.plugin - -import spock.lang.Stepwise - -@Stepwise -class SampleProjectSpec extends AccurestIntegrationSpec { - - def setup() { - setupForProject("functionalTest/sampleProject") - runTasksSuccessfully('clean') //delete accidental output when previously importing SimpleBoot into Idea to tweak it - } - - def "should pass basic flow for Spock"() { - given: - assert fileExists('build.gradle') - expect: - runTasksSuccessfully('check', "publishToMavenLocal") - jarContainsAccurestContracts('fraudDetectionService/build/libs') - } - - def "should pass basic flow for JUnit"() { - given: - switchToJunitTestFramework() - assert fileExists('build.gradle') - expect: - runTasksSuccessfully('check', "publishToMavenLocal") - jarContainsAccurestContracts('fraudDetectionService/build/libs') - } - -} diff --git a/accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/ScenarioProjectSpec.groovy b/accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/ScenarioProjectSpec.groovy deleted file mode 100755 index 939b71db70..0000000000 --- a/accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/ScenarioProjectSpec.groovy +++ /dev/null @@ -1,30 +0,0 @@ -package io.codearte.accurest.plugin - -import spock.lang.Stepwise - -@Stepwise -class ScenarioProjectSpec extends AccurestIntegrationSpec { - - def setup() { - setupForProject("functionalTest/scenarioProject") - runTasksSuccessfully('clean') //delete accidental output when previously importing SimpleBoot into Idea to tweak it - } - - def "should pass basic flow for Spock"() { - given: - assert fileExists('build.gradle') - expect: - runTasksSuccessfully('check', "publishToMavenLocal") - jarContainsAccurestContracts('fraudDetectionService/build/libs') - } - - def "should pass basic flow for JUnit"() { - given: - assert fileExists('build.gradle') - expect: - switchToJunitTestFramework() - runTasksSuccessfully('check', "publishToMavenLocal") - jarContainsAccurestContracts('fraudDetectionService/build/libs') - } - -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradle.properties b/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradle.properties deleted file mode 100644 index 03c9b16bb8..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradle.properties +++ /dev/null @@ -1,6 +0,0 @@ -groupId=com.ofg -jacksonMapper=1.9.13 -restAssuredVersion=2.4.0 -springVersion=4.1.7.RELEASE - -springBootVersion=1.3.3.RELEASE \ No newline at end of file diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradle/wrapper/gradle-wrapper.properties b/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradle/wrapper/gradle-wrapper.properties deleted file mode 100755 index cfa20637e3..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Sat Feb 21 20:13:29 CET 2015 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/repository/mappings/com/ofg/twitter-places-analyzer/pairId/collerate_PlacesFrom_Tweet.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/repository/mappings/com/ofg/twitter-places-analyzer/pairId/collerate_PlacesFrom_Tweet.groovy deleted file mode 100644 index 826f71b791..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/repository/mappings/com/ofg/twitter-places-analyzer/pairId/collerate_PlacesFrom_Tweet.groovy +++ /dev/null @@ -1,18 +0,0 @@ -io.codearte.accurest.dsl.GroovyDsl.make { - priority 2 - request { - method 'PUT' - url '/api/12' - headers { - header 'Content-Type': 'application/json' - } - body '''\ - [{ - "text": "Gonna see you at Warsaw" - }] -''' - } - response { - status 200 - } -} \ No newline at end of file diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/repository/mappings/com/ofg/twitter-places-analyzer/pairId/moreComplexVersion.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/repository/mappings/com/ofg/twitter-places-analyzer/pairId/moreComplexVersion.groovy deleted file mode 100644 index 8348974b89..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/repository/mappings/com/ofg/twitter-places-analyzer/pairId/moreComplexVersion.groovy +++ /dev/null @@ -1,25 +0,0 @@ -io.codearte.accurest.dsl.GroovyDsl.make { - request { - method 'PUT' - url $(client(regex('^/api/[0-9]{2}$')), server('/api/12')) - headers { - header 'Content-Type': 'application/json' - } - body '''\ - [{ - "text": "Gonna see you at Warsaw" - }] -''' - } - response { - headers { - header 'Content-Type': $(client('application/json'), server(regex('application/json.*'))) - header 'Location': $(client('https://localhost:8080'), server(execute('isEmpty($it)'))) - } - body ( - path: $(client('/api/12'), server(regex('^/api/[0-9]{2}$'))), - correlationId: $(client('1223456'), server(execute('isProperCorrelationId($it)'))) - ) - status 200 - } -} \ No newline at end of file diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/settings.gradle b/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/settings.gradle deleted file mode 100644 index d227b869a2..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name='bootSimple' diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/groovy/com/ofg/twitter/places/AcceptanceSpec.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/groovy/com/ofg/twitter/places/AcceptanceSpec.groovy deleted file mode 100644 index 458e275daf..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/groovy/com/ofg/twitter/places/AcceptanceSpec.groovy +++ /dev/null @@ -1,23 +0,0 @@ -package com.ofg.twitter.places - -import com.ofg.twitter.place.PairIdController -import org.springframework.http.MediaType -import org.springframework.test.web.servlet.MockMvc -import org.springframework.test.web.servlet.setup.MockMvcBuilders -import spock.lang.Specification - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status - -class AcceptanceSpec extends Specification { - - def "should have controller up and running"() { - given: - MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new PairIdController()).build() - expect: - mockMvc.perform(put("/api/${1}"). - contentType(MediaType.APPLICATION_JSON). - content("""[{"text":"Gonna see you at Warsaw"}]""")). - andExpect(status().isOk()) - } -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/groovy/com/ofg/twitter/places/BaseMockMvcSpec.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/groovy/com/ofg/twitter/places/BaseMockMvcSpec.groovy deleted file mode 100644 index 4e94ba6525..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/groovy/com/ofg/twitter/places/BaseMockMvcSpec.groovy +++ /dev/null @@ -1,23 +0,0 @@ -package com.ofg.twitter.places - -import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc -import com.ofg.twitter.place.PairIdController -import spock.lang.Specification - -// tag::base_class[] -abstract class BaseMockMvcSpec extends Specification { - - def setup() { - RestAssuredMockMvc.standaloneSetup(new PairIdController()) - } - - void isProperCorrelationId(Integer correlationId) { - assert correlationId == 123456 - } - - void isEmpty(String value) { - assert value == null - } - -} -// end::base_class[] diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/resources/logback-test.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/resources/logback-test.groovy deleted file mode 100644 index 315c39c794..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/resources/logback-test.groovy +++ /dev/null @@ -1,14 +0,0 @@ -import ch.qos.logback.classic.encoder.PatternLayoutEncoder -import ch.qos.logback.core.ConsoleAppender - -String console = "CONSOLE" -String logPattern = "%d{yyyy-MM-dd HH:mm:ss.SSSZ, Europe/Warsaw} | %-5level | %X{correlationId} | %thread | %logger{1} | %m%n" - -appender(console, ConsoleAppender) { - encoder(PatternLayoutEncoder) { - pattern = logPattern - } -} - -root(INFO, [console]) -logger("com.ofg", DEBUG) diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradle.properties b/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradle.properties deleted file mode 100644 index 6910517f7c..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradle.properties +++ /dev/null @@ -1,6 +0,0 @@ -groupId=io.codearte -jacksonMapper=1.9.13 -restAssuredVersion=2.9.0 -springVersion=4.2.3.RELEASE - -springBootVersion=1.3.3.RELEASE \ No newline at end of file diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradle/wrapper/gradle-wrapper.properties b/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradle/wrapper/gradle-wrapper.properties deleted file mode 100755 index a1f7bb3d56..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Sun Apr 17 20:31:11 CEST 2016 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/a_foo.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/a_foo.groovy deleted file mode 100644 index 6de37631ef..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/a_foo.groovy +++ /dev/null @@ -1,10 +0,0 @@ -io.codearte.accurest.dsl.GroovyDsl.make { - request { - url '/foo' - method 'GET' - } - response { - status 200 - body 'bar' - } -} \ No newline at end of file diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/bookDeleted.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/bookDeleted.groovy deleted file mode 100644 index aa319831a4..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/bookDeleted.groovy +++ /dev/null @@ -1,13 +0,0 @@ -io.codearte.accurest.dsl.GroovyDsl.make { - label 'some_label' - input { - messageFrom('delete') - messageBody([ - bookName: 'foo' - ]) - messageHeaders { - header('sample', 'header') - } - assertThat('bookWasDeleted()') - } -} \ No newline at end of file diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/bookReturned1.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/bookReturned1.groovy deleted file mode 100644 index b21b1c7cd1..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/bookReturned1.groovy +++ /dev/null @@ -1,13 +0,0 @@ -io.codearte.accurest.dsl.GroovyDsl.make { - label 'some_label' - input { - triggeredBy('bookReturnedTriggered()') - } - outputMessage { - sentTo('output') - body('''{ "bookName" : "foo" }''') - headers { - header('BOOK-NAME', 'foo') - } - } -} \ No newline at end of file diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/bookReturned2.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/bookReturned2.groovy deleted file mode 100644 index e6090df410..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/bookReturned2.groovy +++ /dev/null @@ -1,21 +0,0 @@ -io.codearte.accurest.dsl.GroovyDsl.make { - label 'some_label' - input { - messageFrom('input') - messageBody([ - bookName: 'foo' - ]) - messageHeaders { - header('sample', 'header') - } - } - outputMessage { - sentTo('output') - body([ - bookName: 'foo' - ]) - headers { - header('BOOK-NAME', 'foo') - } - } -} \ No newline at end of file diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/settings.gradle b/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/settings.gradle deleted file mode 100644 index d227b869a2..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name='bootSimple' diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/io/codearte/accurest/samples/book/BookDeleted.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/io/codearte/accurest/samples/book/BookDeleted.groovy deleted file mode 100644 index bf3cd9b68c..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/io/codearte/accurest/samples/book/BookDeleted.groovy +++ /dev/null @@ -1,14 +0,0 @@ -package io.codearte.accurest.samples.book - -import com.fasterxml.jackson.annotation.JsonCreator -import groovy.transform.CompileStatic - -@CompileStatic -class BookDeleted { - final String bookName - - @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) - BookDeleted(String bookName) { - this.bookName = bookName - } -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/io/codearte/accurest/samples/book/BookReturned.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/io/codearte/accurest/samples/book/BookReturned.groovy deleted file mode 100644 index 3b244a0395..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/io/codearte/accurest/samples/book/BookReturned.groovy +++ /dev/null @@ -1,14 +0,0 @@ -package io.codearte.accurest.samples.book - -import com.fasterxml.jackson.annotation.JsonCreator -import groovy.transform.CompileStatic - -@CompileStatic -class BookReturned { - final String bookName - - @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) - BookReturned(String bookName) { - this.bookName = bookName - } -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/io/codearte/accurest/samples/book/IntegrationMessagingApplication.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/io/codearte/accurest/samples/book/IntegrationMessagingApplication.groovy deleted file mode 100644 index ed28a54b59..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/io/codearte/accurest/samples/book/IntegrationMessagingApplication.groovy +++ /dev/null @@ -1,22 +0,0 @@ -package io.codearte.accurest.samples.book - -import org.springframework.boot.SpringApplication -import org.springframework.boot.autoconfigure.SpringBootApplication -import org.springframework.context.annotation.ImportResource -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController - -@SpringBootApplication -@RestController -@ImportResource("classpath*:integration-context.xml") -class IntegrationMessagingApplication { - - @RequestMapping("/foo") - String foo() { - return "bar" - } - - static void main(String[] args) { - SpringApplication.run(IntegrationMessagingApplication.class, args) - } -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsFraud.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsFraud.groovy deleted file mode 100644 index 44b1c08604..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsFraud.groovy +++ /dev/null @@ -1,27 +0,0 @@ -io.codearte.accurest.dsl.GroovyDsl.make { - request { - method """PUT""" - url """/fraudcheck""" - body(""" - { - "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", - "loanAmount":99999} - """ - ) - headers { - header("""Content-Type""", """application/vnd.fraud.v1+json""") - } - - } - response { - status 200 - body( """{ - "fraudCheckStatus": "${value(client('FRAUD'), server(regex('[A-Z]{5}')))}", - "rejectionReason": "Amount too high" -}""") - headers { - header('Content-Type': 'application/vnd.fraud.v1+json') - } - } - -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.groovy deleted file mode 100644 index 7bc64d0dac..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.groovy +++ /dev/null @@ -1,28 +0,0 @@ -io.codearte.accurest.dsl.GroovyDsl.make { - request { - method 'PUT' - url '/fraudcheck' - body(""" - { - "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", - "loanAmount":123.123 - } - """ - ) - headers { - header('Content-Type', 'application/vnd.fraud.v1+json') - } - - } - response { - status 200 - body( - fraudCheckStatus: "OK", - rejectionReason: $(client(null), server(execute('assertThatRejectionReasonIsNull($it)'))) - ) - headers { - header('Content-Type': 'application/vnd.fraud.v1+json') - } - } - -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java b/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java deleted file mode 100644 index b87c365d51..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.blogspot.toomuchcoding.frauddetection.model; - -public enum FraudCheckStatus { - OK, FRAUD -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/gradle/wrapper/gradle-wrapper.properties b/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 8b2268d1ba..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Wed Jan 28 00:32:44 CET 2015 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/Client.java b/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/Client.java deleted file mode 100644 index 5e91273eda..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/Client.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.blogspot.toomuchcoding.frauddetection.model; - -public class Client { - - private String pesel; - - public String getPesel() { - return pesel; - } - - public void setPesel(String pesel) { - this.pesel = pesel; - } -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java b/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java deleted file mode 100644 index b87c365d51..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.blogspot.toomuchcoding.frauddetection.model; - -public enum FraudCheckStatus { - OK, FRAUD -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceRequest.java b/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceRequest.java deleted file mode 100644 index ac595998bc..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceRequest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.blogspot.toomuchcoding.frauddetection.model; - -import java.math.BigDecimal; - -public class FraudServiceRequest { - - private String clientPesel; - - private BigDecimal loanAmount; - - public FraudServiceRequest() { - } - - public FraudServiceRequest(LoanApplication loanApplication) { - this.clientPesel = loanApplication.getClient().getPesel(); - this.loanAmount = loanApplication.getAmount(); - } - - public String getClientPesel() { - return clientPesel; - } - - public void setClientPesel(String clientPesel) { - this.clientPesel = clientPesel; - } - - public BigDecimal getLoanAmount() { - return loanAmount; - } - - public void setLoanAmount(BigDecimal loanAmount) { - this.loanAmount = loanAmount; - } -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplication.java b/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplication.java deleted file mode 100644 index 816087988b..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplication.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.blogspot.toomuchcoding.frauddetection.model; - -import java.math.BigDecimal; - -public class LoanApplication { - - private Client client; - - private BigDecimal amount; - - private String loanApplicationId; - - public Client getClient() { - return client; - } - - public void setClient(Client client) { - this.client = client; - } - - public BigDecimal getAmount() { - return amount; - } - - public void setAmount(BigDecimal amount) { - this.amount = amount; - } - - public String getLoanApplicationId() { - return loanApplicationId; - } - - public void setLoanApplicationId(String loanApplicationId) { - this.loanApplicationId = loanApplicationId; - } -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/settings.gradle b/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/settings.gradle deleted file mode 100644 index 6a42a6c7ce..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -include ':fraudDetectionService' -include ':loanApplicationService' diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsFraud.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsFraud.groovy deleted file mode 100644 index 44b1c08604..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsFraud.groovy +++ /dev/null @@ -1,27 +0,0 @@ -io.codearte.accurest.dsl.GroovyDsl.make { - request { - method """PUT""" - url """/fraudcheck""" - body(""" - { - "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", - "loanAmount":99999} - """ - ) - headers { - header("""Content-Type""", """application/vnd.fraud.v1+json""") - } - - } - response { - status 200 - body( """{ - "fraudCheckStatus": "${value(client('FRAUD'), server(regex('[A-Z]{5}')))}", - "rejectionReason": "Amount too high" -}""") - headers { - header('Content-Type': 'application/vnd.fraud.v1+json') - } - } - -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.groovy deleted file mode 100644 index 7bc64d0dac..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.groovy +++ /dev/null @@ -1,28 +0,0 @@ -io.codearte.accurest.dsl.GroovyDsl.make { - request { - method 'PUT' - url '/fraudcheck' - body(""" - { - "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", - "loanAmount":123.123 - } - """ - ) - headers { - header('Content-Type', 'application/vnd.fraud.v1+json') - } - - } - response { - status 200 - body( - fraudCheckStatus: "OK", - rejectionReason: $(client(null), server(execute('assertThatRejectionReasonIsNull($it)'))) - ) - headers { - header('Content-Type': 'application/vnd.fraud.v1+json') - } - } - -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java b/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java deleted file mode 100644 index b87c365d51..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.blogspot.toomuchcoding.frauddetection.model; - -public enum FraudCheckStatus { - OK, FRAUD -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/test/groovy/com/blogspot/toomuchcoding/MvcSpec.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/test/groovy/com/blogspot/toomuchcoding/MvcSpec.groovy deleted file mode 100644 index bcb6ef1579..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/test/groovy/com/blogspot/toomuchcoding/MvcSpec.groovy +++ /dev/null @@ -1,15 +0,0 @@ -package com.blogspot.toomuchcoding - -import com.blogspot.toomuchcoding.frauddetection.FraudDetectionController -import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc -import spock.lang.Specification - -class MvcSpec extends Specification { - def setup() { - RestAssuredMockMvc.standaloneSetup(new FraudDetectionController()) - } - - void assertThatRejectionReasonIsNull(def rejectionReason) { - assert !rejectionReason - } -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/gradle/wrapper/gradle-wrapper.properties b/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 8b2268d1ba..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Wed Jan 28 00:32:44 CET 2015 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java b/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java deleted file mode 100644 index b87c365d51..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.blogspot.toomuchcoding.frauddetection.model; - -public enum FraudCheckStatus { - OK, FRAUD -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/settings.gradle b/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/settings.gradle deleted file mode 100644 index 6a42a6c7ce..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -include ':fraudDetectionService' -include ':loanApplicationService' diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/1_shouldMarkClientAsNotFraud.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/1_shouldMarkClientAsNotFraud.groovy deleted file mode 100644 index 7bc64d0dac..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/1_shouldMarkClientAsNotFraud.groovy +++ /dev/null @@ -1,28 +0,0 @@ -io.codearte.accurest.dsl.GroovyDsl.make { - request { - method 'PUT' - url '/fraudcheck' - body(""" - { - "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", - "loanAmount":123.123 - } - """ - ) - headers { - header('Content-Type', 'application/vnd.fraud.v1+json') - } - - } - response { - status 200 - body( - fraudCheckStatus: "OK", - rejectionReason: $(client(null), server(execute('assertThatRejectionReasonIsNull($it)'))) - ) - headers { - header('Content-Type': 'application/vnd.fraud.v1+json') - } - } - -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/2_shouldMarkClientAsFraud.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/2_shouldMarkClientAsFraud.groovy deleted file mode 100644 index 44b1c08604..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/2_shouldMarkClientAsFraud.groovy +++ /dev/null @@ -1,27 +0,0 @@ -io.codearte.accurest.dsl.GroovyDsl.make { - request { - method """PUT""" - url """/fraudcheck""" - body(""" - { - "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", - "loanAmount":99999} - """ - ) - headers { - header("""Content-Type""", """application/vnd.fraud.v1+json""") - } - - } - response { - status 200 - body( """{ - "fraudCheckStatus": "${value(client('FRAUD'), server(regex('[A-Z]{5}')))}", - "rejectionReason": "Amount too high" -}""") - headers { - header('Content-Type': 'application/vnd.fraud.v1+json') - } - } - -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java deleted file mode 100644 index b87c365d51..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.blogspot.toomuchcoding.frauddetection.model; - -public enum FraudCheckStatus { - OK, FRAUD -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/test/groovy/com/blogspot/toomuchcoding/MvcSpec.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/test/groovy/com/blogspot/toomuchcoding/MvcSpec.groovy deleted file mode 100644 index bcb6ef1579..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/test/groovy/com/blogspot/toomuchcoding/MvcSpec.groovy +++ /dev/null @@ -1,15 +0,0 @@ -package com.blogspot.toomuchcoding - -import com.blogspot.toomuchcoding.frauddetection.FraudDetectionController -import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc -import spock.lang.Specification - -class MvcSpec extends Specification { - def setup() { - RestAssuredMockMvc.standaloneSetup(new FraudDetectionController()) - } - - void assertThatRejectionReasonIsNull(def rejectionReason) { - assert !rejectionReason - } -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradle/wrapper/gradle-wrapper.properties b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 8b2268d1ba..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Wed Jan 28 00:32:44 CET 2015 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java deleted file mode 100644 index 5a1a60244e..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.blogspot.toomuchcoding.frauddetection; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -@Configuration -@EnableAutoConfiguration -@ComponentScan -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java deleted file mode 100644 index b87c365d51..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.blogspot.toomuchcoding.frauddetection.model; - -public enum FraudCheckStatus { - OK, FRAUD -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceResponse.java b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceResponse.java deleted file mode 100644 index 9f3353ecbf..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceResponse.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.blogspot.toomuchcoding.frauddetection.model; - -public class FraudServiceResponse { - - private FraudCheckStatus fraudCheckStatus; - - private String rejectionReason; - - public FraudServiceResponse() { - } - - public FraudCheckStatus getFraudCheckStatus() { - return fraudCheckStatus; - } - - public void setFraudCheckStatus(FraudCheckStatus fraudCheckStatus) { - this.fraudCheckStatus = fraudCheckStatus; - } - - public String getRejectionReason() { - return rejectionReason; - } - - public void setRejectionReason(String rejectionReason) { - this.rejectionReason = rejectionReason; - } -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationStatus.java b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationStatus.java deleted file mode 100644 index 7f7f86e0ea..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.blogspot.toomuchcoding.frauddetection.model; - -public enum LoanApplicationStatus { - LOAN_APPLIED, LOAN_APPLICATION_REJECTED -} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/settings.gradle b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/settings.gradle deleted file mode 100644 index 6a42a6c7ce..0000000000 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -include ':fraudDetectionService' -include ':loanApplicationService' diff --git a/accurest-messaging/README.adoc b/accurest-messaging/README.adoc deleted file mode 100644 index b59884a982..0000000000 --- a/accurest-messaging/README.adoc +++ /dev/null @@ -1,25 +0,0 @@ - = Accurest Messaging - -Accurest allows you to verify your application that uses messaging as means of communication. -All of our integrations are working with Spring but you can also set one yourself. - -== Integrations - -You can use one of the three integration configurations: - -- Apache Camel -- Spring Integration -- Spring Cloud Stream - -If you're using Spring Boot, the aforementioned test configurations will be appended automatically. - -== Manual Integration - -The `accurest-messaging-core` module contains 3 main interfaces: - -- AccurestMessage - describes a message received / sent to a channel / queue / topic etc. -- AccurestMessageBuilder - describes how to build a message -- AccurestMessaging - class that allows you to build, send and receive messages - -In the generated test the `AccurestMessaging` is injected via `@Inject` annotation thus you can - diff --git a/accurest-messaging/accurest-messaging-camel/build.gradle b/accurest-messaging/accurest-messaging-camel/build.gradle deleted file mode 100644 index f43e73d0b4..0000000000 --- a/accurest-messaging/accurest-messaging-camel/build.gradle +++ /dev/null @@ -1,16 +0,0 @@ -repositories { - mavenLocal() - jcenter() - maven { - url "http://repo.spring.io/snapshot" - } - maven { - url "http://repo.spring.io/milestone" - } -} - -dependencies { - compile project(':accurest-messaging-root:accurest-messaging-core') - compile "org.apache.camel:camel-spring:${camelVersion}" - compile 'org.slf4j:slf4j-api:1.6.0' -} \ No newline at end of file diff --git a/accurest-messaging/accurest-messaging-camel/src/main/java/io/codearte/accurest/messaging/camel/AccurestCamelConfiguration.java b/accurest-messaging/accurest-messaging-camel/src/main/java/io/codearte/accurest/messaging/camel/AccurestCamelConfiguration.java deleted file mode 100644 index b96caf5ccc..0000000000 --- a/accurest-messaging/accurest-messaging-camel/src/main/java/io/codearte/accurest/messaging/camel/AccurestCamelConfiguration.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.codearte.accurest.messaging.camel; - -import io.codearte.accurest.messaging.AccurestMessageBuilder; -import io.codearte.accurest.messaging.AccurestMessaging; -import org.apache.camel.CamelContext; -import org.springframework.context.annotation.Bean; - -/** - * @author Marcin Grzejszczak - */ -public class AccurestCamelConfiguration { - - @Bean - AccurestMessaging accurestMessaging(CamelContext context, AccurestMessageBuilder builder) { - return new AccurestCamelMessaging(context, builder); - } - - @Bean - AccurestMessageBuilder accurestMessageBuilder() { - return new AccurestCamelMessageBuilder(); - } -} diff --git a/accurest-messaging/accurest-messaging-camel/src/main/java/io/codearte/accurest/messaging/camel/AccurestCamelMessageBuilder.java b/accurest-messaging/accurest-messaging-camel/src/main/java/io/codearte/accurest/messaging/camel/AccurestCamelMessageBuilder.java deleted file mode 100644 index 58f5609fd6..0000000000 --- a/accurest-messaging/accurest-messaging-camel/src/main/java/io/codearte/accurest/messaging/camel/AccurestCamelMessageBuilder.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.codearte.accurest.messaging.camel; - -import java.util.Map; - -import org.apache.camel.Message; -import org.apache.camel.impl.DefaultMessage; - -import io.codearte.accurest.messaging.AccurestMessage; -import io.codearte.accurest.messaging.AccurestMessageBuilder; - -/** - * @author Marcin Grzejszczak - */ -public class AccurestCamelMessageBuilder implements AccurestMessageBuilder { - - @Override - public AccurestMessage create(T payload, Map headers) { - DefaultMessage message = new DefaultMessage(); - message.setBody(payload); - message.setHeaders(headers); - return new CamelMessage<>(message); - } - - @Override - public AccurestMessage create(Message message) { - if (message == null) { - return null; - } - return new CamelMessage<>(message); - } -} diff --git a/accurest-messaging/accurest-messaging-camel/src/main/java/io/codearte/accurest/messaging/camel/CamelMessage.java b/accurest-messaging/accurest-messaging-camel/src/main/java/io/codearte/accurest/messaging/camel/CamelMessage.java deleted file mode 100644 index 6511617a89..0000000000 --- a/accurest-messaging/accurest-messaging-camel/src/main/java/io/codearte/accurest/messaging/camel/CamelMessage.java +++ /dev/null @@ -1,40 +0,0 @@ -package io.codearte.accurest.messaging.camel; - -import io.codearte.accurest.messaging.AccurestMessage; -import org.apache.camel.Message; - -import java.util.Map; - -/** - * @author Marcin Grzejszczak - */ -public class CamelMessage implements AccurestMessage { - - private final Message delegate; - - public CamelMessage(Message delegate) { - this.delegate = delegate; - } - - @Override - @SuppressWarnings("unchecked") - public T getPayload() { - return (T) delegate.getBody(); - } - - @Override - public Map getHeaders() { - return delegate.getHeaders(); - } - - @Override - public Object getHeader(String key) { - return getHeaders().get(key); - } - - @Override - public Message convert() { - return delegate; - } - -} diff --git a/accurest-messaging/accurest-messaging-core/build.gradle b/accurest-messaging/accurest-messaging-core/build.gradle deleted file mode 100644 index 8415bec8c7..0000000000 --- a/accurest-messaging/accurest-messaging-core/build.gradle +++ /dev/null @@ -1,8 +0,0 @@ -repositories { - jcenter() -} - -dependencies { - compile 'com.fasterxml.jackson.core:jackson-databind:2.7.0' - compile 'javax.inject:javax.inject:1' -} \ No newline at end of file diff --git a/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/AccurestFilter.java b/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/AccurestFilter.java deleted file mode 100644 index f41e544df0..0000000000 --- a/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/AccurestFilter.java +++ /dev/null @@ -1,14 +0,0 @@ -package io.codearte.accurest.messaging; - -/** - * Contract for filtering out messages that do not match the structure in the Accurest DSL - * - * @author Marcin Grzejszczak - */ -public interface AccurestFilter { - - /** - * @return @{code true} if the message should be passed through, @{code false} if the message should be filtered out, - */ - boolean matches(AccurestMessage message); -} diff --git a/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/AccurestMessage.java b/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/AccurestMessage.java deleted file mode 100644 index 65710a537a..0000000000 --- a/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/AccurestMessage.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.codearte.accurest.messaging; - -import java.util.Map; - -/** - * Describes a message. Contains payload and headers. A message can be converted - * to another type (e.g. Spring Messaging Message) - * - * @author Marcin Grzejszczak - */ -public interface AccurestMessage { - - /** - * Returns a payload of type {@code PAYLOAD} - */ - PAYLOAD getPayload(); - - /** - * Returns a map of headers - */ - Map getHeaders(); - - /** - * Returns a header for a given key - */ - Object getHeader(String key); - - /** - * Converts the message to {@code TYPE_TO_CONVERT_INTO} type - */ - TYPE_TO_CONVERT_INTO convert(); -} diff --git a/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/AccurestMessageBuilder.java b/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/AccurestMessageBuilder.java deleted file mode 100644 index 3d0a0e37e4..0000000000 --- a/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/AccurestMessageBuilder.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.codearte.accurest.messaging; - -import java.util.Map; - -/** - * Contract for creation of (@link AccurestMessage}. You can create a message from - * payload and headers or from some type (e.g. Spring Messaging Message). - * - * @author Marcin Grzejszczak - */ -public interface AccurestMessageBuilder { - - /** - * Creates a {@link AccurestMessage} from payload and headers - */ - AccurestMessage create(PAYLOAD payload, Map headers); - - /** - * Creates a {@link AccurestMessage} from the {@code TYPE_TO_CONVERT_INTO} type - */ - AccurestMessage create(TYPE_TO_CONVERT_INTO typeToConvertInto); -} diff --git a/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/AccurestMessaging.java b/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/AccurestMessaging.java deleted file mode 100644 index 17ee2e40bf..0000000000 --- a/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/AccurestMessaging.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.codearte.accurest.messaging; - -import java.util.Map; -import java.util.concurrent.TimeUnit; - -/** - * Core interface that allows you to build, send and receive messages. - * - * Destination is relevant to the underlaying implementation. Might be a channel, queue, topic etc. - * - * @author Marcin Grzejszczak - */ -public interface AccurestMessaging extends AccurestMessageBuilder { - /** - * Sends the {@link AccurestMessage} to the given destination. - */ - void send(AccurestMessage message, String destination); - - /** - * Sends the given payload with headers, to the given destination. - */ - void send(PAYLOAD payload, Map headers, String destination); - - /** - * Receives the {@link AccurestMessage} from the given destination. You can provide the timeout - * for receiving that message. - */ - AccurestMessage receiveMessage(String destination, long timeout, TimeUnit timeUnit); - - /** - * Receives the {@link AccurestMessage} from the given destination. A default timeout will be applied. - */ - AccurestMessage receiveMessage(String destination); -} diff --git a/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/AccurestObjectMapper.java b/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/AccurestObjectMapper.java deleted file mode 100644 index 39740539ad..0000000000 --- a/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/AccurestObjectMapper.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.codearte.accurest.messaging; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; - -/** - * Wrapper over {@link ObjectMapper} that won't try to parse - * String but will directly return it. - * - * @author Marcin Grzejszczak - */ -public class AccurestObjectMapper { - - private final ObjectMapper objectMapper; - - public AccurestObjectMapper(ObjectMapper objectMapper) { - this.objectMapper = objectMapper; - } - - public AccurestObjectMapper() { - this.objectMapper = new ObjectMapper(); - } - - public String writeValueAsString(Object payload) throws JsonProcessingException { - if (payload instanceof String) { - return payload.toString(); - } - return objectMapper.writeValueAsString(payload); - } -} diff --git a/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/noop/NoOpAccurestMessage.java b/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/noop/NoOpAccurestMessage.java deleted file mode 100644 index 179a63d9b7..0000000000 --- a/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/noop/NoOpAccurestMessage.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.codearte.accurest.messaging.noop; - -import io.codearte.accurest.messaging.AccurestMessage; - -import java.util.Map; - -/** - * @author Marcin Grzejszczak - */ -public class NoOpAccurestMessage implements AccurestMessage { - @Override - public Object getPayload() { - return null; - } - - @Override - public Map getHeaders() { - return null; - } - - @Override - public Object getHeader(String key) { - return null; - } - - @Override - public Object convert() { - return null; - } -} diff --git a/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/noop/NoOpAccurestMessageBuilder.java b/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/noop/NoOpAccurestMessageBuilder.java deleted file mode 100644 index eadbc73b02..0000000000 --- a/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/noop/NoOpAccurestMessageBuilder.java +++ /dev/null @@ -1,21 +0,0 @@ -package io.codearte.accurest.messaging.noop; - -import java.util.Map; - -import io.codearte.accurest.messaging.AccurestMessage; -import io.codearte.accurest.messaging.AccurestMessageBuilder; - -/** - * @author Marcin Grzejszczak - */ -public class NoOpAccurestMessageBuilder implements AccurestMessageBuilder { - @Override - public AccurestMessage create(Object o, Map headers) { - return new NoOpAccurestMessage(); - } - - @Override - public AccurestMessage create(Object o) { - return new NoOpAccurestMessage(); - } -} diff --git a/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/noop/NoOpAccurestMessaging.java b/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/noop/NoOpAccurestMessaging.java deleted file mode 100644 index 77d186bcd8..0000000000 --- a/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/noop/NoOpAccurestMessaging.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.codearte.accurest.messaging.noop; - -import java.util.Map; -import java.util.concurrent.TimeUnit; - -import io.codearte.accurest.messaging.AccurestMessage; -import io.codearte.accurest.messaging.AccurestMessaging; - -/** - * @author Marcin Grzejszczak - */ -public class NoOpAccurestMessaging implements AccurestMessaging { - @Override - public void send(AccurestMessage message, String destination) { - - } - - @Override - public void send(Object payload, Map headers, String destination) { - - } - - @Override - public AccurestMessage receiveMessage(String destination, long timeout, TimeUnit timeUnit) { - return null; - } - - @Override - public AccurestMessage receiveMessage(String destination) { - return null; - } - - @Override - public AccurestMessage create(Object o, Map headers) { - return null; - } - - @Override - public AccurestMessage create(Object o) { - return null; - } -} diff --git a/accurest-messaging/accurest-messaging-integration/build.gradle b/accurest-messaging/accurest-messaging-integration/build.gradle deleted file mode 100644 index f2ed07c88c..0000000000 --- a/accurest-messaging/accurest-messaging-integration/build.gradle +++ /dev/null @@ -1,16 +0,0 @@ -repositories { - mavenLocal() - jcenter() - maven { - url "http://repo.spring.io/snapshot" - } - maven { - url "http://repo.spring.io/milestone" - } -} - -dependencies { - compile project(':accurest-messaging-root:accurest-messaging-core') - compile "org.springframework:spring-messaging:${springVersion}" - compile 'org.slf4j:slf4j-api:1.6.0' -} \ No newline at end of file diff --git a/accurest-messaging/accurest-messaging-integration/src/main/java/io/codearte/accurest/messaging/integration/AccurestIntegrationConfiguration.java b/accurest-messaging/accurest-messaging-integration/src/main/java/io/codearte/accurest/messaging/integration/AccurestIntegrationConfiguration.java deleted file mode 100644 index 214161b605..0000000000 --- a/accurest-messaging/accurest-messaging-integration/src/main/java/io/codearte/accurest/messaging/integration/AccurestIntegrationConfiguration.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.codearte.accurest.messaging.integration; - -import io.codearte.accurest.messaging.AccurestMessageBuilder; -import io.codearte.accurest.messaging.AccurestMessaging; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; - -/** - * @author Marcin Grzejszczak - */ -public class AccurestIntegrationConfiguration { - - @Bean - AccurestMessaging accurestMessaging(ApplicationContext applicationContext, AccurestMessageBuilder accurestMessageBuilder) { - return new AccurestIntegrationMessaging(applicationContext, accurestMessageBuilder); - } - - @Bean - AccurestMessageBuilder accurestMessageBuilder() { - return new AccurestIntegrationMessageBuilder(); - } -} diff --git a/accurest-messaging/accurest-messaging-integration/src/main/java/io/codearte/accurest/messaging/integration/AccurestIntegrationMessageBuilder.java b/accurest-messaging/accurest-messaging-integration/src/main/java/io/codearte/accurest/messaging/integration/AccurestIntegrationMessageBuilder.java deleted file mode 100644 index 20dc976523..0000000000 --- a/accurest-messaging/accurest-messaging-integration/src/main/java/io/codearte/accurest/messaging/integration/AccurestIntegrationMessageBuilder.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.codearte.accurest.messaging.integration; - -import java.util.Map; - -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageHeaders; -import org.springframework.messaging.support.MessageBuilder; - -import io.codearte.accurest.messaging.AccurestMessage; -import io.codearte.accurest.messaging.AccurestMessageBuilder; - -/** - * @author Marcin Grzejszczak - */ -public class AccurestIntegrationMessageBuilder implements AccurestMessageBuilder> { - - @Override - public AccurestMessage> create(T payload, Map headers) { - return new IntegrationMessage<>(MessageBuilder.createMessage(payload, new MessageHeaders(headers))); - } - - @Override - public AccurestMessage> create(Message message) { - if (message == null) { - return null; - } - return new IntegrationMessage<>(message); - } -} diff --git a/accurest-messaging/accurest-messaging-integration/src/main/java/io/codearte/accurest/messaging/integration/AccurestIntegrationMessaging.java b/accurest-messaging/accurest-messaging-integration/src/main/java/io/codearte/accurest/messaging/integration/AccurestIntegrationMessaging.java deleted file mode 100644 index b977036e36..0000000000 --- a/accurest-messaging/accurest-messaging-integration/src/main/java/io/codearte/accurest/messaging/integration/AccurestIntegrationMessaging.java +++ /dev/null @@ -1,84 +0,0 @@ -package io.codearte.accurest.messaging.integration; - -import java.util.Map; -import java.util.concurrent.TimeUnit; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageChannel; -import org.springframework.messaging.PollableChannel; -import org.springframework.stereotype.Component; - -import io.codearte.accurest.messaging.AccurestMessage; -import io.codearte.accurest.messaging.AccurestMessageBuilder; -import io.codearte.accurest.messaging.AccurestMessaging; - -/** - * @author Marcin Grzejszczak - */ -@Component -public class AccurestIntegrationMessaging implements AccurestMessaging> { - - private static final Logger log = LoggerFactory.getLogger(AccurestIntegrationMessaging.class); - - private final ApplicationContext context; - private final AccurestMessageBuilder builder; - - @Autowired - @SuppressWarnings("unchecked") - public AccurestIntegrationMessaging(ApplicationContext context, AccurestMessageBuilder accurestMessageBuilder) { - this.context = context; - this.builder = accurestMessageBuilder; - } - - @Override - @SuppressWarnings("unchecked") - public void send(T payload, Map headers, String destination) { - send(builder.create(payload, headers), destination); - } - - @Override - public void send(AccurestMessage> message, String destination) { - try { - MessageChannel messageChannel = context.getBean(destination, MessageChannel.class); - messageChannel.send(message.convert()); - } catch (Exception e) { - log.error("Exception occurred while trying to send a message [" + message + "] " + - "to a channel with name [" + destination + "]", e); - throw e; - } - } - - @Override - @SuppressWarnings("unchecked") - public AccurestMessage> receiveMessage(String destination, long timeout, TimeUnit timeUnit) { - try { - PollableChannel messageChannel = context.getBean(destination, PollableChannel.class); - return builder.create(messageChannel.receive(timeUnit.toMillis(timeout))); - } catch (Exception e) { - log.error("Exception occurred while trying to read a message from " + - " a channel with name [" + destination + "]", e); - throw new RuntimeException(e); - } - } - - @Override - public AccurestMessage> receiveMessage(String destination) { - return receiveMessage(destination, 5, TimeUnit.SECONDS); - } - - @Override - @SuppressWarnings("unchecked") - public AccurestMessage> create(T t, Map headers) { - return builder.create(t, headers); - } - - @Override - @SuppressWarnings("unchecked") - public AccurestMessage> create(Message message) { - return builder.create(message); - } -} diff --git a/accurest-messaging/accurest-messaging-integration/src/main/java/io/codearte/accurest/messaging/integration/IntegrationMessage.java b/accurest-messaging/accurest-messaging-integration/src/main/java/io/codearte/accurest/messaging/integration/IntegrationMessage.java deleted file mode 100644 index 87b472f7dd..0000000000 --- a/accurest-messaging/accurest-messaging-integration/src/main/java/io/codearte/accurest/messaging/integration/IntegrationMessage.java +++ /dev/null @@ -1,38 +0,0 @@ -package io.codearte.accurest.messaging.integration; - -import io.codearte.accurest.messaging.AccurestMessage; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageHeaders; - -/** - * @author Marcin Grzejszczak - */ -public class IntegrationMessage implements AccurestMessage> { - - private final Message delegate; - - public IntegrationMessage(Message delegate) { - this.delegate = delegate; - } - - @Override - public T getPayload() { - return delegate.getPayload(); - } - - @Override - public MessageHeaders getHeaders() { - return delegate.getHeaders(); - } - - @Override - public Object getHeader(String key) { - return getHeaders().get(key); - } - - @Override - public Message convert() { - return delegate; - } - -} diff --git a/accurest-messaging/accurest-messaging-integration/src/main/resources/META-INF/spring.factories b/accurest-messaging/accurest-messaging-integration/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 117d34083a..0000000000 --- a/accurest-messaging/accurest-messaging-integration/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,3 +0,0 @@ -# Auto Configuration -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -io.codearte.accurest.messaging.integration.AccurestIntegrationConfiguration diff --git a/accurest-messaging/accurest-messaging-stream/build.gradle b/accurest-messaging/accurest-messaging-stream/build.gradle deleted file mode 100644 index 4f8c9c7344..0000000000 --- a/accurest-messaging/accurest-messaging-stream/build.gradle +++ /dev/null @@ -1,17 +0,0 @@ -repositories { - mavenLocal() - jcenter() - maven { - url "http://repo.spring.io/snapshot" - } - maven { - url "http://repo.spring.io/milestone" - } -} - -dependencies { - compile project(':accurest-messaging-root:accurest-messaging-core') - compile "org.springframework.cloud:spring-cloud-stream:${springStreamVersion}" - // for MessageCollector - compile "org.springframework.cloud:spring-cloud-stream-test-support:${springStreamVersion}" -} \ No newline at end of file diff --git a/accurest-messaging/accurest-messaging-stream/src/main/java/io/codearte/accurest/messaging/stream/AccurestStreamAutoConfiguration.java b/accurest-messaging/accurest-messaging-stream/src/main/java/io/codearte/accurest/messaging/stream/AccurestStreamAutoConfiguration.java deleted file mode 100644 index 243f856acb..0000000000 --- a/accurest-messaging/accurest-messaging-stream/src/main/java/io/codearte/accurest/messaging/stream/AccurestStreamAutoConfiguration.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.codearte.accurest.messaging.stream; - -import io.codearte.accurest.messaging.AccurestMessageBuilder; -import io.codearte.accurest.messaging.AccurestMessaging; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author Marcin Grzejszczak - */ -@Configuration -public class AccurestStreamAutoConfiguration { - - @Bean - AccurestMessaging accurestMessaging(ApplicationContext applicationContext, AccurestMessageBuilder accurestMessageBuilder) { - return new AccurestStreamMessaging(applicationContext, accurestMessageBuilder); - } - - @Bean - AccurestMessageBuilder accurestMessageBuilder() { - return new AccurestStreamMessageBuilder(); - } -} diff --git a/accurest-messaging/accurest-messaging-stream/src/main/java/io/codearte/accurest/messaging/stream/AccurestStreamMessageBuilder.java b/accurest-messaging/accurest-messaging-stream/src/main/java/io/codearte/accurest/messaging/stream/AccurestStreamMessageBuilder.java deleted file mode 100644 index 7f4d994e0a..0000000000 --- a/accurest-messaging/accurest-messaging-stream/src/main/java/io/codearte/accurest/messaging/stream/AccurestStreamMessageBuilder.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.codearte.accurest.messaging.stream; - -import java.util.Map; - -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageHeaders; -import org.springframework.messaging.support.MessageBuilder; - -import io.codearte.accurest.messaging.AccurestMessage; -import io.codearte.accurest.messaging.AccurestMessageBuilder; - -/** - * @author Marcin Grzejszczak - */ -public class AccurestStreamMessageBuilder implements AccurestMessageBuilder> { - - @Override - public AccurestMessage> create(T payload, Map headers) { - return new StreamMessage<>(MessageBuilder.createMessage(payload, new MessageHeaders(headers))); - } - - @Override - public AccurestMessage> create(Message message) { - if (message == null) { - return null; - } - return new StreamMessage<>(message); - } -} diff --git a/accurest-messaging/accurest-messaging-stream/src/main/java/io/codearte/accurest/messaging/stream/StreamMessage.java b/accurest-messaging/accurest-messaging-stream/src/main/java/io/codearte/accurest/messaging/stream/StreamMessage.java deleted file mode 100644 index 9f0a3ba694..0000000000 --- a/accurest-messaging/accurest-messaging-stream/src/main/java/io/codearte/accurest/messaging/stream/StreamMessage.java +++ /dev/null @@ -1,39 +0,0 @@ -package io.codearte.accurest.messaging.stream; - -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageHeaders; - -import io.codearte.accurest.messaging.AccurestMessage; - -/** - * @author Marcin Grzejszczak - */ -public class StreamMessage implements AccurestMessage> { - - private final Message delegate; - - public StreamMessage(Message delegate) { - this.delegate = delegate; - } - - @Override - public T getPayload() { - return delegate.getPayload(); - } - - @Override - public MessageHeaders getHeaders() { - return delegate.getHeaders(); - } - - @Override - public Object getHeader(String key) { - return getHeaders().get(key); - } - - @Override - public Message convert() { - return delegate; - } - -} diff --git a/accurest-messaging/accurest-messaging-stream/src/main/resources/META-INF/spring.factories b/accurest-messaging/accurest-messaging-stream/src/main/resources/META-INF/spring.factories deleted file mode 100644 index b2ba657e44..0000000000 --- a/accurest-messaging/accurest-messaging-stream/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,3 +0,0 @@ -# Auto Configuration -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -io.codearte.accurest.messaging.stream.AccurestStreamAutoConfiguration diff --git a/accurest-testing-utils/src/main/groovy/io/codearte/accurest/util/AssertionUtil.groovy b/accurest-testing-utils/src/main/groovy/io/codearte/accurest/util/AssertionUtil.groovy deleted file mode 100644 index 4c632a4de3..0000000000 --- a/accurest-testing-utils/src/main/groovy/io/codearte/accurest/util/AssertionUtil.groovy +++ /dev/null @@ -1,12 +0,0 @@ -package io.codearte.accurest.util - -import org.skyscreamer.jsonassert.JSONAssert - -class AssertionUtil { - - private static boolean NON_STRICT = false - - public static void assertThatJsonsAreEqual(String expected, String actual) { - JSONAssert.assertEquals(expected, actual, NON_STRICT) - } -} diff --git a/asciidoctor.css b/asciidoctor.css new file mode 100644 index 0000000000..06d52e688a --- /dev/null +++ b/asciidoctor.css @@ -0,0 +1,399 @@ +/* Asciidoctor default stylesheet | MIT License | http://asciidoctor.org */ +/* Remove the comments around the @import statement below when using this as a custom stylesheet */ +/*@import "https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic|Noto+Serif:400,400italic,700,700italic|Droid+Sans+Mono:400";*/ +article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block} +audio,canvas,video{display:inline-block} +audio:not([controls]){display:none;height:0} +[hidden],template{display:none} +script{display:none!important} +html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%} +body{margin:0} +a{background:transparent} +a:focus{outline:thin dotted} +a:active,a:hover{outline:0} +h1{font-size:2em;margin:.67em 0} +abbr[title]{border-bottom:1px dotted} +b,strong{font-weight:bold} +dfn{font-style:italic} +hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0} +mark{background:#ff0;color:#000} +code,kbd,pre,samp{font-family:monospace;font-size:1em} +pre{white-space:pre-wrap} +q{quotes:"\201C" "\201D" "\2018" "\2019"} +small{font-size:80%} +sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline} +sup{top:-.5em} +sub{bottom:-.25em} +img{border:0} +svg:not(:root){overflow:hidden} +figure{margin:0} +fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em} +legend{border:0;padding:0} +button,input,select,textarea{font-family:inherit;font-size:100%;margin:0} +button,input{line-height:normal} +button,select{text-transform:none} +button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer} +button[disabled],html input[disabled]{cursor:default} +input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0} +input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box} +input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none} +button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0} +textarea{overflow:auto;vertical-align:top} +table{border-collapse:collapse;border-spacing:0} +*,*:before,*:after{-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box} +html,body{font-size:100%} +body{background:#fff;color:rgba(0,0,0,.8);padding:0;margin:0;font-family:"Noto Serif","DejaVu Serif",serif;font-weight:400;font-style:normal;line-height:1;position:relative;cursor:auto} +a:hover{cursor:pointer} +img,object,embed{max-width:100%;height:auto} +object,embed{height:100%} +img{-ms-interpolation-mode:bicubic} +#map_canvas img,#map_canvas embed,#map_canvas object,.map_canvas img,.map_canvas embed,.map_canvas object{max-width:none!important} +.left{float:left!important} +.right{float:right!important} +.text-left{text-align:left!important} +.text-right{text-align:right!important} +.text-center{text-align:center!important} +.text-justify{text-align:justify!important} +.hide{display:none} +.antialiased,body{-webkit-font-smoothing:antialiased} +img{display:inline-block;vertical-align:middle} +textarea{height:auto;min-height:50px} +select{width:100%} +p.lead,.paragraph.lead>p,#preamble>.sectionbody>.paragraph:first-of-type p{font-size:1.21875em;line-height:1.6} +.subheader,.admonitionblock td.content>.title,.audioblock>.title,.exampleblock>.title,.imageblock>.title,.listingblock>.title,.literalblock>.title,.stemblock>.title,.openblock>.title,.paragraph>.title,.quoteblock>.title,table.tableblock>.title,.verseblock>.title,.videoblock>.title,.dlist>.title,.olist>.title,.ulist>.title,.qlist>.title,.hdlist>.title{line-height:1.45;color:#7a2518;font-weight:400;margin-top:0;margin-bottom:.25em} +div,dl,dt,dd,ul,ol,li,h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6,pre,form,p,blockquote,th,td{margin:0;padding:0;direction:ltr} +a{color:#2156a5;text-decoration:underline;line-height:inherit} +a:hover,a:focus{color:#1d4b8f} +a img{border:none} +p{font-family:inherit;font-weight:400;font-size:1em;line-height:1.6;margin-bottom:1.25em;text-rendering:optimizeLegibility} +p aside{font-size:.875em;line-height:1.35;font-style:italic} +h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{font-family:"Open Sans","DejaVu Sans",sans-serif;font-weight:300;font-style:normal;color:#ba3925;text-rendering:optimizeLegibility;margin-top:1em;margin-bottom:.5em;line-height:1.0125em} +h1 small,h2 small,h3 small,#toctitle small,.sidebarblock>.content>.title small,h4 small,h5 small,h6 small{font-size:60%;color:#e99b8f;line-height:0} +h1{font-size:2.125em} +h2{font-size:1.6875em} +h3,#toctitle,.sidebarblock>.content>.title{font-size:1.375em} +h4,h5{font-size:1.125em} +h6{font-size:1em} +hr{border:solid #ddddd8;border-width:1px 0 0;clear:both;margin:1.25em 0 1.1875em;height:0} +em,i{font-style:italic;line-height:inherit} +strong,b{font-weight:bold;line-height:inherit} +small{font-size:60%;line-height:inherit} +code{font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;font-weight:400;color:rgba(0,0,0,.9)} +ul,ol,dl{font-size:1em;line-height:1.6;margin-bottom:1.25em;list-style-position:outside;font-family:inherit} +ul,ol,ul.no-bullet,ol.no-bullet{margin-left:1.5em} +ul li ul,ul li ol{margin-left:1.25em;margin-bottom:0;font-size:1em} +ul.square li ul,ul.circle li ul,ul.disc li ul{list-style:inherit} +ul.square{list-style-type:square} +ul.circle{list-style-type:circle} +ul.disc{list-style-type:disc} +ul.no-bullet{list-style:none} +ol li ul,ol li ol{margin-left:1.25em;margin-bottom:0} +dl dt{margin-bottom:.3125em;font-weight:bold} +dl dd{margin-bottom:1.25em} +abbr,acronym{text-transform:uppercase;font-size:90%;color:rgba(0,0,0,.8);border-bottom:1px dotted #ddd;cursor:help} +abbr{text-transform:none} +blockquote{margin:0 0 1.25em;padding:.5625em 1.25em 0 1.1875em;border-left:1px solid #ddd} +blockquote cite{display:block;font-size:.9375em;color:rgba(0,0,0,.6)} +blockquote cite:before{content:"\2014 \0020"} +blockquote cite a,blockquote cite a:visited{color:rgba(0,0,0,.6)} +blockquote,blockquote p{line-height:1.6;color:rgba(0,0,0,.85)} +@media only screen and (min-width:768px){h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{line-height:1.2} +h1{font-size:2.75em} +h2{font-size:2.3125em} +h3,#toctitle,.sidebarblock>.content>.title{font-size:1.6875em} +h4{font-size:1.4375em}}table{background:#fff;margin-bottom:1.25em;border:solid 1px #dedede} +table thead,table tfoot{background:#f7f8f7;font-weight:bold} +table thead tr th,table thead tr td,table tfoot tr th,table tfoot tr td{padding:.5em .625em .625em;font-size:inherit;color:rgba(0,0,0,.8);text-align:left} +table tr th,table tr td{padding:.5625em .625em;font-size:inherit;color:rgba(0,0,0,.8)} +table tr.even,table tr.alt,table tr:nth-of-type(even){background:#f8f8f7} +table thead tr th,table tfoot tr th,table tbody tr td,table tr td,table tfoot tr td{display:table-cell;line-height:1.6} +h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{line-height:1.2;word-spacing:-.05em} +h1 strong,h2 strong,h3 strong,#toctitle strong,.sidebarblock>.content>.title strong,h4 strong,h5 strong,h6 strong{font-weight:400} +.clearfix:before,.clearfix:after,.float-group:before,.float-group:after{content:" ";display:table} +.clearfix:after,.float-group:after{clear:both} +*:not(pre)>code{font-size:.9375em;font-style:normal!important;letter-spacing:0;padding:.1em .5ex;word-spacing:-.15em;background-color:#f7f7f8;-webkit-border-radius:4px;border-radius:4px;line-height:1.45;text-rendering:optimizeSpeed} +pre,pre>code{line-height:1.45;color:rgba(0,0,0,.9);font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;font-weight:400;text-rendering:optimizeSpeed} +.keyseq{color:rgba(51,51,51,.8)} +kbd{display:inline-block;color:rgba(0,0,0,.8);font-size:.75em;line-height:1.4;background-color:#f7f7f7;border:1px solid #ccc;-webkit-border-radius:3px;border-radius:3px;-webkit-box-shadow:0 1px 0 rgba(0,0,0,.2),0 0 0 .1em white inset;box-shadow:0 1px 0 rgba(0,0,0,.2),0 0 0 .1em #fff inset;margin:-.15em .15em 0 .15em;padding:.2em .6em .2em .5em;vertical-align:middle;white-space:nowrap} +.keyseq kbd:first-child{margin-left:0} +.keyseq kbd:last-child{margin-right:0} +.menuseq,.menu{color:rgba(0,0,0,.8)} +b.button:before,b.button:after{position:relative;top:-1px;font-weight:400} +b.button:before{content:"[";padding:0 3px 0 2px} +b.button:after{content:"]";padding:0 2px 0 3px} +p a>code:hover{color:rgba(0,0,0,.9)} +#header,#content,#footnotes,#footer{width:100%;margin-left:auto;margin-right:auto;margin-top:0;margin-bottom:0;max-width:62.5em;*zoom:1;position:relative;padding-left:.9375em;padding-right:.9375em} +#header:before,#header:after,#content:before,#content:after,#footnotes:before,#footnotes:after,#footer:before,#footer:after{content:" ";display:table} +#header:after,#content:after,#footnotes:after,#footer:after{clear:both} +#content{margin-top:1.25em} +#content:before{content:none} +#header>h1:first-child{color:rgba(0,0,0,.85);margin-top:2.25rem;margin-bottom:0} +#header>h1:first-child+#toc{margin-top:8px;border-top:1px solid #ddddd8} +#header>h1:only-child,body.toc2 #header>h1:nth-last-child(2){border-bottom:1px solid #ddddd8;padding-bottom:8px} +#header .details{border-bottom:1px solid #ddddd8;line-height:1.45;padding-top:.25em;padding-bottom:.25em;padding-left:.25em;color:rgba(0,0,0,.6);display:-ms-flexbox;display:-webkit-flex;display:flex;-ms-flex-flow:row wrap;-webkit-flex-flow:row wrap;flex-flow:row wrap} +#header .details span:first-child{margin-left:-.125em} +#header .details span.email a{color:rgba(0,0,0,.85)} +#header .details br{display:none} +#header .details br+span:before{content:"\00a0\2013\00a0"} +#header .details br+span.author:before{content:"\00a0\22c5\00a0";color:rgba(0,0,0,.85)} +#header .details br+span#revremark:before{content:"\00a0|\00a0"} +#header #revnumber{text-transform:capitalize} +#header #revnumber:after{content:"\00a0"} +#content>h1:first-child:not([class]){color:rgba(0,0,0,.85);border-bottom:1px solid #ddddd8;padding-bottom:8px;margin-top:0;padding-top:1rem;margin-bottom:1.25rem} +#toc{border-bottom:1px solid #efefed;padding-bottom:.5em} +#toc>ul{margin-left:.125em} +#toc ul.sectlevel0>li>a{font-style:italic} +#toc ul.sectlevel0 ul.sectlevel1{margin:.5em 0} +#toc ul{font-family:"Open Sans","DejaVu Sans",sans-serif;list-style-type:none} +#toc a{text-decoration:none} +#toc a:active{text-decoration:underline} +#toctitle{color:#7a2518;font-size:1.2em} +@media only screen and (min-width:768px){#toctitle{font-size:1.375em} +body.toc2{padding-left:15em;padding-right:0} +#toc.toc2{margin-top:0!important;background-color:#f8f8f7;position:fixed;width:15em;left:0;top:0;border-right:1px solid #efefed;border-top-width:0!important;border-bottom-width:0!important;z-index:1000;padding:1.25em 1em;height:100%;overflow:auto} +#toc.toc2 #toctitle{margin-top:0;font-size:1.2em} +#toc.toc2>ul{font-size:.9em;margin-bottom:0} +#toc.toc2 ul ul{margin-left:0;padding-left:1em} +#toc.toc2 ul.sectlevel0 ul.sectlevel1{padding-left:0;margin-top:.5em;margin-bottom:.5em} +body.toc2.toc-right{padding-left:0;padding-right:15em} +body.toc2.toc-right #toc.toc2{border-right-width:0;border-left:1px solid #efefed;left:auto;right:0}}@media only screen and (min-width:1280px){body.toc2{padding-left:20em;padding-right:0} +#toc.toc2{width:20em} +#toc.toc2 #toctitle{font-size:1.375em} +#toc.toc2>ul{font-size:.95em} +#toc.toc2 ul ul{padding-left:1.25em} +body.toc2.toc-right{padding-left:0;padding-right:20em}}#content #toc{border-style:solid;border-width:1px;border-color:#e0e0dc;margin-bottom:1.25em;padding:1.25em;background:#f8f8f7;-webkit-border-radius:4px;border-radius:4px} +#content #toc>:first-child{margin-top:0} +#content #toc>:last-child{margin-bottom:0} +#footer{max-width:100%;background-color:rgba(0,0,0,.8);padding:1.25em} +#footer-text{color:rgba(255,255,255,.8);line-height:1.44} +.sect1{padding-bottom:.625em} +@media only screen and (min-width:768px){.sect1{padding-bottom:1.25em}}.sect1+.sect1{border-top:1px solid #efefed} +#content h1>a.anchor,h2>a.anchor,h3>a.anchor,#toctitle>a.anchor,.sidebarblock>.content>.title>a.anchor,h4>a.anchor,h5>a.anchor,h6>a.anchor{position:absolute;z-index:1001;width:1.5ex;margin-left:-1.5ex;display:block;text-decoration:none!important;visibility:hidden;text-align:center;font-weight:400} +#content h1>a.anchor:before,h2>a.anchor:before,h3>a.anchor:before,#toctitle>a.anchor:before,.sidebarblock>.content>.title>a.anchor:before,h4>a.anchor:before,h5>a.anchor:before,h6>a.anchor:before{content:"\00A7";font-size:.85em;display:block;padding-top:.1em} +#content h1:hover>a.anchor,#content h1>a.anchor:hover,h2:hover>a.anchor,h2>a.anchor:hover,h3:hover>a.anchor,#toctitle:hover>a.anchor,.sidebarblock>.content>.title:hover>a.anchor,h3>a.anchor:hover,#toctitle>a.anchor:hover,.sidebarblock>.content>.title>a.anchor:hover,h4:hover>a.anchor,h4>a.anchor:hover,h5:hover>a.anchor,h5>a.anchor:hover,h6:hover>a.anchor,h6>a.anchor:hover{visibility:visible} +#content h1>a.link,h2>a.link,h3>a.link,#toctitle>a.link,.sidebarblock>.content>.title>a.link,h4>a.link,h5>a.link,h6>a.link{color:#ba3925;text-decoration:none} +#content h1>a.link:hover,h2>a.link:hover,h3>a.link:hover,#toctitle>a.link:hover,.sidebarblock>.content>.title>a.link:hover,h4>a.link:hover,h5>a.link:hover,h6>a.link:hover{color:#a53221} +.audioblock,.imageblock,.literalblock,.listingblock,.stemblock,.videoblock{margin-bottom:1.25em} +.admonitionblock td.content>.title,.audioblock>.title,.exampleblock>.title,.imageblock>.title,.listingblock>.title,.literalblock>.title,.stemblock>.title,.openblock>.title,.paragraph>.title,.quoteblock>.title,table.tableblock>.title,.verseblock>.title,.videoblock>.title,.dlist>.title,.olist>.title,.ulist>.title,.qlist>.title,.hdlist>.title{text-rendering:optimizeLegibility;text-align:left;font-family:"Noto Serif","DejaVu Serif",serif;font-size:1rem;font-style:italic} +table.tableblock>caption.title{white-space:nowrap;overflow:visible;max-width:0} +.paragraph.lead>p,#preamble>.sectionbody>.paragraph:first-of-type p{color:rgba(0,0,0,.85)} +table.tableblock #preamble>.sectionbody>.paragraph:first-of-type p{font-size:inherit} +.admonitionblock>table{border-collapse:separate;border:0;background:none;width:100%} +.admonitionblock>table td.icon{text-align:center;width:80px} +.admonitionblock>table td.icon img{max-width:none} +.admonitionblock>table td.icon .title{font-weight:bold;font-family:"Open Sans","DejaVu Sans",sans-serif;text-transform:uppercase} +.admonitionblock>table td.content{padding-left:1.125em;padding-right:1.25em;border-left:1px solid #ddddd8;color:rgba(0,0,0,.6)} +.admonitionblock>table td.content>:last-child>:last-child{margin-bottom:0} +.exampleblock>.content{border-style:solid;border-width:1px;border-color:#e6e6e6;margin-bottom:1.25em;padding:1.25em;background:#fff;-webkit-border-radius:4px;border-radius:4px} +.exampleblock>.content>:first-child{margin-top:0} +.exampleblock>.content>:last-child{margin-bottom:0} +.sidebarblock{border-style:solid;border-width:1px;border-color:#e0e0dc;margin-bottom:1.25em;padding:1.25em;background:#f8f8f7;-webkit-border-radius:4px;border-radius:4px} +.sidebarblock>:first-child{margin-top:0} +.sidebarblock>:last-child{margin-bottom:0} +.sidebarblock>.content>.title{color:#7a2518;margin-top:0;text-align:center} +.exampleblock>.content>:last-child>:last-child,.exampleblock>.content .olist>ol>li:last-child>:last-child,.exampleblock>.content .ulist>ul>li:last-child>:last-child,.exampleblock>.content .qlist>ol>li:last-child>:last-child,.sidebarblock>.content>:last-child>:last-child,.sidebarblock>.content .olist>ol>li:last-child>:last-child,.sidebarblock>.content .ulist>ul>li:last-child>:last-child,.sidebarblock>.content .qlist>ol>li:last-child>:last-child{margin-bottom:0} +.literalblock pre,.listingblock pre:not(.highlight),.listingblock pre[class="highlight"],.listingblock pre[class^="highlight "],.listingblock pre.CodeRay,.listingblock pre.prettyprint{background:#f7f7f8} +.sidebarblock .literalblock pre,.sidebarblock .listingblock pre:not(.highlight),.sidebarblock .listingblock pre[class="highlight"],.sidebarblock .listingblock pre[class^="highlight "],.sidebarblock .listingblock pre.CodeRay,.sidebarblock .listingblock pre.prettyprint{background:#f2f1f1} +.literalblock pre,.literalblock pre[class],.listingblock pre,.listingblock pre[class]{-webkit-border-radius:4px;border-radius:4px;word-wrap:break-word;padding:1em;font-size:.8125em} +.literalblock pre.nowrap,.literalblock pre[class].nowrap,.listingblock pre.nowrap,.listingblock pre[class].nowrap{overflow-x:auto;white-space:pre;word-wrap:normal} +@media only screen and (min-width:768px){.literalblock pre,.literalblock pre[class],.listingblock pre,.listingblock pre[class]{font-size:.90625em}}@media only screen and (min-width:1280px){.literalblock pre,.literalblock pre[class],.listingblock pre,.listingblock pre[class]{font-size:1em}}.literalblock.output pre{color:#f7f7f8;background-color:rgba(0,0,0,.9)} +.listingblock pre.highlightjs{padding:0} +.listingblock pre.highlightjs>code{padding:1em;-webkit-border-radius:4px;border-radius:4px} +.listingblock pre.prettyprint{border-width:0} +.listingblock>.content{position:relative} +.listingblock code[data-lang]:before{display:none;content:attr(data-lang);position:absolute;font-size:.75em;top:.425rem;right:.5rem;line-height:1;text-transform:uppercase;color:#999} +.listingblock:hover code[data-lang]:before{display:block} +.listingblock.terminal pre .command:before{content:attr(data-prompt);padding-right:.5em;color:#999} +.listingblock.terminal pre .command:not([data-prompt]):before{content:"$"} +table.pyhltable{border-collapse:separate;border:0;margin-bottom:0;background:none} +table.pyhltable td{vertical-align:top;padding-top:0;padding-bottom:0} +table.pyhltable td.code{padding-left:.75em;padding-right:0} +pre.pygments .lineno,table.pyhltable td:not(.code){color:#999;padding-left:0;padding-right:.5em;border-right:1px solid #ddddd8} +pre.pygments .lineno{display:inline-block;margin-right:.25em} +table.pyhltable .linenodiv{background:none!important;padding-right:0!important} +.quoteblock{margin:0 1em 1.25em 1.5em;display:table} +.quoteblock>.title{margin-left:-1.5em;margin-bottom:.75em} +.quoteblock blockquote,.quoteblock blockquote p{color:rgba(0,0,0,.85);font-size:1.15rem;line-height:1.75;word-spacing:.1em;letter-spacing:0;font-style:italic;text-align:justify} +.quoteblock blockquote{margin:0;padding:0;border:0} +.quoteblock blockquote:before{content:"\201c";float:left;font-size:2.75em;font-weight:bold;line-height:.6em;margin-left:-.6em;color:#7a2518;text-shadow:0 1px 2px rgba(0,0,0,.1)} +.quoteblock blockquote>.paragraph:last-child p{margin-bottom:0} +.quoteblock .attribution{margin-top:.5em;margin-right:.5ex;text-align:right} +.quoteblock .quoteblock{margin-left:0;margin-right:0;padding:.5em 0;border-left:3px solid rgba(0,0,0,.6)} +.quoteblock .quoteblock blockquote{padding:0 0 0 .75em} +.quoteblock .quoteblock blockquote:before{display:none} +.verseblock{margin:0 1em 1.25em 1em} +.verseblock pre{font-family:"Open Sans","DejaVu Sans",sans;font-size:1.15rem;color:rgba(0,0,0,.85);font-weight:300;text-rendering:optimizeLegibility} +.verseblock pre strong{font-weight:400} +.verseblock .attribution{margin-top:1.25rem;margin-left:.5ex} +.quoteblock .attribution,.verseblock .attribution{font-size:.9375em;line-height:1.45;font-style:italic} +.quoteblock .attribution br,.verseblock .attribution br{display:none} +.quoteblock .attribution cite,.verseblock .attribution cite{display:block;letter-spacing:-.05em;color:rgba(0,0,0,.6)} +.quoteblock.abstract{margin:0 0 1.25em 0;display:block} +.quoteblock.abstract blockquote,.quoteblock.abstract blockquote p{text-align:left;word-spacing:0} +.quoteblock.abstract blockquote:before,.quoteblock.abstract blockquote p:first-of-type:before{display:none} +table.tableblock{max-width:100%;border-collapse:separate} +table.tableblock td>.paragraph:last-child p>p:last-child,table.tableblock th>p:last-child,table.tableblock td>p:last-child{margin-bottom:0} +table.spread{width:100%} +table.tableblock,th.tableblock,td.tableblock{border:0 solid #dedede} +table.grid-all th.tableblock,table.grid-all td.tableblock{border-width:0 1px 1px 0} +table.grid-all tfoot>tr>th.tableblock,table.grid-all tfoot>tr>td.tableblock{border-width:1px 1px 0 0} +table.grid-cols th.tableblock,table.grid-cols td.tableblock{border-width:0 1px 0 0} +table.grid-all *>tr>.tableblock:last-child,table.grid-cols *>tr>.tableblock:last-child{border-right-width:0} +table.grid-rows th.tableblock,table.grid-rows td.tableblock{border-width:0 0 1px 0} +table.grid-all tbody>tr:last-child>th.tableblock,table.grid-all tbody>tr:last-child>td.tableblock,table.grid-all thead:last-child>tr>th.tableblock,table.grid-rows tbody>tr:last-child>th.tableblock,table.grid-rows tbody>tr:last-child>td.tableblock,table.grid-rows thead:last-child>tr>th.tableblock{border-bottom-width:0} +table.grid-rows tfoot>tr>th.tableblock,table.grid-rows tfoot>tr>td.tableblock{border-width:1px 0 0 0} +table.frame-all{border-width:1px} +table.frame-sides{border-width:0 1px} +table.frame-topbot{border-width:1px 0} +th.halign-left,td.halign-left{text-align:left} +th.halign-right,td.halign-right{text-align:right} +th.halign-center,td.halign-center{text-align:center} +th.valign-top,td.valign-top{vertical-align:top} +th.valign-bottom,td.valign-bottom{vertical-align:bottom} +th.valign-middle,td.valign-middle{vertical-align:middle} +table thead th,table tfoot th{font-weight:bold} +tbody tr th{display:table-cell;line-height:1.6;background:#f7f8f7} +tbody tr th,tbody tr th p,tfoot tr th,tfoot tr th p{color:rgba(0,0,0,.8);font-weight:bold} +p.tableblock>code:only-child{background:none;padding:0} +p.tableblock{font-size:1em} +td>div.verse{white-space:pre} +ol{margin-left:1.75em} +ul li ol{margin-left:1.5em} +dl dd{margin-left:1.125em} +dl dd:last-child,dl dd:last-child>:last-child{margin-bottom:0} +ol>li p,ul>li p,ul dd,ol dd,.olist .olist,.ulist .ulist,.ulist .olist,.olist .ulist{margin-bottom:.625em} +ul.unstyled,ol.unnumbered,ul.checklist,ul.none{list-style-type:none} +ul.unstyled,ol.unnumbered,ul.checklist{margin-left:.625em} +ul.checklist li>p:first-child>.fa-check-square-o:first-child,ul.checklist li>p:first-child>input[type="checkbox"]:first-child{margin-right:.25em} +ul.checklist li>p:first-child>input[type="checkbox"]:first-child{position:relative;top:1px} +ul.inline{margin:0 auto .625em auto;margin-left:-1.375em;margin-right:0;padding:0;list-style:none;overflow:hidden} +ul.inline>li{list-style:none;float:left;margin-left:1.375em;display:block} +ul.inline>li>*{display:block} +.unstyled dl dt{font-weight:400;font-style:normal} +ol.arabic{list-style-type:decimal} +ol.decimal{list-style-type:decimal-leading-zero} +ol.loweralpha{list-style-type:lower-alpha} +ol.upperalpha{list-style-type:upper-alpha} +ol.lowerroman{list-style-type:lower-roman} +ol.upperroman{list-style-type:upper-roman} +ol.lowergreek{list-style-type:lower-greek} +.hdlist>table,.colist>table{border:0;background:none} +.hdlist>table>tbody>tr,.colist>table>tbody>tr{background:none} +td.hdlist1{padding-right:.75em;font-weight:bold} +td.hdlist1,td.hdlist2{vertical-align:top} +.literalblock+.colist,.listingblock+.colist{margin-top:-.5em} +.colist>table tr>td:first-of-type{padding:0 .75em;line-height:1} +.colist>table tr>td:last-of-type{padding:.25em 0} +.thumb,.th{line-height:0;display:inline-block;border:solid 4px #fff;-webkit-box-shadow:0 0 0 1px #ddd;box-shadow:0 0 0 1px #ddd} +.imageblock.left,.imageblock[style*="float: left"]{margin:.25em .625em 1.25em 0} +.imageblock.right,.imageblock[style*="float: right"]{margin:.25em 0 1.25em .625em} +.imageblock>.title{margin-bottom:0} +.imageblock.thumb,.imageblock.th{border-width:6px} +.imageblock.thumb>.title,.imageblock.th>.title{padding:0 .125em} +.image.left,.image.right{margin-top:.25em;margin-bottom:.25em;display:inline-block;line-height:0} +.image.left{margin-right:.625em} +.image.right{margin-left:.625em} +a.image{text-decoration:none} +span.footnote,span.footnoteref{vertical-align:super;font-size:.875em} +span.footnote a,span.footnoteref a{text-decoration:none} +span.footnote a:active,span.footnoteref a:active{text-decoration:underline} +#footnotes{padding-top:.75em;padding-bottom:.75em;margin-bottom:.625em} +#footnotes hr{width:20%;min-width:6.25em;margin:-.25em 0 .75em 0;border-width:1px 0 0 0} +#footnotes .footnote{padding:0 .375em;line-height:1.3;font-size:.875em;margin-left:1.2em;text-indent:-1.2em;margin-bottom:.2em} +#footnotes .footnote a:first-of-type{font-weight:bold;text-decoration:none} +#footnotes .footnote:last-of-type{margin-bottom:0} +#content #footnotes{margin-top:-.625em;margin-bottom:0;padding:.75em 0} +.gist .file-data>table{border:0;background:#fff;width:100%;margin-bottom:0} +.gist .file-data>table td.line-data{width:99%} +div.unbreakable{page-break-inside:avoid} +.big{font-size:larger} +.small{font-size:smaller} +.underline{text-decoration:underline} +.overline{text-decoration:overline} +.line-through{text-decoration:line-through} +.aqua{color:#00bfbf} +.aqua-background{background-color:#00fafa} +.black{color:#000} +.black-background{background-color:#000} +.blue{color:#0000bf} +.blue-background{background-color:#0000fa} +.fuchsia{color:#bf00bf} +.fuchsia-background{background-color:#fa00fa} +.gray{color:#606060} +.gray-background{background-color:#7d7d7d} +.green{color:#006000} +.green-background{background-color:#007d00} +.lime{color:#00bf00} +.lime-background{background-color:#00fa00} +.maroon{color:#600000} +.maroon-background{background-color:#7d0000} +.navy{color:#000060} +.navy-background{background-color:#00007d} +.olive{color:#606000} +.olive-background{background-color:#7d7d00} +.purple{color:#600060} +.purple-background{background-color:#7d007d} +.red{color:#bf0000} +.red-background{background-color:#fa0000} +.silver{color:#909090} +.silver-background{background-color:#bcbcbc} +.teal{color:#006060} +.teal-background{background-color:#007d7d} +.white{color:#bfbfbf} +.white-background{background-color:#fafafa} +.yellow{color:#bfbf00} +.yellow-background{background-color:#fafa00} +span.icon>.fa{cursor:default} +.admonitionblock td.icon [class^="fa icon-"]{font-size:2.5em;text-shadow:1px 1px 2px rgba(0,0,0,.5);cursor:default} +.admonitionblock td.icon .icon-note:before{content:"\f05a";color:#19407c} +.admonitionblock td.icon .icon-tip:before{content:"\f0eb";text-shadow:1px 1px 2px rgba(155,155,0,.8);color:#111} +.admonitionblock td.icon .icon-warning:before{content:"\f071";color:#bf6900} +.admonitionblock td.icon .icon-caution:before{content:"\f06d";color:#bf3400} +.admonitionblock td.icon .icon-important:before{content:"\f06a";color:#bf0000} +.conum[data-value]{display:inline-block;color:#fff!important;background-color:rgba(0,0,0,.8);-webkit-border-radius:100px;border-radius:100px;text-align:center;font-size:.75em;width:1.67em;height:1.67em;line-height:1.67em;font-family:"Open Sans","DejaVu Sans",sans-serif;font-style:normal;font-weight:bold} +.conum[data-value] *{color:#fff!important} +.conum[data-value]+b{display:none} +.conum[data-value]:after{content:attr(data-value)} +pre .conum[data-value]{position:relative;top:-.125em} +b.conum *{color:inherit!important} +.conum:not([data-value]):empty{display:none} +h1,h2{letter-spacing:-.01em} +dt,th.tableblock,td.content{text-rendering:optimizeLegibility} +p,td.content{letter-spacing:-.01em} +p strong,td.content strong{letter-spacing:-.005em} +p,blockquote,dt,td.content{font-size:1.0625rem} +p{margin-bottom:1.25rem} +.sidebarblock p,.sidebarblock dt,.sidebarblock td.content,p.tableblock{font-size:1em} +.exampleblock>.content{background-color:#fffef7;border-color:#e0e0dc;-webkit-box-shadow:0 1px 4px #e0e0dc;box-shadow:0 1px 4px #e0e0dc} +.print-only{display:none!important} +@media print{@page{margin:1.25cm .75cm} +*{-webkit-box-shadow:none!important;box-shadow:none!important;text-shadow:none!important} +a{color:inherit!important;text-decoration:underline!important} +a.bare,a[href^="#"],a[href^="mailto:"]{text-decoration:none!important} +a[href^="http:"]:not(.bare):after,a[href^="https:"]:not(.bare):after{content:"(" attr(href) ")";display:inline-block;font-size:.875em;padding-left:.25em} +abbr[title]:after{content:" (" attr(title) ")"} +pre,blockquote,tr,img{page-break-inside:avoid} +thead{display:table-header-group} +img{max-width:100%!important} +p,blockquote,dt,td.content{font-size:1em;orphans:3;widows:3} +h2,h3,#toctitle,.sidebarblock>.content>.title{page-break-after:avoid} +#toc,.sidebarblock,.exampleblock>.content{background:none!important} +#toc{border-bottom:1px solid #ddddd8!important;padding-bottom:0!important} +.sect1{padding-bottom:0!important} +.sect1+.sect1{border:0!important} +#header>h1:first-child{margin-top:1.25rem} +body.book #header{text-align:center} +body.book #header>h1:first-child{border:0!important;margin:2.5em 0 1em 0} +body.book #header .details{border:0!important;display:block;padding:0!important} +body.book #header .details span:first-child{margin-left:0!important} +body.book #header .details br{display:block} +body.book #header .details br+span:before{content:none!important} +body.book #toc{border:0!important;text-align:left!important;padding:0!important;margin:0!important} +body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-break-before:always} +.listingblock code[data-lang]:before{display:block} +#footer{background:none!important;padding:0 .9375em} +#footer-text{color:rgba(0,0,0,.6)!important;font-size:.9em} +.hide-on-print{display:none!important} +.print-only{display:block!important} +.hide-for-print{display:none!important} +.show-for-print{display:inherit!important}} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 53eb33d85b..a59ec6dd9b 100644 --- a/build.gradle +++ b/build.gradle @@ -2,47 +2,31 @@ buildscript { repositories { mavenCentral() mavenLocal() + maven { url 'https://repo.spring.io/plugins-release' } if (project.hasProperty('fatJar')) jcenter() } dependencies { - classpath "pl.allegro.tech.build:axion-release-plugin:1.3.2" classpath "com.bmuschko:gradle-nexus-plugin:2.3" classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.5.3" if (project.hasProperty('fatJar')) classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3' } } -apply plugin: "pl.allegro.tech.build.axion-release" - -scmVersion { - tag { prefix = "accurest" } - createReleaseCommit = true - releaseCommitMessage { version, position -> "Release version: ${version}\n\n[ci skip]" } - hooks { - pre "fileUpdate", [file : "README.md", - pattern : { v, p -> /'io\.codearte\.accurest:accurest-gradle-plugin:.*'/ }, - replacement: { v, p -> "'io.codearte.accurest:accurest-gradle-plugin:$v'" }] - } +ext { + repoUser = project.findProperty('REPO_USERNAME') ?: '' + repoPass = project.findProperty('REPO_PASSWORD') ?: '' + projectsToSkipPublication = ['parent', 'samples', 'docs', 'root'] } allprojects { - project.version = scmVersion.version + project.version = findProperty('contractVerifierVersion') ?: '1.0.0.BUILD-SNAPSHOT' + apply from: "$rootDir/gradle/release.gradle" } -apply plugin: 'io.codearte.nexus-staging' - -nexusStaging { - packageGroup = "io.codearte" - stagingProfileId = '93c08fdebde1ff' -} - -apply from: "$rootDir/gradle/releaseRoot.gradle" - subprojects { apply plugin: 'groovy' - apply from: "$rootDir/gradle/release.gradle" - group = 'io.codearte.accurest' + group = 'org.springframework.cloud.contract' sourceCompatibility = 1.7 targetCompatibility = 1.7 @@ -51,9 +35,10 @@ subprojects { mavenLocal() mavenCentral() jcenter() - maven { - url "http://repo.spring.io/milestone" - } + maven { url "http://repo.spring.io/snapshot" } + maven { url "http://repo.spring.io/milestone" } + maven { url "http://repo.spring.io/libs-release-local" } + maven { url "http://repo.spring.io/libs-staging-local/" } } //Dependencies in all subprojects - http://solidsoft.wordpress.com/2014/11/13/gradle-tricks-display-dependencies-for-all-subprojects-in-multi-project-build/ @@ -87,106 +72,6 @@ subprojects { } } -project(':accurest-core') { - - dependencies { - compile 'org.slf4j:slf4j-api:1.6.0' - compile 'commons-io:commons-io:2.0' - compile 'org.apache.commons:commons-lang3:3.3' - compile "com.github.tomakehurst:wiremock:$wiremockVersion" - compile "com.toomuchcoding.jsonassert:jsonassert:$jsonassertVersion" - compile 'org.codehaus.groovy:groovy-all:2.4.4' - testCompile 'cglib:cglib-nodep:2.2' - testCompile 'org.objenesis:objenesis:2.1' - testCompile project(':accurest-testing-utils') - } - -} - -project(':accurest-testing-utils') { - - dependencies { - compile 'org.skyscreamer:jsonassert:1.2.3' - } - -} - -project(':accurest-converters') { - dependencies { - compile project(':accurest-core') - compile 'org.apache.commons:commons-lang3:3.0' - compile 'commons-io:commons-io:2.0' - compile 'dk.brics.automaton:automaton:1.11-8' // needed for Xeger - testCompile "com.github.tomakehurst:wiremock:$wiremockVersion" - testCompile 'org.hamcrest:hamcrest-all:1.3' - } -} - -project(':accurest-gradle-plugin') { - - ext.messagingLibsDir ="$buildDir/messaging-libs" - ext.accurestGradlePluginLibsDir ="$buildDir/accurest-gradle-plugin-libs" - - ext.testSystemProperties = [ - 'accurest-gradle-plugin-libs-dir': accurestGradlePluginLibsDir, - 'messaging-libs-dir': messagingLibsDir - ] - - dependencies { - compile project(':accurest-core') - compile project(':accurest-converters') - compile gradleApi() - - testCompile gradleTestKit() - testCompile project(':accurest-testing-utils') - } - - configurations { - messagingLibs - accurestGradlePluginLibs - } - - dependencies { - messagingLibs project(':accurest-messaging-root:accurest-messaging-integration') - messagingLibs project(':accurest-messaging-root:accurest-messaging-core') - messagingLibs project(':accurest-testing-utils') - messagingLibs 'org.codehaus.groovy:groovy-all:2.4.5' - - accurestGradlePluginLibs project(':accurest-gradle-plugin') - } - - test { - exclude '**/*FunctionalSpec.*' - systemProperties = testSystemProperties - } - task funcTest(type: Test) { - include '**/*FunctionalSpec.*' - systemProperties = testSystemProperties - reports.html { - destination = file("${reporting.baseDir}/funcTests") - } - } - - task archiveMessagingLibsDependencies(type: Sync) { - from configurations.messagingLibs.resolvedConfiguration.resolvedArtifacts.collect { it.file } - into messagingLibsDir - } - - task archiveAccurestGradlePluginLibsDependencies(type: Sync) { - from configurations.accurestGradlePluginLibs.resolvedConfiguration.resolvedArtifacts.collect { it.file } - into accurestGradlePluginLibsDir - } - - // archive task needs to have jars ready - archiveMessagingLibsDependencies.dependsOn project(':accurest-messaging-root:accurest-messaging-integration').tasks.jar - archiveAccurestGradlePluginLibsDependencies.dependsOn project(':accurest-gradle-plugin').tasks.jar - - test.dependsOn archiveMessagingLibsDependencies, archiveAccurestGradlePluginLibsDependencies - funcTest.dependsOn archiveMessagingLibsDependencies, archiveAccurestGradlePluginLibsDependencies - - uploadArchives.dependsOn { funcTest } -} - configurations { all { resolutionStrategy { @@ -201,17 +86,3 @@ configurations { } } -// REMOVE AFTER https://issues.gradle.org/browse/GRADLE-3433 IS FIXED -buildscript { - repositories { - maven { - url "https://plugins.gradle.org/m2/" - } - } - dependencies { - classpath "gradle.plugin.com.palantir.ideatestfix:gradle-idea-test-fix:0.1.0" - } -} - -apply plugin: "com.palantir.idea-test-fix" - diff --git a/docs/build.gradle b/docs/build.gradle index 49f23f96d9..36a6fbf2b8 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -1,14 +1,53 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + plugins { id 'org.ajoberstar.github-pages' version '1.1.0' id 'org.asciidoctor.gradle.asciidoctor' version '1.5.1' id 'org.asciidoctor.convert' version '1.5.3' + id 'com.github.jruby-gradle.base' version '1.2.1' +} + + +apply plugin: 'org.asciidoctor.gradle.asciidoctor' +apply plugin: 'com.github.jruby-gradle.base' + +dependencies { + gems group: 'rubygems', name: 'asciidoctor', version: '1.5.3' } asciidoctorj { version = '1.5.4' } +task generateReadme(type: com.github.jrubygradle.JRubyExec) { + dependsOn jrubyPrepare + + description "Generates an output README.adoc" + script "${projectDir}/src/main/ruby/generate_readme.sh" + scriptArgs "-o${new File(project.rootDir, 'README.adoc')}" + gemWorkDir jrubyPrepare.outputDir +} + asciidoctor { + dependsOn jrubyPrepare + + sourceDir 'src/main/asciidoc' + setSourceDocumentName file('spring-cloud-contract-verifier.adoc') + backends 'html' attributes 'build-gradle': file('build.gradle'), 'endpoint-url': 'https://Codearte.github.io/accurest', 'source-highlighter': 'coderay', @@ -18,9 +57,13 @@ asciidoctor { 'setanchors': 'true', 'idprefix': '', 'idseparator': '-', - 'docinfo1': 'true' + 'docinfo1': 'true', + 'doctype' : 'article' + + gemPath = jrubyPrepare.outputDir } +generateReadme.dependsOn asciidoctor publishGhPages.dependsOn asciidoctor githubPages { diff --git a/docs/src/docs/asciidoc/index.adoc b/docs/src/docs/asciidoc/index.adoc deleted file mode 100644 index 3e3dc3a980..0000000000 --- a/docs/src/docs/asciidoc/index.adoc +++ /dev/null @@ -1,19 +0,0 @@ -:messaging_version: 1.1.0 - -= Accurest - -_Adam Dudczak, Marcin Grzejszczak, Jakub KubryƄski, Karol Lassak, Olga Maciaszek-Sharma, Mariusz SmykuƂa_ - -include::introduction.adoc[] - -include::contract.adoc[] - -include::rest.adoc[] - -include::messaging.adoc[] - -include::stubrunner.adoc[] - -include::stubrunner_msg.adoc[] - -include::migration.adoc[] \ No newline at end of file diff --git a/docs/src/docs/asciidoc/messaging.adoc b/docs/src/docs/asciidoc/messaging.adoc deleted file mode 100644 index d6946f16ae..0000000000 --- a/docs/src/docs/asciidoc/messaging.adoc +++ /dev/null @@ -1,148 +0,0 @@ -== Accurest Messaging - -WARNING: Feature available since {messaging_version} - -Accurest allows you to verify your application that uses messaging as means of communication. -All of our integrations are working with Spring but you can also set one yourself. - -=== Integrations - -You can use one of the three integration configurations: - -- Apache Camel -- Spring Integration -- Spring Cloud Stream - -If you're using Spring Boot, the aforementioned test configurations will be appended automatically. - -You have to provide as a dependency one of the Accurest Messaging modules. Example for Gradle: - -[source,groovy,indent=0] ----- -// for Apache Camel -testCompile "io.codearte.accurest:accurest-messaging-camel:${accurestVersion}" -// for Spring Integration -testCompile "io.codearte.accurest:accurest-messaging-integration:${accurestVersion}" -// for Spring Cloud Stream -testCompile "io.codearte.accurest:accurest-messaging-stream:${accurestVersion}" ----- - -=== Manual Integration - -The `accurest-messaging-core` module contains 3 main interfaces: - -- `AccurestMessage` - describes a message received / sent to a channel / queue / topic etc. -- `AccurestMessageBuilder` - describes how to build a message -- `AccurestMessaging` - class that allows you to build, send and receive messages -- `AccurestFilter` - interface to filter out the messages that do not follow the pattern from the DSL - -In the generated test the `AccurestMessaging` is injected via `@Inject` annotation thus you can use other injection -frameworks than Spring. - -You have to provide as a dependency the `accurest-messaging-core` module. Example for Gradle: - -[source,groovy,indent=0] ----- -testCompile "io.codearte.accurest:accurest-messaging-core:${accurestVersion}" ----- - -=== Publisher side test generation - -Having the `input` or `outputMessage` sections in your DSL will result in creation of tests on the publisher's side. By default -JUnit tests will be created, however there is also a possibility to create Spock tests. - -There are 3 main scenarios that we should take into consideration: - -- Scenario 1: there is no input message that produces an output one. The output message is triggered by a component -inside the application (e.g. scheduler) -- Scenario 2: the input message triggers an output message -- Scenario 3: the input message is consumed and there is no output message - -==== Scenario 1 (no input message) - -For the given contract: - -[source,groovy] ----- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_method_dsl] ----- - -The following JUnit test will be created: - -[source,groovy] ----- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_method_junit_test] ----- - -And the following Spock test would be created: - -[source,groovy] ----- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_method_test] ----- - -==== Scenario 2 (output triggered by input) - -For the given contract: - -[source,groovy] ----- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_message_dsl] ----- - -The following JUnit test will be created: - -[source,groovy] ----- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_message_junit] ----- - -And the following Spock test would be created: - -[source,groovy] ----- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_message_spock] ----- - -==== Scenario 3 (no output message) - -For the given contract: - -[source,groovy] ----- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_no_output_dsl] ----- - -The following JUnit test will be created: - -[source,groovy] ----- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_no_output_junit] ----- - -And the following Spock test would be created: - -[source,groovy] ----- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_no_output_spock] ----- - -=== Consumer Stub Side generation - -Unlike the HTTP part - in Messaging we need to publish the Groovy DSL inside the JAR with a stub. Then it's parsed on the consumer side -and proper stubbed routes are created. - -For more infromation please consult the Stub Runner Messaging sections. - -==== Gradle Setup - -Example of Accurest Gradle setup: - -[source,groovy,indent=0] ----- -include::../../../../accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/build.gradle[tags=jar_setup,indent=0] ----- - -==== Maven Setup - -Example of Maven can be found in the https://github.com/Codearte/accurest-maven-plugin/=publishing-wiremock-stubs-projectf-stubsjar[Accurest Maven Plugin README] diff --git a/docs/src/docs/asciidoc/migration.adoc b/docs/src/docs/asciidoc/migration.adoc deleted file mode 100644 index 98e1215e9a..0000000000 --- a/docs/src/docs/asciidoc/migration.adoc +++ /dev/null @@ -1,23 +0,0 @@ -== Migration Guide - -=== Migration to 0.4.7 -- in 0.4.7 we've fixed package name (coderate to codearte) so you've to do the same in your projects. This means replacing ```io.coderate.accurest.dsl.GroovyDsl``` with ```io.codearte.accurest.dsl.GroovyDsl``` - -=== Migration to 1.0.0-RC1 -- from 1.0.0 we're distinguish ignored contracts from excluded contracts: - - `excludedFiles` pattern tells Accurest to skip processing those files at all - - `ignoredFiles` pattern tells Accurest to generate contracts and tests, but tests will be marked as `@Ignore` - -- from 1.0.0 the `basePackageForTests` behaviour has changed - - prior to the change all DSL files had to be under `contractsDslDir`/`basePackageForTests`/*subpackage* resulting in `basePackageForTests`.*subpackage* test package creation - - now all DSL files have to be under `contractsDslDir`/*subpackage* resulting in `basePackageForTests`.*subpackage* test package creation - - If you don't migrate to the new approach you will have your tests under `contractsDslDir`.`contractsDslDir`.*subpackage* - -=== Migration to {messaging_version} -- from {messaging_version} we're setting JUnit as a default testing utility. You have to pass the following option to keep Spock -as your first choice: - -[source,groovy] ----- -include::../../../../accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/build.gradle[tags=target_framework,indent=0] ----- \ No newline at end of file diff --git a/docs/src/docs/asciidoc/stubrunner_msg.adoc b/docs/src/docs/asciidoc/stubrunner_msg.adoc deleted file mode 100644 index 28f31d6211..0000000000 --- a/docs/src/docs/asciidoc/stubrunner_msg.adoc +++ /dev/null @@ -1,58 +0,0 @@ -== Stub Runner for Messaging - -WARNING: Feature available since {messaging_version} - -Stub Runner has the functionality to run the published stubs in memory. It can integrate with the following frameworks out of the box - -- Spring Integration -- Spring Cloud Stream -- Apache Camel - -It also provides points of entry to integrate with any other solution on the market. - -=== Stub triggering - -To trigger a message it's enough to use the `StubTigger` interface: - -[source,groovy] ----- -include::../../../../stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubTrigger.groovy[] ----- - -For convenience the `StubFinder` interface extends `StubTrigger` so it's enough to use only one in your tests. - -`StubTrigger` gives you the following options to trigger a message: - -==== Trigger by label - -[source,groovy] ----- -include::../../../../stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_trigger,indent=0] ----- - -===== Trigger by group and artifact ids - -[source,groovy] ----- -include::../../../../stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=trigger_group_artifact,indent=0] ----- - -===== Trigger by artifact ids - -[source,groovy] ----- -include::../../../../stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=trigger_artifact,indent=0] ----- - -===== Trigger all messages - -[source,groovy] ----- -include::../../../../stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=trigger_all,indent=0] ----- - -include::../../../../stub-runner/stub-runner-messaging/stub-runner-messaging-camel/README.adoc[] - -include::../../../../stub-runner/stub-runner-messaging/stub-runner-messaging-integration/README.adoc[] - -include::../../../../stub-runner/stub-runner-messaging/stub-runner-messaging-stream/README.adoc[] \ No newline at end of file diff --git a/docs/src/main/asciidoc/README.adoc b/docs/src/main/asciidoc/README.adoc new file mode 100644 index 0000000000..1a31f6af8e --- /dev/null +++ b/docs/src/main/asciidoc/README.adoc @@ -0,0 +1,17 @@ +:core_path: ../../../.. +:verifier_root_path: {core_path}/spring-cloud-contract-verifier +:verifier_core_path: {verifier_root_path}/spring-cloud-contract-verifier-core +:stubrunner_core_path: {core_path}/spring-cloud-contract-stub-runner +:documentation_url: http://codearte.github.io/accurest + += Spring Cloud Contract Verifier + +include::introduction.adoc[] + +== Documentation + +You can read more about Spring Cloud Contract Verifier by reading the {documentation_url}[docs] + +== Contributing + +include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/docs/src/main/asciidoc/contributing.adoc[] diff --git a/docs/src/docs/asciidoc/contract.adoc b/docs/src/main/asciidoc/contract.adoc similarity index 56% rename from docs/src/docs/asciidoc/contract.adoc rename to docs/src/main/asciidoc/contract.adoc index ad8c58b3f3..19e6be35f3 100644 --- a/docs/src/docs/asciidoc/contract.adoc +++ b/docs/src/main/asciidoc/contract.adoc @@ -1,27 +1,29 @@ +:core_path: ../../../.. +:verifier_root_path: {core_path}/spring-cloud-contract-verifier +:verifier_core_path: {verifier_root_path}/spring-cloud-contract-verifier-core + == Contract DSL -Contract DSL in Accurest is written in Groovy, but don't be alarmed if you didn't use Groovy before. Knowledge of the language is not really needed as our DSL uses only -a tiny subset of it (namely literals, method calls and closures). What's more, Accurest's DSL is designed to be programmer-readable without any knowledge of the DSL itself - +Contract DSL is written in Groovy, but don't be alarmed if you didn't use Groovy before. Knowledge of the language is not really needed as our DSL uses only +a tiny subset of it (namely literals, method calls and closures). What's more the DSL is designed to be programmer-readable without any knowledge of the DSL itself - it's statically typed. -TIP: Since {messaging_version} you can use the `io.codearte.accurest.dsl.Accurest` class in your DSL files. - Let's look at full example of a contract definition. [source,groovy,indent=0] ---- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcMethodBodyBuilderSpec.groovy[tags=dsl_example,indent=0] +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcMethodBodyBuilderSpec.groovy[tags=dsl_example,indent=0] ---- Not all features of the DSL are used in example above. If you didn't find what you are looking for, please check next paragraphs on this page. -> You can easily compile Accurest Contracts to WireMock stubs mapping using standalone maven command: `mvn io.codearte.accurest:accurest-maven-plugin:convert`. +> You can easily compile Contracts to WireMock stubs mapping using standalone maven command: `mvn org.springframework.cloud.contract:spring-cloud-contract-verifier-maven-plugin:convert`. === Limitations -WARNING: Accurest doesn't support XML properly. Please use JSON or help us implement this feature. +WARNING: Spring Cloud Contract Verifier doesn't support XML properly. Please use JSON or help us implement this feature. -WARNING: Accurest supports equality check on text response. Regular expressions are not yet available. +WARNING: Spring Cloud Contract Verifier supports equality check on text response. Regular expressions are not yet available. === HTTP Top-Level Elements @@ -29,23 +31,23 @@ Following methods can be called in the top-level closure of a contract definitio [source,groovy,indent=0] ---- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=http_dsl,indent=0] +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/ContractHttpDocsSpec.groovy[tags=http_dsl,indent=0] ---- === Request -HTTP protocol requires only **method and address** to be specified in a request. The same information is mandatory in request definition of Accurest contract. +HTTP protocol requires only **method and address** to be specified in a request. The same information is mandatory in request definition of the Contract. [source,groovy,indent=0] ---- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=request,indent=0] +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/ContractHttpDocsSpec.groovy[tags=request,indent=0] ---- It is possible to specify whole `url` instead of just path, but `urlPath` is the recommended way as it makes the tests **host-independent**. [source,groovy,indent=0] ---- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=url,indent=0] +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/ContractHttpDocsSpec.groovy[tags=url,indent=0] ---- @@ -53,28 +55,28 @@ Request may contain **query parameters**, which are specified in a closure neste [source,groovy,indent=0] ---- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=urlpath,indent=0] +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/ContractHttpDocsSpec.groovy[tags=urlpath,indent=0] ---- It may contain additional **request headers**... [source,groovy,indent=0] ---- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=headers,indent=0] +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/ContractHttpDocsSpec.groovy[tags=headers,indent=0] ---- ...and a **request body**. [source,groovy,indent=0] ---- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=body,indent=0] +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/ContractHttpDocsSpec.groovy[tags=body,indent=0] ---- **Body's format** can also be specified explicitly by invoking one of format functions. [source,groovy,indent=0] ---- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=bodyAsXml,indent=0] +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/ContractHttpDocsSpec.groovy[tags=bodyAsXml,indent=0] ---- === Response @@ -83,7 +85,7 @@ Minimal response must contain **HTTP status code**. [source,groovy,indent=0] ---- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=response,indent=0] +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/ContractHttpDocsSpec.groovy[tags=response,indent=0] ---- Besides status response may contain **headers** and **body**, which are specified the same way as in the request (see previous paragraph). @@ -97,7 +99,7 @@ Please see the example below: [source,groovy,indent=0] ---- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=regex,indent=0] +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/ContractHttpDocsSpec.groovy[tags=regex,indent=0] ---- === Passing optional parameters @@ -111,7 +113,7 @@ Example: [source,groovy,indent=0] ---- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=optionals,indent=0] +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/ContractHttpDocsSpec.groovy[tags=optionals,indent=0] ---- By wrapping a part of the body with the `optional()` method you are in fact creating a regular expression that should be present 0 or more times. @@ -120,14 +122,14 @@ That way for the example above the following test would be generated if you pick [source,groovy,indent=0] ---- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=optionals_test,indent=0] +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/ContractHttpDocsSpec.groovy[tags=optionals_test,indent=0] ---- and the following stub: [source,javascript,indent=0] ---- -include::../../../../accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverterSpec.groovy[tags=wiremock,indent=0] +include::{verifier_root_path}/spring-cloud-contract-verifier-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockClientConverterSpec.groovy[tags=wiremock,indent=0] ---- === Executing custom methods on server side @@ -138,14 +140,14 @@ in the configuration. Please see the examples below: [source,groovy,indent=0] ---- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=method,indent=0] +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/ContractHttpDocsSpec.groovy[tags=method,indent=0] ---- ==== Base Mock Spec [source,groovy,indent=0] ---- -include::../../../../accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/groovy/com/ofg/twitter/places/BaseMockMvcSpec.groovy[tags=base_class,indent=0] +include::{verifier_root_path}/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/groovy/org/springframework/cloud/twitter/places/BaseMockMvcSpec.groovy[tags=base_class,indent=0] ---- === JAX-RS support @@ -164,13 +166,11 @@ Example of a test API generated: [source,groovy,indent=0] ---- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/JaxRsClientMethodBuilderSpec.groovy[tags=jaxrs,indent=0] +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/JaxRsClientMethodBuilderSpec.groovy[tags=jaxrs,indent=0] ---- === Messaging Top-Level Elements -WARNING: Feature available since {messaging_version} - The DSL for messaging looks a little bit different than the one that focuses on HTTP. ==== Output triggered by a method @@ -179,7 +179,7 @@ The output message can be triggered by calling a method (e.g. a Scheduler was st [source,groovy] ---- -include::../../../../samples/messaging-integration/src/test/groovy/io/codearte/accurest/samples/messaging/IntegrationMessagingApplicationSpec.groovy[tags=method_trigger,indent=0] +include::../../../../samples/messaging-integration/src/test/groovy/org/springframework/cloud/contract/verifier/samples/messaging/IntegrationMessagingApplicationSpec.groovy[tags=method_trigger,indent=0] ---- In this case the output message will be sent to `output` if a method called `bookReturnedTriggered` will be executed. In the message *publisher's* side @@ -191,7 +191,7 @@ The output message can be triggered by receiving a message. [source,groovy] ---- -include::../../../../samples/messaging-integration/src/test/groovy/io/codearte/accurest/samples/messaging/IntegrationMessagingApplicationSpec.groovy[tags=message_trigger,indent=0] +include::../../../../samples/messaging-integration/src/test/groovy/org/springframework/cloud/contract/verifier/samples/messaging/IntegrationMessagingApplicationSpec.groovy[tags=message_trigger,indent=0] ---- In this case the output message will be sent to `output` if a proper message will be received on the `input` destination. In the message *publisher's* side @@ -205,5 +205,5 @@ as presented below (note you can use either `$` or `value` methods to provide `c [source,groovy] ---- -include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy[tags=consumer_producer] +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MessagingMethodBodyBuilderSpec.groovy[tags=consumer_producer] ---- \ No newline at end of file diff --git a/docs/src/docs/asciidoc/images/Deps.png b/docs/src/main/asciidoc/images/Deps.png similarity index 100% rename from docs/src/docs/asciidoc/images/Deps.png rename to docs/src/main/asciidoc/images/Deps.png diff --git a/docs/src/docs/asciidoc/images/Stubs1.png b/docs/src/main/asciidoc/images/Stubs1.png similarity index 100% rename from docs/src/docs/asciidoc/images/Stubs1.png rename to docs/src/main/asciidoc/images/Stubs1.png diff --git a/docs/src/docs/asciidoc/images/Stubs2.png b/docs/src/main/asciidoc/images/Stubs2.png similarity index 100% rename from docs/src/docs/asciidoc/images/Stubs2.png rename to docs/src/main/asciidoc/images/Stubs2.png diff --git a/docs/src/main/asciidoc/index.adoc b/docs/src/main/asciidoc/index.adoc new file mode 120000 index 0000000000..28dc0a7e0c --- /dev/null +++ b/docs/src/main/asciidoc/index.adoc @@ -0,0 +1 @@ +spring-cloud-contract-verifier.adoc \ No newline at end of file diff --git a/docs/src/docs/asciidoc/introduction.adoc b/docs/src/main/asciidoc/introduction.adoc similarity index 77% rename from docs/src/docs/asciidoc/introduction.adoc rename to docs/src/main/asciidoc/introduction.adoc index 08f45e5fa9..95c9b1f58f 100644 --- a/docs/src/docs/asciidoc/introduction.adoc +++ b/docs/src/main/asciidoc/introduction.adoc @@ -1,14 +1,15 @@ == Introduction -Just to make long story short - Accurest is a tool that enables Consumer Driven Contract (CDC) development of JVM-based applications. It is shipped -with __Contract Definition Language__ (DSL). Contract definitions are used by Accurest to produce following resources: +Just to make long story short - Spring Cloud Contract Verifier is a tool that enables Consumer Driven Contract (CDC) development of JVM-based applications. It is shipped +with __Contract Definition Language__ (DSL). Contract definitions are used to produce following resources: * JSON stub definitions to be used by Wiremock when doing integration testing on the client code (__client tests__). -Test code must still be written by hand, test data is produced by Accurest. +Test code must still be written by hand, test data is produced by Spring Cloud Contract Verifier. * Messaging routes if you're using one. We're integrating with Spring Integration, Spring Cloud Stream and Apache Camel. You can however set your own integrations if you want to -* Acceptance tests (in JUnit or Spock) used to verify if server-side implementation of the API is compliant with the contract (__server tests__). Full test is generated by Accurest. +* Acceptance tests (in JUnit or Spock) used to verify if server-side implementation of the API is compliant with the contract (__server tests__). +Full test is generated by Spring Cloud Contract Verifier. -Accurest moves TDD to the level of software architecture. +Spring Cloud Contract Verifier moves TDD to the level of software architecture. === Why? @@ -52,7 +53,7 @@ Disadvantages: - the implementor of the service creates stubs thus they might have nothing to do with the reality - you can go to production with passing tests and failing production -To solve the aforementioned issues Accurest with Stub Runner were created. Their main idea is to give you very fast feedback, without the need +To solve the aforementioned issues Spring Cloud Contract Verifier with Stub Runner were created. Their main idea is to give you very fast feedback, without the need to set up the whole world of microservices. image::Stubs1.png[Stubbed Services] @@ -61,13 +62,13 @@ If you work on stubs then the only applications you need are those that your app image::Stubs2.png[Stubbed Services] -Accurest gives you the certainty that the stubs that you're using were created by the service that you're calling. Also if you can use them it means that they were +Spring Cloud Contract Verifier gives you the certainty that the stubs that you're using were created by the service that you're calling. Also if you can use them it means that they were tested against the producer's side. In other words - you can trust those stubs. === Purposes -The main purposes of Accurest with Stub Runner are: +The main purposes of Spring Cloud Contract Verifier with Stub Runner are: - to ensure that WireMock / Messaging stubs (used when developing the client) are doing exactly what actual server-side implementation will do, - to promote ATDD method and Microservices architectural style, @@ -97,7 +98,7 @@ for response verification. === Dependencies -Accurest and Stub Runner are using the following libraries +Spring Cloud Contract Verifier and Stub Runner are using the following libraries - http://wiremock.org/[WireMock] - https://github.com/jayway/JsonPath[Jayway JSONPath] @@ -105,16 +106,16 @@ Accurest and Stub Runner are using the following libraries === Additional links -Below you can find some resources related to Accurest and Stub Runner. Note that some can be outdated since the Accurest project +Below you can find some resources related to Spring Cloud Contract Verifier and Stub Runner. Note that some can be outdated since the Spring Cloud Contract Verifier project is under constant development. ==== Videos -*Olga Maciaszek-Sharma talking about Accurest* +*Olga Maciaszek-Sharma talking about Accurest (Spring Cloud Contract Verifier predecessor)* video::daafmTYFoDU[youtube] -*Marcin Grzejszczak and Jakub KubryƄski talking about Accurest* +*Marcin Grzejszczak and Jakub KubryƄski talking about Accurest (Spring Cloud Contract Verifier predecessor)* video::130779882[vimeo] diff --git a/docs/src/main/asciidoc/messaging.adoc b/docs/src/main/asciidoc/messaging.adoc new file mode 100644 index 0000000000..24bc2bc272 --- /dev/null +++ b/docs/src/main/asciidoc/messaging.adoc @@ -0,0 +1,150 @@ +:core_path: ../../../.. +:verifier_root_path: {core_path}/spring-cloud-contract-verifier +:verifier_core_path: {verifier_root_path}/spring-cloud-contract-verifier-core + +== Spring Cloud Contract Verifier Messaging + +Spring Cloud Contract Verifier allows you to verify your application that uses messaging as means of communication. +All of our integrations are working with Spring but you can also set one yourself. + +=== Integrations + +You can use one of the three integration configurations: + +- Apache Camel +- Spring Integration +- Spring Cloud Stream + +If you're using Spring Boot, the aforementioned test configurations will be appended automatically. + +You have to provide as a dependency one of the Spring Cloud Contract Verifier Messaging modules. Example for Gradle: + +[source,groovy,indent=0] +---- +// for Apache Camel +testCompile "org.springframework.cloud.contract:spring-cloud-contract-verifier-camel:${verifierVersion}" +// for Spring Integration +testCompile "org.springframework.cloud.contract:spring-cloud-contract-verifier-integration:${verifierVersion}" +// for Spring Cloud Stream +testCompile "org.springframework.cloud.contract:spring-cloud-contract-verifier-stream:${verifierVersion}" +---- + +=== Manual Integration + +The `spring-cloud-contract-verifier-messaging-core` module contains 3 main interfaces: + +- `ContractVerifierMessage` - describes a message received / sent to a channel / queue / topic etc. +- `ContractVerifierMessageBuilder` - describes how to build a message +- `ContractVerifierMessaging` - class that allows you to build, send and receive messages +- `ContractVerifierFilter` - interface to filter out the messages that do not follow the pattern from the DSL + +In the generated test the `ContractVerifierMessaging` is injected via `@Inject` annotation thus you can use other injection +frameworks than Spring. + +You have to provide as a dependency the `spring-cloud-contract-verifier-messaging-core` module. Example for Gradle: + +[source,groovy,indent=0] +---- +testCompile "org.springframework.cloud.contract:spring-cloud-contract-verifier-messaging-core:${verifierVersion}" +---- + +=== Publisher side test generation + +Having the `input` or `outputMessage` sections in your DSL will result in creation of tests on the publisher's side. By default +JUnit tests will be created, however there is also a possibility to create Spock tests. + +There are 3 main scenarios that we should take into consideration: + +- Scenario 1: there is no input message that produces an output one. The output message is triggered by a component +inside the application (e.g. scheduler) +- Scenario 2: the input message triggers an output message +- Scenario 3: the input message is consumed and there is no output message + +==== Scenario 1 (no input message) + +For the given contract: + +[source,groovy] +---- +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_method_dsl] +---- + +The following JUnit test will be created: + +[source,groovy] +---- +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_method_junit_test] +---- + +And the following Spock test would be created: + +[source,groovy] +---- +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_method_test] +---- + +==== Scenario 2 (output triggered by input) + +For the given contract: + +[source,groovy] +---- +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_message_dsl] +---- + +The following JUnit test will be created: + +[source,groovy] +---- +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_message_junit] +---- + +And the following Spock test would be created: + +[source,groovy] +---- +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_message_spock] +---- + +==== Scenario 3 (no output message) + +For the given contract: + +[source,groovy] +---- +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_no_output_dsl] +---- + +The following JUnit test will be created: + +[source,groovy] +---- +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_no_output_junit] +---- + +And the following Spock test would be created: + +[source,groovy] +---- +include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_no_output_spock] +---- + +=== Consumer Stub Side generation + +Unlike the HTTP part - in Messaging we need to publish the Groovy DSL inside the JAR with a stub. Then it's parsed on the consumer side +and proper stubbed routes are created. + +For more infromation please consult the Stub Runner Messaging sections. + +==== Gradle Setup + +Example of Spring Cloud Contract Verifier Gradle setup: + +[source,groovy,indent=0] +---- +include::{verifier_root_path}/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/build.gradle[tags=jar_setup,indent=0] +---- + +==== Maven Setup + +Example of Maven can be found in the https://github.com/Codearte/accurest-maven-plugin/=publishing-wiremock-stubs-projectf-stubsjar[Spring Cloud Contract Verifier Maven Plugin README] diff --git a/docs/src/docs/asciidoc/rest.adoc b/docs/src/main/asciidoc/rest.adoc similarity index 68% rename from docs/src/docs/asciidoc/rest.adoc rename to docs/src/main/asciidoc/rest.adoc index 27ccbec36a..6e7b614eb4 100644 --- a/docs/src/docs/asciidoc/rest.adoc +++ b/docs/src/main/asciidoc/rest.adoc @@ -1,10 +1,14 @@ -== Accurest HTTP +:core_path: ../../../.. +:verifier_root_path: {core_path}/spring-cloud-contract-verifier +:verifier_core_path: {verifier_root_path}/spring-cloud-contract-verifier-core + +== Spring Cloud Contract Verifier HTTP === Gradle Project ==== Prerequisites -In order to use Accurest with Wiremock you have to use gradle or maven plugin. +In order to use Spring Cloud Contract Verifier with Wiremock you have to use gradle or maven plugin. ===== Add gradle plugin @@ -15,12 +19,12 @@ buildscript { mavenCentral() } dependencies { - classpath 'io.codearte.accurest:accurest-gradle-plugin:${accurest_version}' + classpath 'org.springframework.cloud.contract:spring-cloud-contract-verifier-gradle-plugin:${verifier_version}' } } apply plugin: 'groovy' -apply plugin: 'accurest' +apply plugin: 'contract-verifier' dependencies { testCompile 'org.codehaus.groovy:groovy-all:2.4.6' @@ -47,8 +51,8 @@ repositories { [source,xml,indent=0] ---- - io.codearte.accurest - accurest-maven-plugin + org.springframework.cloud.contract + spring-cloud-contract-verifier-maven-plugin @@ -66,7 +70,7 @@ Read more: http://codearte.github.io/accurest-maven-plugin/[accurest-maven-plugi ===== Add stubs -By default Accurest is looking for stubs in `src/test/resources/accurest` directory. +By default Spring Cloud Contract Verifier is looking for stubs in `src/test/resources/contracts` directory. Directory containing stub definitions is treated as a class name, and each stub definition is treated as a single test. We assume that it contains at least one directory which will be used as test class name. If there is more than one level of nested directories all except the last one will be used as package name. @@ -74,29 +78,29 @@ So with following structure [source,groovy,indent=0] ---- -src/test/resources/accurest/myservice/shouldCreateUser.groovy -src/test/resources/accurest/myservice/shouldReturnUser.groovy +src/test/resources/contracts/myservice/shouldCreateUser.groovy +src/test/resources/contracts/myservice/shouldReturnUser.groovy ---- -Accurest will create test class `defaultBasePackage.MyService` with two methods +Spring Cloud Contract Verifier will create test class `defaultBasePackage.MyService` with two methods - `shouldCreateUser()` - `shouldReturnUser()` ==== Run plugin -Plugin registers itself to be invoked before `check` task. You have nothing to do as long as you want it to be part of your build process. If you just want to generate tests please invoke `generateAccurest` task. +Plugin registers itself to be invoked before `check` task. You have nothing to do as long as you want it to be part of your build process. If you just want to generate tests please invoke `generateContractTests` task. ==== Configure plugin -To change default configuration just add `accurest` snippet to your Gradle config +To change default configuration just add `contractVerifier` snippet to your Gradle config [source,groovy,indent=0] ---- -accurest { +contractVerifier { testMode = 'MockMvc' baseClassForTests = 'org.mycompany.tests' - generatedTestSourcesDir = project.file('src/accurest') + generatedTestSourcesDir = project.file('src/generatedContract') } ---- @@ -105,22 +109,22 @@ accurest { - **testMode** - defines mode for acceptance tests. By default MockMvc which is based on Spring's MockMvc. It can also be changed to **JaxRsClient** or to **Explicit** for real HTTP calls. - **imports** - array with imports that should be included in generated tests (for example ['org.myorg.Matchers']). By default empty array [] - **staticImports** - array with static imports that should be included in generated tests(for example ['org.myorg.Matchers.*']). By default empty array [] - - **basePackageForTests** - specifies base package for all generated tests. By default set to io.codearte.accurest.tests + - **basePackageForTests** - specifies base package for all generated tests. By default set to org.springframework.cloud.contract.verifier.tests - **baseClassForTests** - base class for generated tests. By default `spock.lang.Specification` if using Spock tests. - **ruleClassForTests** - specifies Rule which should be added to generated test classes. - **ignoredFiles** - Ant matcher allowing defining stub files for which processing should be skipped. By default empty array [] - - **contractsDslDir** - directory containing contracts written using the GroovyDSL. By default `$rootDir/src/test/resources/accurest` - - **generatedTestSourcesDir** - test source directory where tests generated from Groovy DSL should be placed. By default `$buildDir/generated-test-sources/accurest` - - **stubsOutputDir** - dir where the generated Wiremock stubs from Groovy DSL should be placed + - **contractsDslDir** - directory containing contracts written using the GroovyDSL. By default `$rootDir/src/test/resources/contracts` + - **generatedTestSourcesDir** - test source directory where tests generated from Groovy DSL should be placed. By default `$buildDir/generated-test-sources/contractVerifier` + - **stubsOutputDir** - dir where the generated WireMock stubs from Groovy DSL should be placed - **targetFramework** - the target test framework to be used; currently Spock and JUnit are supported with JUnit being the default framework ===== Base class for tests -When using Accurest in default MockMvc you need to create a base specification for all generated acceptance tests. In this class you need to point to endpoint which should be verified. +When using Spring Cloud Contract Verifier in default MockMvc you need to create a base specification for all generated acceptance tests. In this class you need to point to endpoint which should be verified. [source,groovy,indent=0] ---- -include::../../../../accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/groovy/com/ofg/twitter/places/BaseMockMvcSpec.groovy[tags=base_class,indent=0] +include::{verifier_root_path}/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/groovy/org/springframework/cloud/twitter/places/BaseMockMvcSpec.groovy[tags=base_class,indent=0] ---- In case of using `Explicit` mode, you can use base class to initialize the whole tested app similarly as in regular integration tests. In case of `JAXRSCLIENT` mode this base class @@ -132,13 +136,13 @@ To ensure that provider side is complaint with defined contracts, you need to in [source,bash,indent=0] ---- -./gradlew generateAccurest test +./gradlew generateContractTests test ---- -==== Accurest on consumer side +==== Spring Cloud Contract Verifier on consumer side -In consumer service you need to configure Accurest plugin in exactly the same way as in case of provider. If you don't want to use Stub Runner then you need to copy contracts stored in -`src/test/resources/accurest` and generate WireMock json stubs using: +In consumer service you need to configure Spring Cloud Contract Verifier plugin in exactly the same way as in case of provider. If you don't want to use Stub Runner then you need to copy contracts stored in +`src/test/resources/contracts` and generate WireMock json stubs using: [source,bash,indent=0] ---- @@ -174,7 +178,7 @@ class LoanApplicationServiceSpec extends Specification { } ---- -Underneath LoanApplication makes a call to FraudDetection service. This request is handled by Wiremock server configured using stubs generated by Accurest. +Underneath LoanApplication makes a call to FraudDetection service. This request is handled by Wiremock server configured using stubs generated by Spring Cloud Contract Verifier. === Using in your Maven project @@ -183,8 +187,8 @@ Underneath LoanApplication makes a call to FraudDetection service. This request [source,xml,indent=0] ---- - io.codearte.accurest - accurest-maven-plugin + org.springframework.cloud.contract.verifier + spring-cloud-contract-verifier-maven-plugin @@ -201,18 +205,18 @@ Read more: http://codearte.github.io/accurest-maven-plugin/[accurest-maven-plugi ==== Add stubs -By default Accurest is looking for stubs in `src/test/resources/accurest` directory. +By default Spring Cloud Contract Verifier is looking for stubs in `src/test/resources/contracts` directory. Directory containing stub definitions is treated as a class name, and each stub definition is treated as a single test. We assume that it contains at least one directory which will be used as test class name. If there is more than one level of nested directories all except the last one will be used as package name. So with following structure [source,groovy,indent=0] ---- -src/test/resources/accurest/myservice/shouldCreateUser.groovy -src/test/resources/accurest/myservice/shouldReturnUser.groovy +src/test/resources/contracts/myservice/shouldCreateUser.groovy +src/test/resources/contracts/myservice/shouldReturnUser.groovy ---- -Accurest will create test class `defaultBasePackage.MyService` with two methods +Spring Cloud Contract Verifier will create test class `defaultBasePackage.MyService` with two methods - `shouldCreateUser()` - `shouldReturnUser()` @@ -227,8 +231,8 @@ To change default configuration just add `configuration` section to plugin defin [source,xml,indent=0] ---- - io.codearte.accurest - accurest-maven-plugin + org.springframework.cloud.contract.verifier + spring-cloud-contract-verifier-maven-plugin @@ -239,8 +243,8 @@ To change default configuration just add `configuration` section to plugin defin - com.ofg.twitter.place - com.ofg.twitter.place.BaseMockMvcSpec + org.springframework.cloud.contract.verifier.twitter.place + org.springframework.cloud.contract.verifier.twitter.place.BaseMockMvcSpec ---- @@ -248,17 +252,17 @@ To change default configuration just add `configuration` section to plugin defin ===== Important configuration options - **testMode** - defines mode for acceptance tests. By default `MockMvc` which is based on Spring's MockMvc. It can also be changed to `JaxRsClient` or to `Explicit` for real HTTP calls. - - **basePackageForTests** - specifies base package for all generated tests. By default set to `io.codearte.accurest.tests`. + - **basePackageForTests** - specifies base package for all generated tests. By default set to `org.springframework.cloud.contract.verifier.tests`. - **ruleClassForTests** - specifies Rule which should be added to generated test classes. - **baseClassForTests** - base class for generated tests. By default `spock.lang.Specification` if using Spock tests. - - **contractsDir** - directory containing contracts written using the GroovyDSL. By default `/src/test/resources/accurest`. + - **contractsDir** - directory containing contracts written using the GroovyDSL. By default `/src/test/resources/contracts`. - **testFramework** - the target test framework to be used; currently Spock and JUnit are supported with Spock being the default framework For complete information take a look at http://codearte.github.io/accurest-maven-plugin/plugin-info.html[Plugin Documentation] ===== Base class for tests - When using Accurest in default MockMvc you need to create a base specification for all generated acceptance tests. In this class you need to point to endpoint which should be verified. + When using Spring Cloud Contract Verifier in default MockMvc you need to create a base specification for all generated acceptance tests. In this class you need to point to endpoint which should be verified. [source,groovy,indent=0] ---- @@ -279,7 +283,7 @@ In case of using `Explicit` mode, you can use base class to initialize the whole ==== Invoking generated tests -Accurest Maven Plugins generates verification code into directory `/generated-test-sources/accurest` and attach this directory to `testCompile` goal. +Spring Cloud Contract Verifier Maven Plugins generates verification code into directory `/generated-test-sources/contractVerifier` and attach this directory to `testCompile` goal. For Groovy Spock code use: @@ -305,7 +309,7 @@ For Groovy Spock code use: - ${project.build.directory}/generated-test-sources/accurest + ${project.build.directory}/generated-test-sources/contractVerifier **/*.groovy @@ -317,18 +321,18 @@ For Groovy Spock code use: To ensure that provider side is complaint with defined contracts, you need to invoke `mvn generateTest test` -==== Accurest on consumer side +==== Spring Cloud Contract Verifier on consumer side -In consumer service you need to configure Accurest plugin in exactly the same way as in case of provider. You need to copy contracts stored in `src/test/resources/accurest` and generate Wiremock json stubs using: `mvn generateStubs` command. By default generated WireMock mapping is stored in directory `target/mappings`. Your project should create from this generated mappings additional artifact with classifier `stubs` for easy deploy to maven repository. +In consumer service you need to configure Spring Cloud Contract Verifier plugin in exactly the same way as in case of provider. You need to copy contracts stored in `src/test/resources/contracts` and generate Wiremock json stubs using: `mvn generateStubs` command. By default generated WireMock mapping is stored in directory `target/mappings`. Your project should create from this generated mappings additional artifact with classifier `stubs` for easy deploy to maven repository. Sample configuration: [source,xml,indent=0] ---- - io.codearte.accurest - accurest-maven-plugin - ${accurest-plugin.version} + org.springframework.cloud.contract.verifier + spring-cloud-contract-verifier-maven-plugin + ${verifier-plugin.version} @@ -367,11 +371,11 @@ class LoanApplicationServiceSpec extends Specification { } ---- -Underneath LoanApplication makes a call to FraudDetection service. This request is handled by Wiremock server configured using stubs generated by Accurest. +Underneath LoanApplication makes a call to FraudDetection service. This request is handled by Wiremock server configured using stubs generated by Spring Cloud Contract Verifier. === Scenarios -It's possible to handle scenarios with Accurest. All you need to do is to stick to proper naming convention while creating your contracts. The convention requires to include order number followed by the underscore. +It's possible to handle scenarios with Spring Cloud Contract Verifier. All you need to do is to stick to proper naming convention while creating your contracts. The convention requires to include order number followed by the underscore. [source,indent=0] ---- @@ -382,10 +386,10 @@ my_contracts_dir\ 3_logout.groovy ---- -Such tree will cause Accurest generating Wiremock's scenario with name `scenario1` and three steps: +Such tree will cause Spring Cloud Contract Verifier generating Wiremock's scenario with name `scenario1` and three steps: - login marked as `Started` pointing to: - showCart marked as `Step1` pointing to: - logout marked as `Step2` which will close the scenario. More details about Wiremock scenarios can be found under [http://wiremock.org/stateful-behaviour.html](http://wiremock.org/stateful-behaviour.html) -Accurest will also generate tests with guaranteed order of execution. +Spring Cloud Contract Verifier will also generate tests with guaranteed order of execution. diff --git a/docs/src/main/asciidoc/spring-cloud-contract-verifier.adoc b/docs/src/main/asciidoc/spring-cloud-contract-verifier.adoc new file mode 100644 index 0000000000..8dc733a041 --- /dev/null +++ b/docs/src/main/asciidoc/spring-cloud-contract-verifier.adoc @@ -0,0 +1,20 @@ +:core_path: ../../../.. +:verifier_root_path: {core_path}/spring-cloud-contract-verifier +:verifier_core_path: {verifier_root_path}/spring-cloud-contract-verifier-core +:stubrunner_core_path: {core_path}/spring-cloud-contract-stub-runner + += Spring Cloud Contract Verifier + +_Adam Dudczak, Marcin Grzejszczak, Jakub KubryƄski, Karol Lassak, Olga Maciaszek-Sharma, Mariusz SmykuƂa_ + +include::introduction.adoc[] + +include::contract.adoc[] + +include::rest.adoc[] + +include::messaging.adoc[] + +include::stubrunner.adoc[] + +include::stubrunner_msg.adoc[] \ No newline at end of file diff --git a/docs/src/docs/asciidoc/stubrunner.adoc b/docs/src/main/asciidoc/stubrunner.adoc similarity index 55% rename from docs/src/docs/asciidoc/stubrunner.adoc rename to docs/src/main/asciidoc/stubrunner.adoc index 06aea3f697..3478146c9f 100644 --- a/docs/src/docs/asciidoc/stubrunner.adoc +++ b/docs/src/main/asciidoc/stubrunner.adoc @@ -1,6 +1,10 @@ -== Stub Runner +:core_path: ../../../.. +:verifier_root_path: {core_path}/spring-cloud-contract-verifier +:verifier_core_path: {verifier_root_path}/spring-cloud-contract-verifier-core -One of the issues that you could have encountered while using Accurest was to pass the generated WireMock JSON stubs from the server side to the client side (or various clients). +== Spring Cloud Contract Stub Runner + +One of the issues that you could have encountered while using Spring Cloud Contract Verifier was to pass the generated WireMock JSON stubs from the server side to the client side (or various clients). The same takes place in terms of client side generation for messaging. Copying the JSON files / setting the client side for messaging manually is out of the question. @@ -11,40 +15,40 @@ The easiest approach would be to centralize the way stubs are kept. For example ==== Gradle -Example of Accurest Gradle setup: +Example of Spring Cloud Contract Verifier Gradle setup: [source,groovy,indent=0] ---- -include::../../../../accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/build.gradle[tags=jar_setup,indent=0] +include::{verifier_root_path}/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/build.gradle[tags=jar_setup,indent=0] ---- ==== Maven -Example of Maven can be found in the https://github.com/Codearte/accurest-maven-plugin/=publishing-wiremock-stubs-projectf-stubsjar[Accurest Maven Plugin README] +Example of Maven can be found in the https://github.com/Codearte/accurest-maven-plugin/=publishing-wiremock-stubs-projectf-stubsjar[Spring Cloud Contract Verifier Maven Plugin README] === Modules -Accurest comes with a new structure of modules +Spring Cloud Contract Stub Runner comes with a new structure of modules [source,indent=0] ---- -└── stub-runner - ├── stub-runner - ├── stub-runner-boot - ├── stub-runner-junit - ├── stub-runner-spring - └── stub-runner-spring-cloud +└── spring-cloud-contract-stub-runner + ├── spring-cloud-contract-stub-runner + ├── spring-cloud-contract-stub-runner-boot + ├── spring-cloud-contract-stub-runner-junit + ├── spring-cloud-contract-stub-runner-spring + └── spring-cloud-contract-stub-runner-spring-cloud ---- -include::../../../../stub-runner/stub-runner/README.adoc[] +include::../../../../spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/README.adoc[] -include::../../../../stub-runner/stub-runner-boot/README.adoc[] +include::../../../../spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/README.adoc[] -include::../../../../stub-runner/stub-runner-junit/README.adoc[] +include::../../../../spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/README.adoc[] -include::../../../../stub-runner/stub-runner-spring/README.adoc[] +include::../../../../spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/README.adoc[] -include::../../../../stub-runner/stub-runner-spring-cloud/README.adoc[] +include::../../../../spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/README.adoc[] === Common properties for JUnit and Spring diff --git a/docs/src/main/asciidoc/stubrunner_msg.adoc b/docs/src/main/asciidoc/stubrunner_msg.adoc new file mode 100644 index 0000000000..194076d611 --- /dev/null +++ b/docs/src/main/asciidoc/stubrunner_msg.adoc @@ -0,0 +1,61 @@ +:core_path: ../../../.. +:verifier_root_path: {core_path}/spring-cloud-contract-verifier +:verifier_core_path: {verifier_root_path}/spring-cloud-contract-verifier-core +:stubrunner_core_path: {core_path}/spring-cloud-contract-stub-runner + +== Stub Runner for Messaging + +Stub Runner has the functionality to run the published stubs in memory. It can integrate with the following frameworks out of the box + +- Spring Integration +- Spring Cloud Stream +- Apache Camel + +It also provides points of entry to integrate with any other solution on the market. + +=== Stub triggering + +To trigger a message it's enough to use the `StubTrigger` interface: + +[source,groovy] +---- +include::{stubrunner_core_path}/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubTrigger.groovy[] +---- + +For convenience the `StubFinder` interface extends `StubTrigger` so it's enough to use only one in your tests. + +`StubTrigger` gives you the following options to trigger a message: + +==== Trigger by label + +[source,groovy] +---- +include::{stubrunner_core_path}/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_trigger,indent=0] +---- + +===== Trigger by group and artifact ids + +[source,groovy] +---- +include::{stubrunner_core_path}/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=trigger_group_artifact,indent=0] +---- + +===== Trigger by artifact ids + +[source,groovy] +---- +include::{stubrunner_core_path}/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=trigger_artifact,indent=0] +---- + +===== Trigger all messages + +[source,groovy] +---- +include::{stubrunner_core_path}/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=trigger_all,indent=0] +---- + +include::{stubrunner_core_path}/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/README.adoc[] + +include::{stubrunner_core_path}/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/README.adoc[] + +include::{stubrunner_core_path}/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/README.adoc[] \ No newline at end of file diff --git a/docs/src/main/ruby/generate_readme.sh b/docs/src/main/ruby/generate_readme.sh new file mode 100755 index 0000000000..6d0ce9dc54 --- /dev/null +++ b/docs/src/main/ruby/generate_readme.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env ruby + +base_dir = File.join(File.dirname(__FILE__),'../../..') +src_dir = File.join(base_dir, "/src/main/asciidoc") +require 'asciidoctor' +require 'optparse' + +options = {} +file = "#{src_dir}/README.adoc" + +OptionParser.new do |o| + o.on('-o OUTPUT_FILE', 'Output file (default is stdout)') { |file| options[:to_file] = file unless file=='-' } + o.on('-h', '--help') { puts o; exit } + o.parse! +end + +file = ARGV[0] if ARGV.length>0 + +# Copied from https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/scripts/asciidoc-coalescer.rb +doc = Asciidoctor.load_file file, safe: :unsafe, header_only: true, attributes: options[:attributes] +header_attr_names = (doc.instance_variable_get :@attributes_modified).to_a +header_attr_names.each {|k| doc.attributes[%(#{k}!)] = '' unless doc.attr? k } +attrs = doc.attributes +attrs['allow-uri-read'] = true +puts attrs + +out = "// Do not edit this file (e.g. go instead to src/main/asciidoc)\n\n" +doc = Asciidoctor.load_file file, safe: :unsafe, parse: false, attributes: attrs +out << doc.reader.read + +unless options[:to_file] + puts out +else + File.open(options[:to_file],'w+') do |file| + file.write(out) + end +end diff --git a/generateReadme.sh b/generateReadme.sh new file mode 100755 index 0000000000..1638d7b172 --- /dev/null +++ b/generateReadme.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +./gradlew :docs:clean :docs:generateReadme --configure-on-demand \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index f9a69c8932..4f7bae8abc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,14 +1,32 @@ +# +# Copyright 2013-2016 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + nexusUsername = nexusPassword = wiremockVersion = 2.0.10-beta jsonassertVersion = 0.4.7 -BOM_VERSION=Brixton-1.0.0.RC1 +BOM_VERSION=Brixton-SR1 springBootVersion=1.3.3.RELEASE springVersion=4.2.5.RELEASE springIntegrationDslVersion=1.1.2.RELEASE springStreamVersion=1.0.0.RC2 springCloudVersion=1.1.0.RC2 camelVersion=2.17.0 -aetherVersion=1.1.0 \ No newline at end of file +aetherVersion=1.1.0 + +verifierVersion=1.0.0.BUILD-SNAPSHOT \ No newline at end of file diff --git a/gradle/release.gradle b/gradle/release.gradle index e1c6fb4494..2258dcdfea 100644 --- a/gradle/release.gradle +++ b/gradle/release.gradle @@ -1,59 +1,90 @@ -apply plugin: 'com.bmuschko.nexus' +apply plugin: 'maven' +apply plugin: 'signing' -modifyPom { - project { - name "$project.name" - packaging 'jar' - description 'RESTful Contract Verifier' - url 'https://github.com/Codearte/accurest' - inceptionYear '2014' - - scm { - connection 'scm:git:git@github.com:Codearte/accurest.git' - developerConnection 'scm:git:git@github.com:Codearte/accurest.git' - url 'https://github.com/Codearte/accurest' +ext { + resolveRepoName = { Project project -> + String version = project.version + String name = project.name + String resolvedRepoName = "libs-${resolveVersion(version)}-local" + if (name.contains("gradle")) { + resolvedRepoName = "plugins-${resolveVersion(version)}-local" } + logger.lifecycle("For project [$project.name] with " + + "version [$project.version] the resolved Artifactory repo is [$resolvedRepoName]") + return resolvedRepoName + } - licenses { - license { - name 'The Apache License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - } - } + resolveVersion = { String version -> + if (version.endsWith('BUILD-SNAPSHOT')) return 'snapshot' + if (version.matches('[0-9].[0-9].[0-9].M[0-9]+')) return 'milestone' + if (version.matches('[0-9].[0-9].[0-9].RC[0-9]+')) return 'milestone' + if (version.endsWith('RELEASE')) return 'release' + return 'snapshot' + } - developers { - developer { - id 'jkubrynski' - name 'Jakub Kubrynski' - email 'jk ATT codearte DOTT io' - } - developer { - id 'marcingrzejszczak' - name 'Marcin Grzejszczak' - email 'marcin ATT grzejszczak DOTT pl' + isReleaseVersion = !version.endsWith("SNAPSHOT") +} + +uploadArchives.dependsOn { [check] } + +ext { + repositoryUrl = "https://repo.spring.io/${repoPrefix()}-${resolveVersion(version)}-local" + snapshotRepositoryUrl = "https://repo.spring.io/${repoPrefix()}-snapshot-local" + repoUrl = isReleaseVersion ? repositoryUrl : snapshotRepositoryUrl +} + +afterEvaluate { + uploadArchives { + repositories { + mavenDeployer { + // POM signature + beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } + // Target repository + repository(url: repoUrl) { + authentication(userName: repoUser, password: repoPass) + } + pom.project { + name "$project.name" + packaging 'jar' + description 'Consumer Driven Contract Verifier and Stub Runner' + url 'https://github.com/Codearte/accurest' + inceptionYear '2014' + + scm { + connection 'scm:git:git@github.com:Codearte/accurest.git' + developerConnection 'scm:git:git@github.com:Codearte/accurest.git' + url 'https://github.com/Codearte/accurest' + } + + licenses { + license { + name 'The Apache License, Version 2.0' + url 'http://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + + developers { + developer { + id 'jkubrynski' + name 'Jakub Kubrynski' + email 'jk ATT codearte DOTT io' + } + developer { + id 'marcingrzejszczak' + name 'Marcin Grzejszczak' + email 'marcin ATT grzejszczak DOTT pl' + } + } + } } } } } -uploadArchives.dependsOn { check } - - -task uploadSnapshotArchives { - if (shouldUploadSnapshotArchives) { - dependsOn { uploadArchives } - } - onlyIf { shouldUploadSnapshotArchives } +String repoPrefix() { + return project.name.contains('gradle') ? 'plugins' : 'libs' } -//for Travis to leverage secure variables -project.ext { - if (!hasProperty('nexusUsername') && System.env.NEXUS_USERNAME) { - nexusUsername = System.env.NEXUS_USERNAME - } - if (!hasProperty('nexusPassword') && System.env.NEXUS_PASSWORD) { - nexusPassword = System.env.NEXUS_PASSWORD - } -} - - +if (projectsToSkipPublication.any { project.name.contains(it) }) { + uploadArchives.enabled = false +} \ No newline at end of file diff --git a/gradle/releaseRoot.gradle b/gradle/releaseRoot.gradle deleted file mode 100644 index 667dcbcb82..0000000000 --- a/gradle/releaseRoot.gradle +++ /dev/null @@ -1,16 +0,0 @@ -assert project == rootProject - -project.ext { - isSnapshot = project.version.endsWith("-SNAPSHOT") - currentBranch = System.env.TRAVIS_BRANCH - isPr = !isNullOrFalse(System.env.TRAVIS_PULL_REQUEST) - doRelease = !isNullOrFalse(System.env.DO_RELEASE) - shouldUploadSnapshotArchives = isSnapshot && currentBranch == 'master' && !isPr && doRelease -} - -logger.lifecycle("Automatic snapshot release: {} (isSnapshot: {}, currentBranch: {}, isPr: {}, doRelease: {})", shouldUploadSnapshotArchives, isSnapshot, currentBranch, isPr, doRelease) - -private boolean isNullOrFalse(def env) { - env == null || env == "false" || (env instanceof Boolean && !env) -} - diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 91aa685ded..72e5e30b39 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Apr 12 23:29:55 EDT 2016 +#Wed Jun 15 17:19:08 CEST 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip diff --git a/docs.sh b/publishDocs.sh similarity index 100% rename from docs.sh rename to publishDocs.sh diff --git a/samples/messaging-camel/build.gradle b/samples/messaging-camel/build.gradle deleted file mode 100644 index f358dbffd4..0000000000 --- a/samples/messaging-camel/build.gradle +++ /dev/null @@ -1,26 +0,0 @@ -repositories { - mavenLocal() - jcenter() - maven { - url "http://repo.spring.io/snapshot" - } - maven { - url "http://repo.spring.io/milestone" - } -} - -dependencies { - compile project(':accurest-core') - compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}" - compile "org.apache.camel:camel-spring-boot-starter:${camelVersion}" - compile "org.apache.camel:camel-jms:${camelVersion}" - compile 'org.apache.activemq:activemq-camel:5.12.1' - compile 'org.apache.activemq:activemq-pool:5.12.1' - compile "org.apache.camel:camel-jackson:${camelVersion}" - - testCompile project(':accurest-messaging-root:accurest-messaging-camel') - testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" - testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { - exclude(group: 'org.codehaus.groovy') - } -} \ No newline at end of file diff --git a/samples/messaging-camel/src/main/groovy/io/codearte/accurest/samples/camel/BookDeleted.groovy b/samples/messaging-camel/src/main/groovy/io/codearte/accurest/samples/camel/BookDeleted.groovy deleted file mode 100644 index f20d028575..0000000000 --- a/samples/messaging-camel/src/main/groovy/io/codearte/accurest/samples/camel/BookDeleted.groovy +++ /dev/null @@ -1,14 +0,0 @@ -package io.codearte.accurest.samples.camel - -import com.fasterxml.jackson.annotation.JsonCreator -import groovy.transform.CompileStatic - -@CompileStatic -class BookDeleted implements Serializable { - final String bookName - - @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) - BookDeleted(String bookName) { - this.bookName = bookName - } -} diff --git a/samples/messaging-camel/src/main/groovy/io/codearte/accurest/samples/camel/BookReturned.groovy b/samples/messaging-camel/src/main/groovy/io/codearte/accurest/samples/camel/BookReturned.groovy deleted file mode 100644 index 19ca5837d9..0000000000 --- a/samples/messaging-camel/src/main/groovy/io/codearte/accurest/samples/camel/BookReturned.groovy +++ /dev/null @@ -1,14 +0,0 @@ -package io.codearte.accurest.samples.camel - -import com.fasterxml.jackson.annotation.JsonCreator -import groovy.transform.CompileStatic - -@CompileStatic -class BookReturned implements Serializable { - final String bookName - - @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) - BookReturned(String bookName) { - this.bookName = bookName - } -} diff --git a/samples/messaging-camel/src/main/groovy/io/codearte/accurest/samples/camel/CamelMessagingApplication.groovy b/samples/messaging-camel/src/main/groovy/io/codearte/accurest/samples/camel/CamelMessagingApplication.groovy deleted file mode 100644 index 26819753e5..0000000000 --- a/samples/messaging-camel/src/main/groovy/io/codearte/accurest/samples/camel/CamelMessagingApplication.groovy +++ /dev/null @@ -1,12 +0,0 @@ -package io.codearte.accurest.samples.camel - -import org.springframework.boot.SpringApplication -import org.springframework.boot.autoconfigure.SpringBootApplication - -@SpringBootApplication -class CamelMessagingApplication { - - static void main(String[] args) { - SpringApplication.run(CamelMessagingApplication.class, args) - } -} diff --git a/samples/messaging-integration/build.gradle b/samples/messaging-integration/build.gradle deleted file mode 100644 index 94be6d9087..0000000000 --- a/samples/messaging-integration/build.gradle +++ /dev/null @@ -1,22 +0,0 @@ -repositories { - mavenLocal() - jcenter() - maven { - url "http://repo.spring.io/snapshot" - } - maven { - url "http://repo.spring.io/milestone" - } -} - -dependencies { - compile project(':accurest-core') - compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}" - compile "org.springframework.boot:spring-boot-starter-integration:${springBootVersion}" - - testCompile project(':accurest-messaging-root:accurest-messaging-integration') - testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" - testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { - exclude(group: 'org.codehaus.groovy') - } -} \ No newline at end of file diff --git a/samples/messaging-integration/src/main/groovy/io/codearte/accurest/samples/messaging/BookDeleted.groovy b/samples/messaging-integration/src/main/groovy/io/codearte/accurest/samples/messaging/BookDeleted.groovy deleted file mode 100644 index abe8ce0959..0000000000 --- a/samples/messaging-integration/src/main/groovy/io/codearte/accurest/samples/messaging/BookDeleted.groovy +++ /dev/null @@ -1,14 +0,0 @@ -package io.codearte.accurest.samples.messaging - -import com.fasterxml.jackson.annotation.JsonCreator -import groovy.transform.CompileStatic - -@CompileStatic -class BookDeleted { - final String bookName - - @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) - BookDeleted(String bookName) { - this.bookName = bookName - } -} diff --git a/samples/messaging-integration/src/main/groovy/io/codearte/accurest/samples/messaging/BookReturned.groovy b/samples/messaging-integration/src/main/groovy/io/codearte/accurest/samples/messaging/BookReturned.groovy deleted file mode 100644 index cca077e266..0000000000 --- a/samples/messaging-integration/src/main/groovy/io/codearte/accurest/samples/messaging/BookReturned.groovy +++ /dev/null @@ -1,14 +0,0 @@ -package io.codearte.accurest.samples.messaging - -import com.fasterxml.jackson.annotation.JsonCreator -import groovy.transform.CompileStatic - -@CompileStatic -class BookReturned { - final String bookName - - @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) - BookReturned(String bookName) { - this.bookName = bookName - } -} diff --git a/samples/messaging-integration/src/main/groovy/io/codearte/accurest/samples/messaging/IntegrationMessagingApplication.groovy b/samples/messaging-integration/src/main/groovy/io/codearte/accurest/samples/messaging/IntegrationMessagingApplication.groovy deleted file mode 100644 index e1ec8da114..0000000000 --- a/samples/messaging-integration/src/main/groovy/io/codearte/accurest/samples/messaging/IntegrationMessagingApplication.groovy +++ /dev/null @@ -1,14 +0,0 @@ -package io.codearte.accurest.samples.messaging - -import org.springframework.boot.SpringApplication -import org.springframework.boot.autoconfigure.SpringBootApplication -import org.springframework.context.annotation.ImportResource - -@SpringBootApplication -@ImportResource("classpath*:integration-context.xml") -class IntegrationMessagingApplication { - - static void main(String[] args) { - SpringApplication.run(IntegrationMessagingApplication.class, args) - } -} diff --git a/samples/messaging-spring/build.gradle b/samples/messaging-spring/build.gradle deleted file mode 100644 index c38355e1cf..0000000000 --- a/samples/messaging-spring/build.gradle +++ /dev/null @@ -1,25 +0,0 @@ -repositories { - mavenLocal() - jcenter() - maven { - url "http://repo.spring.io/snapshot" - } - maven { - url "http://repo.spring.io/milestone" - } -} - -dependencies { - compile project(':accurest-core') - compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}" - compile "org.springframework:spring-jms:${springVersion}" - - compile 'org.apache.activemq:activemq-broker:5.12.1' - compile 'org.apache.activemq:activemq-pool:5.12.1' - - testCompile project(':accurest-messaging-root:accurest-messaging-core') - testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" - testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { - exclude(group: 'org.codehaus.groovy') - } -} \ No newline at end of file diff --git a/samples/messaging-spring/src/main/groovy/io/codearte/accurest/samples/spring/BookDeleted.groovy b/samples/messaging-spring/src/main/groovy/io/codearte/accurest/samples/spring/BookDeleted.groovy deleted file mode 100644 index 470329b7a8..0000000000 --- a/samples/messaging-spring/src/main/groovy/io/codearte/accurest/samples/spring/BookDeleted.groovy +++ /dev/null @@ -1,14 +0,0 @@ -package io.codearte.accurest.samples.spring - -import com.fasterxml.jackson.annotation.JsonCreator -import groovy.transform.CompileStatic - -@CompileStatic -class BookDeleted implements Serializable { - final String bookName - - @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) - BookDeleted(String bookName) { - this.bookName = bookName - } -} diff --git a/samples/messaging-spring/src/main/groovy/io/codearte/accurest/samples/spring/BookReturned.groovy b/samples/messaging-spring/src/main/groovy/io/codearte/accurest/samples/spring/BookReturned.groovy deleted file mode 100644 index bd13a4ff6b..0000000000 --- a/samples/messaging-spring/src/main/groovy/io/codearte/accurest/samples/spring/BookReturned.groovy +++ /dev/null @@ -1,14 +0,0 @@ -package io.codearte.accurest.samples.spring - -import com.fasterxml.jackson.annotation.JsonCreator -import groovy.transform.CompileStatic - -@CompileStatic -class BookReturned implements Serializable { - String bookName - - @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) - BookReturned(String bookName) { - this.bookName = bookName - } -} diff --git a/samples/messaging-spring/src/main/groovy/io/codearte/accurest/samples/spring/SpringMessagingApplication.groovy b/samples/messaging-spring/src/main/groovy/io/codearte/accurest/samples/spring/SpringMessagingApplication.groovy deleted file mode 100644 index 287a1e2240..0000000000 --- a/samples/messaging-spring/src/main/groovy/io/codearte/accurest/samples/spring/SpringMessagingApplication.groovy +++ /dev/null @@ -1,14 +0,0 @@ -package io.codearte.accurest.samples.spring - -import org.springframework.boot.SpringApplication -import org.springframework.boot.autoconfigure.SpringBootApplication -import org.springframework.jms.annotation.EnableJms - -@SpringBootApplication -@EnableJms -class SpringMessagingApplication { - - static void main(String[] args) { - SpringApplication.run(SpringMessagingApplication.class, args) - } -} diff --git a/samples/messaging-spring/src/test/groovy/io/codearte/accurest/samples/spring/config/AccurestSpringMessageBuilder.groovy b/samples/messaging-spring/src/test/groovy/io/codearte/accurest/samples/spring/config/AccurestSpringMessageBuilder.groovy deleted file mode 100644 index cf3294b4e1..0000000000 --- a/samples/messaging-spring/src/test/groovy/io/codearte/accurest/samples/spring/config/AccurestSpringMessageBuilder.groovy +++ /dev/null @@ -1,35 +0,0 @@ -package io.codearte.accurest.samples.spring.config - -import io.codearte.accurest.messaging.AccurestMessage -import io.codearte.accurest.messaging.AccurestMessageBuilder -import org.springframework.jms.core.MessageCreator - -import javax.jms.JMSException -import javax.jms.Message -import javax.jms.Session -/** - * @author Marcin Grzejszczak - */ -public class AccurestSpringMessageBuilder implements AccurestMessageBuilder { - - @Override - public AccurestMessage create(final T payload, final Map headers) { - MessageCreator messageCreator = new MessageCreator() { - @Override - public Message createMessage(Session session) throws JMSException { - Message message = session.createObjectMessage(payload); - headers.entrySet().each { Map.Entry entry -> - message.setObjectProperty(entry.key, entry.value) - } - return message - } - }; - - return new SpringMessage<>(messageCreator) - } - - @Override - public AccurestMessage create(Message message) { - return new SpringMessage<>(message); - } -} diff --git a/samples/messaging-spring/src/test/groovy/io/codearte/accurest/samples/spring/config/AccurestSpringMessaging.groovy b/samples/messaging-spring/src/test/groovy/io/codearte/accurest/samples/spring/config/AccurestSpringMessaging.groovy deleted file mode 100644 index 7599cbbb7f..0000000000 --- a/samples/messaging-spring/src/test/groovy/io/codearte/accurest/samples/spring/config/AccurestSpringMessaging.groovy +++ /dev/null @@ -1,77 +0,0 @@ -package io.codearte.accurest.samples.spring.config - -import io.codearte.accurest.messaging.AccurestMessage -import io.codearte.accurest.messaging.AccurestMessageBuilder -import io.codearte.accurest.messaging.AccurestMessaging -import org.slf4j.Logger -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.jms.core.JmsTemplate -import org.springframework.stereotype.Component - -import javax.jms.Message -import java.util.concurrent.TimeUnit -/** - * @author Marcin Grzejszczak - */ -@Component -public class AccurestSpringMessaging implements AccurestMessaging { - - private static final Logger log = LoggerFactory.getLogger(AccurestSpringMessaging.class); - - private final JmsTemplate jmsTemplate; - private final AccurestMessageBuilder builder; - - @Autowired - @SuppressWarnings("unchecked") - public AccurestSpringMessaging(AccurestMessageBuilder builder, JmsTemplate jmsTemplate) { - this.builder = builder - this.jmsTemplate = jmsTemplate - } - - @Override - @SuppressWarnings("unchecked") - public void send(T payload, Map headers, String destination) { - send(builder.create(payload, headers), destination); - } - - @Override - public void send(AccurestMessage message, String destination) { - try { - jmsTemplate.send(destination, ((SpringMessage) message).messageCreator) - } catch (Exception e) { - log.error("Exception occurred while trying to send a message [" + message + "] " + - "to a channel with name [" + destination + "]", e); - throw e; - } - } - - @Override - @SuppressWarnings("unchecked") - public AccurestMessage receiveMessage(String destination, long timeout, TimeUnit timeUnit) { - try { - return builder.create(jmsTemplate.receive(destination)); - } catch (Exception e) { - log.error("Exception occurred while trying to read a message from " + - " a channel with name [" + destination + "]", e); - throw new RuntimeException(e); - } - } - - @Override - public AccurestMessage receiveMessage(String destination) { - return receiveMessage(destination, 5, TimeUnit.SECONDS); - } - - @Override - @SuppressWarnings("unchecked") - public AccurestMessage create(T t, Map headers) { - return builder.create(t, headers); - } - - @Override - @SuppressWarnings("unchecked") - public AccurestMessage create(Message message) { - return builder.create(message); - } -} diff --git a/samples/messaging-spring/src/test/groovy/io/codearte/accurest/samples/spring/config/ManualAccurestConfiguration.groovy b/samples/messaging-spring/src/test/groovy/io/codearte/accurest/samples/spring/config/ManualAccurestConfiguration.groovy deleted file mode 100644 index 1cd05f86f0..0000000000 --- a/samples/messaging-spring/src/test/groovy/io/codearte/accurest/samples/spring/config/ManualAccurestConfiguration.groovy +++ /dev/null @@ -1,18 +0,0 @@ -package io.codearte.accurest.samples.spring.config - -import io.codearte.accurest.messaging.AccurestMessaging -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.jms.core.JmsTemplate -/** - * @author Marcin Grzejszczak - */ -@Configuration -class ManualAccurestConfiguration { - - @Bean - AccurestMessaging accurestMessaging(JmsTemplate jmsTemplate) { - return new AccurestSpringMessaging(new AccurestSpringMessageBuilder(), jmsTemplate); - } - -} diff --git a/samples/messaging-stream/build.gradle b/samples/messaging-stream/build.gradle deleted file mode 100644 index 54779d6866..0000000000 --- a/samples/messaging-stream/build.gradle +++ /dev/null @@ -1,22 +0,0 @@ -repositories { - mavenLocal() - jcenter() - maven { - url "http://repo.spring.io/snapshot" - } - maven { - url "http://repo.spring.io/milestone" - } -} - -dependencies { - compile project(':accurest-core') - compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}" - compile "org.springframework.cloud:spring-cloud-stream-binder-rabbit:${springStreamVersion}" - - testCompile project(':accurest-messaging-root:accurest-messaging-stream') - testCompile "org.springframework.cloud:spring-cloud-stream-test-support:${springStreamVersion}" - testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { - exclude(group: 'org.codehaus.groovy') - } -} \ No newline at end of file diff --git a/samples/messaging-stream/src/main/groovy/io/codearte/accurest/samples/messaging/BookDeleted.groovy b/samples/messaging-stream/src/main/groovy/io/codearte/accurest/samples/messaging/BookDeleted.groovy deleted file mode 100644 index abe8ce0959..0000000000 --- a/samples/messaging-stream/src/main/groovy/io/codearte/accurest/samples/messaging/BookDeleted.groovy +++ /dev/null @@ -1,14 +0,0 @@ -package io.codearte.accurest.samples.messaging - -import com.fasterxml.jackson.annotation.JsonCreator -import groovy.transform.CompileStatic - -@CompileStatic -class BookDeleted { - final String bookName - - @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) - BookDeleted(String bookName) { - this.bookName = bookName - } -} diff --git a/samples/messaging-stream/src/main/groovy/io/codearte/accurest/samples/messaging/BookReturned.groovy b/samples/messaging-stream/src/main/groovy/io/codearte/accurest/samples/messaging/BookReturned.groovy deleted file mode 100644 index cca077e266..0000000000 --- a/samples/messaging-stream/src/main/groovy/io/codearte/accurest/samples/messaging/BookReturned.groovy +++ /dev/null @@ -1,14 +0,0 @@ -package io.codearte.accurest.samples.messaging - -import com.fasterxml.jackson.annotation.JsonCreator -import groovy.transform.CompileStatic - -@CompileStatic -class BookReturned { - final String bookName - - @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) - BookReturned(String bookName) { - this.bookName = bookName - } -} diff --git a/samples/messaging-stream/src/main/groovy/io/codearte/accurest/samples/messaging/DeleteSink.groovy b/samples/messaging-stream/src/main/groovy/io/codearte/accurest/samples/messaging/DeleteSink.groovy deleted file mode 100644 index 6986da9ca8..0000000000 --- a/samples/messaging-stream/src/main/groovy/io/codearte/accurest/samples/messaging/DeleteSink.groovy +++ /dev/null @@ -1,16 +0,0 @@ -package io.codearte.accurest.samples.messaging - -import org.springframework.cloud.stream.annotation.Input -import org.springframework.cloud.stream.messaging.Sink -import org.springframework.messaging.SubscribableChannel - -/** - * @author Marcin Grzejszczak - */ -interface DeleteSink extends Sink { - - String INPUT = "delete"; - - @Input(DeleteSink.INPUT) - SubscribableChannel delete(); -} diff --git a/samples/messaging-stream/src/main/groovy/io/codearte/accurest/samples/messaging/StreamMessagingApplication.groovy b/samples/messaging-stream/src/main/groovy/io/codearte/accurest/samples/messaging/StreamMessagingApplication.groovy deleted file mode 100644 index c6285ea622..0000000000 --- a/samples/messaging-stream/src/main/groovy/io/codearte/accurest/samples/messaging/StreamMessagingApplication.groovy +++ /dev/null @@ -1,16 +0,0 @@ -package io.codearte.accurest.samples.messaging; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cloud.stream.annotation.EnableBinding -import org.springframework.cloud.stream.messaging.Sink; -import org.springframework.cloud.stream.messaging.Source; - -@SpringBootApplication -@EnableBinding([Source, Sink]) -class StreamMessagingApplication { - - static void main(String[] args) { - SpringApplication.run(StreamMessagingApplication.class, args) - } -} diff --git a/samples/samples-messaging-camel/build.gradle b/samples/samples-messaging-camel/build.gradle new file mode 100644 index 0000000000..067b6cdeb2 --- /dev/null +++ b/samples/samples-messaging-camel/build.gradle @@ -0,0 +1,44 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +repositories { + mavenLocal() + jcenter() + maven { + url "http://repo.spring.io/snapshot" + } + maven { + url "http://repo.spring.io/milestone" + } +} + +String verifier = "spring-cloud-contract-verifier" + +dependencies { + compile project(":$verifier-root:$verifier-core") + compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}" + compile "org.apache.camel:camel-spring-boot-starter:${camelVersion}" + compile "org.apache.camel:camel-jms:${camelVersion}" + compile 'org.apache.activemq:activemq-camel:5.12.1' + compile 'org.apache.activemq:activemq-pool:5.12.1' + compile "org.apache.camel:camel-jackson:${camelVersion}" + + testCompile project(":$verifier-root:$verifier-messaging-root:$verifier-camel") + testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" + testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { + exclude(group: 'org.codehaus.groovy') + } +} \ No newline at end of file diff --git a/samples/samples-messaging-camel/src/main/groovy/org/springframework/cloud/contract/verifier/samples/camel/BookDeleted.groovy b/samples/samples-messaging-camel/src/main/groovy/org/springframework/cloud/contract/verifier/samples/camel/BookDeleted.groovy new file mode 100644 index 0000000000..52af5fd871 --- /dev/null +++ b/samples/samples-messaging-camel/src/main/groovy/org/springframework/cloud/contract/verifier/samples/camel/BookDeleted.groovy @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.camel + +import com.fasterxml.jackson.annotation.JsonCreator +import groovy.transform.CompileStatic + +@CompileStatic +class BookDeleted implements Serializable { + final String bookName + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + BookDeleted(String bookName) { + this.bookName = bookName + } +} diff --git a/samples/messaging-camel/src/main/groovy/io/codearte/accurest/samples/camel/BookDeleter.groovy b/samples/samples-messaging-camel/src/main/groovy/org/springframework/cloud/contract/verifier/samples/camel/BookDeleter.groovy similarity index 56% rename from samples/messaging-camel/src/main/groovy/io/codearte/accurest/samples/camel/BookDeleter.groovy rename to samples/samples-messaging-camel/src/main/groovy/org/springframework/cloud/contract/verifier/samples/camel/BookDeleter.groovy index 9184450edc..c1ad517de9 100644 --- a/samples/messaging-camel/src/main/groovy/io/codearte/accurest/samples/camel/BookDeleter.groovy +++ b/samples/samples-messaging-camel/src/main/groovy/org/springframework/cloud/contract/verifier/samples/camel/BookDeleter.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.samples.camel +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.camel import groovy.transform.CompileStatic import groovy.util.logging.Slf4j diff --git a/samples/samples-messaging-camel/src/main/groovy/org/springframework/cloud/contract/verifier/samples/camel/BookReturned.groovy b/samples/samples-messaging-camel/src/main/groovy/org/springframework/cloud/contract/verifier/samples/camel/BookReturned.groovy new file mode 100644 index 0000000000..373743a094 --- /dev/null +++ b/samples/samples-messaging-camel/src/main/groovy/org/springframework/cloud/contract/verifier/samples/camel/BookReturned.groovy @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.camel + +import com.fasterxml.jackson.annotation.JsonCreator +import groovy.transform.CompileStatic + +@CompileStatic +class BookReturned implements Serializable { + final String bookName + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + BookReturned(String bookName) { + this.bookName = bookName + } +} diff --git a/samples/messaging-camel/src/main/groovy/io/codearte/accurest/samples/camel/BookRouteConfiguration.groovy b/samples/samples-messaging-camel/src/main/groovy/org/springframework/cloud/contract/verifier/samples/camel/BookRouteConfiguration.groovy similarity index 64% rename from samples/messaging-camel/src/main/groovy/io/codearte/accurest/samples/camel/BookRouteConfiguration.groovy rename to samples/samples-messaging-camel/src/main/groovy/org/springframework/cloud/contract/verifier/samples/camel/BookRouteConfiguration.groovy index 66f5a46535..06ed844919 100644 --- a/samples/messaging-camel/src/main/groovy/io/codearte/accurest/samples/camel/BookRouteConfiguration.groovy +++ b/samples/samples-messaging-camel/src/main/groovy/org/springframework/cloud/contract/verifier/samples/camel/BookRouteConfiguration.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.samples.camel +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.camel import org.apache.activemq.camel.component.ActiveMQComponent import org.apache.camel.RoutesBuilder diff --git a/samples/messaging-camel/src/main/groovy/io/codearte/accurest/samples/camel/BookService.groovy b/samples/samples-messaging-camel/src/main/groovy/org/springframework/cloud/contract/verifier/samples/camel/BookService.groovy similarity index 52% rename from samples/messaging-camel/src/main/groovy/io/codearte/accurest/samples/camel/BookService.groovy rename to samples/samples-messaging-camel/src/main/groovy/org/springframework/cloud/contract/verifier/samples/camel/BookService.groovy index edda66c9c7..f60ec6fbe9 100644 --- a/samples/messaging-camel/src/main/groovy/io/codearte/accurest/samples/camel/BookService.groovy +++ b/samples/samples-messaging-camel/src/main/groovy/org/springframework/cloud/contract/verifier/samples/camel/BookService.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.samples.camel +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.camel import groovy.transform.CompileStatic import groovy.util.logging.Slf4j diff --git a/samples/samples-messaging-camel/src/main/groovy/org/springframework/cloud/contract/verifier/samples/camel/CamelMessagingApplication.groovy b/samples/samples-messaging-camel/src/main/groovy/org/springframework/cloud/contract/verifier/samples/camel/CamelMessagingApplication.groovy new file mode 100644 index 0000000000..da6bddcb83 --- /dev/null +++ b/samples/samples-messaging-camel/src/main/groovy/org/springframework/cloud/contract/verifier/samples/camel/CamelMessagingApplication.groovy @@ -0,0 +1,28 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.camel + +import org.springframework.boot.SpringApplication +import org.springframework.boot.autoconfigure.SpringBootApplication + +@SpringBootApplication +class CamelMessagingApplication { + + static void main(String[] args) { + SpringApplication.run(CamelMessagingApplication.class, args) + } +} diff --git a/samples/messaging-camel/src/test/groovy/io/codearte/accurest/samples/camel/CamelMessagingApplicationSpec.groovy b/samples/samples-messaging-camel/src/test/groovy/org/springframework/cloud/contract/verifier/samples/camel/CamelMessagingApplicationSpec.groovy similarity index 58% rename from samples/messaging-camel/src/test/groovy/io/codearte/accurest/samples/camel/CamelMessagingApplicationSpec.groovy rename to samples/samples-messaging-camel/src/test/groovy/org/springframework/cloud/contract/verifier/samples/camel/CamelMessagingApplicationSpec.groovy index 0dfecf7e2e..38337f6b76 100644 --- a/samples/messaging-camel/src/test/groovy/io/codearte/accurest/samples/camel/CamelMessagingApplicationSpec.groovy +++ b/samples/samples-messaging-camel/src/test/groovy/org/springframework/cloud/contract/verifier/samples/camel/CamelMessagingApplicationSpec.groovy @@ -1,15 +1,31 @@ -package io.codearte.accurest.samples.camel +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.camel import com.jayway.jsonpath.DocumentContext import com.jayway.jsonpath.JsonPath import com.toomuchcoding.jsonassert.JsonAssertion -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.messaging.AccurestMessage -import io.codearte.accurest.messaging.AccurestMessaging -import io.codearte.accurest.messaging.AccurestObjectMapper +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage import org.apache.camel.model.ModelCamelContext import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.SpringApplicationContextLoader +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierObjectMapper import org.springframework.test.context.ContextConfiguration import spock.lang.Specification import spock.util.concurrent.PollingConditions @@ -23,12 +39,12 @@ import javax.inject.Inject public class CamelMessagingApplicationSpec extends Specification { // ALL CASES - @Inject AccurestMessaging accurestMessaging - AccurestObjectMapper accurestObjectMapper = new AccurestObjectMapper() + @Inject ContractVerifierMessaging contractVerifierMessaging + ContractVerifierObjectMapper contractVerifierObjectMapper = new ContractVerifierObjectMapper() def "should work for triggered based messaging"() { given: - def dsl = GroovyDsl.make { + def dsl = Contract.make { label 'some_label' input { triggeredBy('bookReturnedTriggered()') @@ -45,16 +61,16 @@ public class CamelMessagingApplicationSpec extends Specification { when: bookReturnedTriggered() then: - def response = accurestMessaging.receiveMessage('activemq:output') + def response = contractVerifierMessaging.receiveMessage('activemq:output') response.headers.get('BOOK-NAME') == 'foo' and: - DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload)) + DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.payload)) JsonAssertion.assertThat(parsedJson).field('bookName').isEqualTo('foo') } def "should generate tests triggered by a message"() { given: - def dsl = GroovyDsl.make { + def dsl = Contract.make { label 'some_label' input { messageFrom('jms:input') @@ -80,23 +96,23 @@ public class CamelMessagingApplicationSpec extends Specification { // generated test should look like this: //given: - AccurestMessage inputMessage = accurestMessaging.create( - accurestObjectMapper.writeValueAsString([bookName: 'foo']), + ContractVerifierMessage inputMessage = contractVerifierMessaging.create( + contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']), [sample: 'header'] ) when: - accurestMessaging.send(inputMessage, 'jms:input') + contractVerifierMessaging.send(inputMessage, 'jms:input') then: - def response = accurestMessaging.receiveMessage('jms:output') + def response = contractVerifierMessaging.receiveMessage('jms:output') response.headers.get('BOOK-NAME') == 'foo' and: - DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload)) + DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.payload)) JsonAssertion.assertThat(parsedJson).field('bookName').isEqualTo('foo') } def "should generate tests without destination, triggered by a message"() { given: - def dsl = GroovyDsl.make { + def dsl = Contract.make { label 'some_label' input { messageFrom('jms:delete') @@ -113,12 +129,12 @@ public class CamelMessagingApplicationSpec extends Specification { // generated test should look like this: //given: - AccurestMessage inputMessage = accurestMessaging.create( - accurestObjectMapper.writeValueAsString([bookName: 'foo']), + ContractVerifierMessage inputMessage = contractVerifierMessaging.create( + contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']), [sample: 'header'] ) when: - accurestMessaging.send(inputMessage, 'jms:delete') + contractVerifierMessaging.send(inputMessage, 'jms:delete') then: noExceptionThrown() bookWasDeleted() diff --git a/samples/samples-messaging-integration/build.gradle b/samples/samples-messaging-integration/build.gradle new file mode 100644 index 0000000000..990aa349b2 --- /dev/null +++ b/samples/samples-messaging-integration/build.gradle @@ -0,0 +1,40 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +repositories { + mavenLocal() + jcenter() + maven { + url "http://repo.spring.io/snapshot" + } + maven { + url "http://repo.spring.io/milestone" + } +} + +String verifier = "spring-cloud-contract-verifier" + +dependencies { + compile project(":$verifier-root:$verifier-core") + compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}" + compile "org.springframework.boot:spring-boot-starter-integration:${springBootVersion}" + + testCompile project(":$verifier-root:$verifier-messaging-root:$verifier-integration") + testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" + testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { + exclude(group: 'org.codehaus.groovy') + } +} \ No newline at end of file diff --git a/samples/samples-messaging-integration/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookDeleted.groovy b/samples/samples-messaging-integration/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookDeleted.groovy new file mode 100644 index 0000000000..e43c21c9d2 --- /dev/null +++ b/samples/samples-messaging-integration/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookDeleted.groovy @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.messaging + +import com.fasterxml.jackson.annotation.JsonCreator +import groovy.transform.CompileStatic + +@CompileStatic +class BookDeleted { + final String bookName + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + BookDeleted(String bookName) { + this.bookName = bookName + } +} diff --git a/samples/messaging-integration/src/main/groovy/io/codearte/accurest/samples/messaging/BookListener.groovy b/samples/samples-messaging-integration/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookListener.groovy similarity index 66% rename from samples/messaging-integration/src/main/groovy/io/codearte/accurest/samples/messaging/BookListener.groovy rename to samples/samples-messaging-integration/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookListener.groovy index 1ef7d26f79..e0041a8dcb 100644 --- a/samples/messaging-integration/src/main/groovy/io/codearte/accurest/samples/messaging/BookListener.groovy +++ b/samples/samples-messaging-integration/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookListener.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.samples.messaging +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.messaging import groovy.transform.CompileStatic import groovy.util.logging.Slf4j diff --git a/samples/samples-messaging-integration/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookReturned.groovy b/samples/samples-messaging-integration/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookReturned.groovy new file mode 100644 index 0000000000..130c19d468 --- /dev/null +++ b/samples/samples-messaging-integration/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookReturned.groovy @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.messaging + +import com.fasterxml.jackson.annotation.JsonCreator +import groovy.transform.CompileStatic + +@CompileStatic +class BookReturned { + final String bookName + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + BookReturned(String bookName) { + this.bookName = bookName + } +} diff --git a/samples/messaging-integration/src/main/groovy/io/codearte/accurest/samples/messaging/BookService.groovy b/samples/samples-messaging-integration/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookService.groovy similarity index 61% rename from samples/messaging-integration/src/main/groovy/io/codearte/accurest/samples/messaging/BookService.groovy rename to samples/samples-messaging-integration/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookService.groovy index f5acc1c1e8..888df79bce 100644 --- a/samples/messaging-integration/src/main/groovy/io/codearte/accurest/samples/messaging/BookService.groovy +++ b/samples/samples-messaging-integration/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookService.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.samples.messaging +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.messaging import groovy.transform.CompileStatic import groovy.util.logging.Slf4j diff --git a/samples/samples-messaging-integration/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/IntegrationMessagingApplication.groovy b/samples/samples-messaging-integration/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/IntegrationMessagingApplication.groovy new file mode 100644 index 0000000000..811fcbdfc3 --- /dev/null +++ b/samples/samples-messaging-integration/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/IntegrationMessagingApplication.groovy @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.messaging + +import org.springframework.boot.SpringApplication +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.context.annotation.ImportResource + +@SpringBootApplication +@ImportResource("classpath*:integration-context.xml") +class IntegrationMessagingApplication { + + static void main(String[] args) { + SpringApplication.run(IntegrationMessagingApplication.class, args) + } +} diff --git a/samples/messaging-integration/src/main/resources/integration-context.xml b/samples/samples-messaging-integration/src/main/resources/integration-context.xml similarity index 50% rename from samples/messaging-integration/src/main/resources/integration-context.xml rename to samples/samples-messaging-integration/src/main/resources/integration-context.xml index aa5a5cc3a5..3dd916e22f 100644 --- a/samples/messaging-integration/src/main/resources/integration-context.xml +++ b/samples/samples-messaging-integration/src/main/resources/integration-context.xml @@ -1,4 +1,20 @@ + + - - - + diff --git a/samples/messaging-integration/src/test/groovy/io/codearte/accurest/samples/messaging/IntegrationMessagingApplicationSpec.groovy b/samples/samples-messaging-integration/src/test/groovy/org/springframework/cloud/contract/verifier/samples/messaging/IntegrationMessagingApplicationSpec.groovy similarity index 61% rename from samples/messaging-integration/src/test/groovy/io/codearte/accurest/samples/messaging/IntegrationMessagingApplicationSpec.groovy rename to samples/samples-messaging-integration/src/test/groovy/org/springframework/cloud/contract/verifier/samples/messaging/IntegrationMessagingApplicationSpec.groovy index 75b453940d..7307d4ea71 100644 --- a/samples/messaging-integration/src/test/groovy/io/codearte/accurest/samples/messaging/IntegrationMessagingApplicationSpec.groovy +++ b/samples/samples-messaging-integration/src/test/groovy/org/springframework/cloud/contract/verifier/samples/messaging/IntegrationMessagingApplicationSpec.groovy @@ -1,14 +1,30 @@ -package io.codearte.accurest.samples.messaging +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.messaging import com.jayway.jsonpath.DocumentContext import com.jayway.jsonpath.JsonPath import com.toomuchcoding.jsonassert.JsonAssertion -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.messaging.AccurestMessage -import io.codearte.accurest.messaging.AccurestMessaging -import io.codearte.accurest.messaging.AccurestObjectMapper import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.SpringApplicationContextLoader +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierObjectMapper import org.springframework.test.context.ContextConfiguration import spock.lang.Specification @@ -18,13 +34,13 @@ import javax.inject.Inject public class IntegrationMessagingApplicationSpec extends Specification { // ALL CASES - @Inject AccurestMessaging accurestMessaging - AccurestObjectMapper accurestObjectMapper = new AccurestObjectMapper() + @Inject ContractVerifierMessaging contractVerifierMessaging + ContractVerifierObjectMapper contractVerifierObjectMapper = new ContractVerifierObjectMapper() def "should work for triggered based messaging"() { given: // tag::method_trigger[] - def dsl = GroovyDsl.make { + def dsl = Contract.make { // Human readable description description 'Some description' // Label by means of which the output message can be triggered @@ -51,17 +67,17 @@ public class IntegrationMessagingApplicationSpec extends Specification { when: bookReturnedTriggered() then: - def response = accurestMessaging.receiveMessage('output') + def response = contractVerifierMessaging.receiveMessage('output') response.headers.get('BOOK-NAME') == 'foo' and: - DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload)) + DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.payload)) JsonAssertion.assertThat(parsedJson).field('bookName').isEqualTo('foo') } def "should generate tests triggered by a message"() { given: // tag::message_trigger[] - def dsl = GroovyDsl.make { + def dsl = Contract.make { description 'Some Description' label 'some_label' // input is a message @@ -92,23 +108,23 @@ public class IntegrationMessagingApplicationSpec extends Specification { // generated test should look like this: //given: - AccurestMessage inputMessage = accurestMessaging.create( - accurestObjectMapper.writeValueAsString([bookName: 'foo']), + ContractVerifierMessage inputMessage = contractVerifierMessaging.create( + contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']), [sample: 'header'] ) when: - accurestMessaging.send(inputMessage, 'input') + contractVerifierMessaging.send(inputMessage, 'input') then: - def response = accurestMessaging.receiveMessage('output') + def response = contractVerifierMessaging.receiveMessage('output') response.headers.get('BOOK-NAME') == 'foo' and: - DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload)) + DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.payload)) JsonAssertion.assertThat(parsedJson).field('bookName').isEqualTo('foo') } def "should generate tests without destination, triggered by a message"() { given: - def dsl = GroovyDsl.make { + def dsl = Contract.make { label 'some_label' input { messageFrom('delete') @@ -125,12 +141,12 @@ public class IntegrationMessagingApplicationSpec extends Specification { // generated test should look like this: //given: - AccurestMessage inputMessage = accurestMessaging.create( - accurestObjectMapper.writeValueAsString([bookName: 'foo']), + ContractVerifierMessage inputMessage = contractVerifierMessaging.create( + contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']), [sample: 'header'] ) when: - accurestMessaging.send(inputMessage, 'delete') + contractVerifierMessaging.send(inputMessage, 'delete') then: noExceptionThrown() bookWasDeleted() diff --git a/samples/samples-messaging-spring/build.gradle b/samples/samples-messaging-spring/build.gradle new file mode 100644 index 0000000000..dcc70f5e6e --- /dev/null +++ b/samples/samples-messaging-spring/build.gradle @@ -0,0 +1,43 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +repositories { + mavenLocal() + jcenter() + maven { + url "http://repo.spring.io/snapshot" + } + maven { + url "http://repo.spring.io/milestone" + } +} + +String verifier = "spring-cloud-contract-verifier" + +dependencies { + compile project(":$verifier-root:$verifier-core") + compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}" + compile "org.springframework:spring-jms:${springVersion}" + + compile 'org.apache.activemq:activemq-broker:5.12.1' + compile 'org.apache.activemq:activemq-pool:5.12.1' + + testCompile project(":$verifier-root:$verifier-messaging-root:$verifier-messaging-core") + testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" + testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { + exclude(group: 'org.codehaus.groovy') + } +} \ No newline at end of file diff --git a/samples/samples-messaging-spring/src/main/groovy/org/springframework/cloud/contract/verifier/samples/spring/BookDeleted.groovy b/samples/samples-messaging-spring/src/main/groovy/org/springframework/cloud/contract/verifier/samples/spring/BookDeleted.groovy new file mode 100644 index 0000000000..3ee03c12ec --- /dev/null +++ b/samples/samples-messaging-spring/src/main/groovy/org/springframework/cloud/contract/verifier/samples/spring/BookDeleted.groovy @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.spring + +import com.fasterxml.jackson.annotation.JsonCreator +import groovy.transform.CompileStatic + +@CompileStatic +class BookDeleted implements Serializable { + final String bookName + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + BookDeleted(String bookName) { + this.bookName = bookName + } +} diff --git a/samples/messaging-spring/src/main/groovy/io/codearte/accurest/samples/spring/BookListener.groovy b/samples/samples-messaging-spring/src/main/groovy/org/springframework/cloud/contract/verifier/samples/spring/BookListener.groovy similarity index 75% rename from samples/messaging-spring/src/main/groovy/io/codearte/accurest/samples/spring/BookListener.groovy rename to samples/samples-messaging-spring/src/main/groovy/org/springframework/cloud/contract/verifier/samples/spring/BookListener.groovy index 6d56d0f594..117bf6a9b6 100644 --- a/samples/messaging-spring/src/main/groovy/io/codearte/accurest/samples/spring/BookListener.groovy +++ b/samples/samples-messaging-spring/src/main/groovy/org/springframework/cloud/contract/verifier/samples/spring/BookListener.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.samples.spring +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.spring import com.fasterxml.jackson.databind.ObjectMapper import groovy.transform.CompileStatic diff --git a/samples/samples-messaging-spring/src/main/groovy/org/springframework/cloud/contract/verifier/samples/spring/BookReturned.groovy b/samples/samples-messaging-spring/src/main/groovy/org/springframework/cloud/contract/verifier/samples/spring/BookReturned.groovy new file mode 100644 index 0000000000..a875572a76 --- /dev/null +++ b/samples/samples-messaging-spring/src/main/groovy/org/springframework/cloud/contract/verifier/samples/spring/BookReturned.groovy @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.spring + +import com.fasterxml.jackson.annotation.JsonCreator +import groovy.transform.CompileStatic + +@CompileStatic +class BookReturned implements Serializable { + String bookName + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + BookReturned(String bookName) { + this.bookName = bookName + } +} diff --git a/samples/messaging-spring/src/main/groovy/io/codearte/accurest/samples/spring/BookService.groovy b/samples/samples-messaging-spring/src/main/groovy/org/springframework/cloud/contract/verifier/samples/spring/BookService.groovy similarity index 63% rename from samples/messaging-spring/src/main/groovy/io/codearte/accurest/samples/spring/BookService.groovy rename to samples/samples-messaging-spring/src/main/groovy/org/springframework/cloud/contract/verifier/samples/spring/BookService.groovy index 5ba455d8c1..b6413c21c4 100644 --- a/samples/messaging-spring/src/main/groovy/io/codearte/accurest/samples/spring/BookService.groovy +++ b/samples/samples-messaging-spring/src/main/groovy/org/springframework/cloud/contract/verifier/samples/spring/BookService.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.samples.spring +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.spring import groovy.transform.CompileStatic import groovy.util.logging.Slf4j diff --git a/samples/samples-messaging-spring/src/main/groovy/org/springframework/cloud/contract/verifier/samples/spring/SpringMessagingApplication.groovy b/samples/samples-messaging-spring/src/main/groovy/org/springframework/cloud/contract/verifier/samples/spring/SpringMessagingApplication.groovy new file mode 100644 index 0000000000..c4a6676fb8 --- /dev/null +++ b/samples/samples-messaging-spring/src/main/groovy/org/springframework/cloud/contract/verifier/samples/spring/SpringMessagingApplication.groovy @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.spring + +import org.springframework.boot.SpringApplication +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.jms.annotation.EnableJms + +@SpringBootApplication +@EnableJms +class SpringMessagingApplication { + + static void main(String[] args) { + SpringApplication.run(SpringMessagingApplication.class, args) + } +} diff --git a/samples/messaging-spring/src/test/groovy/io/codearte/accurest/samples/spring/SpringApplicationSpec.groovy b/samples/samples-messaging-spring/src/test/groovy/org/springframework/cloud/contract/verifier/samples/spring/SpringApplicationSpec.groovy similarity index 56% rename from samples/messaging-spring/src/test/groovy/io/codearte/accurest/samples/spring/SpringApplicationSpec.groovy rename to samples/samples-messaging-spring/src/test/groovy/org/springframework/cloud/contract/verifier/samples/spring/SpringApplicationSpec.groovy index 0c79f467c2..7737cd4270 100644 --- a/samples/messaging-spring/src/test/groovy/io/codearte/accurest/samples/spring/SpringApplicationSpec.groovy +++ b/samples/samples-messaging-spring/src/test/groovy/org/springframework/cloud/contract/verifier/samples/spring/SpringApplicationSpec.groovy @@ -1,14 +1,30 @@ -package io.codearte.accurest.samples.spring +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.spring import com.jayway.jsonpath.DocumentContext import com.jayway.jsonpath.JsonPath import com.toomuchcoding.jsonassert.JsonAssertion -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.messaging.AccurestMessage -import io.codearte.accurest.messaging.AccurestMessaging -import io.codearte.accurest.messaging.AccurestObjectMapper import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.SpringApplicationContextLoader +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierObjectMapper import org.springframework.test.context.ContextConfiguration import spock.lang.Specification import spock.util.concurrent.PollingConditions @@ -22,12 +38,12 @@ import javax.inject.Inject public class SpringApplicationSpec extends Specification { // ALL CASES - @Inject AccurestMessaging accurestMessaging - AccurestObjectMapper accurestObjectMapper = new AccurestObjectMapper() + @Inject ContractVerifierMessaging contractVerifierMessaging + ContractVerifierObjectMapper contractVerifierObjectMapper = new ContractVerifierObjectMapper() def "should work for triggered based messaging"() { given: - def dsl = GroovyDsl.make { + def dsl = Contract.make { label 'some_label' input { triggeredBy('bookReturnedTriggered()') @@ -44,16 +60,16 @@ public class SpringApplicationSpec extends Specification { when: bookReturnedTriggered() then: - def response = accurestMessaging.receiveMessage('output') + def response = contractVerifierMessaging.receiveMessage('output') response.headers.get('BOOK-NAME') == 'foo' and: - DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload)) + DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.payload)) JsonAssertion.assertThat(parsedJson).field('bookName').isEqualTo('foo') } def "should generate tests triggered by a message"() { given: - def dsl = GroovyDsl.make { + def dsl = Contract.make { label 'some_label' input { messageFrom('input') @@ -78,23 +94,23 @@ public class SpringApplicationSpec extends Specification { // generated test should look like this: //given: - AccurestMessage inputMessage = accurestMessaging.create( - accurestObjectMapper.writeValueAsString([bookName: 'foo']), + ContractVerifierMessage inputMessage = contractVerifierMessaging.create( + contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']), [sample: 'header'] ) when: - accurestMessaging.send(inputMessage, 'input') + contractVerifierMessaging.send(inputMessage, 'input') then: - def response = accurestMessaging.receiveMessage('output') + def response = contractVerifierMessaging.receiveMessage('output') response.headers.get('BOOK-NAME') == 'foo' and: - DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload)) + DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.payload)) JsonAssertion.assertThat(parsedJson).field('bookName').isEqualTo('foo') } def "should generate tests without destination, triggered by a message"() { given: - def dsl = GroovyDsl.make { + def dsl = Contract.make { label 'some_label' input { messageFrom('delete') @@ -111,12 +127,12 @@ public class SpringApplicationSpec extends Specification { // generated test should look like this: //given: - AccurestMessage inputMessage = accurestMessaging.create( - accurestObjectMapper.writeValueAsString([bookName: 'foo']), + ContractVerifierMessage inputMessage = contractVerifierMessaging.create( + contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']), [sample: 'header'] ) when: - accurestMessaging.send(inputMessage, 'delete') + contractVerifierMessaging.send(inputMessage, 'delete') then: noExceptionThrown() bookWasDeleted() diff --git a/samples/samples-messaging-spring/src/test/groovy/org/springframework/cloud/contract/verifier/samples/spring/config/ContractVerifierSpringMessageBuilder.groovy b/samples/samples-messaging-spring/src/test/groovy/org/springframework/cloud/contract/verifier/samples/spring/config/ContractVerifierSpringMessageBuilder.groovy new file mode 100644 index 0000000000..fdd0094caf --- /dev/null +++ b/samples/samples-messaging-spring/src/test/groovy/org/springframework/cloud/contract/verifier/samples/spring/config/ContractVerifierSpringMessageBuilder.groovy @@ -0,0 +1,51 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.spring.config + +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessageBuilder +import org.springframework.jms.core.MessageCreator + +import javax.jms.JMSException +import javax.jms.Message +import javax.jms.Session +/** + * @author Marcin Grzejszczak + */ +public class ContractVerifierSpringMessageBuilder implements ContractVerifierMessageBuilder { + + @Override + public ContractVerifierMessage create(final T payload, final Map headers) { + MessageCreator messageCreator = new MessageCreator() { + @Override + public Message createMessage(Session session) throws JMSException { + Message message = session.createObjectMessage(payload); + headers.entrySet().each { Map.Entry entry -> + message.setObjectProperty(entry.key, entry.value) + } + return message + } + }; + + return new SpringMessage<>(messageCreator) + } + + @Override + public ContractVerifierMessage create(Message message) { + return new SpringMessage<>(message); + } +} diff --git a/samples/samples-messaging-spring/src/test/groovy/org/springframework/cloud/contract/verifier/samples/spring/config/ContractVerifierSpringMessaging.groovy b/samples/samples-messaging-spring/src/test/groovy/org/springframework/cloud/contract/verifier/samples/spring/config/ContractVerifierSpringMessaging.groovy new file mode 100644 index 0000000000..bd7e93503b --- /dev/null +++ b/samples/samples-messaging-spring/src/test/groovy/org/springframework/cloud/contract/verifier/samples/spring/config/ContractVerifierSpringMessaging.groovy @@ -0,0 +1,93 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.spring.config + +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessageBuilder +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging +import org.springframework.jms.core.JmsTemplate +import org.springframework.stereotype.Component + +import javax.jms.Message +import java.util.concurrent.TimeUnit +/** + * @author Marcin Grzejszczak + */ +@Component +public class ContractVerifierSpringMessaging implements ContractVerifierMessaging { + + private static final Logger log = LoggerFactory.getLogger(ContractVerifierSpringMessaging.class); + + private final JmsTemplate jmsTemplate; + private final ContractVerifierMessageBuilder builder; + + @Autowired + @SuppressWarnings("unchecked") + public ContractVerifierSpringMessaging(ContractVerifierMessageBuilder builder, JmsTemplate jmsTemplate) { + this.builder = builder + this.jmsTemplate = jmsTemplate + } + + @Override + @SuppressWarnings("unchecked") + public void send(T payload, Map headers, String destination) { + send(builder.create(payload, headers), destination); + } + + @Override + public void send(ContractVerifierMessage message, String destination) { + try { + jmsTemplate.send(destination, ((SpringMessage) message).messageCreator) + } catch (Exception e) { + log.error("Exception occurred while trying to send a message [" + message + "] " + + "to a channel with name [" + destination + "]", e); + throw e; + } + } + + @Override + @SuppressWarnings("unchecked") + public ContractVerifierMessage receiveMessage(String destination, long timeout, TimeUnit timeUnit) { + try { + return builder.create(jmsTemplate.receive(destination)); + } catch (Exception e) { + log.error("Exception occurred while trying to read a message from " + + " a channel with name [" + destination + "]", e); + throw new RuntimeException(e); + } + } + + @Override + public ContractVerifierMessage receiveMessage(String destination) { + return receiveMessage(destination, 5, TimeUnit.SECONDS); + } + + @Override + @SuppressWarnings("unchecked") + public ContractVerifierMessage create(T t, Map headers) { + return builder.create(t, headers); + } + + @Override + @SuppressWarnings("unchecked") + public ContractVerifierMessage create(Message message) { + return builder.create(message); + } +} diff --git a/samples/samples-messaging-spring/src/test/groovy/org/springframework/cloud/contract/verifier/samples/spring/config/ManualContractVerifierConfiguration.groovy b/samples/samples-messaging-spring/src/test/groovy/org/springframework/cloud/contract/verifier/samples/spring/config/ManualContractVerifierConfiguration.groovy new file mode 100644 index 0000000000..eb9966e3b3 --- /dev/null +++ b/samples/samples-messaging-spring/src/test/groovy/org/springframework/cloud/contract/verifier/samples/spring/config/ManualContractVerifierConfiguration.groovy @@ -0,0 +1,35 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.spring.config + +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.jms.core.JmsTemplate + +/** + * @author Marcin Grzejszczak + */ +@Configuration +class ManualContractVerifierConfiguration { + + @Bean + ContractVerifierMessaging contractVerifierMessaging(JmsTemplate jmsTemplate) { + return new ContractVerifierSpringMessaging(new ContractVerifierSpringMessageBuilder(), jmsTemplate); + } + +} diff --git a/samples/messaging-spring/src/test/groovy/io/codearte/accurest/samples/spring/config/SpringMessage.groovy b/samples/samples-messaging-spring/src/test/groovy/org/springframework/cloud/contract/verifier/samples/spring/config/SpringMessage.groovy similarity index 55% rename from samples/messaging-spring/src/test/groovy/io/codearte/accurest/samples/spring/config/SpringMessage.groovy rename to samples/samples-messaging-spring/src/test/groovy/org/springframework/cloud/contract/verifier/samples/spring/config/SpringMessage.groovy index 1f8f7cc8b6..28239443a1 100644 --- a/samples/messaging-spring/src/test/groovy/io/codearte/accurest/samples/spring/config/SpringMessage.groovy +++ b/samples/samples-messaging-spring/src/test/groovy/org/springframework/cloud/contract/verifier/samples/spring/config/SpringMessage.groovy @@ -1,6 +1,22 @@ -package io.codearte.accurest.samples.spring.config +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import io.codearte.accurest.messaging.AccurestMessage +package org.springframework.cloud.contract.verifier.samples.spring.config + +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage import org.springframework.jms.core.MessageCreator import javax.jms.Message @@ -8,7 +24,7 @@ import javax.jms.ObjectMessage /** * @author Marcin Grzejszczak */ -public class SpringMessage implements AccurestMessage { +public class SpringMessage implements ContractVerifierMessage { private final ObjectMessage messageDelegate; final MessageCreator messageCreator; diff --git a/samples/samples-messaging-stream/build.gradle b/samples/samples-messaging-stream/build.gradle new file mode 100644 index 0000000000..296798e705 --- /dev/null +++ b/samples/samples-messaging-stream/build.gradle @@ -0,0 +1,40 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +repositories { + mavenLocal() + jcenter() + maven { + url "http://repo.spring.io/snapshot" + } + maven { + url "http://repo.spring.io/milestone" + } +} + +String verifier = "spring-cloud-contract-verifier" + +dependencies { + compile project(":$verifier-root:$verifier-core") + compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}" + compile "org.springframework.cloud:spring-cloud-stream-binder-rabbit:${springStreamVersion}" + + testCompile project(":$verifier-root:$verifier-messaging-root:$verifier-stream") + testCompile "org.springframework.cloud:spring-cloud-stream-test-support:${springStreamVersion}" + testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { + exclude(group: 'org.codehaus.groovy') + } +} \ No newline at end of file diff --git a/samples/samples-messaging-stream/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookDeleted.groovy b/samples/samples-messaging-stream/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookDeleted.groovy new file mode 100644 index 0000000000..e43c21c9d2 --- /dev/null +++ b/samples/samples-messaging-stream/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookDeleted.groovy @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.messaging + +import com.fasterxml.jackson.annotation.JsonCreator +import groovy.transform.CompileStatic + +@CompileStatic +class BookDeleted { + final String bookName + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + BookDeleted(String bookName) { + this.bookName = bookName + } +} diff --git a/samples/messaging-stream/src/main/groovy/io/codearte/accurest/samples/messaging/BookListener.groovy b/samples/samples-messaging-stream/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookListener.groovy similarity index 72% rename from samples/messaging-stream/src/main/groovy/io/codearte/accurest/samples/messaging/BookListener.groovy rename to samples/samples-messaging-stream/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookListener.groovy index fe201e4636..6e70889df4 100644 --- a/samples/messaging-stream/src/main/groovy/io/codearte/accurest/samples/messaging/BookListener.groovy +++ b/samples/samples-messaging-stream/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookListener.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.samples.messaging +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.messaging import groovy.transform.CompileStatic import groovy.util.logging.Slf4j diff --git a/samples/samples-messaging-stream/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookReturned.groovy b/samples/samples-messaging-stream/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookReturned.groovy new file mode 100644 index 0000000000..130c19d468 --- /dev/null +++ b/samples/samples-messaging-stream/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookReturned.groovy @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.messaging + +import com.fasterxml.jackson.annotation.JsonCreator +import groovy.transform.CompileStatic + +@CompileStatic +class BookReturned { + final String bookName + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + BookReturned(String bookName) { + this.bookName = bookName + } +} diff --git a/samples/messaging-stream/src/main/groovy/io/codearte/accurest/samples/messaging/BookService.groovy b/samples/samples-messaging-stream/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookService.groovy similarity index 60% rename from samples/messaging-stream/src/main/groovy/io/codearte/accurest/samples/messaging/BookService.groovy rename to samples/samples-messaging-stream/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookService.groovy index ae310cb836..4e8a8adefa 100644 --- a/samples/messaging-stream/src/main/groovy/io/codearte/accurest/samples/messaging/BookService.groovy +++ b/samples/samples-messaging-stream/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/BookService.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.samples.messaging +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.messaging import groovy.transform.CompileStatic import groovy.util.logging.Slf4j diff --git a/samples/samples-messaging-stream/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/DeleteSink.groovy b/samples/samples-messaging-stream/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/DeleteSink.groovy new file mode 100644 index 0000000000..aa6e72e4e4 --- /dev/null +++ b/samples/samples-messaging-stream/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/DeleteSink.groovy @@ -0,0 +1,32 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.messaging + +import org.springframework.cloud.stream.annotation.Input +import org.springframework.cloud.stream.messaging.Sink +import org.springframework.messaging.SubscribableChannel + +/** + * @author Marcin Grzejszczak + */ +interface DeleteSink extends Sink { + + String INPUT = "delete"; + + @Input(DeleteSink.INPUT) + SubscribableChannel delete(); +} diff --git a/samples/samples-messaging-stream/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/StreamMessagingApplication.groovy b/samples/samples-messaging-stream/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/StreamMessagingApplication.groovy new file mode 100644 index 0000000000..9fa8eb8f86 --- /dev/null +++ b/samples/samples-messaging-stream/src/main/groovy/org/springframework/cloud/contract/verifier/samples/messaging/StreamMessagingApplication.groovy @@ -0,0 +1,32 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.messaging; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.stream.annotation.EnableBinding +import org.springframework.cloud.stream.messaging.Sink; +import org.springframework.cloud.stream.messaging.Source; + +@SpringBootApplication +@EnableBinding([Source, Sink]) +class StreamMessagingApplication { + + static void main(String[] args) { + SpringApplication.run(StreamMessagingApplication.class, args) + } +} diff --git a/samples/messaging-stream/src/main/resources/application.yml b/samples/samples-messaging-stream/src/main/resources/application.yml similarity index 100% rename from samples/messaging-stream/src/main/resources/application.yml rename to samples/samples-messaging-stream/src/main/resources/application.yml diff --git a/samples/messaging-stream/src/test/groovy/io/codearte/accurest/samples/messaging/StreamMessagingApplicationSpec.groovy b/samples/samples-messaging-stream/src/test/groovy/org/springframework/cloud/contract/verifier/samples/messaging/StreamMessagingApplicationSpec.groovy similarity index 55% rename from samples/messaging-stream/src/test/groovy/io/codearte/accurest/samples/messaging/StreamMessagingApplicationSpec.groovy rename to samples/samples-messaging-stream/src/test/groovy/org/springframework/cloud/contract/verifier/samples/messaging/StreamMessagingApplicationSpec.groovy index 597f693709..2aa6c241a9 100644 --- a/samples/messaging-stream/src/test/groovy/io/codearte/accurest/samples/messaging/StreamMessagingApplicationSpec.groovy +++ b/samples/samples-messaging-stream/src/test/groovy/org/springframework/cloud/contract/verifier/samples/messaging/StreamMessagingApplicationSpec.groovy @@ -1,14 +1,30 @@ -package io.codearte.accurest.samples.messaging +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.samples.messaging import com.jayway.jsonpath.DocumentContext import com.jayway.jsonpath.JsonPath import com.toomuchcoding.jsonassert.JsonAssertion -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.messaging.AccurestMessage -import io.codearte.accurest.messaging.AccurestMessaging -import io.codearte.accurest.messaging.AccurestObjectMapper +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.SpringApplicationContextLoader +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierObjectMapper import org.springframework.test.context.ContextConfiguration import spock.lang.Specification @@ -21,12 +37,12 @@ import javax.inject.Inject public class StreamMessagingApplicationSpec extends Specification { // ALL CASES - @Inject AccurestMessaging accurestMessaging - AccurestObjectMapper accurestObjectMapper = new AccurestObjectMapper() + @Inject ContractVerifierMessaging contractVerifierMessaging + ContractVerifierObjectMapper contractVerifierObjectMapper = new ContractVerifierObjectMapper() def "should work for triggered based messaging"() { given: - def dsl = GroovyDsl.make { + def dsl = Contract.make { label 'some_label' input { triggeredBy('bookReturnedTriggered()') @@ -43,16 +59,16 @@ public class StreamMessagingApplicationSpec extends Specification { when: bookReturnedTriggered() then: - def response = accurestMessaging.receiveMessage('output') + def response = contractVerifierMessaging.receiveMessage('output') response.headers.get('BOOK-NAME') == 'foo' and: - DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload)) + DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.payload)) JsonAssertion.assertThat(parsedJson).field('bookName').isEqualTo('foo') } def "should generate tests triggered by a message"() { given: - def dsl = GroovyDsl.make { + def dsl = Contract.make { label 'some_label' input { messageFrom('input') @@ -77,23 +93,23 @@ public class StreamMessagingApplicationSpec extends Specification { // generated test should look like this: //given: - AccurestMessage inputMessage = accurestMessaging.create( - accurestObjectMapper.writeValueAsString([bookName: 'foo']), + ContractVerifierMessage inputMessage = contractVerifierMessaging.create( + contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']), [sample: 'header'] ) when: - accurestMessaging.send(inputMessage, 'input') + contractVerifierMessaging.send(inputMessage, 'input') then: - def response = accurestMessaging.receiveMessage('output') + def response = contractVerifierMessaging.receiveMessage('output') response.headers.get('BOOK-NAME') == 'foo' and: - DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload)) + DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.payload)) JsonAssertion.assertThat(parsedJson).field('bookName').isEqualTo('foo') } def "should generate tests without destination, triggered by a message"() { given: - def dsl = GroovyDsl.make { + def dsl = Contract.make { label 'some_label' input { messageFrom('delete') @@ -110,12 +126,12 @@ public class StreamMessagingApplicationSpec extends Specification { // generated test should look like this: //given: - AccurestMessage inputMessage = accurestMessaging.create( - accurestObjectMapper.writeValueAsString([bookName: 'foo']), + ContractVerifierMessage inputMessage = contractVerifierMessaging.create( + contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']), [sample: 'header'] ) when: - accurestMessaging.send(inputMessage, 'delete') + contractVerifierMessaging.send(inputMessage, 'delete') then: noExceptionThrown() bookWasDeleted() diff --git a/scripts/runTests.sh b/scripts/runTests.sh index 4658a122d2..ccb87af81b 100755 --- a/scripts/runTests.sh +++ b/scripts/runTests.sh @@ -3,17 +3,19 @@ set -o errexit mkdir -p build -GRADLE_OUTPUT=`./gradlew cV --quiet` -ACCUREST_VERSION=`echo ${GRADLE_OUTPUT##*:}` -export ACCUREST_VERSION=${ACCUREST_VERSION} +CONTRACT_VERIFIER_VERSION=1.0.0.BUILD-SNAPSHOT +export CONTRACT_VERIFIER_VERSION=${CONTRACT_VERIFIER_VERSION} -echo "Current accurest version is ${ACCUREST_VERSION}" +echo "Current Spring Cloud Contract Verifier version is ${CONTRACT_VERIFIER_VERSION}" cd build echo "Cloning samples" git clone https://github.com/Codearte/accurest-samples cd accurest-samples +echo "Using the rebranding branch" +git checkout rebranding + echo "Running Gradle tests" . ./runTests.sh diff --git a/settings.gradle b/settings.gradle index 7c598a3401..c86dce469d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,29 +1,37 @@ -include 'docs' -include "accurest-core", "accurest-gradle-plugin", 'accurest-converters', 'accurest-testing-utils' +String verifier = "spring-cloud-contract-verifier" +String stubRunner = "spring-cloud-contract-stub-runner" -include ':accurest-messaging:accurest-messaging-core' -include ':accurest-messaging:accurest-messaging-integration' -include ':accurest-messaging:accurest-messaging-stream' -include ':accurest-messaging:accurest-messaging-camel' +rootProject.name = "$verifier-parent" -include ':stub-runner:stub-runner' -include ':stub-runner:stub-runner-spring' -include ':stub-runner:stub-runner-boot' -include ':stub-runner:stub-runner-spring-cloud' -include ':stub-runner:stub-runner-junit' +include "docs" -include ':stub-runner:stub-runner-messaging:stub-runner-messaging-integration' -include ':stub-runner:stub-runner-messaging:stub-runner-messaging-stream' -include ':stub-runner:stub-runner-messaging:stub-runner-messaging-camel' +include ":$verifier:$verifier-core", + ":$verifier:$verifier-gradle-plugin", + ":$verifier:$verifier-converters", + ":$verifier:$verifier-testing-utils" -include ':samples:messaging-stream' -include ':samples:messaging-integration' -include ':samples:messaging-camel' -include ':samples:messaging-spring' +include ":$verifier:$verifier-messaging:$verifier-messaging-core", + ":$verifier:$verifier-messaging:$verifier-integration", + ":$verifier:$verifier-messaging:$verifier-stream", + ":$verifier:$verifier-messaging:$verifier-camel" -rootProject.name = "accurest" +include ":$stubRunner:$stubRunner", + ":$stubRunner:$stubRunner-spring", + ":$stubRunner:$stubRunner-boot", + ":$stubRunner:$stubRunner-spring-cloud", + ":$stubRunner:$stubRunner-junit" + +include ":$stubRunner:$stubRunner-messaging:$stubRunner-integration", + ":$stubRunner:$stubRunner-messaging:$stubRunner-stream", + ":$stubRunner:$stubRunner-messaging:$stubRunner-camel" + +include ":samples:samples-messaging-stream", + ":samples:samples-messaging-integration", + ":samples:samples-messaging-camel", + ":samples:samples-messaging-spring" //to prevent StackOverflow in Sonar -project(":stub-runner").name = "stub-runner-root" -project(":accurest-messaging").name = "accurest-messaging-root" -project(":stub-runner:stub-runner-messaging").name = "stub-runner-messaging-root" +project(":$verifier").name = "$verifier-root" +project(":$stubRunner").name = "$stubRunner-root" +project(":$verifier:$verifier-messaging").name = "$verifier-messaging-root" +project(":$stubRunner:$stubRunner-messaging").name = "$stubRunner-messaging-root" diff --git a/stub-runner/stub-runner-boot/README.adoc b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/README.adoc similarity index 66% rename from stub-runner/stub-runner-boot/README.adoc rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/README.adoc index 78cb519824..24f7712612 100644 --- a/stub-runner/stub-runner-boot/README.adoc +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/README.adoc @@ -1,8 +1,6 @@ === Stub Runner Boot -WARNING: Feature available since {messaging_version} - -Accurest Stub Runner Boot is a Spring Boot application that exposes REST endpoints to +Spring Cloud Contract Verifier Stub Runner Boot is a Spring Boot application that exposes REST endpoints to trigger the messaging labels and to access started WireMock servers. One of the usecases is to run some smoke (end to end) tests on a deployed application. You can read @@ -14,7 +12,7 @@ Just add the [source,groovy,indent=0] ---- -compile "io.codearte.accurest:stub-runner-boot:${accurestVersion}" +compile "org.springframework.cloud.contract:stub-runner-boot:${verifierVersion}" ---- and a messaging implementation: @@ -22,11 +20,11 @@ and a messaging implementation: [source,groovy,indent=0] ---- // for Apache Camel -compile "io.codearte.accurest:stub-runner-messaging-camel:${accurestVersion}" +compile "org.springframework.cloud.contract:spring-cloud-contract-stub-runner-messaging-camel:${verifierVersion}" // for Spring Integration -compile "io.codearte.accurest:stub-runner-messaging-integration:${accurestVersion}" +compile "org.springframework.cloud.contract:spring-cloud-contract-stub-runner-messaging-integration:${verifierVersion}" // for Spring Cloud Stream -compile "io.codearte.accurest:stub-runner-messaging-stream:${accurestVersion}" +compile "org.springframework.cloud.contract:spring-cloud-contract-stub-runner-messaging-stream:${verifierVersion}" ---- Build a fat-jar and you're ready to go! @@ -52,5 +50,5 @@ For Messaging [source,groovy,indent=0] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/boot/StubRunnerBootSpec.groovy[tags=boot_usage] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/boot/StubRunnerBootSpec.groovy[tags=boot_usage] ---- \ No newline at end of file diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/build.gradle b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/build.gradle new file mode 100644 index 0000000000..a86573fc3a --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/build.gradle @@ -0,0 +1,40 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +repositories { + mavenLocal() + jcenter() + maven { + url "http://repo.spring.io/snapshot" + } + maven { + url "http://repo.spring.io/milestone" + } +} + +String stubRunner = "spring-cloud-contract-stub-runner" + +dependencies { + compile project(":$stubRunner-root:$stubRunner-spring") + compile "org.springframework.boot:spring-boot-starter-web:${springBootVersion}" + + testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" + testCompile project(":$stubRunner-root:$stubRunner-messaging-root:$stubRunner-stream") + testCompile 'com.jayway.restassured:spring-mock-mvc:2.9.0' + testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { + exclude(group: 'org.codehaus.groovy') + } +} \ No newline at end of file diff --git a/stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/HttpStubsController.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/main/groovy/org/springframework/cloud/contract/stubrunner/boot/HttpStubsController.groovy similarity index 55% rename from stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/HttpStubsController.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/main/groovy/org/springframework/cloud/contract/stubrunner/boot/HttpStubsController.groovy index 9a4806edc9..35730cd6ff 100644 --- a/stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/HttpStubsController.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/main/groovy/org/springframework/cloud/contract/stubrunner/boot/HttpStubsController.groovy @@ -1,7 +1,23 @@ -package io.codearte.accurest.stubrunner.boot +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.boot -import io.codearte.accurest.stubrunner.StubRunning import org.springframework.beans.factory.annotation.Autowired +import org.springframework.cloud.contract.stubrunner.StubRunning import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.PathVariable diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/main/groovy/org/springframework/cloud/contract/stubrunner/boot/StubRunnerBoot.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/main/groovy/org/springframework/cloud/contract/stubrunner/boot/StubRunnerBoot.groovy new file mode 100644 index 0000000000..daedaba6d6 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/main/groovy/org/springframework/cloud/contract/stubrunner/boot/StubRunnerBoot.groovy @@ -0,0 +1,52 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.boot + +import org.springframework.boot.SpringApplication +import org.springframework.boot.autoconfigure.AutoConfigureAfter +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean +import org.springframework.cloud.contract.stubrunner.spring.StubRunnerConfiguration +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessageBuilder +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging +import org.springframework.cloud.contract.verifier.messaging.noop.NoOpContractVerifierMessageBuilder +import org.springframework.cloud.contract.verifier.messaging.noop.NoOpContractVerifierMessaging +import org.springframework.context.annotation.Bean + +/** + * @author Marcin Grzejszczak + */ +@SpringBootApplication +@AutoConfigureAfter(StubRunnerConfiguration.class) +class StubRunnerBoot { + + static void main(String[] args) { + SpringApplication.run(StubRunnerBoot.class, args); + } + + @Bean + @ConditionalOnMissingBean + ContractVerifierMessaging noOpContractVerifierMessaging() { + return new NoOpContractVerifierMessaging() + } + + @Bean + @ConditionalOnMissingBean + ContractVerifierMessageBuilder noOpContractVerifierMessageBuilder() { + return new NoOpContractVerifierMessageBuilder() + } +} diff --git a/stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/TriggerController.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/main/groovy/org/springframework/cloud/contract/stubrunner/boot/TriggerController.groovy similarity index 69% rename from stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/TriggerController.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/main/groovy/org/springframework/cloud/contract/stubrunner/boot/TriggerController.groovy index 7bb1a002f7..d06760166a 100644 --- a/stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/TriggerController.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/main/groovy/org/springframework/cloud/contract/stubrunner/boot/TriggerController.groovy @@ -1,8 +1,24 @@ -package io.codearte.accurest.stubrunner.boot +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.boot import groovy.util.logging.Slf4j -import io.codearte.accurest.stubrunner.StubFinder import org.springframework.beans.factory.annotation.Autowired +import org.springframework.cloud.contract.stubrunner.StubFinder import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.PathVariable diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/main/resources/META-INF/spring.factories b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/main/resources/META-INF/spring.factories similarity index 60% rename from stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/main/resources/META-INF/spring.factories rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/main/resources/META-INF/spring.factories index bb95d2a818..31aea03047 100644 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/main/resources/META-INF/spring.factories @@ -1,3 +1,3 @@ # Auto Configuration org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -io.codearte.accurest.stubrunner.messaging.camel.StubRunnerCamelConfiguration +org.springframework.cloud.contract.stubrunner.spring.StubRunnerConfiguration diff --git a/stub-runner/stub-runner-boot/src/test/groovy/io/codearte/accurest/stubrunner/boot/StubRunnerBootSpec.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/test/groovy/org/springframework/cloud/contract/stubrunner/boot/StubRunnerBootSpec.groovy similarity index 62% rename from stub-runner/stub-runner-boot/src/test/groovy/io/codearte/accurest/stubrunner/boot/StubRunnerBootSpec.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/test/groovy/org/springframework/cloud/contract/stubrunner/boot/StubRunnerBootSpec.groovy index 5a02291f2b..40a2e22f41 100644 --- a/stub-runner/stub-runner-boot/src/test/groovy/io/codearte/accurest/stubrunner/boot/StubRunnerBootSpec.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/test/groovy/org/springframework/cloud/contract/stubrunner/boot/StubRunnerBootSpec.groovy @@ -1,10 +1,26 @@ -package io.codearte.accurest.stubrunner.boot +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.boot import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc import groovy.json.JsonSlurper -import io.codearte.accurest.stubrunner.StubRunning import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.SpringApplicationContextLoader +import org.springframework.cloud.contract.stubrunner.StubRunning import org.springframework.cloud.stream.annotation.EnableBinding import org.springframework.context.annotation.Configuration import org.springframework.test.context.ContextConfiguration @@ -31,7 +47,7 @@ class StubRunnerBootSpec extends Specification { String response = RestAssuredMockMvc.get('/stubs').body.asString() then: def root = new JsonSlurper().parseText(response) - root.'io.codearte.accurest.stubs:streamService:0.0.1-SNAPSHOT:stubs' instanceof Integer + root.'org.springframework.cloud.contract.verifier.stubs:streamService:0.0.1-SNAPSHOT:stubs' instanceof Integer } def 'should return a port on which a [#stubId] stub is running'() { @@ -41,10 +57,10 @@ class StubRunnerBootSpec extends Specification { response.statusCode == 200 response.body.as(Integer) > 0 where: - stubId << ['io.codearte.accurest.stubs:streamService:+:stubs', - 'io.codearte.accurest.stubs:streamService:0.0.1-SNAPSHOT:stubs', - 'io.codearte.accurest.stubs:streamService:+', - 'io.codearte.accurest.stubs:streamService', + stubId << ['org.springframework.cloud.contract.verifier.stubs:streamService:+:stubs', + 'org.springframework.cloud.contract.verifier.stubs:streamService:0.0.1-SNAPSHOT:stubs', + 'org.springframework.cloud.contract.verifier.stubs:streamService:+', + 'org.springframework.cloud.contract.verifier.stubs:streamService', 'streamService'] } @@ -60,7 +76,7 @@ class StubRunnerBootSpec extends Specification { String response = RestAssuredMockMvc.get('/triggers').body.asString() then: def root = new JsonSlurper().parseText(response) - root.'io.codearte.accurest.stubs:streamService:0.0.1-SNAPSHOT:stubs'?.containsAll(["delete_book","return_book_1","return_book_2"]) + root.'org.springframework.cloud.contract.verifier.stubs:streamService:0.0.1-SNAPSHOT:stubs'?.containsAll(["delete_book","return_book_1","return_book_2"]) } def 'should trigger a messaging label'() { @@ -86,7 +102,7 @@ class StubRunnerBootSpec extends Specification { and: 1 * stubRunning.trigger(stubId, 'delete_book') where: - stubId << ['io.codearte.accurest.stubs:streamService:stubs', 'io.codearte.accurest.stubs:streamService', 'streamService'] + stubId << ['org.springframework.cloud.contract.verifier.stubs:streamService:stubs', 'org.springframework.cloud.contract.verifier.stubs:streamService', 'streamService'] } def 'should return when trigger is missing'() { @@ -95,7 +111,7 @@ class StubRunnerBootSpec extends Specification { then: response.statusCode == 404 def root = new JsonSlurper().parseText(response.body.asString()) - root.'io.codearte.accurest.stubs:streamService:0.0.1-SNAPSHOT:stubs'?.containsAll(["delete_book","return_book_1","return_book_2"]) + root.'org.springframework.cloud.contract.verifier.stubs:streamService:0.0.1-SNAPSHOT:stubs'?.containsAll(["delete_book","return_book_1","return_book_2"]) } } diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/test/resources/application.yml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/test/resources/application.yml new file mode 100644 index 0000000000..9b34d9d617 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/test/resources/application.yml @@ -0,0 +1,2 @@ +stubrunner.stubs.repository.root: classpath:m2repo/repository/ +stubrunner.stubs.ids: org.springframework.cloud.contract.verifier.stubs:streamService \ No newline at end of file diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT-stubs.jar b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT-stubs.jar new file mode 100644 index 0000000000..4f874c7251 Binary files /dev/null and b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT-stubs.jar differ diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT.pom b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT.pom new file mode 100644 index 0000000000..8613d57be0 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT.pom @@ -0,0 +1,25 @@ + + + + + 4.0.0 + org.springframework.cloud.contract.verifier.stubs + streamService + 0.0.1-SNAPSHOT + pom + diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/maven-metadata.xml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/maven-metadata.xml new file mode 100644 index 0000000000..001cf26899 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/maven-metadata.xml @@ -0,0 +1,28 @@ + + + + + org.springframework.cloud.contract.verifier.stubs + streamService + 0.0.1-SNAPSHOT + + + 0.0.1-SNAPSHOT + + 20160409062112 + + diff --git a/stub-runner/stub-runner-junit/README.adoc b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/README.adoc similarity index 59% rename from stub-runner/stub-runner-junit/README.adoc rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/README.adoc index d55abedcef..6fa5144dd0 100644 --- a/stub-runner/stub-runner-junit/README.adoc +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/README.adoc @@ -4,7 +4,7 @@ Stub Runner comes with a JUnit rule thanks to which you can very easily download [source,java,indent=0] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleJUnitTest.java[tags=classrule] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleJUnitTest.java[tags=classrule] ---- After that rule gets executed Stub Runner connects to your Maven repository and for the given list of dependencies tries to: @@ -18,25 +18,25 @@ After that rule gets executed Stub Runner connects to your Maven repository and Stub Runner uses https://wiki.eclipse.org/Aether[Eclipse Aether] mechanism to download the Maven dependencies. Check their https://wiki.eclipse.org/Aether[docs] for more information. -Since the `AccurestRule` implements the `StubFinder` it allows you to find the started stubs: +Since the `StubRunnerRule` implements the `StubFinder` it allows you to find the started stubs: [source,groovy,indent=0] ---- -include::../stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubFinder.groovy[] +include::../spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubFinder.groovy[] ---- Example of usage in Spock tests: [source,groovy,indent=0] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleSpec.groovy[tags=classrule] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleSpec.groovy[tags=classrule] ---- Example of usage in JUnit tests: [source,java,indent=0] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleJUnitTest.java[tags=test] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleJUnitTest.java[tags=test] ---- Check the *Common properties for JUnit and Spring* for more information on how to apply global configuration of Stub Runner. @@ -48,18 +48,18 @@ JUnit rule. ==== Fluent API -When using the `AccurestRule` you can add a stub to download and then pass the port for the last downloaded stub. +When using the `StubRunnerRule` you can add a stub to download and then pass the port for the last downloaded stub. [source,java,indent=0] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleCustomPortJUnitTest.java[tags=classrule_with_port] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleCustomPortJUnitTest.java[tags=classrule_with_port] ---- You can see that for this example the following test is valid: [source,java,indent=0] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleCustomPortJUnitTest.java[tags=test_with_port] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleCustomPortJUnitTest.java[tags=test_with_port] ---- diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/build.gradle b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/build.gradle new file mode 100644 index 0000000000..3349027ab9 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/build.gradle @@ -0,0 +1,35 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +description = 'JUnit rule for stub-runner' + +String stubRunner = "spring-cloud-contract-stub-runner" + +dependencies { + compile project(":$stubRunner-root:$stubRunner") + + compile localGroovy() + compile 'junit:junit:4.12' + + testCompile('org.spockframework:spock-core:1.0-groovy-2.4') { + exclude(group: 'org.codehaus.groovy') + } + testCompile 'cglib:cglib-nodep:2.2' + testCompile 'org.objenesis:objenesis:2.1' + testCompile 'ch.qos.logback:logback-classic:1.1.3' + testCompile 'org.assertj:assertj-core:2.3.0' + testCompile 'org.apache.commons:commons-io:1.3.2' +} diff --git a/stub-runner/stub-runner-junit/src/main/groovy/io/codearte/accurest/stubrunner/junit/AccurestRule.java b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/main/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRule.java similarity index 65% rename from stub-runner/stub-runner-junit/src/main/groovy/io/codearte/accurest/stubrunner/junit/AccurestRule.java rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/main/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRule.java index fdc76d786a..30f888c6be 100644 --- a/stub-runner/stub-runner-junit/src/main/groovy/io/codearte/accurest/stubrunner/junit/AccurestRule.java +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/main/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRule.java @@ -1,16 +1,20 @@ -package io.codearte.accurest.stubrunner.junit; +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import io.codearte.accurest.dsl.GroovyDsl; -import io.codearte.accurest.stubrunner.BatchStubRunner; -import io.codearte.accurest.stubrunner.BatchStubRunnerFactory; -import io.codearte.accurest.stubrunner.RunningStubs; -import io.codearte.accurest.stubrunner.StubConfiguration; -import io.codearte.accurest.stubrunner.StubFinder; -import io.codearte.accurest.stubrunner.StubRunnerOptions; -import io.codearte.accurest.stubrunner.StubRunnerOptionsBuilder; -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; +package org.springframework.cloud.contract.stubrunner.junit; import java.net.URL; import java.util.Arrays; @@ -18,12 +22,24 @@ import java.util.Collection; import java.util.List; import java.util.Map; +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; +import org.springframework.cloud.contract.stubrunner.BatchStubRunner; +import org.springframework.cloud.contract.stubrunner.BatchStubRunnerFactory; +import org.springframework.cloud.contract.stubrunner.RunningStubs; +import org.springframework.cloud.contract.stubrunner.StubConfiguration; +import org.springframework.cloud.contract.stubrunner.StubFinder; +import org.springframework.cloud.contract.stubrunner.StubRunnerOptions; +import org.springframework.cloud.contract.stubrunner.StubRunnerOptionsBuilder; +import org.springframework.cloud.contract.verifier.dsl.Contract; + /** * JUnit class rule that allows you to download the provided stubs. * * @author Marcin Grzejszczak */ -public class AccurestRule implements TestRule, StubFinder { +public class StubRunnerRule implements TestRule, StubFinder { private static final String DELIMITER = ":"; private static final String LATEST_VERSION = "+"; @@ -63,7 +79,7 @@ public class AccurestRule implements TestRule, StubFinder { * * @see StubRunnerOptions */ - public AccurestRule options(StubRunnerOptions stubRunnerOptions) { + public StubRunnerRule options(StubRunnerOptions stubRunnerOptions) { stubRunnerOptionsBuilder.withOptions(stubRunnerOptions); return this; } @@ -71,7 +87,7 @@ public class AccurestRule implements TestRule, StubFinder { /** * Min value of port for WireMock server */ - public AccurestRule minPort(int minPort) { + public StubRunnerRule minPort(int minPort) { stubRunnerOptionsBuilder.withMinPort(minPort); return this; } @@ -79,7 +95,7 @@ public class AccurestRule implements TestRule, StubFinder { /** * Max value of port for WireMock server */ - public AccurestRule maxPort(int maxPort) { + public StubRunnerRule maxPort(int maxPort) { stubRunnerOptionsBuilder.withMaxPort(maxPort); return this; } @@ -87,7 +103,7 @@ public class AccurestRule implements TestRule, StubFinder { /** * String URI of repository containing stubs */ - public AccurestRule repoRoot(String repoRoot) { + public StubRunnerRule repoRoot(String repoRoot) { stubRunnerOptionsBuilder.withStubRepositoryRoot(repoRoot); return this; } @@ -95,7 +111,7 @@ public class AccurestRule implements TestRule, StubFinder { /** * Should download stubs or use only the local repository */ - public AccurestRule workOffline(boolean workOffline) { + public StubRunnerRule workOffline(boolean workOffline) { stubRunnerOptionsBuilder.withWorkOffline(workOffline); return this; } @@ -103,7 +119,7 @@ public class AccurestRule implements TestRule, StubFinder { /** * Group Id, artifact Id, version and classifier of a single stub to download */ - public AccurestRule downloadStub(String groupId, String artifactId, String version, String classifier) { + public StubRunnerRule downloadStub(String groupId, String artifactId, String version, String classifier) { stubRunnerOptionsBuilder.withStubs(groupId + DELIMITER + artifactId + DELIMITER + version + DELIMITER + classifier); return this; } @@ -111,7 +127,7 @@ public class AccurestRule implements TestRule, StubFinder { /** * Group Id, artifact Id and classifier of a single stub to download in the latest version */ - public AccurestRule downloadLatestStub(String groupId, String artifactId, String classifier) { + public StubRunnerRule downloadLatestStub(String groupId, String artifactId, String classifier) { stubRunnerOptionsBuilder.withStubs(groupId + DELIMITER + artifactId + DELIMITER + LATEST_VERSION + DELIMITER + classifier); return this; } @@ -119,7 +135,7 @@ public class AccurestRule implements TestRule, StubFinder { /** * Group Id, artifact Id and version of a single stub to download */ - public AccurestRule downloadStub(String groupId, String artifactId, String version) { + public StubRunnerRule downloadStub(String groupId, String artifactId, String version) { stubRunnerOptionsBuilder.withStubs(groupId + DELIMITER + artifactId + DELIMITER + version); return this; } @@ -127,7 +143,7 @@ public class AccurestRule implements TestRule, StubFinder { /** * Group Id, artifact Id of a single stub to download. Default classifier will be picked. */ - public AccurestRule downloadStub(String groupId, String artifactId) { + public StubRunnerRule downloadStub(String groupId, String artifactId) { stubRunnerOptionsBuilder.withStubs(groupId + DELIMITER + artifactId); return this; } @@ -135,7 +151,7 @@ public class AccurestRule implements TestRule, StubFinder { /** * Ivy notation of a single stub to download. */ - public AccurestRule downloadStub(String ivyNotation) { + public StubRunnerRule downloadStub(String ivyNotation) { stubRunnerOptionsBuilder.withStubs(ivyNotation); return this; } @@ -143,7 +159,7 @@ public class AccurestRule implements TestRule, StubFinder { /** * Stubs to download in Ivy notations */ - public AccurestRule downloadStubs(String... ivyNotations) { + public StubRunnerRule downloadStubs(String... ivyNotations) { stubRunnerOptionsBuilder.withStubs(Arrays.asList(ivyNotations)); return this; } @@ -151,7 +167,7 @@ public class AccurestRule implements TestRule, StubFinder { /** * Stubs to download in Ivy notations */ - public AccurestRule downloadStubs(List ivyNotations) { + public StubRunnerRule downloadStubs(List ivyNotations) { stubRunnerOptionsBuilder.withStubs(ivyNotations); return this; } @@ -159,7 +175,7 @@ public class AccurestRule implements TestRule, StubFinder { /** * Appends port to last added stub */ - public AccurestRule withPort(Integer port) { + public StubRunnerRule withPort(Integer port) { stubRunnerOptionsBuilder.withPort(port); return this; } @@ -180,8 +196,8 @@ public class AccurestRule implements TestRule, StubFinder { } @Override - public Map> getAccurestContracts() { - return stubFinder.getAccurestContracts(); + public Map> getContracts() { + return stubFinder.getContracts(); } @Override diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleCustomPortJUnitTest.java b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleCustomPortJUnitTest.java new file mode 100644 index 0000000000..06519312b3 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleCustomPortJUnitTest.java @@ -0,0 +1,85 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.junit; + +import java.io.InputStream; +import java.net.URI; + +import org.apache.commons.io.IOUtils; +import org.assertj.core.api.BDDAssertions; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; + +import static org.assertj.core.api.BDDAssertions.then; + +/** + * @author Marcin Grzejszczak + */ +public class StubRunnerRuleCustomPortJUnitTest { + + @BeforeClass + @AfterClass + public static void setupProps() { + System.getProperties().setProperty("stubrunner.stubs.repository.root", ""); + System.getProperties().setProperty("stubrunner.stubs.classifier", "stubs"); + } + + // tag::classrule_with_port[] + @ClassRule public static StubRunnerRule rule = new StubRunnerRule() + .repoRoot(repoRoot()) + .downloadStub("org.springframework.cloud.contract.verifier.stubs", "loanIssuance") + .withPort(12345) + .downloadStub("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer:12346"); + // end::classrule_with_port[] + + @Test + public void should_start_wiremock_servers() throws Exception { + // expect: 'WireMocks are running' + then(rule.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance")).isNotNull(); + then(rule.findStubUrl("loanIssuance")).isNotNull(); + then(rule.findStubUrl("loanIssuance")).isEqualTo(rule.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance")); + then(rule.findStubUrl("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isNotNull(); + // and: + BDDAssertions.then(rule.findAllRunningStubs().isPresent("loanIssuance")).isTrue(); + BDDAssertions.then(rule.findAllRunningStubs().isPresent("org.springframework.cloud.contract.verifier.stubs", "fraudDetectionServer")).isTrue(); + BDDAssertions.then(rule.findAllRunningStubs().isPresent("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isTrue(); + // and: 'Stubs were registered' + then(httpGet(rule.findStubUrl("loanIssuance").toString() + "/name")).isEqualTo("loanIssuance"); + then(httpGet(rule.findStubUrl("fraudDetectionServer").toString() + "/name")).isEqualTo("fraudDetectionServer"); + // and: 'The port is fixed' + // tag::test_with_port[] + then(rule.findStubUrl("loanIssuance")).isEqualTo(URI.create("http://localhost:12345").toURL()); + then(rule.findStubUrl("fraudDetectionServer")).isEqualTo(URI.create("http://localhost:12346").toURL()); + // end::test_with_port[] + } + + private static String repoRoot() { + try { + return StubRunnerRuleCustomPortJUnitTest.class.getResource("/m2repo/repository/").toURI().toString(); + } catch (Exception e) { + return ""; + } + } + + private String httpGet(String url) throws Exception { + try(InputStream stream = URI.create(url).toURL().openStream()) { + return IOUtils.toString(stream); + } + } +} diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleJUnitTest.java b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleJUnitTest.java new file mode 100644 index 0000000000..e5ae1d1c15 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleJUnitTest.java @@ -0,0 +1,81 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.junit; + +import java.io.InputStream; +import java.net.URI; + +import org.apache.commons.io.IOUtils; +import org.assertj.core.api.BDDAssertions; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; + +import static org.assertj.core.api.BDDAssertions.then; + +/** + * @author Marcin Grzejszczak + */ +public class StubRunnerRuleJUnitTest { + + @BeforeClass + @AfterClass + public static void setupProps() { + System.getProperties().setProperty("stubrunner.stubs.repository.root", ""); + System.getProperties().setProperty("stubrunner.stubs.classifier", "stubs"); + } + + // tag::classrule[] + @ClassRule public static StubRunnerRule rule = new StubRunnerRule() + .repoRoot(repoRoot()) + .downloadStub("org.springframework.cloud.contract.verifier.stubs", "loanIssuance") + .downloadStub("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer"); + // end::classrule[] + + // tag::test[] + @Test + public void should_start_wiremock_servers() throws Exception { + // expect: 'WireMocks are running' + then(rule.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance")).isNotNull(); + then(rule.findStubUrl("loanIssuance")).isNotNull(); + then(rule.findStubUrl("loanIssuance")).isEqualTo(rule.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance")); + then(rule.findStubUrl("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isNotNull(); + // and: + BDDAssertions.then(rule.findAllRunningStubs().isPresent("loanIssuance")).isTrue(); + BDDAssertions.then(rule.findAllRunningStubs().isPresent("org.springframework.cloud.contract.verifier.stubs", "fraudDetectionServer")).isTrue(); + BDDAssertions.then(rule.findAllRunningStubs().isPresent("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isTrue(); + // and: 'Stubs were registered' + then(httpGet(rule.findStubUrl("loanIssuance").toString() + "/name")).isEqualTo("loanIssuance"); + then(httpGet(rule.findStubUrl("fraudDetectionServer").toString() + "/name")).isEqualTo("fraudDetectionServer"); + } + // end::test[] + + private static String repoRoot() { + try { + return StubRunnerRuleJUnitTest.class.getResource("/m2repo/repository/").toURI().toString(); + } catch (Exception e) { + return ""; + } + } + + private String httpGet(String url) throws Exception { + try(InputStream stream = URI.create(url).toURL().openStream()) { + return IOUtils.toString(stream); + } + } +} diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleSpec.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleSpec.groovy new file mode 100644 index 0000000000..3399d25ea0 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleSpec.groovy @@ -0,0 +1,58 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.junit + +import org.junit.AfterClass +import org.junit.BeforeClass +import org.junit.ClassRule +import spock.lang.Shared +import spock.lang.Specification + +/** + * @author Marcin Grzejszczak + */ +class StubRunnerRuleSpec extends Specification { + + @BeforeClass + @AfterClass + void setupProps() { + System.getProperties().setProperty("stubrunner.stubs.repository.root", ""); + System.getProperties().setProperty("stubrunner.stubs.classifier", "stubs"); + } + + // tag::classrule[] + @ClassRule @Shared StubRunnerRule rule = new StubRunnerRule() + .repoRoot(StubRunnerRuleSpec.getResource("/m2repo/repository").toURI().toString()) + .downloadStub("org.springframework.cloud.contract.verifier.stubs", "loanIssuance") + .downloadStub("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer") + + def 'should start WireMock servers'() { + expect: 'WireMocks are running' + rule.findStubUrl('org.springframework.cloud.contract.verifier.stubs', 'loanIssuance') != null + rule.findStubUrl('loanIssuance') != null + rule.findStubUrl('loanIssuance') == rule.findStubUrl('org.springframework.cloud.contract.verifier.stubs', 'loanIssuance') + rule.findStubUrl('org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer') != null + and: + rule.findAllRunningStubs().isPresent('loanIssuance') + rule.findAllRunningStubs().isPresent('org.springframework.cloud.contract.verifier.stubs', 'fraudDetectionServer') + rule.findAllRunningStubs().isPresent('org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer') + and: 'Stubs were registered' + "${rule.findStubUrl('loanIssuance').toString()}/name".toURL().text == 'loanIssuance' + "${rule.findStubUrl('fraudDetectionServer').toString()}/name".toURL().text == 'fraudDetectionServer' + } + // end::classrule[] +} diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/resources/logback.xml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/resources/logback.xml new file mode 100644 index 0000000000..7eecabf2f2 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/resources/logback.xml @@ -0,0 +1,30 @@ + + + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + \ No newline at end of file diff --git a/stub-runner/stub-runner-junit/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT-stubs.jar b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT-stubs.jar similarity index 100% rename from stub-runner/stub-runner-junit/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT-stubs.jar rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT-stubs.jar diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT.pom b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT.pom new file mode 100644 index 0000000000..40610c8cdb --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT.pom @@ -0,0 +1,25 @@ + + + + + 4.0.0 + org.springframework.cloud.contract.verifier.stubs + fraudDetectionServer + 0.0.1-SNAPSHOT + pom + diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/maven-metadata.xml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/maven-metadata.xml new file mode 100644 index 0000000000..281b9b3b80 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/maven-metadata.xml @@ -0,0 +1,28 @@ + + + + + org.springframework.cloud.contract.verifier.stubs + fraudDetectionServer + 0.0.1-SNAPSHOT + + + 0.0.1-SNAPSHOT + + 20160409062112 + + diff --git a/stub-runner/stub-runner-junit/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT-stubs.jar b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT-stubs.jar similarity index 100% rename from stub-runner/stub-runner-junit/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT-stubs.jar rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT-stubs.jar diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT.pom b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT.pom new file mode 100644 index 0000000000..59db343686 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT.pom @@ -0,0 +1,25 @@ + + + + + 4.0.0 + org.springframework.cloud.contract.verifier.stubs + loanIssuance + 0.0.1-SNAPSHOT + pom + diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/maven-metadata.xml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/maven-metadata.xml new file mode 100644 index 0000000000..615428dae6 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/maven-metadata.xml @@ -0,0 +1,28 @@ + + + + + org.springframework.cloud.contract.verifier.stubs + loanIssuance + 0.0.1-SNAPSHOT + + + 0.0.1-SNAPSHOT + + 20160409062111 + + diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/README.adoc b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/README.adoc similarity index 61% rename from stub-runner/stub-runner-messaging/stub-runner-messaging-camel/README.adoc rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/README.adoc index d931a61a10..84eb4ac140 100644 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/README.adoc +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/README.adoc @@ -3,7 +3,7 @@ === Stub Runner Messaging Camel -Accurest Stub Runner's messaging module gives you an easy way to integrate with Apache Camel. +Spring Cloud Contract Verifier Stub Runner's messaging module gives you an easy way to integrate with Apache Camel. For the provided artifacts it will automatically download the stubs and register the required routes. @@ -13,7 +13,7 @@ To use it you have to add the following dependency to your project (example for [source,groovy,indent=0] ---- -testCompile "io.codearte.accurest:stub-runner-messaging-camel:${accurestVersion}" +testCompile "org.springframework.cloud.contract:stub-runner-messaging-camel:${verifierVersion}" ---- ==== Examples @@ -57,14 +57,14 @@ Let's consider the following contracts (let' number it with *1*): [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=sample_dsl,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=sample_dsl,indent=0] ---- and number *2* [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=sample_dsl_2,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=sample_dsl_2,indent=0] ---- ===== Scenario 1 (no input message) @@ -73,21 +73,21 @@ So as to trigger a message via the `return_book_1` label we'll use the `StubTigg [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_trigger,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_trigger,indent=0] ---- Next we'll want to listen to the output of the message sent to `{output_name}` [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_trigger_receive,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_trigger_receive,indent=0] ---- And the received message would pass the following assertions [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_trigger_message,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_trigger_message,indent=0] ---- ===== Scenario 2 (output triggered by input) @@ -96,21 +96,21 @@ Since the route is set for you it's enough to just send a message to the `{outpu [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_send,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_send,indent=0] ---- Next we'll want to listen to the output of the message sent to `{output_name}` [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_receive,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_receive,indent=0] ---- And the received message would pass the following assertions [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_receive_message,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_receive_message,indent=0] ---- ===== Scenario 3 (input with no output) @@ -119,5 +119,5 @@ Since the route is set for you it's enough to just send a message to the `{outpu [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=trigger_no_output,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=trigger_no_output,indent=0] ---- diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/build.gradle b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/build.gradle new file mode 100644 index 0000000000..bd4200c30f --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/build.gradle @@ -0,0 +1,45 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +repositories { + mavenLocal() + jcenter() + maven { + url "http://repo.spring.io/snapshot" + } + maven { + url "http://repo.spring.io/milestone" + } +} + +String verifier = "spring-cloud-contract-verifier" +String stubRunner = "spring-cloud-contract-stub-runner" + +dependencies { + compile project(":$stubRunner-root:$stubRunner-spring") + compile project(":$verifier-root:$verifier-messaging-root:$verifier-camel") + compile "org.apache.camel:camel-spring-boot-starter:${camelVersion}" + compile "org.apache.camel:camel-jackson:${camelVersion}" + + testCompile "org.springframework:spring-beans:${springVersion}" + testCompile "org.apache.camel:camel-jms:${camelVersion}" + testCompile 'org.apache.activemq:activemq-camel:5.12.1' + testCompile 'org.apache.activemq:activemq-pool:5.12.1' + testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" + testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { + exclude(group: 'org.codehaus.groovy') + } +} \ No newline at end of file diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelConfiguration.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelConfiguration.groovy new file mode 100644 index 0000000000..a97f21f07c --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelConfiguration.groovy @@ -0,0 +1,51 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.messaging.camel + +import org.apache.camel.RoutesBuilder +import org.apache.camel.spring.SpringRouteBuilder +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.stubrunner.BatchStubRunner +import org.springframework.cloud.contract.stubrunner.StubConfiguration +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +/** + * Camel configuration that iterates over the downloaded Groovy DSLs + * and registers a route for each DSL. + * + * @author Marcin Grzejszczak + */ +@Configuration +class StubRunnerCamelConfiguration { + + @Bean + RoutesBuilder myRouter(BatchStubRunner batchStubRunner) { + return new SpringRouteBuilder() { + @Override + public void configure() throws Exception { + Map> contracts = batchStubRunner.contracts + (contracts.values().flatten() as Collection).findAll { it?.input?.messageFrom?.clientValue && it?.outputMessage?.sentTo }.each { + from(it.input.messageFrom.clientValue) + .filter(new StubRunnerCamelPredicate(it)) + .process(new StubRunnerCamelProcessor(it)) + .to(it.outputMessage.sentTo.clientValue) + } + } + }; + } +} diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/main/groovy/io/codearte/accurest/stubrunner/messaging/camel/StubRunnerCamelPredicate.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelPredicate.groovy similarity index 57% rename from stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/main/groovy/io/codearte/accurest/stubrunner/messaging/camel/StubRunnerCamelPredicate.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelPredicate.groovy index b38b82fabe..c8fc231223 100644 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/main/groovy/io/codearte/accurest/stubrunner/messaging/camel/StubRunnerCamelPredicate.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelPredicate.groovy @@ -1,16 +1,32 @@ -package io.codearte.accurest.stubrunner.messaging.camel +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.messaging.camel import com.jayway.jsonpath.DocumentContext import com.jayway.jsonpath.JsonPath import com.toomuchcoding.jsonassert.JsonAssertion import com.toomuchcoding.jsonassert.JsonVerifiable import groovy.transform.PackageScope -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.messaging.AccurestObjectMapper -import io.codearte.accurest.util.JsonPaths -import io.codearte.accurest.util.JsonToJsonPathsConverter +import org.springframework.cloud.contract.verifier.dsl.Contract import org.apache.camel.Exchange import org.apache.camel.Predicate +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierObjectMapper +import org.springframework.cloud.contract.verifier.util.JsonPaths +import org.springframework.cloud.contract.verifier.util.JsonToJsonPathsConverter import java.util.regex.Pattern @@ -22,10 +38,10 @@ import java.util.regex.Pattern @PackageScope class StubRunnerCamelPredicate implements Predicate { - private final GroovyDsl groovyDsl - private final AccurestObjectMapper objectMapper = new AccurestObjectMapper() + private final Contract groovyDsl + private final ContractVerifierObjectMapper objectMapper = new ContractVerifierObjectMapper() - StubRunnerCamelPredicate(GroovyDsl groovyDsl) { + StubRunnerCamelPredicate(Contract groovyDsl) { this.groovyDsl = groovyDsl } diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelProcessor.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelProcessor.groovy new file mode 100644 index 0000000000..7bf6113f9b --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelProcessor.groovy @@ -0,0 +1,52 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.messaging.camel + +import groovy.transform.PackageScope +import org.springframework.cloud.contract.verifier.util.BodyAsStringUtil +import org.apache.camel.Exchange +import org.apache.camel.Message +import org.apache.camel.Processor +import org.springframework.cloud.contract.verifier.dsl.Contract + +/** + * Sends forward a message defined in the DSL. Also removes headers from the + * input message and provides the headers from the DSL. + * + * @author Marcin Grzejszczak + */ +@PackageScope +class StubRunnerCamelProcessor implements Processor { + + private final Contract groovyDsl + + StubRunnerCamelProcessor(Contract groovyDsl) { + this.groovyDsl = groovyDsl + } + + @Override + void process(Exchange exchange) throws Exception { + Message input = exchange.in + input.body = BodyAsStringUtil.extractClientValueFrom(groovyDsl.outputMessage.body) + groovyDsl.input.messageHeaders.entries.each { + input.removeHeader(it.name) + } + groovyDsl.outputMessage.headers.entries.each { + input.setHeader(it.name, it.clientValue) + } + } +} diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/main/resources/META-INF/spring.factories b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000000..26adb8c16c --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/main/resources/META-INF/spring.factories @@ -0,0 +1,3 @@ +# Auto Configuration +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.springframework.cloud.contract.stubrunner.messaging.camel.StubRunnerCamelConfiguration diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/BookReturned.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/BookReturned.groovy new file mode 100644 index 0000000000..72a689a659 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/BookReturned.groovy @@ -0,0 +1,32 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.messaging.camel + +import com.fasterxml.jackson.annotation.JsonCreator +import groovy.transform.CompileStatic +import groovy.transform.EqualsAndHashCode + +@CompileStatic +@EqualsAndHashCode +class BookReturned implements Serializable { + final String bookName + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + BookReturned(String bookName) { + this.bookName = bookName + } +} diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy similarity index 84% rename from stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy index 28e8053387..1fc0b9bc95 100644 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy @@ -1,9 +1,23 @@ -package io.codearte.accurest.stubrunner.messaging.camel +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.messaging.camel import groovy.json.JsonOutput import groovy.json.JsonSlurper -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.stubrunner.StubFinder import org.apache.activemq.camel.component.ActiveMQComponent import org.apache.camel.CamelContext import org.apache.camel.Exchange @@ -11,6 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Value import org.springframework.boot.autoconfigure.EnableAutoConfiguration import org.springframework.boot.test.SpringApplicationContextLoader +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.stubrunner.StubFinder import org.springframework.context.annotation.Bean import org.springframework.context.annotation.ComponentScan import org.springframework.context.annotation.Configuration @@ -70,7 +86,7 @@ class CamelStubRunnerSpec extends Specification { def 'should trigger a label for the existing groupId:artifactId'() { when: // tag::trigger_group_artifact[] - stubFinder.trigger('io.codearte.accurest.stubs:camelService', 'return_book_1') + stubFinder.trigger('org.springframework.cloud.contract.verifier.stubs:camelService', 'return_book_1') // end::trigger_group_artifact[] then: Exchange receivedMessage = camelContext.createConsumerTemplate().receive('jms:output', 5000) @@ -150,9 +166,9 @@ class CamelStubRunnerSpec extends Specification { return new ActiveMQComponent(brokerURL: url) } - GroovyDsl dsl = + Contract dsl = // tag::sample_dsl[] - io.codearte.accurest.dsl.GroovyDsl.make { + Contract.make { label 'return_book_1' input { triggeredBy('bookReturnedTriggered()') @@ -167,9 +183,9 @@ class CamelStubRunnerSpec extends Specification { } // end::sample_dsl[] - GroovyDsl dsl2 = + Contract dsl2 = // tag::sample_dsl_2[] - io.codearte.accurest.dsl.GroovyDsl.make { + Contract.make { label 'return_book_2' input { messageFrom('jms:input') @@ -192,9 +208,9 @@ class CamelStubRunnerSpec extends Specification { } // end::sample_dsl_2[] - GroovyDsl dsl3 = + Contract dsl3 = // tag::sample_dsl_3[] - io.codearte.accurest.dsl.GroovyDsl.make { + Contract.make { label 'delete_book' input { messageFrom('jms:delete') diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/resources/application.yml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/resources/application.yml new file mode 100644 index 0000000000..db021bb201 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/resources/application.yml @@ -0,0 +1,2 @@ +stubrunner.stubs.repository.root: classpath:m2repo/repository/ +stubrunner.stubs.ids: org.springframework.cloud.contract.verifier.stubs:camelService \ No newline at end of file diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/camelService/0.0.1-SNAPSHOT/camelService-0.0.1-SNAPSHOT-stubs.jar b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/camelService/0.0.1-SNAPSHOT/camelService-0.0.1-SNAPSHOT-stubs.jar new file mode 100644 index 0000000000..4196403cea Binary files /dev/null and b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/camelService/0.0.1-SNAPSHOT/camelService-0.0.1-SNAPSHOT-stubs.jar differ diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/camelService/0.0.1-SNAPSHOT/camelService-0.0.1-SNAPSHOT.pom b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/camelService/0.0.1-SNAPSHOT/camelService-0.0.1-SNAPSHOT.pom new file mode 100644 index 0000000000..0b56465de4 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/camelService/0.0.1-SNAPSHOT/camelService-0.0.1-SNAPSHOT.pom @@ -0,0 +1,25 @@ + + + + + 4.0.0 + org.springframework.cloud.contract.verifier.stubs + camelService + 0.0.1-SNAPSHOT + pom + diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/camelService/0.0.1-SNAPSHOT/maven-metadata-local.xml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/camelService/0.0.1-SNAPSHOT/maven-metadata-local.xml new file mode 100644 index 0000000000..8ac2715bc8 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/camelService/0.0.1-SNAPSHOT/maven-metadata-local.xml @@ -0,0 +1,28 @@ + + + + + org.springframework.cloud.contract.verifier.stubs + camelService + 0.0.1-SNAPSHOT + + + true + + 20160409062112 + + diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/camelService/maven-metadata-local.xml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/camelService/maven-metadata-local.xml new file mode 100644 index 0000000000..237fd747a9 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/camelService/maven-metadata-local.xml @@ -0,0 +1,28 @@ + + + + + org.springframework.cloud.contract.verifier.stubs + camelService + 0.0.1-SNAPSHOT + + + 0.0.1-SNAPSHOT + + 20160409062112 + + diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/camelService/maven-metadata.xml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/camelService/maven-metadata.xml new file mode 100644 index 0000000000..237fd747a9 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-camel/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/camelService/maven-metadata.xml @@ -0,0 +1,28 @@ + + + + + org.springframework.cloud.contract.verifier.stubs + camelService + 0.0.1-SNAPSHOT + + + 0.0.1-SNAPSHOT + + 20160409062112 + + diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/README.adoc b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/README.adoc similarity index 61% rename from stub-runner/stub-runner-messaging/stub-runner-messaging-integration/README.adoc rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/README.adoc index 89c30d9dcf..2d2664bba1 100644 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/README.adoc +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/README.adoc @@ -3,7 +3,7 @@ === Stub Runner Messaging Integration -Accurest Stub Runner's messaging module gives you an easy way to integrate with Spring Integration. +Spring Cloud Contract Verifier Stub Runner's messaging module gives you an easy way to integrate with Spring Integration. For the provided artifacts it will automatically download the stubs and register the required routes. @@ -13,7 +13,7 @@ To use it you have to add the following dependency to your project (example for [source,groovy,indent=0] ---- -testCompile "io.codearte.accurest:stub-runner-messaging-integration:${accurestVersion}" +testCompile "org.springframework.cloud.contract:stub-runner-messaging-integration:${verifierVersion}" ---- ==== Examples @@ -57,14 +57,14 @@ Let's consider the following contracts (let' number it with *1*): [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=sample_dsl,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=sample_dsl,indent=0] ---- and number *2* [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=sample_dsl_2,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=sample_dsl_2,indent=0] ---- and the following Spring Integration Route: @@ -81,21 +81,21 @@ So as to trigger a message via the `return_book_1` label we'll use the `StubTigg [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=client_trigger,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=client_trigger,indent=0] ---- Next we'll want to listen to the output of the message sent to `{output_name}` [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=client_trigger_receive,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=client_trigger_receive,indent=0] ---- And the received message would pass the following assertions [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=client_trigger_message,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=client_trigger_message,indent=0] ---- ===== Scenario 2 (output triggered by input) @@ -104,21 +104,21 @@ Since the route is set for you it's enough to just send a message to the `{outpu [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=client_send,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=client_send,indent=0] ---- Next we'll want to listen to the output of the message sent to `{output_name}` [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=client_receive,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=client_receive,indent=0] ---- And the received message would pass the following assertions [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=client_receive_message,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=client_receive_message,indent=0] ---- ===== Scenario 3 (input with no output) @@ -127,5 +127,5 @@ Since the route is set for you it's enough to just send a message to the `{input [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=trigger_no_output,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=trigger_no_output,indent=0] ---- diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/build.gradle b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/build.gradle new file mode 100644 index 0000000000..338123d564 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/build.gradle @@ -0,0 +1,41 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +repositories { + mavenLocal() + jcenter() + maven { + url "http://repo.spring.io/snapshot" + } + maven { + url "http://repo.spring.io/milestone" + } +} +String verifier = "spring-cloud-contract-verifier" +String stubRunner = "spring-cloud-contract-stub-runner" + +dependencies { + compile project(":$stubRunner-root:$stubRunner-spring") + compile project(":$verifier-root:$verifier-messaging-root:$verifier-integration") + compile "org.springframework.integration:spring-integration-java-dsl:${springIntegrationDslVersion}" + compile 'com.fasterxml.jackson.core:jackson-databind:2.7.0' + + testCompile "org.springframework.boot:spring-boot-starter-integration:${springBootVersion}" + testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" + testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { + exclude(group: 'org.codehaus.groovy') + } +} \ No newline at end of file diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/main/groovy/io/codearte/accurest/stubrunner/messaging/integration/StubRunnerIntegrationConfiguration.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationConfiguration.groovy similarity index 64% rename from stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/main/groovy/io/codearte/accurest/stubrunner/messaging/integration/StubRunnerIntegrationConfiguration.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationConfiguration.groovy index f4ba7902a0..2d777d252e 100644 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/main/groovy/io/codearte/accurest/stubrunner/messaging/integration/StubRunnerIntegrationConfiguration.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationConfiguration.groovy @@ -1,11 +1,27 @@ -package io.codearte.accurest.stubrunner.messaging.integration +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.messaging.integration import groovy.transform.CompileStatic -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.stubrunner.BatchStubRunner -import io.codearte.accurest.stubrunner.StubConfiguration -import io.codearte.accurest.stubrunner.spring.StubRunnerConfiguration +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.stubrunner.StubConfiguration import org.springframework.beans.factory.config.AutowireCapableBeanFactory +import org.springframework.cloud.contract.stubrunner.BatchStubRunner +import org.springframework.cloud.contract.stubrunner.spring.StubRunnerConfiguration import org.springframework.context.Lifecycle import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration @@ -29,10 +45,10 @@ class StubRunnerIntegrationConfiguration { @Bean FlowRegistrar flowRegistrar(AutowireCapableBeanFactory beanFactory, BatchStubRunner batchStubRunner) { - Map> accurestContracts = batchStubRunner.accurestContracts - accurestContracts.each { StubConfiguration key, Collection value -> + Map> contracts = batchStubRunner.contracts + contracts.each { StubConfiguration key, Collection value -> String name = "${key.groupId}_${key.artifactId}" - value.findAll { it?.input?.messageFrom?.clientValue }.each { GroovyDsl dsl -> + value.findAll { it?.input?.messageFrom?.clientValue }.each { Contract dsl -> String flowName = "${name}_${dsl.label}_${dsl.hashCode()}" IntegrationFlowBuilder builder = IntegrationFlows.from(dsl.input.messageFrom.clientValue) .filter(new StubRunnerIntegrationMessageSelector(dsl), { FilterEndpointSpec e -> e.id("${flowName}.filter") } ) diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/main/groovy/io/codearte/accurest/stubrunner/messaging/integration/StubRunnerIntegrationMessageSelector.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationMessageSelector.groovy similarity index 57% rename from stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/main/groovy/io/codearte/accurest/stubrunner/messaging/integration/StubRunnerIntegrationMessageSelector.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationMessageSelector.groovy index 1bdf1398f2..e3a7a87e69 100644 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/main/groovy/io/codearte/accurest/stubrunner/messaging/integration/StubRunnerIntegrationMessageSelector.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationMessageSelector.groovy @@ -1,14 +1,30 @@ -package io.codearte.accurest.stubrunner.messaging.integration +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.messaging.integration import com.jayway.jsonpath.DocumentContext import com.jayway.jsonpath.JsonPath import com.toomuchcoding.jsonassert.JsonAssertion import com.toomuchcoding.jsonassert.JsonVerifiable import groovy.transform.CompileStatic -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.messaging.AccurestObjectMapper -import io.codearte.accurest.util.JsonPaths -import io.codearte.accurest.util.JsonToJsonPathsConverter +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierObjectMapper +import org.springframework.cloud.contract.verifier.util.JsonPaths +import org.springframework.cloud.contract.verifier.util.JsonToJsonPathsConverter import org.springframework.integration.core.MessageSelector import org.springframework.messaging.Message @@ -21,10 +37,10 @@ import java.util.regex.Pattern @CompileStatic class StubRunnerIntegrationMessageSelector implements MessageSelector { - private final GroovyDsl groovyDsl - private final AccurestObjectMapper objectMapper = new AccurestObjectMapper() + private final Contract groovyDsl + private final ContractVerifierObjectMapper objectMapper = new ContractVerifierObjectMapper() - StubRunnerIntegrationMessageSelector(GroovyDsl groovyDsl) { + StubRunnerIntegrationMessageSelector(Contract groovyDsl) { this.groovyDsl = groovyDsl } diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationTransformer.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationTransformer.groovy new file mode 100644 index 0000000000..d45dafcc81 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationTransformer.groovy @@ -0,0 +1,48 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.messaging.integration + +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.util.BodyAsStringUtil +import org.springframework.integration.transformer.GenericTransformer +import org.springframework.messaging.Message +import org.springframework.messaging.MessageHeaders +import org.springframework.messaging.support.MessageBuilder + +/** + * Sends forward a message defined in the DSL. + * + * @author Marcin Grzejszczak + */ +class StubRunnerIntegrationTransformer implements GenericTransformer, Message> { + + private final Contract groovyDsl + + StubRunnerIntegrationTransformer(Contract groovyDsl) { + this.groovyDsl = groovyDsl + } + + @Override + Message transform(Message source) { + if (!groovyDsl.outputMessage) { + return source + } + String payload = BodyAsStringUtil.extractClientValueFrom(groovyDsl.outputMessage.body) + Map headers = groovyDsl.outputMessage.headers.asStubSideMap() + return MessageBuilder.createMessage(payload, new MessageHeaders(headers)) + } +} diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/main/resources/META-INF/spring.factories b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000000..a69b005443 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/main/resources/META-INF/spring.factories @@ -0,0 +1,3 @@ +# Auto Configuration +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.springframework.cloud.contract.stubrunner.messaging.integration.StubRunnerIntegrationConfiguration diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/BookReturned.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/BookReturned.groovy new file mode 100644 index 0000000000..bbb47bbb60 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/BookReturned.groovy @@ -0,0 +1,32 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.messaging.integration + +import com.fasterxml.jackson.annotation.JsonCreator +import groovy.transform.CompileStatic +import groovy.transform.EqualsAndHashCode + +@CompileStatic +@EqualsAndHashCode +class BookReturned implements Serializable { + final String bookName + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + BookReturned(String bookName) { + this.bookName = bookName + } +} diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/groovy/io/codearte/accurest/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy similarity index 72% rename from stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/groovy/io/codearte/accurest/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy index 02b875af6f..3f7a37f357 100644 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/groovy/io/codearte/accurest/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy @@ -1,14 +1,30 @@ -package io.codearte.accurest.stubrunner.messaging.integration +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.messaging.integration import groovy.json.JsonOutput import groovy.json.JsonSlurper -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.messaging.AccurestMessage -import io.codearte.accurest.messaging.AccurestMessaging -import io.codearte.accurest.stubrunner.StubFinder +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.autoconfigure.EnableAutoConfiguration import org.springframework.boot.test.SpringApplicationContextLoader +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.stubrunner.StubFinder +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging import org.springframework.context.annotation.ComponentScan import org.springframework.context.annotation.Configuration import org.springframework.context.annotation.ImportResource @@ -27,7 +43,7 @@ import java.util.concurrent.TimeUnit class IntegrationStubRunnerSpec extends Specification { @Autowired StubFinder stubFinder - @Autowired AccurestMessaging messaging + @Autowired ContractVerifierMessaging messaging def setup() { // ensure that message were taken from the queue @@ -41,7 +57,7 @@ class IntegrationStubRunnerSpec extends Specification { // end::client_send[] then: // tag::client_receive[] - AccurestMessage receivedMessage = messaging.receiveMessage('outputTest') + ContractVerifierMessage receivedMessage = messaging.receiveMessage('outputTest') // end::client_receive[] and: // tag::client_receive_message[] @@ -58,7 +74,7 @@ class IntegrationStubRunnerSpec extends Specification { // end::client_trigger[] then: // tag::client_trigger_receive[] - AccurestMessage receivedMessage = messaging.receiveMessage('outputTest') + ContractVerifierMessage receivedMessage = messaging.receiveMessage('outputTest') // end::client_trigger_receive[] and: // tag::client_trigger_message[] @@ -71,10 +87,10 @@ class IntegrationStubRunnerSpec extends Specification { def 'should trigger a label for the existing groupId:artifactId'() { when: // tag::trigger_group_artifact[] - stubFinder.trigger('io.codearte.accurest.stubs:integrationService', 'return_book_1') + stubFinder.trigger('org.springframework.cloud.contract.verifier.stubs:integrationService', 'return_book_1') // end::trigger_group_artifact[] then: - AccurestMessage receivedMessage = messaging.receiveMessage('outputTest') + ContractVerifierMessage receivedMessage = messaging.receiveMessage('outputTest') and: receivedMessage != null assertJsons(receivedMessage.payload) @@ -87,7 +103,7 @@ class IntegrationStubRunnerSpec extends Specification { stubFinder.trigger('integrationService', 'return_book_1') // end::trigger_artifact[] then: - AccurestMessage receivedMessage = messaging.receiveMessage('outputTest') + ContractVerifierMessage receivedMessage = messaging.receiveMessage('outputTest') and: receivedMessage != null assertJsons(receivedMessage.payload) @@ -114,7 +130,7 @@ class IntegrationStubRunnerSpec extends Specification { stubFinder.trigger() // end::trigger_all[] then: - AccurestMessage receivedMessage = messaging.receiveMessage('outputTest') + ContractVerifierMessage receivedMessage = messaging.receiveMessage('outputTest') and: receivedMessage != null assertJsons(receivedMessage.payload) @@ -134,7 +150,7 @@ class IntegrationStubRunnerSpec extends Specification { when: messaging.send(new BookReturned('not_matching'), [wrong: 'header_value'], 'input') then: - AccurestMessage receivedMessage = messaging.receiveMessage('outputTest', 100, TimeUnit.MILLISECONDS) + ContractVerifierMessage receivedMessage = messaging.receiveMessage('outputTest', 100, TimeUnit.MILLISECONDS) and: receivedMessage == null } @@ -146,9 +162,9 @@ class IntegrationStubRunnerSpec extends Specification { return json.bookName == 'foo' } - GroovyDsl dsl = + Contract dsl = // tag::sample_dsl[] - io.codearte.accurest.dsl.GroovyDsl.make { + Contract.make { label 'return_book_1' input { triggeredBy('bookReturnedTriggered()') @@ -163,9 +179,9 @@ class IntegrationStubRunnerSpec extends Specification { } // end::sample_dsl[] - GroovyDsl dsl2 = + Contract dsl2 = // tag::sample_dsl_2[] - io.codearte.accurest.dsl.GroovyDsl.make { + Contract.make { label 'return_book_2' input { messageFrom('input') @@ -188,9 +204,9 @@ class IntegrationStubRunnerSpec extends Specification { } // end::sample_dsl_2[] - GroovyDsl dsl3 = + Contract dsl3 = // tag::sample_dsl_3[] - io.codearte.accurest.dsl.GroovyDsl.make { + Contract.make { label 'delete_book' input { messageFrom('delete') diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/test/resources/application.yml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/test/resources/application.yml new file mode 100644 index 0000000000..911b24bbaa --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/test/resources/application.yml @@ -0,0 +1,2 @@ +stubrunner.stubs.repository.root: classpath:m2repo/repository/ +stubrunner.stubs.ids: org.springframework.cloud.contract.verifier.stubs:integrationService:0.0.1-SNAPSHOT \ No newline at end of file diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/resources/integration-context.xml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/test/resources/integration-context.xml similarity index 50% rename from stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/resources/integration-context.xml rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/test/resources/integration-context.xml index c342dc9e94..1fdb1bb847 100644 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/resources/integration-context.xml +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/test/resources/integration-context.xml @@ -1,4 +1,20 @@ + + + + + + 4.0.0 + org.springframework.cloud.contract.verifier.stubs + integrationService + 0.0.1-SNAPSHOT + pom + diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/integrationService/0.0.1-SNAPSHOT/maven-metadata-local.xml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/integrationService/0.0.1-SNAPSHOT/maven-metadata-local.xml new file mode 100644 index 0000000000..e6c62c5897 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/integrationService/0.0.1-SNAPSHOT/maven-metadata-local.xml @@ -0,0 +1,28 @@ + + + + + org.springframework.cloud.contract.verifier.stubs + integrationService + 0.0.1-SNAPSHOT + + + true + + 20160409062112 + + diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/integrationService/maven-metadata-local.xml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/integrationService/maven-metadata-local.xml new file mode 100644 index 0000000000..f619bafb54 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/integrationService/maven-metadata-local.xml @@ -0,0 +1,28 @@ + + + + + org.springframework.cloud.contract.verifier.stubs + integrationService + 0.0.1-SNAPSHOT + + + 0.0.1-SNAPSHOT + + 20160409062112 + + diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/integrationService/maven-metadata.xml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/integrationService/maven-metadata.xml new file mode 100644 index 0000000000..f619bafb54 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-integration/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/integrationService/maven-metadata.xml @@ -0,0 +1,28 @@ + + + + + org.springframework.cloud.contract.verifier.stubs + integrationService + 0.0.1-SNAPSHOT + + + 0.0.1-SNAPSHOT + + 20160409062112 + + diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/README.adoc b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/README.adoc similarity index 64% rename from stub-runner/stub-runner-messaging/stub-runner-messaging-stream/README.adoc rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/README.adoc index aa9af8950d..670ea5201a 100644 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/README.adoc +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/README.adoc @@ -1,6 +1,6 @@ === Stub Runner Messaging Stream -Accurest Stub Runner's messaging module gives you an easy way to integrate with Spring Stream. +Spring Cloud Contract Verifier Stub Runner's messaging module gives you an easy way to integrate with Spring Stream. For the provided artifacts it will automatically download the stubs and register the required routes. @@ -14,7 +14,7 @@ To use it you have to add the following dependency to your project (example for [source,groovy,indent=0] ---- -testCompile "io.codearte.accurest:stub-runner-messaging-stream:${accurestVersion}" +testCompile "org.springframework.cloud.contract:stub-runner-messaging-stream:${verifierVersion}" ---- ==== Examples @@ -58,14 +58,14 @@ Let's consider the following contracts (let' number it with *1*): [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=sample_dsl,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=sample_dsl,indent=0] ---- and number *2* [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=sample_dsl_2,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=sample_dsl_2,indent=0] ---- and the following Spring configuration: @@ -82,21 +82,21 @@ So as to trigger a message via the `return_book_1` label we'll use the `StubTrig [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=client_trigger,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=client_trigger,indent=0] ---- Next we'll want to listen to the output of the message sent to a channel whose `destination` is `returnBook` [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=client_trigger_receive,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=client_trigger_receive,indent=0] ---- And the received message would pass the following assertions [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=client_trigger_message,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=client_trigger_message,indent=0] ---- ===== Scenario 2 (output triggered by input) @@ -105,21 +105,21 @@ Since the route is set for you it's enough to just send a message to the `bookSt [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=client_send,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=client_send,indent=0] ---- Next we'll want to listen to the output of the message sent to `returnBook` [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=client_receive,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=client_receive,indent=0] ---- And the received message would pass the following assertions [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=client_receive_message,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=client_receive_message,indent=0] ---- ===== Scenario 3 (input with no output) @@ -128,5 +128,5 @@ Since the route is set for you it's enough to just send a message to the `{outpu [source,groovy] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=trigger_no_output,indent=0] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=trigger_no_output,indent=0] ---- diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/build.gradle b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/build.gradle new file mode 100644 index 0000000000..30791e97ed --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/build.gradle @@ -0,0 +1,43 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +repositories { + mavenLocal() + jcenter() + maven { + url "http://repo.spring.io/snapshot" + } + maven { + url "http://repo.spring.io/milestone" + } +} + +String verifier = "spring-cloud-contract-verifier" +String stubRunner = "spring-cloud-contract-stub-runner" + +dependencies { + compile project(":$stubRunner-root:$stubRunner-spring") + compile project(":$verifier-root:$verifier-messaging-root:$verifier-stream") + compile "org.springframework.integration:spring-integration-java-dsl:${springIntegrationDslVersion}" + + testCompile "org.springframework:spring-context:${springVersion}" + testCompile "org.springframework:spring-beans:${springVersion}" + testCompile "org.springframework.cloud:spring-cloud-stream-test-support:${springStreamVersion}" + testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" + testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { + exclude(group: 'org.codehaus.groovy') + } +} \ No newline at end of file diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/main/groovy/io/codearte/accurest/stubrunner/messaging/stream/StubRunnerStreamConfiguration.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamConfiguration.groovy similarity index 73% rename from stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/main/groovy/io/codearte/accurest/stubrunner/messaging/stream/StubRunnerStreamConfiguration.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamConfiguration.groovy index 41813d1789..7a9c769dbc 100644 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/main/groovy/io/codearte/accurest/stubrunner/messaging/stream/StubRunnerStreamConfiguration.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamConfiguration.groovy @@ -1,13 +1,29 @@ -package io.codearte.accurest.stubrunner.messaging.stream +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.messaging.stream import groovy.transform.CompileStatic -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.stubrunner.BatchStubRunner -import io.codearte.accurest.stubrunner.StubConfiguration -import io.codearte.accurest.stubrunner.spring.StubRunnerConfiguration import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.beans.factory.config.AutowireCapableBeanFactory +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.stubrunner.BatchStubRunner +import org.springframework.cloud.contract.stubrunner.StubConfiguration +import org.springframework.cloud.contract.stubrunner.spring.StubRunnerConfiguration import org.springframework.cloud.stream.config.BindingProperties import org.springframework.cloud.stream.config.ChannelBindingServiceProperties import org.springframework.context.Lifecycle @@ -34,10 +50,10 @@ class StubRunnerStreamConfiguration { @Bean FlowRegistrar flowRegistrar(AutowireCapableBeanFactory beanFactory, BatchStubRunner batchStubRunner) { - Map> accurestContracts = batchStubRunner.accurestContracts - accurestContracts.each { StubConfiguration key, Collection value -> + Map> contracts = batchStubRunner.contracts + contracts.each { StubConfiguration key, Collection value -> String name = "${key.groupId}_${key.artifactId}" - value.findAll { it?.input?.messageFrom?.clientValue }.each { GroovyDsl dsl -> + value.findAll { it?.input?.messageFrom?.clientValue }.each { Contract dsl -> String flowName = "${name}_${dsl.label}_${dsl.hashCode()}" String from = resolvedDestination(beanFactory, dsl.input.messageFrom.clientValue) IntegrationFlowBuilder builder = IntegrationFlows.from(from) diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/main/groovy/io/codearte/accurest/stubrunner/messaging/stream/StubRunnerStreamMessageSelector.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamMessageSelector.groovy similarity index 58% rename from stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/main/groovy/io/codearte/accurest/stubrunner/messaging/stream/StubRunnerStreamMessageSelector.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamMessageSelector.groovy index d32339b504..ca55e84d73 100644 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/main/groovy/io/codearte/accurest/stubrunner/messaging/stream/StubRunnerStreamMessageSelector.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamMessageSelector.groovy @@ -1,14 +1,30 @@ -package io.codearte.accurest.stubrunner.messaging.stream +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.messaging.stream import com.jayway.jsonpath.DocumentContext import com.jayway.jsonpath.JsonPath import com.toomuchcoding.jsonassert.JsonAssertion import com.toomuchcoding.jsonassert.JsonVerifiable import groovy.transform.CompileStatic -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.messaging.AccurestObjectMapper -import io.codearte.accurest.util.JsonPaths -import io.codearte.accurest.util.JsonToJsonPathsConverter +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierObjectMapper +import org.springframework.cloud.contract.verifier.util.JsonPaths +import org.springframework.cloud.contract.verifier.util.JsonToJsonPathsConverter import org.springframework.integration.core.MessageSelector import org.springframework.messaging.Message @@ -22,10 +38,10 @@ import java.util.regex.Pattern @CompileStatic class StubRunnerStreamMessageSelector implements MessageSelector { - private final GroovyDsl groovyDsl - private final AccurestObjectMapper objectMapper = new AccurestObjectMapper() + private final Contract groovyDsl + private final ContractVerifierObjectMapper objectMapper = new ContractVerifierObjectMapper() - StubRunnerStreamMessageSelector(GroovyDsl groovyDsl) { + StubRunnerStreamMessageSelector(Contract groovyDsl) { this.groovyDsl = groovyDsl } diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamTransformer.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamTransformer.groovy new file mode 100644 index 0000000000..949304099c --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/main/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamTransformer.groovy @@ -0,0 +1,48 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.messaging.stream + +import org.springframework.cloud.contract.verifier.util.BodyAsStringUtil +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.integration.transformer.GenericTransformer +import org.springframework.messaging.Message +import org.springframework.messaging.MessageHeaders +import org.springframework.messaging.support.MessageBuilder + +/** + * Sends forward a message defined in the DSL. + * + * @author Marcin Grzejszczak + */ +class StubRunnerStreamTransformer implements GenericTransformer, Message> { + + private final Contract groovyDsl + + StubRunnerStreamTransformer(Contract groovyDsl) { + this.groovyDsl = groovyDsl + } + + @Override + Message transform(Message source) { + if (!groovyDsl.outputMessage) { + return source + } + String payload = BodyAsStringUtil.extractClientValueFrom(groovyDsl.outputMessage.body) + Map headers = groovyDsl.outputMessage.headers.asStubSideMap() + return MessageBuilder.createMessage(payload, new MessageHeaders(headers)) + } +} diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/main/resources/META-INF/spring.factories b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000000..35f2e3fddc --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/main/resources/META-INF/spring.factories @@ -0,0 +1,3 @@ +# Auto Configuration +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.springframework.cloud.contract.stubrunner.messaging.stream.StubRunnerStreamConfiguration diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/BookReturned.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/BookReturned.groovy new file mode 100644 index 0000000000..49dea202eb --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/BookReturned.groovy @@ -0,0 +1,32 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.messaging.stream + +import com.fasterxml.jackson.annotation.JsonCreator +import groovy.transform.CompileStatic +import groovy.transform.EqualsAndHashCode + +@CompileStatic +@EqualsAndHashCode +class BookReturned implements Serializable { + final String bookName + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + BookReturned(String bookName) { + this.bookName = bookName + } +} diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/groovy/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy similarity index 72% rename from stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/groovy/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy index 0233009851..00e9c495b1 100644 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/groovy/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy @@ -1,14 +1,30 @@ -package io.codearte.accurest.stubrunner.messaging.stream +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.messaging.stream import groovy.json.JsonOutput import groovy.json.JsonSlurper -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.messaging.AccurestMessage -import io.codearte.accurest.messaging.AccurestMessaging -import io.codearte.accurest.stubrunner.StubFinder +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage +import org.springframework.cloud.contract.stubrunner.StubFinder import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.autoconfigure.EnableAutoConfiguration import org.springframework.boot.test.SpringApplicationContextLoader +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging import org.springframework.cloud.stream.annotation.EnableBinding import org.springframework.cloud.stream.messaging.Sink import org.springframework.cloud.stream.messaging.Source @@ -29,7 +45,7 @@ import java.util.concurrent.TimeUnit class StreamStubRunnerSpec extends Specification { @Autowired StubFinder stubFinder - @Autowired AccurestMessaging messaging + @Autowired ContractVerifierMessaging messaging def setup() { // ensure that message were taken from the queue @@ -43,7 +59,7 @@ class StreamStubRunnerSpec extends Specification { // end::client_send[] then: // tag::client_receive[] - AccurestMessage receivedMessage = messaging.receiveMessage('returnBook') + ContractVerifierMessage receivedMessage = messaging.receiveMessage('returnBook') // end::client_receive[] and: // tag::client_receive_message[] @@ -60,7 +76,7 @@ class StreamStubRunnerSpec extends Specification { // end::client_trigger[] then: // tag::client_trigger_receive[] - AccurestMessage receivedMessage = messaging.receiveMessage('returnBook') + ContractVerifierMessage receivedMessage = messaging.receiveMessage('returnBook') // end::client_trigger_receive[] and: // tag::client_trigger_message[] @@ -73,10 +89,10 @@ class StreamStubRunnerSpec extends Specification { def 'should trigger a label for the existing groupId:artifactId'() { when: // tag::trigger_group_artifact[] - stubFinder.trigger('io.codearte.accurest.stubs:streamService', 'return_book_1') + stubFinder.trigger('org.springframework.cloud.contract.verifier.stubs:streamService', 'return_book_1') // end::trigger_group_artifact[] then: - AccurestMessage receivedMessage = messaging.receiveMessage('returnBook') + ContractVerifierMessage receivedMessage = messaging.receiveMessage('returnBook') and: receivedMessage != null assertJsons(receivedMessage.payload) @@ -89,7 +105,7 @@ class StreamStubRunnerSpec extends Specification { stubFinder.trigger('streamService', 'return_book_1') // end::trigger_artifact[] then: - AccurestMessage receivedMessage = messaging.receiveMessage('returnBook') + ContractVerifierMessage receivedMessage = messaging.receiveMessage('returnBook') and: receivedMessage != null assertJsons(receivedMessage.payload) @@ -116,7 +132,7 @@ class StreamStubRunnerSpec extends Specification { stubFinder.trigger() // end::trigger_all[] then: - AccurestMessage receivedMessage = messaging.receiveMessage('returnBook') + ContractVerifierMessage receivedMessage = messaging.receiveMessage('returnBook') and: receivedMessage != null assertJsons(receivedMessage.payload) @@ -136,7 +152,7 @@ class StreamStubRunnerSpec extends Specification { when: messaging.send(new BookReturned('not_matching'), [wrong: 'header_value'], 'bookStorage') then: - AccurestMessage receivedMessage = messaging.receiveMessage('returnBook', 100, TimeUnit.MILLISECONDS) + ContractVerifierMessage receivedMessage = messaging.receiveMessage('returnBook', 100, TimeUnit.MILLISECONDS) and: receivedMessage == null } @@ -148,9 +164,9 @@ class StreamStubRunnerSpec extends Specification { return json.bookName == 'foo' } - GroovyDsl dsl = + Contract dsl = // tag::sample_dsl[] - io.codearte.accurest.dsl.GroovyDsl.make { + Contract.make { label 'return_book_1' input { triggeredBy('bookReturnedTriggered()') @@ -165,9 +181,9 @@ class StreamStubRunnerSpec extends Specification { } // end::sample_dsl[] - GroovyDsl dsl2 = + Contract dsl2 = // tag::sample_dsl_2[] - io.codearte.accurest.dsl.GroovyDsl.make { + Contract.make { label 'return_book_2' input { messageFrom('bookStorage') @@ -190,9 +206,9 @@ class StreamStubRunnerSpec extends Specification { } // end::sample_dsl_2[] - GroovyDsl dsl3 = + Contract dsl3 = // tag::sample_dsl_3[] - io.codearte.accurest.dsl.GroovyDsl.make { + Contract.make { label 'delete_book' input { messageFrom('delete') diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/resources/application.yml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/resources/application.yml similarity index 66% rename from stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/resources/application.yml rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/resources/application.yml index 0bcac69997..f7c3f12f4a 100644 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/resources/application.yml +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/resources/application.yml @@ -1,5 +1,5 @@ stubrunner.stubs.repository.root: classpath:m2repo/repository/ -stubrunner.stubs.ids: io.codearte.accurest.stubs:streamService:0.0.1-SNAPSHOT:stubs +stubrunner.stubs.ids: org.springframework.cloud.contract.verifier.stubs:streamService:0.0.1-SNAPSHOT:stubs spring: cloud: diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/0.0.1-SNAPSHOT/maven-metadata-local.xml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/0.0.1-SNAPSHOT/maven-metadata-local.xml new file mode 100644 index 0000000000..f14e885df3 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/0.0.1-SNAPSHOT/maven-metadata-local.xml @@ -0,0 +1,28 @@ + + + + + org.springframework.cloud.contract.verifier.stubs + streamService + 0.0.1-SNAPSHOT + + + true + + 20160409062112 + + diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT-stubs.jar b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT-stubs.jar new file mode 100644 index 0000000000..2fee7265b6 Binary files /dev/null and b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT-stubs.jar differ diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT.pom b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT.pom new file mode 100644 index 0000000000..8613d57be0 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT.pom @@ -0,0 +1,25 @@ + + + + + 4.0.0 + org.springframework.cloud.contract.verifier.stubs + streamService + 0.0.1-SNAPSHOT + pom + diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/maven-metadata-local.xml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/maven-metadata-local.xml new file mode 100644 index 0000000000..001cf26899 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/maven-metadata-local.xml @@ -0,0 +1,28 @@ + + + + + org.springframework.cloud.contract.verifier.stubs + streamService + 0.0.1-SNAPSHOT + + + 0.0.1-SNAPSHOT + + 20160409062112 + + diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/maven-metadata.xml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/maven-metadata.xml new file mode 100644 index 0000000000..001cf26899 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-messaging/spring-cloud-contract-stub-runner-stream/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/streamService/maven-metadata.xml @@ -0,0 +1,28 @@ + + + + + org.springframework.cloud.contract.verifier.stubs + streamService + 0.0.1-SNAPSHOT + + + 0.0.1-SNAPSHOT + + 20160409062112 + + diff --git a/stub-runner/stub-runner-spring-cloud/README.adoc b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/README.adoc similarity index 94% rename from stub-runner/stub-runner-spring-cloud/README.adoc rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/README.adoc index 25e0ca4341..7ea59a2a37 100644 --- a/stub-runner/stub-runner-spring-cloud/README.adoc +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/README.adoc @@ -4,7 +4,7 @@ Registers the stubs in the provided Service Discovery. It's enough to add the ja [source,groovy,indent=0] ---- -io.codearte.accurest:stub-runner-spring-cloud +org.springframework.cloud.contract:stub-runner-spring-cloud ---- and the Stub Runner autoconfiguration should be picked up. diff --git a/stub-runner/stub-runner-spring-cloud/build.gradle b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/build.gradle similarity index 55% rename from stub-runner/stub-runner-spring-cloud/build.gradle rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/build.gradle index 7e3bc4a9a2..b015f00ef4 100644 --- a/stub-runner/stub-runner-spring-cloud/build.gradle +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/build.gradle @@ -1,5 +1,23 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +String stubRunner = "spring-cloud-contract-stub-runner" + dependencies { - compile project(':stub-runner-root:stub-runner-spring') + compile project(":$stubRunner-root:$stubRunner-spring") compile localGroovy() // TODO: should be compile only diff --git a/stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/StubMapperProperties.java b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubMapperProperties.java similarity index 66% rename from stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/StubMapperProperties.java rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubMapperProperties.java index c69ca674dc..79d405b9b0 100644 --- a/stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/StubMapperProperties.java +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubMapperProperties.java @@ -1,4 +1,20 @@ -package io.codearte.accurest.stubrunner.spring.cloud; +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.spring.cloud; import java.util.HashMap; import java.util.Map; @@ -17,6 +33,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * fraudDetectionServer: someNameThatShouldMapFraudDetectionServer * * @author Marcin Grzejszczak + * + * @since 1.0.0 */ @ConfigurationProperties("stubrunner.stubs") public class StubMapperProperties { diff --git a/stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/StubRunnerDiscoveryClient.java b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerDiscoveryClient.java similarity index 71% rename from stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/StubRunnerDiscoveryClient.java rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerDiscoveryClient.java index a6615fd5b0..e4905c7814 100644 --- a/stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/StubRunnerDiscoveryClient.java +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerDiscoveryClient.java @@ -1,4 +1,20 @@ -package io.codearte.accurest.stubrunner.spring.cloud; +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.spring.cloud; import java.net.URI; import java.net.URL; @@ -10,15 +26,17 @@ import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.noop.NoopDiscoveryClient; -import io.codearte.accurest.stubrunner.RunningStubs; -import io.codearte.accurest.stubrunner.StubFinder; -import io.codearte.accurest.stubrunner.util.StringUtils; +import org.springframework.cloud.contract.stubrunner.RunningStubs; +import org.springframework.cloud.contract.stubrunner.StubFinder; +import org.springframework.cloud.contract.stubrunner.util.StringUtils; /** * Custom version of {@link DiscoveryClient} that tries to find an instance * in one of the started WireMock servers * * @author Marcin Grzejszczak + * + * @since 1.0.0 */ public class StubRunnerDiscoveryClient implements DiscoveryClient { diff --git a/stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/StubRunnerServiceInstance.java b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerServiceInstance.java similarity index 57% rename from stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/StubRunnerServiceInstance.java rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerServiceInstance.java index ba5ee8249f..d34340f98e 100644 --- a/stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/StubRunnerServiceInstance.java +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerServiceInstance.java @@ -1,4 +1,20 @@ -package io.codearte.accurest.stubrunner.spring.cloud; +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.spring.cloud; import java.net.URI; import java.util.HashMap; @@ -10,6 +26,8 @@ import org.springframework.cloud.client.ServiceInstance; * {@link ServiceInstance} with a helpful constructor * * @author Marcin Grzejszczak + * + * @since 1.0.0 */ public class StubRunnerServiceInstance implements ServiceInstance { diff --git a/stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/StubRunnerSpringCloudAutoConfiguration.java b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerSpringCloudAutoConfiguration.java similarity index 64% rename from stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/StubRunnerSpringCloudAutoConfiguration.java rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerSpringCloudAutoConfiguration.java index b5d78bfe78..6a5ec3f72d 100644 --- a/stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/StubRunnerSpringCloudAutoConfiguration.java +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerSpringCloudAutoConfiguration.java @@ -1,22 +1,40 @@ -package io.codearte.accurest.stubrunner.spring.cloud; +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.spring.cloud; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cloud.contract.stubrunner.spring.StubRunnerConfiguration; import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Primary; -import io.codearte.accurest.stubrunner.StubFinder; -import io.codearte.accurest.stubrunner.spring.StubRunnerConfiguration; +import org.springframework.cloud.contract.stubrunner.StubFinder; /** * Wraps {@link DiscoveryClient} in a Stub Runner implementation that tries to find * a corresponding WireMock server for a searched dependency + * + * @since 1.0.0 */ @Configuration @EnableConfigurationProperties diff --git a/stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/ribbon/StubRunnerRibbonAutoConfiguration.java b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonAutoConfiguration.java similarity index 53% rename from stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/ribbon/StubRunnerRibbonAutoConfiguration.java rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonAutoConfiguration.java index 9bffb4c1ea..7e886e6eac 100644 --- a/stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/ribbon/StubRunnerRibbonAutoConfiguration.java +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonAutoConfiguration.java @@ -1,7 +1,23 @@ -package io.codearte.accurest.stubrunner.spring.cloud.ribbon; +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.spring.cloud.ribbon; import com.netflix.loadbalancer.ServerList; -import io.codearte.accurest.stubrunner.spring.cloud.StubMapperProperties; +import org.springframework.cloud.contract.stubrunner.spring.cloud.StubMapperProperties; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; diff --git a/stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/ribbon/StubRunnerRibbonBeanPostProcessor.java b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonBeanPostProcessor.java similarity index 67% rename from stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/ribbon/StubRunnerRibbonBeanPostProcessor.java rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonBeanPostProcessor.java index fc4e801e0a..9ba1002603 100644 --- a/stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/ribbon/StubRunnerRibbonBeanPostProcessor.java +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonBeanPostProcessor.java @@ -1,9 +1,25 @@ -package io.codearte.accurest.stubrunner.spring.cloud.ribbon; +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.spring.cloud.ribbon; import com.netflix.client.config.IClientConfig; import com.netflix.loadbalancer.ServerList; -import io.codearte.accurest.stubrunner.StubFinder; -import io.codearte.accurest.stubrunner.spring.cloud.StubMapperProperties; +import org.springframework.cloud.contract.stubrunner.StubFinder; +import org.springframework.cloud.contract.stubrunner.spring.cloud.StubMapperProperties; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.config.BeanPostProcessor; @@ -13,6 +29,8 @@ import org.springframework.beans.factory.config.BeanPostProcessor; * be picked from the list of available WireMock instance if one is available. * * @author Marcin Grzejszczak + * + * @since 1.0.0 */ class StubRunnerRibbonBeanPostProcessor implements BeanPostProcessor { diff --git a/stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/ribbon/StubRunnerRibbonConfiguration.java b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonConfiguration.java similarity index 56% rename from stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/ribbon/StubRunnerRibbonConfiguration.java rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonConfiguration.java index 68aedc86ea..b03d729a5f 100644 --- a/stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/ribbon/StubRunnerRibbonConfiguration.java +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonConfiguration.java @@ -1,4 +1,20 @@ -package io.codearte.accurest.stubrunner.spring.cloud.ribbon; +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.spring.cloud.ribbon; import com.netflix.loadbalancer.Server; import com.netflix.loadbalancer.ServerList; diff --git a/stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/ribbon/StubRunnerRibbonServerList.java b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonServerList.java similarity index 70% rename from stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/ribbon/StubRunnerRibbonServerList.java rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonServerList.java index 2feca19e9b..e0efe4bc8d 100644 --- a/stub-runner/stub-runner-spring-cloud/src/main/groovy/io/codearte/accurest/stubrunner/spring/cloud/ribbon/StubRunnerRibbonServerList.java +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonServerList.java @@ -1,23 +1,42 @@ -package io.codearte.accurest.stubrunner.spring.cloud.ribbon; +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import com.netflix.client.config.IClientConfig; -import com.netflix.loadbalancer.Server; -import com.netflix.loadbalancer.ServerList; -import io.codearte.accurest.stubrunner.RunningStubs; -import io.codearte.accurest.stubrunner.StubConfiguration; -import io.codearte.accurest.stubrunner.StubFinder; -import io.codearte.accurest.stubrunner.spring.cloud.StubMapperProperties; -import io.codearte.accurest.stubrunner.util.StringUtils; +package org.springframework.cloud.contract.stubrunner.spring.cloud.ribbon; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; +import com.netflix.client.config.IClientConfig; +import com.netflix.loadbalancer.Server; +import com.netflix.loadbalancer.ServerList; + +import org.springframework.cloud.contract.stubrunner.RunningStubs; +import org.springframework.cloud.contract.stubrunner.StubConfiguration; +import org.springframework.cloud.contract.stubrunner.StubFinder; +import org.springframework.cloud.contract.stubrunner.spring.cloud.StubMapperProperties; +import org.springframework.cloud.contract.stubrunner.util.StringUtils; + /** * Stub Runner representation of a server list * * @author Marcin Grzejszczak + * + * @since 1.0.0 */ class StubRunnerRibbonServerList implements ServerList { diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/resources/META-INF/spring.factories b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000000..fd191f3591 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/main/resources/META-INF/spring.factories @@ -0,0 +1,4 @@ +# Auto Configuration +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.springframework.cloud.contract.stubrunner.spring.cloud.StubRunnerSpringCloudAutoConfiguration,\ +org.springframework.cloud.contract.stubrunner.spring.cloud.ribbon.StubRunnerRibbonAutoConfiguration diff --git a/stub-runner/stub-runner-spring-cloud/src/test/groovy/io/codearte/accurest/stubrunner/spring/cloud/StubRunnerSpringCloudAutoConfigurationSpec.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerSpringCloudAutoConfigurationSpec.groovy similarity index 74% rename from stub-runner/stub-runner-spring-cloud/src/test/groovy/io/codearte/accurest/stubrunner/spring/cloud/StubRunnerSpringCloudAutoConfigurationSpec.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerSpringCloudAutoConfigurationSpec.groovy index 741d7ccbe0..8a3c6f886e 100644 --- a/stub-runner/stub-runner-spring-cloud/src/test/groovy/io/codearte/accurest/stubrunner/spring/cloud/StubRunnerSpringCloudAutoConfigurationSpec.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerSpringCloudAutoConfigurationSpec.groovy @@ -1,11 +1,27 @@ -package io.codearte.accurest.stubrunner.spring.cloud +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.spring.cloud -import io.codearte.accurest.stubrunner.StubFinder import org.apache.curator.test.TestingServer import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.autoconfigure.EnableAutoConfiguration import org.springframework.boot.test.SpringApplicationContextLoader import org.springframework.boot.test.WebIntegrationTest +import org.springframework.cloud.contract.stubrunner.StubFinder import org.springframework.cloud.client.discovery.EnableDiscoveryClient import org.springframework.cloud.client.loadbalancer.LoadBalanced import org.springframework.cloud.zookeeper.discovery.ZookeeperServiceDiscovery diff --git a/stub-runner/stub-runner-spring-cloud/src/test/resources/application.yml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/resources/application.yml similarity index 56% rename from stub-runner/stub-runner-spring-cloud/src/test/resources/application.yml rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/resources/application.yml index 051a8a328e..629b688f80 100644 --- a/stub-runner/stub-runner-spring-cloud/src/test/resources/application.yml +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/resources/application.yml @@ -1,5 +1,5 @@ stubrunner.stubs.repository.root: classpath:m2repo/repository/ -stubrunner.stubs.ids: io.codearte.accurest.stubs:loanIssuance,io.codearte.accurest.stubs:fraudDetectionServer +stubrunner.stubs.ids: org.springframework.cloud.contract.verifier.stubs:loanIssuance,org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer stubrunner.stubs.idsToServiceIds: ivyNotation: someValueInsideYourCode diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/resources/logback.xml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/resources/logback.xml new file mode 100644 index 0000000000..7eecabf2f2 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/resources/logback.xml @@ -0,0 +1,30 @@ + + + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + \ No newline at end of file diff --git a/stub-runner/stub-runner-spring-cloud/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT-stubs.jar b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT-stubs.jar similarity index 100% rename from stub-runner/stub-runner-spring-cloud/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT-stubs.jar rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT-stubs.jar diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT.pom b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT.pom new file mode 100644 index 0000000000..40610c8cdb --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT.pom @@ -0,0 +1,25 @@ + + + + + 4.0.0 + org.springframework.cloud.contract.verifier.stubs + fraudDetectionServer + 0.0.1-SNAPSHOT + pom + diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/maven-metadata.xml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/maven-metadata.xml new file mode 100644 index 0000000000..281b9b3b80 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/maven-metadata.xml @@ -0,0 +1,28 @@ + + + + + org.springframework.cloud.contract.verifier.stubs + fraudDetectionServer + 0.0.1-SNAPSHOT + + + 0.0.1-SNAPSHOT + + 20160409062112 + + diff --git a/stub-runner/stub-runner-spring-cloud/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT-stubs.jar b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT-stubs.jar similarity index 100% rename from stub-runner/stub-runner-spring-cloud/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT-stubs.jar rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT-stubs.jar diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT.pom b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT.pom new file mode 100644 index 0000000000..59db343686 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT.pom @@ -0,0 +1,25 @@ + + + + + 4.0.0 + org.springframework.cloud.contract.verifier.stubs + loanIssuance + 0.0.1-SNAPSHOT + pom + diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/maven-metadata.xml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/maven-metadata.xml new file mode 100644 index 0000000000..615428dae6 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/maven-metadata.xml @@ -0,0 +1,28 @@ + + + + + org.springframework.cloud.contract.verifier.stubs + loanIssuance + 0.0.1-SNAPSHOT + + + 0.0.1-SNAPSHOT + + 20160409062111 + + diff --git a/stub-runner/stub-runner-spring/README.adoc b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/README.adoc similarity index 80% rename from stub-runner/stub-runner-spring/README.adoc rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/README.adoc index 51342e9c14..38169894bf 100644 --- a/stub-runner/stub-runner-spring/README.adoc +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/README.adoc @@ -10,7 +10,7 @@ its methods as presented below: [source,groovy,indent=0] ---- -include::src/test/groovy/io/codearte/accurest/stubrunner/spring/StubRunnerConfigurationSpec.groovy[tags=test] +include::src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/StubRunnerConfigurationSpec.groovy[tags=test] ---- for the following configuration file: diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/build.gradle b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/build.gradle new file mode 100644 index 0000000000..32586d07e3 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/build.gradle @@ -0,0 +1,38 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +description = 'Spring configuration for stub-runner' + +String stubRunner = "spring-cloud-contract-stub-runner" + +dependencies { + compile project(":$stubRunner-root:$stubRunner") + + compile localGroovy() + compile "org.springframework:spring-context:${springVersion}" + + testCompile('org.spockframework:spock-core:1.0-groovy-2.4') { + exclude(group: 'org.codehaus.groovy') + } + testCompile 'cglib:cglib-nodep:2.2' + testCompile 'org.objenesis:objenesis:2.1' + testCompile "org.springframework.boot:spring-boot-starter:${springBootVersion}" + testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" + testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { + exclude(group: 'org.codehaus.groovy') + } + testCompile 'ch.qos.logback:logback-classic:1.1.3' +} diff --git a/stub-runner/stub-runner-spring/src/main/groovy/io/codearte/accurest/stubrunner/spring/StubRunnerConfiguration.java b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/StubRunnerConfiguration.java similarity index 60% rename from stub-runner/stub-runner-spring/src/main/groovy/io/codearte/accurest/stubrunner/spring/StubRunnerConfiguration.java rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/StubRunnerConfiguration.java index 5ba1a3cc66..bea711f6f1 100644 --- a/stub-runner/stub-runner-spring/src/main/groovy/io/codearte/accurest/stubrunner/spring/StubRunnerConfiguration.java +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/main/groovy/org/springframework/cloud/contract/stubrunner/spring/StubRunnerConfiguration.java @@ -1,30 +1,46 @@ -package io.codearte.accurest.stubrunner.spring; +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.spring; + +import java.io.IOException; -import io.codearte.accurest.messaging.AccurestMessaging; -import io.codearte.accurest.messaging.noop.NoOpAccurestMessaging; -import io.codearte.accurest.stubrunner.AetherStubDownloader; -import io.codearte.accurest.stubrunner.BatchStubRunner; -import io.codearte.accurest.stubrunner.BatchStubRunnerFactory; -import io.codearte.accurest.stubrunner.StubDownloader; -import io.codearte.accurest.stubrunner.StubRunner; -import io.codearte.accurest.stubrunner.StubRunnerOptions; -import io.codearte.accurest.stubrunner.StubRunnerOptionsBuilder; -import io.codearte.accurest.stubrunner.StubRunning; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.contract.stubrunner.AetherStubDownloader; +import org.springframework.cloud.contract.stubrunner.BatchStubRunner; +import org.springframework.cloud.contract.stubrunner.BatchStubRunnerFactory; +import org.springframework.cloud.contract.stubrunner.StubDownloader; +import org.springframework.cloud.contract.stubrunner.StubRunner; +import org.springframework.cloud.contract.stubrunner.StubRunnerOptions; +import org.springframework.cloud.contract.stubrunner.StubRunnerOptionsBuilder; +import org.springframework.cloud.contract.stubrunner.StubRunning; +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging; +import org.springframework.cloud.contract.verifier.messaging.noop.NoOpContractVerifierMessaging; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.Resource; -import java.io.IOException; - /** * Configuration that initializes a {@link BatchStubRunner} that runs {@link StubRunner} instance for each stub */ @Configuration public class StubRunnerConfiguration { - @Autowired(required = false) AccurestMessaging accurestMessaging; + @Autowired(required = false) ContractVerifierMessaging contractVerifierMessaging; @Autowired(required = false) StubDownloader stubDownloader; /** @@ -56,7 +72,7 @@ public class StubRunnerConfiguration { .build(); BatchStubRunner batchStubRunner = new BatchStubRunnerFactory(stubRunnerOptions, stubDownloader != null ? stubDownloader : new AetherStubDownloader(stubRunnerOptions), - accurestMessaging != null ? accurestMessaging : new NoOpAccurestMessaging()).buildBatchStubRunner(); + contractVerifierMessaging != null ? contractVerifierMessaging : new NoOpContractVerifierMessaging()).buildBatchStubRunner(); // TODO: Consider running it in a separate thread batchStubRunner.runStubs(); return batchStubRunner; diff --git a/accurest-messaging/accurest-messaging-camel/src/main/resources/META-INF/spring.factories b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/main/resources/META-INF/spring.factories similarity index 53% rename from accurest-messaging/accurest-messaging-camel/src/main/resources/META-INF/spring.factories rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/main/resources/META-INF/spring.factories index 318eec3472..d39588e8dc 100644 --- a/accurest-messaging/accurest-messaging-camel/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/main/resources/META-INF/spring.factories @@ -1,3 +1,3 @@ # Auto Configuration org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -io.codearte.accurest.messaging.camel.AccurestCamelConfiguration +org.springframework.cloud.contract.stubrunner.spring.StubRunnerConfiguration \ No newline at end of file diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/StubRunnerConfigurationSpec.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/StubRunnerConfigurationSpec.groovy new file mode 100644 index 0000000000..4d9b01856d --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/StubRunnerConfigurationSpec.groovy @@ -0,0 +1,57 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.spring + +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.boot.test.SpringApplicationContextLoader +import org.springframework.cloud.contract.stubrunner.StubFinder +import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Import +import org.springframework.test.context.ContextConfiguration +import spock.lang.Specification + +/** + * @author Marcin Grzejszczak + */ +// tag::test[] +@ContextConfiguration(classes = Config, loader = SpringApplicationContextLoader) +class StubRunnerConfigurationSpec extends Specification { + + @Autowired StubFinder stubFinder + + def 'should start WireMock servers'() { + expect: 'WireMocks are running' + stubFinder.findStubUrl('org.springframework.cloud.contract.verifier.stubs', 'loanIssuance') != null + stubFinder.findStubUrl('loanIssuance') != null + stubFinder.findStubUrl('loanIssuance') == stubFinder.findStubUrl('org.springframework.cloud.contract.verifier.stubs', 'loanIssuance') + stubFinder.findStubUrl('org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer') != null + and: + stubFinder.findAllRunningStubs().isPresent('loanIssuance') + stubFinder.findAllRunningStubs().isPresent('org.springframework.cloud.contract.verifier.stubs', 'fraudDetectionServer') + stubFinder.findAllRunningStubs().isPresent('org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer') + and: 'Stubs were registered' + "${stubFinder.findStubUrl('loanIssuance').toString()}/name".toURL().text == 'loanIssuance' + "${stubFinder.findStubUrl('fraudDetectionServer').toString()}/name".toURL().text == 'fraudDetectionServer' + } + + @Configuration + @Import(StubRunnerConfiguration) + @EnableAutoConfiguration + static class Config {} +} +// end::test[] \ No newline at end of file diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/resources/application.yml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/resources/application.yml new file mode 100644 index 0000000000..4f618057e1 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/resources/application.yml @@ -0,0 +1,2 @@ +stubrunner.stubs.repository.root: classpath:m2repo/repository/ +stubrunner.stubs.ids: org.springframework.cloud.contract.verifier.stubs:loanIssuance,org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer \ No newline at end of file diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/resources/logback.xml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/resources/logback.xml new file mode 100644 index 0000000000..7eecabf2f2 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/resources/logback.xml @@ -0,0 +1,30 @@ + + + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + \ No newline at end of file diff --git a/stub-runner/stub-runner-spring/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT-stubs.jar b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT-stubs.jar similarity index 100% rename from stub-runner/stub-runner-spring/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT-stubs.jar rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT-stubs.jar diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT.pom b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT.pom new file mode 100644 index 0000000000..40610c8cdb --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT.pom @@ -0,0 +1,25 @@ + + + + + 4.0.0 + org.springframework.cloud.contract.verifier.stubs + fraudDetectionServer + 0.0.1-SNAPSHOT + pom + diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/maven-metadata.xml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/maven-metadata.xml new file mode 100644 index 0000000000..281b9b3b80 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/maven-metadata.xml @@ -0,0 +1,28 @@ + + + + + org.springframework.cloud.contract.verifier.stubs + fraudDetectionServer + 0.0.1-SNAPSHOT + + + 0.0.1-SNAPSHOT + + 20160409062112 + + diff --git a/stub-runner/stub-runner-spring/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT-stubs.jar b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT-stubs.jar similarity index 100% rename from stub-runner/stub-runner-spring/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT-stubs.jar rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT-stubs.jar diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT.pom b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT.pom new file mode 100644 index 0000000000..59db343686 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT.pom @@ -0,0 +1,25 @@ + + + + + 4.0.0 + org.springframework.cloud.contract.verifier.stubs + loanIssuance + 0.0.1-SNAPSHOT + pom + diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/maven-metadata.xml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/maven-metadata.xml new file mode 100644 index 0000000000..615428dae6 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/maven-metadata.xml @@ -0,0 +1,28 @@ + + + + + org.springframework.cloud.contract.verifier.stubs + loanIssuance + 0.0.1-SNAPSHOT + + + 0.0.1-SNAPSHOT + + 20160409062111 + + diff --git a/stub-runner/stub-runner/README.adoc b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/README.adoc similarity index 84% rename from stub-runner/stub-runner/README.adoc rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/README.adoc index 075d1c7a6a..fd0ace56e4 100644 --- a/stub-runner/stub-runner/README.adoc +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/README.adoc @@ -41,14 +41,14 @@ Just call the following command: [source,groovy,indent=0] ---- -./gradlew stub-runner-root:stub-runner:shadowJar -PfatJar +./gradlew spring-cloud-contract-stub-runner-root:spring-cloud-contract-stub-runner:shadowJar -PfatJar ---- and inside the `build/lib` there will be a Fat Jar with classifier `fatJar` waiting for you to execute. E.g. [source,groovy,indent=0] ---- -java -jar stub-runner/stub-runner/build/libs/stub-runner-1.0.1-SNAPSHOT-fatJar.jar -sr http://a.b.com -s a:b:c,d:e,f:g:h:i +java -jar spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/build/libs/spring-cloud-contract-stub-runner-1.0.0-SNAPSHOT-fatJar.jar -sr http://a.b.com -s a:b:c,d:e,f:g:h:i ---- ==== Stub runner configuration @@ -57,14 +57,14 @@ You can configure the stub runner by either passing the full arguments list with [source,groovy,indent=0] ---- -./gradlew stub-runner-root:stub-runner:run -Pargs="-c pl -minp 10000 -maxp 10005 -s a:b:c,d:e,f:g:h" +./gradlew spring-cloud-contract-stub-runner-root:spring-cloud-contract-stub-runner:run -Pargs="-c pl -minp 10000 -maxp 10005 -s a:b:c,d:e,f:g:h" ---- or each parameter separately with a `-P` prefix and without the hyphen `-` in the name of the param [source,groovy,indent=0] ---- -./gradlew stub-runner-root:stub-runner:run -Pc=pl -Pminp=10000 -Pmaxp=10005 -Ps=a:b:c,d:e,f:g:h +./gradlew spring-cloud-contract-stub-runner-root:spring-cloud-contract-stub-runner:run -Pc=pl -Pminp=10000 -Pmaxp=10005 -Ps=a:b:c,d:e,f:g:h ---- ===== HTTP Stubs diff --git a/stub-runner/stub-runner/build.gradle b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/build.gradle similarity index 75% rename from stub-runner/stub-runner/build.gradle rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/build.gradle index c633e222aa..dc362bdbdb 100644 --- a/stub-runner/stub-runner/build.gradle +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/build.gradle @@ -1,11 +1,29 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + description = 'Runs stubs for service collaborators' apply plugin: 'application' -mainClassName = 'io.codearte.accurest.stubrunner.StubRunnerMain' +mainClassName = 'org.springframework.cloud.stubrunner.StubRunnerMain' + +String verifier = "spring-cloud-contract-verifier" dependencies { - compile project(':accurest-core') - compile project(':accurest-messaging-root:accurest-messaging-core') + compile project(":$verifier-root:$verifier-core") + compile project(":$verifier-root:$verifier-messaging-root:$verifier-messaging-core") compile 'org.codehaus.groovy:groovy-all:2.4.4' compile "com.github.tomakehurst:wiremock:$wiremockVersion" compile 'javax.servlet:javax.servlet-api:3.1.0' @@ -46,7 +64,7 @@ Object getPropertyByEither(String paramName1, String paramName2, Object defaultV } run { - main = 'io.codearte.accurest.stubrunner.StubRunnerMain' + main = 'org.springframework.cloud.stubrunner.StubRunnerMain' List argumentList if (arguments) { argumentList = (arguments.split(' ') as List).findAll { it != null } diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/AetherFactories.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/AetherFactories.groovy similarity index 76% rename from stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/AetherFactories.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/AetherFactories.groovy index 4999d49b93..df67a84c25 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/AetherFactories.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/AetherFactories.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner import org.apache.maven.repository.internal.MavenRepositorySystemUtils import org.eclipse.aether.DefaultRepositorySystemSession diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/AetherStubDownloader.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/AetherStubDownloader.groovy similarity index 81% rename from stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/AetherStubDownloader.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/AetherStubDownloader.groovy index 271d98cceb..588e26c0b4 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/AetherStubDownloader.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/AetherStubDownloader.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner import groovy.transform.CompileStatic import groovy.util.logging.Slf4j @@ -14,10 +30,10 @@ import org.eclipse.aether.resolution.VersionRangeResult import org.eclipse.aether.resolution.VersionRequest import org.eclipse.aether.resolution.VersionResult -import static io.codearte.accurest.stubrunner.AetherFactories.newRepositories -import static io.codearte.accurest.stubrunner.AetherFactories.newRepositorySystem -import static io.codearte.accurest.stubrunner.AetherFactories.newSession -import static io.codearte.accurest.stubrunner.util.ZipCategory.unzipTo +import static AetherFactories.newRepositories +import static AetherFactories.newRepositorySystem +import static AetherFactories.newSession +import static org.springframework.cloud.contract.stubrunner.util.ZipCategory.unzipTo import static java.nio.file.Files.createTempDirectory /** @@ -27,7 +43,7 @@ import static java.nio.file.Files.createTempDirectory @Slf4j class AetherStubDownloader implements StubDownloader { - private static final String ACCUREST_TEMP_DIR_PREFIX = 'accurest' + private static final String TEMP_DIR_PREFIX = 'contracts' private static final String ARTIFACT_EXTENSION = 'jar' private static final String LATEST_ARTIFACT_VERSION = '(,]' private static final String LATEST_VERSION_IN_IVY = '+' @@ -46,7 +62,7 @@ class AetherStubDownloader implements StubDownloader { } /** - * Used by Accurest Maven Plugin + * Used by the Maven Plugin * * @param repositorySystem * @param remoteRepositories - remote artifact repositories @@ -80,7 +96,9 @@ class AetherStubDownloader implements StubDownloader { try { ArtifactResult result = repositorySystem.resolveArtifact(session, request) log.info("Resolved artifact $artifact to ${result.artifact.file}") - return unpackStubJarToATemporaryFolder(result.artifact.file.toURI()) + File temporaryFile = unpackStubJarToATemporaryFolder(result.artifact.file.toURI()) + log.info("Unpacked file to [$temporaryFile]") + return temporaryFile } catch (Exception e) { log.warn("Exception occured while trying to download a stub for group [$stubsGroup] module [$stubsModule] and classifier [$classifier] in $remoteRepos", e) return null @@ -127,7 +145,7 @@ class AetherStubDownloader implements StubDownloader { } private static File unpackStubJarToATemporaryFolder(URI stubJarUri) { - File tmpDirWhereStubsWillBeUnzipped = createTempDirectory(ACCUREST_TEMP_DIR_PREFIX).toFile() + File tmpDirWhereStubsWillBeUnzipped = createTempDirectory(TEMP_DIR_PREFIX).toFile() tmpDirWhereStubsWillBeUnzipped.deleteOnExit() log.info("Unpacking stub from JAR [URI: ${stubJarUri}]") unzipTo(new File(stubJarUri), tmpDirWhereStubsWillBeUnzipped) diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/Arguments.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/Arguments.groovy new file mode 100644 index 0000000000..254bc0634b --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/Arguments.groovy @@ -0,0 +1,43 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner + +import groovy.transform.CompileStatic +import groovy.transform.PackageScope +import groovy.transform.ToString + +/** + * Arguments passed to the {@link StubRunner} application + * + * @see StubRunner + */ +@CompileStatic +@ToString(includeNames = true) +@PackageScope +class Arguments { + final StubRunnerOptions stubRunnerOptions + final String context + final String repositoryPath + final StubConfiguration stub + + Arguments(StubRunnerOptions stubRunnerOptions, String repositoryPath = "", StubConfiguration stub = null) { + this.stubRunnerOptions = stubRunnerOptions + this.context = context + this.repositoryPath = repositoryPath + this.stub = stub + } +} diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/AvailablePortScanner.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/AvailablePortScanner.groovy similarity index 76% rename from stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/AvailablePortScanner.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/AvailablePortScanner.groovy index 36251d4524..d493199106 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/AvailablePortScanner.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/AvailablePortScanner.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner import groovy.transform.CompileStatic import groovy.transform.PackageScope diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/BatchStubRunner.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/BatchStubRunner.groovy similarity index 76% rename from stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/BatchStubRunner.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/BatchStubRunner.groovy index c2c20567dd..978ca3e109 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/BatchStubRunner.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/BatchStubRunner.groovy @@ -1,7 +1,23 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner import groovy.transform.CompileStatic -import io.codearte.accurest.dsl.GroovyDsl +import org.springframework.cloud.contract.verifier.dsl.Contract /** * Manages lifecycle of multiple {@link StubRunner} instances. * @@ -49,11 +65,11 @@ class BatchStubRunner implements StubRunning { } @Override - Map> getAccurestContracts() { - return stubRunners.inject([:]) { Map> map, StubRunner stubRunner -> - map.putAll(stubRunner.accurestContracts ?: [:]) + Map> getContracts() { + return stubRunners.inject([:]) { Map> map, StubRunner stubRunner -> + map.putAll(stubRunner.contracts ?: [:]) return map - } as Map> + } as Map> } @Override diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/BatchStubRunnerFactory.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/BatchStubRunnerFactory.groovy new file mode 100644 index 0000000000..6261afe289 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/BatchStubRunnerFactory.groovy @@ -0,0 +1,59 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner + +import groovy.transform.CompileStatic +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging +import org.springframework.cloud.contract.verifier.messaging.noop.NoOpContractVerifierMessaging + +/** + * Manages lifecycle of multiple {@link StubRunner} instances. + * + * @see StubRunner + * @see BatchStubRunner + */ +@CompileStatic +class BatchStubRunnerFactory { + + private final StubRunnerOptions stubRunnerOptions + private final StubDownloader stubDownloader + private final ContractVerifierMessaging contractVerifierMessaging + + BatchStubRunnerFactory(StubRunnerOptions stubRunnerOptions) { + this(stubRunnerOptions, new AetherStubDownloader(stubRunnerOptions), new NoOpContractVerifierMessaging()) + } + + BatchStubRunnerFactory(StubRunnerOptions stubRunnerOptions, ContractVerifierMessaging contractVerifierMessaging) { + this(stubRunnerOptions, new AetherStubDownloader(stubRunnerOptions), contractVerifierMessaging) + } + + BatchStubRunnerFactory(StubRunnerOptions stubRunnerOptions, StubDownloader stubDownloader) { + this(stubRunnerOptions, stubDownloader, new NoOpContractVerifierMessaging()) + } + + BatchStubRunnerFactory(StubRunnerOptions stubRunnerOptions, StubDownloader stubDownloader, ContractVerifierMessaging contractVerifierMessaging) { + this.stubRunnerOptions = stubRunnerOptions + this.stubDownloader = stubDownloader + this.contractVerifierMessaging = contractVerifierMessaging + } + + BatchStubRunner buildBatchStubRunner() { + StubRunnerFactory stubRunnerFactory = new StubRunnerFactory(stubRunnerOptions, stubDownloader, contractVerifierMessaging) + return new BatchStubRunner(stubRunnerFactory.createStubsFromServiceConfiguration()) + } + +} diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/GroovyDslWrapper.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/GroovyDslWrapper.groovy new file mode 100644 index 0000000000..252a60510c --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/GroovyDslWrapper.groovy @@ -0,0 +1,39 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner + +import groovy.transform.CompileStatic +import groovy.transform.PackageScope +import org.springframework.cloud.contract.verifier.dsl.Contract + +/** + * @author Marcin Grzejszczak + */ +@PackageScope +@CompileStatic +class GroovyDslWrapper { + + @Delegate final Contract groovyDsl + + GroovyDslWrapper(Contract groovyDsl) { + this.groovyDsl = groovyDsl + } + + boolean hasHttpPart() { + return groovyDsl.request + } +} diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/MessageNotMatchingException.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/MessageNotMatchingException.groovy new file mode 100644 index 0000000000..d99d288ee0 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/MessageNotMatchingException.groovy @@ -0,0 +1,28 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner + +import groovy.transform.InheritConstructors + +/** + * Exception thrown when message is not matched + * + * @author Marcin Grzejszczak + */ +@InheritConstructors +class MessageNotMatchingException extends RuntimeException { +} diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/RunningStubs.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/RunningStubs.groovy similarity index 71% rename from stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/RunningStubs.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/RunningStubs.groovy index 90520ca15d..d0d0b3f657 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/RunningStubs.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/RunningStubs.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner import groovy.transform.CompileStatic import groovy.transform.EqualsAndHashCode diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubConfiguration.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubConfiguration.groovy similarity index 84% rename from stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubConfiguration.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubConfiguration.groovy index 5d04e09850..82daa2d0cc 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubConfiguration.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubConfiguration.groovy @@ -1,9 +1,26 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner import groovy.transform.CompileDynamic import groovy.transform.CompileStatic import groovy.transform.EqualsAndHashCode -import io.codearte.accurest.stubrunner.util.StringUtils +import org.springframework.cloud.contract.stubrunner.util.StringUtils + /** * Represents a configuration of a single stub. The stub can be described * by groupId:artifactId:classifier notation diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubData.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubData.groovy new file mode 100644 index 0000000000..c203c5659d --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubData.groovy @@ -0,0 +1,31 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner + +import groovy.transform.CompileStatic +import groovy.transform.EqualsAndHashCode +import org.springframework.cloud.contract.verifier.dsl.Contract + +/** + * @author Marcin Grzejszczak + */ +@CompileStatic +@EqualsAndHashCode +class StubData { + final Integer port + final List contracts +} diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubDownloader.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubDownloader.groovy new file mode 100644 index 0000000000..fba3a207a1 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubDownloader.groovy @@ -0,0 +1,28 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner + +interface StubDownloader { + + /** + * Returns a mapping of updated StubConfiguration (it will contain the resolved version) and the location of the downloaded JAR. + * If there was no artifact this method will return {@code null}. + */ + Map.Entry downloadAndUnpackStubJar(StubRunnerOptions options, StubConfiguration stubConfiguration) + + +} \ No newline at end of file diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubFinder.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubFinder.groovy new file mode 100644 index 0000000000..368494fb04 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubFinder.groovy @@ -0,0 +1,49 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner + +import org.springframework.cloud.contract.verifier.dsl.Contract + +interface StubFinder extends StubTrigger { + /** + * For the given groupId and artifactId tries to find the matching + * URL of the running stub. + * + * @param groupId - might be null. In that case a search only via artifactId takes place + * @return URL of a running stub or null if not found + */ + URL findStubUrl(String groupId, String artifactId) + + /** + * For the given Ivy notation {@code groupId:artifactId} tries to find the matching + * URL of the running stub. You can also pass only {@code artifactId}. + * + * @param ivyNotation - Ivy representation of the Maven artifact + * @return URL of a running stub or null if not found + */ + URL findStubUrl(String ivyNotation) + + /** + * Returns all running stubs + */ + RunningStubs findAllRunningStubs() + + /** + * Returns the list of Contracts + */ + Map> getContracts() +} \ No newline at end of file diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRepository.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRepository.groovy similarity index 55% rename from stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRepository.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRepository.groovy index 78527dbd6c..b82b1c1694 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRepository.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRepository.groovy @@ -1,10 +1,27 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner import groovy.transform.CompileStatic import groovy.transform.PackageScope import groovy.util.logging.Slf4j -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.util.AccurestDslConverter +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.util.ContractVerifierDslConverter + /** * Wraps the folder with WireMock mappings. */ @@ -15,7 +32,7 @@ class StubRepository { private final File path final List projectDescriptors - final Collection accurestContracts + final Collection contracts StubRepository(File repository) { if (!repository.isDirectory()) { @@ -23,15 +40,15 @@ class StubRepository { } this.path = repository this.projectDescriptors = projectDescriptors() - this.accurestContracts = accurestContracts() + this.contracts = contracts() } /** - * Returns a list of {@link GroovyDsl} + * Returns a list of {@link Contract} */ - private Collection accurestContracts() { - List contracts = [] - contracts.addAll(accurestDescriptors()) + private Collection contracts() { + List contracts = [] + contracts.addAll(contractDescriptors()) return contracts } @@ -58,16 +75,16 @@ class StubRepository { return mappingDescriptors } - private Collection accurestDescriptors() { - return path.exists() ? collectAccurestDescriptors(path) : [] + private Collection contractDescriptors() { + return path.exists() ? collectContractDescriptors(path) : [] } - private Collection collectAccurestDescriptors(File descriptorsDirectory) { - List mappingDescriptors = [] + private Collection collectContractDescriptors(File descriptorsDirectory) { + List mappingDescriptors = [] descriptorsDirectory.eachFileRecurse { File file -> - if (isAccurestDescriptor(file)) { + if (isContractDescriptor(file)) { try { - mappingDescriptors << AccurestDslConverter.convert(file) + mappingDescriptors << ContractVerifierDslConverter.convert(file) } catch (Exception e) { log.warn("Exception occurred while trying to parse file [$file]", e) } @@ -80,7 +97,7 @@ class StubRepository { return file.isFile() && file.name.endsWith('.json') } - private static boolean isAccurestDescriptor(File file) { + private static boolean isContractDescriptor(File file) { //TODO: Consider script injections implications... return file.isFile() && file.name.endsWith('.groovy') } diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunner.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunner.groovy similarity index 66% rename from stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunner.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunner.groovy index c525646c5e..388eafcbce 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunner.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunner.groovy @@ -1,10 +1,26 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner import groovy.transform.CompileStatic import groovy.util.logging.Slf4j -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.messaging.AccurestMessaging -import io.codearte.accurest.messaging.noop.NoOpAccurestMessaging +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging +import org.springframework.cloud.contract.verifier.messaging.noop.NoOpContractVerifierMessaging /** * Represents a single instance of ready-to-run stubs. @@ -21,7 +37,7 @@ class StubRunner implements StubRunning { private final StubConfiguration stubsConfiguration private final StubRunnerOptions stubRunnerOptions private final StubRunnerExecutor localStubRunner - private final AccurestMessaging accurestMessaging + private final ContractVerifierMessaging contractVerifierMessaging @Deprecated StubRunner(Arguments arguments) { @@ -29,18 +45,18 @@ class StubRunner implements StubRunning { } StubRunner(StubRunnerOptions stubRunnerOptions, String repositoryPath, StubConfiguration stubsConfiguration) { - this(stubRunnerOptions, repositoryPath, stubsConfiguration, new NoOpAccurestMessaging()) + this(stubRunnerOptions, repositoryPath, stubsConfiguration, new NoOpContractVerifierMessaging()) } StubRunner(StubRunnerOptions stubRunnerOptions, String repositoryPath, StubConfiguration stubsConfiguration, - AccurestMessaging accurestMessaging) { + ContractVerifierMessaging contractVerifierMessaging) { this.stubsConfiguration = stubsConfiguration this.stubRunnerOptions = stubRunnerOptions this.stubRepository = new StubRepository(new File(repositoryPath)) AvailablePortScanner portScanner = new AvailablePortScanner(stubRunnerOptions.minPortValue, stubRunnerOptions.maxPortValue) - this.accurestMessaging = accurestMessaging - this.localStubRunner = new StubRunnerExecutor(portScanner, accurestMessaging) + this.contractVerifierMessaging = contractVerifierMessaging + this.localStubRunner = new StubRunnerExecutor(portScanner, contractVerifierMessaging) } @Override @@ -70,8 +86,8 @@ class StubRunner implements StubRunning { } @Override - Map> getAccurestContracts() { - return localStubRunner.getAccurestContracts() + Map> getContracts() { + return localStubRunner.getContracts() } @Override diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunnerExecutor.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerExecutor.groovy similarity index 58% rename from stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunnerExecutor.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerExecutor.groovy index 2852327f13..3f688e177d 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunnerExecutor.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerExecutor.groovy @@ -1,11 +1,27 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner import groovy.transform.CompileStatic import groovy.util.logging.Slf4j -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.messaging.AccurestMessage -import io.codearte.accurest.messaging.AccurestMessaging -import io.codearte.accurest.messaging.noop.NoOpAccurestMessaging +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging +import org.springframework.cloud.contract.verifier.messaging.noop.NoOpContractVerifierMessaging /** * Runs stubs for a particular {@link StubServer} @@ -15,17 +31,17 @@ import io.codearte.accurest.messaging.noop.NoOpAccurestMessaging class StubRunnerExecutor implements StubFinder { private final AvailablePortScanner portScanner - private final AccurestMessaging accurestMessaging + private final ContractVerifierMessaging contractVerifierMessaging private StubServer stubServer - StubRunnerExecutor(AvailablePortScanner portScanner, AccurestMessaging accurestMessaging) { + StubRunnerExecutor(AvailablePortScanner portScanner, ContractVerifierMessaging contractVerifierMessaging) { this.portScanner = portScanner - this.accurestMessaging = accurestMessaging + this.contractVerifierMessaging = contractVerifierMessaging } StubRunnerExecutor(AvailablePortScanner portScanner) { this.portScanner = portScanner - this.accurestMessaging = new NoOpAccurestMessaging() + this.contractVerifierMessaging = new NoOpContractVerifierMessaging() } RunningStubs runStubs(StubRunnerOptions stubRunnerOptions, StubRepository repository, StubConfiguration stubConfiguration) { @@ -64,25 +80,25 @@ class StubRunnerExecutor implements StubFinder { } @Override - Map> getAccurestContracts() { + Map> getContracts() { return [(stubServer.stubConfiguration): stubServer.contracts] } @Override boolean trigger(String ivyNotationAsString, String labelName) { - Collection matchingContracts = getAccurestContracts().findAll { + Collection matchingContracts = getContracts().findAll { it.key.groupIdAndArtifactMatches(ivyNotationAsString) - }.values().flatten() as Collection + }.values().flatten() as Collection return triggerForDsls(matchingContracts, labelName) } @Override boolean trigger(String labelName) { - return triggerForDsls(getAccurestContracts().values().flatten() as Collection, labelName) + return triggerForDsls(getContracts().values().flatten() as Collection, labelName) } - private boolean triggerForDsls(Collection dsls, String labelName) { - Collection matchingDsls = dsls.findAll { it.label == labelName } + private boolean triggerForDsls(Collection dsls, String labelName) { + Collection matchingDsls = dsls.findAll { it.label == labelName } if (matchingDsls.empty) { return false } @@ -94,7 +110,7 @@ class StubRunnerExecutor implements StubFinder { @Override boolean trigger() { - (getAccurestContracts().values().flatten() as Collection).each { GroovyDsl groovyDsl -> + (getContracts().values().flatten() as Collection).each { Contract groovyDsl -> sendMessageIfApplicable(groovyDsl) } return true @@ -102,18 +118,18 @@ class StubRunnerExecutor implements StubFinder { @Override Map> labels() { - return getAccurestContracts().collectEntries { + return getContracts().collectEntries { [(it.key.toColonSeparatedDependencyNotation()) : it.value.collect { it.label }] } as Map> } - private void sendMessageIfApplicable(GroovyDsl groovyDsl) { + private void sendMessageIfApplicable(Contract groovyDsl) { if (!groovyDsl.outputMessage) { return } - AccurestMessage message = accurestMessaging.create(groovyDsl.outputMessage?.body?.clientValue, + ContractVerifierMessage message = contractVerifierMessaging.create(groovyDsl.outputMessage?.body?.clientValue, groovyDsl.outputMessage?.headers?.asStubSideMap()) - accurestMessaging.send(message, groovyDsl.outputMessage.sentTo.clientValue) + contractVerifierMessaging.send(message, groovyDsl.outputMessage.sentTo.clientValue) } private URL returnStubUrlIfMatches(boolean condition) { @@ -122,7 +138,7 @@ class StubRunnerExecutor implements StubFinder { private void startStubServers(StubRunnerOptions stubRunnerOptions, StubConfiguration stubConfiguration, StubRepository repository) { List mappings = repository.getProjectDescriptors() - Collection contracts = repository.accurestContracts + Collection contracts = repository.contracts Integer port = stubRunnerOptions.port(stubConfiguration) if (port) { stubServer = new StubServer(port, stubConfiguration, mappings, contracts).start() diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunnerFactory.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerFactory.groovy similarity index 57% rename from stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunnerFactory.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerFactory.groovy index 42f5cf65af..6429e56252 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunnerFactory.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerFactory.groovy @@ -1,8 +1,24 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner import groovy.transform.CompileStatic import groovy.util.logging.Slf4j -import io.codearte.accurest.messaging.AccurestMessaging +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging /** * Factory of StubRunners. Basing on the options and passed collaborators @@ -14,12 +30,12 @@ class StubRunnerFactory { private final StubRunnerOptions stubRunnerOptions private final StubDownloader stubDownloader - private final AccurestMessaging accurestMessaging + private final ContractVerifierMessaging contractVerifierMessaging - StubRunnerFactory(StubRunnerOptions stubRunnerOptions, StubDownloader stubDownloader, AccurestMessaging accurestMessaging) { + StubRunnerFactory(StubRunnerOptions stubRunnerOptions, StubDownloader stubDownloader, ContractVerifierMessaging contractVerifierMessaging) { this.stubRunnerOptions = stubRunnerOptions this.stubDownloader = stubDownloader - this.accurestMessaging = accurestMessaging + this.contractVerifierMessaging = contractVerifierMessaging } Collection createStubsFromServiceConfiguration() { @@ -41,7 +57,7 @@ class StubRunnerFactory { private StubRunner createStubRunner(File unzippedStubsDir, StubConfiguration stubsConfiguration, StubRunnerOptions stubRunnerOptions) { - return new StubRunner(stubRunnerOptions, unzippedStubsDir.path, stubsConfiguration, accurestMessaging) + return new StubRunner(stubRunnerOptions, unzippedStubsDir.path, stubsConfiguration, contractVerifierMessaging) } } diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunnerMain.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerMain.groovy similarity index 81% rename from stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunnerMain.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerMain.groovy index aaa620a63a..3fc959780a 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunnerMain.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerMain.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner import groovy.transform.CompileStatic import groovy.util.logging.Slf4j diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerMessagingTrigger.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerMessagingTrigger.groovy new file mode 100644 index 0000000000..594dd1c1ce --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerMessagingTrigger.groovy @@ -0,0 +1,35 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner + +import groovy.transform.PackageScope +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging + +/** + * @author Marcin Grzejszczak + */ +@PackageScope +class StubRunnerMessagingTrigger { + + private final ContractVerifierMessaging contractVerifierMessaging + + StubRunnerMessagingTrigger(ContractVerifierMessaging contractVerifierMessaging) { + this.contractVerifierMessaging = contractVerifierMessaging + } + + void trigger +} diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunnerOptions.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerOptions.groovy similarity index 71% rename from stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunnerOptions.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerOptions.groovy index aa4a9a890f..d93f8ea034 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunnerOptions.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerOptions.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner import groovy.transform.CompileStatic import groovy.transform.PackageScope diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunnerOptionsBuilder.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilder.groovy similarity index 80% rename from stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunnerOptionsBuilder.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilder.groovy index 903b21c789..78b98c9186 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunnerOptionsBuilder.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilder.groovy @@ -1,7 +1,23 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner import groovy.transform.CompileStatic -import io.codearte.accurest.stubrunner.util.StubsParser +import org.springframework.cloud.contract.stubrunner.util.StubsParser @CompileStatic class StubRunnerOptionsBuilder { diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunning.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunning.groovy new file mode 100644 index 0000000000..08758b541e --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubRunning.groovy @@ -0,0 +1,25 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner + +interface StubRunning extends Closeable, StubFinder { + /** + * Runs the stubs and returns the {@link RunningStubs} + */ + RunningStubs runStubs() + +} \ No newline at end of file diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubServer.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubServer.groovy similarity index 72% rename from stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubServer.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubServer.groovy index 62e5cc5952..5889584035 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubServer.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubServer.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner import com.github.tomakehurst.wiremock.WireMockServer import com.github.tomakehurst.wiremock.client.WireMock @@ -6,7 +22,7 @@ import com.github.tomakehurst.wiremock.core.WireMockConfiguration import groovy.transform.CompileStatic import groovy.transform.PackageScope import groovy.util.logging.Slf4j -import io.codearte.accurest.dsl.GroovyDsl +import org.springframework.cloud.contract.verifier.dsl.Contract @CompileStatic @Slf4j @@ -15,10 +31,10 @@ class StubServer { private WireMockServer wireMockServer final StubConfiguration stubConfiguration final Collection mappings - final Collection contracts + final Collection contracts StubServer(int port, StubConfiguration stubConfiguration, Collection mappings, - Collection contracts) { + Collection contracts) { this.stubConfiguration = stubConfiguration this.mappings = mappings this.wireMockServer = new WireMockServer(WireMockConfiguration.wireMockConfig().port(port)) diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubTrigger.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubTrigger.groovy similarity index 54% rename from stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubTrigger.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubTrigger.groovy index bd5ec1e30e..c9ef71bafa 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubTrigger.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/StubTrigger.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner interface StubTrigger { diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/WiremockMappingDescriptor.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/WiremockMappingDescriptor.groovy new file mode 100644 index 0000000000..e3bdba3f9b --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/WiremockMappingDescriptor.groovy @@ -0,0 +1,43 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner + +import com.github.tomakehurst.wiremock.stubbing.StubMapping +import groovy.transform.CompileStatic +import groovy.transform.EqualsAndHashCode +import groovy.transform.PackageScope +import groovy.transform.ToString + +/** + * Represents a single JSON file that was found in the folder with + * potential WireMock stubs + */ +@CompileStatic +@EqualsAndHashCode +@ToString(includePackage = false) +@PackageScope +class WiremockMappingDescriptor { + final File descriptor + + WiremockMappingDescriptor(File mappingDescriptor) { + this.descriptor = mappingDescriptor + } + + StubMapping getMapping() { + return StubMapping.buildFrom(descriptor.getText('UTF-8')) + } +} diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/util/StringUtils.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/util/StringUtils.groovy similarity index 85% rename from stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/util/StringUtils.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/util/StringUtils.groovy index 16b8f35db1..5382f8ae57 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/util/StringUtils.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/util/StringUtils.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.stubrunner.util +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.util /** * Utils ported from Apache Commons diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/util/StubsParser.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/util/StubsParser.groovy similarity index 69% rename from stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/util/StubsParser.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/util/StubsParser.groovy index ae06a9bfe2..bb45d160fe 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/util/StubsParser.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/util/StubsParser.groovy @@ -1,7 +1,23 @@ -package io.codearte.accurest.stubrunner.util +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.util import groovy.transform.CompileStatic -import io.codearte.accurest.stubrunner.StubConfiguration +import org.springframework.cloud.contract.stubrunner.StubConfiguration /** * Utility to parse string into a list of configuration of stubs diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/util/ZipCategory.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/util/ZipCategory.groovy similarity index 72% rename from stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/util/ZipCategory.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/util/ZipCategory.groovy index 1877da70d4..105298b558 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/util/ZipCategory.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/groovy/org/springframework/cloud/contract/stubrunner/util/ZipCategory.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.stubrunner.util +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.util import groovy.transform.CompileStatic diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/resources/accurestStubrunnerGrapeConfig.xml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/resources/accurestStubrunnerGrapeConfig.xml new file mode 100644 index 0000000000..cbbd28cea5 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/resources/accurestStubrunnerGrapeConfig.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/AvailablePortScannerSpec.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/AvailablePortScannerSpec.groovy similarity index 71% rename from stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/AvailablePortScannerSpec.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/AvailablePortScannerSpec.groovy index 609e746e66..6a7703ee84 100644 --- a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/AvailablePortScannerSpec.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/AvailablePortScannerSpec.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner import spock.lang.Specification diff --git a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/BatchStubRunnerSpec.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/BatchStubRunnerSpec.groovy similarity index 67% rename from stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/BatchStubRunnerSpec.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/BatchStubRunnerSpec.groovy index 0013801aa8..83c46a48d5 100644 --- a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/BatchStubRunnerSpec.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/BatchStubRunnerSpec.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner import spock.lang.Specification diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/MappingDescriptorSpec.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/MappingDescriptorSpec.groovy new file mode 100644 index 0000000000..2fddae9d96 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/MappingDescriptorSpec.groovy @@ -0,0 +1,39 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner + +import com.github.tomakehurst.wiremock.http.RequestMethod +import spock.lang.Specification + +class MappingDescriptorSpec extends Specification { + public static + final File MAPPING_DESCRIPTOR = new File('src/test/resources/repository/mappings/spring/cloud/ping/ping.json') + + def 'should describe stub mapping'() { + given: + WiremockMappingDescriptor mappingDescriptor = new WiremockMappingDescriptor(MAPPING_DESCRIPTOR) + + expect: + with(mappingDescriptor.mapping) { + request.method == RequestMethod.GET + request.url == '/ping' + response.status == 200 + response.body == 'pong' + response.headers.contentTypeHeader.mimeTypePart() == 'text/plain' + } + } +} diff --git a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/RunningStubsSpec.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/RunningStubsSpec.groovy similarity index 72% rename from stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/RunningStubsSpec.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/RunningStubsSpec.groovy index 11acce3339..57eac143b8 100644 --- a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/RunningStubsSpec.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/RunningStubsSpec.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner import spock.lang.Specification diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubConfigurationSpec.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubConfigurationSpec.groovy new file mode 100644 index 0000000000..0e5d631d8d --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubConfigurationSpec.groovy @@ -0,0 +1,37 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner + +import spock.lang.Specification + +/** + * @author Marcin Grzejszczak + */ +class StubConfigurationSpec extends Specification { + + def 'should parse ivy notation'() { + given: + String ivy = 'group:artifact:version:classifier' + when: + StubConfiguration stubConfiguration = new StubConfiguration(ivy) + then: + stubConfiguration.artifactId == 'artifact' + stubConfiguration.groupId == 'group' + stubConfiguration.classifier == 'classifier' + stubConfiguration.version == 'version' + } +} diff --git a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/StubRepositorySpec.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRepositorySpec.groovy similarity index 58% rename from stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/StubRepositorySpec.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRepositorySpec.groovy index 8e50f75267..bc5614e5a1 100644 --- a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/StubRepositorySpec.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRepositorySpec.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner import spock.lang.Specification diff --git a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/StubRunnerExecutorSpec.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerExecutorSpec.groovy similarity index 72% rename from stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/StubRunnerExecutorSpec.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerExecutorSpec.groovy index a90447dce9..ad59d1374b 100644 --- a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/StubRunnerExecutorSpec.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerExecutorSpec.groovy @@ -1,6 +1,22 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import io.codearte.accurest.stubrunner.util.StubsParser +package org.springframework.cloud.contract.stubrunner + +import org.springframework.cloud.contract.stubrunner.util.StubsParser import spock.lang.Specification class StubRunnerExecutorSpec extends Specification { diff --git a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/StubRunnerFactorySpec.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerFactorySpec.groovy similarity index 59% rename from stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/StubRunnerFactorySpec.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerFactorySpec.groovy index 71d5e90f3b..ced2a5f713 100644 --- a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/StubRunnerFactorySpec.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerFactorySpec.groovy @@ -1,8 +1,24 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner -import io.codearte.accurest.messaging.noop.NoOpAccurestMessaging import org.junit.Rule import org.junit.rules.TemporaryFolder +import org.springframework.cloud.contract.verifier.messaging.noop.NoOpContractVerifierMessaging import spock.lang.Specification class StubRunnerFactorySpec extends Specification { @@ -19,7 +35,7 @@ class StubRunnerFactorySpec extends Specification { stubRunnerOptions = new StubRunnerOptionsBuilder() .withStubRepositoryRoot(folder.root.absolutePath) // FIXME: not used .withStubs(stubs).build() - factory = new StubRunnerFactory(stubRunnerOptions, downloader, new NoOpAccurestMessaging()) + factory = new StubRunnerFactory(stubRunnerOptions, downloader, new NoOpContractVerifierMessaging()) } def "Should download stub definitions many times"() { diff --git a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/StubRunnerOptionsBuilderSpec.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilderSpec.groovy similarity index 65% rename from stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/StubRunnerOptionsBuilderSpec.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilderSpec.groovy index 07de7cb30b..c0d4aba44c 100644 --- a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/StubRunnerOptionsBuilderSpec.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilderSpec.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner import spock.lang.Specification diff --git a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/StubRunnerSpec.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerSpec.groovy similarity index 63% rename from stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/StubRunnerSpec.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerSpec.groovy index f67ad211fa..18fb646e97 100644 --- a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/StubRunnerSpec.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerSpec.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner import spock.lang.Specification diff --git a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/StubServerSpec.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubServerSpec.groovy similarity index 62% rename from stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/StubServerSpec.groovy rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubServerSpec.groovy index fad9fd82eb..7be6fbaefc 100644 --- a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/StubServerSpec.groovy +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubServerSpec.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.stubrunner +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner import spock.lang.Specification @@ -6,7 +22,7 @@ class StubServerSpec extends Specification { static final int STUB_SERVER_PORT = 12180 static final URL EXPECTED_URL = new URL("http://localhost:$STUB_SERVER_PORT") - File repository = new File('src/test/resources/repository/mappings/com/ofg/bye') + File repository = new File('src/test/resources/repository/mappings/spring/cloud/bye') StubConfiguration stubConfiguration = new StubConfiguration("a:b") def 'should register stub mappings upon server start'() { diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/util/ZipCategorySpec.groovy b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/util/ZipCategorySpec.groovy new file mode 100644 index 0000000000..c3b0834b02 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/util/ZipCategorySpec.groovy @@ -0,0 +1,40 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.stubrunner.util + +import groovy.util.logging.Slf4j +import spock.lang.Specification + +@Slf4j +class ZipCategorySpec extends Specification { + + def 'should unzip a file to the specified location'() { + given: + File zipFile = new File(ZipCategorySpec.classLoader.getResource('file.zip').toURI()) + File tempDir = File.createTempDir() + tempDir.deleteOnExit() + when: + use(ZipCategory) { + zipFile.unzipTo(tempDir) + } + then: + tempDir.listFiles().find { + it.name == 'file.txt' + }?.text?.trim() == 'test' + } + +} diff --git a/stub-runner/stub-runner/src/test/resources/anotherRepository/mappings/com/ofg/bar/bar.json b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/mappings/spring/cloud/bar/bar.json similarity index 100% rename from stub-runner/stub-runner/src/test/resources/anotherRepository/mappings/com/ofg/bar/bar.json rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/mappings/spring/cloud/bar/bar.json diff --git a/stub-runner/stub-runner/src/test/resources/anotherRepository/mappings/com/ofg/foo/bar/foobar.json b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/mappings/spring/cloud/foo/bar/foobar.json similarity index 100% rename from stub-runner/stub-runner/src/test/resources/anotherRepository/mappings/com/ofg/foo/bar/foobar.json rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/mappings/spring/cloud/foo/bar/foobar.json diff --git a/stub-runner/stub-runner/src/test/resources/anotherRepository/mappings/com/ofg/foo/foo.json b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/mappings/spring/cloud/foo/foo.json similarity index 100% rename from stub-runner/stub-runner/src/test/resources/anotherRepository/mappings/com/ofg/foo/foo.json rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/mappings/spring/cloud/foo/foo.json diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/projects/brokers/brokers.json b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/projects/brokers/brokers.json new file mode 100644 index 0000000000..fae6436ad8 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/projects/brokers/brokers.json @@ -0,0 +1,5 @@ +{ + "pl": [ + "spring/cloud/bar" + ] +} \ No newline at end of file diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/projects/brokers/nested/anotherDescriptor.json b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/projects/brokers/nested/anotherDescriptor.json new file mode 100644 index 0000000000..b3a72bfbcf --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/projects/brokers/nested/anotherDescriptor.json @@ -0,0 +1,5 @@ +{ + "pl": [ + "spring/cloud/foo/bar" + ] +} \ No newline at end of file diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/projects/descriptor.json b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/projects/descriptor.json new file mode 100644 index 0000000000..a2384b0930 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/projects/descriptor.json @@ -0,0 +1,5 @@ +{ + "pl": [ + "spring/cloud/foo" + ] +} \ No newline at end of file diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/mappings/.gitkeep b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/emptyrepo/.gitkeep similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/mappings/.gitkeep rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/emptyrepo/.gitkeep diff --git a/stub-runner/stub-runner/src/test/resources/file.zip b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/file.zip similarity index 100% rename from stub-runner/stub-runner/src/test/resources/file.zip rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/file.zip diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/logback.xml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/logback.xml new file mode 100644 index 0000000000..7eecabf2f2 --- /dev/null +++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/logback.xml @@ -0,0 +1,30 @@ + + + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + \ No newline at end of file diff --git a/stub-runner/stub-runner/src/test/resources/repository/mappings/lv/com/ofg/bye/lv_bye.json b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/lv/spring/cloud/bye/lv_bye.json similarity index 100% rename from stub-runner/stub-runner/src/test/resources/repository/mappings/lv/com/ofg/bye/lv_bye.json rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/lv/spring/cloud/bye/lv_bye.json diff --git a/stub-runner/stub-runner/src/test/resources/repository/mappings/pl/com/ofg/bye/pl_bye.json b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/pl/spring/cloud/bye/pl_bye.json similarity index 100% rename from stub-runner/stub-runner/src/test/resources/repository/mappings/pl/com/ofg/bye/pl_bye.json rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/pl/spring/cloud/bye/pl_bye.json diff --git a/stub-runner/stub-runner/src/test/resources/repository/mappings/pl/com/ofg/bye/pl_overridden_bye.json b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/pl/spring/cloud/bye/pl_overridden_bye.json similarity index 100% rename from stub-runner/stub-runner/src/test/resources/repository/mappings/pl/com/ofg/bye/pl_overridden_bye.json rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/pl/spring/cloud/bye/pl_overridden_bye.json diff --git a/stub-runner/stub-runner/src/test/resources/repository/mappings/com/ofg/bye/admin/admin.json b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/bye/admin/admin.json similarity index 100% rename from stub-runner/stub-runner/src/test/resources/repository/mappings/com/ofg/bye/admin/admin.json rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/bye/admin/admin.json diff --git a/stub-runner/stub-runner/src/test/resources/repository/mappings/com/ofg/bye/bye.json b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/bye/bye.json similarity index 100% rename from stub-runner/stub-runner/src/test/resources/repository/mappings/com/ofg/bye/bye.json rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/bye/bye.json diff --git a/stub-runner/stub-runner/src/test/resources/repository/mappings/com/ofg/hello/README.md b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/hello/README.md similarity index 100% rename from stub-runner/stub-runner/src/test/resources/repository/mappings/com/ofg/hello/README.md rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/hello/README.md diff --git a/stub-runner/stub-runner/src/test/resources/repository/mappings/com/ofg/hello/admin/admin.json b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/hello/admin/admin.json similarity index 100% rename from stub-runner/stub-runner/src/test/resources/repository/mappings/com/ofg/hello/admin/admin.json rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/hello/admin/admin.json diff --git a/stub-runner/stub-runner/src/test/resources/repository/mappings/com/ofg/hello/hello.json b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/hello/hello.json similarity index 100% rename from stub-runner/stub-runner/src/test/resources/repository/mappings/com/ofg/hello/hello.json rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/hello/hello.json diff --git a/stub-runner/stub-runner/src/test/resources/repository/mappings/com/ofg/ping/ping.json b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/ping/ping.json similarity index 100% rename from stub-runner/stub-runner/src/test/resources/repository/mappings/com/ofg/ping/ping.json rename to spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/ping/ping.json diff --git a/spring-cloud-contract-verifier/build.gradle b/spring-cloud-contract-verifier/build.gradle new file mode 100644 index 0000000000..178c42a48e --- /dev/null +++ b/spring-cloud-contract-verifier/build.gradle @@ -0,0 +1,118 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +String verifier = "spring-cloud-contract-verifier" + +project(":$verifier-root:$verifier-core") { + + dependencies { + compile 'org.slf4j:slf4j-api:1.6.0' + compile 'commons-io:commons-io:2.0' + compile 'org.apache.commons:commons-lang3:3.3' + compile "com.github.tomakehurst:wiremock:$wiremockVersion" + compile "com.toomuchcoding.jsonassert:jsonassert:$jsonassertVersion" + compile 'org.codehaus.groovy:groovy-all:2.4.4' + testCompile 'cglib:cglib-nodep:2.2' + testCompile 'org.objenesis:objenesis:2.1' + testCompile project(":$verifier-root:$verifier-testing-utils") + } + +} + +project(":$verifier-root:$verifier-testing-utils") { + + dependencies { + compile 'org.skyscreamer:jsonassert:1.2.3' + } + +} + +project(":$verifier-root:$verifier-converters") { + dependencies { + compile project(":$verifier-root:$verifier-core") + compile 'org.apache.commons:commons-lang3:3.0' + compile 'commons-io:commons-io:2.0' + compile 'dk.brics.automaton:automaton:1.11-8' // needed for Xeger + testCompile "com.github.tomakehurst:wiremock:$wiremockVersion" + testCompile 'org.hamcrest:hamcrest-all:1.3' + } +} + +project(":$verifier-root:$verifier-gradle-plugin") { + + ext.messagingLibsDir ="$buildDir/messaging-libs" + ext.contractVerifierGradlePluginLibsDir ="$buildDir/contractVerifier-gradle-plugin-libs" + + ext.testSystemProperties = [ + 'contract-verifier-gradle-plugin-libs-dir': contractVerifierGradlePluginLibsDir, + 'messaging-libs-dir': messagingLibsDir + ] + + dependencies { + compile project(":$verifier-root:$verifier-core") + compile project(":$verifier-root:$verifier-converters") + compile gradleApi() + + testCompile gradleTestKit() + testCompile project(":$verifier-root:$verifier-testing-utils") + } + + configurations { + messagingLibs + contractVerifierGradlePluginLibs + } + + dependencies { + + messagingLibs project(":$verifier-root:$verifier-messaging-root:$verifier-integration") + messagingLibs project(":$verifier-root:$verifier-messaging-root:$verifier-messaging-core") + messagingLibs project(":$verifier-root:$verifier-testing-utils") + messagingLibs 'org.codehaus.groovy:groovy-all:2.4.5' + + contractVerifierGradlePluginLibs project(":$verifier-root:$verifier-gradle-plugin") + } + + test { + exclude '**/*FunctionalSpec.*' + systemProperties = testSystemProperties + } + task funcTest(type: Test) { + include '**/*FunctionalSpec.*' + systemProperties = testSystemProperties + reports.html { + destination = file("${reporting.baseDir}/funcTests") + } + } + + task archiveMessagingLibsDependencies(type: Sync) { + from configurations.messagingLibs.resolvedConfiguration.resolvedArtifacts.collect { it.file } + into messagingLibsDir + } + + task archiveContractVerifierGradlePluginLibsDependencies(type: Sync) { + from configurations.contractVerifierGradlePluginLibs.resolvedConfiguration.resolvedArtifacts.collect { it.file } + into contractVerifierGradlePluginLibsDir + } + + // archive task needs to have jars ready + archiveMessagingLibsDependencies.dependsOn project(":$verifier-root:$verifier-messaging-root:$verifier-integration").tasks.jar + archiveContractVerifierGradlePluginLibsDependencies.dependsOn project(":$verifier-root:$verifier-gradle-plugin").tasks.jar + + test.dependsOn archiveMessagingLibsDependencies, archiveContractVerifierGradlePluginLibsDependencies + funcTest.dependsOn archiveMessagingLibsDependencies, archiveContractVerifierGradlePluginLibsDependencies + + uploadArchives.dependsOn { funcTest } +} diff --git a/accurest-converters/src/main/groovy/nl/flotsam/xeger/Xeger.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/main/groovy/nl/flotsam/xeger/Xeger.java similarity index 100% rename from accurest-converters/src/main/groovy/nl/flotsam/xeger/Xeger.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/main/groovy/nl/flotsam/xeger/Xeger.java diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/main/groovy/org/springframework/cloud/contract/verifier/converter/SingleFileConverter.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/main/groovy/org/springframework/cloud/contract/verifier/converter/SingleFileConverter.groovy new file mode 100644 index 0000000000..ad860b19ea --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/main/groovy/org/springframework/cloud/contract/verifier/converter/SingleFileConverter.groovy @@ -0,0 +1,44 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.converter + +import groovy.transform.CompileStatic +import org.springframework.cloud.contract.verifier.file.ContractMetadata + +/** + * Converts contracts into their stub representation + * + * @since 1.0.0 + */ +@CompileStatic +interface SingleFileConverter { + + /** + * Returns {@code true} if the converter can handle the file + */ + boolean canHandleFileName(String fileName) + + /** + * Returns the content of the converted file + */ + String convertContent(String rootName, ContractMetadata content) + + /** + * Returns the name of the converted file + */ + String generateOutputFileNameForInput(String inputFileName) +} \ No newline at end of file diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/ConversionContractVerifierException.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/ConversionContractVerifierException.groovy new file mode 100644 index 0000000000..205dd170e4 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/ConversionContractVerifierException.groovy @@ -0,0 +1,33 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.wiremock + +import groovy.transform.CompileStatic +import org.springframework.cloud.contract.verifier.ContractVerifierException + +/** + * Thrown when a a DSL can't be properly converted + * + * @since 1.0.0 + */ +@CompileStatic +class ConversionContractVerifierException extends ContractVerifierException { + + ConversionContractVerifierException(String message, Throwable cause) { + super(message, cause) + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockClientConverter.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockClientConverter.groovy new file mode 100644 index 0000000000..3fe90afb25 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockClientConverter.groovy @@ -0,0 +1,38 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.wiremock + +import groovy.transform.CompileStatic +import org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockStubStrategy +import org.springframework.cloud.contract.verifier.file.ContractMetadata + +import java.nio.charset.StandardCharsets + +/** + * Converts DSLs to WireMock stubs + * + * @since 1.0.0 + */ +@CompileStatic +class DslToWireMockClientConverter extends DslToWireMockConverter { + + @Override + String convertContent(String rootName, ContractMetadata contract) { + String dslContent = contract.path.getText(StandardCharsets.UTF_8.toString()) + return new WireMockStubStrategy(rootName, contract, createGroovyDSLFromStringContent(dslContent)).toWireMockClientStub() + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockConverter.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockConverter.groovy new file mode 100644 index 0000000000..289b1d6ed0 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockConverter.groovy @@ -0,0 +1,45 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.wiremock + +import groovy.transform.CompileStatic +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.converter.SingleFileConverter +import org.springframework.cloud.contract.verifier.util.ContractVerifierDslConverter + +/** + * WireMock implementation of the {@link SingleFileConverter} + * + * @since 1.0.0 + */ +@CompileStatic +abstract class DslToWireMockConverter implements SingleFileConverter { + + @Override + boolean canHandleFileName(String fileName) { + return fileName.endsWith('.groovy') + } + + @Override + String generateOutputFileNameForInput(String inputFileName) { + return inputFileName.replaceAll('.groovy', '.json') + } + + protected Contract createGroovyDSLFromStringContent(String groovyDslAsString) { + return ContractVerifierDslConverter.convert(groovyDslAsString) + } +} diff --git a/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/RecursiveFilesConverter.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/RecursiveFilesConverter.groovy similarity index 57% rename from accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/RecursiveFilesConverter.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/RecursiveFilesConverter.groovy index 867aab8a34..57a56c9c77 100644 --- a/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/RecursiveFilesConverter.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/RecursiveFilesConverter.groovy @@ -1,34 +1,56 @@ -package io.codearte.accurest.wiremock +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.wiremock import com.google.common.collect.ListMultimap import groovy.transform.CompileStatic import groovy.util.logging.Slf4j -import io.codearte.accurest.config.AccurestConfigProperties -import io.codearte.accurest.file.Contract -import io.codearte.accurest.file.ContractFileScanner +import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties +import org.springframework.cloud.contract.verifier.converter.SingleFileConverter +import org.springframework.cloud.contract.verifier.file.ContractMetadata +import org.springframework.cloud.contract.verifier.file.ContractFileScanner import java.nio.charset.StandardCharsets import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths +/** + * Recursively converts contracts into their stub representations + * + * @since 1.0.0 + */ @Slf4j @CompileStatic class RecursiveFilesConverter { private final SingleFileConverter singleFileConverter - private final AccurestConfigProperties properties + private final ContractVerifierConfigProperties properties - RecursiveFilesConverter(SingleFileConverter singleFileConverter, AccurestConfigProperties properties) { + RecursiveFilesConverter(SingleFileConverter singleFileConverter, ContractVerifierConfigProperties properties) { this.properties = properties this.singleFileConverter = singleFileConverter } void processFiles() { ContractFileScanner scanner = new ContractFileScanner(properties.contractsDslDir, properties.excludedFiles as Set, [] as Set) - ListMultimap contracts = scanner.findContracts() + ListMultimap contracts = scanner.findContracts() contracts.asMap().entrySet().each { entry -> - entry.value.each { Contract contract -> + entry.value.each { ContractMetadata contract -> File sourceFile = contract.path.toFile() try { if (!singleFileConverter.canHandleFileName(sourceFile.name)) { @@ -42,7 +64,7 @@ class RecursiveFilesConverter { File newGroovyFile = createTargetFileWithProperName(absoluteTargetPath, sourceFile) newGroovyFile.setText(convertedContent, StandardCharsets.UTF_8.toString()) } catch (Exception e) { - throw new ConversionAccurestException("Unable to make conversion of ${sourceFile.name}", e) + throw new ConversionContractVerifierException("Unable to make conversion of ${sourceFile.name}", e) } } } diff --git a/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/WireMockToDslConverter.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/WireMockToDslConverter.groovy similarity index 83% rename from accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/WireMockToDslConverter.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/WireMockToDslConverter.groovy index 0a7bfc8bb8..7844605653 100644 --- a/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/WireMockToDslConverter.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/WireMockToDslConverter.groovy @@ -1,18 +1,47 @@ -package io.codearte.accurest.wiremock +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.wiremock import groovy.io.FileType import groovy.json.JsonOutput import groovy.json.JsonParserType import groovy.json.JsonSlurper +import groovy.transform.CompileDynamic import groovy.xml.XmlUtil -import io.codearte.accurest.dsl.GroovyDsl +import org.springframework.cloud.contract.verifier.dsl.Contract import nl.flotsam.xeger.Xeger import java.nio.charset.StandardCharsets import static org.apache.commons.lang3.StringEscapeUtils.escapeJava +/** + * Converts WireMock stubs into the DSL format + * + * @since 1.0.0 + */ +@CompileDynamic class WireMockToDslConverter { + + /** + * Returns the string content of the contract + * + * @param wireMockStringStub - string content of the WireMock JSON stub + */ static String fromWireMockStub(String wireMockStringStub) { return new WireMockToDslConverter().convertFromWireMockStub(wireMockStringStub) } @@ -172,7 +201,7 @@ class WireMockToDslConverter { static String wrapWithFactoryMethod(String dslFromWireMockStub) { return """\ -${GroovyDsl.name}.make { +${Contract.name}.make { $dslFromWireMockStub } """ diff --git a/accurest-converters/src/test/groovy/nl/flotsam/xeger/XegerTest.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/groovy/nl/flotsam/xeger/XegerTest.java similarity index 100% rename from accurest-converters/src/test/groovy/nl/flotsam/xeger/XegerTest.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/groovy/nl/flotsam/xeger/XegerTest.java diff --git a/accurest-converters/src/test/groovy/nl/flotsam/xeger/XegerUtilsTest.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/groovy/nl/flotsam/xeger/XegerUtilsTest.java similarity index 100% rename from accurest-converters/src/test/groovy/nl/flotsam/xeger/XegerUtilsTest.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/groovy/nl/flotsam/xeger/XegerUtilsTest.java diff --git a/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverterSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockClientConverterSpec.groovy similarity index 77% rename from accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverterSpec.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockClientConverterSpec.groovy index 0d0eee7c03..9bd88e86c7 100755 --- a/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverterSpec.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockClientConverterSpec.groovy @@ -1,9 +1,25 @@ -package io.codearte.accurest.wiremock +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.wiremock -import io.codearte.accurest.file.Contract import org.junit.Rule import org.junit.rules.TemporaryFolder import org.skyscreamer.jsonassert.JSONAssert +import org.springframework.cloud.contract.verifier.file.ContractMetadata import spock.lang.Issue import spock.lang.Specification @@ -18,7 +34,7 @@ class DslToWireMockClientConverterSpec extends Specification { and: File file = tmpFolder.newFile("dsl1.groovy") file.write(""" - io.codearte.accurest.dsl.GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method('PUT') url \$(client(~/\\/[0-9]{2}/), server('/12')) @@ -29,7 +45,7 @@ class DslToWireMockClientConverterSpec extends Specification { } """) when: - String json = converter.convertContent("Test", new Contract(file.toPath(), false, 0, null)) + String json = converter.convertContent("Test", new ContractMetadata(file.toPath(), false, 0, null)) then: JSONAssert.assertEquals(''' {"request":{"method":"PUT","urlPattern":"/[0-9]{2}"},"response":{"status":200}} @@ -43,7 +59,7 @@ class DslToWireMockClientConverterSpec extends Specification { and: File file = tmpFolder.newFile("dsl-delay.groovy") file.write(""" - io.codearte.accurest.dsl.GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract.make { request { } response { @@ -53,7 +69,7 @@ class DslToWireMockClientConverterSpec extends Specification { } """) when: - String json = converter.convertContent("test", new Contract(file.toPath(), false, 0, null)) + String json = converter.convertContent("test", new ContractMetadata(file.toPath(), false, 0, null)) then: JSONAssert.assertEquals(''' {"request":{},"response":{"status":200,"fixedDelayMilliseconds":1000}} @@ -66,12 +82,12 @@ class DslToWireMockClientConverterSpec extends Specification { and: File file = tmpFolder.newFile("dsl2.groovy") file.write(""" - io.codearte.accurest.dsl.GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'PUT' url '/api/12' headers { - header 'Content-Type': 'application/vnd.com.ofg.twitter-places-analyzer.v1+json' + header 'Content-Type': 'application/vnd.org.springframework.cloud.contract.verifier.twitter-places-analyzer.v1+json' } body ''' @@ -111,7 +127,7 @@ class DslToWireMockClientConverterSpec extends Specification { } """) when: - String json = converter.convertContent("Test", new Contract(file.toPath(), false, 0, null)) + String json = converter.convertContent("Test", new ContractMetadata(file.toPath(), false, 0, null)) then: JSONAssert.assertEquals(''' { @@ -153,7 +169,7 @@ class DslToWireMockClientConverterSpec extends Specification { } ], "headers" : { "Content-Type" : { - "equalTo" : "application/vnd.com.ofg.twitter-places-analyzer.v1+json" + "equalTo" : "application/vnd.org.springframework.cloud.contract.verifier.twitter-places-analyzer.v1+json" } } }, @@ -172,7 +188,7 @@ class DslToWireMockClientConverterSpec extends Specification { and: File file = tmpFolder.newFile("dsl-mapinlist.groovy") file.write(""" - io.codearte.accurest.dsl.GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'GET' urlPath '/foos' @@ -193,7 +209,7 @@ class DslToWireMockClientConverterSpec extends Specification { } """) when: - String json = converter.convertContent("test", new Contract(file.toPath(), false, 0, null)) + String json = converter.convertContent("test", new ContractMetadata(file.toPath(), false, 0, null)) then: JSONAssert.assertEquals(''' {"request":{"urlPath":"/foos","method":"GET"},"response":{"body":"[{\\"id\\":\\"123\\"},{\\"id\\":\\"567\\"}]"}} @@ -206,7 +222,7 @@ class DslToWireMockClientConverterSpec extends Specification { and: File file = tmpFolder.newFile("dsl_from_docs.groovy") file.write(''' - io.codearte.accurest.dsl.GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract.make { priority 1 request { method 'POST' @@ -232,7 +248,7 @@ class DslToWireMockClientConverterSpec extends Specification { } ''') when: - String json = converter.convertContent("Test", new Contract(file.toPath(), false, 0, null)) + String json = converter.convertContent("Test", new ContractMetadata(file.toPath(), false, 0, null)) then: JSONAssert.assertEquals( // tag::wiremock[] ''' diff --git a/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/RecursiveFilesConverterSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/RecursiveFilesConverterSpec.groovy similarity index 78% rename from accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/RecursiveFilesConverterSpec.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/RecursiveFilesConverterSpec.groovy index 754445866e..0e3de65413 100755 --- a/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/RecursiveFilesConverterSpec.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/RecursiveFilesConverterSpec.groovy @@ -1,10 +1,27 @@ -package io.codearte.accurest.wiremock +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.wiremock -import io.codearte.accurest.config.AccurestConfigProperties import org.apache.commons.io.FileUtils import org.apache.commons.io.filefilter.TrueFileFilter import org.junit.Rule import org.junit.rules.TemporaryFolder +import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties +import org.springframework.cloud.contract.verifier.converter.SingleFileConverter import spock.lang.Specification import java.nio.file.Path @@ -20,7 +37,7 @@ class RecursiveFilesConverterSpec extends Specification { def "should recursively convert all matching files"() { given: - AccurestConfigProperties properties = new AccurestConfigProperties() + ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties() File originalSourceRootDirectory = new File(this.getClass().getResource("/converter/source").toURI()) properties.contractsDslDir = tmpFolder.newFolder("source") properties.stubsOutputDir = tmpFolder.newFolder("target") @@ -44,7 +61,7 @@ class RecursiveFilesConverterSpec extends Specification { def "should recursively convert matching files with exlusions"() { given: - AccurestConfigProperties properties = new AccurestConfigProperties() + ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties() File originalSourceRootDirectory = new File(this.getClass().getResource("/converter/source").toURI()) properties.contractsDslDir = tmpFolder.newFolder("source") properties.stubsOutputDir = tmpFolder.newFolder("target") @@ -75,14 +92,14 @@ class RecursiveFilesConverterSpec extends Specification { singleFileConverterStub.canHandleFileName(_) >> { true } singleFileConverterStub.convertContent(_, _) >> { throw new NullPointerException("Test conversion error") } singleFileConverterStub.generateOutputFileNameForInput(_) >> { String inputFileName -> "${inputFileName}2" } - AccurestConfigProperties properties = new AccurestConfigProperties() + ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties() properties.contractsDslDir = tmpFolder.root properties.stubsOutputDir = tmpFolder.root RecursiveFilesConverter recursiveFilesConverter = new RecursiveFilesConverter(singleFileConverterStub, properties) when: recursiveFilesConverter.processFiles() then: - def e = thrown(ConversionAccurestException) + def e = thrown(ConversionContractVerifierException) e.message?.contains(sourceFile.name) e.cause?.message == "Test conversion error" } diff --git a/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/WireMockToDslConverterSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/WireMockToDslConverterSpec.groovy similarity index 78% rename from accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/WireMockToDslConverterSpec.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/WireMockToDslConverterSpec.groovy index 5e71f81605..f564abadb2 100755 --- a/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/WireMockToDslConverterSpec.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/WireMockToDslConverterSpec.groovy @@ -1,8 +1,24 @@ -package io.codearte.accurest.wiremock +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.wiremock import com.github.tomakehurst.wiremock.stubbing.StubMapping -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.util.AccurestDslConverter +import org.springframework.cloud.contract.verifier.util.ContractVerifierDslConverter +import org.springframework.cloud.contract.verifier.dsl.Contract import spock.lang.Specification class WireMockToDslConverterSpec extends Specification { @@ -35,7 +51,7 @@ class WireMockToDslConverterSpec extends Specification { and: stubMappingIsValidWireMockStub(wireMockStub) and: - GroovyDsl expectedGroovyDsl = GroovyDsl.make { + Contract expectedGroovyDsl = Contract.make { request { method 'GET' url '/path' @@ -68,8 +84,8 @@ class WireMockToDslConverterSpec extends Specification { when: String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub) then: - AccurestDslConverter.convert( - """ io.codearte.accurest.dsl.GroovyDsl.make { + ContractVerifierDslConverter.convert( + """org.springframework.cloud.contract.verifier.dsl.Contract.make { $groovyDsl }""") == expectedGroovyDsl } @@ -100,7 +116,7 @@ class WireMockToDslConverterSpec extends Specification { and: stubMappingIsValidWireMockStub(wireMockStub) and: - GroovyDsl expectedGroovyDsl = GroovyDsl.make { + Contract expectedGroovyDsl = Contract.make { request { method 'DELETE' url $(client(~/\/credit-card-verification-data\/[0-9]+/), server('/credit-card-verification-data/1')) @@ -122,8 +138,8 @@ class WireMockToDslConverterSpec extends Specification { when: String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub) then: - AccurestDslConverter.convert( - """ io.codearte.accurest.dsl.GroovyDsl.make { + ContractVerifierDslConverter.convert( + """org.springframework.cloud.contract.verifier.dsl.Contract.make { $groovyDsl }""") == expectedGroovyDsl } @@ -153,7 +169,7 @@ class WireMockToDslConverterSpec extends Specification { and: stubMappingIsValidWireMockStub(wireMockStub) and: - GroovyDsl expectedGroovyDsl = GroovyDsl.make { + Contract expectedGroovyDsl = Contract.make { request { method 'POST' url '/charge/count' @@ -173,8 +189,8 @@ class WireMockToDslConverterSpec extends Specification { when: String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub) then: - AccurestDslConverter.convert( - """ io.codearte.accurest.dsl.GroovyDsl.make { + ContractVerifierDslConverter.convert( + """org.springframework.cloud.contract.verifier.dsl.Contract.make { $groovyDsl }""") == expectedGroovyDsl } @@ -204,7 +220,7 @@ class WireMockToDslConverterSpec extends Specification { and: stubMappingIsValidWireMockStub(wireMockStub) and: - GroovyDsl expectedGroovyDsl = GroovyDsl.make { + Contract expectedGroovyDsl = Contract.make { request { method 'POST' url '/charge/count' @@ -227,8 +243,8 @@ class WireMockToDslConverterSpec extends Specification { when: String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub) then: - AccurestDslConverter.convert( - """ io.codearte.accurest.dsl.GroovyDsl.make { + ContractVerifierDslConverter.convert( + """org.springframework.cloud.contract.verifier.dsl.Contract.make { $groovyDsl }""") == expectedGroovyDsl } @@ -255,7 +271,7 @@ class WireMockToDslConverterSpec extends Specification { and: stubMappingIsValidWireMockStub(wireMockStub) and: - GroovyDsl expectedGroovyDsl = GroovyDsl.make { + Contract expectedGroovyDsl = Contract.make { request { method 'POST' url '/charge/search?pageNumber=0&size=2147483647' @@ -292,8 +308,8 @@ class WireMockToDslConverterSpec extends Specification { when: String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub) then: - AccurestDslConverter.convert( - """ io.codearte.accurest.dsl.GroovyDsl.make { + ContractVerifierDslConverter.convert( + """org.springframework.cloud.contract.verifier.dsl.Contract.make { $groovyDsl }""") == expectedGroovyDsl } @@ -317,7 +333,7 @@ class WireMockToDslConverterSpec extends Specification { and: stubMappingIsValidWireMockStub(wireMockStub) and: - GroovyDsl expectedGroovyDsl = GroovyDsl.make { + Contract expectedGroovyDsl = Contract.make { request { method 'POST' url '/test' @@ -330,8 +346,8 @@ class WireMockToDslConverterSpec extends Specification { when: String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub) then: - GroovyDsl evaluatedGroovyDsl = AccurestDslConverter.convert( - """ io.codearte.accurest.dsl.GroovyDsl.make { + Contract evaluatedGroovyDsl = ContractVerifierDslConverter.convert( + """org.springframework.cloud.contract.verifier.dsl.Contract.make { $groovyDsl }""") and: @@ -357,7 +373,7 @@ class WireMockToDslConverterSpec extends Specification { and: stubMappingIsValidWireMockStub(wireMockStub) and: - GroovyDsl expectedGroovyDsl = GroovyDsl.make { + Contract expectedGroovyDsl = Contract.make { request { method 'POST' url '/test' @@ -370,8 +386,8 @@ class WireMockToDslConverterSpec extends Specification { when: String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub) then: - GroovyDsl evaluatedGroovyDsl = AccurestDslConverter.convert( - """ io.codearte.accurest.dsl.GroovyDsl.make { + Contract evaluatedGroovyDsl = ContractVerifierDslConverter.convert( + """org.springframework.cloud.contract.verifier.dsl.Contract.make { $groovyDsl }""") and: @@ -398,7 +414,7 @@ class WireMockToDslConverterSpec extends Specification { and: stubMappingIsValidWireMockStub(wireMockStub) and: - GroovyDsl expectedGroovyDsl = GroovyDsl.make { + Contract expectedGroovyDsl = Contract.make { request { method 'POST' url '/test' @@ -411,8 +427,8 @@ class WireMockToDslConverterSpec extends Specification { when: String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub) then: - GroovyDsl evaluatedGroovyDsl = AccurestDslConverter.convert( - """ io.codearte.accurest.dsl.GroovyDsl.make { + Contract evaluatedGroovyDsl = ContractVerifierDslConverter.convert( + """org.springframework.cloud.contract.verifier.dsl.Contract.make { $groovyDsl }""") and: @@ -438,7 +454,7 @@ class WireMockToDslConverterSpec extends Specification { and: stubMappingIsValidWireMockStub(wireMockStub) and: - GroovyDsl expectedGroovyDsl = GroovyDsl.make { + Contract expectedGroovyDsl = Contract.make { request { method 'POST' url '/test' @@ -451,8 +467,8 @@ class WireMockToDslConverterSpec extends Specification { when: String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub) then: - GroovyDsl evaluatedGroovyDsl = AccurestDslConverter.convert( - """ io.codearte.accurest.dsl.GroovyDsl.make { + Contract evaluatedGroovyDsl = ContractVerifierDslConverter.convert( + """org.springframework.cloud.contract.verifier.dsl.Contract.make { $groovyDsl }""") and: @@ -478,7 +494,7 @@ class WireMockToDslConverterSpec extends Specification { and: stubMappingIsValidWireMockStub(wireMockStub) and: - GroovyDsl expectedGroovyDsl = GroovyDsl.make { + Contract expectedGroovyDsl = Contract.make { request { method 'POST' url '/test' @@ -491,8 +507,8 @@ class WireMockToDslConverterSpec extends Specification { when: String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub) then: - GroovyDsl evaluatedGroovyDsl = AccurestDslConverter.convert( - """ io.codearte.accurest.dsl.GroovyDsl.make { + Contract evaluatedGroovyDsl = ContractVerifierDslConverter.convert( + """org.springframework.cloud.contract.verifier.dsl.Contract.make { $groovyDsl }""") and: @@ -516,7 +532,7 @@ class WireMockToDslConverterSpec extends Specification { and: stubMappingIsValidWireMockStub(wireMockStub) and: - GroovyDsl expectedGroovyDsl = GroovyDsl.make { + Contract expectedGroovyDsl = Contract.make { priority 2 request { method 'POST' @@ -529,8 +545,8 @@ class WireMockToDslConverterSpec extends Specification { when: String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub) then: - GroovyDsl evaluatedGroovyDsl = AccurestDslConverter.convert( - """ io.codearte.accurest.dsl.GroovyDsl.make { + Contract evaluatedGroovyDsl = ContractVerifierDslConverter.convert( + """org.springframework.cloud.contract.verifier.dsl.Contract.make { $groovyDsl }""") and: diff --git a/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/WiremockScenarioConverterSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/WiremockScenarioConverterSpec.groovy similarity index 65% rename from accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/WiremockScenarioConverterSpec.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/WiremockScenarioConverterSpec.groovy index e7911c1303..64f0cbe13b 100755 --- a/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/WiremockScenarioConverterSpec.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/WiremockScenarioConverterSpec.groovy @@ -1,6 +1,22 @@ -package io.codearte.accurest.wiremock +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import io.codearte.accurest.file.Contract +package org.springframework.cloud.contract.verifier.wiremock + +import org.springframework.cloud.contract.verifier.file.ContractMetadata import spock.lang.Specification import java.nio.file.Path @@ -13,7 +29,7 @@ class WiremockScenarioConverterSpec extends Specification { DslToWireMockClientConverter converter = new DslToWireMockClientConverter() Path dsl = Paths.get(this.getClass().getResource("/converter/scenario/main_scenario/01_login.groovy").toURI()) when: - String content = converter.convertContent("Test", new Contract(dsl, false, 3, 0)) + String content = converter.convertContent("Test", new ContractMetadata(dsl, false, 3, 0)) then: content.contains('"requiredScenarioState" : "Started"') content.contains('"newScenarioState" : "Step1"') @@ -25,7 +41,7 @@ class WiremockScenarioConverterSpec extends Specification { DslToWireMockClientConverter converter = new DslToWireMockClientConverter() Path dsl = Paths.get(this.getClass().getResource("/converter/scenario/main_scenario/02_showCart.groovy").toURI()) when: - String content = converter.convertContent("Test", new Contract(dsl, false, 3, 1)) + String content = converter.convertContent("Test", new ContractMetadata(dsl, false, 3, 1)) then: content.contains('"requiredScenarioState" : "Step1"') content.contains('"newScenarioState" : "Step2"') @@ -37,7 +53,7 @@ class WiremockScenarioConverterSpec extends Specification { DslToWireMockClientConverter converter = new DslToWireMockClientConverter() Path dsl = Paths.get(this.getClass().getResource("/converter/scenario/main_scenario/03_logout.groovy").toURI()) when: - String content = converter.convertContent("Test", new Contract(dsl, false, 3, 2)) + String content = converter.convertContent("Test", new ContractMetadata(dsl, false, 3, 2)) then: content.contains('"requiredScenarioState" : "Step2"') !content.contains('"newScenarioState"') diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/resources/converter/scenario/main_scenario/01_login.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/resources/converter/scenario/main_scenario/01_login.groovy new file mode 100644 index 0000000000..c2c151e460 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/resources/converter/scenario/main_scenario/01_login.groovy @@ -0,0 +1,27 @@ +import org.springframework.cloud.contract.verifier.dsl.Contract + +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Contract.make { + request { + method('POST') + url '/login' + } + response { + status 200 + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/resources/converter/scenario/main_scenario/02_showCart.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/resources/converter/scenario/main_scenario/02_showCart.groovy new file mode 100644 index 0000000000..a4284fe016 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/resources/converter/scenario/main_scenario/02_showCart.groovy @@ -0,0 +1,27 @@ +import org.springframework.cloud.contract.verifier.dsl.Contract + +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Contract.make { + request { + method('GET') + url '/cart' + } + response { + status 200 + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/resources/converter/scenario/main_scenario/03_logout.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/resources/converter/scenario/main_scenario/03_logout.groovy new file mode 100644 index 0000000000..d2675b3a90 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/resources/converter/scenario/main_scenario/03_logout.groovy @@ -0,0 +1,27 @@ +import org.springframework.cloud.contract.verifier.dsl.Contract + +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Contract.make { + request { + method('POST') + url '/logout' + } + response { + status 200 + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/resources/converter/source/dir1/dsl1.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/resources/converter/source/dir1/dsl1.groovy new file mode 100644 index 0000000000..b23e11ed01 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/resources/converter/source/dir1/dsl1.groovy @@ -0,0 +1,30 @@ +import org.springframework.cloud.contract.verifier.dsl.Contract + +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Contract.make { + request { + method('PUT') + headers { + header 'Content-Type': 'application/json' + } + url $(client('/[0-9]{2}'), server('/12')) + } + response { + status 200 + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/resources/converter/source/dir1/dsl1b.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/resources/converter/source/dir1/dsl1b.groovy new file mode 100644 index 0000000000..3a8bed4ecc --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/resources/converter/source/dir1/dsl1b.groovy @@ -0,0 +1,30 @@ +import org.springframework.cloud.contract.verifier.dsl.Contract + +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Contract.make { + request { + method('PUT') + headers { + header 'Content-Type': 'application/json' + } + urlPattern $(client('/[0-9]{2}'), server('/12')) + } + response { + status 200 + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/resources/converter/source/dir2/dsl2.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/resources/converter/source/dir2/dsl2.groovy new file mode 100644 index 0000000000..b23e11ed01 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/resources/converter/source/dir2/dsl2.groovy @@ -0,0 +1,30 @@ +import org.springframework.cloud.contract.verifier.dsl.Contract + +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Contract.make { + request { + method('PUT') + headers { + header 'Content-Type': 'application/json' + } + url $(client('/[0-9]{2}'), server('/12')) + } + response { + status 200 + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/resources/converter/source/dslRoot.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/resources/converter/source/dslRoot.groovy new file mode 100644 index 0000000000..b23e11ed01 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-converters/src/test/resources/converter/source/dslRoot.groovy @@ -0,0 +1,30 @@ +import org.springframework.cloud.contract.verifier.dsl.Contract + +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Contract.make { + request { + method('PUT') + headers { + header 'Content-Type': 'application/json' + } + url $(client('/[0-9]{2}'), server('/12')) + } + response { + status 200 + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/ContractVerifierException.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/ContractVerifierException.groovy new file mode 100644 index 0000000000..6b1d5a9c79 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/ContractVerifierException.groovy @@ -0,0 +1,34 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier + +import groovy.transform.CompileStatic + +/** + * @author Jakub Kubrynski, codearte.io + */ +@CompileStatic +class ContractVerifierException extends RuntimeException { + + ContractVerifierException(String message) { + super(message) + } + + ContractVerifierException(String message, Throwable cause) { + super(message, cause) + } +} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/FileSaver.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/FileSaver.groovy similarity index 50% rename from accurest-core/src/main/groovy/io/codearte/accurest/FileSaver.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/FileSaver.groovy index 2a9c730787..6b350b34e3 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/FileSaver.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/FileSaver.groovy @@ -1,17 +1,33 @@ -package io.codearte.accurest +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier import groovy.transform.CompileStatic import groovy.util.logging.Slf4j -import io.codearte.accurest.config.TestFramework +import org.springframework.cloud.contract.verifier.config.TestFramework import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths import java.nio.file.StandardOpenOption -import static io.codearte.accurest.util.NamesUtil.beforeLast -import static io.codearte.accurest.util.NamesUtil.capitalize -import static io.codearte.accurest.util.NamesUtil.packageToDirectory +import static org.springframework.cloud.contract.verifier.util.NamesUtil.beforeLast +import static org.springframework.cloud.contract.verifier.util.NamesUtil.capitalize +import static org.springframework.cloud.contract.verifier.util.NamesUtil.packageToDirectory @CompileStatic @Slf4j diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/TestGenerator.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/TestGenerator.groovy similarity index 51% rename from accurest-core/src/main/groovy/io/codearte/accurest/TestGenerator.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/TestGenerator.groovy index d0e9f15346..47f3da17b1 100755 --- a/accurest-core/src/main/groovy/io/codearte/accurest/TestGenerator.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/TestGenerator.groovy @@ -1,43 +1,60 @@ -package io.codearte.accurest +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier import com.google.common.collect.ListMultimap import groovy.transform.PackageScope -import io.codearte.accurest.config.AccurestConfigProperties -import io.codearte.accurest.file.Contract -import io.codearte.accurest.file.ContractFileScanner import org.apache.commons.lang3.StringUtils +import org.springframework.cloud.contract.verifier.builder.SingleTestGenerator +import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties +import org.springframework.cloud.contract.verifier.file.ContractMetadata +import org.springframework.cloud.contract.verifier.file.ContractFileScanner import java.nio.charset.StandardCharsets import java.nio.file.Path import java.util.concurrent.atomic.AtomicInteger -import static io.codearte.accurest.util.NamesUtil.afterLast -import static io.codearte.accurest.util.NamesUtil.beforeLast -import static io.codearte.accurest.util.NamesUtil.convertIllegalPackageChars -import static io.codearte.accurest.util.NamesUtil.directoryToPackage +import static org.springframework.cloud.contract.verifier.util.NamesUtil.afterLast +import static org.springframework.cloud.contract.verifier.util.NamesUtil.beforeLast +import static org.springframework.cloud.contract.verifier.util.NamesUtil.convertIllegalPackageChars +import static org.springframework.cloud.contract.verifier.util.NamesUtil.directoryToPackage /** - * @author Jakub Kubrynski + * @author Jakub Kubrynski, codearte.io */ class TestGenerator { - private final AccurestConfigProperties configProperties - private final String DEFAULT_CLASS_PREFIX = "Accurest" + private final ContractVerifierConfigProperties configProperties + private final String DEFAULT_CLASS_PREFIX = "ContractVerifier" private AtomicInteger counter = new AtomicInteger() private SingleTestGenerator generator private FileSaver saver private ContractFileScanner contractFileScanner - TestGenerator(AccurestConfigProperties accurestConfigProperties) { - this(accurestConfigProperties, new SingleTestGenerator(accurestConfigProperties), - new FileSaver(accurestConfigProperties.generatedTestSourcesDir, accurestConfigProperties.targetFramework)) + TestGenerator(ContractVerifierConfigProperties configProperties) { + this(configProperties, new SingleTestGenerator(configProperties), + new FileSaver(configProperties.generatedTestSourcesDir, configProperties.targetFramework)) } - TestGenerator(AccurestConfigProperties configProperties, SingleTestGenerator generator, FileSaver saver) { + TestGenerator(ContractVerifierConfigProperties configProperties, SingleTestGenerator generator, FileSaver saver) { this.configProperties = configProperties if (configProperties.contractsDslDir == null) { - throw new AccurestException("Stubs directory not found under " + configProperties.contractsDslDir) + throw new ContractVerifierException("Stubs directory not found under " + configProperties.contractsDslDir) } this.generator = generator this.saver = saver @@ -53,9 +70,9 @@ class TestGenerator { @PackageScope void generateTestClasses(final String basePackageName) { - ListMultimap contracts = contractFileScanner.findContracts() + ListMultimap contracts = contractFileScanner.findContracts() contracts.asMap().entrySet().each { - Map.Entry> entry -> processIncludedDirectory(relativizeContractPath(entry), entry.getValue(), basePackageName) + Map.Entry> entry -> processIncludedDirectory(relativizeContractPath(entry), entry.getValue(), basePackageName) } } @@ -68,7 +85,7 @@ class TestGenerator { } private void processIncludedDirectory( - final String includedDirectoryRelativePath, Collection contracts, final String basePackageNameForClass) { + final String includedDirectoryRelativePath, Collection contracts, final String basePackageNameForClass) { if (contracts.size()) { def className = afterLast(includedDirectoryRelativePath.toString(), File.separator) + resolveNameSuffix() def packageName = buildPackage(basePackageNameForClass, includedDirectoryRelativePath) diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/builder/BlockBuilder.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/BlockBuilder.groovy similarity index 55% rename from accurest-core/src/main/groovy/io/codearte/accurest/builder/BlockBuilder.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/BlockBuilder.groovy index 3ab11e9359..2f0fb85483 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/builder/BlockBuilder.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/BlockBuilder.groovy @@ -1,17 +1,43 @@ -package io.codearte.accurest.builder +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.cloud.contract.verifier.builder + +import groovy.transform.CompileDynamic +import groovy.transform.CompileStatic import groovy.transform.PackageScope /** - * @author Jakub Kubrynski + * Builds a block of code. Allows to start, end, indent etc. pieces of code. + * + * @author Jakub Kubrynski, codearte.io + * + * @since 1.0.0 */ @PackageScope +@CompileStatic class BlockBuilder { private final StringBuilder builder private final String spacer private int indents + /** + * @param spacer - char used for spacing + */ BlockBuilder(String spacer) { this.spacer = spacer builder = new StringBuilder() @@ -48,6 +74,7 @@ class BlockBuilder { return this } + @CompileDynamic private void addIndentation() { indents.times { builder << spacer @@ -72,7 +99,6 @@ class BlockBuilder { return this } - @Override String toString() { return builder.toString() diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/builder/ClassBuilder.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/ClassBuilder.groovy similarity index 71% rename from accurest-core/src/main/groovy/io/codearte/accurest/builder/ClassBuilder.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/ClassBuilder.groovy index b24c5b57ec..4552ca7f05 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/builder/ClassBuilder.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/ClassBuilder.groovy @@ -1,11 +1,36 @@ -package io.codearte.accurest.builder - -import io.codearte.accurest.config.AccurestConfigProperties -import io.codearte.accurest.config.TestFramework -import io.codearte.accurest.util.NamesUtil -/** - * @author Jakub Kubrynski +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + +package org.springframework.cloud.contract.verifier.builder + +import groovy.transform.CompileStatic +import groovy.transform.PackageScope +import org.springframework.cloud.contract.verifier.config.TestFramework +import org.springframework.cloud.contract.verifier.util.NamesUtil +import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties + +/** + * Builds a class. Adds all the imports, static imports etc. + * + * @author Jakub Kubrynski, codearte.io + * + * @since 1.0.0 + */ +@CompileStatic +@PackageScope class ClassBuilder { private final String className @@ -29,7 +54,10 @@ class ClassBuilder { this.className = className } - static ClassBuilder createClass(String className, String classPackage, AccurestConfigProperties properties) { + /** + * Returns a {@link ClassBuilder} for the given parameters + */ + static ClassBuilder createClass(String className, String classPackage, ContractVerifierConfigProperties properties) { String baseClassForTests if (properties.targetFramework == TestFramework.SPOCK && !properties.baseClassForTests) { baseClassForTests = 'spock.lang.Specification' @@ -49,7 +77,6 @@ class ClassBuilder { return this } - ClassBuilder addStaticImport(String importToAdd) { staticImports << importToAdd return this diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/builder/JUnitMessagingMethodBodyBuilder.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JUnitMessagingMethodBodyBuilder.groovy similarity index 68% rename from accurest-core/src/main/groovy/io/codearte/accurest/builder/JUnitMessagingMethodBodyBuilder.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JUnitMessagingMethodBodyBuilder.groovy index fa8551cdb2..bf58dbef87 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/builder/JUnitMessagingMethodBodyBuilder.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JUnitMessagingMethodBodyBuilder.groovy @@ -1,25 +1,49 @@ -package io.codearte.accurest.builder +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.builder import groovy.json.StringEscapeUtils import groovy.transform.PackageScope import groovy.transform.TypeChecked -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.dsl.internal.ExecutionProperty -import io.codearte.accurest.dsl.internal.Header -import io.codearte.accurest.dsl.internal.Input -import io.codearte.accurest.dsl.internal.NamedProperty +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.dsl.internal.Header +import org.springframework.cloud.contract.verifier.dsl.internal.Input +import org.springframework.cloud.contract.verifier.dsl.internal.NamedProperty +import org.springframework.cloud.contract.verifier.dsl.internal.ExecutionProperty import java.util.regex.Pattern -import static io.codearte.accurest.config.TestFramework.JUNIT +import static org.springframework.cloud.contract.verifier.config.TestFramework.JUNIT + /** - * @author Jakub Kubrynski + * Builds a JUnit method for messaging + * + * Do not change to {@code @CompileStatic} since it's using double dispatch. + * + * @author Marcin Grzejszczak + * @author Jakub Kubrynski, codearte.io + * + * @since 1.0.0 */ @PackageScope @TypeChecked class JUnitMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder { - JUnitMessagingMethodBodyBuilder(GroovyDsl stubDefinition) { + JUnitMessagingMethodBodyBuilder(Contract stubDefinition) { super(stubDefinition) } @@ -28,7 +52,7 @@ class JUnitMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder { if (request.triggeredBy) { return request.triggeredBy.executionCommand } - return "accurestMessaging.send(inputMessage, \"${request.messageFrom.serverValue}\")" + return "contractVerifierMessaging.send(inputMessage, \"${request.messageFrom.serverValue}\")" } @Override @@ -68,16 +92,16 @@ class JUnitMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder { @Override protected void validateResponseHeadersBlock(BlockBuilder bb) { - bb.addLine("""AccurestMessage response = accurestMessaging.receiveMessage("${outputMessage.sentTo.serverValue}");""") + bb.addLine("""ContractVerifierMessage response = contractVerifierMessaging.receiveMessage("${outputMessage.sentTo.serverValue}");""") bb.addLine("""assertThat(response).isNotNull();""") - outputMessage.headers?.collect { Header header ->\ + outputMessage.headers?.executeForEachHeader { Header header ->\ processHeaderElement(bb, header.name, header.serverValue) } } @Override protected String getResponseAsString() { - return 'accurestObjectMapper.writeValueAsString(response.getPayload())' + return 'contractVerifierObjectMapper.writeValueAsString(response.getPayload())' } @Override @@ -113,14 +137,14 @@ class JUnitMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder { @Override protected String getInputString() { - String request = 'AccurestMessage inputMessage = accurestMessaging.create(' + String request = 'ContractVerifierMessage inputMessage = contractVerifierMessaging.create(' if (inputMessage.messageBody) { request = "${request}\n \"${StringEscapeUtils.escapeJava(bodyAsString)}\"\n " } if (inputMessage.messageHeaders) { request = "${request}, headers()\n" } - inputMessage.messageHeaders?.collect { Header header -> + inputMessage.messageHeaders?.executeForEachHeader { Header header -> request = "${request} ${getHeaderString(header)}" } return "${request})" diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/builder/JUnitMethodBodyBuilder.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JUnitMethodBodyBuilder.groovy similarity index 69% rename from accurest-core/src/main/groovy/io/codearte/accurest/builder/JUnitMethodBodyBuilder.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JUnitMethodBodyBuilder.groovy index 543e8c41cf..8c3fc89258 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/builder/JUnitMethodBodyBuilder.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JUnitMethodBodyBuilder.groovy @@ -1,29 +1,51 @@ -package io.codearte.accurest.builder +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.builder import groovy.json.StringEscapeUtils import groovy.transform.PackageScope import groovy.transform.TypeChecked -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.dsl.internal.ExecutionProperty -import io.codearte.accurest.dsl.internal.Header -import io.codearte.accurest.dsl.internal.NamedProperty -import io.codearte.accurest.dsl.internal.Request +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.dsl.internal.Header +import org.springframework.cloud.contract.verifier.dsl.internal.NamedProperty +import org.springframework.cloud.contract.verifier.dsl.internal.Request +import org.springframework.cloud.contract.verifier.dsl.internal.ExecutionProperty import java.util.regex.Pattern import static groovy.json.StringEscapeUtils.escapeJava -import static io.codearte.accurest.config.TestFramework.JUNIT -import static io.codearte.accurest.util.ContentUtils.getJavaMultipartFileParameterContent +import static org.springframework.cloud.contract.verifier.config.TestFramework.JUNIT +import static org.springframework.cloud.contract.verifier.util.ContentUtils.getJavaMultipartFileParameterContent /** - * @author Jakub Kubrynski - * @author Olga Maciaszek-Sharma + * Root class for JUnit method building + * + * Do not change to {@code @CompileStatic} since it's using double dispatch. + * + * @author Jakub Kubrynski, codearte.io + * @author Olga Maciaszek-Sharma, codearte.io + * + * @since 1.0.0 */ @TypeChecked @PackageScope abstract class JUnitMethodBodyBuilder extends RequestProcessingMethodBodyBuilder { - JUnitMethodBodyBuilder(GroovyDsl stubDefinition) { + JUnitMethodBodyBuilder(Contract stubDefinition) { super(stubDefinition) } diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/builder/JaxRsClientJUnitMethodBodyBuilder.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JaxRsClientJUnitMethodBodyBuilder.groovy similarity index 66% rename from accurest-core/src/main/groovy/io/codearte/accurest/builder/JaxRsClientJUnitMethodBodyBuilder.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JaxRsClientJUnitMethodBodyBuilder.groovy index ab8506d61f..feb23dfd57 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/builder/JaxRsClientJUnitMethodBodyBuilder.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JaxRsClientJUnitMethodBodyBuilder.groovy @@ -1,22 +1,48 @@ -package io.codearte.accurest.builder +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.dsl.internal.ExecutionProperty -import io.codearte.accurest.dsl.internal.Header -import io.codearte.accurest.dsl.internal.QueryParameter -import io.codearte.accurest.dsl.internal.QueryParameters +package org.springframework.cloud.contract.verifier.builder + +import groovy.transform.PackageScope +import groovy.transform.TypeChecked +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.dsl.internal.Header +import org.springframework.cloud.contract.verifier.dsl.internal.QueryParameter +import org.springframework.cloud.contract.verifier.dsl.internal.ExecutionProperty +import org.springframework.cloud.contract.verifier.dsl.internal.QueryParameters import java.util.regex.Pattern -import static io.codearte.accurest.config.TestFramework.JUNIT +import static org.springframework.cloud.contract.verifier.config.TestFramework.JUNIT /** - * @author Olga Maciaszek-Sharma - @since 21.02.16 + * JaxRs implementation of the {@link JUnitMethodBodyBuilder}. Knows how to build + * a test method for JaxRs. + * + * Do not change to {@code @CompileStatic} since it's using double dispatch. + * + * @author Olga Maciaszek-Sharma, codearte.io + * + * @since 1.0.0 */ +@TypeChecked +@PackageScope class JaxRsClientJUnitMethodBodyBuilder extends JUnitMethodBodyBuilder { - JaxRsClientJUnitMethodBodyBuilder(GroovyDsl stubDefinition) { + JaxRsClientJUnitMethodBodyBuilder(Contract stubDefinition) { super(stubDefinition) } @@ -74,7 +100,7 @@ class JaxRsClientJUnitMethodBodyBuilder extends JUnitMethodBodyBuilder { } protected appendHeaders(BlockBuilder bb) { - request.headers?.collect { Header header -> + request.headers?.executeForEachHeader { Header header -> if (header.name == 'Content-Type' || header.name == 'Accept') return bb.addLine(".header(\"${header.name}\", \"${header.serverValue}\")") } @@ -96,7 +122,7 @@ class JaxRsClientJUnitMethodBodyBuilder extends JUnitMethodBodyBuilder { @Override protected void validateResponseHeadersBlock(BlockBuilder bb) { - response.headers?.collect { Header header -> + response.headers?.executeForEachHeader { Header header -> processHeaderElement(bb, header.name, header.serverValue) } } diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/builder/JaxRsClientSpockMethodRequestProcessingBodyBuilder.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JaxRsClientSpockMethodRequestProcessingBodyBuilder.groovy similarity index 69% rename from accurest-core/src/main/groovy/io/codearte/accurest/builder/JaxRsClientSpockMethodRequestProcessingBodyBuilder.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JaxRsClientSpockMethodRequestProcessingBodyBuilder.groovy index 86fe435034..b45c7981f2 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/builder/JaxRsClientSpockMethodRequestProcessingBodyBuilder.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JaxRsClientSpockMethodRequestProcessingBodyBuilder.groovy @@ -1,20 +1,45 @@ -package io.codearte.accurest.builder +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.builder import groovy.transform.PackageScope import groovy.transform.TypeChecked -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.dsl.internal.ExecutionProperty -import io.codearte.accurest.dsl.internal.Header -import io.codearte.accurest.dsl.internal.QueryParameter -import io.codearte.accurest.dsl.internal.QueryParameters +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.dsl.internal.Header +import org.springframework.cloud.contract.verifier.dsl.internal.QueryParameter +import org.springframework.cloud.contract.verifier.dsl.internal.QueryParameters +import org.springframework.cloud.contract.verifier.dsl.internal.ExecutionProperty import java.util.regex.Pattern +/** + * Knows how to build a Spock test method for JaxRs. + * + * Do not change to {@code @CompileStatic} since it's using double dispatch. + * + * @author Olga Maciaszek-Sharma, codearte.io + * + * @since 1.0.0 + */ @PackageScope @TypeChecked class JaxRsClientSpockMethodRequestProcessingBodyBuilder extends SpockMethodRequestProcessingBodyBuilder { - JaxRsClientSpockMethodRequestProcessingBodyBuilder(GroovyDsl stubDefinition) { + JaxRsClientSpockMethodRequestProcessingBodyBuilder(Contract stubDefinition) { super(stubDefinition) } @@ -80,7 +105,7 @@ class JaxRsClientSpockMethodRequestProcessingBodyBuilder extends SpockMethodRequ } protected appendHeaders(BlockBuilder bb) { - request.headers?.collect { Header header -> + request.headers?.executeForEachHeader { Header header -> if (header.name == 'Content-Type' || header.name == 'Accept') return // Particular headers are set via 'request' / 'entity' methods bb.addLine(".header('${header.name}', '${header.serverValue}')") } @@ -97,7 +122,7 @@ class JaxRsClientSpockMethodRequestProcessingBodyBuilder extends SpockMethodRequ @Override protected void validateResponseHeadersBlock(BlockBuilder bb) { - response.headers?.collect { Header header -> + response.headers?.executeForEachHeader { Header header -> processHeaderElement(bb, header.name, header.serverValue) } } diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilder.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/MessagingMethodBodyBuilder.groovy similarity index 56% rename from accurest-core/src/main/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilder.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/MessagingMethodBodyBuilder.groovy index 6da92a5bce..33229a001a 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilder.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/MessagingMethodBodyBuilder.groovy @@ -1,18 +1,40 @@ -package io.codearte.accurest.builder +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.builder import groovy.json.JsonOutput import groovy.transform.PackageScope import groovy.transform.TypeChecked -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.dsl.internal.Input -import io.codearte.accurest.dsl.internal.OutputMessage -import io.codearte.accurest.util.ContentType +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.dsl.internal.Input +import org.springframework.cloud.contract.verifier.dsl.internal.OutputMessage +import org.springframework.cloud.contract.verifier.util.ContentType + +import static org.springframework.cloud.contract.verifier.util.ContentUtils.recognizeContentTypeFromContent +import static org.springframework.cloud.contract.verifier.util.ContentUtils.recognizeContentTypeFromHeader -import static io.codearte.accurest.util.ContentUtils.recognizeContentTypeFromContent -import static io.codearte.accurest.util.ContentUtils.recognizeContentTypeFromHeader /** - * @author Olga Maciaszek-Sharma - * @since 2016-02-17 + * Root class for messaging method building. + * + * Do not change to {@code @CompileStatic} since it's using double dispatch. + * + * @author Olga Maciaszek-Sharma, codearte.io + * + * @since 1.0.0 */ @TypeChecked @PackageScope @@ -21,7 +43,7 @@ abstract class MessagingMethodBodyBuilder extends MethodBodyBuilder { protected final Input inputMessage protected final OutputMessage outputMessage - MessagingMethodBodyBuilder(GroovyDsl stubDefinition) { + MessagingMethodBodyBuilder(Contract stubDefinition) { this.inputMessage = stubDefinition.input this.outputMessage = stubDefinition.outputMessage } diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/builder/MethodBodyBuilder.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/MethodBodyBuilder.groovy similarity index 52% rename from accurest-core/src/main/groovy/io/codearte/accurest/builder/MethodBodyBuilder.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/MethodBodyBuilder.groovy index 044394a1aa..eb7b7fc1ea 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/builder/MethodBodyBuilder.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/MethodBodyBuilder.groovy @@ -1,76 +1,186 @@ -package io.codearte.accurest.builder +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.builder import groovy.transform.PackageScope import groovy.transform.TypeChecked -import io.codearte.accurest.dsl.internal.* -import io.codearte.accurest.util.ContentType -import io.codearte.accurest.util.JsonPaths -import io.codearte.accurest.util.JsonToJsonPathsConverter -import io.codearte.accurest.util.MapConverter +import org.springframework.cloud.contract.verifier.dsl.internal.NamedProperty +import org.springframework.cloud.contract.verifier.util.MapConverter +import org.springframework.cloud.contract.verifier.dsl.internal.DslProperty +import org.springframework.cloud.contract.verifier.dsl.internal.ExecutionProperty +import org.springframework.cloud.contract.verifier.dsl.internal.Header +import org.springframework.cloud.contract.verifier.dsl.internal.MatchingStrategy +import org.springframework.cloud.contract.verifier.dsl.internal.QueryParameter +import org.springframework.cloud.contract.verifier.util.ContentType +import org.springframework.cloud.contract.verifier.util.JsonPaths +import org.springframework.cloud.contract.verifier.util.JsonToJsonPathsConverter import java.util.regex.Pattern -import static io.codearte.accurest.util.ContentUtils.extractValue +import static org.springframework.cloud.contract.verifier.util.ContentUtils.extractValue + /** - * @author Olga Maciaszek-Sharma - * @since 2016-02-17 + * Main class for building method body. + * + * Do not change to {@code @CompileStatic} since it's using double dispatch. + * + * @author Olga Maciaszek-Sharma, codearte.io + * + * @since 1.0.0 */ @TypeChecked @PackageScope abstract class MethodBodyBuilder { + /** + * Builds the response body validation code block + */ protected abstract void validateResponseCodeBlock(BlockBuilder bb) + /** + * Builds the response headers validation code block + */ protected abstract void validateResponseHeadersBlock(BlockBuilder bb) + /** + * Builds the code that returns response in the string format + */ protected abstract String getResponseAsString() + /** + * Returns the given string with comment sign if required by the given implementation + */ protected abstract String addCommentSignIfRequired(String baseString) + /** + * Adds a colon sign at the end of each line if necessary + */ protected abstract BlockBuilder addColonIfRequired(BlockBuilder blockBuilder) + /** + * Builds the code that for the given {@code property} will compare it to + * the given {@code value} + */ protected abstract String getResponseBodyPropertyComparisonString(String property, String value) + /** + * Appends to the {@link BlockBuilder} the assertion for the given body element + */ protected abstract void processBodyElement(BlockBuilder blockBuilder, String property, ExecutionProperty exec) + /** + * Appends to the {@link BlockBuilder} the assertion for the given body element + */ protected abstract void processBodyElement(BlockBuilder blockBuilder, String property, Map.Entry entry) + /** + * Appends to the {@link BlockBuilder} the assertion for the given header element + */ protected abstract void processHeaderElement(BlockBuilder blockBuilder, String property, Pattern pattern) + /** + * Appends to the {@link BlockBuilder} the assertion for the given header element + */ protected abstract void processHeaderElement(BlockBuilder blockBuilder, String property, ExecutionProperty exec) + /** + * Appends to the {@link BlockBuilder} the assertion for the given header element + */ protected abstract void processHeaderElement(BlockBuilder blockBuilder, String property, String value) + /** + * Appends to the {@link BlockBuilder} the code to retrieve a value for a property + * from the list with the given index + */ protected abstract String getPropertyInListString(String property, Integer index) protected abstract String convertUnicodeEscapesIfRequired(String json) + /** + * NOTE: XML support is experimental + */ protected abstract String getParsedXmlResponseBodyString(String responseString) + /** + * Builds the code that returns String from a body that is plain text + */ protected abstract String getSimpleResponseBodyString(String responseString) + /** + * Builds the code that returns the "message". For messaging it will be an input + * message. For REST it will be an input request. + */ protected abstract String getInputString() + /** + * Builds the code to append a header to the request / message + */ protected abstract String getHeaderString(Header header) + /** + * Builds the code to append body to the request / message + */ protected abstract String getBodyString(String bodyAsString) + /** + * Builds the code to append multipart content to the request. + * Not applicable for messaging. + */ protected abstract String getMultipartFileParameterContent(String propertyName, NamedProperty propertyValue) + /** + * Builds the code to append a form parameter to the request. + * Not applicable for messaging. + */ protected abstract String getParameterString(Map.Entry parameter) + /** + * Appends the code to {@link BlockBuilder} for initial request processing + */ protected abstract void processInput(BlockBuilder bb) + /** + * Appends the code to {@link BlockBuilder} for the {@code //when} block + */ protected abstract void when(BlockBuilder bb) + /** + * Appends the code to {@link BlockBuilder} for the {@code //then} block + */ protected abstract void then(BlockBuilder bb) + /** + * Returns a {@link org.springframework.cloud.contract.verifier.util.ContentType} for the given request + */ protected abstract ContentType getResponseContentType() + /** + * Converts the body into String format + */ protected abstract String getBodyAsString() + /** + * Returns {@code true} if given section should be created + */ protected abstract boolean hasGivenSection() + /** + * Builds the test contents and appends them to {@link BlockBuilder} + */ void appendTo(BlockBuilder blockBuilder) { blockBuilder.startBlock() @@ -83,6 +193,9 @@ abstract class MethodBodyBuilder { blockBuilder.endBlock() } + /** + * Prepares the {@code given} block section together with comments and indents + */ protected void givenBlock(BlockBuilder bb) { bb.addLine(addCommentSignIfRequired('given:')) bb.startBlock() @@ -90,6 +203,9 @@ abstract class MethodBodyBuilder { bb.endBlock().addEmptyLine() } + /** + * Prepares the {@code when} block section together with comments and indents + */ protected void whenBlock(BlockBuilder bb) { bb.addLine(addCommentSignIfRequired('when:')) bb.startBlock() @@ -97,6 +213,9 @@ abstract class MethodBodyBuilder { bb.endBlock().addEmptyLine() } + /** + * Prepares the {@code then} block section together with comments and indents + */ protected void thenBlock(BlockBuilder bb) { bb.addLine(addCommentSignIfRequired('then:')) bb.startBlock() @@ -104,6 +223,9 @@ abstract class MethodBodyBuilder { bb.endBlock() } + /** + * Builds the {@code given} block section together with comments and indents + */ protected void given(BlockBuilder bb) { bb.addLine(getInputString()) bb.indent() @@ -112,6 +234,10 @@ abstract class MethodBodyBuilder { bb.unindent() } + /** + * Builds the response body verification part. The code will differ depending on the + * ContentType, type of response etc. The result will be appended to {@link BlockBuilder} + */ protected void validateResponseBodyBlock(BlockBuilder bb, Object responseBody) { ContentType contentType = getResponseContentType() if (responseBody instanceof GString) { @@ -138,15 +264,24 @@ abstract class MethodBodyBuilder { } } + /** + * Post processing of each JSON path entry + */ protected String postProcessJsonPathCall(String jsonPath) { return jsonPath } + /** + * Appends to {@link BlockBuilder} parsing of the JSON Path document + */ protected void appendJsonPath(BlockBuilder blockBuilder, String json) { blockBuilder.addLine(("DocumentContext parsedJson = JsonPath.parse($json)")) addColonIfRequired(blockBuilder) } + /** + * Appends to {@link BlockBuilder} processing of the given String value. + */ protected void processText(BlockBuilder blockBuilder, String property, String value) { if (value.startsWith('$')) { value = stripFirstChar(value).replaceAll('\\$value', "responseBody$property") @@ -161,16 +296,29 @@ abstract class MethodBodyBuilder { return s.substring(1); } + /** + * Appends to the {@link BlockBuilder} the assertion for the given header element + */ protected void processHeaderElement(BlockBuilder blockBuilder, String property, Object value) { } + /** + * Appends to the {@link BlockBuilder} the assertion for the given body element + */ protected void processBodyElement(BlockBuilder blockBuilder, String property, Object value) { } + /** + * Removes unnecessary quotes + */ protected String trimRepeatedQuotes(String toTrim) { return toTrim.startsWith('"') ? toTrim.replaceAll('"', '') : toTrim } + /** + * Converts the passed body into ints server side representation. All {@link DslProperty} + * will return their server side values + */ protected Object extractServerValueFromBody(bodyValue) { if (bodyValue instanceof GString) { bodyValue = extractValue(bodyValue, { DslProperty dslProperty -> dslProperty.serverValue }) @@ -180,28 +328,48 @@ abstract class MethodBodyBuilder { return bodyValue } + /** + * Converts the {@link org.springframework.cloud.contract.verifier.dsl.internal.QueryParameter} server side value into its String + * representation + */ protected String resolveParamValue(QueryParameter param) { return resolveParamValue(param.serverValue) } + /** + * Converts the query parameter value into String + */ protected String resolveParamValue(Object value) { return value.toString() } + /** + * Converts the query parameter value into String + */ protected String resolveParamValue(MatchingStrategy matchingStrategy) { return matchingStrategy.serverValue.toString() } + /** + * Depending on the object type extracts the test side values and + * combines them into a String representation + */ protected String getTestSideValue(Object object) { return MapConverter.getTestSideValues(object).toString() } + /** + * Appends to the {@link BlockBuilder} the assertion for the given body element + */ protected void processBodyElement(BlockBuilder blockBuilder, String property, Map map) { map.each { processBodyElement(blockBuilder, property, it) } } + /** + * Appends to the {@link BlockBuilder} the assertion for the given body element + */ protected void processBodyElement(BlockBuilder blockBuilder, String property, List list) { list.eachWithIndex { listElement, listIndex -> String prop = getPropertyInListString(property, listIndex as Integer) diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/MethodBuilder.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/MethodBuilder.groovy new file mode 100644 index 0000000000..090f87273e --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/MethodBuilder.groovy @@ -0,0 +1,95 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.builder + +import groovy.transform.CompileStatic +import groovy.transform.PackageScope +import groovy.util.logging.Slf4j +import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties +import org.springframework.cloud.contract.verifier.config.TestFramework +import org.springframework.cloud.contract.verifier.util.NamesUtil +import org.springframework.cloud.contract.verifier.config.TestMode +import org.springframework.cloud.contract.verifier.file.ContractMetadata + +/** + * Builds a test method. Adds an ignore annotation on a method if necessary. + * + * @author Jakub Kubrynski, codearte.io + * + * @since 1.0.0 + */ +@Slf4j +@CompileStatic +@PackageScope +class MethodBuilder { + + private final String methodName + private final org.springframework.cloud.contract.verifier.dsl.Contract stubContent + private final ContractVerifierConfigProperties configProperties + private final boolean ignored + + private MethodBuilder(String methodName, org.springframework.cloud.contract.verifier.dsl.Contract stubContent, ContractVerifierConfigProperties configProperties, boolean ignored) { + this.ignored = ignored + this.stubContent = stubContent + this.methodName = methodName + this.configProperties = configProperties + } + + /** + * A factory method that creates a {@link MethodBuilder} for the given arguments + */ + static MethodBuilder createTestMethod(ContractMetadata contract, File stubsFile, org.springframework.cloud.contract.verifier.dsl.Contract stubContent, ContractVerifierConfigProperties configProperties) { + log.debug("Stub content Groovy DSL [$stubContent]") + String methodName = NamesUtil.camelCase(NamesUtil.toLastDot(NamesUtil.afterLast(stubsFile.path, File.separator))) + return new MethodBuilder(methodName, stubContent, configProperties, contract.ignored) + } + + /** + * Appends to the {@link BlockBuilder} the contents of the test + */ + void appendTo(BlockBuilder blockBuilder) { + if (configProperties.targetFramework == TestFramework.JUNIT) { + blockBuilder.addLine('@Test') + } + if (ignored) { + blockBuilder.addLine('@Ignore') + } + blockBuilder.addLine(configProperties.targetFramework.methodModifier + "validate_$methodName() throws Exception {") + getMethodBodyBuilder().appendTo(blockBuilder) + blockBuilder.addLine('}') + } + + private MethodBodyBuilder getMethodBodyBuilder() { + if (stubContent.input || stubContent.outputMessage) { + if (configProperties.targetFramework == TestFramework.JUNIT){ + return new JUnitMessagingMethodBodyBuilder(stubContent) + } + return new SpockMessagingMethodBodyBuilder(stubContent) + } + if (configProperties.testMode == TestMode.MOCKMVC && configProperties.targetFramework == TestFramework.JUNIT){ + return new MockMvcJUnitMethodBodyBuilder(stubContent) + } + if (configProperties.testMode == TestMode.JAXRSCLIENT) { + if (configProperties.targetFramework == TestFramework.JUNIT){ + return new JaxRsClientJUnitMethodBodyBuilder(stubContent) + } + return new JaxRsClientSpockMethodRequestProcessingBodyBuilder(stubContent) + } + return new MockMvcSpockMethodRequestProcessingBodyBuilder(stubContent) + } + +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcJUnitMethodBodyBuilder.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcJUnitMethodBodyBuilder.groovy new file mode 100644 index 0000000000..406ad8a5f2 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcJUnitMethodBodyBuilder.groovy @@ -0,0 +1,69 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.builder + +import groovy.transform.PackageScope +import groovy.transform.TypeChecked +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.dsl.internal.Header +import org.springframework.cloud.contract.verifier.dsl.internal.ExecutionProperty + +import java.util.regex.Pattern + +/** + * A {@link JUnitMethodBodyBuilder} implementation that uses MockMvc to send requests. + * + * @author Olga Maciaszek-Sharma, codearte.io + * + * @since 1.0.0 + */ +@TypeChecked +@PackageScope +class MockMvcJUnitMethodBodyBuilder extends JUnitMethodBodyBuilder { + + MockMvcJUnitMethodBodyBuilder(Contract stubDefinition) { + super(stubDefinition) + } + + @Override + protected void validateResponseCodeBlock(BlockBuilder bb) { + bb.addLine("assertThat(response.statusCode()).isEqualTo($response.status.serverValue);") + } + + @Override + protected void validateResponseHeadersBlock(BlockBuilder bb) { + response.headers?.executeForEachHeader { Header header ->\ + processHeaderElement(bb, header.name, header.serverValue) + } + } + + @Override + protected void processHeaderElement(BlockBuilder blockBuilder, String property, String value) { + blockBuilder.addLine("assertThat(response.header(\"$property\")).${createHeaderComparison(value)}") + } + + @Override + protected void processHeaderElement(BlockBuilder blockBuilder, String property, Pattern pattern) { + blockBuilder.addLine("assertThat(response.header(\"$property\")).${createHeaderComparison(pattern)}") + } + + @Override + protected void processHeaderElement(BlockBuilder blockBuilder, String property, ExecutionProperty exec) { + blockBuilder.addLine("${exec.insertValue("response.header(\"$property\")")};") + } + +} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/builder/MockMvcSpockMethodRequestProcessingBodyBuilder.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcSpockMethodRequestProcessingBodyBuilder.groovy similarity index 55% rename from accurest-core/src/main/groovy/io/codearte/accurest/builder/MockMvcSpockMethodRequestProcessingBodyBuilder.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcSpockMethodRequestProcessingBodyBuilder.groovy index 5d983c3e6c..742a49ab41 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/builder/MockMvcSpockMethodRequestProcessingBodyBuilder.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcSpockMethodRequestProcessingBodyBuilder.groovy @@ -1,18 +1,39 @@ -package io.codearte.accurest.builder +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.builder import groovy.transform.PackageScope import groovy.transform.TypeChecked -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.dsl.internal.ExecutionProperty -import io.codearte.accurest.dsl.internal.Header +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.dsl.internal.ExecutionProperty +import org.springframework.cloud.contract.verifier.dsl.internal.Header import java.util.regex.Pattern +/** + * A {@link SpockMethodRequestProcessingBodyBuilder} implementation that uses MockMvc to send requests. + * + * @since 1.0.0 + */ @PackageScope @TypeChecked class MockMvcSpockMethodRequestProcessingBodyBuilder extends SpockMethodRequestProcessingBodyBuilder { - MockMvcSpockMethodRequestProcessingBodyBuilder(GroovyDsl stubDefinition) { + MockMvcSpockMethodRequestProcessingBodyBuilder(Contract stubDefinition) { super(stubDefinition) } @@ -23,7 +44,7 @@ class MockMvcSpockMethodRequestProcessingBodyBuilder extends SpockMethodRequestP @Override protected void validateResponseHeadersBlock(BlockBuilder bb) { - response.headers?.collect { Header header -> + response.headers?.executeForEachHeader { Header header -> processHeaderElement(bb, header.name, header.serverValue) } } diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/builder/RequestProcessingMethodBodyBuilder.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/RequestProcessingMethodBodyBuilder.groovy similarity index 57% rename from accurest-core/src/main/groovy/io/codearte/accurest/builder/RequestProcessingMethodBodyBuilder.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/RequestProcessingMethodBodyBuilder.groovy index c26e09ab08..ce3385a18d 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/builder/RequestProcessingMethodBodyBuilder.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/RequestProcessingMethodBodyBuilder.groovy @@ -1,26 +1,47 @@ -package io.codearte.accurest.builder +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.builder import groovy.json.JsonOutput import groovy.transform.PackageScope import groovy.transform.TypeChecked import groovy.transform.TypeCheckingMode -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.dsl.internal.Header -import io.codearte.accurest.dsl.internal.MatchingStrategy -import io.codearte.accurest.dsl.internal.NamedProperty -import io.codearte.accurest.dsl.internal.QueryParameter -import io.codearte.accurest.dsl.internal.Request -import io.codearte.accurest.dsl.internal.Response -import io.codearte.accurest.dsl.internal.Url -import io.codearte.accurest.util.ContentType -import io.codearte.accurest.util.MapConverter +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.dsl.internal.Request +import org.springframework.cloud.contract.verifier.dsl.internal.Header +import org.springframework.cloud.contract.verifier.dsl.internal.MatchingStrategy +import org.springframework.cloud.contract.verifier.dsl.internal.NamedProperty +import org.springframework.cloud.contract.verifier.dsl.internal.QueryParameter +import org.springframework.cloud.contract.verifier.dsl.internal.Response +import org.springframework.cloud.contract.verifier.dsl.internal.Url +import org.springframework.cloud.contract.verifier.util.ContentType +import org.springframework.cloud.contract.verifier.util.MapConverter -import static io.codearte.accurest.util.ContentUtils.recognizeContentTypeFromContent -import static io.codearte.accurest.util.ContentUtils.recognizeContentTypeFromHeader +import static org.springframework.cloud.contract.verifier.util.ContentUtils.recognizeContentTypeFromContent +import static org.springframework.cloud.contract.verifier.util.ContentUtils.recognizeContentTypeFromHeader /** - * @author Olga Maciaszek-Sharma - * @since 2016-02-17 + * An abstraction for creating a test method that includes processing of an HTTP request + * + * Do not change to {@code @CompileStatic} since it's using double dispatch. + * + * @author Olga Maciaszek-Sharma, codearte.io + * + * @since 1.0.0 */ @TypeChecked @PackageScope @@ -29,11 +50,14 @@ abstract class RequestProcessingMethodBodyBuilder extends MethodBodyBuilder { protected final Request request protected final Response response - RequestProcessingMethodBodyBuilder(GroovyDsl stubDefinition) { + RequestProcessingMethodBodyBuilder(Contract stubDefinition) { this.request = stubDefinition.request this.response = stubDefinition.response } + /** + * Returns code used to retrieve a response for the given {@link Request} + */ protected abstract String getInputString(Request request) @Override @@ -41,20 +65,30 @@ abstract class RequestProcessingMethodBodyBuilder extends MethodBodyBuilder { return true } + /** + * Returns {@code true} if the query parameter is allowed + */ protected boolean allowedQueryParameter(QueryParameter param) { return allowedQueryParameter(param.serverValue) } + /** + * Returns {@code true} if the query parameter is allowed + */ protected boolean allowedQueryParameter(MatchingStrategy matchingStrategy) { return matchingStrategy.type != MatchingStrategy.Type.ABSENT } + /** + * Returns {@code true} if the query parameter is allowed + */ protected boolean allowedQueryParameter(Object o) { return true } + @Override protected void processInput(BlockBuilder bb) { - request.headers?.collect { Header header -> + request.headers?.executeForEachHeader { Header header -> bb.addLine(getHeaderString(header)) } if (request.body) { @@ -65,6 +99,7 @@ abstract class RequestProcessingMethodBodyBuilder extends MethodBodyBuilder { } } + @Override protected void when(BlockBuilder bb) { bb.addLine(getInputString(request)) bb.indent() @@ -77,6 +112,7 @@ abstract class RequestProcessingMethodBodyBuilder extends MethodBodyBuilder { bb.unindent() } + @Override protected void then(BlockBuilder bb) { validateResponseCodeBlock(bb) if (response.headers) { @@ -89,6 +125,7 @@ abstract class RequestProcessingMethodBodyBuilder extends MethodBodyBuilder { } } + @Override protected ContentType getResponseContentType() { ContentType contentType = recognizeContentTypeFromHeader(response.headers) if (contentType == ContentType.UNKNOWN) { @@ -97,6 +134,7 @@ abstract class RequestProcessingMethodBodyBuilder extends MethodBodyBuilder { return contentType } + @Override protected String getBodyAsString() { Object bodyValue = extractServerValueFromBody(request.body.serverValue) String json = new JsonOutput().toJson(bodyValue) @@ -104,10 +142,16 @@ abstract class RequestProcessingMethodBodyBuilder extends MethodBodyBuilder { return trimRepeatedQuotes(json) } + /** + * Returns a map of server side multipart parameters + */ protected Map getMultipartParameters() { return (Map) request?.multipart?.serverValue } + /** + * Maps the {@link Request} into a {@link ContentType} + */ protected ContentType getRequestContentType() { ContentType contentType = recognizeContentTypeFromHeader(request.headers) if (contentType == ContentType.UNKNOWN) { @@ -116,6 +160,10 @@ abstract class RequestProcessingMethodBodyBuilder extends MethodBodyBuilder { return contentType } + /** + * Builds a String URL from {@link Request}'s test side values. It can be + * a concrete value of the URL or a path. + */ protected String buildUrl(Request request) { if (request.url) return getTestSideValue(buildUrlFromUrlPath(request.url)) @@ -124,6 +172,10 @@ abstract class RequestProcessingMethodBodyBuilder extends MethodBodyBuilder { throw new IllegalStateException("URL is not set!") } + /** + * Depending on the presence of query parameters builds the String value + * of the URL. Retrieves any present test side values + */ @TypeChecked(TypeCheckingMode.SKIP) protected String buildUrlFromUrlPath(Url url) { if (hasQueryParams(url)) { @@ -138,6 +190,9 @@ abstract class RequestProcessingMethodBodyBuilder extends MethodBodyBuilder { return MapConverter.getTestSideValues(url.serverValue) } + /** + * Returns a line of code to send a multi part parameter in the request + */ protected String getMultipartParameterLine(Map.Entry parameter) { if (parameter.value instanceof NamedProperty) { return ".multiPart(${getMultipartFileParameterContent(parameter.key, (NamedProperty) parameter.value)})" diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/SingleTestGenerator.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/SingleTestGenerator.groovy similarity index 56% rename from accurest-core/src/main/groovy/io/codearte/accurest/SingleTestGenerator.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/SingleTestGenerator.groovy index ee8a8e64b1..58e406b66a 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/SingleTestGenerator.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/SingleTestGenerator.groovy @@ -1,35 +1,58 @@ -package io.codearte.accurest +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.builder import groovy.transform.Canonical import groovy.transform.EqualsAndHashCode import groovy.transform.PackageScope import groovy.util.logging.Slf4j -import io.codearte.accurest.builder.ClassBuilder -import io.codearte.accurest.config.AccurestConfigProperties -import io.codearte.accurest.config.TestFramework -import io.codearte.accurest.config.TestMode -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.file.Contract -import io.codearte.accurest.util.AccurestDslConverter +import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties +import org.springframework.cloud.contract.verifier.config.TestFramework +import org.springframework.cloud.contract.verifier.file.ContractMetadata +import org.springframework.cloud.contract.verifier.util.ContractVerifierDslConverter +import org.springframework.cloud.contract.verifier.config.TestMode -import static io.codearte.accurest.builder.ClassBuilder.createClass -import static io.codearte.accurest.builder.MethodBuilder.createTestMethod -import static io.codearte.accurest.util.NamesUtil.capitalize +import static ClassBuilder.createClass +import static MethodBuilder.createTestMethod +import static org.springframework.cloud.contract.verifier.util.NamesUtil.capitalize +/** + * Builds a single test for the given {@link ContractVerifierConfigProperties properties} + * + * @since 1.0.0 + */ @Slf4j class SingleTestGenerator { private static final String JSON_ASSERT_STATIC_IMPORT = 'com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson' private static final String JSON_ASSERT_CLASS = 'com.toomuchcoding.jsonassert.JsonAssertion' - private final AccurestConfigProperties configProperties + private final ContractVerifierConfigProperties configProperties - SingleTestGenerator(AccurestConfigProperties configProperties) { + SingleTestGenerator(ContractVerifierConfigProperties configProperties) { this.configProperties = configProperties } + /** + * Returns String code representing a test class with test methods for + * each {@link ContractMetadata} + */ @PackageScope - String buildClass(Collection listOfFiles, String className, String classPackage) { + String buildClass(Collection listOfFiles, String className, String classPackage) { ClassBuilder clazz = createClass(capitalize(className), classPackage, configProperties) if (configProperties.imports) { @@ -55,13 +78,7 @@ class SingleTestGenerator { addJsonPathRelatedImports(clazz) - Map contracts = listOfFiles.collectEntries { - File stubsFile = it.path.toFile() - log.debug("Stub content from file [${stubsFile.text}]") - GroovyDsl stubContent = AccurestDslConverter.convert(stubsFile) - TestType testType = (stubContent.input || stubContent.outputMessage) ? TestType.MESSAGING : TestType.HTTP - return [(new ParsedDsl(it, stubContent, stubsFile)) : testType] - } + Map contracts = mapContractsToTheirTestTypes(listOfFiles) boolean conditionalImportsAdded = false contracts.each { ParsedDsl key, TestType value -> @@ -99,11 +116,21 @@ class SingleTestGenerator { return clazz.build() } + private Map mapContractsToTheirTestTypes(Collection listOfFiles) { + return listOfFiles.collectEntries { + File stubsFile = it.path.toFile() + log.debug("Stub content from file [${stubsFile.text}]") + org.springframework.cloud.contract.verifier.dsl.Contract stubContent = ContractVerifierDslConverter.convert(stubsFile) + TestType testType = (stubContent.input || stubContent.outputMessage) ? TestType.MESSAGING : TestType.HTTP + return [(new ParsedDsl(it, stubContent, stubsFile)): testType] + } + } + @Canonical @EqualsAndHashCode private static class ParsedDsl { - Contract contract - GroovyDsl groovyDsl + ContractMetadata contract + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl File stubsFile } @@ -111,7 +138,7 @@ class SingleTestGenerator { MESSAGING, HTTP } - private boolean isScenarioClass(Collection listOfFiles) { + private boolean isScenarioClass(Collection listOfFiles) { listOfFiles.find({ it.order != null }) != null } @@ -125,15 +152,15 @@ class SingleTestGenerator { } private ClassBuilder addMessagingRelatedEntries(ClassBuilder clazz) { - clazz.addField(['@Inject AccurestMessaging accurestMessaging', - 'AccurestObjectMapper accurestObjectMapper = new AccurestObjectMapper()' + clazz.addField(['@Inject ContractVerifierMessaging contractVerifierMessaging', + 'ContractVerifierObjectMapper contractVerifierObjectMapper = new ContractVerifierObjectMapper()' ]) clazz.addImport([ 'javax.inject.Inject', - 'io.codearte.accurest.messaging.AccurestObjectMapper', - 'io.codearte.accurest.messaging.AccurestMessage', - 'io.codearte.accurest.messaging.AccurestMessaging', + 'org.springframework.cloud.contract.verifier.messaging.ContractVerifierObjectMapper', + 'org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage', + 'org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging', ]) - clazz.addStaticImport('io.codearte.accurest.messaging.AccurestMessagingUtil.headers') + clazz.addStaticImport('org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessagingUtil.headers') } private static boolean jsonAssertPresent() { diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/builder/SpockMessagingMethodBodyBuilder.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/SpockMessagingMethodBodyBuilder.groovy similarity index 71% rename from accurest-core/src/main/groovy/io/codearte/accurest/builder/SpockMessagingMethodBodyBuilder.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/SpockMessagingMethodBodyBuilder.groovy index 0c9a0b5f83..7996f413f7 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/builder/SpockMessagingMethodBodyBuilder.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/SpockMessagingMethodBodyBuilder.groovy @@ -1,23 +1,39 @@ -package io.codearte.accurest.builder +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.builder import groovy.json.StringEscapeUtils import groovy.transform.PackageScope import groovy.transform.TypeChecked -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.dsl.internal.ExecutionProperty -import io.codearte.accurest.dsl.internal.Header -import io.codearte.accurest.dsl.internal.Input -import io.codearte.accurest.dsl.internal.NamedProperty +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.dsl.internal.ExecutionProperty +import org.springframework.cloud.contract.verifier.dsl.internal.Header +import org.springframework.cloud.contract.verifier.dsl.internal.Input +import org.springframework.cloud.contract.verifier.dsl.internal.NamedProperty import java.util.regex.Pattern /** - * @author Jakub Kubrynski + * @author Jakub Kubrynski, codearte.io */ @PackageScope @TypeChecked class SpockMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder { - SpockMessagingMethodBodyBuilder(GroovyDsl stubDefinition) { + SpockMessagingMethodBodyBuilder(Contract stubDefinition) { super(stubDefinition) } @@ -26,7 +42,7 @@ class SpockMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder { if (request.triggeredBy) { return request.triggeredBy.executionCommand } - return "accurestMessaging.send(inputMessage, '${request.messageFrom.serverValue}')" + return "contractVerifierMessaging.send(inputMessage, '${request.messageFrom.serverValue}')" } @Override @@ -62,7 +78,7 @@ class SpockMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder { @Override protected void validateResponseCodeBlock(BlockBuilder bb) { if (outputMessage) { - bb.addLine("""def response = accurestMessaging.receiveMessage('${outputMessage.sentTo.serverValue}')""") + bb.addLine("""def response = contractVerifierMessaging.receiveMessage('${outputMessage.sentTo.serverValue}')""") bb.addLine("""assert response != null""") } else { bb.addLine('noExceptionThrown()') @@ -71,14 +87,14 @@ class SpockMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder { @Override protected void validateResponseHeadersBlock(BlockBuilder bb) { - outputMessage.headers?.collect { Header header -> + outputMessage.headers?.executeForEachHeader { Header header -> processHeaderElement(bb, header.name, header.serverValue) } } @Override protected String getResponseAsString() { - return 'accurestObjectMapper.writeValueAsString(response.payload)' + return 'contractVerifierObjectMapper.writeValueAsString(response.payload)' } @Override @@ -113,7 +129,7 @@ class SpockMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder { @Override protected String getInputString() { - String request = 'def inputMessage = accurestMessaging.create(' + String request = 'def inputMessage = contractVerifierMessaging.create(' if (inputMessage.messageBody) { request = "${request}'''${bodyAsString}'''\n " } @@ -121,7 +137,7 @@ class SpockMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder { request = "${request},[\n" } def headers = [] - inputMessage.messageHeaders?.collect { Header header -> + inputMessage.messageHeaders?.executeForEachHeader { Header header -> headers << " ${getHeaderString(header)}" } request = "${request}${headers.join(',\n')}" diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/builder/SpockMethodRequestProcessingBodyBuilder.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/SpockMethodRequestProcessingBodyBuilder.groovy similarity index 66% rename from accurest-core/src/main/groovy/io/codearte/accurest/builder/SpockMethodRequestProcessingBodyBuilder.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/SpockMethodRequestProcessingBodyBuilder.groovy index c149c13bb8..cc60ff5055 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/builder/SpockMethodRequestProcessingBodyBuilder.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/builder/SpockMethodRequestProcessingBodyBuilder.groovy @@ -1,26 +1,46 @@ -package io.codearte.accurest.builder +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.builder import groovy.json.StringEscapeUtils import groovy.transform.PackageScope import groovy.transform.TypeChecked -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.dsl.internal.ExecutionProperty -import io.codearte.accurest.dsl.internal.Header -import io.codearte.accurest.dsl.internal.NamedProperty -import io.codearte.accurest.dsl.internal.Request +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.dsl.internal.Header +import org.springframework.cloud.contract.verifier.dsl.internal.NamedProperty +import org.springframework.cloud.contract.verifier.dsl.internal.Request +import org.springframework.cloud.contract.verifier.dsl.internal.ExecutionProperty import java.util.regex.Pattern -import static io.codearte.accurest.util.ContentUtils.getGroovyMultipartFileParameterContent +import static org.springframework.cloud.contract.verifier.util.ContentUtils.getGroovyMultipartFileParameterContent /** - * @author Jakub Kubrynski + * A {@link RequestProcessingMethodBodyBuilder} implementation that uses Spock + * + * @author Jakub Kubrynski, codearte.io + * + * @since 1.0.0 */ @PackageScope @TypeChecked abstract class SpockMethodRequestProcessingBodyBuilder extends RequestProcessingMethodBodyBuilder { - SpockMethodRequestProcessingBodyBuilder(GroovyDsl stubDefinition) { + SpockMethodRequestProcessingBodyBuilder(Contract stubDefinition) { super(stubDefinition) } diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/config/AccurestConfigProperties.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/config/ContractVerifierConfigProperties.groovy similarity index 59% rename from accurest-core/src/main/groovy/io/codearte/accurest/config/AccurestConfigProperties.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/config/ContractVerifierConfigProperties.groovy index 53567ed1a2..58b81803a4 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/config/AccurestConfigProperties.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/config/ContractVerifierConfigProperties.groovy @@ -1,8 +1,29 @@ -package io.codearte.accurest.config -/** - * @author Jakub Kubrynski +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ -class AccurestConfigProperties { + +package org.springframework.cloud.contract.verifier.config + +/** + * Represents Contract Verifier configuration properties + * + * @author Jakub Kubrynski, codearte.io + * + * @since 1.0.0 + */ +class ContractVerifierConfigProperties { /** * For which unit test library tests should be generated @@ -34,18 +55,13 @@ class AccurestConfigProperties { */ String ruleClassForTests - /** - * Which version of JSON Assert (com.toomuchcoding.jsonassert:jsonassert) to use - */ - String jsonAssertVersion = "+" - /** * Patterns that should not be taken into account for processing */ List excludedFiles = [] /** - * Patterns for which Accurest should generate @Ignored tests + * Patterns for which generated tests should be @Ignored */ List ignoredFiles = [] diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/config/TestFramework.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/config/TestFramework.groovy similarity index 66% rename from accurest-core/src/main/groovy/io/codearte/accurest/config/TestFramework.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/config/TestFramework.groovy index 42d420ee7b..8b5f14e707 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/config/TestFramework.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/config/TestFramework.groovy @@ -1,7 +1,27 @@ -package io.codearte.accurest.config +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.config /** - * @author Jakub Kubrynski + * Contains main building blocks for a test class for the given framework + * + * @author Jakub Kubrynski, codearte.io + * + * @since 1.0.0 */ enum TestFramework { JUNIT("public ", "public void ", ";", ".java", "Test", "org.junit.Ignore", ["org.junit.FixMethodOrder", "org.junit.runners.MethodSorters"], "@FixMethodOrder(MethodSorters.NAME_ASCENDING)"), diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/config/TestMode.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/config/TestMode.groovy new file mode 100644 index 0000000000..a6df25c9e3 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/config/TestMode.groovy @@ -0,0 +1,41 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.config + +/** + * Provides different testing modes + * + * @author Jakub Kubrynski, codearte.io + * + * @since 1.0.0 + */ +enum TestMode { + /** + * Uses Spring's MockMvc + */ + MOCKMVC, + + /** + * Uses direct HTTP invocations + */ + EXPLICIT, + + /** + * Uses JAX-RS client + */ + JAXRSCLIENT +} \ No newline at end of file diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/Contract.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/Contract.groovy new file mode 100644 index 0000000000..57ccd03dea --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/Contract.groovy @@ -0,0 +1,93 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl + +import groovy.transform.EqualsAndHashCode +import groovy.transform.ToString +import groovy.transform.TypeChecked +import org.springframework.cloud.contract.verifier.dsl.internal.Input +import org.springframework.cloud.contract.verifier.dsl.internal.OutputMessage +import org.springframework.cloud.contract.verifier.dsl.internal.Request +import org.springframework.cloud.contract.verifier.dsl.internal.Response + +/** + * The point of entry to the DSL + * + * @since 1.0.0 + */ +@TypeChecked +@EqualsAndHashCode +@ToString(includeFields = true, includePackage = false, includeNames = true) +class Contract { + + Integer priority + Request request + Response response + String label + String description + Input input + OutputMessage outputMessage + + protected Contract() {} + + /** + * Factory method to create the DSL + */ + static Contract make(Closure closure) { + Contract dsl = new Contract() + closure.delegate = dsl + closure() + return dsl + } + + void priority(int priority) { + this.priority = priority + } + + void label(String label) { + this.label = label + } + + void description(String description) { + this.description = description + } + + void request(@DelegatesTo(Request) Closure closure) { + this.request = new Request() + closure.delegate = request + closure() + } + + void response(@DelegatesTo(Response) Closure closure) { + this.response = new Response() + closure.delegate = response + closure() + } + + void input(@DelegatesTo(Input) Closure closure) { + this.input = new Input() + closure.delegate = input + closure() + } + + void outputMessage(@DelegatesTo(OutputMessage) Closure closure) { + this.outputMessage = new OutputMessage() + closure.delegate = outputMessage + closure() + } + +} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Body.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Body.groovy similarity index 59% rename from accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Body.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Body.groovy index df799d87f8..07051bd494 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Body.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Body.groovy @@ -1,9 +1,30 @@ -package io.codearte.accurest.dsl.internal +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal import groovy.transform.CompileStatic import groovy.transform.EqualsAndHashCode import groovy.transform.ToString +/** + * Represents a body of a request / response or a message + * + * @since 1.0.0 + */ @ToString(includePackage = false, includeFields = true, includeNames = true) @EqualsAndHashCode(includeFields = true) @CompileStatic diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/ClientDslProperty.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/ClientDslProperty.groovy new file mode 100644 index 0000000000..4e0a7aad8e --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/ClientDslProperty.groovy @@ -0,0 +1,32 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal + +import groovy.transform.CompileStatic + +/** + * Represents a client side {@link DslProperty} + * + * @since 1.0.0 + */ +@CompileStatic +class ClientDslProperty extends DslProperty { + + ClientDslProperty(Object singleValue) { + super(singleValue) + } +} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Common.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Common.groovy similarity index 83% rename from accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Common.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Common.groovy index a6d86e080b..f167521fa4 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Common.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Common.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.dsl.internal +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal import groovy.transform.PackageScope import groovy.transform.TypeChecked @@ -6,8 +22,12 @@ import groovy.transform.TypeChecked import java.util.regex.Pattern /** + * Contains useful common methods for the DSL. + * * @TypeChecked instead of @CompileStatic due to usage of double dispatch. * Double dispatch doesn't work if you're using @CompileStatic + * + * @since 1.0.0 */ @TypeChecked @PackageScope diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/DslProperty.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/DslProperty.groovy new file mode 100644 index 0000000000..b7bea9e3fb --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/DslProperty.groovy @@ -0,0 +1,45 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal + +import groovy.transform.CompileStatic +import groovy.transform.EqualsAndHashCode +import groovy.transform.ToString + +/** + * Represents an element of a DSL that can contain client or sever side values + * + * @since 1.0.0 + */ +@CompileStatic +@EqualsAndHashCode(includeFields = true) +@ToString(includePackage = false, includeNames = true) +class DslProperty { + + final T clientValue + final T serverValue + + DslProperty(T clientValue, T serverValue) { + this.clientValue = clientValue + this.serverValue = serverValue + } + + DslProperty(T singleValue) { + this.clientValue = singleValue + this.serverValue = singleValue + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/ExecutionProperty.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/ExecutionProperty.groovy new file mode 100644 index 0000000000..8948cccf0e --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/ExecutionProperty.groovy @@ -0,0 +1,45 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal + +import groovy.transform.CompileStatic + +/** + * Represents a property that will become an executable method in the + * generated tests + * + * @since 1.0.0 + */ +@CompileStatic +class ExecutionProperty { + + private static final String PLACEHOLDER_VALUE = '\\$it' + + final String executionCommand + + ExecutionProperty(String executionCommand) { + this.executionCommand = executionCommand + } + + /** + * Inserts the provided code as a parameter to the method and returns + * the code that represents that method execution + */ + String insertValue(String valueToInsert) { + return executionCommand.replaceAll(PLACEHOLDER_VALUE, valueToInsert) + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Header.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Header.groovy new file mode 100644 index 0000000000..3ab86a08b6 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Header.groovy @@ -0,0 +1,44 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal +import groovy.transform.CompileStatic +import groovy.transform.EqualsAndHashCode +import groovy.transform.ToString + +/** + * Represents a header of a request / response or a message + * + * @since 1.0.0 + */ +@EqualsAndHashCode(includeFields = true) +@ToString(includePackage = false, includeFields = true, ignoreNulls = true, includeNames = true) +@CompileStatic +class Header extends DslProperty { + + String name + + Header(String name, DslProperty dslProperty) { + super(dslProperty.clientValue, dslProperty.serverValue) + this.name = name + } + + Header(String name, Object value) { + super(value) + this.name = name + } + +} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Headers.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Headers.groovy similarity index 54% rename from accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Headers.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Headers.groovy index 98e7bed9bc..03af32fbe9 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Headers.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Headers.groovy @@ -1,9 +1,30 @@ -package io.codearte.accurest.dsl.internal +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal import groovy.transform.EqualsAndHashCode import groovy.transform.ToString import groovy.transform.TypeChecked +/** + * Represents a set of headers of a request / response or a message + * + * @since 1.0.0 + */ @EqualsAndHashCode(includeFields = true) @ToString(includePackage = false, includeFields = true, ignoreNulls = true, includeNames = true) @TypeChecked @@ -20,12 +41,16 @@ class Headers { entries << new Header(headerKey, headerValue) } - void collect(Closure closure) { + void executeForEachHeader(Closure closure) { entries?.each { header -> closure(header) } } + /** + * Converts the headers into their stub side representations and returns as + * a map of String key => Object value. + */ Map asStubSideMap() { def acc = [:].withDefault { [] as Collection } return entries.inject(acc as Map) { Map map, Header header -> diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Input.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Input.groovy similarity index 58% rename from accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Input.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Input.groovy index 0b833c4090..34a16d1579 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Input.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Input.groovy @@ -1,10 +1,32 @@ -package io.codearte.accurest.dsl.internal +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal import groovy.transform.CompileStatic import groovy.transform.EqualsAndHashCode import groovy.transform.ToString import groovy.transform.TypeChecked +/** + * Represents an input for messaging. The input can be a message or some + * action inside the application. + * + * @since 1.0.0 + */ @TypeChecked @EqualsAndHashCode @ToString(includePackage = false, includeNames = true) @@ -24,22 +46,37 @@ 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 + */ void messageFrom(String messageFrom) { this.messageFrom = new DslProperty<>(messageFrom) } + /** + * Name of a destination from which message would come to trigger action in the system + */ void messageFrom(DslProperty messageFrom) { this.messageFrom = messageFrom } + /** + * Function that needs to be executed to trigger action in the system + */ void triggeredBy(String triggeredBy) { this.triggeredBy = new ExecutionProperty(triggeredBy) } @@ -54,7 +91,7 @@ class Input extends Common { closure() } - public static class BodyType extends DslProperty { + static class BodyType extends DslProperty { BodyType(Object clientValue, Object serverValue) { super(clientValue, serverValue) @@ -70,6 +107,7 @@ class Input extends Common { } } + @CompileStatic @EqualsAndHashCode @ToString(includePackage = false) diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/JSONCompareMode.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/JSONCompareMode.groovy new file mode 100644 index 0000000000..8fb8d92738 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/JSONCompareMode.groovy @@ -0,0 +1,26 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal + +/** + * Represents JSON comparison modes + * + * @since 1.0.0 + */ +enum JSONCompareMode { + STRICT, LENIENT, NON_EXTENSIBLE, STRICT_ORDER +} \ No newline at end of file diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/MatchingStrategy.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/MatchingStrategy.groovy similarity index 59% rename from accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/MatchingStrategy.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/MatchingStrategy.groovy index 191af8d7ee..f4d1ec0248 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/MatchingStrategy.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/MatchingStrategy.groovy @@ -1,9 +1,30 @@ -package io.codearte.accurest.dsl.internal +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal import groovy.transform.CompileStatic import groovy.transform.EqualsAndHashCode import groovy.transform.ToString; +/** + * Represents a matching strategy for a JSON + * + * @since 1.0.0 + */ @EqualsAndHashCode(includeFields = true) @ToString(includePackage = false, includeFields = true, ignoreNulls = true, includeNames = true) @CompileStatic @@ -33,7 +54,6 @@ class MatchingStrategy extends DslProperty { } enum Type { - EQUAL_TO("equalTo"), CONTAINS("containing"), MATCHING("matches"), NOT_MATCHING("doesNotMatch"), EQUAL_TO_JSON("equalToJson"), EQUAL_TO_XML("equalToXml"), ABSENT("absent") diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Multipart.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Multipart.groovy similarity index 66% rename from accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Multipart.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Multipart.groovy index 1ebc06e1e7..554afad2ae 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Multipart.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Multipart.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.dsl.internal +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal import groovy.transform.CompileStatic import groovy.transform.EqualsAndHashCode diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/NamedProperty.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/NamedProperty.groovy new file mode 100644 index 0000000000..6c1ca066c7 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/NamedProperty.groovy @@ -0,0 +1,48 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal + +import groovy.transform.CompileStatic +import groovy.transform.EqualsAndHashCode +import groovy.transform.ToString + +/** + * Represents a property that has name and content. Used together with + * multipart requests. + * + * @since 1.0.0 + */ +@ToString(includePackage = false, includeFields = true, includeNames = true) +@EqualsAndHashCode(includeFields = true) +@CompileStatic +class NamedProperty { + + private static final String NAME = 'name' + private static final String CONTENT = 'content' + + DslProperty name + DslProperty value + + NamedProperty(DslProperty name, DslProperty value) { + this.name = name + this.value = value + } + + NamedProperty(Map namedMap) { + this(namedMap?.get(NAME), namedMap?.get(CONTENT)) + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/OptionalProperty.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/OptionalProperty.groovy new file mode 100644 index 0000000000..d822cb043f --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/OptionalProperty.groovy @@ -0,0 +1,41 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal + +import groovy.transform.CompileStatic + +/** + * Represents a property that may or may not be there + * + * @since 1.0.0 + */ +@CompileStatic +class OptionalProperty { + final Object value + + OptionalProperty(Object value) { + this.value = value + } + + /** + * String version of a regular expression that wraps the provided value + * in an optional function + */ + String optionalPattern() { + return "($value)?" + } +} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/OutputMessage.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/OutputMessage.groovy similarity index 70% rename from accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/OutputMessage.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/OutputMessage.groovy index b173c6481c..0435ac5a76 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/OutputMessage.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/OutputMessage.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.dsl.internal +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal import groovy.transform.CompileStatic import groovy.transform.EqualsAndHashCode diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/QueryParameter.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/QueryParameter.groovy similarity index 50% rename from accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/QueryParameter.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/QueryParameter.groovy index c0ca01c97b..21e6aab67c 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/QueryParameter.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/QueryParameter.groovy @@ -1,11 +1,32 @@ -package io.codearte.accurest.dsl.internal +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal import groovy.transform.CompileStatic import groovy.transform.EqualsAndHashCode import groovy.transform.ToString -import static io.codearte.accurest.util.ValidateUtils.validateServerValueIsAvailable +import static org.springframework.cloud.contract.verifier.util.ValidateUtils.validateServerValueIsAvailable +/** + * Represents a single HTTP query parameter + * + * @since 1.0.0 + */ @EqualsAndHashCode(includeFields = true) @ToString(includePackage = false, includeFields = true, ignoreNulls = true, includeNames = true) @CompileStatic diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/QueryParameters.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/QueryParameters.groovy new file mode 100644 index 0000000000..dd69ff707a --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/QueryParameters.groovy @@ -0,0 +1,39 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal + +import groovy.transform.EqualsAndHashCode +import groovy.transform.ToString +import groovy.transform.TypeChecked + +@EqualsAndHashCode(includeFields = true) +@ToString(includePackage = false, includeFields = true, ignoreNulls = true, includeNames = true) +@TypeChecked +class QueryParameters { + + List parameters = [] + + void parameter(Map singleParameter) { + Map.Entry first = singleParameter.entrySet().first() + parameters << new QueryParameter(first?.key, first?.value) + } + + void parameter(String parameterName, Object parameterValue) { + parameters << new QueryParameter(parameterName, parameterValue) + } + +} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/RegexPatterns.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/RegexPatterns.groovy similarity index 69% rename from accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/RegexPatterns.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/RegexPatterns.groovy index 1c18226fd9..4315e7965c 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/RegexPatterns.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/RegexPatterns.groovy @@ -1,9 +1,30 @@ -package io.codearte.accurest.dsl.internal +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal import groovy.transform.CompileStatic import java.util.regex.Pattern +/** + * Contains most common regular expression patterns + * + * @since 1.0.0 + */ @CompileStatic class RegexPatterns { @@ -15,7 +36,6 @@ class RegexPatterns { private static final Pattern EMAIL = Pattern.compile('[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}'); private static final Pattern URL = Pattern.compile('((www\\.|(http|https|ftp|news|file)+\\:\\/\\/)[_.a-z0-9-]+\\.[a-z0-9\\/_:@=.+?,##%&~-]*[^.|\\\'|\\# |!|\\(|?|,| |>|<|;|\\)])') - String onlyAlphaUnicode() { return ONLY_ALPHA_UNICODE.pattern() } diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Request.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Request.groovy similarity index 83% rename from accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Request.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Request.groovy index 54d57e8c53..8e189a9b60 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Request.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Request.groovy @@ -1,9 +1,31 @@ -package io.codearte.accurest.dsl.internal +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal + import groovy.transform.CompileStatic import groovy.transform.EqualsAndHashCode import groovy.transform.ToString import groovy.transform.TypeChecked +/** + * Represents the request side of the HTTP communication + * + * @since 1.0.0 + */ @TypeChecked @EqualsAndHashCode @ToString(includePackage = false, includeNames = true) diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Response.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Response.groovy similarity index 67% rename from accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Response.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Response.groovy index 9078add18f..44da4a5aa9 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Response.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Response.groovy @@ -1,10 +1,31 @@ -package io.codearte.accurest.dsl.internal +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal import groovy.transform.CompileStatic import groovy.transform.EqualsAndHashCode import groovy.transform.ToString import groovy.transform.TypeChecked +/** + * Represents the response side of the HTTP communication + * + * @since 1.0.0 + */ @TypeChecked @EqualsAndHashCode @ToString(includePackage = false, includeFields = true) @@ -55,7 +76,7 @@ class Response extends Common { this.delay = toDslProperty(timeInMilliseconds) } - public void async() { + void async() { this.async = true } diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/ServerDslProperty.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/ServerDslProperty.groovy new file mode 100644 index 0000000000..3f2cf0e59e --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/ServerDslProperty.groovy @@ -0,0 +1,36 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal + +import groovy.transform.CompileStatic +import groovy.transform.EqualsAndHashCode +import groovy.transform.ToString + +/** + * Represents a server side {@link DslProperty} + * + * @since 1.0.0 + */ +@CompileStatic +@EqualsAndHashCode(includeFields = true) +@ToString(includePackage = false) +class ServerDslProperty extends DslProperty { + + ServerDslProperty(Object singleValue) { + super(singleValue) + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Url.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Url.groovy new file mode 100644 index 0000000000..8c5b3e8a0f --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/Url.groovy @@ -0,0 +1,53 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal + +import groovy.transform.CompileStatic +import groovy.transform.EqualsAndHashCode +import groovy.transform.ToString + +import static org.springframework.cloud.contract.verifier.util.ValidateUtils.validateServerValueIsAvailable + +/** + * Represents a URL that may contain query parameters + * + * @since 1.0.0 + */ +@ToString(includePackage = false, includeFields = true, includeNames = true) +@EqualsAndHashCode(includeFields = true) +@CompileStatic +class Url extends DslProperty { + + QueryParameters queryParameters + + Url(DslProperty prop) { + super(prop.clientValue, prop.serverValue) + validateServerValueIsAvailable(prop.serverValue, "Url") + } + + Url(Object url) { + super(url) + validateServerValueIsAvailable(url, "Url") + } + + void queryParameters(@DelegatesTo(QueryParameters) Closure closure) { + this.queryParameters = new QueryParameters() + closure.delegate = queryParameters + closure() + } + +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/UrlPath.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/UrlPath.groovy new file mode 100644 index 0000000000..62a8d8c60e --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/internal/UrlPath.groovy @@ -0,0 +1,41 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal + +import groovy.transform.CompileStatic +import groovy.transform.EqualsAndHashCode +import groovy.transform.ToString + +/** + * Represents a url path + * + * @since 1.0.0 + */ +@ToString(includePackage = false, includeFields = true, includeNames = true) +@EqualsAndHashCode(includeFields = true) +@CompileStatic +class UrlPath extends Url { + + UrlPath(String path) { + super(path) + } + + UrlPath(DslProperty path) { + super(path) + } + +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/wiremock/BaseWireMockStubStrategy.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/wiremock/BaseWireMockStubStrategy.groovy new file mode 100755 index 0000000000..914c705bb6 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/wiremock/BaseWireMockStubStrategy.groovy @@ -0,0 +1,126 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.wiremock + +import groovy.json.JsonBuilder +import groovy.transform.PackageScope +import groovy.transform.TypeChecked +import org.springframework.cloud.contract.verifier.dsl.internal.Headers +import org.springframework.cloud.contract.verifier.util.MapConverter +import org.springframework.cloud.contract.verifier.dsl.internal.DslProperty +import org.springframework.cloud.contract.verifier.util.ContentType +import org.springframework.cloud.contract.verifier.util.ContentUtils + +import static ContentUtils.extractValue +import static MapConverter.transformValues + +/** + * Common abstraction over WireMock Request / Response conversion implementations + * + * Do not change to {@code @CompileStatic} since it's using double dispatch. + * + * @since 1.0.0 + */ +@TypeChecked +@PackageScope +abstract class BaseWireMockStubStrategy { + + /** + * Returns the stub side values from the object + */ + protected getStubSideValue(Object object) { + return MapConverter.getStubSideValues(object) + } + + private static Closure transform = { + it instanceof DslProperty ? transformValues(it.clientValue, transform) : it + } + + /** + * For the given {@link org.springframework.cloud.contract.verifier.util.ContentType} returns the String version of the body + */ + String parseBody(Object value, ContentType contentType) { + return parseBody(value.toString(), contentType) + } + + /** + * For the given {@link ContentType} returns the Boolean version of the body + */ + Boolean parseBody(Boolean value, ContentType contentType) { + return value + } + + /** + * For the given {@link ContentType} returns the String version of the body + */ + String parseBody(Map map, ContentType contentType) { + def transformedMap = MapConverter.getStubSideValues(map) + return parseBody(toJson(transformedMap), contentType) + } + + /** + * For the given {@link ContentType} returns the String version of the body + */ + String parseBody(List list, ContentType contentType) { + List result = [] + list.each { + if (it instanceof Map) { + result += MapConverter.getStubSideValues(it) + } else { + result += parseBody(it, contentType) + } + } + return parseBody(toJson(result), contentType) + } + + /** + * For the given {@link ContentType} returns the String version of the body + */ + String parseBody(GString value, ContentType contentType) { + Object processedValue = extractValue(value, contentType, { DslProperty dslProperty -> dslProperty.clientValue }) + if (processedValue instanceof GString) { + return parseBody(processedValue.toString(), contentType) + } + return parseBody(processedValue, contentType) + } + + /** + * For the given {@link ContentType} returns the String version of the body + */ + String parseBody(String value, ContentType contentType) { + return value + } + + private static toJson(Object value) { + return new JsonBuilder(value).toString() + } + + /** + * Attempts to guess the {@link ContentType} from body and headers. Returns + * {@link ContentType#UNKNOWN} if it fails to guess. + */ + protected ContentType tryToGetContentType(Object body, Headers headers) { + ContentType contentType = ContentUtils.recognizeContentTypeFromHeader(headers) + if (contentType == ContentType.UNKNOWN) { + if (!body) { + return ContentType.UNKNOWN + } + return ContentUtils.getClientContentType(body) + } + return contentType + } +} \ No newline at end of file diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/WireMockRequestStubStrategy.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/wiremock/WireMockRequestStubStrategy.groovy similarity index 78% rename from accurest-core/src/main/groovy/io/codearte/accurest/dsl/WireMockRequestStubStrategy.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/wiremock/WireMockRequestStubStrategy.groovy index 07955fc699..0fad82f131 100755 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/WireMockRequestStubStrategy.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/wiremock/WireMockRequestStubStrategy.groovy @@ -1,4 +1,21 @@ -package io.codearte.accurest.dsl +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.wiremock + import com.github.tomakehurst.wiremock.http.RequestMethod import com.github.tomakehurst.wiremock.matching.RequestPattern import com.github.tomakehurst.wiremock.matching.ValuePattern @@ -6,36 +23,42 @@ import groovy.json.JsonOutput import groovy.transform.PackageScope import groovy.transform.TypeChecked import groovy.transform.TypeCheckingMode -import io.codearte.accurest.dsl.internal.Body -import io.codearte.accurest.dsl.internal.DslProperty -import io.codearte.accurest.dsl.internal.MatchingStrategy -import io.codearte.accurest.dsl.internal.NamedProperty -import io.codearte.accurest.dsl.internal.OptionalProperty -import io.codearte.accurest.dsl.internal.QueryParameters -import io.codearte.accurest.dsl.internal.RegexPatterns -import io.codearte.accurest.dsl.internal.Request -import io.codearte.accurest.util.ContentType -import io.codearte.accurest.util.ContentUtils -import io.codearte.accurest.util.JsonPaths -import io.codearte.accurest.util.JsonToJsonPathsConverter -import io.codearte.accurest.util.MapConverter +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.dsl.internal.Body +import org.springframework.cloud.contract.verifier.dsl.internal.NamedProperty +import org.springframework.cloud.contract.verifier.dsl.internal.QueryParameters +import org.springframework.cloud.contract.verifier.util.ContentUtils +import org.springframework.cloud.contract.verifier.util.JsonPaths +import org.springframework.cloud.contract.verifier.util.MapConverter +import org.springframework.cloud.contract.verifier.dsl.internal.DslProperty +import org.springframework.cloud.contract.verifier.dsl.internal.OptionalProperty +import org.springframework.cloud.contract.verifier.dsl.internal.RegexPatterns +import org.springframework.cloud.contract.verifier.dsl.internal.Request +import org.springframework.cloud.contract.verifier.util.JsonToJsonPathsConverter +import org.springframework.cloud.contract.verifier.dsl.internal.MatchingStrategy +import org.springframework.cloud.contract.verifier.util.ContentType import java.util.regex.Pattern -import static io.codearte.accurest.util.ContentUtils.getEqualsTypeFromContentType -import static io.codearte.accurest.util.ContentUtils.recognizeContentTypeFromContent -import static io.codearte.accurest.util.ContentUtils.recognizeContentTypeFromHeader -import static io.codearte.accurest.util.ContentUtils.recognizeContentTypeFromMatchingStrategy -import static io.codearte.accurest.util.RegexpBuilders.buildGStringRegexpForStubSide -import static io.codearte.accurest.util.RegexpBuilders.buildJSONRegexpMatch +import static ContentUtils.getEqualsTypeFromContentType +import static ContentUtils.recognizeContentTypeFromContent +import static ContentUtils.recognizeContentTypeFromHeader +import static ContentUtils.recognizeContentTypeFromMatchingStrategy +import static org.springframework.cloud.contract.verifier.util.RegexpBuilders.buildGStringRegexpForStubSide +import static org.springframework.cloud.contract.verifier.util.RegexpBuilders.buildJSONRegexpMatch +/** + * Converts a {@link Request} into {@link RequestPattern} + * + * @since 1.0.0 + */ @TypeChecked @PackageScope class WireMockRequestStubStrategy extends BaseWireMockStubStrategy { private final Request request - WireMockRequestStubStrategy(GroovyDsl groovyDsl) { + WireMockRequestStubStrategy(Contract groovyDsl) { this.request = groovyDsl.request } diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/WireMockResponseStubStrategy.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/wiremock/WireMockResponseStubStrategy.groovy similarity index 54% rename from accurest-core/src/main/groovy/io/codearte/accurest/dsl/WireMockResponseStubStrategy.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/wiremock/WireMockResponseStubStrategy.groovy index 1d19dfcb38..96eda8c33b 100755 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/WireMockResponseStubStrategy.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/wiremock/WireMockResponseStubStrategy.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.dsl +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.wiremock import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder import com.github.tomakehurst.wiremock.http.HttpHeader @@ -6,23 +22,27 @@ import com.github.tomakehurst.wiremock.http.HttpHeaders import com.github.tomakehurst.wiremock.http.ResponseDefinition import groovy.transform.PackageScope import groovy.transform.TypeChecked -import io.codearte.accurest.dsl.internal.Request -import io.codearte.accurest.dsl.internal.Response -import io.codearte.accurest.util.ContentType +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.dsl.internal.Request +import org.springframework.cloud.contract.verifier.dsl.internal.Response +import org.springframework.cloud.contract.verifier.util.ContentType -import static io.codearte.accurest.util.ContentUtils.recognizeContentTypeFromContent -import static io.codearte.accurest.util.ContentUtils.recognizeContentTypeFromHeader +import static org.springframework.cloud.contract.verifier.util.ContentUtils.recognizeContentTypeFromContent +import static org.springframework.cloud.contract.verifier.util.ContentUtils.recognizeContentTypeFromHeader +/** + * Converts a {@link Request} into {@link ResponseDefinition} + * + * @since 1.0.0 + */ @TypeChecked @PackageScope class WireMockResponseStubStrategy extends BaseWireMockStubStrategy { - private final Request request private final Response response - WireMockResponseStubStrategy(GroovyDsl groovyDsl) { + WireMockResponseStubStrategy(Contract groovyDsl) { this.response = groovyDsl.response - this.request = groovyDsl.request } @PackageScope @@ -58,6 +78,7 @@ class WireMockResponseStubStrategy extends BaseWireMockStubStrategy { } private void appendResponseDelayTime(ResponseDefinitionBuilder builder) { + // TODO: Add a missing test for this if (response.delay) { builder.withFixedDelay(response.delay.clientValue as Integer) } diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/WireMockStubStrategy.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/wiremock/WireMockStubStrategy.groovy similarity index 60% rename from accurest-core/src/main/groovy/io/codearte/accurest/dsl/WireMockStubStrategy.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/wiremock/WireMockStubStrategy.groovy index 2f1cb8b0f4..e40850cbe4 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/WireMockStubStrategy.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/dsl/wiremock/WireMockStubStrategy.groovy @@ -1,12 +1,33 @@ -package io.codearte.accurest.dsl +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.wiremock import com.github.tomakehurst.wiremock.http.ResponseDefinition import com.github.tomakehurst.wiremock.matching.RequestPattern import com.github.tomakehurst.wiremock.stubbing.StubMapping import groovy.transform.CompileDynamic import groovy.transform.CompileStatic -import io.codearte.accurest.file.Contract +import org.springframework.cloud.contract.verifier.file.ContractMetadata +/** + * Converts a {@link ContractMetadata} into a WireMock stub + * + * @since 1.0.0 + */ @CompileStatic class WireMockStubStrategy { @@ -15,10 +36,10 @@ class WireMockStubStrategy { private final WireMockRequestStubStrategy wireMockRequestStubStrategy private final WireMockResponseStubStrategy wireMockResponseStubStrategy private final Integer priority - private final Contract contract + private final ContractMetadata contract private final String rootName - WireMockStubStrategy(String rootName, Contract contract, GroovyDsl groovyDsl) { + WireMockStubStrategy(String rootName, ContractMetadata contract, org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl) { this.rootName = rootName this.contract = contract this.wireMockRequestStubStrategy = new WireMockRequestStubStrategy(groovyDsl) @@ -26,6 +47,9 @@ class WireMockStubStrategy { this.priority = groovyDsl.priority } + /** + * Converts {@link ContractMetadata} to String version of {@link StubMapping} + */ @CompileDynamic String toWireMockClientStub() { StubMapping stubMapping = new StubMapping() diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/file/ContractFileScanner.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/file/ContractFileScanner.groovy similarity index 58% rename from accurest-core/src/main/groovy/io/codearte/accurest/file/ContractFileScanner.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/file/ContractFileScanner.groovy index cc00799c08..7b7ad47618 100755 --- a/accurest-core/src/main/groovy/io/codearte/accurest/file/ContractFileScanner.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/file/ContractFileScanner.groovy @@ -1,7 +1,24 @@ -package io.codearte.accurest.file +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.file import com.google.common.collect.ArrayListMultimap import com.google.common.collect.ListMultimap +import groovy.transform.CompileStatic import org.apache.commons.io.FilenameUtils import org.apache.commons.lang3.SystemUtils @@ -12,8 +29,14 @@ import java.nio.file.PathMatcher import java.util.regex.Pattern /** - * @author Jakub Kubrynski + * Scans the provided file path for the DSLs. There's a possibility to provide + * inclusion and exclusion filters. + * + * @author Jakub Kubrynski, codearte.io + * + * @since 1.0.0 */ +@CompileStatic class ContractFileScanner { private static final String MATCH_PREFIX = "glob:" @@ -24,8 +47,8 @@ class ContractFileScanner { ContractFileScanner(File baseDir, Set excluded, Set ignored) { this.baseDir = baseDir - excludeMatchers = processPatterns(excluded) - ignoreMatchers = processPatterns(ignored) + excludeMatchers = processPatterns(excluded ?: [] as Set) + ignoreMatchers = processPatterns(ignored ?: [] as Set) } private Set processPatterns(Set patterns) { @@ -40,13 +63,16 @@ class ContractFileScanner { }) as Set } - ListMultimap findContracts() { - ListMultimap result = ArrayListMultimap.create() + /** + * Returns for a map of paths for which a list of matching contracts has been found + */ + ListMultimap findContracts() { + ListMultimap result = ArrayListMultimap.create() appendRecursively(baseDir, result) return result } - private void appendRecursively(File baseDir, ListMultimap result) { + private void appendRecursively(File baseDir, ListMultimap result) { File[] files = baseDir.listFiles() if (!files) { return; @@ -59,7 +85,7 @@ class ContractFileScanner { if (hasScenarioFilenamePattern(path)) { order = index } - result.put(file.parentFile.toPath(), new Contract(path, matchesPattern(file, ignoreMatchers), files.size(), order)) + result.put(file.parentFile.toPath(), new ContractMetadata(path, matchesPattern(file, ignoreMatchers), files.size(), order)) } else { appendRecursively(file, result) } @@ -71,7 +97,7 @@ class ContractFileScanner { return SCENARIO_STEP_FILENAME_PATTERN.matcher(path.fileName.toString()).matches() } - boolean matchesPattern(File file, Set excludeMatchers) { + private boolean matchesPattern(File file, Set excludeMatchers) { for (PathMatcher matcher : excludeMatchers) { if (matcher.matches(file.toPath())) { return true; diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/file/ContractMetadata.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/file/ContractMetadata.groovy new file mode 100644 index 0000000000..f201949740 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/file/ContractMetadata.groovy @@ -0,0 +1,53 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.file + +import groovy.transform.CompileStatic + +import java.nio.file.Path + +/** + * Contains metadata for a particular file with a DSL + * + * @author Jakub Kubrynski, codearte.io + * + * @since 1.0.0 + */ +@CompileStatic +class ContractMetadata { + final Path path; + final boolean ignored; + final int groupSize + final Integer order; + + ContractMetadata(Path path, boolean ignored, int groupSize, Integer order) { + this.groupSize = groupSize + this.path = path + this.ignored = ignored + this.order = order + } + + @Override + public String toString() { + return "ContractMetadata{" + + "fileName=" + path.fileName + + ", ignored=" + ignored + + ", groupSize=" + groupSize + + ", order=" + order + + '}'; + } +} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/builder/BodyAsString.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/BodyAsStringUtil.groovy similarity index 51% rename from accurest-core/src/main/groovy/io/codearte/accurest/builder/BodyAsString.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/BodyAsStringUtil.groovy index 7b03c5d126..44963c84b3 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/builder/BodyAsString.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/BodyAsStringUtil.groovy @@ -1,19 +1,45 @@ -package io.codearte.accurest.builder +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.util import groovy.json.JsonOutput import groovy.json.StringEscapeUtils -import io.codearte.accurest.dsl.internal.DslProperty -import io.codearte.accurest.util.MapConverter - -import static io.codearte.accurest.util.ContentUtils.extractValue +import groovy.transform.CompileStatic +import org.springframework.cloud.contract.verifier.dsl.internal.DslProperty +import static ContentUtils.extractValue /** - * Class that constructs a String from Body + * Class that constructs a String from a body. The body can be a GString + * or a map. * * @author Marcin Grzejszczak + * + * @since 1.0.0 */ -class BodyAsString { +@CompileStatic +class BodyAsStringUtil { + private BodyAsStringUtil() {} + + /** + * Returns the string representation of the body for the server side. + * That means that all the interpolations etc. will be resolved for the + * server side. + */ static String extractServerValueFrom(Object body) { Object bodyValue = extractServerValueFromBody(body) String json = new JsonOutput().toJson(bodyValue) @@ -21,6 +47,11 @@ class BodyAsString { return trimRepeatedQuotes(json) } + /** + * Returns the string representation of the body for the client side. + * That means that all the interpolations etc. will be resolved for the + * client side. + */ static String extractClientValueFrom(Object body) { Object bodyValue = extractClientValueFromBody(body); String json = new JsonOutput().toJson(bodyValue) diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/ContentType.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/ContentType.groovy new file mode 100644 index 0000000000..48887c3744 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/ContentType.groovy @@ -0,0 +1,36 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.util + +/** + * Represents content type + * + * @since 1.0.0 + */ +enum ContentType { + + JSON("application/json"), + XML("application/xml"), + UNKNOWN("application/octet-stream") + + final String mimeType + + ContentType(String mimeType) { + this.mimeType = mimeType + } + +} \ No newline at end of file diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/util/ContentUtils.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/ContentUtils.groovy similarity index 91% rename from accurest-core/src/main/groovy/io/codearte/accurest/util/ContentUtils.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/ContentUtils.groovy index b8608f767a..c2168f564d 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/util/ContentUtils.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/ContentUtils.groovy @@ -1,16 +1,32 @@ -package io.codearte.accurest.util +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.util import groovy.json.JsonException import groovy.json.JsonOutput import groovy.json.JsonSlurper import groovy.transform.TypeChecked import groovy.util.logging.Slf4j -import io.codearte.accurest.dsl.internal.DslProperty -import io.codearte.accurest.dsl.internal.ExecutionProperty -import io.codearte.accurest.dsl.internal.Headers -import io.codearte.accurest.dsl.internal.MatchingStrategy -import io.codearte.accurest.dsl.internal.NamedProperty -import io.codearte.accurest.dsl.internal.OptionalProperty +import org.springframework.cloud.contract.verifier.dsl.internal.Headers import org.codehaus.groovy.runtime.GStringImpl +import org.springframework.cloud.contract.verifier.dsl.internal.NamedProperty +import org.springframework.cloud.contract.verifier.dsl.internal.DslProperty +import org.springframework.cloud.contract.verifier.dsl.internal.ExecutionProperty +import org.springframework.cloud.contract.verifier.dsl.internal.MatchingStrategy +import org.springframework.cloud.contract.verifier.dsl.internal.OptionalProperty import java.util.regex.Matcher import java.util.regex.Pattern diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/ContractVerifierDslConverter.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/ContractVerifierDslConverter.groovy new file mode 100644 index 0000000000..31c29365f3 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/ContractVerifierDslConverter.groovy @@ -0,0 +1,44 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.util + +import groovy.transform.CompileStatic +import org.codehaus.groovy.control.CompilerConfiguration +import org.springframework.cloud.contract.verifier.dsl.Contract + +/** + * Converts a file or String into a {@link Contract} + * + * @author Marcin Grzejszczak + * + * @since 1.0.0 + */ +@CompileStatic +class ContractVerifierDslConverter { + + static Contract convert(String dsl) { + return groovyShell().evaluate(dsl) as Contract + } + + static Contract convert(File dsl) { + return groovyShell().evaluate(dsl) as Contract + } + + private static GroovyShell groovyShell() { + return new GroovyShell(ContractVerifierDslConverter.classLoader, new Binding(), new CompilerConfiguration(sourceEncoding: 'UTF-8')) + } +} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/util/DelegatingJsonVerifiable.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/DelegatingJsonVerifiable.java similarity index 91% rename from accurest-core/src/main/groovy/io/codearte/accurest/util/DelegatingJsonVerifiable.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/DelegatingJsonVerifiable.java index 0b927452cb..5dd82a7fb1 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/util/DelegatingJsonVerifiable.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/DelegatingJsonVerifiable.java @@ -1,4 +1,20 @@ -package io.codearte.accurest.util; +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.util; import java.util.LinkedList; import java.util.regex.Pattern; @@ -8,7 +24,12 @@ import com.toomuchcoding.jsonassert.JsonVerifiable; import static org.apache.commons.lang3.StringEscapeUtils.escapeJava; /** + * Implementation of the {@link MethodBufferingJsonVerifiable} that contains a list + * of String method commands that need to be executed to assert JSONs. + * * @author Marcin Grzejszczak + * + * @since 1.0.0 */ class DelegatingJsonVerifiable implements MethodBufferingJsonVerifiable { diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/FinishedDelegatingJsonVerifiable.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/FinishedDelegatingJsonVerifiable.java new file mode 100644 index 0000000000..000d6e75a4 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/FinishedDelegatingJsonVerifiable.java @@ -0,0 +1,38 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.util; + +import java.util.LinkedList; + +import com.toomuchcoding.jsonassert.JsonVerifiable; + +/** + * Helper class that represents a finished assertion of a JSON. + * Contains a list of all necessary method calls to assert the JSON. + * + * @author Marcin Grzejszczak + * + * @since 1.0.0 + */ +class FinishedDelegatingJsonVerifiable extends DelegatingJsonVerifiable { + + FinishedDelegatingJsonVerifiable(JsonVerifiable delegate, + LinkedList methodsBuffer) { + super(delegate, methodsBuffer); + } + +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/JsonPaths.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/JsonPaths.groovy new file mode 100644 index 0000000000..f737a53602 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/JsonPaths.groovy @@ -0,0 +1,29 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.util + +import groovy.transform.CompileStatic + +/** + * Represents a set of Strings - set of method calls to assert a JSON + * + * @since 1.0.0 + */ +@CompileStatic +class JsonPaths extends HashSet { +} + diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/util/JsonToJsonPathsConverter.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/JsonToJsonPathsConverter.groovy similarity index 90% rename from accurest-core/src/main/groovy/io/codearte/accurest/util/JsonToJsonPathsConverter.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/JsonToJsonPathsConverter.groovy index 131dde47e1..f4c35bb866 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/util/JsonToJsonPathsConverter.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/JsonToJsonPathsConverter.groovy @@ -1,10 +1,26 @@ -package io.codearte.accurest.util +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.util import com.toomuchcoding.jsonassert.JsonAssertion import groovy.json.JsonOutput import groovy.json.JsonSlurper -import io.codearte.accurest.dsl.internal.ExecutionProperty -import io.codearte.accurest.dsl.internal.OptionalProperty +import org.springframework.cloud.contract.verifier.dsl.internal.OptionalProperty +import org.springframework.cloud.contract.verifier.dsl.internal.ExecutionProperty import java.util.regex.Pattern @@ -21,7 +37,7 @@ class JsonToJsonPathsConverter { * In case of issues with size assertion just provide this property as system property * equal to "false" and then size assertion will be disabled */ - private static final String SIZE_ASSERTION_SYSTEM_PROP = "accurest.assert.size" + private static final String SIZE_ASSERTION_SYSTEM_PROP = "spring.cloud.contract.verifier.assert.size" private static final Boolean SERVER_SIDE = false private static final Boolean CLIENT_SIDE = true diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/util/MapConverter.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/MapConverter.groovy similarity index 59% rename from accurest-core/src/main/groovy/io/codearte/accurest/util/MapConverter.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/MapConverter.groovy index 4f21f880ff..ed83f76a3d 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/util/MapConverter.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/MapConverter.groovy @@ -1,22 +1,54 @@ -package io.codearte.accurest.util +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.util import groovy.json.JsonSlurper -import io.codearte.accurest.dsl.internal.DslProperty +import org.springframework.cloud.contract.verifier.dsl.internal.DslProperty /** + * Converts an object into either client or server side representation. + * Iterates over the structure of an object (depending on whether it's an + * iterable or a primitive type etc.), converts the {@link DslProperty} into their + * client / server representation and returns the result + * * @author Marcin Grzejszczak + * + * @since 1.0.0 */ class MapConverter { public static final boolean STUB_SIDE = true public static final boolean TEST_SIDE = false + /** + * Returns the object with client side values of {@link org.springframework.cloud.contract.verifier.dsl.internal.DslProperty} + */ static def transformToClientValues(def value) { return transformValues(value) { it instanceof DslProperty ? it.clientValue : it } } + /** + * Iterates over the structure of the object and executes the closure + * on each element of that structure. + * + * Returns the transformed structure + */ static def transformValues(def value, Closure closure) { if (value instanceof String && value) { try { @@ -35,6 +67,10 @@ class MapConverter { return transformValue(closure, value) } + /** + * Transforms a value with the given closure. Needs to be protected, otherwise + * method access exception will occur at runtime. + */ protected static Object transformValue(Closure closure, Object value) { return extractValue(value, { Object val-> Object newValue = closure(val) @@ -60,6 +96,10 @@ class MapConverter { } } + /** + * If {@code clientSide} is {@code true} returns the client side value for the + * provided object + */ static Object getClientOrServerSideValues(json, boolean clientSide) { return transformValues(json) { if (it instanceof DslProperty) { diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/MethodBuffering.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/MethodBuffering.java new file mode 100644 index 0000000000..12774b14bb --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/MethodBuffering.java @@ -0,0 +1,29 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.util; + +/** + * Contract for classes that buffer method executions + * + * @author Marcin Grzejszczak + * + * @since 1.0.0 + */ +public interface MethodBuffering { + + String method(); +} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/util/MethodBufferingJsonVerifiable.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/MethodBufferingJsonVerifiable.java similarity index 56% rename from accurest-core/src/main/groovy/io/codearte/accurest/util/MethodBufferingJsonVerifiable.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/MethodBufferingJsonVerifiable.java index df22b85bc8..746bf3a9a9 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/util/MethodBufferingJsonVerifiable.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/MethodBufferingJsonVerifiable.java @@ -1,9 +1,30 @@ -package io.codearte.accurest.util; +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.util; import com.toomuchcoding.jsonassert.JsonVerifiable; /** + * A wrapper over {@link JsonVerifiable} that allows to store the method + * name in order to print it out in the generated test + * * @author Marcin Grzejszczak + * + * @since 1.0.0 */ public interface MethodBufferingJsonVerifiable extends JsonVerifiable, MethodBuffering { diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/NamesUtil.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/NamesUtil.groovy new file mode 100644 index 0000000000..6957ed3d8d --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/NamesUtil.groovy @@ -0,0 +1,111 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.util + +/** + * A utility class that helps to convert names + * + * @author Jakub Kubrynski, codearte.io + * + * @since 1.0.0 + */ +class NamesUtil { + + /** + * Returns the first element before the last separator presence. + * Returns empty string if separator is not found. + */ + static String beforeLast(String string, String separator) { + if (string?.indexOf(separator) > -1) { + return string.substring(0, string.lastIndexOf(separator)) + } + return '' + } + + /** + * Returns the first element after the last separator presence + * Returns the provided string if separator is not found. + */ + static String afterLast(String string, String separator) { + if (string?.indexOf(separator) > -1) { + return string.substring(string.lastIndexOf(separator) + 1) + } + return string + } + + /** + * Returns the first element after the last dot presence + * Returns the provided string if separator is not found. + */ + static String afterLastDot(String string) { + return afterLast(string, '.') + } + + /** + * Converts a string into a camel case format + */ + static String camelCase(String className) { + if (!className) { + return className + } + String firstChar = className.charAt(0).toLowerCase() as String + return firstChar + className.substring(1) + } + + /** + * Capitalizes the provided string + */ + static String capitalize(String className) { + if (!className) { + return className + } + String firstChar = className.charAt(0).toUpperCase() as String + return firstChar + className.substring(1) + } + + /** + * Returns the whole string to the last present dot. + * Returns input string if there is no dot + */ + static String toLastDot(String string) { + if (string?.indexOf('.') > -1) { + return string.substring(0, string.lastIndexOf('.')) + } + return string + } + + /** + * Converts the Java package notation to a path format + */ + static String packageToDirectory(String packageName) { + return packageName.replace('.' as char, File.separatorChar) + } + + /** + * Converts the path format to a Java package notation + */ + static String directoryToPackage(String directory) { + return directory.replace(File.separator, '.') + } + + /** + * Converts illegal package characters to underscores + */ + static String convertIllegalPackageChars(String packageName) { + return packageName.replace('-', '_') + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/RegexpBuilders.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/RegexpBuilders.groovy new file mode 100644 index 0000000000..cb284679a5 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/RegexpBuilders.groovy @@ -0,0 +1,155 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.util + +import groovy.transform.TypeChecked +import org.codehaus.groovy.runtime.GStringImpl +import org.springframework.cloud.contract.verifier.dsl.internal.DslProperty + +import java.util.regex.Pattern + +import static ContentUtils.extractValue +import static org.apache.commons.lang3.StringEscapeUtils.escapeJson + +/** + * Useful utility methods to work with regular expresisons + * + * Do not change to {@code @CompileStatic} since it's using double dispatch. + * + * @since 1.0.0 + */ +@TypeChecked +class RegexpBuilders { + + /** + * Converts the {@link GString} passed values into their stub side String representations + */ + static String buildGStringRegexpForStubSide(GString gString) { + new GStringImpl( + gString.values.collect(this.&buildGStringRegexpForStubSide) as Object[], + gString.strings.collect(this.&escapeSpecialRegexChars) as String[] + ) + } + + /** + * Converts the {@link Pattern} passed values into their stub side String representations + */ + static String buildGStringRegexpForStubSide(Pattern pattern) { + return pattern.pattern() + } + + /** + * Converts the {@link org.springframework.cloud.contract.verifier.dsl.internal.DslProperty} passed values into their stub side String representations + */ + static String buildGStringRegexpForStubSide(DslProperty dslProperty) { + return buildGStringRegexpForStubSide(dslProperty.clientValue) + } + + /** + * Converts the {@link Object} passed values into their stub side String representations + */ + static String buildGStringRegexpForStubSide(Object o) { + return escapeSpecialRegexChars(o.toString()) + } + + /** + * Converts the {@link GString} passed values into their test side String representations + */ + static String buildGStringRegexpForTestSide(GString gString) { + new GStringImpl( + gString.values.collect(this.&buildGStringRegexpForTestSide) as Object[], + gString.strings.collect(this.&escapeSpecialRegexChars) as String[] + ) + } + + /** + * Converts the {@link Pattern} passed values into their test side String representations + */ + static String buildGStringRegexpForTestSide(Pattern pattern) { + return pattern.pattern() + } + + /** + * Converts the {@link DslProperty} passed values into their test side String representations + */ + static String buildGStringRegexpForTestSide(DslProperty dslProperty) { + return buildGStringRegexpForTestSide(dslProperty.clientValue) + } + + /** + * Converts the {@link Object} passed values into their test side String representations + */ + static String buildGStringRegexpForTestSide(Object o) { + return o.toString().replaceAll('\\\\', '\\\\\\\\') + } + + private final static Pattern SPECIAL_REGEX_CHARS = Pattern.compile('[{}()\\[\\].+*?^$\\\\|]') + + private static String escapeSpecialRegexChars(String str) { + return SPECIAL_REGEX_CHARS.matcher(str).replaceAll('\\\\\\\\$0') + } + + private final static String WS = /\s*/ + + static String buildJSONRegexpMatch(GString gString) { + return buildJSONRegexpMatch(extractValue(gString, ContentType.JSON, { DslProperty dslProperty -> dslProperty.clientValue })) + } + + static String buildJSONRegexpMatch(Map jsonMap) { + return WS + "\\{" + jsonMap.collect(this.&buildJSONRegexpMatch).join(",") + "\\}" + WS + } + + static String buildJSONRegexpMatch(List jsonList) { + return WS + "\\[" + jsonList.collect(this.&buildJSONRegexpMatch).join(",") + "\\]" + WS + } + + /** + * Converts the map into String representation of regular expressions + */ + static String buildJSONRegexpMatch(Map.Entry entry) { + return buildJSONRegexpMatchString(escapeJson(entry.key)) + ":" + buildJSONRegexpMatch(entry.value) + } + + /** + * Converts the object into String representation of regular expressions + */ + static String buildJSONRegexpMatch(Object value) { + return buildJSONRegexpMatchStringOptionalQuotes(escapeJson(value.toString())) + } + + /** + * Converts the pattern into String representation of regular expressions + */ + static String buildJSONRegexpMatch(Pattern pattern) { + return buildJSONRegexpMatchStringOptionalQuotes(pattern.pattern()) + } + + /** + * Converts the String into String representation of regular expressions + */ + static String buildJSONRegexpMatchString(String value) { + return WS + '"' + value + '"' + WS + } + + /** + * Converts the String into an optional String representation of regular expressions + */ + static String buildJSONRegexpMatchStringOptionalQuotes(String value) { + return WS + '"?' + value + '"?' + WS + } + +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/ShouldTraverse.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/ShouldTraverse.java new file mode 100644 index 0000000000..2fad0fcd6a --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/ShouldTraverse.java @@ -0,0 +1,33 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.util; + +/** + * Utility class that wraps an object that should be traversed + * when building a list of methods to execute in the generated test. + * + * @author Marcin Grzejszczak + * + * @since 1.0.0 + */ +class ShouldTraverse { + final Object value; + + ShouldTraverse(Object value) { + this.value = value; + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/ValidateUtils.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/ValidateUtils.groovy new file mode 100644 index 0000000000..98aebb1ca8 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/groovy/org/springframework/cloud/contract/verifier/util/ValidateUtils.groovy @@ -0,0 +1,69 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.util + +import groovy.transform.TypeChecked +import org.springframework.cloud.contract.verifier.dsl.internal.DslProperty +import org.springframework.cloud.contract.verifier.dsl.internal.MatchingStrategy + +import java.util.regex.Pattern + +import static org.springframework.cloud.contract.verifier.dsl.internal.MatchingStrategy.Type.ABSENT +import static org.springframework.cloud.contract.verifier.dsl.internal.MatchingStrategy.Type.EQUAL_TO + +/** + * Checks the validity of DSL entries. + * + * Do not change to {@code @CompileStatic} since it's using double dispatch. + * + * @since 1.0.0 + */ +@TypeChecked +class ValidateUtils { + + static Object validateServerValueIsAvailable(Object value) { + validateServerValueIsAvailable(value, "Server value") + return value + } + + static Object validateServerValueIsAvailable(Object value, String msg) { + validateServerValue(value, msg) + return value + } + + static void validateServerValue(Pattern pattern, String msg) { + throw new IllegalStateException("$msg can't be a pattern for the server side") + } + + static List ALLOWED_MATCHING_TYPES_ON_SERVER_SIDE = [EQUAL_TO, ABSENT] + + static void validateServerValue(MatchingStrategy matchingStrategy, String msg) { + if (!ALLOWED_MATCHING_TYPES_ON_SERVER_SIDE.contains(matchingStrategy.type)) { + throw new IllegalStateException("$msg can't be of a matching type: $matchingStrategy.type for the server side") + } + validateServerValue(matchingStrategy.serverValue, msg) + } + + static void validateServerValue(DslProperty value, String msg) { + validateServerValue(value.serverValue, msg) + } + + static void validateServerValue(Object value, String msg) { + // OK + } + +} diff --git a/accurest-core/src/main/resources/stubs/wiremocks/other/sample.json b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/resources/stubs/wiremocks/other/sample.json similarity index 100% rename from accurest-core/src/main/resources/stubs/wiremocks/other/sample.json rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/resources/stubs/wiremocks/other/sample.json diff --git a/accurest-core/src/main/resources/stubs/wiremocks/sample.json b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/resources/stubs/wiremocks/sample.json similarity index 100% rename from accurest-core/src/main/resources/stubs/wiremocks/sample.json rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/main/resources/stubs/wiremocks/sample.json diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/GeneratorScannerSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/GeneratorScannerSpec.groovy new file mode 100644 index 0000000000..85f8c84fd4 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/GeneratorScannerSpec.groovy @@ -0,0 +1,53 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier + +import org.springframework.cloud.contract.verifier.builder.SingleTestGenerator +import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties +import org.springframework.cloud.contract.verifier.config.TestFramework +import spock.lang.Specification + +class GeneratorScannerSpec extends Specification { + + private SingleTestGenerator classGenerator = Mock(SingleTestGenerator) + + def "should find all .json files and generate 6 classes for them"() { + given: + File resource = new File(this.getClass().getResource("/directory/with/stubs/stubsRepositoryIndicator").toURI()) + ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties() + properties.contractsDslDir = resource.parentFile + TestGenerator testGenerator = new TestGenerator(properties, classGenerator, Stub(FileSaver)) + when: + testGenerator.generateTestClasses("org.springframework.cloud.contract.verifier") + then: + 6 * classGenerator.buildClass(_, _, _) >> "qwerty" + } + + def "should create class with full package"() { + given: + ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(targetFramework: TestFramework.SPOCK) + properties.contractsDslDir = new File(this.getClass().getResource("/directory/with/stubs/package").toURI()) + TestGenerator testGenerator = new TestGenerator(properties, classGenerator, Stub(FileSaver)) + when: + testGenerator.generateTestClasses("org.springframework.cloud.contract.verifier") + then: + 1 * classGenerator.buildClass(_, 'exceptionsSpec', 'org.springframework.cloud.contract.verifier') >> "spec" + 1 * classGenerator.buildClass(_, 'exceptionsSpec', 'org.springframework.cloud.contract.verifier.v1') >> "spec1" + 1 * classGenerator.buildClass(_, 'exceptionsSpec', 'org.springframework.cloud.contract.verifier.v2') >> "spec2" + } + +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/MainTest.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/MainTest.groovy new file mode 100644 index 0000000000..261416ca7e --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/MainTest.groovy @@ -0,0 +1,32 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier + +import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties +import org.springframework.cloud.contract.verifier.config.TestFramework +import org.springframework.cloud.contract.verifier.config.TestMode + +class MainTest { + public static void main(String[] args) { + ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties( + contractsDslDir: new File('/some/path/dsl'), + generatedTestSourcesDir: new File('/tmp/contracts'), + targetFramework: TestFramework.SPOCK, testMode: TestMode.MOCKMVC, basePackageForTests: 'io.test', + staticImports: ['com.package.Test.*'], imports: ['org.package.Test'], excludedFiles: ["**/other"]) + println new TestGenerator(properties).generate() + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/builder/BookReturned.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/builder/BookReturned.groovy new file mode 100644 index 0000000000..c47554348a --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/builder/BookReturned.groovy @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.builder + +import com.fasterxml.jackson.annotation.JsonCreator +import groovy.transform.CompileStatic + +@CompileStatic +class BookReturned implements Serializable { + final String bookName + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + BookReturned(String bookName) { + this.bookName = bookName + } +} diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/builder/ContractHttpDocsSpec.groovy similarity index 83% rename from accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/builder/ContractHttpDocsSpec.groovy index d8610d92a9..462c623cc4 100644 --- a/accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/builder/ContractHttpDocsSpec.groovy @@ -1,6 +1,22 @@ -package io.codearte.accurest.builder +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import io.codearte.accurest.dsl.GroovyDsl +package org.springframework.cloud.contract.verifier.builder + +import org.springframework.cloud.contract.verifier.dsl.Contract import spock.lang.Specification /** * Tests used for the documentation @@ -9,9 +25,9 @@ import spock.lang.Specification */ class ContractHttpDocsSpec extends Specification { - GroovyDsl httpDsl = + Contract httpDsl = // tag::http_dsl[] - io.codearte.accurest.dsl.GroovyDsl.make { + Contract.make { // Definition of HTTP request part of the contract // (this can be a valid request or invalid depending // on type of contract being specified). @@ -33,9 +49,9 @@ class ContractHttpDocsSpec extends Specification { } // end::http_dsl[] - GroovyDsl request = + Contract request = // tag::request[] - io.codearte.accurest.dsl.GroovyDsl.make { + Contract.make { request { // HTTP request method (GET/POST/PUT/DELETE). method 'GET' @@ -50,9 +66,9 @@ class ContractHttpDocsSpec extends Specification { } // end::request[] - GroovyDsl url = + Contract url = // tag::url[] - io.codearte.accurest.dsl.GroovyDsl.make { + Contract.make { request { method 'GET' @@ -66,9 +82,9 @@ class ContractHttpDocsSpec extends Specification { } // end::url[] - GroovyDsl urlPaths = + Contract urlPaths = // tag::urlpath[] - io.codearte.accurest.dsl.GroovyDsl.make { + Contract.make { request { //... @@ -111,9 +127,9 @@ class ContractHttpDocsSpec extends Specification { } // end::urlpath[] - GroovyDsl headers = + Contract headers = // tag::headers[] - io.codearte.accurest.dsl.GroovyDsl.make { + Contract.make { request { //... @@ -131,9 +147,9 @@ class ContractHttpDocsSpec extends Specification { } // end::headers[] - GroovyDsl body = + Contract body = // tag::body[] - io.codearte.accurest.dsl.GroovyDsl.make { + Contract.make { request { //... @@ -148,9 +164,9 @@ class ContractHttpDocsSpec extends Specification { } // end::body[] - GroovyDsl bodyAsXml = + Contract bodyAsXml = // tag::bodyAsXml[] - io.codearte.accurest.dsl.GroovyDsl.make { + Contract.make { request { //... @@ -166,9 +182,9 @@ class ContractHttpDocsSpec extends Specification { } // end::bodyAsXml[] - GroovyDsl response = + Contract response = // tag::response[] - io.codearte.accurest.dsl.GroovyDsl.make { + Contract.make { request { //... } @@ -180,9 +196,9 @@ class ContractHttpDocsSpec extends Specification { } // end::response[] - GroovyDsl regex = + Contract regex = // tag::regex[] - io.codearte.accurest.dsl.GroovyDsl.make { + Contract.make { request { method('GET') url $(client(~/\/[0-9]{2}/), server('/12')) @@ -211,9 +227,9 @@ class ContractHttpDocsSpec extends Specification { } // end::regex[] - GroovyDsl optionals = + Contract optionals = // tag::optionals[] - io.codearte.accurest.dsl.GroovyDsl.make { + Contract.make { priority 1 request { method 'POST' @@ -266,9 +282,9 @@ class ContractHttpDocsSpec extends Specification { stripped(blockBuilder.toString()) == stripped(expectedTest) } - GroovyDsl method = + Contract method = // tag::method[] - io.codearte.accurest.dsl.GroovyDsl.make { + Contract.make { request { method 'PUT' url $(client(regex('^/api/[0-9]{2}$')), server('/api/12')) diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/builder/JaxRsClientMethodBuilderSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/builder/JaxRsClientMethodBuilderSpec.groovy similarity index 64% rename from accurest-core/src/test/groovy/io/codearte/accurest/builder/JaxRsClientMethodBuilderSpec.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/builder/JaxRsClientMethodBuilderSpec.groovy index 38a6a8b442..cf419bd745 100644 --- a/accurest-core/src/test/groovy/io/codearte/accurest/builder/JaxRsClientMethodBuilderSpec.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/builder/JaxRsClientMethodBuilderSpec.groovy @@ -1,9 +1,24 @@ -package io.codearte.accurest.builder +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.dsl.WireMockStubStrategy -import io.codearte.accurest.dsl.WireMockStubVerifier -import io.codearte.accurest.file.Contract +package org.springframework.cloud.contract.verifier.builder + +import org.springframework.cloud.contract.verifier.dsl.WireMockStubVerifier +import org.springframework.cloud.contract.verifier.file.ContractMetadata +import org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockStubStrategy import spock.lang.Issue import spock.lang.Specification @@ -11,7 +26,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub def "should generate assertions for simple response body with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract contractDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method "GET" url "test" @@ -35,14 +50,14 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub stubMappingIsValidWireMockStub(contractDsl) where: methodBuilderName | methodBuilder - "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } - "JaxRsClientJUnitMethodBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } + "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } + "JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } } @Issue("#187") def "should generate assertions for null and boolean values with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract contractDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method "GET" url "test" @@ -65,17 +80,17 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property2").isNull()""") blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property1").isEqualTo("true")""") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null), contractDsl).toWireMockClientStub()) where: methodBuilderName | methodBuilder - "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } - "JaxRsClientJUnitMethodBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } + "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } + "JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } } @Issue("#79") def "should generate assertions for simple response body constructed from map with a list with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract contractDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method "GET" url "test" @@ -101,17 +116,17 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub blockBuilder.toString().contains("""assertThatJson(parsedJson).array("property2").hasSize(2)""") blockBuilder.toString().contains("""assertThatJson(parsedJson).array("property2").contains("b").isEqualTo("sthElse")""") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null), contractDsl).toWireMockClientStub()) where: methodBuilderName | methodBuilder - "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } - "JaxRsClientJUnitMethodBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } + "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } + "JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } } @Issue("#82") def "should generate proper request when body constructed from map with a list with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract contractDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method "GET" url "test" @@ -132,15 +147,15 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub and: stubMappingIsValidWireMockStub(contractDsl) where: - methodBuilderName | methodBuilder | bodyString - "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | """entity('{\"items\":[\"HOP\"]}', 'application/json')""" - "JaxRsClientJUnitMethodBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | 'entity("{\\"items\\":[\\"HOP\\"]}", "application/json")' + methodBuilderName | methodBuilder | bodyString + "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | """entity('{\"items\":[\"HOP\"]}', 'application/json')""" + "JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | 'entity("{\\"items\\":[\\"HOP\\"]}", "application/json")' } @Issue("#88") def "should generate proper request when body constructed from GString with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract contractDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method "GET" url "test" @@ -161,14 +176,14 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub and: stubMappingIsValidWireMockStub(contractDsl) where: - methodBuilderName | methodBuilder | bodyString - "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | """entity('property1=VAL1', 'application/octet-stream')""" - "JaxRsClientJUnitMethodBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | 'entity("\\"property1=VAL1\\"", "application/octet-stream")' + methodBuilderName | methodBuilder | bodyString + "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | """entity('property1=VAL1', 'application/octet-stream')""" + "JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | 'entity("\\"property1=VAL1\\"", "application/octet-stream")' } def "should generate assertions for array in response body with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract contractDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method "GET" url "test" @@ -195,13 +210,13 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub stubMappingIsValidWireMockStub(contractDsl) where: methodBuilderName | methodBuilder - "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } - "JaxRsClientJUnitMethodBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } + "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } + "JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } } def "should generate assertions for array inside response body element with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract contractDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method "GET" url "test" @@ -227,13 +242,13 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub stubMappingIsValidWireMockStub(contractDsl) where: methodBuilderName | methodBuilder - "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } - "JaxRsClientJUnitMethodBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } + "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } + "JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } } def "should generate assertions for nested objects in response body with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract contractDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method "GET" url "test" @@ -259,13 +274,13 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub stubMappingIsValidWireMockStub(contractDsl) where: methodBuilderName | methodBuilder - "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } - "JaxRsClientJUnitMethodBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } + "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } + "JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } } def "should generate regex assertions for map objects in response body with #methodBodyName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract contractDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method "GET" url "test" @@ -297,13 +312,13 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub stubMappingIsValidWireMockStub(contractDsl) where: methodBuilderName | methodBuilder - "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } - "JaxRsClientJUnitMethodBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } + "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } + "JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } } def "should generate regex assertions for string objects in response body with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract contractDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method "GET" url "test" @@ -329,13 +344,13 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub stubMappingIsValidWireMockStub(contractDsl) where: methodBuilderName | methodBuilder - "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } - "JaxRsClientJUnitMethodBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } + "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } + "JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } } def "should ignore 'Accept' header and use 'request' method with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract contractDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method "GET" url "test" @@ -356,14 +371,14 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub and: stubMappingIsValidWireMockStub(contractDsl) where: - methodBuilderName | methodBuilder | requestString - "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | "request('text/plain')" - "JaxRsClientJUnitMethodBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | 'request("text/plain")' + methodBuilderName | methodBuilder | requestString + "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | "request('text/plain')" + "JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | 'request("text/plain")' } def "should ignore 'Content-Type' header and use 'entity' method with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract contractDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method "GET" url "test" @@ -389,14 +404,14 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub and: stubMappingIsValidWireMockStub(contractDsl) where: - methodBuilderName | methodBuilder | requestStrings - "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | ["""entity('', 'text/plain')""", """header('Timer', '123')"""] - "JaxRsClientJUnitMethodBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | ['entity("\\"\\"", "text/plain")', 'header("Timer", "123")'] + methodBuilderName | methodBuilder | requestStrings + "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | ["""entity('', 'text/plain')""", """header('Timer', '123')"""] + "JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | ['entity("\\"\\"", "text/plain")', 'header("Timer", "123")'] } def "should generate a call with an url path and query parameters with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract contractDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'GET' urlPath('/users') { @@ -443,15 +458,15 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub and: stubMappingIsValidWireMockStub(contractDsl) where: - methodBuilderName | methodBuilder | modifyStringIfRequired - "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | { String paramString -> paramString } - "JaxRsClientJUnitMethodBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | { String paramString -> paramString.replace("'", "\"") } + methodBuilderName | methodBuilder | modifyStringIfRequired + "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | { String paramString -> paramString } + "JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | { String paramString -> paramString.replace("'", "\"") } } @Issue('#169') def "should generate a call with an url path and query parameters with url containing a pattern with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract contractDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'GET' url($(stub(regex('/foo/[0-9]+')), test('/foo/123456'))) { @@ -498,14 +513,14 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub and: stubMappingIsValidWireMockStub(contractDsl) where: - methodBuilderName | methodBuilder | modifyStringIfRequired - "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | { String paramString -> paramString } - "JaxRsClientJUnitMethodBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | { String paramString -> paramString.replace("'", "\"") } + methodBuilderName | methodBuilder | modifyStringIfRequired + "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | { String paramString -> paramString } + "JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | { String paramString -> paramString.replace("'", "\"") } } def "should generate test for empty body with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract contractDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method('POST') url("/ws/payments") @@ -526,14 +541,14 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub and: stubMappingIsValidWireMockStub(contractDsl) where: - methodBuilderName | methodBuilder | bodyString - "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | "entity('', 'application/octet-stream')" - "JaxRsClientJUnitMethodBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | 'entity("\\"\\"", "application/octet-stream"' + methodBuilderName | methodBuilder | bodyString + "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | "entity('', 'application/octet-stream')" + "JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | 'entity("\\"\\"", "application/octet-stream"' } def "should generate test for String in response body with #methodBodyName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract contractDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method "POST" url "test" @@ -554,15 +569,15 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub and: stubMappingIsValidWireMockStub(contractDsl) where: - methodBuilderName | methodBuilder | bodyDefinitionString | bodyEvaluationString - "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | "String responseAsString = response.readEntity(String)" | 'responseBody == "test"' - "JaxRsClientJUnitMethodBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | 'Object responseBody = (responseAsString);' | 'assertThat(responseBody).isEqualTo("test");' + methodBuilderName | methodBuilder | bodyDefinitionString | bodyEvaluationString + "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | "String responseAsString = response.readEntity(String)" | 'responseBody == "test"' + "JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | 'Object responseBody = (responseAsString);' | 'assertThat(responseBody).isEqualTo("test");' } @Issue('#171') def "should generate test with uppercase method name with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract contractDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method "get" url "/v1/some_cool_requests/e86df6f693de4b35ae648464c5b0dc08" @@ -587,14 +602,14 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub and: stubMappingIsValidWireMockStub(contractDsl) where: - methodBuilderName | methodBuilder | methodString - "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | ".method('GET')" - "JaxRsClientJUnitMethodBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | 'method("GET")' + methodBuilderName | methodBuilder | methodString + "JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | ".method('GET')" + "JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.verifier.dsl.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | 'method("GET")' } def "should generate a call with an url path and query parameters with JUnit - we'll put it into docs"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract contractDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'GET' urlPath('/users') { diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MessagingMethodBodyBuilderSpec.groovy similarity index 71% rename from accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MessagingMethodBodyBuilderSpec.groovy index 22dba316f2..98e02596de 100644 --- a/accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MessagingMethodBodyBuilderSpec.groovy @@ -1,7 +1,22 @@ -package io.codearte.accurest.builder +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import io.codearte.accurest.dsl.Accurest -import io.codearte.accurest.dsl.GroovyDsl +package org.springframework.cloud.contract.verifier.builder + +import org.springframework.cloud.contract.verifier.dsl.Contract import spock.lang.Specification /** * @author Marcin Grzejszczak @@ -11,7 +26,7 @@ class MessagingMethodBodyBuilderSpec extends Specification { def "should work for triggered based messaging with Spock"() { given: // tag::trigger_method_dsl[] -def contractDsl = GroovyDsl.make { +def contractDsl = Contract.make { label 'some_label' input { triggeredBy('bookReturnedTriggered()') @@ -38,11 +53,11 @@ def contractDsl = GroovyDsl.make { bookReturnedTriggered() then: - def response = accurestMessaging.receiveMessage('activemq:output') + def response = contractVerifierMessaging.receiveMessage('activemq:output') assert response != null response.getHeader('BOOK-NAME') == 'foo' and: - DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload)) + DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.payload)) assertThatJson(parsedJson).field("bookName").isEqualTo("foo") ''' @@ -52,7 +67,7 @@ def contractDsl = GroovyDsl.make { def "should work for triggered based messaging with JUnit"() { given: - def contractDsl = GroovyDsl.make { + def contractDsl = Contract.make { label 'some_label' input { triggeredBy('bookReturnedTriggered()') @@ -78,11 +93,11 @@ def contractDsl = GroovyDsl.make { bookReturnedTriggered(); // then: - AccurestMessage response = accurestMessaging.receiveMessage("activemq:output"); + ContractVerifierMessage response = contractVerifierMessaging.receiveMessage("activemq:output"); assertThat(response).isNotNull(); assertThat(response.getHeader("BOOK-NAME")).isEqualTo("foo"); // and: - DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.getPayload())); + DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.getPayload())); assertThatJson(parsedJson).field("bookName").isEqualTo("foo"); ''' // end::trigger_method_junit_test[] @@ -92,7 +107,7 @@ def contractDsl = GroovyDsl.make { def "should generate tests triggered by a message for Spock"() { given: // tag::trigger_message_dsl[] -def contractDsl = GroovyDsl.make { +def contractDsl = Contract.make { label 'some_label' input { messageFrom('jms:input') @@ -124,20 +139,20 @@ def contractDsl = GroovyDsl.make { // tag::trigger_message_spock[] """\ given: - def inputMessage = accurestMessaging.create( + def inputMessage = contractVerifierMessaging.create( '''{"bookName":"foo"}''', ['sample': 'header'] ) when: - accurestMessaging.send(inputMessage, 'jms:input') + contractVerifierMessaging.send(inputMessage, 'jms:input') then: - def response = accurestMessaging.receiveMessage('jms:output') + def response = contractVerifierMessaging.receiveMessage('jms:output') assert response !- null response.getHeader('BOOK-NAME') == 'foo' and: - DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload)) + DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.payload)) assertThatJson(parsedJson).field("bookName").isEqualTo("foo") """ // end::trigger_message_spock[] @@ -146,7 +161,7 @@ and: def "should generate tests triggered by a message for JUnit"() { given: - def contractDsl = GroovyDsl.make { + def contractDsl = Contract.make { label 'some_label' input { messageFrom('jms:input') @@ -177,20 +192,20 @@ and: // tag::trigger_message_junit[] ''' // given: - AccurestMessage inputMessage = accurestMessaging.create( + ContractVerifierMessage inputMessage = contractVerifierMessaging.create( "{\\"bookName\\":\\"foo\\"}" , headers() .header("sample", "header")); // when: - accurestMessaging.send(inputMessage, "jms:input"); + contractVerifierMessaging.send(inputMessage, "jms:input"); // then: - AccurestMessage response = accurestMessaging.receiveMessage("jms:output"); + ContractVerifierMessage response = contractVerifierMessaging.receiveMessage("jms:output"); assertThat(response).isNotNull(); assertThat(response.getHeader("BOOK-NAME")).isEqualTo("foo"); // and: - DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.getPayload())); + DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.getPayload())); assertThatJson(parsedJson).field("bookName").isEqualTo("foo"); ''' // end::trigger_message_junit[] @@ -200,7 +215,7 @@ and: def "should generate tests without destination, triggered by a message"() { given: // tag::trigger_no_output_dsl[] -def contractDsl = GroovyDsl.make { +def contractDsl = Contract.make { label 'some_label' input { messageFrom('jms:delete') @@ -224,13 +239,13 @@ def contractDsl = GroovyDsl.make { // tag::trigger_no_output_spock[] ''' given: - def inputMessage = accurestMessaging.create( + def inputMessage = contractVerifierMessaging.create( \'\'\'{"bookName":"foo"}\'\'\', ['sample': 'header'] ) when: - accurestMessaging.send(inputMessage, 'jms:delete') + contractVerifierMessaging.send(inputMessage, 'jms:delete') then: noExceptionThrown() @@ -242,7 +257,7 @@ then: def "should generate tests without destination, triggered by a message for JUnit"() { given: - def contractDsl = GroovyDsl.make { + def contractDsl = Contract.make { label 'some_label' input { messageFrom('jms:delete') @@ -265,13 +280,13 @@ then: // tag::trigger_no_output_junit[] ''' // given: - AccurestMessage inputMessage = accurestMessaging.create( + ContractVerifierMessage inputMessage = contractVerifierMessaging.create( "{\\"bookName\\":\\"foo\\"}" , headers() .header("sample", "header")); // when: - accurestMessaging.send(inputMessage, "jms:delete"); + contractVerifierMessaging.send(inputMessage, "jms:delete"); // then: bookWasDeleted(); @@ -282,7 +297,7 @@ then: def "should generate tests without headers for JUnit"() { given: - def contractDsl = GroovyDsl.make { + def contractDsl = Contract.make { label 'some_label' input { messageFrom('jms:input') @@ -309,18 +324,18 @@ then: String expectedMsg = ''' // given: - AccurestMessage inputMessage = accurestMessaging.create( + ContractVerifierMessage inputMessage = contractVerifierMessaging.create( "{\\"bookName\\":\\"foo\\"}" , headers() .header("sample", "header")); // when: - accurestMessaging.send(inputMessage, "jms:input"); + contractVerifierMessaging.send(inputMessage, "jms:input"); // then: - AccurestMessage response = accurestMessaging.receiveMessage("jms:output"); + ContractVerifierMessage response = contractVerifierMessaging.receiveMessage("jms:output"); assertThat(response).isNotNull(); - DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.getPayload())); + DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.getPayload())); assertThatJson(parsedJson).field("bookName").isEqualTo("foo"); ''' stripped(test) == stripped(expectedMsg) @@ -328,7 +343,7 @@ then: def "should generate tests without headers for Spock"() { given: - def contractDsl = GroovyDsl.make { + def contractDsl = Contract.make { label 'some_label' input { messageFrom('jms:input') @@ -355,18 +370,18 @@ then: String expectedMsg = """ given: - def inputMessage = accurestMessaging.create('''{"bookName":"foo"}''' + def inputMessage = contractVerifierMessaging.create('''{"bookName":"foo"}''' ,[ 'sample': 'header' ]) when: - accurestMessaging.send(inputMessage, 'jms:input') + contractVerifierMessaging.send(inputMessage, 'jms:input') then: - def response = accurestMessaging.receiveMessage('jms:output') + def response = contractVerifierMessaging.receiveMessage('jms:output') assert response != null - DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload)) + DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.payload)) assertThatJson(parsedJson).field("bookName").isEqualTo("foo") """ stripped(test) == stripped(expectedMsg) @@ -380,7 +395,7 @@ then: given: def contractDsl = // tag::consumer_producer[] -Accurest.make { +Contract.make { label 'some_label' input { messageFrom value(consumer('jms:output'), producer('jms:input')) @@ -408,18 +423,18 @@ Accurest.make { String expectedMsg = ''' // given: - AccurestMessage inputMessage = accurestMessaging.create( + ContractVerifierMessage inputMessage = contractVerifierMessaging.create( "{\\"bookName\\":\\"foo\\"}" , headers() .header("sample", "header")); // when: - accurestMessaging.send(inputMessage, "jms:input"); + contractVerifierMessaging.send(inputMessage, "jms:input"); // then: - AccurestMessage response = accurestMessaging.receiveMessage("jms:output"); + ContractVerifierMessage response = contractVerifierMessaging.receiveMessage("jms:output"); assertThat(response).isNotNull(); - DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.getPayload())); + DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.getPayload())); assertThatJson(parsedJson).field("bookName").isEqualTo("foo"); ''' stripped(test) == stripped(expectedMsg) diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcMethodBodyBuilderSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcMethodBodyBuilderSpec.groovy similarity index 76% rename from accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcMethodBodyBuilderSpec.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcMethodBodyBuilderSpec.groovy index 538125006e..3b2e77c4b5 100644 --- a/accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcMethodBodyBuilderSpec.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcMethodBodyBuilderSpec.groovy @@ -1,20 +1,35 @@ -package io.codearte.accurest.builder +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import io.codearte.accurest.dsl.Accurest -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.dsl.WireMockStubVerifier +package org.springframework.cloud.contract.verifier.builder + +import org.springframework.cloud.contract.verifier.dsl.Contract +import org.springframework.cloud.contract.verifier.dsl.WireMockStubVerifier import spock.lang.Issue import spock.lang.Shared import spock.lang.Specification import java.util.regex.Pattern /** - * @author Jakub Kubrynski + * @author Jakub Kubrynski, codearte.io */ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStubVerifier { @Shared - GroovyDsl dslWithOptionalsInString = Accurest.make { + Contract dslWithOptionalsInString = Contract.make { priority 1 request { method 'POST' @@ -40,7 +55,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub } @Shared - GroovyDsl dslWithOptionals = GroovyDsl.make { + Contract dslWithOptionals = Contract.make { priority 1 request { method 'POST' @@ -79,7 +94,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub def "should generate assertions for simple response body with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method "GET" url "test" @@ -103,14 +118,14 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub stubMappingIsValidWireMockStub(contractDsl) where: methodBuilderName | methodBuilder - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } } @Issue("#187") def "should generate assertions for null and boolean values with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method "GET" url "test" @@ -136,14 +151,14 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub stubMappingIsValidWireMockStub(contractDsl) where: methodBuilderName | methodBuilder - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } } @Issue("#79") def "should generate assertions for simple response body constructed from map with a list with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method "GET" url "test" @@ -172,14 +187,14 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub stubMappingIsValidWireMockStub(contractDsl) where: methodBuilderName | methodBuilder - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } } @Issue("#82") def "should generate proper request when body constructed from map with a list #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method "GET" url "test" @@ -200,15 +215,15 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub and: stubMappingIsValidWireMockStub(contractDsl) where: - methodBuilderName | methodBuilder | bodyString - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | """.body('''{\"items\":[\"HOP\"]}''')""" - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '.body("{\\"items\\":[\\"HOP\\"]}")' + methodBuilderName | methodBuilder | bodyString + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | """.body('''{\"items\":[\"HOP\"]}''')""" + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '.body("{\\"items\\":[\\"HOP\\"]}")' } @Issue("#88") def "should generate proper request when body constructed from GString with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method "GET" url "test" @@ -229,15 +244,15 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub and: stubMappingIsValidWireMockStub(contractDsl) where: - methodBuilderName | methodBuilder | bodyString - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | """.body('''property1=VAL1''')""" - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '.body("\\"property1=VAL1\\"")' + methodBuilderName | methodBuilder | bodyString + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | """.body('''property1=VAL1''')""" + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '.body("\\"property1=VAL1\\"")' } @Issue("185") def "should generate assertions for a response body containing map with integers as keys with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method "GET" url "test" @@ -263,13 +278,13 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub stubMappingIsValidWireMockStub(contractDsl) where: methodBuilderName | methodBuilder - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } } def "should generate assertions for array in response body with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method "GET" url "test" @@ -296,13 +311,13 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub stubMappingIsValidWireMockStub(contractDsl) where: methodBuilderName | methodBuilder - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } } def "should generate assertions for array inside response body element with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method "GET" url "test" @@ -328,13 +343,13 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub stubMappingIsValidWireMockStub(contractDsl) where: methodBuilderName | methodBuilder - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } } def "should generate assertions for nested objects in response body with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method "GET" url "test" @@ -360,13 +375,13 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub stubMappingIsValidWireMockStub(contractDsl) where: methodBuilderName | methodBuilder - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } } def "should generate regex assertions for map objects in response body with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method "GET" url "test" @@ -396,13 +411,13 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub stubMappingIsValidWireMockStub(contractDsl) where: methodBuilderName | methodBuilder - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } } def "should generate regex assertions for string objects in response body with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method "GET" url "test" @@ -428,14 +443,14 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub stubMappingIsValidWireMockStub(contractDsl) where: methodBuilderName | methodBuilder - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } } @Issue(["#126", "#143"]) def "should generate escaped regex assertions for string objects in response body with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method "GET" url "test" @@ -460,13 +475,13 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub stubMappingIsValidWireMockStub(contractDsl) where: methodBuilderName | methodBuilder - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } } def "should generate a call with an url path and query parameters with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method 'GET' urlPath('/users') { @@ -507,14 +522,14 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub stubMappingIsValidWireMockStub(contractDsl) where: methodBuilderName | methodBuilder - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } } @Issue('#169') def "should generate a call with an url path and query parameters with url containing a pattern with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method 'GET' url($(stub(regex('/foo/[0-9]+')), test('/foo/123456'))) { @@ -555,13 +570,13 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub stubMappingIsValidWireMockStub(contractDsl) where: methodBuilderName | methodBuilder - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } } def "should generate test for empty body with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method('POST') url("/ws/payments") @@ -581,14 +596,14 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub and: stubMappingIsValidWireMockStub(contractDsl) where: - methodBuilderName | methodBuilder | bodyString - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | ".body('''''')" - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | ".body(\"\\\"\\\"\")" + methodBuilderName | methodBuilder | bodyString + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | ".body('''''')" + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | ".body(\"\\\"\\\"\")" } def "should generate test for String in response body with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method "POST" url "test" @@ -609,15 +624,15 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub and: stubMappingIsValidWireMockStub(contractDsl) where: - methodBuilderName | methodBuilder | bodyDefinitionString | bodyEvaluationString - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | 'def responseBody = (response.body.asString())' | 'responseBody == "test"' - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | 'Object responseBody = (response.getBody().asString());' | 'assertThat(responseBody).isEqualTo("test");' + methodBuilderName | methodBuilder | bodyDefinitionString | bodyEvaluationString + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | 'def responseBody = (response.body.asString())' | 'responseBody == "test"' + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | 'Object responseBody = (response.getBody().asString());' | 'assertThat(responseBody).isEqualTo("test");' } @Issue('113') def "should generate regex test for String in response header with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method 'POST' url $(client(regex('/partners/[0-9]+/users')), server('/partners/1000/users')) @@ -648,15 +663,15 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub and: stubMappingIsValidWireMockStub(contractDsl) where: - methodBuilderName | methodBuilder | headerEvaluationString - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | '''response.header('Location') ==~ java.util.regex.Pattern.compile('http://localhost/partners/[0-9]+/users/[0-9]+')''' - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | 'assertThat(response.header("Location")).matches("http://localhost/partners/[0-9]+/users/[0-9]+");' + methodBuilderName | methodBuilder | headerEvaluationString + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | '''response.header('Location') ==~ java.util.regex.Pattern.compile('http://localhost/partners/[0-9]+/users/[0-9]+')''' + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | 'assertThat(response.header("Location")).matches("http://localhost/partners/[0-9]+/users/[0-9]+");' } @Issue('115') def "should generate regex with helper method with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method 'POST' url $(client(regex('/partners/[0-9]+/users')), server('/partners/1000/users')) @@ -687,14 +702,14 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub and: stubMappingIsValidWireMockStub(contractDsl) where: - methodBuilderName | methodBuilder | headerEvaluationString - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | '''response.header('Location') ==~ java.util.regex.Pattern.compile('^((http[s]?|ftp):\\/)\\/?([^:\\/\\s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+')''' - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | 'assertThat(response.header("Location")).matches("^((http[s]?|ftp):/)/?([^:/s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+");' + methodBuilderName | methodBuilder | headerEvaluationString + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | '''response.header('Location') ==~ java.util.regex.Pattern.compile('^((http[s]?|ftp):\\/)\\/?([^:\\/\\s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+')''' + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | 'assertThat(response.header("Location")).matches("^((http[s]?|ftp):/)/?([^:/s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+");' } def "should work with more complex stuff and jsonpaths with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { priority 10 request { method 'POST' @@ -729,13 +744,13 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub stubMappingIsValidWireMockStub(contractDsl) where: methodBuilderName | methodBuilder - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } } def "should work properly with GString url with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method 'PUT' @@ -762,13 +777,13 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub stubMappingIsValidWireMockStub(contractDsl) where: methodBuilderName | methodBuilder - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } } def "should resolve properties in GString with regular expression with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { priority 1 request { method 'POST' @@ -801,8 +816,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub test.contains("""assertThatJson(parsedJson).field("message").matches("User not found by email = \\\\\\\\[[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\\\\\.[a-zA-Z]{2,4}\\\\\\\\]")""") where: methodBuilderName | methodBuilder - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } } @Issue('42') @@ -844,7 +859,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub @Issue('72') def "should make the execute method work with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method """PUT""" url """/fraudcheck""" @@ -889,9 +904,9 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub assert test.contains(assertionString) } where: - methodBuilderName | methodBuilder | assertionStrings - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | ['''assertThatRejectionReasonIsNull(parsedJson.read('$.rejectionReason'))''', '''assertThatLocationIsNull(response.header('Location'))'''] - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | ['''assertThatRejectionReasonIsNull(parsedJson.read("$.rejectionReason"))''', '''assertThatLocationIsNull(response.header("Location"))'''] + methodBuilderName | methodBuilder | assertionStrings + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | ['''assertThatRejectionReasonIsNull(parsedJson.read('$.rejectionReason'))''', '''assertThatLocationIsNull(response.header('Location'))'''] + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | ['''assertThatRejectionReasonIsNull(parsedJson.read("$.rejectionReason"))''', '''assertThatLocationIsNull(response.header("Location"))'''] } def "should support inner map and list definitions with #methodBuilderName"() { @@ -902,7 +917,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub Pattern NUMBERS = Pattern.compile(/[\d\.]*/) Pattern DATETIME = ANYSTRING - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method "PUT" url "/v1/payments/e86df6f693de4b35ae648464c5b0dc09/client_data" @@ -956,9 +971,9 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub !test.contains("clientValue") !test.contains("cursor") where: - methodBuilderName | methodBuilder | bodyString - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | '"street":"Light Street"' - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '\\"street\\":\\"Light Street\\"' + methodBuilderName | methodBuilder | bodyString + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | '"street":"Light Street"' + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '\\"street\\":\\"Light Street\\"' } @@ -966,7 +981,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub given: Pattern ONLY_ALPHA_UNICODE = Pattern.compile(/[\p{L}]*/) - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method "PUT" url "/v1/payments/e86df6f693de4b35ae648464c5b0dc09/Đ”ĐœĐ”ĐČ" @@ -996,14 +1011,14 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub !test.contains("\\u041f") where: methodBuilderName | methodBuilder - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } } @Issue('177') def "should generate proper test code when having multiline body with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method "PUT" url "/multiline" @@ -1022,16 +1037,16 @@ World.''') then: test.contains(bodyString) where: - methodBuilderName | methodBuilder | bodyString - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | """'''hello, + methodBuilderName | methodBuilder | bodyString + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | """'''hello, World.'''""" - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '\\"hello,\\nWorld.\\"' + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '\\"hello,\\nWorld.\\"' } @Issue('180') def "should generate proper test code when having multipart parameters with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method "PUT" url "/multipart" @@ -1058,21 +1073,21 @@ World.'''""" test.contains(requestString) } where: - methodBuilderName | methodBuilder | requestStrings - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | ["""'content-type', 'multipart/form-data;boundary=AaB03x'""", - """.param('formParameter', '"formParameterValue"'""", - """.param('someBooleanParameter', 'true')""", - """.multiPart('file', 'filename.csv', 'file content'.bytes)"""] - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | ['"content-type", "multipart/form-data;boundary=AaB03x"', - '.param("formParameter", "\\"formParameterValue\\"")', - '.param("someBooleanParameter", "true")', - '.multiPart("file", "filename.csv", "file content".getBytes());'] + methodBuilderName | methodBuilder | requestStrings + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | ["""'content-type', 'multipart/form-data;boundary=AaB03x'""", + """.param('formParameter', '"formParameterValue"'""", + """.param('someBooleanParameter', 'true')""", + """.multiPart('file', 'filename.csv', 'file content'.bytes)"""] + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | ['"content-type", "multipart/form-data;boundary=AaB03x"', + '.param("formParameter", "\\"formParameterValue\\"")', + '.param("someBooleanParameter", "true")', + '.multiPart("file", "filename.csv", "file content".getBytes());'] } @Issue('180') def "should generate proper test code when having multipart parameters with named as map with #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method "PUT" url "/multipart" @@ -1097,14 +1112,14 @@ World.'''""" test.contains('.multiPart') where: methodBuilderName | methodBuilder - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } } @Issue('#216') def "should parse JSON with arrays using Spock"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method "GET" urlPath('/auth/oauth/check_token') { @@ -1138,7 +1153,7 @@ World.'''""" @Issue('#216') def "should parse JSON with arrays using JUnit"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method "GET" urlPath('/auth/oauth/check_token') { @@ -1171,7 +1186,7 @@ World.'''""" def "should work with execution property"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method 'PUT' url '/fraudcheck' @@ -1195,14 +1210,14 @@ World.'''""" test.contains('''assertThatRejectionReasonIsNull(''') where: methodBuilderName | methodBuilder - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } } @Issue('262') def "should generate proper test code with map inside list"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method 'GET' urlPath '/foos' @@ -1233,7 +1248,7 @@ World.'''""" @Issue('266') def "should generate proper test code with top level array using #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method 'GET' urlPath '/api/tags' @@ -1260,14 +1275,14 @@ World.'''""" test.contains('assertThatJson(parsedJson).arrayField().contains("SpringBoot").value()') where: methodBuilderName | methodBuilder - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } } @Issue('266') def "should generate proper test code with top level array or arrays using #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method 'GET' urlPath '/api/categories' @@ -1293,14 +1308,14 @@ World.'''""" test.contains('assertThatJson(parsedJson).array().arrayField().isEqualTo("Boot").value()') where: methodBuilderName | methodBuilder - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } } @Issue('47') def "should generate async body when async flag set in response"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method 'GET' url '/test' @@ -1320,14 +1335,14 @@ World.'''""" and: stubMappingIsValidWireMockStub(contractDsl) where: - methodBuilderName | methodBuilder | bodyDefinitionString - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | '.when().async()' - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '.when().async()' + methodBuilderName | methodBuilder | bodyDefinitionString + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | '.when().async()' + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '.when().async()' } def "should generate proper test code with array of primitives using #methodBuilderName"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method 'GET' urlPath '/api/tags' @@ -1354,14 +1369,14 @@ World.'''""" test.contains('assertThatJson(parsedJson).array("partners").array("payment_methods").arrayField().isEqualTo("CASH").value()') where: methodBuilderName | methodBuilder - "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } - "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } + "MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } + "MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } } @Issue('#273') def "should not escape dollar in Spock regex tests"() { given: - GroovyDsl contractDsl = GroovyDsl.make { + Contract contractDsl = Contract.make { request { method 'GET' urlPath '/get' @@ -1381,14 +1396,14 @@ World.'''""" } - GroovyDsl dslForDocs = + Contract dslForDocs = // tag::dsl_example[] - io.codearte.accurest.dsl.GroovyDsl.make { + Contract.make { request { method 'PUT' url '/api/12' headers { - header 'Content-Type': 'application/vnd.com.ofg.twitter-places-analyzer.v1+json' + header 'Content-Type': 'application/vnd.org.springframework.cloud.contract.verifier.twitter-places-analyzer.v1+json' } body '''\ [{ diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/SingleTestGeneratorSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/builder/SingleTestGeneratorSpec.groovy similarity index 67% rename from accurest-core/src/test/groovy/io/codearte/accurest/SingleTestGeneratorSpec.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/builder/SingleTestGeneratorSpec.groovy index 6fbcac3f45..d4b3bb3485 100644 --- a/accurest-core/src/test/groovy/io/codearte/accurest/SingleTestGeneratorSpec.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/builder/SingleTestGeneratorSpec.groovy @@ -1,14 +1,30 @@ -package io.codearte.accurest +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.builder -import io.codearte.accurest.config.AccurestConfigProperties -import io.codearte.accurest.config.TestMode -import io.codearte.accurest.file.Contract import org.junit.Rule import org.junit.rules.TemporaryFolder +import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties +import org.springframework.cloud.contract.verifier.config.TestMode +import org.springframework.cloud.contract.verifier.file.ContractMetadata import spock.lang.Specification -import static io.codearte.accurest.config.TestFramework.JUNIT -import static io.codearte.accurest.config.TestFramework.SPOCK +import static org.springframework.cloud.contract.verifier.config.TestFramework.JUNIT +import static org.springframework.cloud.contract.verifier.config.TestFramework.SPOCK class SingleTestGeneratorSpec extends Specification { @@ -30,7 +46,7 @@ class SingleTestGeneratorSpec extends Specification { def setup() { file = tmpFolder.newFile() file.write(""" - io.codearte.accurest.dsl.GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'PUT' url 'url' @@ -44,9 +60,9 @@ class SingleTestGeneratorSpec extends Specification { def "should build MockMvc test class for #testFramework"() { given: - AccurestConfigProperties properties = new AccurestConfigProperties(); + ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(); properties.targetFramework = testFramework - Contract contract = new Contract(file.toPath(), true, 1, 2) + ContractMetadata contract = new ContractMetadata(file.toPath(), true, 1, 2) contract.ignored >> true contract.order >> 2 SingleTestGenerator testGenerator = new SingleTestGenerator(properties) @@ -65,10 +81,10 @@ class SingleTestGeneratorSpec extends Specification { def "should build JaxRs test class for #testFramework"() { given: - AccurestConfigProperties properties = new AccurestConfigProperties(); + ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(); properties.testMode = TestMode.JAXRSCLIENT properties.targetFramework = testFramework - Contract contract = new Contract(file.toPath(), true, 1, 2) + ContractMetadata contract = new ContractMetadata(file.toPath(), true, 1, 2) contract.ignored >> true contract.order >> 2 SingleTestGenerator testGenerator = new SingleTestGenerator(properties) @@ -89,7 +105,7 @@ class SingleTestGeneratorSpec extends Specification { given: File secondFile = tmpFolder.newFile() secondFile.write(""" - io.codearte.accurest.dsl.GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract.make { label 'some_label' input { messageFrom('delete') @@ -104,13 +120,13 @@ class SingleTestGeneratorSpec extends Specification { } """) and: - AccurestConfigProperties properties = new AccurestConfigProperties(); + ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(); properties.targetFramework = testFramework - Contract contract = new Contract(file.toPath(), true, 1, 2) + ContractMetadata contract = new ContractMetadata(file.toPath(), true, 1, 2) contract.ignored >> true contract.order >> 2 and: - Contract contract2 = new Contract(secondFile.toPath(), true, 1, 2) + ContractMetadata contract2 = new ContractMetadata(secondFile.toPath(), true, 1, 2) contract2.ignored >> true contract2.order >> 2 and: @@ -121,7 +137,7 @@ class SingleTestGeneratorSpec extends Specification { then: classStrings.each { clazz.contains(it) } - clazz.contains('@Inject AccurestMessaging') + clazz.contains('@Inject ContractVerifierMessaging') where: testFramework | classStrings diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WireMockGroovyDslSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/WireMockGroovyDslSpec.groovy similarity index 84% rename from accurest-core/src/test/groovy/io/codearte/accurest/dsl/WireMockGroovyDslSpec.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/WireMockGroovyDslSpec.groovy index 2b5157a3f7..458e94ab9e 100755 --- a/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WireMockGroovyDslSpec.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/WireMockGroovyDslSpec.groovy @@ -1,9 +1,26 @@ -package io.codearte.accurest.dsl +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl import groovy.json.JsonBuilder import groovy.json.JsonSlurper -import io.codearte.accurest.file.Contract -import io.codearte.accurest.util.AssertionUtil +import org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockStubStrategy +import org.springframework.cloud.contract.verifier.file.ContractMetadata +import org.springframework.cloud.contract.verifier.util.AssertionUtil import spock.lang.Issue import spock.lang.Specification @@ -11,7 +28,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def 'should convert groovy dsl stub to wireMock stub for the client side'() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method('GET') url $(client(~/\/[0-9]{2}/), server('/12')) @@ -36,7 +53,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual(''' { @@ -60,7 +77,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie @Issue("#79") def 'should convert groovy dsl stub to wireMock stub for the client side with a body containing a map'() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'GET' url '/ingredients' @@ -81,7 +98,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual(''' { @@ -107,7 +124,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie @Issue("#86") def 'should convert groovy dsl stub with GString and regexp'() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method('POST') url('/ws/payments') @@ -129,7 +146,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual(''' { @@ -159,7 +176,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def 'should convert groovy dsl stub with Body as String to wireMock stub for the client side'() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method('GET') url $(client(~/\/[0-9]{2}/), server('/12')) @@ -181,7 +198,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual((''' { @@ -204,7 +221,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def 'should convert groovy dsl stub with simple Body as String to wireMock stub for the client side'() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method('GET') url $(client(regex('/[0-9]{2}')), server('/12')) @@ -228,7 +245,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual(''' { @@ -254,7 +271,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def 'should use equalToJson when body match is defined as map'() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method('GET') url $(client(~/\/[0-9]{2}/), server('/12')) @@ -276,7 +293,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual((''' { @@ -304,7 +321,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def 'should use equalToJson when content type ends with json'() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'GET' url "/users" @@ -349,7 +366,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def 'should use equalToXml when content type ends with xml'() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'GET' url "/users" @@ -394,7 +411,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def 'should use equalToXml when content type is parsable xml'() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'GET' url "/users" @@ -431,7 +448,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def 'should support xml as a response body'() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'GET' url "/users" @@ -464,7 +481,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def 'should use equalToJson'() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'GET' url "/users" @@ -499,7 +516,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def 'should use equalToXml'() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'GET' url "/users" @@ -536,7 +553,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def 'should convert groovy dsl stub with regexp Body as String to wireMock stub for the client side'() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method('GET') url $(client(regex('/[0-9]{2}')), server('/12')) @@ -560,7 +577,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual((''' { @@ -586,7 +603,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def 'should convert groovy dsl stub with a regexp and an integer in request body'() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'PUT' url '/fraudcheck' @@ -615,7 +632,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } when: - String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual((''' { @@ -648,7 +665,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def "should generate request with urlPath and queryParameters for client side"() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'GET' urlPath($(client("users"), server("items"))) { @@ -716,7 +733,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def "should generate request with urlPathPattern and queryParameters for client side\ when both contains regular expressions"() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'GET' urlPath($(client(regex("/users/[0-9]+")), server("/users/1"))) { @@ -755,7 +772,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def "should generate request with urlPath for client side"() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'GET' urlPath $(client("boxes"), server("items")) @@ -784,7 +801,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def "should generate simple request with urlPath for client side"() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'GET' urlPath "boxes" @@ -813,7 +830,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def "should not allow regexp in url for server value"() { when: - GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'GET' url(regex(/users\/[0-9]*/)) { @@ -834,7 +851,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def "should not allow regexp in query parameter for server value"() { when: - GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'GET' url("abc") { @@ -854,7 +871,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def "should not allow query parameter unresolvable for a server value"() { when: - GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'GET' urlPath("users") { @@ -875,7 +892,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def "should not allow query parameter with a different absent variation for server/client"() { when: - GroovyDsl.make dsl + org.springframework.cloud.contract.verifier.dsl.Contract.make dsl then: def e = thrown(IllegalStateException) e.message.contains "Absent cannot only be used only on one side" @@ -925,7 +942,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def "should generate request with url and queryParameters for client side"() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'GET' url($(client(regex(/users\/[0-9]*/)), server("users/123"))) { @@ -967,7 +984,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def 'should convert groovy dsl stub with rich tree Body as String to wireMock stub for the client side'() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method('GET') url $(client(~/\/[0-9]{2}/), server('/12')) @@ -1004,7 +1021,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual((''' { @@ -1038,7 +1055,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def 'should use regexp matches when request body match is defined using a map with a pattern'() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'POST' url '/reissue-payment-order' @@ -1098,7 +1115,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def "should generate stub for empty body"() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method('POST') url("test") @@ -1131,7 +1148,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def "should generate stub with priority"() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { priority 9 request { method('POST') @@ -1161,7 +1178,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie @Issue("#127") def 'should use "test" as an alias for "server"'() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method('POST') body( @@ -1173,7 +1190,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual((''' { @@ -1195,7 +1212,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie @Issue("#121") def 'should generate stub with empty list as a value of a field'() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method('POST') body( @@ -1207,7 +1224,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual((''' { @@ -1230,7 +1247,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def 'should generate stub properly resolving GString with regular expression'() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { priority 1 request { method 'POST' @@ -1255,7 +1272,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual((''' { @@ -1289,7 +1306,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie def 'should generate stub properly resolving GString with regular expression in url'() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'PUT' @@ -1306,7 +1323,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual((''' { @@ -1334,7 +1351,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie @Issue('42') def 'should generate stub without optional parameters'() { when: - String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null), contractDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual((''' { @@ -1366,7 +1383,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie stubMappingIsValidWireMockStub(wireMockStub) where: contractDsl << [ - GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract.make { priority 1 request { method 'POST' @@ -1390,7 +1407,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie ) } }, - GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract.make { priority 1 request { method 'POST' @@ -1432,13 +1449,13 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } String toWireMockClientJsonStub(groovyDsl) { - new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() + new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null), groovyDsl).toWireMockClientStub() } @Issue('180') def 'should generate stub with multipart parameters'() { given: - GroovyDsl contractDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract contractDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method "PUT" url "/multipart" @@ -1455,7 +1472,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null), contractDsl).toWireMockClientStub() then: println wireMockStub AssertionUtil.assertThatJsonsAreEqual((''' @@ -1483,7 +1500,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie @Issue('#219') def "should generate request with an optional queryParameter for client side"() { given: - GroovyDsl groovyDsl = GroovyDsl.make { + org.springframework.cloud.contract.verifier.dsl.Contract groovyDsl = org.springframework.cloud.contract.verifier.dsl.Contract.make { request { method 'GET' urlPath ('/some/api') { diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/WireMockStubVerifier.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/WireMockStubVerifier.groovy new file mode 100644 index 0000000000..f0d7a9d50a --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/WireMockStubVerifier.groovy @@ -0,0 +1,39 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl + +import com.github.tomakehurst.wiremock.stubbing.StubMapping +import org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockStubStrategy +import org.springframework.cloud.contract.verifier.file.ContractMetadata + +import java.util.regex.Pattern + +trait WireMockStubVerifier { + + void stubMappingIsValidWireMockStub(String mappingDefinition) { + StubMapping stubMapping = StubMapping.buildFrom(mappingDefinition) + stubMapping.request.bodyPatterns.findAll { it.matches }.every { + Pattern.compile(it.matches) + } + assert !mappingDefinition.contains('org.springframework.cloud.contract.verifier.dsl.internal') + } + + void stubMappingIsValidWireMockStub(org.springframework.cloud.contract.verifier.dsl.Contract contractDsl) { + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null), contractDsl).toWireMockClientStub()) + } + +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/internal/ExecutionPropertySpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/internal/ExecutionPropertySpec.groovy new file mode 100644 index 0000000000..4d3144371e --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/internal/ExecutionPropertySpec.groovy @@ -0,0 +1,35 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal + +import spock.lang.Specification + +class ExecutionPropertySpec extends Specification { + + def 'should insert passed value in place of $it placeholder'() { + given: + String commandToExecute = 'commandToExecute($it)' + ExecutionProperty executionProperty = new ExecutionProperty(commandToExecute) + and: + String valueToInsert = 'someObject.itsValue' + when: + String commandWithInsertedValue = executionProperty.insertValue(valueToInsert) + then: + 'commandToExecute(someObject.itsValue)' == commandWithInsertedValue + } + +} diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/dsl/internal/RegexPatternsSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/internal/RegexPatternsSpec.groovy similarity index 73% rename from accurest-core/src/test/groovy/io/codearte/accurest/dsl/internal/RegexPatternsSpec.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/internal/RegexPatternsSpec.groovy index 3dca400003..4f3b7cdcde 100644 --- a/accurest-core/src/test/groovy/io/codearte/accurest/dsl/internal/RegexPatternsSpec.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/internal/RegexPatternsSpec.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.dsl.internal +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.dsl.internal import spock.lang.Specification diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/file/ContractFileScannerSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/file/ContractFileScannerSpec.groovy similarity index 61% rename from accurest-core/src/test/groovy/io/codearte/accurest/file/ContractFileScannerSpec.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/file/ContractFileScannerSpec.groovy index c699a2a3a1..73e7fc85c0 100644 --- a/accurest-core/src/test/groovy/io/codearte/accurest/file/ContractFileScannerSpec.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/file/ContractFileScannerSpec.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.file +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.file import com.google.common.collect.ListMultimap import spock.lang.Specification @@ -6,7 +22,7 @@ import spock.lang.Specification import java.nio.file.Path /** - * @author Jakub Kubrynski + * @author Jakub Kubrynski, codearte.io */ class ContractFileScannerSpec extends Specification { @@ -17,13 +33,13 @@ class ContractFileScannerSpec extends Specification { Set ignored = ["other/different/**"] as Set ContractFileScanner scanner = new ContractFileScanner(baseDir, excluded, ignored) when: - ListMultimap result = scanner.findContracts() + ListMultimap result = scanner.findContracts() then: result.keySet().size() == 3 result.get(baseDir.toPath().resolve("different")).size() == 1 result.get(baseDir.toPath().resolve("other")).size() == 2 and: - Collection ignoredSet = result.get(baseDir.toPath().resolve("other").resolve("different")) + Collection ignoredSet = result.get(baseDir.toPath().resolve("other").resolve("different")) ignoredSet.size() == 1 ignoredSet.ignored == [true] } @@ -35,11 +51,11 @@ class ContractFileScannerSpec extends Specification { Set ignored = ["bar/**"] as Set ContractFileScanner scanner = new ContractFileScanner(baseDir, excluded, ignored) when: - ListMultimap result = scanner.findContracts() + ListMultimap result = scanner.findContracts() then: result.entries().size() == 2 and: - Collection ignoredSet = result.get(baseDir.toPath().resolve("bar")) + Collection ignoredSet = result.get(baseDir.toPath().resolve("bar")) ignoredSet.size() == 1 ignoredSet.ignored == [true] } @@ -49,7 +65,7 @@ class ContractFileScannerSpec extends Specification { File baseDir = new File(this.getClass().getResource("/directory/with/scenario").toURI()) ContractFileScanner scanner = new ContractFileScanner(baseDir, [] as Set, [] as Set) when: - ListMultimap contracts = scanner.findContracts() + ListMultimap contracts = scanner.findContracts() then: contracts.values().size() == 3 contracts.values().find { it.path.fileName.toString().startsWith('01') }.groupSize == 3 diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/util/JsonToJsonPathsConverterSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/util/JsonToJsonPathsConverterSpec.groovy similarity index 96% rename from accurest-core/src/test/groovy/io/codearte/accurest/util/JsonToJsonPathsConverterSpec.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/util/JsonToJsonPathsConverterSpec.groovy index 5cfdfab42d..958dddf585 100644 --- a/accurest-core/src/test/groovy/io/codearte/accurest/util/JsonToJsonPathsConverterSpec.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/groovy/org/springframework/cloud/contract/verifier/util/JsonToJsonPathsConverterSpec.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.util +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.util import com.jayway.jsonpath.Configuration import com.jayway.jsonpath.DocumentContext diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/scenario/01_login.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/scenario/01_login.groovy new file mode 100644 index 0000000000..958ccd0673 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/scenario/01_login.groovy @@ -0,0 +1,16 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/scenario/02_showCart.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/scenario/02_showCart.groovy new file mode 100644 index 0000000000..958ccd0673 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/scenario/02_showCart.groovy @@ -0,0 +1,16 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/scenario/03_logout.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/scenario/03_logout.groovy new file mode 100644 index 0000000000..958ccd0673 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/scenario/03_logout.groovy @@ -0,0 +1,16 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/stubs/different/diff.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/stubs/different/diff.groovy new file mode 100644 index 0000000000..958ccd0673 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/stubs/different/diff.groovy @@ -0,0 +1,16 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/stubs/other/different/diff.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/stubs/other/different/diff.groovy new file mode 100644 index 0000000000..958ccd0673 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/stubs/other/different/diff.groovy @@ -0,0 +1,16 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/stubs/other/other.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/stubs/other/other.groovy new file mode 100644 index 0000000000..958ccd0673 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/stubs/other/other.groovy @@ -0,0 +1,16 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/stubs/other/sample.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/stubs/other/sample.groovy new file mode 100644 index 0000000000..958ccd0673 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/stubs/other/sample.groovy @@ -0,0 +1,16 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/stubs/package/exceptions/test.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/stubs/package/exceptions/test.groovy new file mode 100644 index 0000000000..958ccd0673 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/stubs/package/exceptions/test.groovy @@ -0,0 +1,16 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/stubs/package/v1/exceptions/testv1.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/stubs/package/v1/exceptions/testv1.groovy new file mode 100644 index 0000000000..958ccd0673 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/stubs/package/v1/exceptions/testv1.groovy @@ -0,0 +1,16 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/stubs/package/v2/exceptions/testv2.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/stubs/package/v2/exceptions/testv2.groovy new file mode 100644 index 0000000000..958ccd0673 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/stubs/package/v2/exceptions/testv2.groovy @@ -0,0 +1,16 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + diff --git a/accurest-core/src/test/resources/directory/with/stubs/stubsRepositoryIndicator b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/stubs/stubsRepositoryIndicator similarity index 100% rename from accurest-core/src/test/resources/directory/with/stubs/stubsRepositoryIndicator rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/directory/with/stubs/stubsRepositoryIndicator diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/dsl/basic/sampleDsl.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/dsl/basic/sampleDsl.groovy new file mode 100644 index 0000000000..38f5869fc5 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/dsl/basic/sampleDsl.groovy @@ -0,0 +1,48 @@ +import org.springframework.cloud.contract.verifier.dsl.Contract + +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Contract.make { + request { + method('PUT') + headers { + header 'Content-Type': 'application/json' + } + body("""\ + { + "name": "Jan", + "id": "${value(client('abc'), server('def'))}", + } + """ + ) + url $(client('/[0-9]{2}'), server('/12')) + } + response { + status 200 + body("""\ + { + "name": "Jan", + "id": "${value(client('123'), server('321'))}", + "surname": "${value(client('Kowalsky'), server('$checkIfSurnameValid($value)'))}" + } + """ + ) + headers { + header 'Content-Type': 'text/plain' + } + } +} diff --git a/accurest-core/src/test/resources/main.json b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/main.json similarity index 100% rename from accurest-core/src/test/resources/main.json rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/main.json diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/strange_[3.3.3]_directory/02_login.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/strange_[3.3.3]_directory/02_login.groovy new file mode 100644 index 0000000000..958ccd0673 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/strange_[3.3.3]_directory/02_login.groovy @@ -0,0 +1,16 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/strange_[3.3.3]_directory/bar/03_login.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/strange_[3.3.3]_directory/bar/03_login.groovy new file mode 100644 index 0000000000..958ccd0673 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/strange_[3.3.3]_directory/bar/03_login.groovy @@ -0,0 +1,16 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/strange_[3.3.3]_directory/foo/01_login.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/strange_[3.3.3]_directory/foo/01_login.groovy new file mode 100644 index 0000000000..958ccd0673 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-core/src/test/resources/strange_[3.3.3]_directory/foo/01_login.groovy @@ -0,0 +1,16 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/GenerateServerTestsTask.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/GenerateServerTestsTask.groovy new file mode 100644 index 0000000000..71935b4d5f --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/GenerateServerTestsTask.groovy @@ -0,0 +1,61 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.plugin + +import org.gradle.api.GradleException +import org.gradle.api.internal.ConventionTask +import org.gradle.api.tasks.InputDirectory +import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.TaskAction +import org.springframework.cloud.contract.verifier.ContractVerifierException +import org.springframework.cloud.contract.verifier.TestGenerator +import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties + +/** + * Task used to generate server side tests + * + * @since 1.0.0 + */ +class GenerateServerTestsTask extends ConventionTask { + + @InputDirectory + File contractsDslDir + @OutputDirectory + File generatedTestSourcesDir + + //TODO: How to deal with @Input*, @Output* and that domain object? + ContractVerifierConfigProperties configProperties + + @TaskAction + void generate() { + project.logger.info("Spring Cloud Contract Verifier Plugin: Invoking test sources generation") + + project.sourceSets.test.groovy { + project.logger.info("Registering ${getConfigProperties().generatedTestSourcesDir} as test source directory") + srcDir getConfigProperties().generatedTestSourcesDir + } + + try { + //TODO: What with that? How to pass? + TestGenerator generator = new TestGenerator(getConfigProperties()) + int generatedClasses = generator.generate() + project.logger.info("Generated {} test classes", generatedClasses) + } catch (ContractVerifierException e) { + throw new GradleException("Spring Cloud Contract Verifier Plugin exception: ${e.message}", e) + } + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/GenerateWireMockClientStubsFromDslTask.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/GenerateWireMockClientStubsFromDslTask.groovy new file mode 100644 index 0000000000..e8f565eb46 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/GenerateWireMockClientStubsFromDslTask.groovy @@ -0,0 +1,49 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.plugin + +import org.gradle.api.internal.ConventionTask +import org.gradle.api.tasks.InputDirectory +import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.TaskAction +import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties +import org.springframework.cloud.contract.verifier.wiremock.DslToWireMockClientConverter +import org.springframework.cloud.contract.verifier.wiremock.RecursiveFilesConverter + +//TODO: Implement as an incremental task: https://gradle.org/docs/current/userguide/custom_tasks.html#incremental_tasks ? +/** + * Generates WireMock stubs from the contracts + * + * @since 1.0.0 + */ +class GenerateWireMockClientStubsFromDslTask extends ConventionTask { + + @InputDirectory + File contractsDslDir + @OutputDirectory + File stubsOutputDir + + ContractVerifierConfigProperties configProperties + + @TaskAction + void generate() { + logger.info("Spring Cloud Contract Verifier Plugin: Invoking DSL to WireMock client stubs conversion") + logger.debug("From '${getContractsDslDir()}' to '${getStubsOutputDir()}'") + RecursiveFilesConverter converter = new RecursiveFilesConverter(new DslToWireMockClientConverter(), getConfigProperties()) + converter.processFiles() + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/SpringCloudContractVerifierGradlePlugin.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/SpringCloudContractVerifierGradlePlugin.groovy new file mode 100644 index 0000000000..e699653491 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/SpringCloudContractVerifierGradlePlugin.groovy @@ -0,0 +1,114 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.plugin + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.Task +import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties + +/** + * Gradle plugin for Spring Cloud Contract Verifier that from the DSL contract can + *
    + *
  • generate tests
  • + *
  • generate stubs
  • + *
+ * + * Also adds the necessary {@code testCompile} dependencies + * + *
    + *
  • WireMock
  • + *
  • JSON Assert
  • + *
  • AssertJ
  • + *
+ * + * @author Jakub Kubrynski, codearte.io + * + * @since 1.0.0 + */ +class SpringCloudContractVerifierGradlePlugin implements Plugin { + + private static final String GENERATE_SERVER_TESTS_TASK_NAME = 'generateContractTests' + private static final String DSL_TO_WIREMOCK_CLIENT_TASK_NAME = 'generateWireMockClientStubs' + + private static final Class IDEA_PLUGIN_CLASS = org.gradle.plugins.ide.idea.IdeaPlugin + private static final String GROUP_NAME = "Verification" + private static final String EXTENSION_NAME = 'contractVerifier' + + private Project project + + @Override + void apply(Project project) { + this.project = project + ContractVerifierConfigProperties extension = project.extensions.create(EXTENSION_NAME, ContractVerifierConfigProperties) + + project.check.dependsOn(GENERATE_SERVER_TESTS_TASK_NAME) + + setConfigurationDefaults(extension) + createGenerateTestsTask(extension) + createAndConfigureGenerateWireMockClientStubsFromDslTask(extension) + project.dependencies.add("testCompile", "com.github.tomakehurst:wiremock:2.0.10-beta") + project.dependencies.add("testCompile", "com.toomuchcoding.jsonassert:jsonassert:0.4.7") + project.dependencies.add("testCompile", "org.assertj:assertj-core:2.3.0") + + project.afterEvaluate { + def hasIdea = project.plugins.findPlugin(IDEA_PLUGIN_CLASS) + if (hasIdea) { + project.idea { + module { + testSourceDirs += extension.generatedTestSourcesDir + testSourceDirs += extension.contractsDslDir + } + } + } + } + } + + private void setConfigurationDefaults(ContractVerifierConfigProperties extension) { + extension.with { + generatedTestSourcesDir = project.file("${project.buildDir}/generated-test-sources/contracts") + contractsDslDir = defaultContractsDir() //TODO: Use sourceset + basePackageForTests = 'org.springframework.cloud.contract.verifier.tests' + } + } + + private File defaultContractsDir() { + project.file("${project.rootDir}/src/test/resources/contracts") + } + + private void createGenerateTestsTask(ContractVerifierConfigProperties extension) { + Task task = project.tasks.create(GENERATE_SERVER_TESTS_TASK_NAME, GenerateServerTestsTask) + task.description = "Generate server tests from the contracts" + task.group = GROUP_NAME + task.conventionMapping.with { + contractsDslDir = { extension.contractsDslDir } + generatedTestSourcesDir = { extension.generatedTestSourcesDir } + configProperties = { extension } + } + } + + private void createAndConfigureGenerateWireMockClientStubsFromDslTask(ContractVerifierConfigProperties extension) { + Task task = project.tasks.create(DSL_TO_WIREMOCK_CLIENT_TASK_NAME, GenerateWireMockClientStubsFromDslTask) + task.description = "Generate WireMock client stubs from the contracts" + task.group = GROUP_NAME + task.conventionMapping.with { + contractsDslDir = { extension.contractsDslDir } + stubsOutputDir = { extension.stubsOutputDir } + configProperties = { extension } + } + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/main/resources/META-INF/gradle-plugins/contract-verifier.properties b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/main/resources/META-INF/gradle-plugins/contract-verifier.properties new file mode 100644 index 0000000000..d5479da71a --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/main/resources/META-INF/gradle-plugins/contract-verifier.properties @@ -0,0 +1,17 @@ +# +# Copyright 2013-2016 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +implementation-class=org.springframework.cloud.contract.verifier.plugin.SpringCloudContractVerifierGradlePlugin \ No newline at end of file diff --git a/accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/BasicFunctionalSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/BasicFunctionalSpec.groovy similarity index 64% rename from accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/BasicFunctionalSpec.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/BasicFunctionalSpec.groovy index 015825ccf1..8634877b49 100755 --- a/accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/BasicFunctionalSpec.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/BasicFunctionalSpec.groovy @@ -1,5 +1,21 @@ -package io.codearte.accurest.plugin -import io.codearte.accurest.util.AssertionUtil +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.plugin +import org.springframework.cloud.contract.verifier.util.AssertionUtil import org.gradle.testkit.runner.BuildResult import spock.lang.Stepwise @@ -7,12 +23,12 @@ import static org.gradle.testkit.runner.TaskOutcome.SUCCESS import static org.gradle.testkit.runner.TaskOutcome.UP_TO_DATE @Stepwise -class BasicFunctionalSpec extends AccurestIntegrationSpec { +class BasicFunctionalSpec extends ContractVerifierIntegrationSpec { - private static final String GENERATED_TEST = "build//generated-test-sources//accurest//accurest//com//ofg//twitter_places_analyzer//PairIdSpec.groovy" - private static final String GENERATED_CLIENT_JSON_STUB = "build//production//bootSimple-stubs//repository//mappings//com//ofg//twitter-places-analyzer//pairId//collerate_PlacesFrom_Tweet.json" - private static final String GROOVY_DSL_CONTRACT = "repository//mappings//com//ofg//twitter-places-analyzer//pairId//collerate_PlacesFrom_Tweet.groovy" - private static final String TEST_EXECUTION_XML_REPORT = "build/test-results/TEST-accurest.com.ofg.twitter_places_analyzer.PairIdSpec.xml" + private static final String GENERATED_TEST = "build//generated-test-sources//contracts//contracts//spring//cloud//twitter_places_analyzer//PairIdSpec.groovy" + private static final String GENERATED_CLIENT_JSON_STUB = "build//production//bootSimple-stubs//repository//mappings//spring//cloud//twitter-places-analyzer//pairId//collerate_PlacesFrom_Tweet.json" + private static final String GROOVY_DSL_CONTRACT = "repository//mappings//spring//cloud//twitter-places-analyzer//pairId//collerate_PlacesFrom_Tweet.groovy" + private static final String TEST_EXECUTION_XML_REPORT = "build/test-results/TEST-contracts.spring.cloud.twitter_places_analyzer.PairIdSpec.xml" def setup() { setupForProject("functionalTest/bootSimple") @@ -24,7 +40,7 @@ class BasicFunctionalSpec extends AccurestIntegrationSpec { BuildResult result = run("check", "publishToMavenLocal") then: result.task(":generateWireMockClientStubs").outcome == SUCCESS - result.task(":generateAccurest").outcome == SUCCESS + result.task(":generateContractTests").outcome == SUCCESS and: "tests generated" fileExists(GENERATED_TEST) @@ -68,26 +84,26 @@ class BasicFunctionalSpec extends AccurestIntegrationSpec { assert !fileExists(GENERATED_CLIENT_JSON_STUB) assert !fileExists(TEST_EXECUTION_XML_REPORT) when: - runTasksSuccessfully('generateWireMockClientStubs', 'generateAccurest') + runTasksSuccessfully('generateWireMockClientStubs', 'generateContractTests') then: fileExists(GENERATED_CLIENT_JSON_STUB) fileExists(GENERATED_TEST) when: "running generation without change inputs" - def secondExecutionResult = run('generateWireMockClientStubs', 'generateAccurest') + def secondExecutionResult = run('generateWireMockClientStubs', 'generateContractTests') then: "tasks should be up-to-date" - validateTasksOutcome(secondExecutionResult, UP_TO_DATE, 'generateWireMockClientStubs', 'generateAccurest') + validateTasksOutcome(secondExecutionResult, UP_TO_DATE, 'generateWireMockClientStubs', 'generateContractTests') when: "inputs changed" def groovyDslFile = file(GROOVY_DSL_CONTRACT) groovyDslFile.text = groovyDslFile.text.replace("200", "599") and: "tasks run" - def thirdExecutionResult = run('generateWireMockClientStubs', 'generateAccurest') + def thirdExecutionResult = run('generateWireMockClientStubs', 'generateContractTests') then: "tasks should be reexecuted" - validateTasksOutcome(thirdExecutionResult, SUCCESS, 'generateWireMockClientStubs', 'generateAccurest') + validateTasksOutcome(thirdExecutionResult, SUCCESS, 'generateWireMockClientStubs', 'generateContractTests') and: "changes visible in generate files" file(GENERATED_CLIENT_JSON_STUB).text.contains("599") diff --git a/accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/AccurestIntegrationSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/ContractVerifierIntegrationSpec.groovy similarity index 70% rename from accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/AccurestIntegrationSpec.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/ContractVerifierIntegrationSpec.groovy index 779d156be3..6e3ced3368 100644 --- a/accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/AccurestIntegrationSpec.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/ContractVerifierIntegrationSpec.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.plugin +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.plugin import org.apache.commons.io.FileUtils import org.gradle.testkit.runner.BuildResult @@ -13,12 +29,8 @@ import java.util.zip.ZipException import java.util.zip.ZipFile import static java.nio.charset.StandardCharsets.UTF_8 -/** - * @author Olga Maciaszek-Sharma - * @author Denis Stepanov - * @since 23.02.16 - */ -abstract class AccurestIntegrationSpec extends Specification { + +abstract class ContractVerifierIntegrationSpec extends Specification { File testProjectDir @@ -31,20 +43,22 @@ abstract class AccurestIntegrationSpec extends Specification { public static final String SPOCK = "targetFramework = 'Spock'" public static final String JUNIT = "targetFramework = 'JUnit'" - public static final String MVC_SPEC = "baseClassForTests = 'com.blogspot.toomuchcoding.MvcSpec'" - public static final String MVC_TEST = "baseClassForTests = 'com.blogspot.toomuchcoding.MvcTest'" + public static final String MVC_SPEC = "baseClassForTests = 'org.springframework.cloud.MvcSpec'" + public static final String MVC_TEST = "baseClassForTests = 'org.springframework.cloud.MvcTest'" protected void setupForProject(String projectRoot) { copyResourcesToRoot(projectRoot) - String accurestGradlePluginLibsDir = System.getProperty("accurest-gradle-plugin-libs-dir").replace('\\', '\\\\') - String messagingLibDir = System.getProperty("messaging-libs-dir").replace('\\', '\\\\') + String gradlePluginSysProp = System.getProperty("contract-verifier-gradle-plugin-libs-dir") + String gradlePluginLibsDir = (gradlePluginSysProp ?: new File("build/").toString()).replace('\\', '\\\\') + String messagingLibDirProp = System.getProperty("messaging-libs-dir") + String messagingLibDir = (messagingLibDirProp ?: new File("build/").toString()).replace('\\', '\\\\') buildFile.write """ ext.messagingLibsDir = '$messagingLibDir' buildscript { dependencies { - classpath fileTree(dir: '$accurestGradlePluginLibsDir', include: '*.jar') + classpath fileTree(dir: '$gradlePluginLibsDir', include: '*.jar') } } @@ -117,7 +131,7 @@ abstract class AccurestIntegrationSpec extends Specification { return new File('build.gradle', testProjectDir) } - protected boolean jarContainsAccurestContracts(String path) { + protected boolean jarContainsContractVerifierContracts(String path) { assert fileExists(path) File rootFile = file(path) boolean containsGroovyFiles = false diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/MessagingProjectSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/MessagingProjectSpec.groovy new file mode 100755 index 0000000000..9f63a1b29c --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/MessagingProjectSpec.groovy @@ -0,0 +1,47 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.plugin + +import spock.lang.Stepwise + +@Stepwise +class MessagingProjectSpec extends ContractVerifierIntegrationSpec { + + def setup() { + setupForProject("functionalTest/messagingProject") + runTasksSuccessfully('clean') //delete accidental output when previously importing SimpleBoot into Idea to tweak it + } + + def "should pass basic flow for Spock"() { + given: + assert fileExists('build.gradle') + expect: + runTasksSuccessfully('check', "publishToMavenLocal") + jarContainsContractVerifierContracts('build/libs') + } + + def "should pass basic flow for JUnit"() { + given: + runTasksSuccessfully('clean') + assert fileExists('build.gradle') + expect: + switchToJunitTestFramework('org.springframework.cloud.samples.book.MessagingBaseSpec', 'org.springframework.cloud.samples.book.MessagingBaseTest') + runTasksSuccessfully('check', "publishToMavenLocal") + jarContainsContractVerifierContracts('build/libs') + } + +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/SampleJerseyProjectSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/SampleJerseyProjectSpec.groovy new file mode 100755 index 0000000000..25b6754d60 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/SampleJerseyProjectSpec.groovy @@ -0,0 +1,46 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.plugin + +import spock.lang.Stepwise + +@Stepwise +class SampleJerseyProjectSpec extends ContractVerifierIntegrationSpec { + + def setup() { + setupForProject("functionalTest/sampleJerseyProject") + runTasksSuccessfully('clean') //delete accidental output when previously importing SimpleBoot into Idea to tweak it + } + + def "should pass basic flow for Spock"() { + given: + assert fileExists('build.gradle') + expect: + runTasksSuccessfully('check', "publishToMavenLocal") + jarContainsContractVerifierContracts('fraudDetectionService/build/libs') + } + + def "should pass basic flow for JUnit"() { + given: + switchToJunitTestFramework() + assert fileExists('build.gradle') + expect: + runTasksSuccessfully('check', "publishToMavenLocal") + jarContainsContractVerifierContracts('fraudDetectionService/build/libs') + } + +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/SampleProjectSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/SampleProjectSpec.groovy new file mode 100755 index 0000000000..5b31c3d4dd --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/SampleProjectSpec.groovy @@ -0,0 +1,46 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.plugin + +import spock.lang.Stepwise + +@Stepwise +class SampleProjectSpec extends ContractVerifierIntegrationSpec { + + def setup() { + setupForProject("functionalTest/sampleProject") + runTasksSuccessfully('clean') //delete accidental output when previously importing SimpleBoot into Idea to tweak it + } + + def "should pass basic flow for Spock"() { + given: + assert fileExists('build.gradle') + expect: + runTasksSuccessfully('check', "publishToMavenLocal") + jarContainsContractVerifierContracts('fraudDetectionService/build/libs') + } + + def "should pass basic flow for JUnit"() { + given: + switchToJunitTestFramework() + assert fileExists('build.gradle') + expect: + runTasksSuccessfully('check', "publishToMavenLocal") + jarContainsContractVerifierContracts('fraudDetectionService/build/libs') + } + +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/ScenarioProjectSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/ScenarioProjectSpec.groovy new file mode 100755 index 0000000000..f822982bef --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/ScenarioProjectSpec.groovy @@ -0,0 +1,46 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.plugin + +import spock.lang.Stepwise + +@Stepwise +class ScenarioProjectSpec extends ContractVerifierIntegrationSpec { + + def setup() { + setupForProject("functionalTest/scenarioProject") + runTasksSuccessfully('clean') //delete accidental output when previously importing SimpleBoot into Idea to tweak it + } + + def "should pass basic flow for Spock"() { + given: + assert fileExists('build.gradle') + expect: + runTasksSuccessfully('check', "publishToMavenLocal") + jarContainsContractVerifierContracts('fraudDetectionService/build/libs') + } + + def "should pass basic flow for JUnit"() { + given: + assert fileExists('build.gradle') + expect: + switchToJunitTestFramework() + runTasksSuccessfully('check', "publishToMavenLocal") + jarContainsContractVerifierContracts('fraudDetectionService/build/libs') + } + +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/build.gradle b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/build.gradle similarity index 88% rename from accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/build.gradle rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/build.gradle index 602bb14cc8..1acee5de97 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/build.gradle +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/build.gradle @@ -5,16 +5,16 @@ buildscript { } apply plugin: 'groovy' -apply plugin: 'accurest' +apply plugin: 'contract-verifier' apply plugin: 'maven-publish' -group = 'io.codearte.accurest.testprojects' +group = 'org.springframework.cloud.testprojects' ext { contractsDir = file("repository/mappings") stubsOutputDirRoot = file("${project.buildDir}/production/${project.name}-stubs/") wireMockStubsOutputDir = file(new File(stubsOutputDirRoot, 'repository/mappings/')) - contractsOutputDir = file(new File(stubsOutputDirRoot, 'repository/accurest/')) + contractsOutputDir = file(new File(stubsOutputDirRoot, 'repository/contracts/')) } configurations { @@ -49,9 +49,9 @@ dependencies { testCompile "ch.qos.logback:logback-classic:1.1.2" } -accurest { - baseClassForTests = 'com.ofg.twitter.places.BaseMockMvcSpec' - basePackageForTests = 'accurest' +contractVerifier { + baseClassForTests = 'org.springframework.cloud.contract.verifier.twitter.places.BaseMockMvcSpec' + basePackageForTests = 'contracts' contractsDslDir = contractsDir // generatedTestSourcesDir = file("${project.rootDir}/src/test/groovy/") stubsOutputDir = wireMockStubsOutputDir @@ -64,7 +64,7 @@ task createWireMockStubsOutputDir << { } generateWireMockClientStubs.dependsOn { createWireMockStubsOutputDir } -generateAccurest.dependsOn generateWireMockClientStubs +generateContractTests.dependsOn generateWireMockClientStubs wrapper { gradleVersion '2.2.1' diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradle.properties b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradle.properties new file mode 100644 index 0000000000..7c325172fd --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradle.properties @@ -0,0 +1,22 @@ +# +# Copyright 2013-2016 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +groupId=org.springframework.cloud.contract.verifier +jacksonMapper=1.9.13 +restAssuredVersion=2.4.0 +springVersion=4.1.7.RELEASE + +springBootVersion=1.3.3.RELEASE \ No newline at end of file diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradle/wrapper/gradle-wrapper.jar b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradle/wrapper/gradle-wrapper.jar rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradle/wrapper/gradle-wrapper.jar diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradle/wrapper/gradle-wrapper.properties b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradle/wrapper/gradle-wrapper.properties new file mode 100755 index 0000000000..f510690c32 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,22 @@ +# +# Copyright 2013-2016 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +#Sat Feb 21 20:13:29 CET 2015 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradlew b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradlew similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradlew rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradlew diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradlew.bat b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradlew.bat similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradlew.bat rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradlew.bat diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/repository/mappings/spring/cloud/twitter-places-analyzer/pairId/collerate_PlacesFrom_Tweet.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/repository/mappings/spring/cloud/twitter-places-analyzer/pairId/collerate_PlacesFrom_Tweet.groovy new file mode 100644 index 0000000000..2f01af1c93 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/repository/mappings/spring/cloud/twitter-places-analyzer/pairId/collerate_PlacesFrom_Tweet.groovy @@ -0,0 +1,36 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.springframework.cloud.contract.verifier.dsl.Contract + +Contract.make { + priority 2 + request { + method 'PUT' + url '/api/12' + headers { + header 'Content-Type': 'application/json' + } + body '''\ + [{ + "text": "Gonna see you at Warsaw" + }] +''' + } + response { + status 200 + } +} \ No newline at end of file diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/repository/mappings/spring/cloud/twitter-places-analyzer/pairId/moreComplexVersion.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/repository/mappings/spring/cloud/twitter-places-analyzer/pairId/moreComplexVersion.groovy new file mode 100644 index 0000000000..c98b51279d --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/repository/mappings/spring/cloud/twitter-places-analyzer/pairId/moreComplexVersion.groovy @@ -0,0 +1,43 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.springframework.cloud.contract.verifier.dsl.Contract + +Contract.make { + request { + method 'PUT' + url $(client(regex('^/api/[0-9]{2}$')), server('/api/12')) + headers { + header 'Content-Type': 'application/json' + } + body '''\ + [{ + "text": "Gonna see you at Warsaw" + }] +''' + } + response { + headers { + header 'Content-Type': $(client('application/json'), server(regex('application/json.*'))) + header 'Location': $(client('https://localhost:8080'), server(execute('isEmpty($it)'))) + } + body ( + path: $(client('/api/12'), server(regex('^/api/[0-9]{2}$'))), + correlationId: $(client('1223456'), server(execute('isProperCorrelationId($it)'))) + ) + status 200 + } +} \ No newline at end of file diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/settings.gradle b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/settings.gradle new file mode 100644 index 0000000000..f452413fb1 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/settings.gradle @@ -0,0 +1,17 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +rootProject.name='bootSimple' diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/main/groovy/com/ofg/twitter/place/PairIdController.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/main/groovy/org/springframework/cloud/twitter/place/PairIdController.groovy similarity index 56% rename from accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/main/groovy/com/ofg/twitter/place/PairIdController.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/main/groovy/org/springframework/cloud/twitter/place/PairIdController.groovy index 3a7671793c..38b7dfc178 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/main/groovy/com/ofg/twitter/place/PairIdController.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/main/groovy/org/springframework/cloud/twitter/place/PairIdController.groovy @@ -1,4 +1,20 @@ -package com.ofg.twitter.place +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.twitter.place import groovy.transform.TypeChecked import groovy.util.logging.Slf4j @@ -21,7 +37,7 @@ class PairIdController { method = PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - String getPlacesFromTweets(@PathVariable long pairId, @RequestBody List tweets) { + String getPlacesFromTweets(@PathVariable long pairId, @RequestBody List tweets) { log.info("Inside PairIdController, doing very important logic") if (tweets?.text != ["Gonna see you at Warsaw"]) { throw new IllegalArgumentException("Wrong text in tweet: ${tweets?.text}") diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/main/groovy/com/ofg/twitter/place/Tweet.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/main/groovy/org/springframework/cloud/twitter/place/Tweet.java similarity index 69% rename from accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/main/groovy/com/ofg/twitter/place/Tweet.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/main/groovy/org/springframework/cloud/twitter/place/Tweet.java index 5d1e9c2835..9417289cec 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/main/groovy/com/ofg/twitter/place/Tweet.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/main/groovy/org/springframework/cloud/twitter/place/Tweet.java @@ -1,4 +1,4 @@ -package com.ofg.twitter.place; +package org.springframework.cloud.contract.verifier.twitter.place; public class Tweet { private String text; diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/groovy/org/springframework/cloud/contract/verifier/twitter/places/AcceptanceSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/groovy/org/springframework/cloud/contract/verifier/twitter/places/AcceptanceSpec.groovy new file mode 100644 index 0000000000..9f482e0b4c --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/groovy/org/springframework/cloud/contract/verifier/twitter/places/AcceptanceSpec.groovy @@ -0,0 +1,39 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.twitter.places + +import org.springframework.cloud.contract.verifier.twitter.place.PairIdController +import org.springframework.http.MediaType +import org.springframework.test.web.servlet.MockMvc +import org.springframework.test.web.servlet.setup.MockMvcBuilders +import spock.lang.Specification + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status + +class AcceptanceSpec extends Specification { + + def "should have controller up and running"() { + given: + MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new PairIdController()).build() + expect: + mockMvc.perform(put("/api/${1}"). + contentType(MediaType.APPLICATION_JSON). + content("""[{"text":"Gonna see you at Warsaw"}]""")). + andExpect(status().isOk()) + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/groovy/org/springframework/cloud/contract/verifier/twitter/places/BaseMockMvcSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/groovy/org/springframework/cloud/contract/verifier/twitter/places/BaseMockMvcSpec.groovy new file mode 100644 index 0000000000..6057d7081a --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/groovy/org/springframework/cloud/contract/verifier/twitter/places/BaseMockMvcSpec.groovy @@ -0,0 +1,39 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.twitter.places + +import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc +import org.springframework.cloud.contract.verifier.twitter.place.PairIdController +import spock.lang.Specification + +// tag::base_class[] +abstract class BaseMockMvcSpec extends Specification { + + def setup() { + RestAssuredMockMvc.standaloneSetup(new PairIdController()) + } + + void isProperCorrelationId(Integer correlationId) { + assert correlationId == 123456 + } + + void isEmpty(String value) { + assert value == null + } + +} +// end::base_class[] diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/resources/logback-test.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/resources/logback-test.groovy new file mode 100644 index 0000000000..0b49bdfb4a --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/resources/logback-test.groovy @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import ch.qos.logback.classic.encoder.PatternLayoutEncoder +import ch.qos.logback.core.ConsoleAppender + +String console = "CONSOLE" +String logPattern = "%d{yyyy-MM-dd HH:mm:ss.SSSZ, Europe/Warsaw} | %-5level | %X{correlationId} | %thread | %logger{1} | %m%n" + +appender(console, ConsoleAppender) { + encoder(PatternLayoutEncoder) { + pattern = logPattern + } +} + +root(INFO, [console]) +logger("org.springframework.cloud.contract.verifier", DEBUG) diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/build.gradle b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/build.gradle similarity index 85% rename from accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/build.gradle rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/build.gradle index 8b476c9267..2f5a549e19 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/build.gradle +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/build.gradle @@ -6,16 +6,16 @@ buildscript { } apply plugin: 'groovy' -apply plugin: 'accurest' +apply plugin: 'contract-verifier' apply plugin: 'maven-publish' -group = 'io.codearte.accurest.testprojects' +group = 'org.springframework.cloud.testprojects' ext { contractsDir = file("repository/mappings") stubsOutputDirRoot = file("${project.buildDir}/production/${project.name}-stubs/") wireMockStubsOutputDir = new File(stubsOutputDirRoot, 'repository/mappings/') - contractsOutputDir = new File(stubsOutputDirRoot, 'repository/accurest/') + contractsOutputDir = new File(stubsOutputDirRoot, 'repository/contracts/') targetFramework = 'Spock' } @@ -58,10 +58,10 @@ dependencies { testCompile 'com.jayway.restassured:spring-mock-mvc:2.9.0' // needed if you're going to use Spring MockMvc } -accurest { - //baseClassForTests = 'io.codearte.accurest.samples.book.MessagingBaseTest' - baseClassForTests = 'io.codearte.accurest.samples.book.MessagingBaseSpec' - basePackageForTests = 'accurest' +contractVerifier { + //baseClassForTests = 'org.springframework.cloud.samples.book.MessagingBaseTest' + baseClassForTests = 'org.springframework.cloud.samples.book.MessagingBaseSpec' + basePackageForTests = 'contracts' //targetFramework = 'JUnit' targetFramework = 'Spock' contractsDslDir = contractsDir @@ -75,7 +75,7 @@ task createWireMockStubsOutputDir << { } generateWireMockClientStubs.dependsOn { createWireMockStubsOutputDir } -generateAccurest.dependsOn generateWireMockClientStubs +generateContractTests.dependsOn generateWireMockClientStubs wrapper { gradleVersion '2.12' diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradle.properties b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradle.properties new file mode 100644 index 0000000000..7293ee6bc8 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradle.properties @@ -0,0 +1,22 @@ +# +# Copyright 2013-2016 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +groupId=org.springframework.cloud +jacksonMapper=1.9.13 +restAssuredVersion=2.9.0 +springVersion=4.2.3.RELEASE + +springBootVersion=1.3.3.RELEASE \ No newline at end of file diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradle/wrapper/gradle-wrapper.jar b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradle/wrapper/gradle-wrapper.jar rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradle/wrapper/gradle-wrapper.jar diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradle/wrapper/gradle-wrapper.properties b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradle/wrapper/gradle-wrapper.properties new file mode 100755 index 0000000000..7f6620ddcf --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,22 @@ +# +# Copyright 2013-2016 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +#Sun Apr 17 20:31:11 CEST 2016 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradlew b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradlew similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradlew rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradlew diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradlew.bat b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradlew.bat similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradlew.bat rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradlew.bat diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/a_foo.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/a_foo.groovy new file mode 100644 index 0000000000..202c8808fe --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/a_foo.groovy @@ -0,0 +1,28 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.springframework.cloud.contract.verifier.dsl.Contract + +Contract.make { + request { + url '/foo' + method 'GET' + } + response { + status 200 + body 'bar' + } +} \ No newline at end of file diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/bookDeleted.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/bookDeleted.groovy new file mode 100644 index 0000000000..4c73b42e4d --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/bookDeleted.groovy @@ -0,0 +1,31 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.springframework.cloud.contract.verifier.dsl.Contract + +Contract.make { + label 'some_label' + input { + messageFrom('delete') + messageBody([ + bookName: 'foo' + ]) + messageHeaders { + header('sample', 'header') + } + assertThat('bookWasDeleted()') + } +} \ No newline at end of file diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/bookReturned1.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/bookReturned1.groovy new file mode 100644 index 0000000000..3d4ba32c3a --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/bookReturned1.groovy @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import org.springframework.cloud.contract.verifier.dsl.Contract + +Contract.make { + label 'some_label' + input { + triggeredBy('bookReturnedTriggered()') + } + outputMessage { + sentTo('output') + body('''{ "bookName" : "foo" }''') + headers { + header('BOOK-NAME', 'foo') + } + } +} \ No newline at end of file diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/bookReturned2.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/bookReturned2.groovy new file mode 100644 index 0000000000..91ae4361ef --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/repository/mappings/bookReturned2.groovy @@ -0,0 +1,38 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import org.springframework.cloud.contract.verifier.dsl.Contract + +Contract.make { + label 'some_label' + input { + messageFrom('input') + messageBody([ + bookName: 'foo' + ]) + messageHeaders { + header('sample', 'header') + } + } + outputMessage { + sentTo('output') + body([ + bookName: 'foo' + ]) + headers { + header('BOOK-NAME', 'foo') + } + } +} \ No newline at end of file diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/settings.gradle b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/settings.gradle new file mode 100644 index 0000000000..f452413fb1 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/settings.gradle @@ -0,0 +1,17 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +rootProject.name='bootSimple' diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/org/springframework/cloud/samples/book/BookDeleted.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/org/springframework/cloud/samples/book/BookDeleted.groovy new file mode 100644 index 0000000000..3d9e527fb5 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/org/springframework/cloud/samples/book/BookDeleted.groovy @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.samples.book + +import com.fasterxml.jackson.annotation.JsonCreator +import groovy.transform.CompileStatic + +@CompileStatic +class BookDeleted { + final String bookName + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + BookDeleted(String bookName) { + this.bookName = bookName + } +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/io/codearte/accurest/samples/book/BookListener.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/org/springframework/cloud/samples/book/BookListener.groovy similarity index 67% rename from accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/io/codearte/accurest/samples/book/BookListener.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/org/springframework/cloud/samples/book/BookListener.groovy index 60838893b8..6399b53a79 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/io/codearte/accurest/samples/book/BookListener.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/org/springframework/cloud/samples/book/BookListener.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.samples.book +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.samples.book import groovy.transform.CompileStatic import groovy.util.logging.Slf4j diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/org/springframework/cloud/samples/book/BookReturned.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/org/springframework/cloud/samples/book/BookReturned.groovy new file mode 100644 index 0000000000..22353e827f --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/org/springframework/cloud/samples/book/BookReturned.groovy @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.samples.book + +import com.fasterxml.jackson.annotation.JsonCreator +import groovy.transform.CompileStatic + +@CompileStatic +class BookReturned { + final String bookName + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + BookReturned(String bookName) { + this.bookName = bookName + } +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/io/codearte/accurest/samples/book/BookService.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/org/springframework/cloud/samples/book/BookService.groovy similarity index 61% rename from accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/io/codearte/accurest/samples/book/BookService.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/org/springframework/cloud/samples/book/BookService.groovy index 25e943fc93..b44a36a834 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/io/codearte/accurest/samples/book/BookService.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/org/springframework/cloud/samples/book/BookService.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.samples.book +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.samples.book import groovy.transform.CompileStatic import groovy.util.logging.Slf4j diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/org/springframework/cloud/samples/book/IntegrationMessagingApplication.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/org/springframework/cloud/samples/book/IntegrationMessagingApplication.groovy new file mode 100644 index 0000000000..e7345c64c8 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/groovy/org/springframework/cloud/samples/book/IntegrationMessagingApplication.groovy @@ -0,0 +1,38 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.samples.book + +import org.springframework.boot.SpringApplication +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.context.annotation.ImportResource +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +@SpringBootApplication +@RestController +@ImportResource("classpath*:integration-context.xml") +class IntegrationMessagingApplication { + + @RequestMapping("/foo") + String foo() { + return "bar" + } + + static void main(String[] args) { + SpringApplication.run(IntegrationMessagingApplication.class, args) + } +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/resources/integration-context.xml b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/resources/integration-context.xml similarity index 52% rename from accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/resources/integration-context.xml rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/resources/integration-context.xml index e8c7accb04..f29045cdb2 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/resources/integration-context.xml +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/main/resources/integration-context.xml @@ -1,4 +1,20 @@ + + - - - + diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/test/groovy/io/codearte/accurest/samples/book/MessagingBaseSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/test/groovy/org/springframework/cloud/samples/book/MessagingBaseSpec.groovy similarity index 56% rename from accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/test/groovy/io/codearte/accurest/samples/book/MessagingBaseSpec.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/test/groovy/org/springframework/cloud/samples/book/MessagingBaseSpec.groovy index 0beb893d51..b0950a030c 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/test/groovy/io/codearte/accurest/samples/book/MessagingBaseSpec.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/test/groovy/org/springframework/cloud/samples/book/MessagingBaseSpec.groovy @@ -1,4 +1,20 @@ -package io.codearte.accurest.samples.book +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.samples.book import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.SpringApplicationContextLoader diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/test/java/io/codearte/accurest/samples/book/MessagingBaseTest.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/test/java/org/springframework/cloud/samples/book/MessagingBaseTest.java similarity index 62% rename from accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/test/java/io/codearte/accurest/samples/book/MessagingBaseTest.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/test/java/org/springframework/cloud/samples/book/MessagingBaseTest.java index 47634cbf37..2cc4aa8abb 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/test/java/io/codearte/accurest/samples/book/MessagingBaseTest.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/messagingProject/src/test/java/org/springframework/cloud/samples/book/MessagingBaseTest.java @@ -1,4 +1,20 @@ -package io.codearte.accurest.samples.book; +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.samples.book; import org.assertj.core.api.Assertions; import org.junit.runner.RunWith; diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/build.gradle b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/build.gradle similarity index 75% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/build.gradle rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/build.gradle index 3e3e107564..5b67157601 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/build.gradle +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/build.gradle @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + buildscript { repositories { mavenLocal() @@ -8,14 +24,14 @@ buildscript { } } -group = 'io.codearte.accurest.testprojects' +group = 'org.springframework.cloud.testprojects' ext { restAssuredVersion = '2.5.0' spockVersion = '1.0-groovy-2.4' wiremockVersion = '2.0.10-beta' - accurestStubsBaseDirectory = 'src/test/resources/stubs' + contractVerifierStubsBaseDirectory = 'src/test/resources/stubs' } subprojects { @@ -36,20 +52,20 @@ subprojects { configure([project(':fraudDetectionService'), project(':loanApplicationService')]) { apply plugin: 'spring-boot' - apply plugin: 'accurest' + apply plugin: 'contract-verifier' apply plugin: 'maven-publish' ext { contractsDir = file("mappings") stubsOutputDirRoot = file("${project.buildDir}/production/${project.name}-stubs/") wireMockStubsOutputDir = file(new File(stubsOutputDirRoot, 'repository/mappings/')) - contractsOutputDir = file(new File(stubsOutputDirRoot, 'repository/accurest/')) + contractsOutputDir = file(new File(stubsOutputDirRoot, 'repository/contracts/')) } - accurest { + contractVerifier { targetFramework = 'Spock' testMode = 'JaxRsClient' - baseClassForTests = 'com.blogspot.toomuchcoding.MvcSpec' + baseClassForTests = 'org.springframework.cloud.MvcSpec' contractsDslDir = file("${project.projectDir.absolutePath}/mappings/") generatedTestSourcesDir = file("${project.buildDir}/generated-test-sources/") stubsOutputDir = wireMockStubsOutputDir @@ -125,6 +141,6 @@ configure(project(':loanApplicationService')) { into "src/test/resources/" } - generateAccurest.dependsOn('copyCollaboratorStubs') + generateContractTests.dependsOn('copyCollaboratorStubs') } diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsFraud.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsFraud.groovy new file mode 100644 index 0000000000..2634bca6cc --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsFraud.groovy @@ -0,0 +1,45 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.springframework.cloud.contract.verifier.dsl.Contract + +Contract.make { + request { + method """PUT""" + url """/fraudcheck""" + body(""" + { + "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", + "loanAmount":99999} + """ + ) + headers { + header("""Content-Type""", """application/vnd.fraud.v1+json""") + } + + } + response { + status 200 + body( """{ + "fraudCheckStatus": "${value(client('FRAUD'), server(regex('[A-Z]{5}')))}", + "rejectionReason": "Amount too high" +}""") + headers { + header('Content-Type': 'application/vnd.fraud.v1+json') + } + } + +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.groovy new file mode 100644 index 0000000000..249de5bc5f --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.groovy @@ -0,0 +1,46 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.springframework.cloud.contract.verifier.dsl.Contract + +Contract.make { + request { + method 'PUT' + url '/fraudcheck' + body(""" + { + "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", + "loanAmount":123.123 + } + """ + ) + headers { + header('Content-Type', 'application/vnd.fraud.v1+json') + } + + } + response { + status 200 + body( + fraudCheckStatus: "OK", + rejectionReason: $(client(null), server(execute('assertThatRejectionReasonIsNull($it)'))) + ) + headers { + header('Content-Type': 'application/vnd.fraud.v1+json') + } + } + +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/Application.java similarity index 92% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/Application.java index 99a72fbf26..e671a56892 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/Application.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection; +package org.springframework.cloud.frauddetection; import org.glassfish.jersey.server.ResourceConfig; import org.springframework.boot.SpringApplication; diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/FraudDetectionController.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/FraudDetectionController.java similarity index 73% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/FraudDetectionController.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/FraudDetectionController.java index bb015f08a4..3eaaea3a42 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/FraudDetectionController.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/FraudDetectionController.java @@ -1,15 +1,15 @@ -package com.blogspot.toomuchcoding.frauddetection; +package org.springframework.cloud.frauddetection; -import com.blogspot.toomuchcoding.frauddetection.model.FraudCheck; -import com.blogspot.toomuchcoding.frauddetection.model.FraudCheckResult; +import org.springframework.cloud.frauddetection.model.FraudCheck; +import org.springframework.cloud.frauddetection.model.FraudCheckResult; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; import javax.ws.rs.*; import java.math.BigDecimal; -import static com.blogspot.toomuchcoding.frauddetection.model.FraudCheckStatus.FRAUD; -import static com.blogspot.toomuchcoding.frauddetection.model.FraudCheckStatus.OK; +import static org.springframework.cloud.frauddetection.model.FraudCheckStatus.FRAUD; +import static org.springframework.cloud.frauddetection.model.FraudCheckStatus.OK; @Controller @Path("/") diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/FraudRestApplication.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/FraudRestApplication.java similarity index 83% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/FraudRestApplication.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/FraudRestApplication.java index 83e15edc59..064e59196b 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/FraudRestApplication.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/FraudRestApplication.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection; +package org.springframework.cloud.frauddetection; import java.util.Collections; import java.util.Set; diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheck.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheck.java similarity index 88% rename from accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheck.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheck.java index 77471aee19..72551915bc 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheck.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheck.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection.model; +package org.springframework.cloud.frauddetection.model; import java.math.BigDecimal; diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckResult.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheckResult.java similarity index 92% rename from accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckResult.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheckResult.java index 28efc573f5..95fd5e04c4 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckResult.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheckResult.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection.model; +package org.springframework.cloud.frauddetection.model; public class FraudCheckResult { diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheckStatus.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheckStatus.java new file mode 100644 index 0000000000..b4fd951df2 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheckStatus.java @@ -0,0 +1,5 @@ +package org.springframework.cloud.frauddetection.model; + +public enum FraudCheckStatus { + OK, FRAUD +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/resources/application.yml b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/resources/application.yml similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/resources/application.yml rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/resources/application.yml diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/test/groovy/com/blogspot/toomuchcoding/MvcSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/test/groovy/org/springframework/cloud/MvcSpec.groovy similarity index 65% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/test/groovy/com/blogspot/toomuchcoding/MvcSpec.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/test/groovy/org/springframework/cloud/MvcSpec.groovy index 621d20ded4..1fab371acc 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/test/groovy/com/blogspot/toomuchcoding/MvcSpec.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/test/groovy/org/springframework/cloud/MvcSpec.groovy @@ -1,6 +1,22 @@ -package com.blogspot.toomuchcoding -import com.blogspot.toomuchcoding.frauddetection.Application -import com.blogspot.toomuchcoding.frauddetection.FraudRestApplication +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud +import org.springframework.cloud.frauddetection.Application +import org.springframework.cloud.frauddetection.FraudRestApplication import org.eclipse.jetty.server.Server import org.glassfish.jersey.apache.connector.ApacheConnectorProvider import org.glassfish.jersey.client.ClientConfig diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/test/java/com/blogspot/toomuchcoding/MvcTest.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/test/java/org/springframework/cloud/MvcTest.java similarity index 91% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/test/java/com/blogspot/toomuchcoding/MvcTest.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/test/java/org/springframework/cloud/MvcTest.java index d36d31e510..93c9209621 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/test/java/com/blogspot/toomuchcoding/MvcTest.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/test/java/org/springframework/cloud/MvcTest.java @@ -1,7 +1,7 @@ -package com.blogspot.toomuchcoding; +package org.springframework.cloud; -import com.blogspot.toomuchcoding.frauddetection.Application; -import com.blogspot.toomuchcoding.frauddetection.FraudRestApplication; +import org.springframework.cloud.frauddetection.Application; +import org.springframework.cloud.frauddetection.FraudRestApplication; import org.eclipse.jetty.server.Server; import org.glassfish.jersey.apache.connector.ApacheConnectorProvider; import org.glassfish.jersey.client.ClientConfig; diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/gradle/wrapper/gradle-wrapper.jar b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/gradle/wrapper/gradle-wrapper.jar rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/gradle/wrapper/gradle-wrapper.jar diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/gradle/wrapper/gradle-wrapper.properties b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..1aa6b34ba4 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,22 @@ +# +# Copyright 2013-2016 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +#Wed Jan 28 00:32:44 CET 2015 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/gradlew b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/gradlew similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/gradlew rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/gradlew diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/gradlew.bat b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/gradlew.bat similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/gradlew.bat rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/gradlew.bat diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/mappings/.gitkeep b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/mappings/.gitkeep similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/mappings/.gitkeep rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/mappings/.gitkeep diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/Application.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/Application.java new file mode 100644 index 0000000000..e70eca242e --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/Application.java @@ -0,0 +1,33 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.frauddetection; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableAutoConfiguration +@ComponentScan +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/LoanApplicationService.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/LoanApplicationService.java similarity index 62% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/LoanApplicationService.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/LoanApplicationService.java index a2d8ce1e74..64402473fa 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/LoanApplicationService.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/LoanApplicationService.java @@ -1,11 +1,27 @@ -package com.blogspot.toomuchcoding.frauddetection; +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import com.blogspot.toomuchcoding.frauddetection.model.FraudCheckStatus; -import com.blogspot.toomuchcoding.frauddetection.model.FraudServiceRequest; -import com.blogspot.toomuchcoding.frauddetection.model.FraudServiceResponse; -import com.blogspot.toomuchcoding.frauddetection.model.LoanApplication; -import com.blogspot.toomuchcoding.frauddetection.model.LoanApplicationResult; -import com.blogspot.toomuchcoding.frauddetection.model.LoanApplicationStatus; +package org.springframework.cloud.frauddetection; + +import org.springframework.cloud.frauddetection.model.FraudCheckStatus; +import org.springframework.cloud.frauddetection.model.FraudServiceRequest; +import org.springframework.cloud.frauddetection.model.FraudServiceResponse; +import org.springframework.cloud.frauddetection.model.LoanApplication; +import org.springframework.cloud.frauddetection.model.LoanApplicationResult; +import org.springframework.cloud.frauddetection.model.LoanApplicationStatus; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/Client.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/Client.java new file mode 100644 index 0000000000..403da83818 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/Client.java @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.frauddetection.model; + +public class Client { + + private String pesel; + + public String getPesel() { + return pesel; + } + + public void setPesel(String pesel) { + this.pesel = pesel; + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheckStatus.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheckStatus.java new file mode 100644 index 0000000000..4fb43b0cf8 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheckStatus.java @@ -0,0 +1,21 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.frauddetection.model; + +public enum FraudCheckStatus { + OK, FRAUD +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudServiceRequest.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudServiceRequest.java new file mode 100644 index 0000000000..fc2aa4580c --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudServiceRequest.java @@ -0,0 +1,50 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.frauddetection.model; + +import java.math.BigDecimal; + +public class FraudServiceRequest { + + private String clientPesel; + + private BigDecimal loanAmount; + + public FraudServiceRequest() { + } + + public FraudServiceRequest(LoanApplication loanApplication) { + this.clientPesel = loanApplication.getClient().getPesel(); + this.loanAmount = loanApplication.getAmount(); + } + + public String getClientPesel() { + return clientPesel; + } + + public void setClientPesel(String clientPesel) { + this.clientPesel = clientPesel; + } + + public BigDecimal getLoanAmount() { + return loanAmount; + } + + public void setLoanAmount(BigDecimal loanAmount) { + this.loanAmount = loanAmount; + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudServiceResponse.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudServiceResponse.java new file mode 100644 index 0000000000..79eb5b2c0d --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudServiceResponse.java @@ -0,0 +1,43 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.frauddetection.model; + +public class FraudServiceResponse { + + private FraudCheckStatus fraudCheckStatus; + + private String rejectionReason; + + public FraudServiceResponse() { + } + + public FraudCheckStatus getFraudCheckStatus() { + return fraudCheckStatus; + } + + public void setFraudCheckStatus(FraudCheckStatus fraudCheckStatus) { + this.fraudCheckStatus = fraudCheckStatus; + } + + public String getRejectionReason() { + return rejectionReason; + } + + public void setRejectionReason(String rejectionReason) { + this.rejectionReason = rejectionReason; + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplication.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplication.java new file mode 100644 index 0000000000..ad2c6c80a1 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplication.java @@ -0,0 +1,52 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.frauddetection.model; + +import java.math.BigDecimal; + +public class LoanApplication { + + private Client client; + + private BigDecimal amount; + + private String loanApplicationId; + + public Client getClient() { + return client; + } + + public void setClient(Client client) { + this.client = client; + } + + public BigDecimal getAmount() { + return amount; + } + + public void setAmount(BigDecimal amount) { + this.amount = amount; + } + + public String getLoanApplicationId() { + return loanApplicationId; + } + + public void setLoanApplicationId(String loanApplicationId) { + this.loanApplicationId = loanApplicationId; + } +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationResult.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplicationResult.java similarity index 53% rename from accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationResult.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplicationResult.java index 523f4f2ea3..a9b0617c11 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationResult.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplicationResult.java @@ -1,4 +1,20 @@ -package com.blogspot.toomuchcoding.frauddetection.model; +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.frauddetection.model; public class LoanApplicationResult { diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplicationStatus.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplicationStatus.java new file mode 100644 index 0000000000..e939d49b8f --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplicationStatus.java @@ -0,0 +1,21 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.frauddetection.model; + +public enum LoanApplicationStatus { + LOAN_APPLIED, LOAN_APPLICATION_REJECTED +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/resources/application.yml b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/resources/application.yml similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/resources/application.yml rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/resources/application.yml diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/test/groovy/com/blogspot/toomuchcoding/LoanApplicationServiceSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/test/groovy/org/springframework/cloud/LoanApplicationServiceSpec.groovy similarity index 58% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/test/groovy/com/blogspot/toomuchcoding/LoanApplicationServiceSpec.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/test/groovy/org/springframework/cloud/LoanApplicationServiceSpec.groovy index 21ee7a4d39..d5104eb499 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/test/groovy/com/blogspot/toomuchcoding/LoanApplicationServiceSpec.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/test/groovy/org/springframework/cloud/LoanApplicationServiceSpec.groovy @@ -1,11 +1,27 @@ -package com.blogspot.toomuchcoding +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import com.blogspot.toomuchcoding.frauddetection.Application -import com.blogspot.toomuchcoding.frauddetection.LoanApplicationService -import com.blogspot.toomuchcoding.frauddetection.model.Client -import com.blogspot.toomuchcoding.frauddetection.model.LoanApplication -import com.blogspot.toomuchcoding.frauddetection.model.LoanApplicationResult -import com.blogspot.toomuchcoding.frauddetection.model.LoanApplicationStatus +package org.springframework.cloud + +import org.springframework.cloud.frauddetection.Application +import org.springframework.cloud.frauddetection.LoanApplicationService +import org.springframework.cloud.frauddetection.model.Client +import org.springframework.cloud.frauddetection.model.LoanApplication +import org.springframework.cloud.frauddetection.model.LoanApplicationResult +import org.springframework.cloud.frauddetection.model.LoanApplicationStatus import com.github.tomakehurst.wiremock.junit.WireMockClassRule import org.junit.ClassRule import org.springframework.beans.factory.annotation.Autowired diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsFraud.json b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsFraud.json similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsFraud.json rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsFraud.json diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.json b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.json similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.json rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.json diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/settings.gradle b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/settings.gradle new file mode 100644 index 0000000000..48db488159 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/settings.gradle @@ -0,0 +1,18 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +include ':fraudDetectionService' +include ':loanApplicationService' diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/build.gradle b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/build.gradle similarity index 75% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/build.gradle rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/build.gradle index 606fc7ba5d..b388ed0da6 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/build.gradle +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/build.gradle @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + buildscript { repositories { mavenCentral() @@ -13,10 +29,10 @@ ext { spockVersion = '1.0-groovy-2.4' wiremockVersion = '2.0.10-beta' - accurestStubsBaseDirectory = 'src/test/resources/stubs' + contractVerifierStubsBaseDirectory = 'src/test/resources/stubs' } -group = 'io.codearte.accurest.testprojects' +group = 'org.springframework.cloud.testprojects' subprojects { apply plugin: 'groovy' @@ -36,20 +52,20 @@ subprojects { configure([project(':fraudDetectionService'), project(':loanApplicationService')]) { apply plugin: 'spring-boot' - apply plugin: 'accurest' + apply plugin: 'contract-verifier' apply plugin: 'maven-publish' ext { contractsDir = file("mappings") stubsOutputDirRoot = file("${project.buildDir}/production/${project.name}-stubs/") wireMockStubsOutputDir = file(new File(stubsOutputDirRoot, 'repository/mappings/')) - contractsOutputDir = file(new File(stubsOutputDirRoot, 'repository/accurest/')) + contractsOutputDir = file(new File(stubsOutputDirRoot, 'repository/contracts/')) } - accurest { + contractVerifier { targetFramework = 'Spock' testMode = 'MockMvc' - baseClassForTests = 'com.blogspot.toomuchcoding.MvcSpec' + baseClassForTests = 'org.springframework.cloud.MvcSpec' contractsDslDir = file("${project.projectDir.absolutePath}/mappings/") generatedTestSourcesDir = file("${project.buildDir}/generated-test-sources/") stubsOutputDir = wireMockStubsOutputDir @@ -122,6 +138,6 @@ configure(project(':loanApplicationService')) { into "src/test/resources/" } - generateAccurest.dependsOn('copyCollaboratorStubs') + generateContractTests.dependsOn('copyCollaboratorStubs') } diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsFraud.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsFraud.groovy new file mode 100644 index 0000000000..91246ddfee --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsFraud.groovy @@ -0,0 +1,44 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import org.springframework.cloud.contract.verifier.dsl.Contract + +Contract.make { + request { + method """PUT""" + url """/fraudcheck""" + body(""" + { + "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", + "loanAmount":99999} + """ + ) + headers { + header("""Content-Type""", """application/vnd.fraud.v1+json""") + } + + } + response { + status 200 + body( """{ + "fraudCheckStatus": "${value(client('FRAUD'), server(regex('[A-Z]{5}')))}", + "rejectionReason": "Amount too high" +}""") + headers { + header('Content-Type': 'application/vnd.fraud.v1+json') + } + } + +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.groovy new file mode 100644 index 0000000000..5a2f1a1312 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.groovy @@ -0,0 +1,45 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import org.springframework.cloud.contract.verifier.dsl.Contract + +Contract.make { + request { + method 'PUT' + url '/fraudcheck' + body(""" + { + "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", + "loanAmount":123.123 + } + """ + ) + headers { + header('Content-Type', 'application/vnd.fraud.v1+json') + } + + } + response { + status 200 + body( + fraudCheckStatus: "OK", + rejectionReason: $(client(null), server(execute('assertThatRejectionReasonIsNull($it)'))) + ) + headers { + header('Content-Type': 'application/vnd.fraud.v1+json') + } + } + +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/org/springframework/frauddetection/Application.java similarity index 72% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/org/springframework/frauddetection/Application.java index 5a1a60244e..bc8131fe49 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/org/springframework/frauddetection/Application.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection; +package org.springframework.cloud.frauddetection; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -11,7 +11,8 @@ import org.springframework.context.annotation.Configuration; public class Application { public static void main(String[] args) { - SpringApplication.run(Application.class, args); + SpringApplication.run( + org.springframework.cloud.frauddetection.Application.class, args); } } diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/FraudDetectionController.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/org/springframework/frauddetection/FraudDetectionController.java similarity index 76% rename from accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/FraudDetectionController.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/org/springframework/frauddetection/FraudDetectionController.java index e264462cce..213a037f87 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/FraudDetectionController.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/org/springframework/frauddetection/FraudDetectionController.java @@ -1,15 +1,15 @@ -package com.blogspot.toomuchcoding.frauddetection; +package org.springframework.cloud.frauddetection; -import com.blogspot.toomuchcoding.frauddetection.model.FraudCheck; -import com.blogspot.toomuchcoding.frauddetection.model.FraudCheckResult; +import org.springframework.cloud.frauddetection.model.FraudCheck; +import org.springframework.cloud.frauddetection.model.FraudCheckResult; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.math.BigDecimal; -import static com.blogspot.toomuchcoding.frauddetection.model.FraudCheckStatus.FRAUD; -import static com.blogspot.toomuchcoding.frauddetection.model.FraudCheckStatus.OK; +import static org.springframework.cloud.frauddetection.model.FraudCheckStatus.FRAUD; +import static org.springframework.cloud.frauddetection.model.FraudCheckStatus.OK; import static org.springframework.web.bind.annotation.RequestMethod.PUT; @RestController diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheck.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/org/springframework/frauddetection/model/FraudCheck.java similarity index 88% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheck.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/org/springframework/frauddetection/model/FraudCheck.java index 77471aee19..72551915bc 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheck.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/org/springframework/frauddetection/model/FraudCheck.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection.model; +package org.springframework.cloud.frauddetection.model; import java.math.BigDecimal; diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckResult.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/org/springframework/frauddetection/model/FraudCheckResult.java similarity index 92% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckResult.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/org/springframework/frauddetection/model/FraudCheckResult.java index 28efc573f5..95fd5e04c4 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckResult.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/org/springframework/frauddetection/model/FraudCheckResult.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection.model; +package org.springframework.cloud.frauddetection.model; public class FraudCheckResult { diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/org/springframework/frauddetection/model/FraudCheckStatus.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/org/springframework/frauddetection/model/FraudCheckStatus.java new file mode 100644 index 0000000000..b4fd951df2 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/org/springframework/frauddetection/model/FraudCheckStatus.java @@ -0,0 +1,5 @@ +package org.springframework.cloud.frauddetection.model; + +public enum FraudCheckStatus { + OK, FRAUD +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/resources/application.yml b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/resources/application.yml similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/resources/application.yml rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/resources/application.yml diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/test/groovy/org/springframework/cloud/MvcSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/test/groovy/org/springframework/cloud/MvcSpec.groovy new file mode 100644 index 0000000000..dfff02db5e --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/test/groovy/org/springframework/cloud/MvcSpec.groovy @@ -0,0 +1,31 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud + +import org.springframework.cloud.frauddetection.FraudDetectionController +import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc +import spock.lang.Specification + +class MvcSpec extends Specification { + def setup() { + RestAssuredMockMvc.standaloneSetup(new FraudDetectionController()) + } + + void assertThatRejectionReasonIsNull(def rejectionReason) { + assert !rejectionReason + } +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/test/java/com/blogspot/toomuchcoding/MvcTest.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/test/java/org/springframework/cloud/MvcTest.java similarity index 63% rename from accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/test/java/com/blogspot/toomuchcoding/MvcTest.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/test/java/org/springframework/cloud/MvcTest.java index 084a65ebf5..8fa2aad6ff 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/test/java/com/blogspot/toomuchcoding/MvcTest.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/test/java/org/springframework/cloud/MvcTest.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding; +package org.springframework.cloud; import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc; import org.junit.Before; @@ -7,7 +7,7 @@ public class MvcTest { @Before public void setup() { - RestAssuredMockMvc.standaloneSetup(new com.blogspot.toomuchcoding.frauddetection.FraudDetectionController()); + RestAssuredMockMvc.standaloneSetup(new org.springframework.cloud.frauddetection.FraudDetectionController()); } public void assertThatRejectionReasonIsNull(Object rejectionReason) { diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/gradle/wrapper/gradle-wrapper.jar b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/gradle/wrapper/gradle-wrapper.jar rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/gradle/wrapper/gradle-wrapper.jar diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/gradle/wrapper/gradle-wrapper.properties b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..1aa6b34ba4 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,22 @@ +# +# Copyright 2013-2016 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +#Wed Jan 28 00:32:44 CET 2015 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/gradlew b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/gradlew similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/gradlew rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/gradlew diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/gradlew.bat b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/gradlew.bat similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/gradlew.bat rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/gradlew.bat diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/mappings/.gitkeep b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/mappings/.gitkeep similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/mappings/.gitkeep rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/mappings/.gitkeep diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/Application.java similarity index 72% rename from accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/Application.java index 5a1a60244e..bc8131fe49 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/Application.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection; +package org.springframework.cloud.frauddetection; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -11,7 +11,8 @@ import org.springframework.context.annotation.Configuration; public class Application { public static void main(String[] args) { - SpringApplication.run(Application.class, args); + SpringApplication.run( + org.springframework.cloud.frauddetection.Application.class, args); } } diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/LoanApplicationService.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/LoanApplicationService.java similarity index 79% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/LoanApplicationService.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/LoanApplicationService.java index a2d8ce1e74..65ec787113 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/LoanApplicationService.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/LoanApplicationService.java @@ -1,11 +1,11 @@ -package com.blogspot.toomuchcoding.frauddetection; +package org.springframework.cloud.frauddetection; -import com.blogspot.toomuchcoding.frauddetection.model.FraudCheckStatus; -import com.blogspot.toomuchcoding.frauddetection.model.FraudServiceRequest; -import com.blogspot.toomuchcoding.frauddetection.model.FraudServiceResponse; -import com.blogspot.toomuchcoding.frauddetection.model.LoanApplication; -import com.blogspot.toomuchcoding.frauddetection.model.LoanApplicationResult; -import com.blogspot.toomuchcoding.frauddetection.model.LoanApplicationStatus; +import org.springframework.cloud.frauddetection.model.FraudCheckStatus; +import org.springframework.cloud.frauddetection.model.FraudServiceRequest; +import org.springframework.cloud.frauddetection.model.FraudServiceResponse; +import org.springframework.cloud.frauddetection.model.LoanApplication; +import org.springframework.cloud.frauddetection.model.LoanApplicationResult; +import org.springframework.cloud.frauddetection.model.LoanApplicationStatus; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/Client.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/Client.java similarity index 73% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/Client.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/Client.java index 5e91273eda..1a85740dde 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/Client.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/Client.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection.model; +package org.springframework.cloud.frauddetection.model; public class Client { diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheckStatus.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheckStatus.java new file mode 100644 index 0000000000..b4fd951df2 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheckStatus.java @@ -0,0 +1,5 @@ +package org.springframework.cloud.frauddetection.model; + +public enum FraudCheckStatus { + OK, FRAUD +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceRequest.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudServiceRequest.java similarity index 91% rename from accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceRequest.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudServiceRequest.java index ac595998bc..f79ff3b740 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceRequest.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudServiceRequest.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection.model; +package org.springframework.cloud.frauddetection.model; import java.math.BigDecimal; diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceResponse.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudServiceResponse.java similarity index 90% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceResponse.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudServiceResponse.java index 9f3353ecbf..dbf8384a53 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceResponse.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudServiceResponse.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection.model; +package org.springframework.cloud.frauddetection.model; public class FraudServiceResponse { diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplication.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplication.java similarity index 91% rename from accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplication.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplication.java index 816087988b..58757331d0 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplication.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplication.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection.model; +package org.springframework.cloud.frauddetection.model; import java.math.BigDecimal; diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationResult.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplicationResult.java similarity index 93% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationResult.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplicationResult.java index 523f4f2ea3..11c3ee1d2c 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationResult.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplicationResult.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection.model; +package org.springframework.cloud.frauddetection.model; public class LoanApplicationResult { diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationStatus.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplicationStatus.java similarity index 58% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationStatus.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplicationStatus.java index 7f7f86e0ea..bdb886d0fc 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationStatus.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplicationStatus.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection.model; +package org.springframework.cloud.frauddetection.model; public enum LoanApplicationStatus { LOAN_APPLIED, LOAN_APPLICATION_REJECTED diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/resources/application.yml b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/resources/application.yml similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/resources/application.yml rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/resources/application.yml diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/test/groovy/com/blogspot/toomuchcoding/LoanApplicationServiceSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/test/groovy/org/springframework/cloud/LoanApplicationServiceSpec.groovy similarity index 58% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/test/groovy/com/blogspot/toomuchcoding/LoanApplicationServiceSpec.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/test/groovy/org/springframework/cloud/LoanApplicationServiceSpec.groovy index 21ee7a4d39..d5104eb499 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/test/groovy/com/blogspot/toomuchcoding/LoanApplicationServiceSpec.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/test/groovy/org/springframework/cloud/LoanApplicationServiceSpec.groovy @@ -1,11 +1,27 @@ -package com.blogspot.toomuchcoding +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import com.blogspot.toomuchcoding.frauddetection.Application -import com.blogspot.toomuchcoding.frauddetection.LoanApplicationService -import com.blogspot.toomuchcoding.frauddetection.model.Client -import com.blogspot.toomuchcoding.frauddetection.model.LoanApplication -import com.blogspot.toomuchcoding.frauddetection.model.LoanApplicationResult -import com.blogspot.toomuchcoding.frauddetection.model.LoanApplicationStatus +package org.springframework.cloud + +import org.springframework.cloud.frauddetection.Application +import org.springframework.cloud.frauddetection.LoanApplicationService +import org.springframework.cloud.frauddetection.model.Client +import org.springframework.cloud.frauddetection.model.LoanApplication +import org.springframework.cloud.frauddetection.model.LoanApplicationResult +import org.springframework.cloud.frauddetection.model.LoanApplicationStatus import com.github.tomakehurst.wiremock.junit.WireMockClassRule import org.junit.ClassRule import org.springframework.beans.factory.annotation.Autowired diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsFraud.json b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsFraud.json similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsFraud.json rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsFraud.json diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.json b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.json similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.json rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.json diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/settings.gradle b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/settings.gradle new file mode 100644 index 0000000000..48db488159 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/sampleProject/settings.gradle @@ -0,0 +1,18 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +include ':fraudDetectionService' +include ':loanApplicationService' diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/build.gradle b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/build.gradle similarity index 76% rename from accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/build.gradle rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/build.gradle index 6b72e88a6a..75060f4740 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/build.gradle +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/build.gradle @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + buildscript { repositories { mavenCentral() @@ -13,10 +29,10 @@ ext { spockVersion = '1.0-groovy-2.4' wiremockVersion = '2.0.10-beta' - accurestStubsBaseDirectory = 'src/test/resources/stubs' + contractVerifierStubsBaseDirectory = 'src/test/resources/stubs' } -group = 'io.codearte.accurest.testprojects' +group = 'org.springframework.cloud.testprojects' subprojects { apply plugin: 'groovy' @@ -37,14 +53,14 @@ subprojects { configure([project(':fraudDetectionService'), project(':loanApplicationService')]) { apply plugin: 'spring-boot' - apply plugin: 'accurest' + apply plugin: 'contract-verifier' // tag::jar_setup[] ext { contractsDir = file("mappings") stubsOutputDirRoot = file("${project.buildDir}/production/${project.name}-stubs/") wireMockStubsOutputDir = file(new File(stubsOutputDirRoot, 'repository/mappings/')) - contractsOutputDir = file(new File(stubsOutputDirRoot, 'repository/accurest/')) + contractsOutputDir = file(new File(stubsOutputDirRoot, 'repository/contracts/')) } task copyContracts(type: Copy) { @@ -73,12 +89,12 @@ configure([project(':fraudDetectionService'), project(':loanApplicationService') } // end::jar_setup[] - accurest { + contractVerifier { // tag::target_framework[] targetFramework = 'Spock' // end::target_framework[] testMode = 'MockMvc' - baseClassForTests = 'com.blogspot.toomuchcoding.MvcSpec' + baseClassForTests = 'org.springframework.cloud.MvcSpec' contractsDslDir = file("${project.projectDir.absolutePath}/mappings/") generatedTestSourcesDir = file("${project.buildDir}/generated-test-sources/") stubsOutputDir = wireMockStubsOutputDir @@ -126,6 +142,6 @@ configure(project(':loanApplicationService')) { into "src/test/resources/" } - generateAccurest.dependsOn('copyCollaboratorStubs') + generateContractTests.dependsOn('copyCollaboratorStubs') } diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/1_shouldMarkClientAsNotFraud.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/1_shouldMarkClientAsNotFraud.groovy new file mode 100644 index 0000000000..5a2f1a1312 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/1_shouldMarkClientAsNotFraud.groovy @@ -0,0 +1,45 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import org.springframework.cloud.contract.verifier.dsl.Contract + +Contract.make { + request { + method 'PUT' + url '/fraudcheck' + body(""" + { + "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", + "loanAmount":123.123 + } + """ + ) + headers { + header('Content-Type', 'application/vnd.fraud.v1+json') + } + + } + response { + status 200 + body( + fraudCheckStatus: "OK", + rejectionReason: $(client(null), server(execute('assertThatRejectionReasonIsNull($it)'))) + ) + headers { + header('Content-Type': 'application/vnd.fraud.v1+json') + } + } + +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/2_shouldMarkClientAsFraud.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/2_shouldMarkClientAsFraud.groovy new file mode 100644 index 0000000000..2634bca6cc --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/2_shouldMarkClientAsFraud.groovy @@ -0,0 +1,45 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.springframework.cloud.contract.verifier.dsl.Contract + +Contract.make { + request { + method """PUT""" + url """/fraudcheck""" + body(""" + { + "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", + "loanAmount":99999} + """ + ) + headers { + header("""Content-Type""", """application/vnd.fraud.v1+json""") + } + + } + response { + status 200 + body( """{ + "fraudCheckStatus": "${value(client('FRAUD'), server(regex('[A-Z]{5}')))}", + "rejectionReason": "Amount too high" +}""") + headers { + header('Content-Type': 'application/vnd.fraud.v1+json') + } + } + +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/Application.java similarity index 72% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/Application.java index 5a1a60244e..bc8131fe49 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/Application.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection; +package org.springframework.cloud.frauddetection; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -11,7 +11,8 @@ import org.springframework.context.annotation.Configuration; public class Application { public static void main(String[] args) { - SpringApplication.run(Application.class, args); + SpringApplication.run( + org.springframework.cloud.frauddetection.Application.class, args); } } diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/FraudDetectionController.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/FraudDetectionController.java similarity index 76% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/FraudDetectionController.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/FraudDetectionController.java index e264462cce..213a037f87 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/FraudDetectionController.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/FraudDetectionController.java @@ -1,15 +1,15 @@ -package com.blogspot.toomuchcoding.frauddetection; +package org.springframework.cloud.frauddetection; -import com.blogspot.toomuchcoding.frauddetection.model.FraudCheck; -import com.blogspot.toomuchcoding.frauddetection.model.FraudCheckResult; +import org.springframework.cloud.frauddetection.model.FraudCheck; +import org.springframework.cloud.frauddetection.model.FraudCheckResult; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.math.BigDecimal; -import static com.blogspot.toomuchcoding.frauddetection.model.FraudCheckStatus.FRAUD; -import static com.blogspot.toomuchcoding.frauddetection.model.FraudCheckStatus.OK; +import static org.springframework.cloud.frauddetection.model.FraudCheckStatus.FRAUD; +import static org.springframework.cloud.frauddetection.model.FraudCheckStatus.OK; import static org.springframework.web.bind.annotation.RequestMethod.PUT; @RestController diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheck.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheck.java similarity index 88% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheck.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheck.java index 77471aee19..72551915bc 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheck.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheck.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection.model; +package org.springframework.cloud.frauddetection.model; import java.math.BigDecimal; diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckResult.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheckResult.java similarity index 92% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckResult.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheckResult.java index 28efc573f5..95fd5e04c4 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckResult.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheckResult.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection.model; +package org.springframework.cloud.frauddetection.model; public class FraudCheckResult { diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheckStatus.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheckStatus.java new file mode 100644 index 0000000000..b4fd951df2 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheckStatus.java @@ -0,0 +1,5 @@ +package org.springframework.cloud.frauddetection.model; + +public enum FraudCheckStatus { + OK, FRAUD +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/resources/application.yml b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/resources/application.yml similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/resources/application.yml rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/resources/application.yml diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/test/groovy/org/springframework/cloud/MvcSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/test/groovy/org/springframework/cloud/MvcSpec.groovy new file mode 100644 index 0000000000..dfff02db5e --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/test/groovy/org/springframework/cloud/MvcSpec.groovy @@ -0,0 +1,31 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud + +import org.springframework.cloud.frauddetection.FraudDetectionController +import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc +import spock.lang.Specification + +class MvcSpec extends Specification { + def setup() { + RestAssuredMockMvc.standaloneSetup(new FraudDetectionController()) + } + + void assertThatRejectionReasonIsNull(def rejectionReason) { + assert !rejectionReason + } +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/test/java/com/blogspot/toomuchcoding/MvcTest.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/test/java/org/springframework/cloud/MvcTest.java similarity index 63% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/test/java/com/blogspot/toomuchcoding/MvcTest.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/test/java/org/springframework/cloud/MvcTest.java index 084a65ebf5..8fa2aad6ff 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/test/java/com/blogspot/toomuchcoding/MvcTest.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/test/java/org/springframework/cloud/MvcTest.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding; +package org.springframework.cloud; import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc; import org.junit.Before; @@ -7,7 +7,7 @@ public class MvcTest { @Before public void setup() { - RestAssuredMockMvc.standaloneSetup(new com.blogspot.toomuchcoding.frauddetection.FraudDetectionController()); + RestAssuredMockMvc.standaloneSetup(new org.springframework.cloud.frauddetection.FraudDetectionController()); } public void assertThatRejectionReasonIsNull(Object rejectionReason) { diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradle/wrapper/gradle-wrapper.jar b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradle/wrapper/gradle-wrapper.jar rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradle/wrapper/gradle-wrapper.jar diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradle/wrapper/gradle-wrapper.properties b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..1aa6b34ba4 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,22 @@ +# +# Copyright 2013-2016 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +#Wed Jan 28 00:32:44 CET 2015 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradlew b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradlew similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradlew rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradlew diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradlew.bat b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradlew.bat similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradlew.bat rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradlew.bat diff --git a/stub-runner/stub-runner/src/test/resources/emptyrepo/.gitkeep b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/mappings/.gitkeep similarity index 100% rename from stub-runner/stub-runner/src/test/resources/emptyrepo/.gitkeep rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/mappings/.gitkeep diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/Application.java similarity index 72% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/Application.java index 5a1a60244e..bc8131fe49 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/Application.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection; +package org.springframework.cloud.frauddetection; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -11,7 +11,8 @@ import org.springframework.context.annotation.Configuration; public class Application { public static void main(String[] args) { - SpringApplication.run(Application.class, args); + SpringApplication.run( + org.springframework.cloud.frauddetection.Application.class, args); } } diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/LoanApplicationService.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/LoanApplicationService.java similarity index 79% rename from accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/LoanApplicationService.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/LoanApplicationService.java index a2d8ce1e74..65ec787113 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/LoanApplicationService.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/LoanApplicationService.java @@ -1,11 +1,11 @@ -package com.blogspot.toomuchcoding.frauddetection; +package org.springframework.cloud.frauddetection; -import com.blogspot.toomuchcoding.frauddetection.model.FraudCheckStatus; -import com.blogspot.toomuchcoding.frauddetection.model.FraudServiceRequest; -import com.blogspot.toomuchcoding.frauddetection.model.FraudServiceResponse; -import com.blogspot.toomuchcoding.frauddetection.model.LoanApplication; -import com.blogspot.toomuchcoding.frauddetection.model.LoanApplicationResult; -import com.blogspot.toomuchcoding.frauddetection.model.LoanApplicationStatus; +import org.springframework.cloud.frauddetection.model.FraudCheckStatus; +import org.springframework.cloud.frauddetection.model.FraudServiceRequest; +import org.springframework.cloud.frauddetection.model.FraudServiceResponse; +import org.springframework.cloud.frauddetection.model.LoanApplication; +import org.springframework.cloud.frauddetection.model.LoanApplicationResult; +import org.springframework.cloud.frauddetection.model.LoanApplicationStatus; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/Client.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/Client.java similarity index 73% rename from accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/Client.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/Client.java index 5e91273eda..1a85740dde 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/Client.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/Client.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection.model; +package org.springframework.cloud.frauddetection.model; public class Client { diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheckStatus.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheckStatus.java new file mode 100644 index 0000000000..b4fd951df2 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudCheckStatus.java @@ -0,0 +1,5 @@ +package org.springframework.cloud.frauddetection.model; + +public enum FraudCheckStatus { + OK, FRAUD +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceRequest.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudServiceRequest.java similarity index 91% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceRequest.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudServiceRequest.java index ac595998bc..f79ff3b740 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceRequest.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudServiceRequest.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection.model; +package org.springframework.cloud.frauddetection.model; import java.math.BigDecimal; diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceResponse.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudServiceResponse.java similarity index 90% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceResponse.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudServiceResponse.java index 9f3353ecbf..dbf8384a53 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceResponse.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/FraudServiceResponse.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection.model; +package org.springframework.cloud.frauddetection.model; public class FraudServiceResponse { diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplication.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplication.java similarity index 91% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplication.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplication.java index 816087988b..58757331d0 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplication.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplication.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection.model; +package org.springframework.cloud.frauddetection.model; import java.math.BigDecimal; diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationResult.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplicationResult.java similarity index 93% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationResult.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplicationResult.java index 523f4f2ea3..11c3ee1d2c 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationResult.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplicationResult.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection.model; +package org.springframework.cloud.frauddetection.model; public class LoanApplicationResult { diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationStatus.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplicationStatus.java similarity index 58% rename from accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationStatus.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplicationStatus.java index 7f7f86e0ea..bdb886d0fc 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/sampleProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationStatus.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/org/springframework/cloud/frauddetection/model/LoanApplicationStatus.java @@ -1,4 +1,4 @@ -package com.blogspot.toomuchcoding.frauddetection.model; +package org.springframework.cloud.frauddetection.model; public enum LoanApplicationStatus { LOAN_APPLIED, LOAN_APPLICATION_REJECTED diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/resources/application.yml b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/resources/application.yml similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/resources/application.yml rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/resources/application.yml diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/groovy/com/blogspot/toomuchcoding/LoanApplicationServiceSpec.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/groovy/org/springframework/cloud/LoanApplicationServiceSpec.groovy similarity index 59% rename from accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/groovy/com/blogspot/toomuchcoding/LoanApplicationServiceSpec.groovy rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/groovy/org/springframework/cloud/LoanApplicationServiceSpec.groovy index 5a7d0ae9a9..eae9a5c817 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/groovy/com/blogspot/toomuchcoding/LoanApplicationServiceSpec.groovy +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/groovy/org/springframework/cloud/LoanApplicationServiceSpec.groovy @@ -1,11 +1,27 @@ -package com.blogspot.toomuchcoding +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import com.blogspot.toomuchcoding.frauddetection.Application -import com.blogspot.toomuchcoding.frauddetection.LoanApplicationService -import com.blogspot.toomuchcoding.frauddetection.model.Client -import com.blogspot.toomuchcoding.frauddetection.model.LoanApplication -import com.blogspot.toomuchcoding.frauddetection.model.LoanApplicationResult -import com.blogspot.toomuchcoding.frauddetection.model.LoanApplicationStatus +package org.springframework.cloud + +import org.springframework.cloud.frauddetection.Application +import org.springframework.cloud.frauddetection.LoanApplicationService +import org.springframework.cloud.frauddetection.model.Client +import org.springframework.cloud.frauddetection.model.LoanApplication +import org.springframework.cloud.frauddetection.model.LoanApplicationResult +import org.springframework.cloud.frauddetection.model.LoanApplicationStatus import com.github.tomakehurst.wiremock.junit.WireMockClassRule import org.junit.ClassRule import org.springframework.beans.factory.annotation.Autowired diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsFraud.json b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsFraud.json similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsFraud.json rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsFraud.json diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.json b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.json similarity index 100% rename from accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.json rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.json diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/settings.gradle b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/settings.gradle new file mode 100644 index 0000000000..48db488159 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-gradle-plugin/src/test/resources/functionalTest/scenarioProject/settings.gradle @@ -0,0 +1,18 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +include ':fraudDetectionService' +include ':loanApplicationService' diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/README.adoc b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/README.adoc new file mode 100644 index 0000000000..2488410263 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/README.adoc @@ -0,0 +1,23 @@ + = Spring Cloud Contract Verifier Messaging + +Spring Cloud Contract Verifier allows you to verify your application that uses messaging as means of communication. +All of our integrations are working with Spring but you can also set one yourself. + +== Integrations + +You can use one of the three integration configurations: + +- Apache Camel +- Spring Integration +- Spring Cloud Stream + +If you're using Spring Boot, the aforementioned test configurations will be appended automatically. + +== Manual Integration + +The `spring-cloud-contract-verifier-messaging-core` module contains 3 main interfaces: + +- `ContractVerifierMessage` - describes a message received / sent to a channel / queue / topic etc. +- `ContractVerifierMessageBuilder` - describes how to build a message +- `ContractVerifierMessaging` - class that allows you to build, send and receive messages + diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-camel/build.gradle b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-camel/build.gradle new file mode 100644 index 0000000000..dc27dcd2b2 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-camel/build.gradle @@ -0,0 +1,34 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +repositories { + mavenLocal() + jcenter() + maven { + url "http://repo.spring.io/snapshot" + } + maven { + url "http://repo.spring.io/milestone" + } +} + +String verifier = "spring-cloud-contract-verifier" + +dependencies { + compile project(":$verifier-root:$verifier-messaging-root:$verifier-messaging-core") + compile "org.apache.camel:camel-spring:${camelVersion}" + compile 'org.slf4j:slf4j-api:1.6.0' +} \ No newline at end of file diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-camel/src/main/java/org/springframework/cloud/contract/verifier/messaging/camel/CamelMessage.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-camel/src/main/java/org/springframework/cloud/contract/verifier/messaging/camel/CamelMessage.java new file mode 100644 index 0000000000..1d4a94257d --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-camel/src/main/java/org/springframework/cloud/contract/verifier/messaging/camel/CamelMessage.java @@ -0,0 +1,56 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.messaging.camel; + +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage; +import org.apache.camel.Message; + +import java.util.Map; + +/** + * @author Marcin Grzejszczak + */ +public class CamelMessage implements ContractVerifierMessage { + + private final Message delegate; + + public CamelMessage(Message delegate) { + this.delegate = delegate; + } + + @Override + @SuppressWarnings("unchecked") + public T getPayload() { + return (T) delegate.getBody(); + } + + @Override + public Map getHeaders() { + return delegate.getHeaders(); + } + + @Override + public Object getHeader(String key) { + return getHeaders().get(key); + } + + @Override + public Message convert() { + return delegate; + } + +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-camel/src/main/java/org/springframework/cloud/contract/verifier/messaging/camel/ContractVerifierCamelConfiguration.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-camel/src/main/java/org/springframework/cloud/contract/verifier/messaging/camel/ContractVerifierCamelConfiguration.java new file mode 100644 index 0000000000..71280d4700 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-camel/src/main/java/org/springframework/cloud/contract/verifier/messaging/camel/ContractVerifierCamelConfiguration.java @@ -0,0 +1,37 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.messaging.camel; + +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessageBuilder; +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging; +import org.apache.camel.CamelContext; +import org.springframework.context.annotation.Bean; + +/** + * @author Marcin Grzejszczak + */ +public class ContractVerifierCamelConfiguration { + + @Bean ContractVerifierMessaging contractVerifierMessaging(CamelContext context, + ContractVerifierMessageBuilder builder) { + return new ContractVerifierCamelMessaging(context, builder); + } + + @Bean ContractVerifierMessageBuilder contractVerifierMessageBuilder() { + return new ContractVerifierCamelMessageBuilder(); + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-camel/src/main/java/org/springframework/cloud/contract/verifier/messaging/camel/ContractVerifierCamelMessageBuilder.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-camel/src/main/java/org/springframework/cloud/contract/verifier/messaging/camel/ContractVerifierCamelMessageBuilder.java new file mode 100644 index 0000000000..77aa4f2c91 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-camel/src/main/java/org/springframework/cloud/contract/verifier/messaging/camel/ContractVerifierCamelMessageBuilder.java @@ -0,0 +1,48 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.messaging.camel; + +import java.util.Map; + +import org.apache.camel.Message; +import org.apache.camel.impl.DefaultMessage; +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage; + +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessageBuilder; + +/** + * @author Marcin Grzejszczak + */ +public class ContractVerifierCamelMessageBuilder implements + ContractVerifierMessageBuilder { + + @Override + public ContractVerifierMessage create(T payload, Map headers) { + DefaultMessage message = new DefaultMessage(); + message.setBody(payload); + message.setHeaders(headers); + return new CamelMessage<>(message); + } + + @Override + public ContractVerifierMessage create(Message message) { + if (message == null) { + return null; + } + return new CamelMessage<>(message); + } +} diff --git a/accurest-messaging/accurest-messaging-camel/src/main/java/io/codearte/accurest/messaging/camel/AccurestCamelMessaging.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-camel/src/main/java/org/springframework/cloud/contract/verifier/messaging/camel/ContractVerifierCamelMessaging.java similarity index 51% rename from accurest-messaging/accurest-messaging-camel/src/main/java/io/codearte/accurest/messaging/camel/AccurestCamelMessaging.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-camel/src/main/java/org/springframework/cloud/contract/verifier/messaging/camel/ContractVerifierCamelMessaging.java index 914d962f47..14b0a7db36 100644 --- a/accurest-messaging/accurest-messaging-camel/src/main/java/io/codearte/accurest/messaging/camel/AccurestCamelMessaging.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-camel/src/main/java/org/springframework/cloud/contract/verifier/messaging/camel/ContractVerifierCamelMessaging.java @@ -1,4 +1,20 @@ -package io.codearte.accurest.messaging.camel; +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.messaging.camel; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -12,32 +28,34 @@ import org.apache.camel.impl.DefaultExchange; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging; import org.springframework.stereotype.Component; -import io.codearte.accurest.messaging.AccurestMessage; -import io.codearte.accurest.messaging.AccurestMessageBuilder; -import io.codearte.accurest.messaging.AccurestMessaging; +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage; +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessageBuilder; /** * @author Marcin Grzejszczak */ @Component -public class AccurestCamelMessaging implements AccurestMessaging { +public class ContractVerifierCamelMessaging implements + ContractVerifierMessaging { - private static final Logger log = LoggerFactory.getLogger(AccurestCamelMessaging.class); + private static final Logger log = LoggerFactory.getLogger( + ContractVerifierCamelMessaging.class); private final CamelContext context; - private final AccurestMessageBuilder builder; + private final ContractVerifierMessageBuilder builder; @Autowired @SuppressWarnings("unchecked") - public AccurestCamelMessaging(CamelContext context, AccurestMessageBuilder accurestMessageBuilder) { + public ContractVerifierCamelMessaging(CamelContext context, ContractVerifierMessageBuilder contractVerifierMessageBuilder) { this.context = context; - this.builder = accurestMessageBuilder; + this.builder = contractVerifierMessageBuilder; } @Override - public void send(AccurestMessage message, String destination) { + public void send(ContractVerifierMessage message, String destination) { try { ProducerTemplate producerTemplate = context.createProducerTemplate(); Exchange exchange = new DefaultExchange(context); @@ -58,7 +76,7 @@ public class AccurestCamelMessaging implements AccurestMessaging @Override @SuppressWarnings("unchecked") - public AccurestMessage receiveMessage(String destination, long timeout, TimeUnit timeUnit) { + public ContractVerifierMessage receiveMessage(String destination, long timeout, TimeUnit timeUnit) { try { ConsumerTemplate consumerTemplate = context.createConsumerTemplate(); Exchange exchange = consumerTemplate.receive(destination, timeUnit.toMillis(timeout)); @@ -71,19 +89,19 @@ public class AccurestCamelMessaging implements AccurestMessaging } @Override - public AccurestMessage receiveMessage(String destination) { + public ContractVerifierMessage receiveMessage(String destination) { return receiveMessage(destination, 5, TimeUnit.SECONDS); } @Override @SuppressWarnings("unchecked") - public AccurestMessage create(T t, Map headers) { + public ContractVerifierMessage create(T t, Map headers) { return builder.create(t, headers); } @Override @SuppressWarnings("unchecked") - public AccurestMessage create(Message message) { + public ContractVerifierMessage create(Message message) { return builder.create(message); } } diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-camel/src/main/resources/META-INF/spring.factories b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-camel/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000000..4515c7bbdb --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-camel/src/main/resources/META-INF/spring.factories @@ -0,0 +1,3 @@ +# Auto Configuration +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.springframework.cloud.contract.verifier.messaging.camel.ContractVerifierCamelConfiguration diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-integration/build.gradle b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-integration/build.gradle new file mode 100644 index 0000000000..b69c26a76c --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-integration/build.gradle @@ -0,0 +1,34 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +String verifier = "spring-cloud-contract-verifier" + +repositories { + mavenLocal() + jcenter() + maven { + url "http://repo.spring.io/snapshot" + } + maven { + url "http://repo.spring.io/milestone" + } +} + +dependencies { + compile project(":$verifier-root:$verifier-messaging-root:$verifier-messaging-core") + compile "org.springframework:spring-messaging:${springVersion}" + compile 'org.slf4j:slf4j-api:1.6.0' +} \ No newline at end of file diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-integration/src/main/java/org/springframework/cloud/contract/verifier/messaging/integration/ContractVerifierIntegrationConfiguration.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-integration/src/main/java/org/springframework/cloud/contract/verifier/messaging/integration/ContractVerifierIntegrationConfiguration.java new file mode 100644 index 0000000000..3f1ddc2c97 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-integration/src/main/java/org/springframework/cloud/contract/verifier/messaging/integration/ContractVerifierIntegrationConfiguration.java @@ -0,0 +1,36 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.messaging.integration; + +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessageBuilder; +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; + +/** + * @author Marcin Grzejszczak + */ +public class ContractVerifierIntegrationConfiguration { + + @Bean ContractVerifierMessaging contractVerifierMessaging(ApplicationContext applicationContext, ContractVerifierMessageBuilder contractVerifierMessageBuilder) { + return new ContractVerifierIntegrationMessaging(applicationContext, contractVerifierMessageBuilder); + } + + @Bean ContractVerifierMessageBuilder contractVerifierMessageBuilder() { + return new ContractVerifierIntegrationMessageBuilder(); + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-integration/src/main/java/org/springframework/cloud/contract/verifier/messaging/integration/ContractVerifierIntegrationMessageBuilder.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-integration/src/main/java/org/springframework/cloud/contract/verifier/messaging/integration/ContractVerifierIntegrationMessageBuilder.java new file mode 100644 index 0000000000..60f10b1493 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-integration/src/main/java/org/springframework/cloud/contract/verifier/messaging/integration/ContractVerifierIntegrationMessageBuilder.java @@ -0,0 +1,45 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.messaging.integration; + +import java.util.Map; + +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage; +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessageBuilder; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageHeaders; +import org.springframework.messaging.support.MessageBuilder; + +/** + * @author Marcin Grzejszczak + */ +public class ContractVerifierIntegrationMessageBuilder implements + ContractVerifierMessageBuilder> { + + @Override + public ContractVerifierMessage> create(T payload, Map headers) { + return new IntegrationMessage<>(MessageBuilder.createMessage(payload, new MessageHeaders(headers))); + } + + @Override + public ContractVerifierMessage> create(Message message) { + if (message == null) { + return null; + } + return new IntegrationMessage<>(message); + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-integration/src/main/java/org/springframework/cloud/contract/verifier/messaging/integration/ContractVerifierIntegrationMessaging.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-integration/src/main/java/org/springframework/cloud/contract/verifier/messaging/integration/ContractVerifierIntegrationMessaging.java new file mode 100644 index 0000000000..960e07d520 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-integration/src/main/java/org/springframework/cloud/contract/verifier/messaging/integration/ContractVerifierIntegrationMessaging.java @@ -0,0 +1,102 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.messaging.integration; + +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging; +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessageBuilder; +import org.springframework.context.ApplicationContext; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.PollableChannel; +import org.springframework.stereotype.Component; + +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage; + +/** + * @author Marcin Grzejszczak + */ +@Component +public class ContractVerifierIntegrationMessaging implements + ContractVerifierMessaging> { + + private static final Logger log = LoggerFactory.getLogger( + ContractVerifierIntegrationMessaging.class); + + private final ApplicationContext context; + private final ContractVerifierMessageBuilder builder; + + @Autowired + @SuppressWarnings("unchecked") + public ContractVerifierIntegrationMessaging(ApplicationContext context, ContractVerifierMessageBuilder contractVerifierMessageBuilder) { + this.context = context; + this.builder = contractVerifierMessageBuilder; + } + + @Override + @SuppressWarnings("unchecked") + public void send(T payload, Map headers, String destination) { + send(builder.create(payload, headers), destination); + } + + @Override + public void send(ContractVerifierMessage> message, String destination) { + try { + MessageChannel messageChannel = context.getBean(destination, MessageChannel.class); + messageChannel.send(message.convert()); + } catch (Exception e) { + log.error("Exception occurred while trying to send a message [" + message + "] " + + "to a channel with name [" + destination + "]", e); + throw e; + } + } + + @Override + @SuppressWarnings("unchecked") + public ContractVerifierMessage> receiveMessage(String destination, long timeout, TimeUnit timeUnit) { + try { + PollableChannel messageChannel = context.getBean(destination, PollableChannel.class); + return builder.create(messageChannel.receive(timeUnit.toMillis(timeout))); + } catch (Exception e) { + log.error("Exception occurred while trying to read a message from " + + " a channel with name [" + destination + "]", e); + throw new RuntimeException(e); + } + } + + @Override + public ContractVerifierMessage> receiveMessage(String destination) { + return receiveMessage(destination, 5, TimeUnit.SECONDS); + } + + @Override + @SuppressWarnings("unchecked") + public ContractVerifierMessage> create(T t, Map headers) { + return builder.create(t, headers); + } + + @Override + @SuppressWarnings("unchecked") + public ContractVerifierMessage> create(Message message) { + return builder.create(message); + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-integration/src/main/java/org/springframework/cloud/contract/verifier/messaging/integration/IntegrationMessage.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-integration/src/main/java/org/springframework/cloud/contract/verifier/messaging/integration/IntegrationMessage.java new file mode 100644 index 0000000000..b75e92eb69 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-integration/src/main/java/org/springframework/cloud/contract/verifier/messaging/integration/IntegrationMessage.java @@ -0,0 +1,54 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.messaging.integration; + +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageHeaders; + +/** + * @author Marcin Grzejszczak + */ +public class IntegrationMessage implements ContractVerifierMessage> { + + private final Message delegate; + + public IntegrationMessage(Message delegate) { + this.delegate = delegate; + } + + @Override + public T getPayload() { + return delegate.getPayload(); + } + + @Override + public MessageHeaders getHeaders() { + return delegate.getHeaders(); + } + + @Override + public Object getHeader(String key) { + return getHeaders().get(key); + } + + @Override + public Message convert() { + return delegate; + } + +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-integration/src/main/resources/META-INF/spring.factories b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-integration/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000000..2251d19bd0 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-integration/src/main/resources/META-INF/spring.factories @@ -0,0 +1,3 @@ +# Auto Configuration +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.springframework.cloud.contract.verifier.messaging.integration.ContractVerifierIntegrationConfiguration diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/build.gradle b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/build.gradle new file mode 100644 index 0000000000..068826284e --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/build.gradle @@ -0,0 +1,24 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +repositories { + jcenter() +} + +dependencies { + compile 'com.fasterxml.jackson.core:jackson-databind:2.7.0' + compile 'javax.inject:javax.inject:1' +} \ No newline at end of file diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/ContractVerifierFilter.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/ContractVerifierFilter.java new file mode 100644 index 0000000000..3c864f1bee --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/ContractVerifierFilter.java @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.messaging; + +/** + * Contract for filtering out messages that do not match the structure in the Contract DSL + * + * @author Marcin Grzejszczak + */ +public interface ContractVerifierFilter { + + /** + * @return @{code true} if the message should be passed through, @{code false} if the message should be filtered out, + */ + boolean matches(ContractVerifierMessage message); +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/ContractVerifierMessage.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/ContractVerifierMessage.java new file mode 100644 index 0000000000..c8510cd526 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/ContractVerifierMessage.java @@ -0,0 +1,48 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.messaging; + +import java.util.Map; + +/** + * Describes a message. Contains payload and headers. A message can be converted + * to another type (e.g. Spring Messaging Message) + * + * @author Marcin Grzejszczak + */ +public interface ContractVerifierMessage { + + /** + * Returns a payload of type {@code PAYLOAD} + */ + PAYLOAD getPayload(); + + /** + * Returns a map of headers + */ + Map getHeaders(); + + /** + * Returns a header for a given key + */ + Object getHeader(String key); + + /** + * Converts the message to {@code TYPE_TO_CONVERT_INTO} type + */ + TYPE_TO_CONVERT_INTO convert(); +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/ContractVerifierMessageBuilder.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/ContractVerifierMessageBuilder.java new file mode 100644 index 0000000000..7325ac29de --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/ContractVerifierMessageBuilder.java @@ -0,0 +1,38 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.messaging; + +import java.util.Map; + +/** + * Contract for creation of (@link ContractVerifierMessage}. You can create a message from + * payload and headers or from some type (e.g. Spring Messaging Message). + * + * @author Marcin Grzejszczak + */ +public interface ContractVerifierMessageBuilder { + + /** + * Creates a {@link ContractVerifierMessage} from payload and headers + */ + ContractVerifierMessage create(PAYLOAD payload, Map headers); + + /** + * Creates a {@link ContractVerifierMessage} from the {@code TYPE_TO_CONVERT_INTO} type + */ + ContractVerifierMessage create(TYPE_TO_CONVERT_INTO typeToConvertInto); +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/ContractVerifierMessaging.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/ContractVerifierMessaging.java new file mode 100644 index 0000000000..01c377aa8f --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/ContractVerifierMessaging.java @@ -0,0 +1,51 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.messaging; + +import java.util.Map; +import java.util.concurrent.TimeUnit; + +/** + * Core interface that allows you to build, send and receive messages. + * + * Destination is relevant to the underlaying implementation. Might be a channel, queue, topic etc. + * + * @author Marcin Grzejszczak + */ +public interface ContractVerifierMessaging extends + ContractVerifierMessageBuilder { + /** + * Sends the {@link ContractVerifierMessage} to the given destination. + */ + void send(ContractVerifierMessage message, String destination); + + /** + * Sends the given payload with headers, to the given destination. + */ + void send(PAYLOAD payload, Map headers, String destination); + + /** + * Receives the {@link ContractVerifierMessage} from the given destination. You can provide the timeout + * for receiving that message. + */ + ContractVerifierMessage receiveMessage(String destination, long timeout, TimeUnit timeUnit); + + /** + * Receives the {@link ContractVerifierMessage} from the given destination. A default timeout will be applied. + */ + ContractVerifierMessage receiveMessage(String destination); +} diff --git a/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/AccurestMessagingUtil.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/ContractVerifierMessagingUtil.java similarity index 60% rename from accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/AccurestMessagingUtil.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/ContractVerifierMessagingUtil.java index d2749c03ea..18de368aa5 100644 --- a/accurest-messaging/accurest-messaging-core/src/main/java/io/codearte/accurest/messaging/AccurestMessagingUtil.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/ContractVerifierMessagingUtil.java @@ -1,4 +1,20 @@ -package io.codearte.accurest.messaging; +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.messaging; import java.util.Collection; import java.util.HashMap; @@ -10,17 +26,17 @@ import java.util.Set; * * @author Marcin Grzejszczak */ -public class AccurestMessagingUtil { +public class ContractVerifierMessagingUtil { - public static AccurestHeaders headers() { - return new AccurestHeaders(); + public static ContractVerifierHeaders headers() { + return new ContractVerifierHeaders(); } - public static class AccurestHeaders implements Map { + public static class ContractVerifierHeaders implements Map { private final Map delegate = new HashMap<>(); - public AccurestHeaders header(String key, Object value) { + public ContractVerifierHeaders header(String key, Object value) { put(key, value); return this; } diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/ContractVerifierObjectMapper.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/ContractVerifierObjectMapper.java new file mode 100644 index 0000000000..dfbdcf461d --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/ContractVerifierObjectMapper.java @@ -0,0 +1,46 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.messaging; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Wrapper over {@link ObjectMapper} that won't try to parse + * String but will directly return it. + * + * @author Marcin Grzejszczak + */ +public class ContractVerifierObjectMapper { + + private final ObjectMapper objectMapper; + + public ContractVerifierObjectMapper(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + + public ContractVerifierObjectMapper() { + this.objectMapper = new ObjectMapper(); + } + + public String writeValueAsString(Object payload) throws JsonProcessingException { + if (payload instanceof String) { + return payload.toString(); + } + return objectMapper.writeValueAsString(payload); + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/noop/NoOpContractVerifierMessage.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/noop/NoOpContractVerifierMessage.java new file mode 100644 index 0000000000..c7c37514d5 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/noop/NoOpContractVerifierMessage.java @@ -0,0 +1,46 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.messaging.noop; + +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage; + +import java.util.Map; + +/** + * @author Marcin Grzejszczak + */ +public class NoOpContractVerifierMessage implements ContractVerifierMessage { + @Override + public Object getPayload() { + return null; + } + + @Override + public Map getHeaders() { + return null; + } + + @Override + public Object getHeader(String key) { + return null; + } + + @Override + public Object convert() { + return null; + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/noop/NoOpContractVerifierMessageBuilder.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/noop/NoOpContractVerifierMessageBuilder.java new file mode 100644 index 0000000000..edd9a3142c --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/noop/NoOpContractVerifierMessageBuilder.java @@ -0,0 +1,38 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.messaging.noop; + +import java.util.Map; + +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage; +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessageBuilder; + +/** + * @author Marcin Grzejszczak + */ +public class NoOpContractVerifierMessageBuilder + implements ContractVerifierMessageBuilder { + @Override + public ContractVerifierMessage create(Object o, Map headers) { + return new NoOpContractVerifierMessage(); + } + + @Override + public ContractVerifierMessage create(Object o) { + return new NoOpContractVerifierMessage(); + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/noop/NoOpContractVerifierMessaging.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/noop/NoOpContractVerifierMessaging.java new file mode 100644 index 0000000000..da28a92d56 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-messaging-core/src/main/java/org/springframework/cloud/contract/verifier/messaging/noop/NoOpContractVerifierMessaging.java @@ -0,0 +1,58 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.messaging.noop; + +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage; +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging; + +/** + * @author Marcin Grzejszczak + */ +public class NoOpContractVerifierMessaging implements ContractVerifierMessaging { + @Override + public void send(ContractVerifierMessage message, String destination) { + + } + + @Override + public void send(Object payload, Map headers, String destination) { + + } + + @Override + public ContractVerifierMessage receiveMessage(String destination, long timeout, TimeUnit timeUnit) { + return null; + } + + @Override + public ContractVerifierMessage receiveMessage(String destination) { + return null; + } + + @Override + public ContractVerifierMessage create(Object o, Map headers) { + return null; + } + + @Override + public ContractVerifierMessage create(Object o) { + return null; + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-stream/build.gradle b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-stream/build.gradle new file mode 100644 index 0000000000..6d894381a3 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-stream/build.gradle @@ -0,0 +1,35 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +repositories { + mavenLocal() + jcenter() + maven { + url "http://repo.spring.io/snapshot" + } + maven { + url "http://repo.spring.io/milestone" + } +} + +String verifier = "spring-cloud-contract-verifier" + +dependencies { + compile project(":$verifier-root:$verifier-messaging-root:$verifier-messaging-core") + compile "org.springframework.cloud:spring-cloud-stream:${springStreamVersion}" + // for MessageCollector + compile "org.springframework.cloud:spring-cloud-stream-test-support:${springStreamVersion}" +} \ No newline at end of file diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-stream/src/main/java/org/springframework/cloud/contract/verifier/messaging/stream/ContractVerifierStreamAutoConfiguration.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-stream/src/main/java/org/springframework/cloud/contract/verifier/messaging/stream/ContractVerifierStreamAutoConfiguration.java new file mode 100644 index 0000000000..00d445917d --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-stream/src/main/java/org/springframework/cloud/contract/verifier/messaging/stream/ContractVerifierStreamAutoConfiguration.java @@ -0,0 +1,38 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.messaging.stream; + +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessageBuilder; +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author Marcin Grzejszczak + */ +@Configuration +public class ContractVerifierStreamAutoConfiguration { + + @Bean ContractVerifierMessaging contractVerifierMessaging(ApplicationContext applicationContext, ContractVerifierMessageBuilder contractVerifierMessageBuilder) { + return new ContractVerifierStreamMessaging(applicationContext, contractVerifierMessageBuilder); + } + + @Bean ContractVerifierMessageBuilder contractVerifierMessageBuilder() { + return new ContractVerifierStreamMessageBuilder(); + } +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-stream/src/main/java/org/springframework/cloud/contract/verifier/messaging/stream/ContractVerifierStreamMessageBuilder.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-stream/src/main/java/org/springframework/cloud/contract/verifier/messaging/stream/ContractVerifierStreamMessageBuilder.java new file mode 100644 index 0000000000..90270657b4 --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-stream/src/main/java/org/springframework/cloud/contract/verifier/messaging/stream/ContractVerifierStreamMessageBuilder.java @@ -0,0 +1,46 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.messaging.stream; + +import java.util.Map; + +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessageBuilder; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageHeaders; +import org.springframework.messaging.support.MessageBuilder; + +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage; + +/** + * @author Marcin Grzejszczak + */ +public class ContractVerifierStreamMessageBuilder implements + ContractVerifierMessageBuilder> { + + @Override + public ContractVerifierMessage> create(T payload, Map headers) { + return new StreamMessage<>(MessageBuilder.createMessage(payload, new MessageHeaders(headers))); + } + + @Override + public ContractVerifierMessage> create(Message message) { + if (message == null) { + return null; + } + return new StreamMessage<>(message); + } +} diff --git a/accurest-messaging/accurest-messaging-stream/src/main/java/io/codearte/accurest/messaging/stream/AccurestStreamMessaging.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-stream/src/main/java/org/springframework/cloud/contract/verifier/messaging/stream/ContractVerifierStreamMessaging.java similarity index 60% rename from accurest-messaging/accurest-messaging-stream/src/main/java/io/codearte/accurest/messaging/stream/AccurestStreamMessaging.java rename to spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-stream/src/main/java/org/springframework/cloud/contract/verifier/messaging/stream/ContractVerifierStreamMessaging.java index 4fd456e637..3b885a4801 100644 --- a/accurest-messaging/accurest-messaging-stream/src/main/java/io/codearte/accurest/messaging/stream/AccurestStreamMessaging.java +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-stream/src/main/java/org/springframework/cloud/contract/verifier/messaging/stream/ContractVerifierStreamMessaging.java @@ -1,8 +1,24 @@ -package io.codearte.accurest.messaging.stream; +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import io.codearte.accurest.messaging.AccurestMessage; -import io.codearte.accurest.messaging.AccurestMessageBuilder; -import io.codearte.accurest.messaging.AccurestMessaging; +package org.springframework.cloud.contract.verifier.messaging.stream; + +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage; +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessageBuilder; +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -19,17 +35,18 @@ import java.util.concurrent.TimeUnit; /** * @author Marcin Grzejszczak */ -public class AccurestStreamMessaging implements AccurestMessaging> { +public class ContractVerifierStreamMessaging implements + ContractVerifierMessaging> { - private static final Logger log = LoggerFactory.getLogger(AccurestStreamMessaging.class); + private static final Logger log = LoggerFactory.getLogger(ContractVerifierStreamMessaging.class); private final ApplicationContext context; private final MessageCollector messageCollector; - private final AccurestMessageBuilder builder; + private final ContractVerifierMessageBuilder builder; @Autowired @SuppressWarnings("unchecked") - public AccurestStreamMessaging(ApplicationContext context, AccurestMessageBuilder builder) { + public ContractVerifierStreamMessaging(ApplicationContext context, ContractVerifierMessageBuilder builder) { this.context = context; this.messageCollector = context.getBean(MessageCollector.class); this.builder = builder; @@ -42,7 +59,7 @@ public class AccurestStreamMessaging implements AccurestMessaging> message, String destination) { + public void send(ContractVerifierMessage> message, String destination) { try { MessageChannel messageChannel = context.getBean(resolvedDestination(destination), MessageChannel.class); messageChannel.send(message.convert()); @@ -55,7 +72,7 @@ public class AccurestStreamMessaging implements AccurestMessaging> receiveMessage(String destination, long timeout, TimeUnit timeUnit) { + public ContractVerifierMessage> receiveMessage(String destination, long timeout, TimeUnit timeUnit) { try { MessageChannel messageChannel = context.getBean(resolvedDestination(destination), MessageChannel.class); return builder.create(messageCollector.forChannel(messageChannel).poll(timeout, timeUnit)); @@ -80,19 +97,19 @@ public class AccurestStreamMessaging implements AccurestMessaging> receiveMessage(String destination) { + public ContractVerifierMessage> receiveMessage(String destination) { return receiveMessage(destination, 5, TimeUnit.SECONDS); } @Override @SuppressWarnings("unchecked") - public AccurestMessage> create(T t, Map headers) { + public ContractVerifierMessage> create(T t, Map headers) { return builder.create(t, headers); } @Override @SuppressWarnings("unchecked") - public AccurestMessage> create(Message message) { + public ContractVerifierMessage> create(Message message) { return builder.create(message); } } diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-stream/src/main/java/org/springframework/cloud/contract/verifier/messaging/stream/StreamMessage.java b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-stream/src/main/java/org/springframework/cloud/contract/verifier/messaging/stream/StreamMessage.java new file mode 100644 index 0000000000..7582daf46a --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-stream/src/main/java/org/springframework/cloud/contract/verifier/messaging/stream/StreamMessage.java @@ -0,0 +1,54 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.messaging.stream; + +import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageHeaders; + +/** + * @author Marcin Grzejszczak + */ +public class StreamMessage implements ContractVerifierMessage> { + + private final Message delegate; + + public StreamMessage(Message delegate) { + this.delegate = delegate; + } + + @Override + public T getPayload() { + return delegate.getPayload(); + } + + @Override + public MessageHeaders getHeaders() { + return delegate.getHeaders(); + } + + @Override + public Object getHeader(String key) { + return getHeaders().get(key); + } + + @Override + public Message convert() { + return delegate; + } + +} diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-stream/src/main/resources/META-INF/spring.factories b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-stream/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000000..6b6e2b930d --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-messaging/spring-cloud-contract-verifier-stream/src/main/resources/META-INF/spring.factories @@ -0,0 +1,3 @@ +# Auto Configuration +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.springframework.cloud.contract.verifier.messaging.stream.ContractVerifierStreamAutoConfiguration diff --git a/spring-cloud-contract-verifier/spring-cloud-contract-verifier-testing-utils/src/main/groovy/org/springframework/cloud/contract/verifier/util/AssertionUtil.groovy b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-testing-utils/src/main/groovy/org/springframework/cloud/contract/verifier/util/AssertionUtil.groovy new file mode 100644 index 0000000000..8b23a3473c --- /dev/null +++ b/spring-cloud-contract-verifier/spring-cloud-contract-verifier-testing-utils/src/main/groovy/org/springframework/cloud/contract/verifier/util/AssertionUtil.groovy @@ -0,0 +1,28 @@ +/* + * Copyright 2013-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.contract.verifier.util + +import org.skyscreamer.jsonassert.JSONAssert + +class AssertionUtil { + + private static boolean NON_STRICT = false + + public static void assertThatJsonsAreEqual(String expected, String actual) { + JSONAssert.assertEquals(expected, actual, NON_STRICT) + } +} diff --git a/stub-runner/stub-runner-boot/build.gradle b/stub-runner/stub-runner-boot/build.gradle deleted file mode 100644 index a10236151b..0000000000 --- a/stub-runner/stub-runner-boot/build.gradle +++ /dev/null @@ -1,22 +0,0 @@ -repositories { - mavenLocal() - jcenter() - maven { - url "http://repo.spring.io/snapshot" - } - maven { - url "http://repo.spring.io/milestone" - } -} - -dependencies { - compile project(':stub-runner-root:stub-runner-spring') - compile "org.springframework.boot:spring-boot-starter-web:${springBootVersion}" - - testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" - testCompile project(':stub-runner-root:stub-runner-messaging-root:stub-runner-messaging-stream') - testCompile 'com.jayway.restassured:spring-mock-mvc:2.9.0' - testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { - exclude(group: 'org.codehaus.groovy') - } -} \ No newline at end of file diff --git a/stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/StubRunnerBoot.groovy b/stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/StubRunnerBoot.groovy deleted file mode 100644 index d3ec34a69e..0000000000 --- a/stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/StubRunnerBoot.groovy +++ /dev/null @@ -1,15 +0,0 @@ -package io.codearte.accurest.stubrunner.boot - -import org.springframework.boot.SpringApplication -import org.springframework.boot.autoconfigure.SpringBootApplication - -/** - * @author Marcin Grzejszczak - */ -@SpringBootApplication -class StubRunnerBoot { - - static void main(String[] args) { - SpringApplication.run(StubRunnerBoot.class, args); - } -} diff --git a/stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/StubRunnerConfig.groovy b/stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/StubRunnerConfig.groovy deleted file mode 100644 index d0352a2624..0000000000 --- a/stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/StubRunnerConfig.groovy +++ /dev/null @@ -1,28 +0,0 @@ -package io.codearte.accurest.stubrunner.boot - -import io.codearte.accurest.messaging.AccurestMessageBuilder -import io.codearte.accurest.messaging.AccurestMessaging -import io.codearte.accurest.messaging.noop.NoOpAccurestMessageBuilder -import io.codearte.accurest.messaging.noop.NoOpAccurestMessaging -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration - -/** - * @author Marcin Grzejszczak - */ -@Configuration -class StubRunnerConfig { - - @Bean - @ConditionalOnMissingBean - AccurestMessaging noOpAccurestMessaging() { - return new NoOpAccurestMessaging() - } - - @Bean - @ConditionalOnMissingBean - AccurestMessageBuilder noOpAccurestMessageBuilder() { - return new NoOpAccurestMessageBuilder() - } -} diff --git a/stub-runner/stub-runner-boot/src/main/resources/META-INF/spring.factories b/stub-runner/stub-runner-boot/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 1f6ec12f3e..0000000000 --- a/stub-runner/stub-runner-boot/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,3 +0,0 @@ -# Auto Configuration -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -io.codearte.accurest.stubrunner.spring.StubRunnerConfiguration diff --git a/stub-runner/stub-runner-boot/src/test/resources/application.yml b/stub-runner/stub-runner-boot/src/test/resources/application.yml deleted file mode 100644 index 154bfe1b6a..0000000000 --- a/stub-runner/stub-runner-boot/src/test/resources/application.yml +++ /dev/null @@ -1,2 +0,0 @@ -stubrunner.stubs.repository.root: classpath:m2repo/repository/ -stubrunner.stubs.ids: io.codearte.accurest.stubs:streamService \ No newline at end of file diff --git a/stub-runner/stub-runner-boot/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT-stubs.jar b/stub-runner/stub-runner-boot/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT-stubs.jar deleted file mode 100644 index 86c61d52ec..0000000000 Binary files a/stub-runner/stub-runner-boot/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT-stubs.jar and /dev/null differ diff --git a/stub-runner/stub-runner-boot/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT.pom b/stub-runner/stub-runner-boot/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT.pom deleted file mode 100644 index dcb2e4ffd9..0000000000 --- a/stub-runner/stub-runner-boot/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT.pom +++ /dev/null @@ -1,9 +0,0 @@ - - - 4.0.0 - io.codearte.accurest.stubs - streamService - 0.0.1-SNAPSHOT - pom - diff --git a/stub-runner/stub-runner-boot/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/maven-metadata.xml b/stub-runner/stub-runner-boot/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/maven-metadata.xml deleted file mode 100644 index dc32790f53..0000000000 --- a/stub-runner/stub-runner-boot/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/maven-metadata.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - io.codearte.accurest.stubs - streamService - 0.0.1-SNAPSHOT - - - 0.0.1-SNAPSHOT - - 20160409062112 - - diff --git a/stub-runner/stub-runner-junit/build.gradle b/stub-runner/stub-runner-junit/build.gradle deleted file mode 100644 index bd9a36bfe0..0000000000 --- a/stub-runner/stub-runner-junit/build.gradle +++ /dev/null @@ -1,17 +0,0 @@ -description = 'JUnit rule for stub-runner' - -dependencies { - compile project(':stub-runner-root:stub-runner') - - compile localGroovy() - compile 'junit:junit:4.12' - - testCompile('org.spockframework:spock-core:1.0-groovy-2.4') { - exclude(group: 'org.codehaus.groovy') - } - testCompile 'cglib:cglib-nodep:2.2' - testCompile 'org.objenesis:objenesis:2.1' - testCompile 'ch.qos.logback:logback-classic:1.1.3' - testCompile 'org.assertj:assertj-core:2.3.0' - testCompile 'org.apache.commons:commons-io:1.3.2' -} diff --git a/stub-runner/stub-runner-junit/src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleCustomPortJUnitTest.java b/stub-runner/stub-runner-junit/src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleCustomPortJUnitTest.java deleted file mode 100644 index ef05510e74..0000000000 --- a/stub-runner/stub-runner-junit/src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleCustomPortJUnitTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package io.codearte.accurest.stubrunner.junit; - -import java.io.InputStream; -import java.net.URI; - -import org.apache.commons.io.IOUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; - -import static org.assertj.core.api.BDDAssertions.then; - -/** - * @author Marcin Grzejszczak - */ -public class AccurestRuleCustomPortJUnitTest { - - @BeforeClass - @AfterClass - public static void setupProps() { - System.getProperties().setProperty("stubrunner.stubs.repository.root", ""); - System.getProperties().setProperty("stubrunner.stubs.classifier", "stubs"); - } - - // tag::classrule_with_port[] - @ClassRule public static AccurestRule rule = new AccurestRule() - .repoRoot(repoRoot()) - .downloadStub("io.codearte.accurest.stubs", "loanIssuance") - .withPort(12345) - .downloadStub("io.codearte.accurest.stubs:fraudDetectionServer:12346"); - // end::classrule_with_port[] - - @Test - public void should_start_wiremock_servers() throws Exception { - // expect: 'WireMocks are running' - then(rule.findStubUrl("io.codearte.accurest.stubs", "loanIssuance")).isNotNull(); - then(rule.findStubUrl("loanIssuance")).isNotNull(); - then(rule.findStubUrl("loanIssuance")).isEqualTo(rule.findStubUrl("io.codearte.accurest.stubs", "loanIssuance")); - then(rule.findStubUrl("io.codearte.accurest.stubs:fraudDetectionServer")).isNotNull(); - // and: - then(rule.findAllRunningStubs().isPresent("loanIssuance")).isTrue(); - then(rule.findAllRunningStubs().isPresent("io.codearte.accurest.stubs", "fraudDetectionServer")).isTrue(); - then(rule.findAllRunningStubs().isPresent("io.codearte.accurest.stubs:fraudDetectionServer")).isTrue(); - // and: 'Stubs were registered' - then(httpGet(rule.findStubUrl("loanIssuance").toString() + "/name")).isEqualTo("loanIssuance"); - then(httpGet(rule.findStubUrl("fraudDetectionServer").toString() + "/name")).isEqualTo("fraudDetectionServer"); - // and: 'The port is fixed' - // tag::test_with_port[] - then(rule.findStubUrl("loanIssuance")).isEqualTo(URI.create("http://localhost:12345").toURL()); - then(rule.findStubUrl("fraudDetectionServer")).isEqualTo(URI.create("http://localhost:12346").toURL()); - // end::test_with_port[] - } - - private static String repoRoot() { - try { - return AccurestRuleCustomPortJUnitTest.class.getResource("/m2repo/repository/").toURI().toString(); - } catch (Exception e) { - return ""; - } - } - - private String httpGet(String url) throws Exception { - try(InputStream stream = URI.create(url).toURL().openStream()) { - return IOUtils.toString(stream); - } - } -} diff --git a/stub-runner/stub-runner-junit/src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleJUnitTest.java b/stub-runner/stub-runner-junit/src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleJUnitTest.java deleted file mode 100644 index 407c78f781..0000000000 --- a/stub-runner/stub-runner-junit/src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleJUnitTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package io.codearte.accurest.stubrunner.junit; - -import java.io.InputStream; -import java.net.URI; - -import org.apache.commons.io.IOUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; - -import static org.assertj.core.api.BDDAssertions.then; - -/** - * @author Marcin Grzejszczak - */ -public class AccurestRuleJUnitTest { - - @BeforeClass - @AfterClass - public static void setupProps() { - System.getProperties().setProperty("stubrunner.stubs.repository.root", ""); - System.getProperties().setProperty("stubrunner.stubs.classifier", "stubs"); - } - - // tag::classrule[] - @ClassRule public static AccurestRule rule = new AccurestRule() - .repoRoot(repoRoot()) - .downloadStub("io.codearte.accurest.stubs", "loanIssuance") - .downloadStub("io.codearte.accurest.stubs:fraudDetectionServer"); - // end::classrule[] - - // tag::test[] - @Test - public void should_start_wiremock_servers() throws Exception { - // expect: 'WireMocks are running' - then(rule.findStubUrl("io.codearte.accurest.stubs", "loanIssuance")).isNotNull(); - then(rule.findStubUrl("loanIssuance")).isNotNull(); - then(rule.findStubUrl("loanIssuance")).isEqualTo(rule.findStubUrl("io.codearte.accurest.stubs", "loanIssuance")); - then(rule.findStubUrl("io.codearte.accurest.stubs:fraudDetectionServer")).isNotNull(); - // and: - then(rule.findAllRunningStubs().isPresent("loanIssuance")).isTrue(); - then(rule.findAllRunningStubs().isPresent("io.codearte.accurest.stubs", "fraudDetectionServer")).isTrue(); - then(rule.findAllRunningStubs().isPresent("io.codearte.accurest.stubs:fraudDetectionServer")).isTrue(); - // and: 'Stubs were registered' - then(httpGet(rule.findStubUrl("loanIssuance").toString() + "/name")).isEqualTo("loanIssuance"); - then(httpGet(rule.findStubUrl("fraudDetectionServer").toString() + "/name")).isEqualTo("fraudDetectionServer"); - } - // end::test[] - - private static String repoRoot() { - try { - return AccurestRuleJUnitTest.class.getResource("/m2repo/repository/").toURI().toString(); - } catch (Exception e) { - return ""; - } - } - - private String httpGet(String url) throws Exception { - try(InputStream stream = URI.create(url).toURL().openStream()) { - return IOUtils.toString(stream); - } - } -} diff --git a/stub-runner/stub-runner-junit/src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleSpec.groovy b/stub-runner/stub-runner-junit/src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleSpec.groovy deleted file mode 100644 index 7b5ee643fd..0000000000 --- a/stub-runner/stub-runner-junit/src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleSpec.groovy +++ /dev/null @@ -1,42 +0,0 @@ -package io.codearte.accurest.stubrunner.junit - -import org.junit.AfterClass -import org.junit.BeforeClass -import org.junit.ClassRule -import spock.lang.Shared -import spock.lang.Specification - -/** - * @author Marcin Grzejszczak - */ -class AccurestRuleSpec extends Specification { - - @BeforeClass - @AfterClass - void setupProps() { - System.getProperties().setProperty("stubrunner.stubs.repository.root", ""); - System.getProperties().setProperty("stubrunner.stubs.classifier", "stubs"); - } - - // tag::classrule[] - @ClassRule @Shared AccurestRule rule = new AccurestRule() - .repoRoot(AccurestRuleSpec.getResource("/m2repo/repository").toURI().toString()) - .downloadStub("io.codearte.accurest.stubs", "loanIssuance") - .downloadStub("io.codearte.accurest.stubs:fraudDetectionServer") - - def 'should start WireMock servers'() { - expect: 'WireMocks are running' - rule.findStubUrl('io.codearte.accurest.stubs', 'loanIssuance') != null - rule.findStubUrl('loanIssuance') != null - rule.findStubUrl('loanIssuance') == rule.findStubUrl('io.codearte.accurest.stubs', 'loanIssuance') - rule.findStubUrl('io.codearte.accurest.stubs:fraudDetectionServer') != null - and: - rule.findAllRunningStubs().isPresent('loanIssuance') - rule.findAllRunningStubs().isPresent('io.codearte.accurest.stubs', 'fraudDetectionServer') - rule.findAllRunningStubs().isPresent('io.codearte.accurest.stubs:fraudDetectionServer') - and: 'Stubs were registered' - "${rule.findStubUrl('loanIssuance').toString()}/name".toURL().text == 'loanIssuance' - "${rule.findStubUrl('fraudDetectionServer').toString()}/name".toURL().text == 'fraudDetectionServer' - } - // end::classrule[] -} diff --git a/stub-runner/stub-runner-junit/src/test/resources/logback.xml b/stub-runner/stub-runner-junit/src/test/resources/logback.xml deleted file mode 100644 index 0cfb35f4cd..0000000000 --- a/stub-runner/stub-runner-junit/src/test/resources/logback.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - \ No newline at end of file diff --git a/stub-runner/stub-runner-junit/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT.pom b/stub-runner/stub-runner-junit/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT.pom deleted file mode 100644 index 9f04720f7d..0000000000 --- a/stub-runner/stub-runner-junit/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT.pom +++ /dev/null @@ -1,9 +0,0 @@ - - - 4.0.0 - io.codearte.accurest.stubs - fraudDetectionServer - 0.0.1-SNAPSHOT - pom - diff --git a/stub-runner/stub-runner-junit/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/maven-metadata.xml b/stub-runner/stub-runner-junit/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/maven-metadata.xml deleted file mode 100644 index d4ab9afc83..0000000000 --- a/stub-runner/stub-runner-junit/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/maven-metadata.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - io.codearte.accurest.stubs - fraudDetectionServer - 0.0.1-SNAPSHOT - - - 0.0.1-SNAPSHOT - - 20160409062112 - - diff --git a/stub-runner/stub-runner-junit/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT.pom b/stub-runner/stub-runner-junit/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT.pom deleted file mode 100644 index 9185d4bc8f..0000000000 --- a/stub-runner/stub-runner-junit/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT.pom +++ /dev/null @@ -1,9 +0,0 @@ - - - 4.0.0 - io.codearte.accurest.stubs - loanIssuance - 0.0.1-SNAPSHOT - pom - diff --git a/stub-runner/stub-runner-junit/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/maven-metadata.xml b/stub-runner/stub-runner-junit/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/maven-metadata.xml deleted file mode 100644 index bf14a1ad21..0000000000 --- a/stub-runner/stub-runner-junit/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/maven-metadata.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - io.codearte.accurest.stubs - loanIssuance - 0.0.1-SNAPSHOT - - - 0.0.1-SNAPSHOT - - 20160409062111 - - diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/build.gradle b/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/build.gradle deleted file mode 100644 index 0c284fdd5b..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/build.gradle +++ /dev/null @@ -1,26 +0,0 @@ -repositories { - mavenLocal() - jcenter() - maven { - url "http://repo.spring.io/snapshot" - } - maven { - url "http://repo.spring.io/milestone" - } -} - -dependencies { - compile project(':stub-runner-root:stub-runner-spring') - compile project(':accurest-messaging-root:accurest-messaging-camel') - compile "org.apache.camel:camel-spring-boot-starter:${camelVersion}" - compile "org.apache.camel:camel-jackson:${camelVersion}" - - testCompile "org.springframework:spring-beans:${springVersion}" - testCompile "org.apache.camel:camel-jms:${camelVersion}" - testCompile 'org.apache.activemq:activemq-camel:5.12.1' - testCompile 'org.apache.activemq:activemq-pool:5.12.1' - testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" - testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { - exclude(group: 'org.codehaus.groovy') - } -} \ No newline at end of file diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/main/groovy/io/codearte/accurest/stubrunner/messaging/camel/StubRunnerCamelConfiguration.groovy b/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/main/groovy/io/codearte/accurest/stubrunner/messaging/camel/StubRunnerCamelConfiguration.groovy deleted file mode 100644 index a00e1d6c85..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/main/groovy/io/codearte/accurest/stubrunner/messaging/camel/StubRunnerCamelConfiguration.groovy +++ /dev/null @@ -1,35 +0,0 @@ -package io.codearte.accurest.stubrunner.messaging.camel - -import io.codearte.accurest.dsl.GroovyDsl -import io.codearte.accurest.stubrunner.BatchStubRunner -import io.codearte.accurest.stubrunner.StubConfiguration -import org.apache.camel.RoutesBuilder -import org.apache.camel.spring.SpringRouteBuilder -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration - -/** - * Camel configuration that iterates over the downloaded Groovy DSLs - * and registers a route for each DSL. - * - * @author Marcin Grzejszczak - */ -@Configuration -class StubRunnerCamelConfiguration { - - @Bean - RoutesBuilder myRouter(BatchStubRunner batchStubRunner) { - return new SpringRouteBuilder() { - @Override - public void configure() throws Exception { - Map> accurestContracts = batchStubRunner.accurestContracts - (accurestContracts.values().flatten() as Collection).findAll { it?.input?.messageFrom?.clientValue && it?.outputMessage?.sentTo }.each { - from(it.input.messageFrom.clientValue) - .filter(new StubRunnerCamelPredicate(it)) - .process(new StubRunnerCamelProcessor(it)) - .to(it.outputMessage.sentTo.clientValue) - } - } - }; - } -} diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/main/groovy/io/codearte/accurest/stubrunner/messaging/camel/StubRunnerCamelProcessor.groovy b/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/main/groovy/io/codearte/accurest/stubrunner/messaging/camel/StubRunnerCamelProcessor.groovy deleted file mode 100644 index 87b2f8590e..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/main/groovy/io/codearte/accurest/stubrunner/messaging/camel/StubRunnerCamelProcessor.groovy +++ /dev/null @@ -1,36 +0,0 @@ -package io.codearte.accurest.stubrunner.messaging.camel - -import groovy.transform.PackageScope -import io.codearte.accurest.builder.BodyAsString -import io.codearte.accurest.dsl.GroovyDsl -import org.apache.camel.Exchange -import org.apache.camel.Message -import org.apache.camel.Processor - -/** - * Sends forward a message defined in the DSL. Also removes headers from the - * input message and provides the headers from the DSL. - * - * @author Marcin Grzejszczak - */ -@PackageScope -class StubRunnerCamelProcessor implements Processor { - - private final GroovyDsl groovyDsl - - StubRunnerCamelProcessor(GroovyDsl groovyDsl) { - this.groovyDsl = groovyDsl - } - - @Override - void process(Exchange exchange) throws Exception { - Message input = exchange.in - input.body = BodyAsString.extractClientValueFrom(groovyDsl.outputMessage.body) - groovyDsl.input.messageHeaders.entries.each { - input.removeHeader(it.name) - } - groovyDsl.outputMessage.headers.entries.each { - input.setHeader(it.name, it.clientValue) - } - } -} diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/BookReturned.groovy b/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/BookReturned.groovy deleted file mode 100644 index b6523d2e5c..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/BookReturned.groovy +++ /dev/null @@ -1,16 +0,0 @@ -package io.codearte.accurest.stubrunner.messaging.camel - -import com.fasterxml.jackson.annotation.JsonCreator -import groovy.transform.CompileStatic -import groovy.transform.EqualsAndHashCode - -@CompileStatic -@EqualsAndHashCode -class BookReturned implements Serializable { - final String bookName - - @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) - BookReturned(String bookName) { - this.bookName = bookName - } -} diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/resources/application.yml b/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/resources/application.yml deleted file mode 100644 index 6fadb526ec..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/resources/application.yml +++ /dev/null @@ -1,2 +0,0 @@ -stubrunner.stubs.repository.root: classpath:m2repo/repository/ -stubrunner.stubs.ids: io.codearte.accurest.stubs:camelService \ No newline at end of file diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/camelService/0.0.1-SNAPSHOT/camelService-0.0.1-SNAPSHOT-stubs.jar b/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/camelService/0.0.1-SNAPSHOT/camelService-0.0.1-SNAPSHOT-stubs.jar deleted file mode 100644 index 17df8f09ab..0000000000 Binary files a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/camelService/0.0.1-SNAPSHOT/camelService-0.0.1-SNAPSHOT-stubs.jar and /dev/null differ diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/camelService/0.0.1-SNAPSHOT/camelService-0.0.1-SNAPSHOT.pom b/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/camelService/0.0.1-SNAPSHOT/camelService-0.0.1-SNAPSHOT.pom deleted file mode 100644 index 4e8bab7de0..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/camelService/0.0.1-SNAPSHOT/camelService-0.0.1-SNAPSHOT.pom +++ /dev/null @@ -1,9 +0,0 @@ - - - 4.0.0 - io.codearte.accurest.stubs - camelService - 0.0.1-SNAPSHOT - pom - diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/camelService/0.0.1-SNAPSHOT/maven-metadata-local.xml b/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/camelService/0.0.1-SNAPSHOT/maven-metadata-local.xml deleted file mode 100644 index f8f49e32bb..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/camelService/0.0.1-SNAPSHOT/maven-metadata-local.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - io.codearte.accurest.stubs - camelService - 0.0.1-SNAPSHOT - - - true - - 20160409062112 - - diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/camelService/maven-metadata-local.xml b/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/camelService/maven-metadata-local.xml deleted file mode 100644 index e71db595a7..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/camelService/maven-metadata-local.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - io.codearte.accurest.stubs - camelService - 0.0.1-SNAPSHOT - - - 0.0.1-SNAPSHOT - - 20160409062112 - - diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/camelService/maven-metadata.xml b/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/camelService/maven-metadata.xml deleted file mode 100644 index e71db595a7..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/camelService/maven-metadata.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - io.codearte.accurest.stubs - camelService - 0.0.1-SNAPSHOT - - - 0.0.1-SNAPSHOT - - 20160409062112 - - diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/build.gradle b/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/build.gradle deleted file mode 100644 index f8b8a8277d..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/build.gradle +++ /dev/null @@ -1,23 +0,0 @@ -repositories { - mavenLocal() - jcenter() - maven { - url "http://repo.spring.io/snapshot" - } - maven { - url "http://repo.spring.io/milestone" - } -} - -dependencies { - compile project(':stub-runner-root:stub-runner-spring') - compile project(':accurest-messaging-root:accurest-messaging-integration') - compile "org.springframework.integration:spring-integration-java-dsl:${springIntegrationDslVersion}" - compile 'com.fasterxml.jackson.core:jackson-databind:2.7.0' - - testCompile "org.springframework.boot:spring-boot-starter-integration:${springBootVersion}" - testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" - testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { - exclude(group: 'org.codehaus.groovy') - } -} \ No newline at end of file diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/main/groovy/io/codearte/accurest/stubrunner/messaging/integration/StubRunnerIntegrationTransformer.groovy b/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/main/groovy/io/codearte/accurest/stubrunner/messaging/integration/StubRunnerIntegrationTransformer.groovy deleted file mode 100644 index 2bb6fa19ca..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/main/groovy/io/codearte/accurest/stubrunner/messaging/integration/StubRunnerIntegrationTransformer.groovy +++ /dev/null @@ -1,32 +0,0 @@ -package io.codearte.accurest.stubrunner.messaging.integration - -import io.codearte.accurest.builder.BodyAsString -import io.codearte.accurest.dsl.GroovyDsl -import org.springframework.integration.transformer.GenericTransformer -import org.springframework.messaging.Message -import org.springframework.messaging.MessageHeaders -import org.springframework.messaging.support.MessageBuilder - -/** - * Sends forward a message defined in the DSL. - * - * @author Marcin Grzejszczak - */ -class StubRunnerIntegrationTransformer implements GenericTransformer, Message> { - - private final GroovyDsl groovyDsl - - StubRunnerIntegrationTransformer(GroovyDsl groovyDsl) { - this.groovyDsl = groovyDsl - } - - @Override - Message transform(Message source) { - if (!groovyDsl.outputMessage) { - return source - } - String payload = BodyAsString.extractClientValueFrom(groovyDsl.outputMessage.body) - Map headers = groovyDsl.outputMessage.headers.asStubSideMap() - return MessageBuilder.createMessage(payload, new MessageHeaders(headers)) - } -} diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/main/resources/META-INF/spring.factories b/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/main/resources/META-INF/spring.factories deleted file mode 100644 index dfd989c8bc..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,3 +0,0 @@ -# Auto Configuration -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -io.codearte.accurest.stubrunner.messaging.integration.StubRunnerIntegrationConfiguration diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/groovy/io/codearte/accurest/stubrunner/messaging/integration/BookReturned.groovy b/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/groovy/io/codearte/accurest/stubrunner/messaging/integration/BookReturned.groovy deleted file mode 100644 index c5826c848d..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/groovy/io/codearte/accurest/stubrunner/messaging/integration/BookReturned.groovy +++ /dev/null @@ -1,16 +0,0 @@ -package io.codearte.accurest.stubrunner.messaging.integration - -import com.fasterxml.jackson.annotation.JsonCreator -import groovy.transform.CompileStatic -import groovy.transform.EqualsAndHashCode - -@CompileStatic -@EqualsAndHashCode -class BookReturned implements Serializable { - final String bookName - - @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) - BookReturned(String bookName) { - this.bookName = bookName - } -} diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/resources/application.yml b/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/resources/application.yml deleted file mode 100644 index 3bec94b4b9..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/resources/application.yml +++ /dev/null @@ -1,2 +0,0 @@ -stubrunner.stubs.repository.root: classpath:m2repo/repository/ -stubrunner.stubs.ids: io.codearte.accurest.stubs:integrationService:0.0.1-SNAPSHOT \ No newline at end of file diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/integrationService/0.0.1-SNAPSHOT/integrationService-0.0.1-SNAPSHOT-stubs.jar b/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/integrationService/0.0.1-SNAPSHOT/integrationService-0.0.1-SNAPSHOT-stubs.jar deleted file mode 100644 index 86c61d52ec..0000000000 Binary files a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/integrationService/0.0.1-SNAPSHOT/integrationService-0.0.1-SNAPSHOT-stubs.jar and /dev/null differ diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/integrationService/0.0.1-SNAPSHOT/integrationService-0.0.1-SNAPSHOT.pom b/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/integrationService/0.0.1-SNAPSHOT/integrationService-0.0.1-SNAPSHOT.pom deleted file mode 100644 index 84d7a5b7d7..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/integrationService/0.0.1-SNAPSHOT/integrationService-0.0.1-SNAPSHOT.pom +++ /dev/null @@ -1,9 +0,0 @@ - - - 4.0.0 - io.codearte.accurest.stubs - integrationService - 0.0.1-SNAPSHOT - pom - diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/integrationService/0.0.1-SNAPSHOT/maven-metadata-local.xml b/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/integrationService/0.0.1-SNAPSHOT/maven-metadata-local.xml deleted file mode 100644 index 20ba9761d8..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/integrationService/0.0.1-SNAPSHOT/maven-metadata-local.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - io.codearte.accurest.stubs - integrationService - 0.0.1-SNAPSHOT - - - true - - 20160409062112 - - diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/integrationService/maven-metadata-local.xml b/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/integrationService/maven-metadata-local.xml deleted file mode 100644 index b93b655f1f..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/integrationService/maven-metadata-local.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - io.codearte.accurest.stubs - integrationService - 0.0.1-SNAPSHOT - - - 0.0.1-SNAPSHOT - - 20160409062112 - - diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/integrationService/maven-metadata.xml b/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/integrationService/maven-metadata.xml deleted file mode 100644 index b93b655f1f..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/integrationService/maven-metadata.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - io.codearte.accurest.stubs - integrationService - 0.0.1-SNAPSHOT - - - 0.0.1-SNAPSHOT - - 20160409062112 - - diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/build.gradle b/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/build.gradle deleted file mode 100644 index b03e790ea4..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/build.gradle +++ /dev/null @@ -1,24 +0,0 @@ -repositories { - mavenLocal() - jcenter() - maven { - url "http://repo.spring.io/snapshot" - } - maven { - url "http://repo.spring.io/milestone" - } -} - -dependencies { - compile project(':stub-runner-root:stub-runner-spring') - compile project(':accurest-messaging-root:accurest-messaging-stream') - compile "org.springframework.integration:spring-integration-java-dsl:${springIntegrationDslVersion}" - - testCompile "org.springframework:spring-context:${springVersion}" - testCompile "org.springframework:spring-beans:${springVersion}" - testCompile "org.springframework.cloud:spring-cloud-stream-test-support:${springStreamVersion}" - testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" - testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { - exclude(group: 'org.codehaus.groovy') - } -} \ No newline at end of file diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/main/groovy/io/codearte/accurest/stubrunner/messaging/stream/StubRunnerStreamTransformer.groovy b/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/main/groovy/io/codearte/accurest/stubrunner/messaging/stream/StubRunnerStreamTransformer.groovy deleted file mode 100644 index c8e61b665f..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/main/groovy/io/codearte/accurest/stubrunner/messaging/stream/StubRunnerStreamTransformer.groovy +++ /dev/null @@ -1,32 +0,0 @@ -package io.codearte.accurest.stubrunner.messaging.stream - -import io.codearte.accurest.builder.BodyAsString -import io.codearte.accurest.dsl.GroovyDsl -import org.springframework.integration.transformer.GenericTransformer -import org.springframework.messaging.Message -import org.springframework.messaging.MessageHeaders -import org.springframework.messaging.support.MessageBuilder - -/** - * Sends forward a message defined in the DSL. - * - * @author Marcin Grzejszczak - */ -class StubRunnerStreamTransformer implements GenericTransformer, Message> { - - private final GroovyDsl groovyDsl - - StubRunnerStreamTransformer(GroovyDsl groovyDsl) { - this.groovyDsl = groovyDsl - } - - @Override - Message transform(Message source) { - if (!groovyDsl.outputMessage) { - return source - } - String payload = BodyAsString.extractClientValueFrom(groovyDsl.outputMessage.body) - Map headers = groovyDsl.outputMessage.headers.asStubSideMap() - return MessageBuilder.createMessage(payload, new MessageHeaders(headers)) - } -} diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/main/resources/META-INF/spring.factories b/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 7b69d1b85a..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,3 +0,0 @@ -# Auto Configuration -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -io.codearte.accurest.stubrunner.messaging.stream.StubRunnerStreamConfiguration diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/groovy/io/codearte/accurest/stubrunner/messaging/stream/BookReturned.groovy b/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/groovy/io/codearte/accurest/stubrunner/messaging/stream/BookReturned.groovy deleted file mode 100644 index 0dd3ca4216..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/groovy/io/codearte/accurest/stubrunner/messaging/stream/BookReturned.groovy +++ /dev/null @@ -1,16 +0,0 @@ -package io.codearte.accurest.stubrunner.messaging.stream - -import com.fasterxml.jackson.annotation.JsonCreator -import groovy.transform.CompileStatic -import groovy.transform.EqualsAndHashCode - -@CompileStatic -@EqualsAndHashCode -class BookReturned implements Serializable { - final String bookName - - @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) - BookReturned(String bookName) { - this.bookName = bookName - } -} diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/0.0.1-SNAPSHOT/maven-metadata-local.xml b/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/0.0.1-SNAPSHOT/maven-metadata-local.xml deleted file mode 100644 index bad844ba2a..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/0.0.1-SNAPSHOT/maven-metadata-local.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - io.codearte.accurest.stubs - streamService - 0.0.1-SNAPSHOT - - - true - - 20160409062112 - - diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT-stubs.jar b/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT-stubs.jar deleted file mode 100644 index 79d37267a7..0000000000 Binary files a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT-stubs.jar and /dev/null differ diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT.pom b/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT.pom deleted file mode 100644 index dcb2e4ffd9..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT.pom +++ /dev/null @@ -1,9 +0,0 @@ - - - 4.0.0 - io.codearte.accurest.stubs - streamService - 0.0.1-SNAPSHOT - pom - diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/maven-metadata-local.xml b/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/maven-metadata-local.xml deleted file mode 100644 index dc32790f53..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/maven-metadata-local.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - io.codearte.accurest.stubs - streamService - 0.0.1-SNAPSHOT - - - 0.0.1-SNAPSHOT - - 20160409062112 - - diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/maven-metadata.xml b/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/maven-metadata.xml deleted file mode 100644 index dc32790f53..0000000000 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/maven-metadata.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - io.codearte.accurest.stubs - streamService - 0.0.1-SNAPSHOT - - - 0.0.1-SNAPSHOT - - 20160409062112 - - diff --git a/stub-runner/stub-runner-spring-cloud/src/main/resources/META-INF/spring.factories b/stub-runner/stub-runner-spring-cloud/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 60fb0401e6..0000000000 --- a/stub-runner/stub-runner-spring-cloud/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,4 +0,0 @@ -# Auto Configuration -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -io.codearte.accurest.stubrunner.spring.cloud.StubRunnerSpringCloudAutoConfiguration,\ -io.codearte.accurest.stubrunner.spring.cloud.ribbon.StubRunnerRibbonAutoConfiguration diff --git a/stub-runner/stub-runner-spring-cloud/src/test/resources/logback.xml b/stub-runner/stub-runner-spring-cloud/src/test/resources/logback.xml deleted file mode 100644 index 0cfb35f4cd..0000000000 --- a/stub-runner/stub-runner-spring-cloud/src/test/resources/logback.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - \ No newline at end of file diff --git a/stub-runner/stub-runner-spring-cloud/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT.pom b/stub-runner/stub-runner-spring-cloud/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT.pom deleted file mode 100644 index 9f04720f7d..0000000000 --- a/stub-runner/stub-runner-spring-cloud/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT.pom +++ /dev/null @@ -1,9 +0,0 @@ - - - 4.0.0 - io.codearte.accurest.stubs - fraudDetectionServer - 0.0.1-SNAPSHOT - pom - diff --git a/stub-runner/stub-runner-spring-cloud/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/maven-metadata.xml b/stub-runner/stub-runner-spring-cloud/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/maven-metadata.xml deleted file mode 100644 index d4ab9afc83..0000000000 --- a/stub-runner/stub-runner-spring-cloud/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/maven-metadata.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - io.codearte.accurest.stubs - fraudDetectionServer - 0.0.1-SNAPSHOT - - - 0.0.1-SNAPSHOT - - 20160409062112 - - diff --git a/stub-runner/stub-runner-spring-cloud/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT.pom b/stub-runner/stub-runner-spring-cloud/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT.pom deleted file mode 100644 index 9185d4bc8f..0000000000 --- a/stub-runner/stub-runner-spring-cloud/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT.pom +++ /dev/null @@ -1,9 +0,0 @@ - - - 4.0.0 - io.codearte.accurest.stubs - loanIssuance - 0.0.1-SNAPSHOT - pom - diff --git a/stub-runner/stub-runner-spring-cloud/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/maven-metadata.xml b/stub-runner/stub-runner-spring-cloud/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/maven-metadata.xml deleted file mode 100644 index bf14a1ad21..0000000000 --- a/stub-runner/stub-runner-spring-cloud/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/maven-metadata.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - io.codearte.accurest.stubs - loanIssuance - 0.0.1-SNAPSHOT - - - 0.0.1-SNAPSHOT - - 20160409062111 - - diff --git a/stub-runner/stub-runner-spring/build.gradle b/stub-runner/stub-runner-spring/build.gradle deleted file mode 100644 index acb0432826..0000000000 --- a/stub-runner/stub-runner-spring/build.gradle +++ /dev/null @@ -1,20 +0,0 @@ -description = 'Spring configuration for stub-runner' - -dependencies { - compile project(':stub-runner-root:stub-runner') - - compile localGroovy() - compile "org.springframework:spring-context:${springVersion}" - - testCompile('org.spockframework:spock-core:1.0-groovy-2.4') { - exclude(group: 'org.codehaus.groovy') - } - testCompile 'cglib:cglib-nodep:2.2' - testCompile 'org.objenesis:objenesis:2.1' - testCompile "org.springframework.boot:spring-boot-starter:${springBootVersion}" - testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" - testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { - exclude(group: 'org.codehaus.groovy') - } - testCompile 'ch.qos.logback:logback-classic:1.1.3' -} diff --git a/stub-runner/stub-runner-spring/src/main/resources/META-INF/spring.factories b/stub-runner/stub-runner-spring/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 24ddd934bf..0000000000 --- a/stub-runner/stub-runner-spring/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,3 +0,0 @@ -# Auto Configuration -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -io.codearte.accurest.stubrunner.spring.StubRunnerConfiguration \ No newline at end of file diff --git a/stub-runner/stub-runner-spring/src/test/groovy/io/codearte/accurest/stubrunner/spring/StubRunnerConfigurationSpec.groovy b/stub-runner/stub-runner-spring/src/test/groovy/io/codearte/accurest/stubrunner/spring/StubRunnerConfigurationSpec.groovy deleted file mode 100644 index a6800015b6..0000000000 --- a/stub-runner/stub-runner-spring/src/test/groovy/io/codearte/accurest/stubrunner/spring/StubRunnerConfigurationSpec.groovy +++ /dev/null @@ -1,41 +0,0 @@ -package io.codearte.accurest.stubrunner.spring - -import io.codearte.accurest.stubrunner.StubFinder -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.boot.test.SpringApplicationContextLoader -import org.springframework.context.annotation.Configuration -import org.springframework.context.annotation.Import -import org.springframework.test.context.ContextConfiguration -import spock.lang.Specification - -/** - * @author Marcin Grzejszczak - */ -// tag::test[] -@ContextConfiguration(classes = Config, loader = SpringApplicationContextLoader) -class StubRunnerConfigurationSpec extends Specification { - - @Autowired StubFinder stubFinder - - def 'should start WireMock servers'() { - expect: 'WireMocks are running' - stubFinder.findStubUrl('io.codearte.accurest.stubs', 'loanIssuance') != null - stubFinder.findStubUrl('loanIssuance') != null - stubFinder.findStubUrl('loanIssuance') == stubFinder.findStubUrl('io.codearte.accurest.stubs', 'loanIssuance') - stubFinder.findStubUrl('io.codearte.accurest.stubs:fraudDetectionServer') != null - and: - stubFinder.findAllRunningStubs().isPresent('loanIssuance') - stubFinder.findAllRunningStubs().isPresent('io.codearte.accurest.stubs', 'fraudDetectionServer') - stubFinder.findAllRunningStubs().isPresent('io.codearte.accurest.stubs:fraudDetectionServer') - and: 'Stubs were registered' - "${stubFinder.findStubUrl('loanIssuance').toString()}/name".toURL().text == 'loanIssuance' - "${stubFinder.findStubUrl('fraudDetectionServer').toString()}/name".toURL().text == 'fraudDetectionServer' - } - - @Configuration - @Import(StubRunnerConfiguration) - @EnableAutoConfiguration - static class Config {} -} -// end::test[] \ No newline at end of file diff --git a/stub-runner/stub-runner-spring/src/test/resources/application.yml b/stub-runner/stub-runner-spring/src/test/resources/application.yml deleted file mode 100644 index 25ca710cb7..0000000000 --- a/stub-runner/stub-runner-spring/src/test/resources/application.yml +++ /dev/null @@ -1,2 +0,0 @@ -stubrunner.stubs.repository.root: classpath:m2repo/repository/ -stubrunner.stubs.ids: io.codearte.accurest.stubs:loanIssuance,io.codearte.accurest.stubs:fraudDetectionServer \ No newline at end of file diff --git a/stub-runner/stub-runner-spring/src/test/resources/logback.xml b/stub-runner/stub-runner-spring/src/test/resources/logback.xml deleted file mode 100644 index 0cfb35f4cd..0000000000 --- a/stub-runner/stub-runner-spring/src/test/resources/logback.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - \ No newline at end of file diff --git a/stub-runner/stub-runner-spring/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT.pom b/stub-runner/stub-runner-spring/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT.pom deleted file mode 100644 index 9f04720f7d..0000000000 --- a/stub-runner/stub-runner-spring/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT.pom +++ /dev/null @@ -1,9 +0,0 @@ - - - 4.0.0 - io.codearte.accurest.stubs - fraudDetectionServer - 0.0.1-SNAPSHOT - pom - diff --git a/stub-runner/stub-runner-spring/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/maven-metadata.xml b/stub-runner/stub-runner-spring/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/maven-metadata.xml deleted file mode 100644 index d4ab9afc83..0000000000 --- a/stub-runner/stub-runner-spring/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/fraudDetectionServer/maven-metadata.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - io.codearte.accurest.stubs - fraudDetectionServer - 0.0.1-SNAPSHOT - - - 0.0.1-SNAPSHOT - - 20160409062112 - - diff --git a/stub-runner/stub-runner-spring/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT.pom b/stub-runner/stub-runner-spring/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT.pom deleted file mode 100644 index 9185d4bc8f..0000000000 --- a/stub-runner/stub-runner-spring/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT.pom +++ /dev/null @@ -1,9 +0,0 @@ - - - 4.0.0 - io.codearte.accurest.stubs - loanIssuance - 0.0.1-SNAPSHOT - pom - diff --git a/stub-runner/stub-runner-spring/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/maven-metadata.xml b/stub-runner/stub-runner-spring/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/maven-metadata.xml deleted file mode 100644 index bf14a1ad21..0000000000 --- a/stub-runner/stub-runner-spring/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/loanIssuance/maven-metadata.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - io.codearte.accurest.stubs - loanIssuance - 0.0.1-SNAPSHOT - - - 0.0.1-SNAPSHOT - - 20160409062111 - - diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/Arguments.groovy b/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/Arguments.groovy deleted file mode 100644 index cccf0f91aa..0000000000 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/Arguments.groovy +++ /dev/null @@ -1,27 +0,0 @@ -package io.codearte.accurest.stubrunner - -import groovy.transform.CompileStatic -import groovy.transform.PackageScope -import groovy.transform.ToString - -/** - * Arguments passed to the {@link StubRunner} application - * - * @see StubRunner - */ -@CompileStatic -@ToString(includeNames = true) -@PackageScope -class Arguments { - final StubRunnerOptions stubRunnerOptions - final String context - final String repositoryPath - final StubConfiguration stub - - Arguments(StubRunnerOptions stubRunnerOptions, String repositoryPath = "", StubConfiguration stub = null) { - this.stubRunnerOptions = stubRunnerOptions - this.context = context - this.repositoryPath = repositoryPath - this.stub = stub - } -} diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/BatchStubRunnerFactory.groovy b/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/BatchStubRunnerFactory.groovy deleted file mode 100644 index 6c7061da7e..0000000000 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/BatchStubRunnerFactory.groovy +++ /dev/null @@ -1,43 +0,0 @@ -package io.codearte.accurest.stubrunner - -import groovy.transform.CompileStatic -import io.codearte.accurest.messaging.AccurestMessaging -import io.codearte.accurest.messaging.noop.NoOpAccurestMessaging - -/** - * Manages lifecycle of multiple {@link StubRunner} instances. - * - * @see StubRunner - * @see BatchStubRunner - */ -@CompileStatic -class BatchStubRunnerFactory { - - private final StubRunnerOptions stubRunnerOptions - private final StubDownloader stubDownloader - private final AccurestMessaging accurestMessaging - - BatchStubRunnerFactory(StubRunnerOptions stubRunnerOptions) { - this(stubRunnerOptions, new AetherStubDownloader(stubRunnerOptions), new NoOpAccurestMessaging()) - } - - BatchStubRunnerFactory(StubRunnerOptions stubRunnerOptions, AccurestMessaging accurestMessaging) { - this(stubRunnerOptions, new AetherStubDownloader(stubRunnerOptions), accurestMessaging) - } - - BatchStubRunnerFactory(StubRunnerOptions stubRunnerOptions, StubDownloader stubDownloader) { - this(stubRunnerOptions, stubDownloader, new NoOpAccurestMessaging()) - } - - BatchStubRunnerFactory(StubRunnerOptions stubRunnerOptions, StubDownloader stubDownloader, AccurestMessaging accurestMessaging) { - this.stubRunnerOptions = stubRunnerOptions - this.stubDownloader = stubDownloader - this.accurestMessaging = accurestMessaging - } - - BatchStubRunner buildBatchStubRunner() { - StubRunnerFactory stubRunnerFactory = new StubRunnerFactory(stubRunnerOptions, stubDownloader, accurestMessaging) - return new BatchStubRunner(stubRunnerFactory.createStubsFromServiceConfiguration()) - } - -} diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/GroovyDslWrapper.groovy b/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/GroovyDslWrapper.groovy deleted file mode 100644 index dbd73859b9..0000000000 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/GroovyDslWrapper.groovy +++ /dev/null @@ -1,23 +0,0 @@ -package io.codearte.accurest.stubrunner - -import groovy.transform.CompileStatic -import groovy.transform.PackageScope -import io.codearte.accurest.dsl.GroovyDsl - -/** - * @author Marcin Grzejszczak - */ -@PackageScope -@CompileStatic -class GroovyDslWrapper { - - @Delegate final GroovyDsl groovyDsl - - GroovyDslWrapper(GroovyDsl groovyDsl) { - this.groovyDsl = groovyDsl - } - - boolean hasHttpPart() { - return groovyDsl.request - } -} diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/MessageNotMatchingException.groovy b/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/MessageNotMatchingException.groovy deleted file mode 100644 index 62368d75bf..0000000000 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/MessageNotMatchingException.groovy +++ /dev/null @@ -1,12 +0,0 @@ -package io.codearte.accurest.stubrunner - -import groovy.transform.InheritConstructors - -/** - * Exception thrown when message is not matched - * - * @author Marcin Grzejszczak - */ -@InheritConstructors -class MessageNotMatchingException extends RuntimeException { -} diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubData.groovy b/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubData.groovy deleted file mode 100644 index dbbe08c4c6..0000000000 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubData.groovy +++ /dev/null @@ -1,15 +0,0 @@ -package io.codearte.accurest.stubrunner - -import groovy.transform.CompileStatic -import groovy.transform.EqualsAndHashCode -import io.codearte.accurest.dsl.GroovyDsl - -/** - * @author Marcin Grzejszczak - */ -@CompileStatic -@EqualsAndHashCode -class StubData { - final Integer port - final List contracts -} diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubDownloader.groovy b/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubDownloader.groovy deleted file mode 100644 index e3391a67ef..0000000000 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubDownloader.groovy +++ /dev/null @@ -1,12 +0,0 @@ -package io.codearte.accurest.stubrunner - -interface StubDownloader { - - /** - * Returns a mapping of updated StubConfiguration (it will contain the resolved version) and the location of the downloaded JAR. - * If there was no artifact this method will return {@code null}. - */ - Map.Entry downloadAndUnpackStubJar(StubRunnerOptions options, StubConfiguration stubConfiguration) - - -} \ No newline at end of file diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubFinder.groovy b/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubFinder.groovy deleted file mode 100644 index f69f88044c..0000000000 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubFinder.groovy +++ /dev/null @@ -1,33 +0,0 @@ -package io.codearte.accurest.stubrunner - -import io.codearte.accurest.dsl.GroovyDsl - -interface StubFinder extends StubTrigger { - /** - * For the given groupId and artifactId tries to find the matching - * URL of the running stub. - * - * @param groupId - might be null. In that case a search only via artifactId takes place - * @return URL of a running stub or null if not found - */ - URL findStubUrl(String groupId, String artifactId) - - /** - * For the given Ivy notation {@code groupId:artifactId} tries to find the matching - * URL of the running stub. You can also pass only {@code artifactId}. - * - * @param ivyNotation - Ivy representation of the Maven artifact - * @return URL of a running stub or null if not found - */ - URL findStubUrl(String ivyNotation) - - /** - * Returns all running stubs - */ - RunningStubs findAllRunningStubs() - - /** - * Returns the list of Accurest contracts - */ - Map> getAccurestContracts() -} \ No newline at end of file diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunnerMessagingTrigger.groovy b/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunnerMessagingTrigger.groovy deleted file mode 100644 index 0fd2ef1c8a..0000000000 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunnerMessagingTrigger.groovy +++ /dev/null @@ -1,18 +0,0 @@ -package io.codearte.accurest.stubrunner - -import groovy.transform.PackageScope -import io.codearte.accurest.messaging.AccurestMessaging -/** - * @author Marcin Grzejszczak - */ -@PackageScope -class StubRunnerMessagingTrigger { - - private final AccurestMessaging accurestMessaging - - StubRunnerMessagingTrigger(AccurestMessaging accurestMessaging) { - this.accurestMessaging = accurestMessaging - } - - void trigger -} diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunning.groovy b/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunning.groovy deleted file mode 100644 index 15941448b4..0000000000 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunning.groovy +++ /dev/null @@ -1,9 +0,0 @@ -package io.codearte.accurest.stubrunner - -interface StubRunning extends Closeable, StubFinder { - /** - * Runs the stubs and returns the {@link RunningStubs} - */ - RunningStubs runStubs() - -} \ No newline at end of file diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/WiremockMappingDescriptor.groovy b/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/WiremockMappingDescriptor.groovy deleted file mode 100644 index d8cb688f8c..0000000000 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/WiremockMappingDescriptor.groovy +++ /dev/null @@ -1,27 +0,0 @@ -package io.codearte.accurest.stubrunner - -import com.github.tomakehurst.wiremock.stubbing.StubMapping -import groovy.transform.CompileStatic -import groovy.transform.EqualsAndHashCode -import groovy.transform.PackageScope -import groovy.transform.ToString - -/** - * Represents a single JSON file that was found in the folder with - * potential WireMock stubs - */ -@CompileStatic -@EqualsAndHashCode -@ToString(includePackage = false) -@PackageScope -class WiremockMappingDescriptor { - final File descriptor - - WiremockMappingDescriptor(File mappingDescriptor) { - this.descriptor = mappingDescriptor - } - - StubMapping getMapping() { - return StubMapping.buildFrom(descriptor.getText('UTF-8')) - } -} diff --git a/stub-runner/stub-runner/src/main/resources/accurestStubrunnerGrapeConfig.xml b/stub-runner/stub-runner/src/main/resources/accurestStubrunnerGrapeConfig.xml deleted file mode 100644 index 2054715610..0000000000 --- a/stub-runner/stub-runner/src/main/resources/accurestStubrunnerGrapeConfig.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/MappingDescriptorSpec.groovy b/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/MappingDescriptorSpec.groovy deleted file mode 100644 index 6e04a8beef..0000000000 --- a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/MappingDescriptorSpec.groovy +++ /dev/null @@ -1,23 +0,0 @@ -package io.codearte.accurest.stubrunner - -import com.github.tomakehurst.wiremock.http.RequestMethod -import spock.lang.Specification - -class MappingDescriptorSpec extends Specification { - public static - final File MAPPING_DESCRIPTOR = new File('src/test/resources/repository/mappings/com/ofg/ping/ping.json') - - def 'should describe stub mapping'() { - given: - WiremockMappingDescriptor mappingDescriptor = new WiremockMappingDescriptor(MAPPING_DESCRIPTOR) - - expect: - with(mappingDescriptor.mapping) { - request.method == RequestMethod.GET - request.url == '/ping' - response.status == 200 - response.body == 'pong' - response.headers.contentTypeHeader.mimeTypePart() == 'text/plain' - } - } -} diff --git a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/StubConfigurationSpec.groovy b/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/StubConfigurationSpec.groovy deleted file mode 100644 index 87b346da94..0000000000 --- a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/StubConfigurationSpec.groovy +++ /dev/null @@ -1,21 +0,0 @@ -package io.codearte.accurest.stubrunner - -import spock.lang.Specification - -/** - * @author Marcin Grzejszczak - */ -class StubConfigurationSpec extends Specification { - - def 'should parse ivy notation'() { - given: - String ivy = 'group:artifact:version:classifier' - when: - StubConfiguration stubConfiguration = new StubConfiguration(ivy) - then: - stubConfiguration.artifactId == 'artifact' - stubConfiguration.groupId == 'group' - stubConfiguration.classifier == 'classifier' - stubConfiguration.version == 'version' - } -} diff --git a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/util/ZipCategorySpec.groovy b/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/util/ZipCategorySpec.groovy deleted file mode 100644 index 2a3f5e16ef..0000000000 --- a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/util/ZipCategorySpec.groovy +++ /dev/null @@ -1,24 +0,0 @@ -package io.codearte.accurest.stubrunner.util - -import groovy.util.logging.Slf4j -import spock.lang.Specification - -@Slf4j -class ZipCategorySpec extends Specification { - - def 'should unzip a file to the specified location'() { - given: - File zipFile = new File(ZipCategorySpec.classLoader.getResource('file.zip').toURI()) - File tempDir = File.createTempDir() - tempDir.deleteOnExit() - when: - use(ZipCategory) { - zipFile.unzipTo(tempDir) - } - then: - tempDir.listFiles().find { - it.name == 'file.txt' - }?.text?.trim() == 'test' - } - -} diff --git a/stub-runner/stub-runner/src/test/resources/anotherRepository/projects/brokers/brokers.json b/stub-runner/stub-runner/src/test/resources/anotherRepository/projects/brokers/brokers.json deleted file mode 100644 index bfc64f392c..0000000000 --- a/stub-runner/stub-runner/src/test/resources/anotherRepository/projects/brokers/brokers.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "pl": [ - "com/ofg/bar" - ] -} \ No newline at end of file diff --git a/stub-runner/stub-runner/src/test/resources/anotherRepository/projects/brokers/nested/anotherDescriptor.json b/stub-runner/stub-runner/src/test/resources/anotherRepository/projects/brokers/nested/anotherDescriptor.json deleted file mode 100644 index fe635a1b3a..0000000000 --- a/stub-runner/stub-runner/src/test/resources/anotherRepository/projects/brokers/nested/anotherDescriptor.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "pl": [ - "com/ofg/foo/bar" - ] -} \ No newline at end of file diff --git a/stub-runner/stub-runner/src/test/resources/anotherRepository/projects/descriptor.json b/stub-runner/stub-runner/src/test/resources/anotherRepository/projects/descriptor.json deleted file mode 100644 index 7ecd1e1ed6..0000000000 --- a/stub-runner/stub-runner/src/test/resources/anotherRepository/projects/descriptor.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "pl": [ - "com/ofg/foo" - ] -} \ No newline at end of file diff --git a/stub-runner/stub-runner/src/test/resources/logback.xml b/stub-runner/stub-runner/src/test/resources/logback.xml deleted file mode 100644 index 0cfb35f4cd..0000000000 --- a/stub-runner/stub-runner/src/test/resources/logback.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - \ No newline at end of file