diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..ddda9782f6 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,24 @@ +root = true + +[*.java] +indent_style = tab +indent_size = 4 +continuation_indent_size = 8 + +[*.groovy] +indent_style = tab +indent_size = 4 +continuation_indent_size = 8 + +[*.xml] +indent_style = tab +indent_size = 4 +continuation_indent_size = 8 + +[*.yml] +indent_style = space +indent_size = 2 + +[*.yaml] +indent_style = space +indent_size = 2 diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java index d475a89ce1..f3e6046f04 100755 --- a/.mvn/wrapper/MavenWrapperDownloader.java +++ b/.mvn/wrapper/MavenWrapperDownloader.java @@ -1,3 +1,4 @@ + /* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -17,94 +18,100 @@ specific language governing permissions and limitations under the License. */ -import java.net.*; -import java.io.*; -import java.nio.channels.*; import java.util.Properties; public class MavenWrapperDownloader { - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = - "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is + * provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to - * use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = - ".mvn/wrapper/maven-wrapper.properties"; + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl + * property to use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = ".mvn/wrapper/maven-wrapper.properties"; - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = - ".mvn/wrapper/maven-wrapper.jar"; + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar"; - /** - * Name of the property which should be used to override the default download url for the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + /** + * Name of the property which should be used to override the default download url for + * the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - // If the maven-wrapper.properties exists, read it and check if it contains a custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } finally { - try { - if(mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: : " + url); + // If the maven-wrapper.properties exists, read it and check if it contains a + // custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, + MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if (mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream( + mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } + catch (IOException e) { + System.out.println( + "- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } + finally { + try { + if (mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } + catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { - System.out.println( - "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } + File outputFile = new File(baseDirectory.getAbsolutePath(), + MAVEN_WRAPPER_JAR_PATH); + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { + System.out.println("- ERROR creating output direcrory '" + + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } + catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } - private static void downloadFileFromURL(String urlString, File destination) throws Exception { - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } + private static void downloadFileFromURL(String urlString, File destination) + throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } } diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar index 08ebbb67f0..01e6799737 100755 Binary files a/.mvn/wrapper/maven-wrapper.jar and b/.mvn/wrapper/maven-wrapper.jar differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties index a5fcc11920..00d32aab1d 100755 --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -1 +1 @@ -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip \ No newline at end of file +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip \ No newline at end of file diff --git a/.settings.xml b/.settings.xml index 32e8266cce..1261ef8f76 100644 --- a/.settings.xml +++ b/.settings.xml @@ -1,73 +1,77 @@ - - - repo.spring.io - ${env.CI_DEPLOY_USERNAME} - ${env.CI_DEPLOY_PASSWORD} - - - - - - spring - true - - - spring-snapshots - Spring Snapshots - http://repo.spring.io/libs-snapshot-local - - true - - - - spring-milestones - Spring Milestones - http://repo.spring.io/libs-milestone-local - - false - - - - spring-releases - Spring Releases - http://repo.spring.io/release - - false - - - - - - spring-snapshots - Spring Snapshots - http://repo.spring.io/libs-snapshot-local - - true - - - - spring-milestones - Spring Milestones - http://repo.spring.io/libs-milestone-local - - false - - - - - - - ide - true - - + + + repo.spring.io + ${env.CI_DEPLOY_USERNAME} + ${env.CI_DEPLOY_PASSWORD} + + + + + + spring + + true + + + + spring-snapshots + Spring Snapshots + http://repo.spring.io/libs-snapshot-local + + true + + + + spring-milestones + Spring Milestones + http://repo.spring.io/libs-milestone-local + + false + + + + spring-releases + Spring Releases + http://repo.spring.io/release + + false + + + + + + spring-snapshots + Spring Snapshots + http://repo.spring.io/libs-snapshot-local + + true + + + + spring-milestones + Spring Milestones + http://repo.spring.io/libs-milestone-local + + false + + + + + + + ide + + true + + + diff --git a/.springformat b/.springformat new file mode 100644 index 0000000000..e69de29bb2 diff --git a/README.adoc b/README.adoc index 6c7d01df16..56d6396d96 100644 --- a/README.adoc +++ b/README.adoc @@ -337,19 +337,19 @@ The following example shows a Camel messaging contract expressed in Groovy DSL: [source,groovy] ---- -def contractDsl = Contract.make { - label 'some_label' - input { - messageFrom('jms:delete') - messageBody([ - bookName: 'foo' - ]) - messageHeaders { - header('sample', 'header') - } - assertThat('bookWasDeleted()') - } -} + def contractDsl = Contract.make { + label 'some_label' + input { + messageFrom('jms:delete') + messageBody([ + bookName: 'foo' + ]) + messageHeaders { + header('sample', 'header') + } + assertThat('bookWasDeleted()') + } + } ---- The following example shows the same contract expressed in YAML: @@ -604,6 +604,22 @@ the PUT method. .Groovy DSL [source,groovy,indent=0] ---- +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts org.springframework.cloud.contract.spec.Contract.make { @@ -612,7 +628,7 @@ org.springframework.cloud.contract.spec.Contract.make { url '/fraudcheck' // (3) body([ // (4) "client.id": $(regex('[0-9]{10}')), - loanAmount: 99999 + loanAmount : 99999 ]) headers { // (5) contentType('application/json') @@ -621,7 +637,7 @@ org.springframework.cloud.contract.spec.Contract.make { response { // (6) status OK() // (7) body([ // (8) - fraudCheckStatus: "FRAUD", + fraudCheckStatus : "FRAUD", "rejection.reason": "Amount too high" ]) headers { // (9) @@ -730,10 +746,9 @@ At some point in time, you need to send a request to the Fraud Detection service [source,groovy,indent=0] ---- -ResponseEntity response = - restTemplate.exchange("http://localhost:" + port + "/fraudcheck", HttpMethod.PUT, - new HttpEntity<>(request, httpHeaders), - FraudServiceResponse.class); +ResponseEntity response = restTemplate.exchange( + "http://localhost:" + port + "/fraudcheck", HttpMethod.PUT, + new HttpEntity<>(request, httpHeaders), FraudServiceResponse.class); ---- Annotate your test class with `@AutoConfigureStubRunner`. In the annotation provide the group id and artifact id for the Stub Runner to download stubs of your collaborators. @@ -742,9 +757,10 @@ Annotate your test class with `@AutoConfigureStubRunner`. In the annotation prov ---- @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.NONE) -@AutoConfigureStubRunner(ids = {"com.example:http-server-dsl:+:stubs:6565"}, - stubsMode = StubRunnerProperties.StubsMode.LOCAL) +@AutoConfigureStubRunner(ids = { + "com.example:http-server-dsl:+:stubs:6565" }, stubsMode = StubRunnerProperties.StubsMode.LOCAL) public class LoanApplicationServiceTests { + ---- After that, during the tests, Spring Cloud Contract automatically finds the stubs @@ -928,10 +944,9 @@ client wants to borrow. You want to send it to the `/fraudcheck` url via the `PU [source,groovy,indent=0] ---- -ResponseEntity response = - restTemplate.exchange("http://localhost:" + port + "/fraudcheck", HttpMethod.PUT, - new HttpEntity<>(request, httpHeaders), - FraudServiceResponse.class); +ResponseEntity response = restTemplate.exchange( + "http://localhost:" + port + "/fraudcheck", HttpMethod.PUT, + new HttpEntity<>(request, httpHeaders), FraudServiceResponse.class); ---- For simplicity, the port of the Fraud Detection service is set to `8080`, and the @@ -961,6 +976,22 @@ is important because the producer's test base class name references that folder. .Groovy DSL [source,groovy,indent=0] ---- +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts org.springframework.cloud.contract.spec.Contract.make { @@ -969,7 +1000,7 @@ org.springframework.cloud.contract.spec.Contract.make { url '/fraudcheck' // (3) body([ // (4) "client.id": $(regex('[0-9]{10}')), - loanAmount: 99999 + loanAmount : 99999 ]) headers { // (5) contentType('application/json') @@ -978,7 +1009,7 @@ org.springframework.cloud.contract.spec.Contract.make { response { // (6) status OK() // (7) body([ // (8) - fraudCheckStatus: "FRAUD", + fraudCheckStatus : "FRAUD", "rejection.reason": "Amount too high" ]) headers { // (9) @@ -1228,9 +1259,10 @@ can also provide the offline work switch (`StubRunnerProperties.StubsMode.LOCAL` ---- @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.NONE) -@AutoConfigureStubRunner(ids = {"com.example:http-server-dsl:+:stubs:6565"}, - stubsMode = StubRunnerProperties.StubsMode.LOCAL) +@AutoConfigureStubRunner(ids = { + "com.example:http-server-dsl:+:stubs:6565" }, stubsMode = StubRunnerProperties.StubsMode.LOCAL) public class LoanApplicationServiceTests { + ---- Now, when you run your tests, you see something like this: @@ -1323,12 +1355,29 @@ start the server side `FraudDetectionController`. [source,java,indent=0] ---- +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; import io.restassured.module.mockmvc.RestAssuredMockMvc; import org.junit.Before; public class FraudBase { + @Before public void setup() { RestAssuredMockMvc.standaloneSetup(new FraudDetectionController(), @@ -1350,6 +1399,7 @@ public class FraudBase { public void assertThatRejectionReasonIsNull(Object rejectionReason) { assert rejectionReason == null; } + } ---- @@ -1537,6 +1587,12 @@ public class WiremockForDocsTests { @Autowired private Service service; + @Before + public void setup() { + this.service.setBase("http://localhost:" + + this.environment.getProperty("wiremock.server.port")); + } + // Using the WireMock APIs in the normal way: @Test public void contextLoads() throws Exception { @@ -1629,15 +1685,15 @@ public class WiremockForDocsClassRuleTests { public static WireMockClassRule wiremock = new WireMockClassRule( WireMockSpring.options().dynamicPort()); + // A service that calls out over HTTP to wiremock's port + @Autowired + private Service service; + @Before public void setup() { this.service.setBase("http://localhost:" + wiremock.port()); } - // A service that calls out over HTTP to wiremock's port - @Autowired - private Service service; - // Using the WireMock APIs in the normal way: @Test public void contextLoads() throws Exception { @@ -2000,6 +2056,8 @@ You can read more about Spring Cloud Contract Verifier by reading the == Contributing +:spring-cloud-build-branch: master + 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 @@ -2045,6 +2103,138 @@ added after the original pull request but before a merge. 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). +=== Checkstyle + +Spring Cloud Build comes with a set of checkstyle rules. You can find them in the `spring-cloud-build-tools` module. The most notable files under the module are: + +.spring-cloud-build-tools/ +---- +└── src +    ├── checkstyle +    │   └── checkstyle-suppressions.xml <3> +    └── main +    └── resources +    ├── checkstyle-header.txt <2> +    └── checkstyle.xml <1> +---- +<1> Default Checkstyle rules +<2> File header setup +<3> Default suppression rules + +==== Checkstyle configuration + +Checkstyle rules are *disabled by default*. To add checkstyle to your project just define the following properties and plugins. + +.pom.xml +---- + +true <1> + true + <2> + true + <3> + + + + + <4> + io.spring.javaformat + spring-javaformat-maven-plugin + + <5> + org.apache.maven.plugins + maven-checkstyle-plugin + + + + + + <5> + org.apache.maven.plugins + maven-checkstyle-plugin + + + + +---- +<1> Fails the build upon Checkstyle errors +<2> Fails the build upon Checkstyle violations +<3> Checkstyle analyzes also the test sources +<4> Add the Spring Java Format plugin that will reformat your code to pass most of the Checkstyle formatting rules +<5> Add checkstyle plugin to your build and reporting phases + +If you need to suppress some rules (e.g. line length needs to be longer), then it's enough for you to define a file under `${project.root}/src/checkstyle/checkstyle-suppressions.xml` with your suppressions. Example: + +.projectRoot/src/checkstyle/checkstyle-suppresions.xml +---- + + + + + + +---- + +It's advisable to copy the `${spring-cloud-build.rootFolder}/.editorconfig` and `${spring-cloud-build.rootFolder}/.springformat` to your project. That way, some default formatting rules will be applied. You can do so by running this script: + +```bash +$ curl https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/.editorconfig -o .editorconfig +$ touch .springformat +``` + +=== IDE setup + +==== Intellij IDEA + +In order to setup Intellij you should import our coding conventions, inspection profiles and set up the checkstyle plugin. + +.spring-cloud-build-tools/ +---- +└── src +    ├── checkstyle +    │   └── checkstyle-suppressions.xml <3> +    └── main +    └── resources +    ├── checkstyle-header.txt <2> +    ├── checkstyle.xml <1> +    └── intellij +       ├── Intellij_Project_Defaults.xml <4> +       └── Intellij_Spring_Boot_Java_Conventions.xml <5> +---- +<1> Default Checkstyle rules +<2> File header setup +<3> Default suppression rules +<4> Project defaults for Intellij that apply most of Checkstyle rules +<5> Project style conventions for Intellij that apply most of Checkstyle rules + +.Code style + +image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-code-style.png[Code style] + +Go to `File` -> `Settings` -> `Editor` -> `Code style`. There click on the icon next to the `Scheme` section. There, click on the `Import Scheme` value and pick the `Intellij IDEA code style XML` option. Import the `spring-cloud-build-tools/src/main/resources/intellij/Intellij_Spring_Boot_Java_Conventions.xml` file. + +.Inspection profiles + +image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-inspections.png[Code style] + +Go to `File` -> `Settings` -> `Editor` -> `Inspections`. There click on the icon next to the `Profile` section. There, click on the `Import Profile` and import the `spring-cloud-build-tools/src/main/resources/intellij/Intellij_Project_Defaults.xml` file. + +.Checkstyle + +To have Intellij work with Checkstyle, you have to install the `Checkstyle` plugin. It's advisable to also install the `Assertions2Assertj` to automatically convert the JUnit assertions + +image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-checkstyle.png[Checkstyle] + +Go to `File` -> `Settings` -> `Other settings` -> `Checkstyle`. There click on the `+` icon in the `Configuration file` section. There, you'll have to define where the checkstyle rules should be picked from. In the image above, we've picked the rules from the cloned Spring Cloud Build repository. However, you can point to the Spring Cloud Build's GitHub repository (e.g. for the `checkstyle.xml` : `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle.xml`). We need to provide the following variables: + +- `checkstyle.header.file` - please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/main/resources/checkstyle/checkstyle-header.txt` file either in your cloned repo or via the `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle-header.txt` URL. +- `checkstyle.suppressions.file` - default suppressions. Please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` file either in your cloned repo or via the `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` URL. +- `checkstyle.additional.suppressions.file` - this variable corresponds to suppressions in your local project. E.g. you're working on `spring-cloud-contract`. Then point to the `project-root/src/checkstyle/checkstyle-suppressions.xml` folder. Example for `spring-cloud-contract` would be: `/home/username/spring-cloud-contract/src/checkstyle/checkstyle-suppressions.xml`. + +IMPORTANT: Remember to set the `Scan Scope` to `All sources` since we apply checkstyle rules for production and test sources. + == How to build it IMPORTANT: You need to have all the necessary Groovy plugins diff --git a/asciidoctor.css b/asciidoctor.css index 06d52e688a..022f01b166 100644 --- a/asciidoctor.css +++ b/asciidoctor.css @@ -1,399 +1,2011 @@ /* 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 +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 + } +} diff --git a/circle.yml b/circle.yml index 36a3437564..398873c62e 100644 --- a/circle.yml +++ b/circle.yml @@ -11,18 +11,18 @@ machine: TERM: dumb dependencies: pre: - - | - sudo service zookeeper stop || echo "Service not running" - sudo service cassandra stop || echo "Service not running" - sudo service elasticsearch stop || echo "Service not running" - sudo service rabbitmq-server stop || echo "Service not running" - sudo service redis stop || echo "Service not running" - sudo service riak stop || echo "Service not running" - sudo service beanstalkd stop || echo "Service not running" - sudo service couchbase-server stop || echo "Service not running" - sudo service neo4j stop || echo "Service not running" - sudo service sphinxsearch stop || echo "Service not running" - sudo service postgresql stop || echo "Service not running" + - | + sudo service zookeeper stop || echo "Service not running" + sudo service cassandra stop || echo "Service not running" + sudo service elasticsearch stop || echo "Service not running" + sudo service rabbitmq-server stop || echo "Service not running" + sudo service redis stop || echo "Service not running" + sudo service riak stop || echo "Service not running" + sudo service beanstalkd stop || echo "Service not running" + sudo service couchbase-server stop || echo "Service not running" + sudo service neo4j stop || echo "Service not running" + sudo service sphinxsearch stop || echo "Service not running" + sudo service postgresql stop || echo "Service not running" - touch ~/.gradle/gradle.properties && echo "org.gradle.daemon=false" >> ~/.gradle/gradle.properties override: - ./scripts/downloadDependencies.sh diff --git a/docker/pom.xml b/docker/pom.xml index 22e5351578..74dd596ada 100644 --- a/docker/pom.xml +++ b/docker/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 diff --git a/docker/spring-cloud-contract-docker/pom.xml b/docker/spring-cloud-contract-docker/pom.xml index 4f2484743c..6ee3871165 100644 --- a/docker/spring-cloud-contract-docker/pom.xml +++ b/docker/spring-cloud-contract-docker/pom.xml @@ -1,6 +1,6 @@ - 4.0.0 diff --git a/docker/spring-cloud-contract-docker/project/build.gradle b/docker/spring-cloud-contract-docker/project/build.gradle index 7400c5b0e7..b881859a7c 100644 --- a/docker/spring-cloud-contract-docker/project/build.gradle +++ b/docker/spring-cloud-contract-docker/project/build.gradle @@ -61,7 +61,8 @@ contracts { baseClassForTests = "contracts.RestBase" testMode = "EXPLICIT" if (getProp("EXTERNAL_CONTRACTS_ARTIFACT_ID")) { - logger.lifecycle("Will use an artifact with contracts [${getProp("EXTERNAL_CONTRACTS_GROUP_ID")}:${getProp("EXTERNAL_CONTRACTS_ARTIFACT_ID")}]") + logger. + lifecycle("Will use an artifact with contracts [${getProp("EXTERNAL_CONTRACTS_GROUP_ID")}:${getProp("EXTERNAL_CONTRACTS_ARTIFACT_ID")}]") // tests - contracts from an artifact contractsPath = getProp("EXTERNAL_CONTRACTS_PATH") ?: "" if (Boolean.parseBoolean(getProp("EXTERNAL_CONTRACTS_WORK_OFFLINE")) == false) { @@ -76,8 +77,10 @@ contracts { delegate.classifier = getProp("EXTERNAL_CONTRACTS_CLASSIFIER") ?: "" delegate.version = getProp("EXTERNAL_CONTRACTS_VERSION") ?: "+" } - contractsMode = Boolean.parseBoolean(getProp("EXTERNAL_CONTRACTS_WORK_OFFLINE")) ? "LOCAL" : "REMOTE" - } else { + contractsMode = Boolean. + parseBoolean(getProp("EXTERNAL_CONTRACTS_WORK_OFFLINE")) ? "LOCAL" : "REMOTE" + } + else { logger.lifecycle("Will use contracts from the mounted [/contracts] folder") // tests - contracts in this repo contractsDslDir = new File("/contracts") @@ -90,9 +93,9 @@ task wrapper(type: Wrapper) { task cleanOutput(type: Delete) { def dirName = "/spring-cloud-contract-output" - file(dirName).list().each { - f -> delete "${dirName}/${f}" - } + file(dirName).list().each { + f -> delete "${dirName}/${f}" + } } task copyOutput(type: Copy) { @@ -126,7 +129,9 @@ boolean publishEnabled = Boolean.parseBoolean(publishArtifacts) publish.setEnabled(publishEnabled) gradle.taskGraph.whenReady { graph -> - graph.allTasks.findAll { it.name.startsWith("publish") && "publishStubsToScm" != it.name }*.setEnabled(publishEnabled) + graph.allTasks. + findAll { it.name.startsWith("publish") && "publishStubsToScm" != it.name }*. + setEnabled(publishEnabled) } if (Boolean.parseBoolean(getProp("PUBLISH_STUBS_TO_SCM"))) { diff --git a/docker/spring-cloud-contract-docker/project/src/test/java/contracts/RestBase.java b/docker/spring-cloud-contract-docker/project/src/test/java/contracts/RestBase.java index 24e7b06354..294fb24c16 100644 --- a/docker/spring-cloud-contract-docker/project/src/test/java/contracts/RestBase.java +++ b/docker/spring-cloud-contract-docker/project/src/test/java/contracts/RestBase.java @@ -1,10 +1,25 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts; import io.restassured.RestAssured; import org.junit.Before; -import org.junit.ClassRule; import org.junit.runner.RunWith; -import org.junit.validator.ValidateWith; + import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; @@ -16,20 +31,23 @@ import org.springframework.util.StringUtils; * @author Marcin Grzejszczak */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = RestBase.Config.class, - webEnvironment = SpringBootTest.WebEnvironment.NONE) +@SpringBootTest(classes = RestBase.Config.class, webEnvironment = SpringBootTest.WebEnvironment.NONE) public abstract class RestBase { - @Value("${APPLICATION_BASE_URL}") String url; - @Value("${APPLICATION_USERNAME:}") String username; - @Value("${APPLICATION_PASSWORD:}") String password; + @Value("${APPLICATION_BASE_URL}") + String url; + + @Value("${APPLICATION_USERNAME:}") + String username; + + @Value("${APPLICATION_PASSWORD:}") + String password; @Before public void setup() { RestAssured.baseURI = this.url; if (StringUtils.hasText(this.username)) { - RestAssured.authentication = - RestAssured.basic(this.username, this.password); + RestAssured.authentication = RestAssured.basic(this.username, this.password); } } @@ -38,4 +56,5 @@ public abstract class RestBase { protected static class Config { } + } diff --git a/docker/spring-cloud-contract-stub-runner-docker/pom.xml b/docker/spring-cloud-contract-stub-runner-docker/pom.xml index 3ad2cd431b..084b85c23d 100644 --- a/docker/spring-cloud-contract-stub-runner-docker/pom.xml +++ b/docker/spring-cloud-contract-stub-runner-docker/pom.xml @@ -1,6 +1,6 @@ - 4.0.0 diff --git a/docs/pom.xml b/docs/pom.xml index 332d5e9804..4c5dc71963 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -1,6 +1,6 @@ - 4.0.0 diff --git a/mvnw b/mvnw index 961a825001..5551fde8e7 100755 --- a/mvnw +++ b/mvnw @@ -212,7 +212,7 @@ else if [ "$MVNW_VERBOSE" = true ]; then echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." fi - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar" + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" while IFS="=" read key value; do case "$key" in (wrapperUrl) jarUrl="$value"; break ;; esac diff --git a/mvnw.cmd b/mvnw.cmd index 03d90e960b..48363fa60b 100755 --- a/mvnw.cmd +++ b/mvnw.cmd @@ -120,7 +120,7 @@ SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar" +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B ) diff --git a/pom.xml b/pom.xml index e7532cdc51..963eb2ec3d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,6 @@ - 4.0.0 @@ -29,7 +29,8 @@ 3.5.13 0.0.9 2.1.3.BUILD-SNAPSHOT - 2.1.1.BUILD-SNAPSHOT + 2.1.1.BUILD-SNAPSHOT + Fishtown.BUILD-SNAPSHOT 2.1.1.BUILD-SNAPSHOT 2.1.1.BUILD-SNAPSHOT @@ -453,8 +454,11 @@ - scm:git:https://github.com/spring-cloud/spring-cloud-contract.git - scm:git:git@github.com:spring-cloud/spring-cloud-contract.git + scm:git:https://github.com/spring-cloud/spring-cloud-contract.git + + + scm:git:git@github.com:spring-cloud/spring-cloud-contract.git + https://github.com/spring-cloud/spring-cloud-contract HEAD @@ -515,6 +519,10 @@ + + io.spring.javaformat + spring-javaformat-maven-plugin + org.apache.maven.plugins maven-checkstyle-plugin @@ -609,7 +617,8 @@ surefireArgLine - ${project.build.directory}/jacoco.exec + ${project.build.directory}/jacoco.exec + @@ -620,7 +629,8 @@ - ${project.build.directory}/jacoco.exec + ${project.build.directory}/jacoco.exec + diff --git a/samples/pom.xml b/samples/pom.xml index 77b37941db..ac284536a1 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -1,7 +1,8 @@ - - 4.0.0 + + 4.0.0 org.springframework.cloud @@ -10,11 +11,11 @@ .. - spring-cloud-contract-samples - pom + spring-cloud-contract-samples + pom 2.1.1.BUILD-SNAPSHOT - Spring Cloud Contract Samples - Spring Cloud Contract Samples + Spring Cloud Contract Samples + Spring Cloud Contract Samples ${basedir}/.. diff --git a/samples/standalone/contracts/com/example/server/client1/expectation.groovy b/samples/standalone/contracts/com/example/server/client1/expectation.groovy index 9185953537..3db6fc0130 100644 --- a/samples/standalone/contracts/com/example/server/client1/expectation.groovy +++ b/samples/standalone/contracts/com/example/server/client1/expectation.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts org.springframework.cloud.contract.spec.Contract.make { @@ -5,7 +21,7 @@ org.springframework.cloud.contract.spec.Contract.make { method 'PUT' // (2) url '/fraudcheck' // (3) body([ // (4) - clientId: $(regex('[0-9]{10}')), + clientId : $(regex('[0-9]{10}')), loanAmount: 99999 ]) headers { // (5) @@ -16,7 +32,7 @@ org.springframework.cloud.contract.spec.Contract.make { status OK() // (7) body([ // (8) fraudCheckStatus: "FRAUD", - rejectionReason: "Amount too high" + rejectionReason : "Amount too high" ]) headers { // (9) contentType('application/vnd.fraud.v1+json') @@ -63,4 +79,4 @@ From the Producer perspective, in the autogenerated producer-side test: (8) - and JSON body equal to { "fraudCheckStatus": "FRAUD", "rejectionReason": "Amount too high" } (9) - with header `Content-Type` matching `application/vnd.fraud.v1+json.*` - */ \ No newline at end of file + */ diff --git a/samples/standalone/contracts/com/example/server/client2/expectation.groovy b/samples/standalone/contracts/com/example/server/client2/expectation.groovy index 5c98a9f735..7959510233 100644 --- a/samples/standalone/contracts/com/example/server/client2/expectation.groovy +++ b/samples/standalone/contracts/com/example/server/client2/expectation.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts org.springframework.cloud.contract.spec.Contract.make { @@ -5,7 +21,7 @@ org.springframework.cloud.contract.spec.Contract.make { method 'PUT' // (2) url '/fraudcheck2' // (3) body([ // (4) - clientId: value(consumer(regex('[0-9]{10}'))), + clientId : value(consumer(regex('[0-9]{10}'))), loanAmount: 99999 ]) headers { // (5) @@ -16,7 +32,7 @@ org.springframework.cloud.contract.spec.Contract.make { status OK() // (7) body([ // (8) fraudCheckStatus: "FRAUD", - rejectionReason: "Amount too high" + rejectionReason : "Amount too high" ]) headers { // (9) header('Content-Type': value( @@ -64,4 +80,4 @@ From the Producer perspective, in the autogenerated producer-side test: (8) - and JSON body equal to { "fraudCheckStatus": "FRAUD", "rejectionReason": "Amount too high" } (9) - with header `Content-Type` matching `application/vnd.fraud.v1+json.*` - */ \ No newline at end of file + */ diff --git a/samples/standalone/contracts/com/example/server/client3/expectation.groovy b/samples/standalone/contracts/com/example/server/client3/expectation.groovy index 49e278e0a6..dc094962b2 100644 --- a/samples/standalone/contracts/com/example/server/client3/expectation.groovy +++ b/samples/standalone/contracts/com/example/server/client3/expectation.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts org.springframework.cloud.contract.spec.Contract.make { @@ -5,7 +21,7 @@ org.springframework.cloud.contract.spec.Contract.make { method 'PUT' // (2) url '/fraudcheck3' // (3) body([ // (4) - clientId: value(consumer(regex('[0-9]{10}'))), + clientId : value(consumer(regex('[0-9]{10}'))), loanAmount: 99999 ]) headers { // (5) @@ -16,7 +32,7 @@ org.springframework.cloud.contract.spec.Contract.make { status OK() // (7) body([ // (8) fraudCheckStatus: "FRAUD", - rejectionReason: "Amount too high" + rejectionReason : "Amount too high" ]) headers { // (9) header('Content-Type': value( @@ -64,4 +80,4 @@ From the Producer perspective, in the autogenerated producer-side test: (8) - and JSON body equal to { "fraudCheckStatus": "FRAUD", "rejectionReason": "Amount too high" } (9) - with header `Content-Type` matching `application/vnd.fraud.v1+json.*` - */ \ No newline at end of file + */ diff --git a/samples/standalone/contracts/com/example/server/pom.xml b/samples/standalone/contracts/com/example/server/pom.xml index 3135dbc3c0..e27e327f52 100644 --- a/samples/standalone/contracts/com/example/server/pom.xml +++ b/samples/standalone/contracts/com/example/server/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 com.example @@ -14,14 +15,16 @@ org.springframework.boot spring-boot-starter-parent 2.1.2.RELEASE - + UTF-8 1.8 - 2.1.1.BUILD-SNAPSHOT - Greenwich.BUILD-SNAPSHOT + 2.1.1.BUILD-SNAPSHOT + + Greenwich.BUILD-SNAPSHOT + true diff --git a/samples/standalone/contracts/pom.xml b/samples/standalone/contracts/pom.xml index acc1969216..678e7efbb8 100644 --- a/samples/standalone/contracts/pom.xml +++ b/samples/standalone/contracts/pom.xml @@ -1,5 +1,6 @@ - 4.0.0 @@ -8,7 +9,9 @@ 0.0.1-SNAPSHOT Contracts - Contains all the Spring Cloud Contracts, well, contracts. JAR used by the producers to generate tests and stubs + Contains all the Spring Cloud Contracts, well, contracts. JAR used by the + producers to generate tests and stubs + UTF-8 diff --git a/samples/standalone/contracts/src/assembly/contracts.xml b/samples/standalone/contracts/src/assembly/contracts.xml index 89fb589f6c..7b278bcf38 100644 --- a/samples/standalone/contracts/src/assembly/contracts.xml +++ b/samples/standalone/contracts/src/assembly/contracts.xml @@ -1,5 +1,5 @@ - project @@ -20,4 +20,4 @@ - \ No newline at end of file + diff --git a/samples/standalone/dsl/http-client/.mvn/wrapper/MavenWrapperDownloader.java b/samples/standalone/dsl/http-client/.mvn/wrapper/MavenWrapperDownloader.java index d475a89ce1..44f295e331 100755 --- a/samples/standalone/dsl/http-client/.mvn/wrapper/MavenWrapperDownloader.java +++ b/samples/standalone/dsl/http-client/.mvn/wrapper/MavenWrapperDownloader.java @@ -1,3 +1,4 @@ + /* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -17,94 +18,100 @@ specific language governing permissions and limitations under the License. */ -import java.net.*; -import java.io.*; -import java.nio.channels.*; import java.util.Properties; public class MavenWrapperDownloader { - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = - "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is + * provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to - * use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = - ".mvn/wrapper/maven-wrapper.properties"; + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl + * property to use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = ".mvn/wrapper/maven-wrapper.properties"; - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = - ".mvn/wrapper/maven-wrapper.jar"; + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar"; - /** - * Name of the property which should be used to override the default download url for the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + /** + * Name of the property which should be used to override the default download url for + * the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - // If the maven-wrapper.properties exists, read it and check if it contains a custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } finally { - try { - if(mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: : " + url); + // If the maven-wrapper.properties exists, read it and check if it contains a + // custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, + MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if (mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream( + mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } + catch (IOException e) { + System.out.println( + "- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } + finally { + try { + if (mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } + catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { - System.out.println( - "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } + File outputFile = new File(baseDirectory.getAbsolutePath(), + MAVEN_WRAPPER_JAR_PATH); + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { + System.out.println("- ERROR creating output direcrory '" + + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } + catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } - private static void downloadFileFromURL(String urlString, File destination) throws Exception { - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } + private static void downloadFileFromURL(String urlString, File destination) + throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } } diff --git a/samples/standalone/dsl/http-client/pom.xml b/samples/standalone/dsl/http-client/pom.xml index d1df2813d7..15028d548d 100644 --- a/samples/standalone/dsl/http-client/pom.xml +++ b/samples/standalone/dsl/http-client/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 com.example @@ -14,13 +15,14 @@ org.springframework.boot spring-boot-starter-parent 2.1.2.RELEASE - + UTF-8 1.8 - Greenwich.BUILD-SNAPSHOT + Greenwich.BUILD-SNAPSHOT + @@ -176,7 +178,9 @@ clean build publishToMavenLocal - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + @@ -206,7 +210,9 @@ clean build publishToMavenLocal - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + diff --git a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/Application.java b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/Application.java index 6f36301172..ca4e1a4767 100644 --- a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/Application.java +++ b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/Application.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan; import org.springframework.boot.SpringApplication; diff --git a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/LoanApplicationService.java b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/LoanApplicationService.java index beae2c7594..d58231b420 100644 --- a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/LoanApplicationService.java +++ b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/LoanApplicationService.java @@ -1,5 +1,29 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan; +import com.example.loan.model.FraudCheckStatus; +import com.example.loan.model.FraudServiceRequest; +import com.example.loan.model.FraudServiceResponse; +import com.example.loan.model.LoanApplication; +import com.example.loan.model.LoanApplicationResult; +import com.example.loan.model.LoanApplicationStatus; +import com.example.loan.model.Response; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.http.HttpEntity; @@ -10,14 +34,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; -import com.example.loan.model.FraudCheckStatus; -import com.example.loan.model.FraudServiceRequest; -import com.example.loan.model.FraudServiceResponse; -import com.example.loan.model.LoanApplication; -import com.example.loan.model.LoanApplicationResult; -import com.example.loan.model.LoanApplicationStatus; -import com.example.loan.model.Response; - @Service public class LoanApplicationService { @@ -31,11 +47,9 @@ public class LoanApplicationService { } public LoanApplicationResult loanApplication(LoanApplication loanApplication) { - FraudServiceRequest request = - new FraudServiceRequest(loanApplication); + FraudServiceRequest request = new FraudServiceRequest(loanApplication); - FraudServiceResponse response = - sendRequestToFraudDetectionService(request); + FraudServiceResponse response = sendRequestToFraudDetectionService(request); return buildResponseFromFraudResult(response); } @@ -46,43 +60,43 @@ public class LoanApplicationService { httpHeaders.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); // tag::client_call_server[] - ResponseEntity response = - restTemplate.exchange("http://localhost:" + port + "/fraudcheck", HttpMethod.PUT, - new HttpEntity<>(request, httpHeaders), - FraudServiceResponse.class); + ResponseEntity response = restTemplate.exchange( + "http://localhost:" + port + "/fraudcheck", HttpMethod.PUT, + new HttpEntity<>(request, httpHeaders), FraudServiceResponse.class); // end::client_call_server[] return response.getBody(); } - private LoanApplicationResult buildResponseFromFraudResult(FraudServiceResponse response) { + private LoanApplicationResult buildResponseFromFraudResult( + FraudServiceResponse response) { LoanApplicationStatus applicationStatus = null; if (FraudCheckStatus.OK == response.getFraudCheckStatus()) { applicationStatus = LoanApplicationStatus.LOAN_APPLIED; - } else if (FraudCheckStatus.FRAUD == response.getFraudCheckStatus()) { + } + else if (FraudCheckStatus.FRAUD == response.getFraudCheckStatus()) { applicationStatus = LoanApplicationStatus.LOAN_APPLICATION_REJECTED; } - return new LoanApplicationResult(applicationStatus, response.getRejectionReason()); + return new LoanApplicationResult(applicationStatus, + response.getRejectionReason()); } public int countAllFrauds() { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); - ResponseEntity response = - restTemplate.exchange("http://localhost:" + port + "/frauds", HttpMethod.GET, - new HttpEntity<>(httpHeaders), - Response.class); + ResponseEntity response = restTemplate.exchange( + "http://localhost:" + port + "/frauds", HttpMethod.GET, + new HttpEntity<>(httpHeaders), Response.class); return response.getBody().getCount(); } public int countDrunks() { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); - ResponseEntity response = - restTemplate.exchange("http://localhost:" + port + "/drunks", HttpMethod.GET, - new HttpEntity<>(httpHeaders), - Response.class); + ResponseEntity response = restTemplate.exchange( + "http://localhost:" + port + "/drunks", HttpMethod.GET, + new HttpEntity<>(httpHeaders), Response.class); return response.getBody().getCount(); } @@ -90,10 +104,9 @@ public class LoanApplicationService { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.add("Cookie", "name=foo"); httpHeaders.add("Cookie", "name2=bar"); - ResponseEntity response = - restTemplate.exchange("http://localhost:" + port + "/frauds/name", HttpMethod.GET, - new HttpEntity<>(httpHeaders), - String.class); + ResponseEntity response = restTemplate.exchange( + "http://localhost:" + port + "/frauds/name", HttpMethod.GET, + new HttpEntity<>(httpHeaders), String.class); return response.getBody(); } diff --git a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/Client.java b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/Client.java index abf66106b5..4c197f9a4e 100644 --- a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/Client.java +++ b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/Client.java @@ -1,9 +1,25 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public class Client { private String pesel; - + public Client() { } @@ -18,4 +34,5 @@ public class Client { public void setPesel(String pesel) { this.pesel = pesel; } + } diff --git a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/FraudCheckStatus.java b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/FraudCheckStatus.java index c5217ef471..762692e74a 100644 --- a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/FraudCheckStatus.java +++ b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/FraudCheckStatus.java @@ -1,5 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public enum FraudCheckStatus { + OK, FRAUD + } diff --git a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/FraudServiceRequest.java b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/FraudServiceRequest.java index 5cc40027bb..55fb7875f6 100644 --- a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/FraudServiceRequest.java +++ b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/FraudServiceRequest.java @@ -1,9 +1,25 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; -import com.fasterxml.jackson.annotation.JsonProperty; - import java.math.BigDecimal; +import com.fasterxml.jackson.annotation.JsonProperty; + public class FraudServiceRequest { @JsonProperty("client.id") @@ -34,4 +50,5 @@ public class FraudServiceRequest { public void setLoanAmount(BigDecimal loanAmount) { this.loanAmount = loanAmount; } + } diff --git a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/FraudServiceResponse.java b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/FraudServiceResponse.java index af58a03223..81d3864cab 100644 --- a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/FraudServiceResponse.java +++ b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/FraudServiceResponse.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; import com.fasterxml.jackson.annotation.JsonProperty; @@ -27,4 +43,5 @@ public class FraudServiceResponse { public void setRejectionReason(String rejectionReason) { this.rejectionReason = rejectionReason; } + } diff --git a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/LoanApplication.java b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/LoanApplication.java index 27d66f884c..e0cd87ec51 100644 --- a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/LoanApplication.java +++ b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/LoanApplication.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; import java.math.BigDecimal; @@ -41,4 +57,5 @@ public class LoanApplication { public void setLoanApplicationId(String loanApplicationId) { this.loanApplicationId = loanApplicationId; } + } diff --git a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/LoanApplicationResult.java b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/LoanApplicationResult.java index ffd44e1a26..44ea77ebce 100644 --- a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/LoanApplicationResult.java +++ b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/LoanApplicationResult.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public class LoanApplicationResult { @@ -9,7 +25,8 @@ public class LoanApplicationResult { public LoanApplicationResult() { } - public LoanApplicationResult(LoanApplicationStatus loanApplicationStatus, String rejectionReason) { + public LoanApplicationResult(LoanApplicationStatus loanApplicationStatus, + String rejectionReason) { this.loanApplicationStatus = loanApplicationStatus; this.rejectionReason = rejectionReason; } @@ -29,4 +46,5 @@ public class LoanApplicationResult { public void setRejectionReason(String rejectionReason) { this.rejectionReason = rejectionReason; } + } diff --git a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/LoanApplicationStatus.java b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/LoanApplicationStatus.java index 34cf91a89f..b5c85900d3 100644 --- a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/LoanApplicationStatus.java +++ b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/LoanApplicationStatus.java @@ -1,5 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public enum LoanApplicationStatus { + LOAN_APPLIED, LOAN_APPLICATION_REJECTED + } diff --git a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/Response.java b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/Response.java index 8335ee0cc6..d43a4cf298 100644 --- a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/Response.java +++ b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/model/Response.java @@ -1,6 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public class Response { + private int count; public Response(int count) { @@ -17,4 +34,5 @@ public class Response { public void setCount(int count) { this.count = count; } -} \ No newline at end of file + +} diff --git a/samples/standalone/dsl/http-client/src/test/java/com/example/loan/LoanApplicationServiceContextPathTests.java b/samples/standalone/dsl/http-client/src/test/java/com/example/loan/LoanApplicationServiceContextPathTests.java index 1eb7e0a364..7219fb741e 100644 --- a/samples/standalone/dsl/http-client/src/test/java/com/example/loan/LoanApplicationServiceContextPathTests.java +++ b/samples/standalone/dsl/http-client/src/test/java/com/example/loan/LoanApplicationServiceContextPathTests.java @@ -1,7 +1,28 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan; +import com.example.loan.model.Client; +import com.example.loan.model.LoanApplication; +import com.example.loan.model.LoanApplicationResult; +import com.example.loan.model.LoanApplicationStatus; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -9,17 +30,12 @@ import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRun import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties; import org.springframework.test.context.junit4.SpringRunner; -import com.example.loan.model.Client; -import com.example.loan.model.LoanApplication; -import com.example.loan.model.LoanApplicationResult; -import com.example.loan.model.LoanApplicationStatus; - import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment=WebEnvironment.NONE, properties="server.context-path=/app") -@AutoConfigureStubRunner(ids = {"com.example:http-server-dsl:+:stubs:6565"}, - stubsMode = StubRunnerProperties.StubsMode.LOCAL) +@SpringBootTest(webEnvironment = WebEnvironment.NONE, properties = "server.context-path=/app") +@AutoConfigureStubRunner(ids = { + "com.example:http-server-dsl:+:stubs:6565" }, stubsMode = StubRunnerProperties.StubsMode.LOCAL) public class LoanApplicationServiceContextPathTests { @Autowired diff --git a/samples/standalone/dsl/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java b/samples/standalone/dsl/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java index d741a5129a..26ffc5380a 100644 --- a/samples/standalone/dsl/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java +++ b/samples/standalone/dsl/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan; import java.io.File; @@ -33,10 +49,11 @@ import static org.assertj.core.api.Assertions.assertThat; // tag::autoconfigure_stubrunner[] @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.NONE) -@AutoConfigureStubRunner(ids = {"com.example:http-server-dsl:+:stubs:6565"}, - stubsMode = StubRunnerProperties.StubsMode.LOCAL) +@AutoConfigureStubRunner(ids = { + "com.example:http-server-dsl:+:stubs:6565" }, stubsMode = StubRunnerProperties.StubsMode.LOCAL) public class LoanApplicationServiceTests { -// end::autoconfigure_stubrunner[] + + // end::autoconfigure_stubrunner[] @Autowired private LoanApplicationService service; @@ -100,13 +117,12 @@ public class LoanApplicationServiceTests { .baseUri("http://localhost:6565/") .header("Content-Type", "multipart/form-data") .multiPart("file1", "filename1", "content1".getBytes()) - .multiPart("file2", "filename1", "content2".getBytes()) - .multiPart("test", "filename1", "{\n \"status\": \"test\"\n}" - .getBytes(), "application/json"); + .multiPart("file2", "filename1", "content2".getBytes()).multiPart("test", + "filename1", "{\n \"status\": \"test\"\n}".getBytes(), + "application/json"); // when: - ResponseOptions response = RestAssured.given().spec(request) - .post("/tests"); + ResponseOptions response = RestAssured.given().spec(request).post("/tests"); // then: assertThat(response.statusCode()).isEqualTo(200); @@ -125,10 +141,12 @@ public class LoanApplicationServiceTests { .getResource("/binary/response.pdf").getFile()); // when: - ResponseEntity exchange = new RestTemplate().exchange( - RequestEntity.put(URI.create("http://localhost:6565/1")) - .header("Content-Type", "application/octet-stream") - .body(Files.readAllBytes(request.toPath())), byte[].class); + ResponseEntity exchange = new RestTemplate() + .exchange( + RequestEntity.put(URI.create("http://localhost:6565/1")) + .header("Content-Type", "application/octet-stream") + .body(Files.readAllBytes(request.toPath())), + byte[].class); // then: assertThat(exchange.getStatusCodeValue()).isEqualTo(200); diff --git a/samples/standalone/dsl/http-client/src/test/resources/application-gradle.yaml b/samples/standalone/dsl/http-client/src/test/resources/application-gradle.yaml index 3732eefd5f..3de9f8be98 100644 --- a/samples/standalone/dsl/http-client/src/test/resources/application-gradle.yaml +++ b/samples/standalone/dsl/http-client/src/test/resources/application-gradle.yaml @@ -1,3 +1,3 @@ stubrunner: stubs-mode: local - stubs.ids: 'com.example:http-server-dsl-gradle:+:stubs:6565' \ No newline at end of file + stubs.ids: 'com.example:http-server-dsl-gradle:+:stubs:6565' diff --git a/samples/standalone/dsl/http-client/src/test/resources/application.yaml b/samples/standalone/dsl/http-client/src/test/resources/application.yaml index fcdfd10d16..78a78e6fa6 100644 --- a/samples/standalone/dsl/http-client/src/test/resources/application.yaml +++ b/samples/standalone/dsl/http-client/src/test/resources/application.yaml @@ -2,4 +2,4 @@ server: port: 6565 logging: level: - org.springframework.cloud.contract: debug \ No newline at end of file + org.springframework.cloud.contract: debug diff --git a/samples/standalone/dsl/http-server/.mvn/wrapper/MavenWrapperDownloader.java b/samples/standalone/dsl/http-server/.mvn/wrapper/MavenWrapperDownloader.java index d475a89ce1..44f295e331 100755 --- a/samples/standalone/dsl/http-server/.mvn/wrapper/MavenWrapperDownloader.java +++ b/samples/standalone/dsl/http-server/.mvn/wrapper/MavenWrapperDownloader.java @@ -1,3 +1,4 @@ + /* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -17,94 +18,100 @@ specific language governing permissions and limitations under the License. */ -import java.net.*; -import java.io.*; -import java.nio.channels.*; import java.util.Properties; public class MavenWrapperDownloader { - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = - "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is + * provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to - * use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = - ".mvn/wrapper/maven-wrapper.properties"; + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl + * property to use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = ".mvn/wrapper/maven-wrapper.properties"; - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = - ".mvn/wrapper/maven-wrapper.jar"; + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar"; - /** - * Name of the property which should be used to override the default download url for the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + /** + * Name of the property which should be used to override the default download url for + * the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - // If the maven-wrapper.properties exists, read it and check if it contains a custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } finally { - try { - if(mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: : " + url); + // If the maven-wrapper.properties exists, read it and check if it contains a + // custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, + MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if (mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream( + mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } + catch (IOException e) { + System.out.println( + "- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } + finally { + try { + if (mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } + catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { - System.out.println( - "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } + File outputFile = new File(baseDirectory.getAbsolutePath(), + MAVEN_WRAPPER_JAR_PATH); + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { + System.out.println("- ERROR creating output direcrory '" + + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } + catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } - private static void downloadFileFromURL(String urlString, File destination) throws Exception { - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } + private static void downloadFileFromURL(String urlString, File destination) + throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } } diff --git a/samples/standalone/dsl/http-server/pom.xml b/samples/standalone/dsl/http-server/pom.xml index 143f9bf573..0a25b82cb5 100644 --- a/samples/standalone/dsl/http-server/pom.xml +++ b/samples/standalone/dsl/http-server/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 com.example @@ -14,14 +15,16 @@ org.springframework.boot spring-boot-starter-parent 2.1.2.RELEASE - + UTF-8 1.8 - 2.1.1.BUILD-SNAPSHOT - Greenwich.BUILD-SNAPSHOT + 2.1.1.BUILD-SNAPSHOT + + Greenwich.BUILD-SNAPSHOT + @@ -124,8 +127,11 @@ org.springframework.cloud - spring-cloud-contract-maven-plugin - [${spring-cloud-contract.version},) + spring-cloud-contract-maven-plugin + + + [${spring-cloud-contract.version},) + convert generateTests @@ -217,7 +223,9 @@ clean build publishToMavenLocal - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + @@ -247,7 +255,9 @@ clean build publishToMavenLocal - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + diff --git a/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/Application.java b/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/Application.java index 9117009b09..ef20bf067e 100644 --- a/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/Application.java +++ b/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/Application.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; import org.springframework.boot.SpringApplication; diff --git a/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/FraudDetectionController.java b/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/FraudDetectionController.java index 764f8a6e96..c8fe767530 100644 --- a/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/FraudDetectionController.java +++ b/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/FraudDetectionController.java @@ -1,28 +1,46 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; import java.math.BigDecimal; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - import com.example.fraud.model.FraudCheck; import com.example.fraud.model.FraudCheckResult; import com.example.fraud.model.FraudCheckStatus; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + import static org.springframework.web.bind.annotation.RequestMethod.PUT; @RestController public class FraudDetectionController { private static final String NO_REASON = null; + private static final String AMOUNT_TOO_HIGH = "Amount too high"; + private static final BigDecimal MAX_AMOUNT = new BigDecimal("5000"); // tag::server_api[] @RequestMapping(value = "/fraudcheck", method = PUT) public FraudCheckResult fraudCheck(@RequestBody FraudCheck fraudCheck) { - // end::server_api[] + // end::server_api[] // tag::new_impl[] if (amountGreaterThanThreshold(fraudCheck)) { return new FraudCheckResult(FraudCheckStatus.FRAUD, AMOUNT_TOO_HIGH); diff --git a/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/FraudNameController.java b/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/FraudNameController.java index fe99c7c713..207c780f34 100644 --- a/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/FraudNameController.java +++ b/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/FraudNameController.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; import org.springframework.web.bind.annotation.CookieValue; @@ -6,6 +22,12 @@ import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; +interface FraudVerifier { + + boolean isFraudByName(String name); + +} + /** * @author Marcin Grzejszczak */ @@ -24,7 +46,8 @@ class FraudNameController { if (fraud) { return new NameResponse("Sorry " + request.getName() + " but you're a fraud"); } - return new NameResponse("Don't worry " + request.getName() + " you're not a fraud"); + return new NameResponse( + "Don't worry " + request.getName() + " you're not a fraud"); } @GetMapping(value = "/frauds/name") @@ -32,13 +55,11 @@ class FraudNameController { @CookieValue("name2") String value2) { return value + " " + value2; } -} -interface FraudVerifier { - boolean isFraudByName(String name); } class NameRequest { + private String name; public NameRequest(String name) { @@ -55,9 +76,11 @@ class NameRequest { public void setName(String name) { this.name = name; } + } class NameResponse { + private String result; public NameResponse(String result) { @@ -74,4 +97,5 @@ class NameResponse { public void setResult(String result) { this.result = result; } + } diff --git a/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/FraudStatsController.java b/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/FraudStatsController.java index ac9340611c..76a4886e3f 100644 --- a/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/FraudStatsController.java +++ b/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/FraudStatsController.java @@ -1,8 +1,36 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; +enum FraudType { + + DRUNKS, ALL + +} + +interface StatsProvider { + + int count(FraudType fraudType); + +} + @RestController public class FraudStatsController { @@ -21,17 +49,11 @@ public class FraudStatsController { public Response countAllDrunks() { return new Response(this.statsProvider.count(FraudType.DRUNKS)); } -} -enum FraudType { - DRUNKS, ALL -} - -interface StatsProvider { - int count(FraudType fraudType); } class Response { + private int count; public Response(int count) { @@ -48,4 +70,5 @@ class Response { public void setCount(int count) { this.count = count; } + } diff --git a/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/TestController.java b/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/TestController.java index bf0e3a1743..a3f769cc35 100644 --- a/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/TestController.java +++ b/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/TestController.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; import java.io.File; @@ -19,13 +35,14 @@ import org.springframework.web.multipart.MultipartFile; public class TestController { private final byte[] request; + private final byte[] response; public TestController() { - this.request = toByte(TestController.class - .getResource("/contracts/binary/request.pdf")); - this.response = toByte(TestController.class - .getResource("/contracts/binary/response.pdf")); + this.request = toByte( + TestController.class.getResource("/contracts/binary/request.pdf")); + this.response = toByte( + TestController.class.getResource("/contracts/binary/response.pdf")); } private byte[] toByte(URL url) { @@ -39,23 +56,22 @@ public class TestController { @PostMapping("/tests") public Test createNew(@RequestPart MultipartFile file1, - @RequestPart MultipartFile file2, - @RequestPart Test test) { + @RequestPart MultipartFile file2, @RequestPart Test test) { return new Test("ok"); } - @PutMapping(value = "/1", - consumes = MediaType.APPLICATION_OCTET_STREAM_VALUE, - produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) + @PutMapping(value = "/1", consumes = MediaType.APPLICATION_OCTET_STREAM_VALUE, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) public byte[] response(@RequestBody byte[] requestBody) { if (!Arrays.equals(this.request, requestBody)) { throw new IllegalStateException("Invalid request body"); } return this.response; } + } class Test { + private String status; public Test(String status) { @@ -72,4 +88,5 @@ class Test { public void setStatus(String status) { this.status = status; } -} \ No newline at end of file + +} diff --git a/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/model/FraudCheck.java b/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/model/FraudCheck.java index e98c2b60d2..bc7dd3a936 100644 --- a/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/model/FraudCheck.java +++ b/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/model/FraudCheck.java @@ -1,9 +1,25 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud.model; -import com.fasterxml.jackson.annotation.JsonProperty; - import java.math.BigDecimal; +import com.fasterxml.jackson.annotation.JsonProperty; + public class FraudCheck { @JsonProperty("client.id") @@ -29,4 +45,5 @@ public class FraudCheck { public void setLoanAmount(BigDecimal loanAmount) { this.loanAmount = loanAmount; } + } diff --git a/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/model/FraudCheckResult.java b/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/model/FraudCheckResult.java index 2f30912063..dbf4ff8fef 100644 --- a/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/model/FraudCheckResult.java +++ b/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/model/FraudCheckResult.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud.model; import com.fasterxml.jackson.annotation.JsonProperty; @@ -32,4 +48,5 @@ public class FraudCheckResult { public void setRejectionReason(String rejectionReason) { this.rejectionReason = rejectionReason; } + } diff --git a/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/model/FraudCheckStatus.java b/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/model/FraudCheckStatus.java index 5a6adcf274..02d37adf46 100644 --- a/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/model/FraudCheckStatus.java +++ b/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/model/FraudCheckStatus.java @@ -1,5 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud.model; public enum FraudCheckStatus { + OK, FRAUD + } diff --git a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/BinaryBase.java b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/BinaryBase.java index ad7c3a53cd..86f2686b1b 100644 --- a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/BinaryBase.java +++ b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/BinaryBase.java @@ -1,18 +1,17 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT 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 com.example.fraud; @@ -26,4 +25,5 @@ public class BinaryBase { public void setUp() throws Exception { RestAssuredMockMvc.standaloneSetup(new TestController()); } -} \ No newline at end of file + +} diff --git a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/FraudBase.java b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/FraudBase.java index 681c432058..22b788e8c3 100644 --- a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/FraudBase.java +++ b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/FraudBase.java @@ -1,9 +1,26 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; import io.restassured.module.mockmvc.RestAssuredMockMvc; import org.junit.Before; public class FraudBase { + @Before public void setup() { RestAssuredMockMvc.standaloneSetup(new FraudDetectionController(), @@ -25,4 +42,5 @@ public class FraudBase { public void assertThatRejectionReasonIsNull(Object rejectionReason) { assert rejectionReason == null; } -} \ No newline at end of file + +} diff --git a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/FraudnameBase.java b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/FraudnameBase.java index f1338fd188..9e7196124e 100644 --- a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/FraudnameBase.java +++ b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/FraudnameBase.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; import io.restassured.module.mockmvc.RestAssuredMockMvc; @@ -13,4 +29,5 @@ public class FraudnameBase { public void setup() { RestAssuredMockMvc.standaloneSetup(new FraudNameController(this.fraudVerifier)); } -} \ No newline at end of file + +} diff --git a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/MultipartBase.java b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/MultipartBase.java index 3b983f5e93..a4293339f1 100644 --- a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/MultipartBase.java +++ b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/MultipartBase.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; import io.restassured.module.mockmvc.RestAssuredMockMvc; @@ -9,4 +25,5 @@ public class MultipartBase { public void setUp() throws Exception { RestAssuredMockMvc.standaloneSetup(new TestController()); } -} \ No newline at end of file + +} diff --git a/samples/standalone/dsl/http-server/src/test/resources/contracts/binary/shouldWorkWithBinaryPayload.groovy b/samples/standalone/dsl/http-server/src/test/resources/contracts/binary/shouldWorkWithBinaryPayload.groovy index b8d7c527e5..3fc6fde1a2 100644 --- a/samples/standalone/dsl/http-server/src/test/resources/contracts/binary/shouldWorkWithBinaryPayload.groovy +++ b/samples/standalone/dsl/http-server/src/test/resources/contracts/binary/shouldWorkWithBinaryPayload.groovy @@ -1,18 +1,17 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT 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 contracts diff --git a/samples/standalone/dsl/http-server/src/test/resources/contracts/fraud/shouldMarkClientAsFraud.groovy b/samples/standalone/dsl/http-server/src/test/resources/contracts/fraud/shouldMarkClientAsFraud.groovy index b321d0f483..f5ff21c3d6 100644 --- a/samples/standalone/dsl/http-server/src/test/resources/contracts/fraud/shouldMarkClientAsFraud.groovy +++ b/samples/standalone/dsl/http-server/src/test/resources/contracts/fraud/shouldMarkClientAsFraud.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts org.springframework.cloud.contract.spec.Contract.make { @@ -6,7 +22,7 @@ org.springframework.cloud.contract.spec.Contract.make { url '/fraudcheck' // (3) body([ // (4) "client.id": $(regex('[0-9]{10}')), - loanAmount: 99999 + loanAmount : 99999 ]) headers { // (5) contentType('application/json') @@ -15,7 +31,7 @@ org.springframework.cloud.contract.spec.Contract.make { response { // (6) status OK() // (7) body([ // (8) - fraudCheckStatus: "FRAUD", + fraudCheckStatus : "FRAUD", "rejection.reason": "Amount too high" ]) headers { // (9) @@ -54,4 +70,4 @@ From the Producer perspective, in the autogenerated producer-side test: (8) - and JSON body equal to { "fraudCheckStatus": "FRAUD", "rejectionReason": "Amount too high" } (9) - with header `Content-Type` matching `application/json.*` - */ \ No newline at end of file + */ diff --git a/samples/standalone/dsl/http-server/src/test/resources/contracts/fraud/shouldMarkClientAsNotFraud.groovy b/samples/standalone/dsl/http-server/src/test/resources/contracts/fraud/shouldMarkClientAsNotFraud.groovy index 9a085932ca..f6e2c6b6fe 100644 --- a/samples/standalone/dsl/http-server/src/test/resources/contracts/fraud/shouldMarkClientAsNotFraud.groovy +++ b/samples/standalone/dsl/http-server/src/test/resources/contracts/fraud/shouldMarkClientAsNotFraud.groovy @@ -1,30 +1,49 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts org.springframework.cloud.contract.spec.Contract.make { - request { - method 'PUT' - url '/fraudcheck' - body(""" + request { + method 'PUT' + url '/fraudcheck' + body(""" { - "client.id":"${value(consumer(regex('[0-9]{10}')), producer('1234567890'))}", + "client.id":"${ + value(consumer(regex('[0-9]{10}')), producer('1234567890')) + }", "loanAmount":123.123 } """ - ) - headers { - contentType("application/json") - } + ) + headers { + contentType("application/json") + } - } - response { - status OK() - body( - fraudCheckStatus: "OK", - "rejection.reason": $(consumer(null), producer(execute('assertThatRejectionReasonIsNull($it)'))) - ) - headers { - contentType("application/json") - } - } + } + response { + status OK() + body( + fraudCheckStatus: "OK", + "rejection.reason": $(consumer(null), + producer(execute('assertThatRejectionReasonIsNull($it)'))) + ) + headers { + contentType("application/json") + } + } } diff --git a/samples/standalone/dsl/http-server/src/test/resources/contracts/fraud/shouldReturnFraudStats.groovy b/samples/standalone/dsl/http-server/src/test/resources/contracts/fraud/shouldReturnFraudStats.groovy index 7e05390199..5054ab6472 100644 --- a/samples/standalone/dsl/http-server/src/test/resources/contracts/fraud/shouldReturnFraudStats.groovy +++ b/samples/standalone/dsl/http-server/src/test/resources/contracts/fraud/shouldReturnFraudStats.groovy @@ -1,37 +1,53 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts import org.springframework.cloud.contract.spec.Contract [ - Contract.make { - request { - name "should count all frauds" - method GET() - url '/frauds' - } - response { - status OK() - body([ - count: $(regex("[2-9][0-9][0-9]").asInteger()) - ]) - headers { - contentType("application/json") - } - } - }, - Contract.make { - request { - method GET() - url '/drunks' - } - response { - status OK() - body([ - count: 100 - ]) - headers { - contentType("application/json") - } + Contract.make { + request { + name "should count all frauds" + method GET() + url '/frauds' + } + response { + status OK() + body([ + count: $(regex("[2-9][0-9][0-9]").asInteger()) + ]) + headers { + contentType("application/json") } } -] \ No newline at end of file + }, + Contract.make { + request { + method GET() + url '/drunks' + } + response { + status OK() + body([ + count: 100 + ]) + headers { + contentType("application/json") + } + } + } +] diff --git a/samples/standalone/dsl/http-server/src/test/resources/contracts/fraudname/shouldReturnACookie.groovy b/samples/standalone/dsl/http-server/src/test/resources/contracts/fraudname/shouldReturnACookie.groovy index 54983e928e..441e80cf8d 100644 --- a/samples/standalone/dsl/http-server/src/test/resources/contracts/fraudname/shouldReturnACookie.groovy +++ b/samples/standalone/dsl/http-server/src/test/resources/contracts/fraudname/shouldReturnACookie.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.fraudname org.springframework.cloud.contract.spec.Contract.make { @@ -13,4 +29,4 @@ org.springframework.cloud.contract.spec.Contract.make { status 200 body("foo bar") } -} \ No newline at end of file +} diff --git a/samples/standalone/dsl/http-server/src/test/resources/contracts/fraudname/shouldReturnAFraudForTheName.groovy b/samples/standalone/dsl/http-server/src/test/resources/contracts/fraudname/shouldReturnAFraudForTheName.groovy index a09a6e8455..516f09bfc4 100644 --- a/samples/standalone/dsl/http-server/src/test/resources/contracts/fraudname/shouldReturnAFraudForTheName.groovy +++ b/samples/standalone/dsl/http-server/src/test/resources/contracts/fraudname/shouldReturnAFraudForTheName.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.fraudname org.springframework.cloud.contract.spec.Contract.make { @@ -7,7 +23,7 @@ org.springframework.cloud.contract.spec.Contract.make { method PUT() url '/frauds/name' body([ - name: "fraud" + name: "fraud" ]) headers { contentType("application/json") @@ -22,4 +38,4 @@ org.springframework.cloud.contract.spec.Contract.make { header(contentType(), "${fromRequest().header(contentType())};charset=UTF-8") } } -} \ No newline at end of file +} diff --git a/samples/standalone/dsl/http-server/src/test/resources/contracts/fraudname/shouldReturnNonFraudForTheName.groovy b/samples/standalone/dsl/http-server/src/test/resources/contracts/fraudname/shouldReturnNonFraudForTheName.groovy index 8a27d4e1b0..bd579318ba 100644 --- a/samples/standalone/dsl/http-server/src/test/resources/contracts/fraudname/shouldReturnNonFraudForTheName.groovy +++ b/samples/standalone/dsl/http-server/src/test/resources/contracts/fraudname/shouldReturnNonFraudForTheName.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.fraudname org.springframework.cloud.contract.spec.Contract.make { @@ -5,7 +21,7 @@ org.springframework.cloud.contract.spec.Contract.make { method PUT() url '/frauds/name' body([ - name: $(anyAlphaUnicode()) + name: $(anyAlphaUnicode()) ]) headers { contentType("application/json") @@ -20,4 +36,4 @@ org.springframework.cloud.contract.spec.Contract.make { header(contentType(), "${fromRequest().header(contentType())};charset=UTF-8") } } -} \ No newline at end of file +} diff --git a/samples/standalone/dsl/http-server/src/test/resources/contracts/multipart/shouldWorkForMultipartAsBytesWithContentType.groovy b/samples/standalone/dsl/http-server/src/test/resources/contracts/multipart/shouldWorkForMultipartAsBytesWithContentType.groovy index ab5223ce34..072a0df7b1 100644 --- a/samples/standalone/dsl/http-server/src/test/resources/contracts/multipart/shouldWorkForMultipartAsBytesWithContentType.groovy +++ b/samples/standalone/dsl/http-server/src/test/resources/contracts/multipart/shouldWorkForMultipartAsBytesWithContentType.groovy @@ -1,18 +1,17 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT 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.spec.Contract @@ -31,7 +30,8 @@ Contract.make { content: value(c(regex(nonEmpty())), producer('content2'))), test : named( name: value(consumer(regex(nonEmpty())), producer('filename1')), - content: value(c(regex(nonEmpty())), producer(fileAsBytes("test.json"))), + content: + value(c(regex(nonEmpty())), producer(fileAsBytes("test.json"))), contentType: value("application/json")) ] ) diff --git a/samples/standalone/dsl/http-server/src/test/resources/contracts/multipart/test.json b/samples/standalone/dsl/http-server/src/test/resources/contracts/multipart/test.json index 21a721f25a..984c08fbdf 100644 --- a/samples/standalone/dsl/http-server/src/test/resources/contracts/multipart/test.json +++ b/samples/standalone/dsl/http-server/src/test/resources/contracts/multipart/test.json @@ -1,3 +1,3 @@ { "status": "test" -} \ No newline at end of file +} diff --git a/samples/standalone/dsl/pom.xml b/samples/standalone/dsl/pom.xml index 3f52d74426..149c7d96f9 100644 --- a/samples/standalone/dsl/pom.xml +++ b/samples/standalone/dsl/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 @@ -14,10 +15,12 @@ pom Spring Cloud Contract Standalone Dsl Test Samples - Spring Cloud Contract Standalone Test Samples used for end to end tests + Spring Cloud Contract Standalone Test Samples used for end to end tests + - 2.1.1.BUILD-SNAPSHOT + 2.1.1.BUILD-SNAPSHOT + diff --git a/samples/standalone/messaging/pom.xml b/samples/standalone/messaging/pom.xml index 2d054be450..60c257c219 100644 --- a/samples/standalone/messaging/pom.xml +++ b/samples/standalone/messaging/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 @@ -14,10 +15,12 @@ pom Spring Cloud Contract Standalone Dsl Test Samples With Messaging - Spring Cloud Contract Standalone Test Samples used for end to end tests + Spring Cloud Contract Standalone Test Samples used for end to end tests + - 2.1.1.BUILD-SNAPSHOT + 2.1.1.BUILD-SNAPSHOT + diff --git a/samples/standalone/messaging/stream-sink/.mvn/wrapper/MavenWrapperDownloader.java b/samples/standalone/messaging/stream-sink/.mvn/wrapper/MavenWrapperDownloader.java index d475a89ce1..44f295e331 100755 --- a/samples/standalone/messaging/stream-sink/.mvn/wrapper/MavenWrapperDownloader.java +++ b/samples/standalone/messaging/stream-sink/.mvn/wrapper/MavenWrapperDownloader.java @@ -1,3 +1,4 @@ + /* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -17,94 +18,100 @@ specific language governing permissions and limitations under the License. */ -import java.net.*; -import java.io.*; -import java.nio.channels.*; import java.util.Properties; public class MavenWrapperDownloader { - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = - "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is + * provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to - * use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = - ".mvn/wrapper/maven-wrapper.properties"; + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl + * property to use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = ".mvn/wrapper/maven-wrapper.properties"; - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = - ".mvn/wrapper/maven-wrapper.jar"; + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar"; - /** - * Name of the property which should be used to override the default download url for the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + /** + * Name of the property which should be used to override the default download url for + * the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - // If the maven-wrapper.properties exists, read it and check if it contains a custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } finally { - try { - if(mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: : " + url); + // If the maven-wrapper.properties exists, read it and check if it contains a + // custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, + MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if (mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream( + mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } + catch (IOException e) { + System.out.println( + "- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } + finally { + try { + if (mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } + catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { - System.out.println( - "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } + File outputFile = new File(baseDirectory.getAbsolutePath(), + MAVEN_WRAPPER_JAR_PATH); + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { + System.out.println("- ERROR creating output direcrory '" + + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } + catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } - private static void downloadFileFromURL(String urlString, File destination) throws Exception { - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } + private static void downloadFileFromURL(String urlString, File destination) + throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } } diff --git a/samples/standalone/messaging/stream-sink/pom.xml b/samples/standalone/messaging/stream-sink/pom.xml index 52edd6afbe..30d085e58a 100644 --- a/samples/standalone/messaging/stream-sink/pom.xml +++ b/samples/standalone/messaging/stream-sink/pom.xml @@ -1,5 +1,6 @@ - 4.0.0 @@ -21,7 +22,8 @@ UTF-8 1.8 - 2.1.1.BUILD-SNAPSHOT + 2.1.1.BUILD-SNAPSHOT + @@ -166,7 +168,9 @@ clean build publishToMavenLocal - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + @@ -196,7 +200,9 @@ clean build publishToMavenLocal - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + diff --git a/samples/standalone/messaging/stream-sink/src/main/java/com/example/sink/ContractVerifierSampleStreamSinkApplication.java b/samples/standalone/messaging/stream-sink/src/main/java/com/example/sink/ContractVerifierSampleStreamSinkApplication.java index 18bfef64b0..d5e143c947 100644 --- a/samples/standalone/messaging/stream-sink/src/main/java/com/example/sink/ContractVerifierSampleStreamSinkApplication.java +++ b/samples/standalone/messaging/stream-sink/src/main/java/com/example/sink/ContractVerifierSampleStreamSinkApplication.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.sink; import org.springframework.boot.SpringApplication; @@ -11,11 +27,10 @@ import org.springframework.stereotype.Component; @EnableBinding(Sink.class) public class ContractVerifierSampleStreamSinkApplication { - - public static void main(String[] args) { SpringApplication.run(ContractVerifierSampleStreamSinkApplication.class, args); } + } @Component @@ -32,4 +47,5 @@ class Listener { public int getCount() { return this.count; } -} \ No newline at end of file + +} diff --git a/samples/standalone/messaging/stream-sink/src/main/java/com/example/sink/SensorData.java b/samples/standalone/messaging/stream-sink/src/main/java/com/example/sink/SensorData.java index dcf51ab3ba..367d1d9466 100644 --- a/samples/standalone/messaging/stream-sink/src/main/java/com/example/sink/SensorData.java +++ b/samples/standalone/messaging/stream-sink/src/main/java/com/example/sink/SensorData.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,4 +40,5 @@ public class SensorData { public void setTemperature(Double temperature) { this.temperature = temperature; } + } diff --git a/samples/standalone/messaging/stream-sink/src/test/java/com/example/sink/ContractVerifierSampleStreamSinkApplicationTests.java b/samples/standalone/messaging/stream-sink/src/test/java/com/example/sink/ContractVerifierSampleStreamSinkApplicationTests.java index 95e1348a33..5fd91a3bdd 100644 --- a/samples/standalone/messaging/stream-sink/src/test/java/com/example/sink/ContractVerifierSampleStreamSinkApplicationTests.java +++ b/samples/standalone/messaging/stream-sink/src/test/java/com/example/sink/ContractVerifierSampleStreamSinkApplicationTests.java @@ -1,7 +1,24 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.sink; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; diff --git a/samples/standalone/messaging/stream-sink/src/test/java/com/example/sink/MessageConsumedTests.java b/samples/standalone/messaging/stream-sink/src/test/java/com/example/sink/MessageConsumedTests.java index 29bc549f0e..c0a2741d14 100644 --- a/samples/standalone/messaging/stream-sink/src/test/java/com/example/sink/MessageConsumedTests.java +++ b/samples/standalone/messaging/stream-sink/src/test/java/com/example/sink/MessageConsumedTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,15 +20,11 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.cloud.contract.stubrunner.StubTrigger; import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner; import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties; -import org.springframework.cloud.stream.messaging.Sink; -import org.springframework.integration.support.management.MessageChannelMetrics; -import org.springframework.messaging.SubscribableChannel; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -37,8 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Marius Bogoevici */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.NONE, - properties = "spring.cloud.stream.bindings.input.destination=sensor-data") +@SpringBootTest(webEnvironment = WebEnvironment.NONE, properties = "spring.cloud.stream.bindings.input.destination=sensor-data") @AutoConfigureStubRunner(stubsMode = StubRunnerProperties.StubsMode.LOCAL) public class MessageConsumedTests { @@ -54,4 +49,5 @@ public class MessageConsumedTests { stubTrigger.trigger("sensor1"); assertThat(this.listener.getCount()).isEqualTo(count + 1); } + } diff --git a/samples/standalone/messaging/stream-source/.mvn/wrapper/MavenWrapperDownloader.java b/samples/standalone/messaging/stream-source/.mvn/wrapper/MavenWrapperDownloader.java index d475a89ce1..44f295e331 100755 --- a/samples/standalone/messaging/stream-source/.mvn/wrapper/MavenWrapperDownloader.java +++ b/samples/standalone/messaging/stream-source/.mvn/wrapper/MavenWrapperDownloader.java @@ -1,3 +1,4 @@ + /* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -17,94 +18,100 @@ specific language governing permissions and limitations under the License. */ -import java.net.*; -import java.io.*; -import java.nio.channels.*; import java.util.Properties; public class MavenWrapperDownloader { - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = - "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is + * provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to - * use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = - ".mvn/wrapper/maven-wrapper.properties"; + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl + * property to use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = ".mvn/wrapper/maven-wrapper.properties"; - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = - ".mvn/wrapper/maven-wrapper.jar"; + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar"; - /** - * Name of the property which should be used to override the default download url for the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + /** + * Name of the property which should be used to override the default download url for + * the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - // If the maven-wrapper.properties exists, read it and check if it contains a custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } finally { - try { - if(mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: : " + url); + // If the maven-wrapper.properties exists, read it and check if it contains a + // custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, + MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if (mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream( + mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } + catch (IOException e) { + System.out.println( + "- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } + finally { + try { + if (mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } + catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { - System.out.println( - "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } + File outputFile = new File(baseDirectory.getAbsolutePath(), + MAVEN_WRAPPER_JAR_PATH); + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { + System.out.println("- ERROR creating output direcrory '" + + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } + catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } - private static void downloadFileFromURL(String urlString, File destination) throws Exception { - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } + private static void downloadFileFromURL(String urlString, File destination) + throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } } diff --git a/samples/standalone/messaging/stream-source/pom.xml b/samples/standalone/messaging/stream-source/pom.xml index 2c0f3f7aa5..63d0fae7e7 100644 --- a/samples/standalone/messaging/stream-source/pom.xml +++ b/samples/standalone/messaging/stream-source/pom.xml @@ -1,5 +1,6 @@ - 4.0.0 @@ -21,7 +22,8 @@ UTF-8 1.8 - 2.1.1.BUILD-SNAPSHOT + 2.1.1.BUILD-SNAPSHOT + @@ -91,7 +93,8 @@ .* - com.example.source.SensorSourceTestBase + com.example.source.SensorSourceTestBase + @@ -155,8 +158,11 @@ org.springframework.cloud - spring-cloud-contract-maven-plugin - [${spring-cloud-contract.version},) + spring-cloud-contract-maven-plugin + + + [${spring-cloud-contract.version},) + convert generateTests @@ -246,7 +252,9 @@ clean build publishToMavenLocal - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + @@ -276,7 +284,9 @@ clean build publishToMavenLocal - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + diff --git a/samples/standalone/messaging/stream-source/src/main/java/com/example/source/ContractVerifierSampleStreamSourceApplication.java b/samples/standalone/messaging/stream-source/src/main/java/com/example/source/ContractVerifierSampleStreamSourceApplication.java index f91ba1df1c..3e0051c6ff 100644 --- a/samples/standalone/messaging/stream-source/src/main/java/com/example/source/ContractVerifierSampleStreamSourceApplication.java +++ b/samples/standalone/messaging/stream-source/src/main/java/com/example/source/ContractVerifierSampleStreamSourceApplication.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.source; import java.io.File; @@ -22,8 +38,17 @@ import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.MessageChannel; import org.springframework.stereotype.Component; +interface MyProcessor extends Sink { + + String MY_OUTPUT = "my_output"; + + @Output("my_output") + MessageChannel output(); + +} + @SpringBootApplication -@EnableBinding({Source.class, MyProcessor.class}) +@EnableBinding({ Source.class, MyProcessor.class }) public class ContractVerifierSampleStreamSourceApplication { @Autowired @@ -37,13 +62,7 @@ public class ContractVerifierSampleStreamSourceApplication { this.source.output().send(MessageBuilder .withPayload("{\"id\":\"99\",\"temperature\":\"123.45\"}").build()); } -} -interface MyProcessor extends Sink { - String MY_OUTPUT = "my_output"; - - @Output("my_output") - MessageChannel output(); } @Component @@ -52,7 +71,9 @@ class MyProcessorListener { private static final Logger log = LoggerFactory.getLogger(MyProcessorListener.class); private final MyProcessor processor; + private final byte[] expectedInput; + private final byte[] expectedOutput; MyProcessorListener(MyProcessor processor) { @@ -77,8 +98,8 @@ class MyProcessorListener { if (!Arrays.equals(payload, this.expectedInput)) { throw new IllegalStateException("Wrong input"); } - this.processor.output().send( - MessageBuilder.withPayload(this.expectedOutput) - .build()); + this.processor.output() + .send(MessageBuilder.withPayload(this.expectedOutput).build()); } -} \ No newline at end of file + +} diff --git a/samples/standalone/messaging/stream-source/src/main/java/com/example/source/FooController.java b/samples/standalone/messaging/stream-source/src/main/java/com/example/source/FooController.java index e72de164eb..125331a6d8 100644 --- a/samples/standalone/messaging/stream-source/src/main/java/com/example/source/FooController.java +++ b/samples/standalone/messaging/stream-source/src/main/java/com/example/source/FooController.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.source; import org.springframework.web.bind.annotation.GetMapping; @@ -9,8 +25,9 @@ import org.springframework.web.bind.annotation.RestController; @RestController class FooController { - @GetMapping("/foo") - void foo() { + @GetMapping("/foo") + void foo() { + + } - } } diff --git a/samples/standalone/messaging/stream-source/src/test/java/com/example/source/ContractVerifierSampleStreamSourceApplicationTests.java b/samples/standalone/messaging/stream-source/src/test/java/com/example/source/ContractVerifierSampleStreamSourceApplicationTests.java index fe1133c580..90dab3d548 100644 --- a/samples/standalone/messaging/stream-source/src/test/java/com/example/source/ContractVerifierSampleStreamSourceApplicationTests.java +++ b/samples/standalone/messaging/stream-source/src/test/java/com/example/source/ContractVerifierSampleStreamSourceApplicationTests.java @@ -1,7 +1,24 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.source; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; diff --git a/samples/standalone/messaging/stream-source/src/test/java/com/example/source/SensorSourceTestBase.java b/samples/standalone/messaging/stream-source/src/test/java/com/example/source/SensorSourceTestBase.java index 63d504e5f8..aaafcaffe1 100644 --- a/samples/standalone/messaging/stream-source/src/test/java/com/example/source/SensorSourceTestBase.java +++ b/samples/standalone/messaging/stream-source/src/test/java/com/example/source/SensorSourceTestBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package com.example.source; import io.restassured.module.mockmvc.RestAssuredMockMvc; import org.junit.Before; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.contract.verifier.messaging.boot.AutoConfigureMessageVerifier; @@ -33,7 +34,7 @@ import org.springframework.web.context.WebApplicationContext; * @author Marius Bogoevici */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = ContractVerifierSampleStreamSourceApplication.class, properties="spring.cloud.stream.bindings.output.destination=sensor-data") +@SpringBootTest(classes = ContractVerifierSampleStreamSourceApplication.class, properties = "spring.cloud.stream.bindings.output.destination=sensor-data") @AutoConfigureMessageVerifier public abstract class SensorSourceTestBase { @@ -51,4 +52,5 @@ public abstract class SensorSourceTestBase { public void createSensorData() { application.poll(); } + } diff --git a/samples/standalone/messaging/stream-source/src/test/resources/contracts/shouldProduceValidSensorData.groovy b/samples/standalone/messaging/stream-source/src/test/resources/contracts/shouldProduceValidSensorData.groovy index 9eb30debf0..da45ed7d72 100644 --- a/samples/standalone/messaging/stream-source/src/test/resources/contracts/shouldProduceValidSensorData.groovy +++ b/samples/standalone/messaging/stream-source/src/test/resources/contracts/shouldProduceValidSensorData.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts org.springframework.cloud.contract.spec.Contract.make { @@ -18,8 +34,8 @@ org.springframework.cloud.contract.spec.Contract.make { header('contentType': 'application/json') } // the body of the output message - body ([ - id: $(consumer(9), producer(regex("[0-9]+"))), + body([ + id : $(consumer(9), producer(regex("[0-9]+"))), temperature: "123.45" ]) } diff --git a/samples/standalone/messaging/stream-source/src/test/resources/contracts/shouldWorkWithInputOutputBinary.groovy b/samples/standalone/messaging/stream-source/src/test/resources/contracts/shouldWorkWithInputOutputBinary.groovy index 2d7a2474df..f42b3502cc 100644 --- a/samples/standalone/messaging/stream-source/src/test/resources/contracts/shouldWorkWithInputOutputBinary.groovy +++ b/samples/standalone/messaging/stream-source/src/test/resources/contracts/shouldWorkWithInputOutputBinary.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts import org.springframework.cloud.contract.spec.Contract diff --git a/samples/standalone/pact/pact-http-client/.mvn/wrapper/MavenWrapperDownloader.java b/samples/standalone/pact/pact-http-client/.mvn/wrapper/MavenWrapperDownloader.java index d475a89ce1..44f295e331 100755 --- a/samples/standalone/pact/pact-http-client/.mvn/wrapper/MavenWrapperDownloader.java +++ b/samples/standalone/pact/pact-http-client/.mvn/wrapper/MavenWrapperDownloader.java @@ -1,3 +1,4 @@ + /* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -17,94 +18,100 @@ specific language governing permissions and limitations under the License. */ -import java.net.*; -import java.io.*; -import java.nio.channels.*; import java.util.Properties; public class MavenWrapperDownloader { - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = - "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is + * provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to - * use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = - ".mvn/wrapper/maven-wrapper.properties"; + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl + * property to use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = ".mvn/wrapper/maven-wrapper.properties"; - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = - ".mvn/wrapper/maven-wrapper.jar"; + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar"; - /** - * Name of the property which should be used to override the default download url for the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + /** + * Name of the property which should be used to override the default download url for + * the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - // If the maven-wrapper.properties exists, read it and check if it contains a custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } finally { - try { - if(mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: : " + url); + // If the maven-wrapper.properties exists, read it and check if it contains a + // custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, + MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if (mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream( + mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } + catch (IOException e) { + System.out.println( + "- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } + finally { + try { + if (mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } + catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { - System.out.println( - "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } + File outputFile = new File(baseDirectory.getAbsolutePath(), + MAVEN_WRAPPER_JAR_PATH); + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { + System.out.println("- ERROR creating output direcrory '" + + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } + catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } - private static void downloadFileFromURL(String urlString, File destination) throws Exception { - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } + private static void downloadFileFromURL(String urlString, File destination) + throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } } diff --git a/samples/standalone/pact/pact-http-client/pom.xml b/samples/standalone/pact/pact-http-client/pom.xml index d4458ce2d9..faacbb7c5a 100644 --- a/samples/standalone/pact/pact-http-client/pom.xml +++ b/samples/standalone/pact/pact-http-client/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 com.example @@ -14,13 +15,14 @@ org.springframework.boot spring-boot-starter-parent 2.1.2.RELEASE - + UTF-8 1.8 - Greenwich.BUILD-SNAPSHOT + Greenwich.BUILD-SNAPSHOT + @@ -173,7 +175,9 @@ clean build publishToMavenLocal - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + @@ -203,7 +207,9 @@ clean build publishToMavenLocal - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + diff --git a/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/Application.java b/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/Application.java index 6f36301172..ca4e1a4767 100644 --- a/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/Application.java +++ b/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/Application.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan; import org.springframework.boot.SpringApplication; diff --git a/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/LoanApplicationService.java b/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/LoanApplicationService.java index c91df67aea..a279823dfb 100644 --- a/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/LoanApplicationService.java +++ b/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/LoanApplicationService.java @@ -1,5 +1,29 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan; +import com.example.loan.model.FraudCheckStatus; +import com.example.loan.model.FraudServiceRequest; +import com.example.loan.model.FraudServiceResponse; +import com.example.loan.model.LoanApplication; +import com.example.loan.model.LoanApplicationResult; +import com.example.loan.model.LoanApplicationStatus; +import com.example.loan.model.Response; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.http.HttpEntity; @@ -9,19 +33,10 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; -import com.example.loan.model.FraudCheckStatus; -import com.example.loan.model.FraudServiceRequest; -import com.example.loan.model.FraudServiceResponse; -import com.example.loan.model.LoanApplication; -import com.example.loan.model.LoanApplicationResult; -import com.example.loan.model.LoanApplicationStatus; -import com.example.loan.model.Response; - @Service public class LoanApplicationService { - private static final String FRAUD_SERVICE_JSON_VERSION_1 = - "application/vnd.fraud.v1+json"; + private static final String FRAUD_SERVICE_JSON_VERSION_1 = "application/vnd.fraud.v1+json"; private final RestTemplate restTemplate; @@ -33,11 +48,9 @@ public class LoanApplicationService { } public LoanApplicationResult loanApplication(LoanApplication loanApplication) { - FraudServiceRequest request = - new FraudServiceRequest(loanApplication); + FraudServiceRequest request = new FraudServiceRequest(loanApplication); - FraudServiceResponse response = - sendRequestToFraudDetectionService(request); + FraudServiceResponse response = sendRequestToFraudDetectionService(request); return buildResponseFromFraudResult(response); } @@ -48,43 +61,43 @@ public class LoanApplicationService { httpHeaders.add(HttpHeaders.CONTENT_TYPE, FRAUD_SERVICE_JSON_VERSION_1); // tag::client_call_server[] - ResponseEntity response = - restTemplate.exchange("http://localhost:" + port + "/fraudcheck", HttpMethod.PUT, - new HttpEntity<>(request, httpHeaders), - FraudServiceResponse.class); + ResponseEntity response = restTemplate.exchange( + "http://localhost:" + port + "/fraudcheck", HttpMethod.PUT, + new HttpEntity<>(request, httpHeaders), FraudServiceResponse.class); // end::client_call_server[] return response.getBody(); } - private LoanApplicationResult buildResponseFromFraudResult(FraudServiceResponse response) { + private LoanApplicationResult buildResponseFromFraudResult( + FraudServiceResponse response) { LoanApplicationStatus applicationStatus = null; if (FraudCheckStatus.OK == response.getFraudCheckStatus()) { applicationStatus = LoanApplicationStatus.LOAN_APPLIED; - } else if (FraudCheckStatus.FRAUD == response.getFraudCheckStatus()) { + } + else if (FraudCheckStatus.FRAUD == response.getFraudCheckStatus()) { applicationStatus = LoanApplicationStatus.LOAN_APPLICATION_REJECTED; } - return new LoanApplicationResult(applicationStatus, response.getRejectionReason()); + return new LoanApplicationResult(applicationStatus, + response.getRejectionReason()); } public int countAllFrauds() { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.add(HttpHeaders.CONTENT_TYPE, FRAUD_SERVICE_JSON_VERSION_1); - ResponseEntity response = - restTemplate.exchange("http://localhost:" + port + "/frauds", HttpMethod.GET, - new HttpEntity<>(httpHeaders), - Response.class); + ResponseEntity response = restTemplate.exchange( + "http://localhost:" + port + "/frauds", HttpMethod.GET, + new HttpEntity<>(httpHeaders), Response.class); return response.getBody().getCount(); } public int countDrunks() { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.add(HttpHeaders.CONTENT_TYPE, FRAUD_SERVICE_JSON_VERSION_1); - ResponseEntity response = - restTemplate.exchange("http://localhost:" + port + "/drunks", HttpMethod.GET, - new HttpEntity<>(httpHeaders), - Response.class); + ResponseEntity response = restTemplate.exchange( + "http://localhost:" + port + "/drunks", HttpMethod.GET, + new HttpEntity<>(httpHeaders), Response.class); return response.getBody().getCount(); } diff --git a/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/Client.java b/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/Client.java index abf66106b5..4c197f9a4e 100644 --- a/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/Client.java +++ b/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/Client.java @@ -1,9 +1,25 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public class Client { private String pesel; - + public Client() { } @@ -18,4 +34,5 @@ public class Client { public void setPesel(String pesel) { this.pesel = pesel; } + } diff --git a/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/FraudCheckStatus.java b/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/FraudCheckStatus.java index c5217ef471..762692e74a 100644 --- a/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/FraudCheckStatus.java +++ b/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/FraudCheckStatus.java @@ -1,5 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public enum FraudCheckStatus { + OK, FRAUD + } diff --git a/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/FraudServiceRequest.java b/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/FraudServiceRequest.java index 0230540131..8b309f130d 100644 --- a/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/FraudServiceRequest.java +++ b/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/FraudServiceRequest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; import java.math.BigDecimal; @@ -31,4 +47,5 @@ public class FraudServiceRequest { public void setLoanAmount(BigDecimal loanAmount) { this.loanAmount = loanAmount; } + } diff --git a/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/FraudServiceResponse.java b/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/FraudServiceResponse.java index 50e64478b9..5e86755f36 100644 --- a/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/FraudServiceResponse.java +++ b/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/FraudServiceResponse.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public class FraudServiceResponse { @@ -24,4 +40,5 @@ public class FraudServiceResponse { public void setRejectionReason(String rejectionReason) { this.rejectionReason = rejectionReason; } + } diff --git a/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/LoanApplication.java b/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/LoanApplication.java index 27d66f884c..e0cd87ec51 100644 --- a/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/LoanApplication.java +++ b/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/LoanApplication.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; import java.math.BigDecimal; @@ -41,4 +57,5 @@ public class LoanApplication { public void setLoanApplicationId(String loanApplicationId) { this.loanApplicationId = loanApplicationId; } + } diff --git a/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/LoanApplicationResult.java b/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/LoanApplicationResult.java index ffd44e1a26..44ea77ebce 100644 --- a/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/LoanApplicationResult.java +++ b/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/LoanApplicationResult.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public class LoanApplicationResult { @@ -9,7 +25,8 @@ public class LoanApplicationResult { public LoanApplicationResult() { } - public LoanApplicationResult(LoanApplicationStatus loanApplicationStatus, String rejectionReason) { + public LoanApplicationResult(LoanApplicationStatus loanApplicationStatus, + String rejectionReason) { this.loanApplicationStatus = loanApplicationStatus; this.rejectionReason = rejectionReason; } @@ -29,4 +46,5 @@ public class LoanApplicationResult { public void setRejectionReason(String rejectionReason) { this.rejectionReason = rejectionReason; } + } diff --git a/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/LoanApplicationStatus.java b/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/LoanApplicationStatus.java index 34cf91a89f..b5c85900d3 100644 --- a/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/LoanApplicationStatus.java +++ b/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/LoanApplicationStatus.java @@ -1,5 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public enum LoanApplicationStatus { + LOAN_APPLIED, LOAN_APPLICATION_REJECTED + } diff --git a/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/Response.java b/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/Response.java index 8335ee0cc6..d43a4cf298 100644 --- a/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/Response.java +++ b/samples/standalone/pact/pact-http-client/src/main/java/com/example/loan/model/Response.java @@ -1,6 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public class Response { + private int count; public Response(int count) { @@ -17,4 +34,5 @@ public class Response { public void setCount(int count) { this.count = count; } -} \ No newline at end of file + +} diff --git a/samples/standalone/pact/pact-http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java b/samples/standalone/pact/pact-http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java index 3bf935987d..904dddfc86 100644 --- a/samples/standalone/pact/pact-http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java +++ b/samples/standalone/pact/pact-http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java @@ -1,10 +1,29 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan; -import static org.assertj.core.api.Assertions.assertThat; - +import com.example.loan.model.Client; +import com.example.loan.model.LoanApplication; +import com.example.loan.model.LoanApplicationResult; +import com.example.loan.model.LoanApplicationStatus; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -13,15 +32,12 @@ import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties import org.springframework.core.env.Environment; import org.springframework.test.context.junit4.SpringRunner; -import com.example.loan.model.Client; -import com.example.loan.model.LoanApplication; -import com.example.loan.model.LoanApplicationResult; -import com.example.loan.model.LoanApplicationStatus; +import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment=WebEnvironment.NONE) -@AutoConfigureStubRunner(ids = {"com.example:pact-http-server:+:stubs"}, - stubsMode = StubRunnerProperties.StubsMode.LOCAL) +@SpringBootTest(webEnvironment = WebEnvironment.NONE) +@AutoConfigureStubRunner(ids = { + "com.example:pact-http-server:+:stubs" }, stubsMode = StubRunnerProperties.StubsMode.LOCAL) public class LoanApplicationServiceTests { @Autowired @@ -32,7 +48,8 @@ public class LoanApplicationServiceTests { @Before public void setup() { - this.service.setPort(this.environment.getProperty("stubrunner.runningstubs.pact-http-server.port", Integer.class)); + this.service.setPort(this.environment.getProperty( + "stubrunner.runningstubs.pact-http-server.port", Integer.class)); } @Test diff --git a/samples/standalone/pact/pact-http-client/src/test/resources/application-gradle.yaml b/samples/standalone/pact/pact-http-client/src/test/resources/application-gradle.yaml index 25f0e2b24a..81833e733d 100644 --- a/samples/standalone/pact/pact-http-client/src/test/resources/application-gradle.yaml +++ b/samples/standalone/pact/pact-http-client/src/test/resources/application-gradle.yaml @@ -1,3 +1,3 @@ stubrunner: work-offline: true - stubs.ids: 'com.example:pact-http-server-gradle:+:stubs' \ No newline at end of file + stubs.ids: 'com.example:pact-http-server-gradle:+:stubs' diff --git a/samples/standalone/pact/pact-http-server/.mvn/wrapper/MavenWrapperDownloader.java b/samples/standalone/pact/pact-http-server/.mvn/wrapper/MavenWrapperDownloader.java index d475a89ce1..44f295e331 100755 --- a/samples/standalone/pact/pact-http-server/.mvn/wrapper/MavenWrapperDownloader.java +++ b/samples/standalone/pact/pact-http-server/.mvn/wrapper/MavenWrapperDownloader.java @@ -1,3 +1,4 @@ + /* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -17,94 +18,100 @@ specific language governing permissions and limitations under the License. */ -import java.net.*; -import java.io.*; -import java.nio.channels.*; import java.util.Properties; public class MavenWrapperDownloader { - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = - "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is + * provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to - * use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = - ".mvn/wrapper/maven-wrapper.properties"; + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl + * property to use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = ".mvn/wrapper/maven-wrapper.properties"; - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = - ".mvn/wrapper/maven-wrapper.jar"; + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar"; - /** - * Name of the property which should be used to override the default download url for the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + /** + * Name of the property which should be used to override the default download url for + * the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - // If the maven-wrapper.properties exists, read it and check if it contains a custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } finally { - try { - if(mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: : " + url); + // If the maven-wrapper.properties exists, read it and check if it contains a + // custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, + MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if (mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream( + mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } + catch (IOException e) { + System.out.println( + "- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } + finally { + try { + if (mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } + catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { - System.out.println( - "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } + File outputFile = new File(baseDirectory.getAbsolutePath(), + MAVEN_WRAPPER_JAR_PATH); + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { + System.out.println("- ERROR creating output direcrory '" + + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } + catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } - private static void downloadFileFromURL(String urlString, File destination) throws Exception { - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } + private static void downloadFileFromURL(String urlString, File destination) + throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } } diff --git a/samples/standalone/pact/pact-http-server/pom.xml b/samples/standalone/pact/pact-http-server/pom.xml index eaa671d414..85ba1814dc 100644 --- a/samples/standalone/pact/pact-http-server/pom.xml +++ b/samples/standalone/pact/pact-http-server/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 com.example @@ -14,14 +15,16 @@ org.springframework.boot spring-boot-starter-parent 2.1.2.RELEASE - + UTF-8 1.8 - 2.1.1.BUILD-SNAPSHOT - Greenwich.BUILD-SNAPSHOT + 2.1.1.BUILD-SNAPSHOT + + Greenwich.BUILD-SNAPSHOT + @@ -126,8 +129,11 @@ org.springframework.cloud - spring-cloud-contract-maven-plugin - [${spring-cloud-contract.version},) + spring-cloud-contract-maven-plugin + + + [${spring-cloud-contract.version},) + convert generateTests @@ -217,7 +223,9 @@ clean build publishToMavenLocal - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + @@ -247,7 +255,9 @@ clean build publishToMavenLocal - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + diff --git a/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/Application.java b/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/Application.java index 9117009b09..ef20bf067e 100644 --- a/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/Application.java +++ b/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/Application.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; import org.springframework.boot.SpringApplication; diff --git a/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/FraudDetectionController.java b/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/FraudDetectionController.java index 99e7fea84e..def306cb6b 100644 --- a/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/FraudDetectionController.java +++ b/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/FraudDetectionController.java @@ -1,30 +1,45 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; -import static org.springframework.web.bind.annotation.RequestMethod.PUT; - import java.math.BigDecimal; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - import com.example.fraud.model.FraudCheck; import com.example.fraud.model.FraudCheckResult; import com.example.fraud.model.FraudCheckStatus; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import static org.springframework.web.bind.annotation.RequestMethod.PUT; + @RestController public class FraudDetectionController { private static final String FRAUD_SERVICE_JSON_VERSION_1 = "application/vnd.fraud.v1+json"; + private static final String NO_REASON = null; + private static final String AMOUNT_TOO_HIGH = "Amount too high"; + private static final BigDecimal MAX_AMOUNT = new BigDecimal("5000"); - @RequestMapping( - value = "/fraudcheck", - method = PUT, - consumes = FRAUD_SERVICE_JSON_VERSION_1, - produces = FRAUD_SERVICE_JSON_VERSION_1) + @RequestMapping(value = "/fraudcheck", method = PUT, consumes = FRAUD_SERVICE_JSON_VERSION_1, produces = FRAUD_SERVICE_JSON_VERSION_1) public FraudCheckResult fraudCheck(@RequestBody FraudCheck fraudCheck) { if (amountGreaterThanThreshold(fraudCheck)) { return new FraudCheckResult(FraudCheckStatus.FRAUD, AMOUNT_TOO_HIGH); diff --git a/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/FraudStatsController.java b/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/FraudStatsController.java index 5b27668600..c0db44f5dd 100644 --- a/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/FraudStatsController.java +++ b/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/FraudStatsController.java @@ -1,8 +1,36 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; +enum FraudType { + + DRUNKS, ALL + +} + +interface StatsProvider { + + int count(FraudType fraudType); + +} + @RestController public class FraudStatsController { @@ -14,30 +42,20 @@ public class FraudStatsController { this.statsProvider = statsProvider; } - @GetMapping( - value = "/frauds", - produces = FRAUD_SERVICE_JSON_VERSION_1) + @GetMapping(value = "/frauds", produces = FRAUD_SERVICE_JSON_VERSION_1) public Response countAllFrauds() { return new Response(this.statsProvider.count(FraudType.ALL)); } - @GetMapping( - value = "/drunks", - produces = FRAUD_SERVICE_JSON_VERSION_1) + @GetMapping(value = "/drunks", produces = FRAUD_SERVICE_JSON_VERSION_1) public Response countAllDrunks() { return new Response(this.statsProvider.count(FraudType.DRUNKS)); } -} -enum FraudType { - DRUNKS, ALL -} - -interface StatsProvider { - int count(FraudType fraudType); } class Response { + private int count; public Response(int count) { @@ -54,5 +72,5 @@ class Response { public void setCount(int count) { this.count = count; } -} +} diff --git a/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/model/FraudCheck.java b/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/model/FraudCheck.java index b0210573e2..9ed18b12df 100644 --- a/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/model/FraudCheck.java +++ b/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/model/FraudCheck.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud.model; import java.math.BigDecimal; @@ -26,4 +42,5 @@ public class FraudCheck { public void setLoanAmount(BigDecimal loanAmount) { this.loanAmount = loanAmount; } + } diff --git a/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/model/FraudCheckResult.java b/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/model/FraudCheckResult.java index 60b340276a..9d9ab02c18 100644 --- a/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/model/FraudCheckResult.java +++ b/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/model/FraudCheckResult.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud.model; public class FraudCheckResult { @@ -29,4 +45,5 @@ public class FraudCheckResult { public void setRejectionReason(String rejectionReason) { this.rejectionReason = rejectionReason; } + } diff --git a/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/model/FraudCheckStatus.java b/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/model/FraudCheckStatus.java index 5a6adcf274..02d37adf46 100644 --- a/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/model/FraudCheckStatus.java +++ b/samples/standalone/pact/pact-http-server/src/main/java/com/example/fraud/model/FraudCheckStatus.java @@ -1,5 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud.model; public enum FraudCheckStatus { + OK, FRAUD + } diff --git a/samples/standalone/pact/pact-http-server/src/test/java/com/example/fraud/FraudBase.java b/samples/standalone/pact/pact-http-server/src/test/java/com/example/fraud/FraudBase.java index 1e4fc7aff3..22b788e8c3 100644 --- a/samples/standalone/pact/pact-http-server/src/test/java/com/example/fraud/FraudBase.java +++ b/samples/standalone/pact/pact-http-server/src/test/java/com/example/fraud/FraudBase.java @@ -1,8 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; -import org.junit.Before; - import io.restassured.module.mockmvc.RestAssuredMockMvc; +import org.junit.Before; public class FraudBase { @@ -27,4 +42,5 @@ public class FraudBase { public void assertThatRejectionReasonIsNull(Object rejectionReason) { assert rejectionReason == null; } -} \ No newline at end of file + +} diff --git a/samples/standalone/pact/pact-http-server/src/test/resources/contracts/fraud/shouldMarkClientAsFraud.json b/samples/standalone/pact/pact-http-server/src/test/resources/contracts/fraud/shouldMarkClientAsFraud.json index 40675c6dac..3135fef8f4 100644 --- a/samples/standalone/pact/pact-http-server/src/test/resources/contracts/fraud/shouldMarkClientAsFraud.json +++ b/samples/standalone/pact/pact-http-server/src/test/resources/contracts/fraud/shouldMarkClientAsFraud.json @@ -38,7 +38,7 @@ "combine": "AND" } }, - "body" : { + "body": { "$.clientId": { "matchers": [ { @@ -95,4 +95,4 @@ "version": "3.5.13" } } -} \ No newline at end of file +} diff --git a/samples/standalone/pact/pact-http-server/src/test/resources/contracts/fraud/shouldMarkClientAsNotFraud.json b/samples/standalone/pact/pact-http-server/src/test/resources/contracts/fraud/shouldMarkClientAsNotFraud.json index 0b947bc8c0..0d1825a800 100644 --- a/samples/standalone/pact/pact-http-server/src/test/resources/contracts/fraud/shouldMarkClientAsNotFraud.json +++ b/samples/standalone/pact/pact-http-server/src/test/resources/contracts/fraud/shouldMarkClientAsNotFraud.json @@ -39,4 +39,4 @@ "version": "2.4.18" } } -} \ No newline at end of file +} diff --git a/samples/standalone/pact/pact-http-server/src/test/resources/contracts/fraud/shouldReturnDrunksStats.json b/samples/standalone/pact/pact-http-server/src/test/resources/contracts/fraud/shouldReturnDrunksStats.json index f939e710c9..e53984d8f9 100644 --- a/samples/standalone/pact/pact-http-server/src/test/resources/contracts/fraud/shouldReturnDrunksStats.json +++ b/samples/standalone/pact/pact-http-server/src/test/resources/contracts/fraud/shouldReturnDrunksStats.json @@ -31,4 +31,4 @@ "version": "2.4.18" } } -} \ No newline at end of file +} diff --git a/samples/standalone/pact/pact-http-server/src/test/resources/contracts/fraud/shouldReturnFraudStats.json b/samples/standalone/pact/pact-http-server/src/test/resources/contracts/fraud/shouldReturnFraudStats.json index 160f1e618f..3cf184c343 100644 --- a/samples/standalone/pact/pact-http-server/src/test/resources/contracts/fraud/shouldReturnFraudStats.json +++ b/samples/standalone/pact/pact-http-server/src/test/resources/contracts/fraud/shouldReturnFraudStats.json @@ -31,4 +31,4 @@ "version": "2.4.18" } } -} \ No newline at end of file +} diff --git a/samples/standalone/pact/pom.xml b/samples/standalone/pact/pom.xml index a2c1095865..6d78e855a2 100644 --- a/samples/standalone/pact/pom.xml +++ b/samples/standalone/pact/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 @@ -14,10 +15,13 @@ pom Spring Cloud Contract Standalone Pact Test Samples - Spring Cloud Contract Standalone Test Samples used for end to end tests with Pact + Spring Cloud Contract Standalone Test Samples used for end to end tests + with Pact + - 2.1.1.BUILD-SNAPSHOT + 2.1.1.BUILD-SNAPSHOT + diff --git a/samples/standalone/pom.xml b/samples/standalone/pom.xml index 69143a12d6..c5b2d2dc81 100644 --- a/samples/standalone/pom.xml +++ b/samples/standalone/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 @@ -14,7 +15,8 @@ pom 2.1.1.BUILD-SNAPSHOT Spring Cloud Contract Standalone Test Samples - Spring Cloud Contract Standalone Test Samples used for end to end tests + Spring Cloud Contract Standalone Test Samples used for end to end tests + ${project.version} diff --git a/samples/standalone/restdocs/http-client/.mvn/wrapper/MavenWrapperDownloader.java b/samples/standalone/restdocs/http-client/.mvn/wrapper/MavenWrapperDownloader.java index d475a89ce1..44f295e331 100755 --- a/samples/standalone/restdocs/http-client/.mvn/wrapper/MavenWrapperDownloader.java +++ b/samples/standalone/restdocs/http-client/.mvn/wrapper/MavenWrapperDownloader.java @@ -1,3 +1,4 @@ + /* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -17,94 +18,100 @@ specific language governing permissions and limitations under the License. */ -import java.net.*; -import java.io.*; -import java.nio.channels.*; import java.util.Properties; public class MavenWrapperDownloader { - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = - "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is + * provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to - * use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = - ".mvn/wrapper/maven-wrapper.properties"; + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl + * property to use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = ".mvn/wrapper/maven-wrapper.properties"; - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = - ".mvn/wrapper/maven-wrapper.jar"; + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar"; - /** - * Name of the property which should be used to override the default download url for the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + /** + * Name of the property which should be used to override the default download url for + * the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - // If the maven-wrapper.properties exists, read it and check if it contains a custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } finally { - try { - if(mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: : " + url); + // If the maven-wrapper.properties exists, read it and check if it contains a + // custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, + MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if (mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream( + mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } + catch (IOException e) { + System.out.println( + "- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } + finally { + try { + if (mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } + catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { - System.out.println( - "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } + File outputFile = new File(baseDirectory.getAbsolutePath(), + MAVEN_WRAPPER_JAR_PATH); + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { + System.out.println("- ERROR creating output direcrory '" + + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } + catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } - private static void downloadFileFromURL(String urlString, File destination) throws Exception { - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } + private static void downloadFileFromURL(String urlString, File destination) + throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } } diff --git a/samples/standalone/restdocs/http-client/build.gradle b/samples/standalone/restdocs/http-client/build.gradle index aef0342b60..c5a98ae511 100644 --- a/samples/standalone/restdocs/http-client/build.gradle +++ b/samples/standalone/restdocs/http-client/build.gradle @@ -38,7 +38,7 @@ dependencies { compile("org.springframework.boot:spring-boot-starter-web") compile("org.springframework.boot:spring-boot-starter-actuator") compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml") - + testCompile 'org.springframework.cloud:spring-cloud-contract-wiremock' testCompile 'org.springframework.cloud:spring-cloud-starter-contract-stub-runner' testCompile "org.springframework.boot:spring-boot-starter-test" diff --git a/samples/standalone/restdocs/http-client/pom.xml b/samples/standalone/restdocs/http-client/pom.xml index 03cf455046..2ccdebcee3 100644 --- a/samples/standalone/restdocs/http-client/pom.xml +++ b/samples/standalone/restdocs/http-client/pom.xml @@ -16,8 +16,9 @@ ~ --> - + 4.0.0 com.example @@ -31,13 +32,14 @@ org.springframework.boot spring-boot-starter-parent 2.1.2.RELEASE - + UTF-8 1.8 - 2.1.1.BUILD-SNAPSHOT + 2.1.1.BUILD-SNAPSHOT + @@ -205,7 +207,9 @@ clean build publishToMavenLocal - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + @@ -235,7 +239,9 @@ clean build publishToMavenLocal - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + diff --git a/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/Application.java b/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/Application.java index 6f36301172..ca4e1a4767 100644 --- a/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/Application.java +++ b/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/Application.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan; import org.springframework.boot.SpringApplication; diff --git a/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/LoanApplicationService.java b/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/LoanApplicationService.java index 9f3c759b9e..30829ce208 100644 --- a/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/LoanApplicationService.java +++ b/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/LoanApplicationService.java @@ -1,18 +1,17 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT 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 com.example.loan; @@ -37,8 +36,7 @@ import org.springframework.web.client.RestTemplate; @ConfigurationProperties("service") public class LoanApplicationService { - private static final String FRAUD_SERVICE_JSON_VERSION_1 = - "application/vnd.fraud.v1+json"; + private static final String FRAUD_SERVICE_JSON_VERSION_1 = "application/vnd.fraud.v1+json"; private final RestTemplate restTemplate; @@ -47,17 +45,14 @@ public class LoanApplicationService { public LoanApplicationService() { this.restTemplate = new RestTemplate(); // tag::custom_request_factory[] - this.restTemplate - .setRequestFactory(new HttpComponentsClientHttpRequestFactory()); + this.restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory()); // end::custom_request_factory[] } public LoanApplicationResult loanApplication(LoanApplication loanApplication) { - FraudServiceRequest request = - new FraudServiceRequest(loanApplication); + FraudServiceRequest request = new FraudServiceRequest(loanApplication); - FraudServiceResponse response = - sendRequestToFraudDetectionService(request); + FraudServiceResponse response = sendRequestToFraudDetectionService(request); return buildResponseFromFraudResult(response); } @@ -68,24 +63,26 @@ public class LoanApplicationService { httpHeaders.add(HttpHeaders.CONTENT_TYPE, FRAUD_SERVICE_JSON_VERSION_1); // tag::client_call_server[] - ResponseEntity response = - restTemplate.exchange("http://localhost:" + port + "/fraudcheck", HttpMethod.PUT, - new HttpEntity<>(request, httpHeaders), - FraudServiceResponse.class); + ResponseEntity response = restTemplate.exchange( + "http://localhost:" + port + "/fraudcheck", HttpMethod.PUT, + new HttpEntity<>(request, httpHeaders), FraudServiceResponse.class); // end::client_call_server[] return response.getBody(); } - private LoanApplicationResult buildResponseFromFraudResult(FraudServiceResponse response) { + private LoanApplicationResult buildResponseFromFraudResult( + FraudServiceResponse response) { LoanApplicationStatus applicationStatus = null; if (FraudCheckStatus.OK == response.getFraudCheckStatus()) { applicationStatus = LoanApplicationStatus.LOAN_APPLIED; - } else if (FraudCheckStatus.FRAUD == response.getFraudCheckStatus()) { + } + else if (FraudCheckStatus.FRAUD == response.getFraudCheckStatus()) { applicationStatus = LoanApplicationStatus.LOAN_APPLICATION_REJECTED; } - return new LoanApplicationResult(applicationStatus, response.getRejectionReason()); + return new LoanApplicationResult(applicationStatus, + response.getRejectionReason()); } public void setPort(int port) { diff --git a/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/ServiceProperties.java b/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/ServiceProperties.java index 0dff3bd2da..89034827da 100644 --- a/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/ServiceProperties.java +++ b/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/ServiceProperties.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -7,11 +23,12 @@ public class ServiceProperties { private int port = 8080; + public int getPort() { + return this.port; + } + public void setPort(int port) { this.port = port; } - public int getPort() { - return this.port; - } } diff --git a/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/Client.java b/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/Client.java index abf66106b5..4c197f9a4e 100644 --- a/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/Client.java +++ b/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/Client.java @@ -1,9 +1,25 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public class Client { private String pesel; - + public Client() { } @@ -18,4 +34,5 @@ public class Client { public void setPesel(String pesel) { this.pesel = pesel; } + } diff --git a/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/FraudCheckStatus.java b/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/FraudCheckStatus.java index c5217ef471..762692e74a 100644 --- a/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/FraudCheckStatus.java +++ b/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/FraudCheckStatus.java @@ -1,5 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public enum FraudCheckStatus { + OK, FRAUD + } diff --git a/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/FraudServiceRequest.java b/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/FraudServiceRequest.java index 0230540131..8b309f130d 100644 --- a/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/FraudServiceRequest.java +++ b/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/FraudServiceRequest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; import java.math.BigDecimal; @@ -31,4 +47,5 @@ public class FraudServiceRequest { public void setLoanAmount(BigDecimal loanAmount) { this.loanAmount = loanAmount; } + } diff --git a/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/FraudServiceResponse.java b/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/FraudServiceResponse.java index 50e64478b9..5e86755f36 100644 --- a/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/FraudServiceResponse.java +++ b/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/FraudServiceResponse.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public class FraudServiceResponse { @@ -24,4 +40,5 @@ public class FraudServiceResponse { public void setRejectionReason(String rejectionReason) { this.rejectionReason = rejectionReason; } + } diff --git a/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/LoanApplication.java b/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/LoanApplication.java index 27d66f884c..e0cd87ec51 100644 --- a/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/LoanApplication.java +++ b/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/LoanApplication.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; import java.math.BigDecimal; @@ -41,4 +57,5 @@ public class LoanApplication { public void setLoanApplicationId(String loanApplicationId) { this.loanApplicationId = loanApplicationId; } + } diff --git a/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/LoanApplicationResult.java b/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/LoanApplicationResult.java index ffd44e1a26..44ea77ebce 100644 --- a/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/LoanApplicationResult.java +++ b/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/LoanApplicationResult.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public class LoanApplicationResult { @@ -9,7 +25,8 @@ public class LoanApplicationResult { public LoanApplicationResult() { } - public LoanApplicationResult(LoanApplicationStatus loanApplicationStatus, String rejectionReason) { + public LoanApplicationResult(LoanApplicationStatus loanApplicationStatus, + String rejectionReason) { this.loanApplicationStatus = loanApplicationStatus; this.rejectionReason = rejectionReason; } @@ -29,4 +46,5 @@ public class LoanApplicationResult { public void setRejectionReason(String rejectionReason) { this.rejectionReason = rejectionReason; } + } diff --git a/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/LoanApplicationStatus.java b/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/LoanApplicationStatus.java index 34cf91a89f..b5c85900d3 100644 --- a/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/LoanApplicationStatus.java +++ b/samples/standalone/restdocs/http-client/src/main/java/com/example/loan/model/LoanApplicationStatus.java @@ -1,5 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public enum LoanApplicationStatus { + LOAN_APPLIED, LOAN_APPLICATION_REJECTED + } diff --git a/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java b/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java index ab17861df9..59faa0d0bb 100644 --- a/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java +++ b/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java @@ -1,11 +1,32 @@ -package com.example.loan; +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 static org.assertj.core.api.Assertions.assertThat; +package com.example.loan; import java.nio.charset.Charset; +import com.example.loan.model.Client; +import com.example.loan.model.LoanApplication; +import com.example.loan.model.LoanApplicationResult; +import com.example.loan.model.LoanApplicationStatus; +import com.github.tomakehurst.wiremock.WireMockServer; +import com.github.tomakehurst.wiremock.stubbing.StubMapping; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; @@ -14,16 +35,11 @@ import org.springframework.core.io.Resource; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.StreamUtils; -import com.example.loan.model.Client; -import com.example.loan.model.LoanApplication; -import com.example.loan.model.LoanApplicationResult; -import com.example.loan.model.LoanApplicationStatus; -import com.github.tomakehurst.wiremock.WireMockServer; -import com.github.tomakehurst.wiremock.stubbing.StubMapping; +import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@SpringBootTest(properties="service.port=${wiremock.server.port}") -@AutoConfigureWireMock(port=0) +@SpringBootTest(properties = "service.port=${wiremock.server.port}") +@AutoConfigureWireMock(port = 0) public class LoanApplicationServiceTests { @Autowired diff --git a/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerTests.java b/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerTests.java index 3c7403298f..9c789060fc 100644 --- a/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerTests.java +++ b/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerTests.java @@ -1,13 +1,29 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan; import com.example.loan.model.Client; import com.example.loan.model.LoanApplication; import com.example.loan.model.LoanApplicationResult; import com.example.loan.model.LoanApplicationStatus; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; @@ -21,8 +37,11 @@ import static org.assertj.core.api.Assertions.assertThat; @AutoConfigureStubRunner(ids = "com.example:http-server-restdocs") public class LoanApplicationServiceusingStubRunnerTests { - @Autowired LoanApplicationService service; - @Value("${stubrunner.runningstubs.http-server-restdocs.port}") int port; + @Autowired + LoanApplicationService service; + + @Value("${stubrunner.runningstubs.http-server-restdocs.port}") + int port; @Before public void setup() { diff --git a/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/XmlServiceTests.java b/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/XmlServiceTests.java index 77e0b2682b..2217954473 100644 --- a/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/XmlServiceTests.java +++ b/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/XmlServiceTests.java @@ -1,18 +1,17 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT 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 com.example.loan; @@ -39,8 +38,8 @@ import org.springframework.util.StreamUtils; import org.springframework.web.client.RestTemplate; @RunWith(SpringRunner.class) -@SpringBootTest(properties="service.port=${wiremock.server.port}") -@AutoConfigureWireMock(port=0) +@SpringBootTest(properties = "service.port=${wiremock.server.port}") +@AutoConfigureWireMock(port = 0) public class XmlServiceTests { @Value("classpath:META-INF/com.example/http-server-restdocs/0.0.1-SNAPSHOT/mappings/should_return_empty_content.json") @@ -54,11 +53,13 @@ public class XmlServiceTests { @Test public void shouldSuccessfullyReturnFullResponse() throws Exception { - server.addStubMapping(StubMapping.buildFrom(StreamUtils.copyToString( - full.getInputStream(), Charset.forName("UTF-8")))); + server.addStubMapping(StubMapping.buildFrom(StreamUtils + .copyToString(full.getInputStream(), Charset.forName("UTF-8")))); - ResponseEntity responseEntity = new RestTemplate().exchange( - RequestEntity.post(URI.create("http://localhost:" + server.port() + "/xmlfraud")) + ResponseEntity responseEntity = new RestTemplate() + .exchange(RequestEntity + .post(URI.create( + "http://localhost:" + server.port() + "/xmlfraud")) .contentType(MediaType.valueOf("application/xml;charset=UTF-8")) .body(new XmlRequestBody("foo")), XmlResponseBody.class); @@ -68,11 +69,13 @@ public class XmlServiceTests { @Test public void shouldSuccessfullyReturnEmptyResponse() throws Exception { - server.addStubMapping(StubMapping.buildFrom(StreamUtils.copyToString( - empty.getInputStream(), Charset.forName("UTF-8")))); + server.addStubMapping(StubMapping.buildFrom(StreamUtils + .copyToString(empty.getInputStream(), Charset.forName("UTF-8")))); - ResponseEntity responseEntity = new RestTemplate().exchange( - RequestEntity.post(URI.create("http://localhost:" + server.port() + "/xmlfraud")) + ResponseEntity responseEntity = new RestTemplate() + .exchange(RequestEntity + .post(URI.create( + "http://localhost:" + server.port() + "/xmlfraud")) .contentType(MediaType.valueOf("application/xml;charset=UTF-8")) .body(new XmlRequestBody("")), XmlResponseBody.class); @@ -83,14 +86,17 @@ public class XmlServiceTests { } class XmlRequestBody { + public String name; public XmlRequestBody(String name) { this.name = name; } + } class XmlResponseBody { + public String status; public XmlResponseBody(String status) { @@ -99,4 +105,5 @@ class XmlResponseBody { public XmlResponseBody() { } -} \ No newline at end of file + +} diff --git a/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/XmlServiceUsingStubRunnerTests.java b/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/XmlServiceUsingStubRunnerTests.java index bd7b47e2a6..533f7390a0 100644 --- a/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/XmlServiceUsingStubRunnerTests.java +++ b/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/XmlServiceUsingStubRunnerTests.java @@ -1,18 +1,27 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan; import java.net.URI; -import java.nio.charset.Charset; -import com.example.loan.model.Client; -import com.example.loan.model.LoanApplication; -import com.example.loan.model.LoanApplicationResult; -import com.example.loan.model.LoanApplicationStatus; -import com.github.tomakehurst.wiremock.stubbing.StubMapping; import org.assertj.core.api.BDDAssertions; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; + import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner; @@ -20,22 +29,21 @@ import org.springframework.http.MediaType; import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.util.StreamUtils; import org.springframework.web.client.RestTemplate; -import static org.assertj.core.api.Assertions.assertThat; - @RunWith(SpringRunner.class) @SpringBootTest @AutoConfigureStubRunner(ids = "com.example:http-server-restdocs") public class XmlServiceUsingStubRunnerTests { - @Value("${stubrunner.runningstubs.http-server-restdocs.port}") int port; + @Value("${stubrunner.runningstubs.http-server-restdocs.port}") + int port; @Test public void shouldSuccessfullyReturnFullResponse() throws Exception { - ResponseEntity responseEntity = new RestTemplate().exchange( - RequestEntity.post(URI.create("http://localhost:" + this.port + "/xmlfraud")) + ResponseEntity responseEntity = new RestTemplate() + .exchange(RequestEntity + .post(URI.create("http://localhost:" + this.port + "/xmlfraud")) .contentType(MediaType.valueOf("application/xml;charset=UTF-8")) .body(new XmlRequestBody("foo")), XmlResponseBody.class); @@ -45,8 +53,9 @@ public class XmlServiceUsingStubRunnerTests { @Test public void shouldSuccessfullyReturnEmptyResponse() throws Exception { - ResponseEntity responseEntity = new RestTemplate().exchange( - RequestEntity.post(URI.create("http://localhost:" + this.port + "/xmlfraud")) + ResponseEntity responseEntity = new RestTemplate() + .exchange(RequestEntity + .post(URI.create("http://localhost:" + this.port + "/xmlfraud")) .contentType(MediaType.valueOf("application/xml;charset=UTF-8")) .body(new XmlRequestBody("")), XmlResponseBody.class); diff --git a/samples/standalone/restdocs/http-client/src/test/resources/application-gradle.yaml b/samples/standalone/restdocs/http-client/src/test/resources/application-gradle.yaml index 3b8362b436..b1818d9164 100644 --- a/samples/standalone/restdocs/http-client/src/test/resources/application-gradle.yaml +++ b/samples/standalone/restdocs/http-client/src/test/resources/application-gradle.yaml @@ -1,2 +1,2 @@ stubrunner: - stubs.ids: 'com.example:http-server-restdocs-gradle' \ No newline at end of file + stubs.ids: 'com.example:http-server-restdocs-gradle' diff --git a/samples/standalone/restdocs/http-server/.mvn/wrapper/MavenWrapperDownloader.java b/samples/standalone/restdocs/http-server/.mvn/wrapper/MavenWrapperDownloader.java index d475a89ce1..44f295e331 100755 --- a/samples/standalone/restdocs/http-server/.mvn/wrapper/MavenWrapperDownloader.java +++ b/samples/standalone/restdocs/http-server/.mvn/wrapper/MavenWrapperDownloader.java @@ -1,3 +1,4 @@ + /* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -17,94 +18,100 @@ specific language governing permissions and limitations under the License. */ -import java.net.*; -import java.io.*; -import java.nio.channels.*; import java.util.Properties; public class MavenWrapperDownloader { - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = - "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is + * provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to - * use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = - ".mvn/wrapper/maven-wrapper.properties"; + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl + * property to use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = ".mvn/wrapper/maven-wrapper.properties"; - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = - ".mvn/wrapper/maven-wrapper.jar"; + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar"; - /** - * Name of the property which should be used to override the default download url for the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + /** + * Name of the property which should be used to override the default download url for + * the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - // If the maven-wrapper.properties exists, read it and check if it contains a custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } finally { - try { - if(mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: : " + url); + // If the maven-wrapper.properties exists, read it and check if it contains a + // custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, + MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if (mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream( + mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } + catch (IOException e) { + System.out.println( + "- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } + finally { + try { + if (mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } + catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { - System.out.println( - "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } + File outputFile = new File(baseDirectory.getAbsolutePath(), + MAVEN_WRAPPER_JAR_PATH); + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { + System.out.println("- ERROR creating output direcrory '" + + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } + catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } - private static void downloadFileFromURL(String urlString, File destination) throws Exception { - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } + private static void downloadFileFromURL(String urlString, File destination) + throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } } diff --git a/samples/standalone/restdocs/http-server/build.gradle b/samples/standalone/restdocs/http-server/build.gradle index 1a4ecdc980..794c87ae17 100644 --- a/samples/standalone/restdocs/http-server/build.gradle +++ b/samples/standalone/restdocs/http-server/build.gradle @@ -78,7 +78,7 @@ contracts { generateClientStubs.enabled = false task wrapper(type: Wrapper) { - gradleVersion = '4.10' + gradleVersion = '4.10' } task stubsJar(type: Jar, dependsOn: ['copySnippets', 'copySources', 'copyClasses']) { diff --git a/samples/standalone/restdocs/http-server/pom.xml b/samples/standalone/restdocs/http-server/pom.xml index 9ced7b9301..f5896c4318 100644 --- a/samples/standalone/restdocs/http-server/pom.xml +++ b/samples/standalone/restdocs/http-server/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 com.example @@ -14,14 +15,16 @@ org.springframework.boot spring-boot-starter-parent 2.1.2.RELEASE - + UTF-8 1.8 - 2.1.1.BUILD-SNAPSHOT - true + 2.1.1.BUILD-SNAPSHOT + + true + @@ -137,11 +140,13 @@ .*standalone.* - com.example.fraud.FraudBaseWithStandaloneSetup + com.example.fraud.FraudBaseWithStandaloneSetup + .*webapp.* - com.example.fraud.FraudBaseWithWebAppSetup + com.example.fraud.FraudBaseWithWebAppSetup + @@ -223,7 +228,9 @@ build install - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + @@ -254,7 +261,9 @@ build install - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + diff --git a/samples/standalone/restdocs/http-server/src/assembly/stub.xml b/samples/standalone/restdocs/http-server/src/assembly/stub.xml index b459d2a636..947f7d9aff 100644 --- a/samples/standalone/restdocs/http-server/src/assembly/stub.xml +++ b/samples/standalone/restdocs/http-server/src/assembly/stub.xml @@ -1,7 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd"> stubs jar @@ -24,7 +24,9 @@ ${project.build.directory}/snippets/stubs - META-INF/${project.groupId}/${project.artifactId}/${project.version}/mappings + + META-INF/${project.groupId}/${project.artifactId}/${project.version}/mappings + **/* @@ -37,4 +39,4 @@ - \ No newline at end of file + diff --git a/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/Application.java b/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/Application.java index 9117009b09..ef20bf067e 100644 --- a/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/Application.java +++ b/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/Application.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; import org.springframework.boot.SpringApplication; diff --git a/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/FraudDetectionController.java b/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/FraudDetectionController.java index 82ae6bee85..5f6a89a0f5 100644 --- a/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/FraudDetectionController.java +++ b/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/FraudDetectionController.java @@ -1,14 +1,30 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; -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 com.example.fraud.model.FraudCheck; import com.example.fraud.model.FraudCheckResult; import com.example.fraud.model.FraudCheckStatus; -import java.math.BigDecimal; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import static org.springframework.web.bind.annotation.RequestMethod.PUT; @@ -16,18 +32,17 @@ import static org.springframework.web.bind.annotation.RequestMethod.PUT; public class FraudDetectionController { private static final String FRAUD_SERVICE_JSON_VERSION_1 = "application/vnd.fraud.v1+json"; + private static final String NO_REASON = null; + private static final String AMOUNT_TOO_HIGH = "Amount too high"; + private static final BigDecimal MAX_AMOUNT = new BigDecimal("5000"); // tag::server_api[] - @RequestMapping( - value = "/fraudcheck", - method = PUT, - consumes = FRAUD_SERVICE_JSON_VERSION_1, - produces = FRAUD_SERVICE_JSON_VERSION_1) + @RequestMapping(value = "/fraudcheck", method = PUT, consumes = FRAUD_SERVICE_JSON_VERSION_1, produces = FRAUD_SERVICE_JSON_VERSION_1) public FraudCheckResult fraudCheck(@RequestBody FraudCheck fraudCheck) { - // end::server_api[] + // end::server_api[] // tag::new_impl[] if (amountGreaterThanThreshold(fraudCheck)) { return new FraudCheckResult(FraudCheckStatus.FRAUD, AMOUNT_TOO_HIGH); diff --git a/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/FraudDetectionXmlController.java b/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/FraudDetectionXmlController.java index afc1cd1073..b4b1f60811 100644 --- a/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/FraudDetectionXmlController.java +++ b/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/FraudDetectionXmlController.java @@ -1,8 +1,21 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; -import java.math.BigDecimal; - -import com.example.fraud.model.FraudCheck; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.util.StringUtils; @@ -11,16 +24,11 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import static org.springframework.web.bind.annotation.RequestMethod.POST; -import static org.springframework.web.bind.annotation.RequestMethod.PUT; @Controller public class FraudDetectionXmlController { - @RequestMapping( - value = "/xmlfraud", - method = POST, - consumes = MediaType.APPLICATION_XML_VALUE, - produces = MediaType.APPLICATION_XML_VALUE) + @RequestMapping(value = "/xmlfraud", method = POST, consumes = MediaType.APPLICATION_XML_VALUE, produces = MediaType.APPLICATION_XML_VALUE) @ResponseBody public XmlResponseBody xmlResponseBody(@RequestBody XmlRequestBody xmlRequestBody) { if (StringUtils.isEmpty(xmlRequestBody.name)) { @@ -32,10 +40,13 @@ public class FraudDetectionXmlController { } class XmlRequestBody { + public String name; + } class XmlResponseBody { + public String status; public XmlResponseBody(String status) { @@ -44,4 +55,5 @@ class XmlResponseBody { public XmlResponseBody() { } -} \ No newline at end of file + +} diff --git a/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/model/FraudCheck.java b/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/model/FraudCheck.java index b0210573e2..9ed18b12df 100644 --- a/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/model/FraudCheck.java +++ b/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/model/FraudCheck.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud.model; import java.math.BigDecimal; @@ -26,4 +42,5 @@ public class FraudCheck { public void setLoanAmount(BigDecimal loanAmount) { this.loanAmount = loanAmount; } + } diff --git a/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/model/FraudCheckResult.java b/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/model/FraudCheckResult.java index 60b340276a..9d9ab02c18 100644 --- a/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/model/FraudCheckResult.java +++ b/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/model/FraudCheckResult.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud.model; public class FraudCheckResult { @@ -29,4 +45,5 @@ public class FraudCheckResult { public void setRejectionReason(String rejectionReason) { this.rejectionReason = rejectionReason; } + } diff --git a/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/model/FraudCheckStatus.java b/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/model/FraudCheckStatus.java index 5a6adcf274..02d37adf46 100644 --- a/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/model/FraudCheckStatus.java +++ b/samples/standalone/restdocs/http-server/src/main/java/com/example/fraud/model/FraudCheckStatus.java @@ -1,5 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud.model; public enum FraudCheckStatus { + OK, FRAUD + } diff --git a/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/FraudBaseWithStandaloneSetup.java b/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/FraudBaseWithStandaloneSetup.java index 4484a09e8a..e17c8117c8 100644 --- a/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/FraudBaseWithStandaloneSetup.java +++ b/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/FraudBaseWithStandaloneSetup.java @@ -5,6 +5,7 @@ import io.restassured.module.mockmvc.RestAssuredMockMvc; import org.junit.Before; import org.junit.Rule; import org.junit.rules.TestName; + import org.springframework.restdocs.JUnitRestDocumentation; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -18,14 +19,17 @@ public abstract class FraudBaseWithStandaloneSetup { @Rule public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation(OUTPUT); - @Rule public TestName testName = new TestName(); + @Rule + public TestName testName = new TestName(); @Before public void setup() { - RestAssuredMockMvc.standaloneSetup(MockMvcBuilders.standaloneSetup(new FraudDetectionController()) + RestAssuredMockMvc.standaloneSetup(MockMvcBuilders + .standaloneSetup(new FraudDetectionController()) .apply(documentationConfiguration(this.restDocumentation)) - .alwaysDo(document(getClass().getSimpleName() + "_" + testName.getMethodName()))); + .alwaysDo(document( + getClass().getSimpleName() + "_" + testName.getMethodName()))); } } -// end::base_class[] \ No newline at end of file +// end::base_class[] diff --git a/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/FraudBaseWithWebAppSetup.java b/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/FraudBaseWithWebAppSetup.java index ffcf09ddad..40452325a0 100644 --- a/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/FraudBaseWithWebAppSetup.java +++ b/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/FraudBaseWithWebAppSetup.java @@ -2,7 +2,6 @@ package com.example.fraud; import io.restassured.module.mockmvc.RestAssuredMockMvc; - import org.junit.Before; import org.junit.Rule; import org.junit.rules.TestName; @@ -27,21 +26,24 @@ public abstract class FraudBaseWithWebAppSetup { @Rule public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation(OUTPUT); - @Rule public TestName testName = new TestName(); + @Rule + public TestName testName = new TestName(); @Autowired private WebApplicationContext context; @Before public void setup() { - RestAssuredMockMvc.mockMvc(MockMvcBuilders.webAppContextSetup(this.context) - .apply(documentationConfiguration(this.restDocumentation)) - .alwaysDo(document(getClass().getSimpleName() + "_" + testName.getMethodName())) - .build()); + RestAssuredMockMvc.mockMvc(MockMvcBuilders.webAppContextSetup(this.context) + .apply(documentationConfiguration(this.restDocumentation)) + .alwaysDo(document( + getClass().getSimpleName() + "_" + testName.getMethodName())) + .build()); } protected void assertThatRejectionReasonIsNull(Object rejectionReason) { assert rejectionReason == null; } + } -// end::base_class[] \ No newline at end of file +// end::base_class[] diff --git a/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/StubGeneratorTests.java b/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/StubGeneratorTests.java index 60cb3ab6f5..0ba6d84a54 100644 --- a/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/StubGeneratorTests.java +++ b/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/StubGeneratorTests.java @@ -1,10 +1,29 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; import java.math.BigDecimal; +import com.example.fraud.model.FraudCheck; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters; import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; @@ -16,9 +35,6 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import com.example.fraud.model.FraudCheck; -import com.fasterxml.jackson.databind.ObjectMapper; - import static org.springframework.cloud.contract.wiremock.restdocs.WireMockRestDocs.verify; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; @@ -73,4 +89,4 @@ public class StubGeneratorTests { .stub("markClientAsNotFraud")); } -} \ No newline at end of file +} diff --git a/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/XmlStubGeneratorTests.java b/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/XmlStubGeneratorTests.java index 1180334a06..9359ad2498 100644 --- a/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/XmlStubGeneratorTests.java +++ b/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/XmlStubGeneratorTests.java @@ -1,29 +1,35 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; -import java.math.BigDecimal; - -import com.example.fraud.model.FraudCheck; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters; import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.json.JacksonTester; import org.springframework.http.MediaType; import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; -import static org.springframework.cloud.contract.wiremock.restdocs.WireMockRestDocs.verify; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @RunWith(SpringRunner.class) @@ -37,22 +43,22 @@ public class XmlStubGeneratorTests { @Test public void should_return_full_content() throws Exception { - mockMvc.perform(post("/xmlfraud") - .contentType(MediaType.APPLICATION_XML) + mockMvc.perform(post("/xmlfraud").contentType(MediaType.APPLICATION_XML) .content("foo")) .andExpect(status().is2xxSuccessful()) - .andExpect(content().string("FULL")) + .andExpect(content().string( + "FULL")) .andDo(MockMvcRestDocumentation.document("{methodName}")); } @Test public void should_return_empty_content() throws Exception { - mockMvc.perform(post("/xmlfraud") - .contentType(MediaType.APPLICATION_XML) + mockMvc.perform(post("/xmlfraud").contentType(MediaType.APPLICATION_XML) .content("")) .andExpect(status().is2xxSuccessful()) - .andExpect(content().string("EMPTY")) + .andExpect(content().string( + "EMPTY")) .andDo(MockMvcRestDocumentation.document("{methodName}")); } -} \ No newline at end of file +} diff --git a/samples/standalone/restdocs/http-server/src/test/resources/contracts/standalone/shouldMarkClientAsFraud.groovy b/samples/standalone/restdocs/http-server/src/test/resources/contracts/standalone/shouldMarkClientAsFraud.groovy index 10fec1a686..8594b12ca6 100644 --- a/samples/standalone/restdocs/http-server/src/test/resources/contracts/standalone/shouldMarkClientAsFraud.groovy +++ b/samples/standalone/restdocs/http-server/src/test/resources/contracts/standalone/shouldMarkClientAsFraud.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.standalone org.springframework.cloud.contract.spec.Contract.make { @@ -5,7 +21,7 @@ org.springframework.cloud.contract.spec.Contract.make { method 'PUT' // (2) url '/fraudcheck' // (3) body([ // (4) - clientId: $(c(regex('[0-9]{10}')), p("8532032713")), + clientId : $(c(regex('[0-9]{10}')), p("8532032713")), loanAmount: 99999 ]) headers { // (5) @@ -16,7 +32,7 @@ org.springframework.cloud.contract.spec.Contract.make { status OK() // (7) body([ // (8) fraudCheckStatus: "FRAUD", - rejectionReason: "Amount too high" + rejectionReason : "Amount too high" ]) headers { // (9) contentType('application/vnd.fraud.v1+json') @@ -63,4 +79,4 @@ From the Producer perspective, in the autogenerated producer-side test: (8) - and JSON body equal to { "fraudCheckStatus": "FRAUD", "rejectionReason": "Amount too high" } (9) - with header `Content-Type` matching `application/vnd.fraud.v1+json.*` - */ \ No newline at end of file + */ diff --git a/samples/standalone/restdocs/http-server/src/test/resources/contracts/webapp/shouldMarkClientAsNotFraud.groovy b/samples/standalone/restdocs/http-server/src/test/resources/contracts/webapp/shouldMarkClientAsNotFraud.groovy index e2ad1731c8..9104fa19ad 100644 --- a/samples/standalone/restdocs/http-server/src/test/resources/contracts/webapp/shouldMarkClientAsNotFraud.groovy +++ b/samples/standalone/restdocs/http-server/src/test/resources/contracts/webapp/shouldMarkClientAsNotFraud.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.webapp org.springframework.cloud.contract.spec.Contract.make { @@ -20,7 +36,8 @@ org.springframework.cloud.contract.spec.Contract.make { status OK() body( fraudCheckStatus: "OK", - rejectionReason: $(consumer(null), producer(execute('assertThatRejectionReasonIsNull($it)'))) + rejectionReason: $(consumer(null), + producer(execute('assertThatRejectionReasonIsNull($it)'))) ) headers { contentType("application/vnd.fraud.v1+json") diff --git a/samples/standalone/restdocs/pom.xml b/samples/standalone/restdocs/pom.xml index fbbb99a185..334f651121 100644 --- a/samples/standalone/restdocs/pom.xml +++ b/samples/standalone/restdocs/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 @@ -14,10 +15,12 @@ pom Spring Cloud Contract Standalone Restdocs Test Samples - Spring Cloud Contract Standalone Test Samples used for end to end tests + Spring Cloud Contract Standalone Test Samples used for end to end tests + - 2.1.1.BUILD-SNAPSHOT + 2.1.1.BUILD-SNAPSHOT + diff --git a/samples/standalone/settings.gradle b/samples/standalone/settings.gradle index 118d8adddd..bd57d7d432 100644 --- a/samples/standalone/settings.gradle +++ b/samples/standalone/settings.gradle @@ -1,4 +1,4 @@ include 'contract-verifier-sample-stream-sink', 'contract-verifier-sample-stream-source', 'http-client', - 'http-server' \ No newline at end of file + 'http-server' diff --git a/samples/standalone/webclient/http-client/.mvn/wrapper/MavenWrapperDownloader.java b/samples/standalone/webclient/http-client/.mvn/wrapper/MavenWrapperDownloader.java index d475a89ce1..44f295e331 100755 --- a/samples/standalone/webclient/http-client/.mvn/wrapper/MavenWrapperDownloader.java +++ b/samples/standalone/webclient/http-client/.mvn/wrapper/MavenWrapperDownloader.java @@ -1,3 +1,4 @@ + /* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -17,94 +18,100 @@ specific language governing permissions and limitations under the License. */ -import java.net.*; -import java.io.*; -import java.nio.channels.*; import java.util.Properties; public class MavenWrapperDownloader { - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = - "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is + * provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to - * use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = - ".mvn/wrapper/maven-wrapper.properties"; + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl + * property to use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = ".mvn/wrapper/maven-wrapper.properties"; - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = - ".mvn/wrapper/maven-wrapper.jar"; + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar"; - /** - * Name of the property which should be used to override the default download url for the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + /** + * Name of the property which should be used to override the default download url for + * the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - // If the maven-wrapper.properties exists, read it and check if it contains a custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } finally { - try { - if(mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: : " + url); + // If the maven-wrapper.properties exists, read it and check if it contains a + // custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, + MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if (mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream( + mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } + catch (IOException e) { + System.out.println( + "- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } + finally { + try { + if (mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } + catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { - System.out.println( - "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } + File outputFile = new File(baseDirectory.getAbsolutePath(), + MAVEN_WRAPPER_JAR_PATH); + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { + System.out.println("- ERROR creating output direcrory '" + + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } + catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } - private static void downloadFileFromURL(String urlString, File destination) throws Exception { - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } + private static void downloadFileFromURL(String urlString, File destination) + throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } } diff --git a/samples/standalone/webclient/http-client/pom.xml b/samples/standalone/webclient/http-client/pom.xml index 69b4fcc7d3..1198096cbf 100644 --- a/samples/standalone/webclient/http-client/pom.xml +++ b/samples/standalone/webclient/http-client/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 com.example @@ -14,13 +15,14 @@ org.springframework.boot spring-boot-starter-parent 2.1.2.RELEASE - + UTF-8 1.8 - 2.1.1.BUILD-SNAPSHOT + 2.1.1.BUILD-SNAPSHOT + @@ -181,7 +183,9 @@ clean build publishToMavenLocal - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + @@ -211,7 +215,9 @@ clean build publishToMavenLocal - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + diff --git a/samples/standalone/webclient/http-client/src/main/java/com/example/loan/Application.java b/samples/standalone/webclient/http-client/src/main/java/com/example/loan/Application.java index 6f36301172..ca4e1a4767 100644 --- a/samples/standalone/webclient/http-client/src/main/java/com/example/loan/Application.java +++ b/samples/standalone/webclient/http-client/src/main/java/com/example/loan/Application.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan; import org.springframework.boot.SpringApplication; diff --git a/samples/standalone/webclient/http-client/src/main/java/com/example/loan/LoanApplicationService.java b/samples/standalone/webclient/http-client/src/main/java/com/example/loan/LoanApplicationService.java index de64180aad..f3e67ef1bf 100644 --- a/samples/standalone/webclient/http-client/src/main/java/com/example/loan/LoanApplicationService.java +++ b/samples/standalone/webclient/http-client/src/main/java/com/example/loan/LoanApplicationService.java @@ -1,5 +1,28 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan; +import com.example.loan.model.FraudCheckStatus; +import com.example.loan.model.FraudServiceRequest; +import com.example.loan.model.FraudServiceResponse; +import com.example.loan.model.LoanApplication; +import com.example.loan.model.LoanApplicationResult; +import com.example.loan.model.LoanApplicationStatus; + import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -8,19 +31,11 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; -import com.example.loan.model.FraudCheckStatus; -import com.example.loan.model.FraudServiceRequest; -import com.example.loan.model.FraudServiceResponse; -import com.example.loan.model.LoanApplication; -import com.example.loan.model.LoanApplicationResult; -import com.example.loan.model.LoanApplicationStatus; - @Service @ConfigurationProperties("service") public class LoanApplicationService { - private static final String FRAUD_SERVICE_JSON_VERSION_1 = - "application/vnd.fraud.v1+json"; + private static final String FRAUD_SERVICE_JSON_VERSION_1 = "application/vnd.fraud.v1+json"; private final RestTemplate restTemplate; @@ -31,11 +46,9 @@ public class LoanApplicationService { } public LoanApplicationResult loanApplication(LoanApplication loanApplication) { - FraudServiceRequest request = - new FraudServiceRequest(loanApplication); + FraudServiceRequest request = new FraudServiceRequest(loanApplication); - FraudServiceResponse response = - sendRequestToFraudDetectionService(request); + FraudServiceResponse response = sendRequestToFraudDetectionService(request); return buildResponseFromFraudResult(response); } @@ -46,24 +59,26 @@ public class LoanApplicationService { httpHeaders.add(HttpHeaders.CONTENT_TYPE, FRAUD_SERVICE_JSON_VERSION_1); // tag::client_call_server[] - ResponseEntity response = - this.restTemplate.exchange("http://localhost:" + this.port + "/fraudcheck", HttpMethod.PUT, - new HttpEntity<>(request, httpHeaders), - FraudServiceResponse.class); + ResponseEntity response = this.restTemplate.exchange( + "http://localhost:" + this.port + "/fraudcheck", HttpMethod.PUT, + new HttpEntity<>(request, httpHeaders), FraudServiceResponse.class); // end::client_call_server[] return response.getBody(); } - private LoanApplicationResult buildResponseFromFraudResult(FraudServiceResponse response) { + private LoanApplicationResult buildResponseFromFraudResult( + FraudServiceResponse response) { LoanApplicationStatus applicationStatus = null; if (FraudCheckStatus.OK == response.getFraudCheckStatus()) { applicationStatus = LoanApplicationStatus.LOAN_APPLIED; - } else if (FraudCheckStatus.FRAUD == response.getFraudCheckStatus()) { + } + else if (FraudCheckStatus.FRAUD == response.getFraudCheckStatus()) { applicationStatus = LoanApplicationStatus.LOAN_APPLICATION_REJECTED; } - return new LoanApplicationResult(applicationStatus, response.getRejectionReason()); + return new LoanApplicationResult(applicationStatus, + response.getRejectionReason()); } public void setPort(int port) { diff --git a/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/Client.java b/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/Client.java index 73e6824cff..6f9cb364a6 100644 --- a/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/Client.java +++ b/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/Client.java @@ -1,9 +1,25 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public class Client { private String pesel; - + public Client() { } @@ -18,4 +34,5 @@ public class Client { public void setPesel(String pesel) { this.pesel = pesel; } + } diff --git a/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/FraudCheckStatus.java b/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/FraudCheckStatus.java index c5217ef471..762692e74a 100644 --- a/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/FraudCheckStatus.java +++ b/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/FraudCheckStatus.java @@ -1,5 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public enum FraudCheckStatus { + OK, FRAUD + } diff --git a/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/FraudServiceRequest.java b/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/FraudServiceRequest.java index 0a96a1cb48..b7c1c20933 100644 --- a/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/FraudServiceRequest.java +++ b/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/FraudServiceRequest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; import java.math.BigDecimal; @@ -31,4 +47,5 @@ public class FraudServiceRequest { public void setLoanAmount(BigDecimal loanAmount) { this.loanAmount = loanAmount; } + } diff --git a/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/FraudServiceResponse.java b/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/FraudServiceResponse.java index eb5f64116d..9d7f4002f2 100644 --- a/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/FraudServiceResponse.java +++ b/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/FraudServiceResponse.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public class FraudServiceResponse { @@ -24,4 +40,5 @@ public class FraudServiceResponse { public void setRejectionReason(String rejectionReason) { this.rejectionReason = rejectionReason; } + } diff --git a/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/LoanApplication.java b/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/LoanApplication.java index 85a7f8c5d9..5abb21c108 100644 --- a/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/LoanApplication.java +++ b/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/LoanApplication.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; import java.math.BigDecimal; @@ -41,4 +57,5 @@ public class LoanApplication { public void setLoanApplicationId(String loanApplicationId) { this.loanApplicationId = loanApplicationId; } + } diff --git a/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/LoanApplicationResult.java b/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/LoanApplicationResult.java index 5214e0d4f7..102c6d704f 100644 --- a/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/LoanApplicationResult.java +++ b/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/LoanApplicationResult.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public class LoanApplicationResult { @@ -9,7 +25,8 @@ public class LoanApplicationResult { public LoanApplicationResult() { } - public LoanApplicationResult(LoanApplicationStatus loanApplicationStatus, String rejectionReason) { + public LoanApplicationResult(LoanApplicationStatus loanApplicationStatus, + String rejectionReason) { this.loanApplicationStatus = loanApplicationStatus; this.rejectionReason = rejectionReason; } @@ -29,4 +46,5 @@ public class LoanApplicationResult { public void setRejectionReason(String rejectionReason) { this.rejectionReason = rejectionReason; } + } diff --git a/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/LoanApplicationStatus.java b/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/LoanApplicationStatus.java index 34cf91a89f..b5c85900d3 100644 --- a/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/LoanApplicationStatus.java +++ b/samples/standalone/webclient/http-client/src/main/java/com/example/loan/model/LoanApplicationStatus.java @@ -1,5 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public enum LoanApplicationStatus { + LOAN_APPLIED, LOAN_APPLICATION_REJECTED + } diff --git a/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java b/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java index d5490755cd..ec13928a10 100644 --- a/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java +++ b/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java @@ -1,11 +1,32 @@ -package com.example.loan; +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 static org.assertj.core.api.Assertions.assertThat; +package com.example.loan; import java.nio.charset.Charset; +import com.example.loan.model.Client; +import com.example.loan.model.LoanApplication; +import com.example.loan.model.LoanApplicationResult; +import com.example.loan.model.LoanApplicationStatus; +import com.github.tomakehurst.wiremock.WireMockServer; +import com.github.tomakehurst.wiremock.stubbing.StubMapping; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; @@ -14,16 +35,11 @@ import org.springframework.core.io.Resource; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.StreamUtils; -import com.example.loan.model.Client; -import com.example.loan.model.LoanApplication; -import com.example.loan.model.LoanApplicationResult; -import com.example.loan.model.LoanApplicationStatus; -import com.github.tomakehurst.wiremock.WireMockServer; -import com.github.tomakehurst.wiremock.stubbing.StubMapping; +import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@SpringBootTest(properties="service.port=${wiremock.server.port}") -@AutoConfigureWireMock(port=0) +@SpringBootTest(properties = "service.port=${wiremock.server.port}") +@AutoConfigureWireMock(port = 0) public class LoanApplicationServiceTests { @Autowired diff --git a/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerGradleTests.java b/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerGradleTests.java index 96adc89152..ff30e31569 100644 --- a/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerGradleTests.java +++ b/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerGradleTests.java @@ -1,13 +1,29 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan; import com.example.loan.model.Client; import com.example.loan.model.LoanApplication; import com.example.loan.model.LoanApplicationResult; import com.example.loan.model.LoanApplicationStatus; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; @@ -21,8 +37,11 @@ import static org.assertj.core.api.Assertions.assertThat; @AutoConfigureStubRunner(ids = "com.example:http-server-webclient-gradle") public class LoanApplicationServiceusingStubRunnerGradleTests { - @Autowired LoanApplicationService service; - @Value("${stubrunner.runningstubs.http-server-webclient-gradle.port}") int port; + @Autowired + LoanApplicationService service; + + @Value("${stubrunner.runningstubs.http-server-webclient-gradle.port}") + int port; @Before public void setup() { diff --git a/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerTests.java b/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerTests.java index 111b569944..36199facfe 100644 --- a/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerTests.java +++ b/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerTests.java @@ -1,13 +1,29 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan; import com.example.loan.model.Client; import com.example.loan.model.LoanApplication; import com.example.loan.model.LoanApplicationResult; import com.example.loan.model.LoanApplicationStatus; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; @@ -21,8 +37,11 @@ import static org.assertj.core.api.Assertions.assertThat; @AutoConfigureStubRunner(ids = "com.example:http-server-webclient") public class LoanApplicationServiceusingStubRunnerTests { - @Autowired LoanApplicationService service; - @Value("${stubrunner.runningstubs.http-server-webclient.port}") int port; + @Autowired + LoanApplicationService service; + + @Value("${stubrunner.runningstubs.http-server-webclient.port}") + int port; @Before public void setup() { diff --git a/samples/standalone/webclient/http-client/src/test/resources/application-gradle.yaml b/samples/standalone/webclient/http-client/src/test/resources/application-gradle.yaml index e10e7190ed..ba78f20e68 100644 --- a/samples/standalone/webclient/http-client/src/test/resources/application-gradle.yaml +++ b/samples/standalone/webclient/http-client/src/test/resources/application-gradle.yaml @@ -1,2 +1,2 @@ stubrunner: - stubs.ids: 'com.example:http-server-webclient-gradle' \ No newline at end of file + stubs.ids: 'com.example:http-server-webclient-gradle' diff --git a/samples/standalone/webclient/http-server/.mvn/wrapper/MavenWrapperDownloader.java b/samples/standalone/webclient/http-server/.mvn/wrapper/MavenWrapperDownloader.java index d475a89ce1..44f295e331 100755 --- a/samples/standalone/webclient/http-server/.mvn/wrapper/MavenWrapperDownloader.java +++ b/samples/standalone/webclient/http-server/.mvn/wrapper/MavenWrapperDownloader.java @@ -1,3 +1,4 @@ + /* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -17,94 +18,100 @@ specific language governing permissions and limitations under the License. */ -import java.net.*; -import java.io.*; -import java.nio.channels.*; import java.util.Properties; public class MavenWrapperDownloader { - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = - "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is + * provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to - * use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = - ".mvn/wrapper/maven-wrapper.properties"; + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl + * property to use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = ".mvn/wrapper/maven-wrapper.properties"; - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = - ".mvn/wrapper/maven-wrapper.jar"; + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar"; - /** - * Name of the property which should be used to override the default download url for the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + /** + * Name of the property which should be used to override the default download url for + * the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - // If the maven-wrapper.properties exists, read it and check if it contains a custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } finally { - try { - if(mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: : " + url); + // If the maven-wrapper.properties exists, read it and check if it contains a + // custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, + MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if (mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream( + mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } + catch (IOException e) { + System.out.println( + "- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } + finally { + try { + if (mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } + catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { - System.out.println( - "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } + File outputFile = new File(baseDirectory.getAbsolutePath(), + MAVEN_WRAPPER_JAR_PATH); + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { + System.out.println("- ERROR creating output direcrory '" + + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } + catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } - private static void downloadFileFromURL(String urlString, File destination) throws Exception { - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } + private static void downloadFileFromURL(String urlString, File destination) + throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } } diff --git a/samples/standalone/webclient/http-server/pom.xml b/samples/standalone/webclient/http-server/pom.xml index 34f7eb69e3..48381dac5d 100644 --- a/samples/standalone/webclient/http-server/pom.xml +++ b/samples/standalone/webclient/http-server/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 com.example @@ -14,13 +15,14 @@ org.springframework.boot spring-boot-starter-parent 2.1.2.RELEASE - + UTF-8 1.8 - 2.1.1.BUILD-SNAPSHOT + 2.1.1.BUILD-SNAPSHOT + @@ -191,7 +193,9 @@ build install - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + @@ -222,7 +226,9 @@ build install - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + diff --git a/samples/standalone/webclient/http-server/src/assembly/stub.xml b/samples/standalone/webclient/http-server/src/assembly/stub.xml index 914f265c70..118b211809 100644 --- a/samples/standalone/webclient/http-server/src/assembly/stub.xml +++ b/samples/standalone/webclient/http-server/src/assembly/stub.xml @@ -1,7 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd"> stubs jar @@ -24,10 +24,12 @@ ${project.build.directory}/snippets/stubs - META-INF/${project.groupId}/${project.artifactId}/${project.version}/mappings + + META-INF/${project.groupId}/${project.artifactId}/${project.version}/mappings + **/* - \ No newline at end of file + diff --git a/samples/standalone/webclient/http-server/src/main/java/com/example/fraud/Application.java b/samples/standalone/webclient/http-server/src/main/java/com/example/fraud/Application.java index 9117009b09..ef20bf067e 100644 --- a/samples/standalone/webclient/http-server/src/main/java/com/example/fraud/Application.java +++ b/samples/standalone/webclient/http-server/src/main/java/com/example/fraud/Application.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; import org.springframework.boot.SpringApplication; diff --git a/samples/standalone/webclient/http-server/src/main/java/com/example/fraud/FraudDetectionController.java b/samples/standalone/webclient/http-server/src/main/java/com/example/fraud/FraudDetectionController.java index 82ae6bee85..5f6a89a0f5 100644 --- a/samples/standalone/webclient/http-server/src/main/java/com/example/fraud/FraudDetectionController.java +++ b/samples/standalone/webclient/http-server/src/main/java/com/example/fraud/FraudDetectionController.java @@ -1,14 +1,30 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; -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 com.example.fraud.model.FraudCheck; import com.example.fraud.model.FraudCheckResult; import com.example.fraud.model.FraudCheckStatus; -import java.math.BigDecimal; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import static org.springframework.web.bind.annotation.RequestMethod.PUT; @@ -16,18 +32,17 @@ import static org.springframework.web.bind.annotation.RequestMethod.PUT; public class FraudDetectionController { private static final String FRAUD_SERVICE_JSON_VERSION_1 = "application/vnd.fraud.v1+json"; + private static final String NO_REASON = null; + private static final String AMOUNT_TOO_HIGH = "Amount too high"; + private static final BigDecimal MAX_AMOUNT = new BigDecimal("5000"); // tag::server_api[] - @RequestMapping( - value = "/fraudcheck", - method = PUT, - consumes = FRAUD_SERVICE_JSON_VERSION_1, - produces = FRAUD_SERVICE_JSON_VERSION_1) + @RequestMapping(value = "/fraudcheck", method = PUT, consumes = FRAUD_SERVICE_JSON_VERSION_1, produces = FRAUD_SERVICE_JSON_VERSION_1) public FraudCheckResult fraudCheck(@RequestBody FraudCheck fraudCheck) { - // end::server_api[] + // end::server_api[] // tag::new_impl[] if (amountGreaterThanThreshold(fraudCheck)) { return new FraudCheckResult(FraudCheckStatus.FRAUD, AMOUNT_TOO_HIGH); diff --git a/samples/standalone/webclient/http-server/src/main/java/com/example/fraud/model/FraudCheck.java b/samples/standalone/webclient/http-server/src/main/java/com/example/fraud/model/FraudCheck.java index b0210573e2..9ed18b12df 100644 --- a/samples/standalone/webclient/http-server/src/main/java/com/example/fraud/model/FraudCheck.java +++ b/samples/standalone/webclient/http-server/src/main/java/com/example/fraud/model/FraudCheck.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud.model; import java.math.BigDecimal; @@ -26,4 +42,5 @@ public class FraudCheck { public void setLoanAmount(BigDecimal loanAmount) { this.loanAmount = loanAmount; } + } diff --git a/samples/standalone/webclient/http-server/src/main/java/com/example/fraud/model/FraudCheckResult.java b/samples/standalone/webclient/http-server/src/main/java/com/example/fraud/model/FraudCheckResult.java index 60b340276a..9d9ab02c18 100644 --- a/samples/standalone/webclient/http-server/src/main/java/com/example/fraud/model/FraudCheckResult.java +++ b/samples/standalone/webclient/http-server/src/main/java/com/example/fraud/model/FraudCheckResult.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud.model; public class FraudCheckResult { @@ -29,4 +45,5 @@ public class FraudCheckResult { public void setRejectionReason(String rejectionReason) { this.rejectionReason = rejectionReason; } + } diff --git a/samples/standalone/webclient/http-server/src/main/java/com/example/fraud/model/FraudCheckStatus.java b/samples/standalone/webclient/http-server/src/main/java/com/example/fraud/model/FraudCheckStatus.java index 5a6adcf274..02d37adf46 100644 --- a/samples/standalone/webclient/http-server/src/main/java/com/example/fraud/model/FraudCheckStatus.java +++ b/samples/standalone/webclient/http-server/src/main/java/com/example/fraud/model/FraudCheckStatus.java @@ -1,5 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud.model; public enum FraudCheckStatus { + OK, FRAUD + } diff --git a/samples/standalone/webclient/http-server/src/test/java/com/example/fraud/StubGeneratorTests.java b/samples/standalone/webclient/http-server/src/test/java/com/example/fraud/StubGeneratorTests.java index 57debe95cc..7a3fce8bec 100644 --- a/samples/standalone/webclient/http-server/src/test/java/com/example/fraud/StubGeneratorTests.java +++ b/samples/standalone/webclient/http-server/src/test/java/com/example/fraud/StubGeneratorTests.java @@ -1,10 +1,25 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; import java.math.BigDecimal; import com.example.fraud.model.FraudCheck; import com.fasterxml.jackson.databind.ObjectMapper; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -56,7 +71,8 @@ public class StubGeneratorTests { .jsonPath("$[?(@.loanAmount > 1000)]") .contentType(MediaType.valueOf("application/vnd.fraud.v1+json")) .stub("markClientAsFraud")) - .consumeWith(WebTestClientRestDocumentation.document("markClientAsFraud")); + .consumeWith( + WebTestClientRestDocumentation.document("markClientAsFraud")); } @Test @@ -73,7 +89,8 @@ public class StubGeneratorTests { .jsonPath("$[?(@.loanAmount <= 1000)]") .contentType(MediaType.valueOf("application/vnd.fraud.v1+json")) .stub("markClientAsNotFraud")) - .consumeWith(WebTestClientRestDocumentation.document("markClientAsNotFraud")); + .consumeWith( + WebTestClientRestDocumentation.document("markClientAsNotFraud")); } -} \ No newline at end of file +} diff --git a/samples/standalone/webclient/pom.xml b/samples/standalone/webclient/pom.xml index 683b52d9a0..ccec8944ef 100644 --- a/samples/standalone/webclient/pom.xml +++ b/samples/standalone/webclient/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 @@ -14,10 +15,12 @@ pom Spring Cloud Contract Standalone Restdocs Test Samples - Spring Cloud Contract Standalone Test Samples used for end to end tests + Spring Cloud Contract Standalone Test Samples used for end to end tests + - 2.1.1.BUILD-SNAPSHOT + 2.1.1.BUILD-SNAPSHOT + diff --git a/samples/standalone/yml/http-client/.mvn/wrapper/MavenWrapperDownloader.java b/samples/standalone/yml/http-client/.mvn/wrapper/MavenWrapperDownloader.java index d475a89ce1..44f295e331 100755 --- a/samples/standalone/yml/http-client/.mvn/wrapper/MavenWrapperDownloader.java +++ b/samples/standalone/yml/http-client/.mvn/wrapper/MavenWrapperDownloader.java @@ -1,3 +1,4 @@ + /* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -17,94 +18,100 @@ specific language governing permissions and limitations under the License. */ -import java.net.*; -import java.io.*; -import java.nio.channels.*; import java.util.Properties; public class MavenWrapperDownloader { - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = - "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is + * provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to - * use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = - ".mvn/wrapper/maven-wrapper.properties"; + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl + * property to use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = ".mvn/wrapper/maven-wrapper.properties"; - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = - ".mvn/wrapper/maven-wrapper.jar"; + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar"; - /** - * Name of the property which should be used to override the default download url for the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + /** + * Name of the property which should be used to override the default download url for + * the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - // If the maven-wrapper.properties exists, read it and check if it contains a custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } finally { - try { - if(mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: : " + url); + // If the maven-wrapper.properties exists, read it and check if it contains a + // custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, + MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if (mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream( + mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } + catch (IOException e) { + System.out.println( + "- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } + finally { + try { + if (mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } + catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { - System.out.println( - "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } + File outputFile = new File(baseDirectory.getAbsolutePath(), + MAVEN_WRAPPER_JAR_PATH); + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { + System.out.println("- ERROR creating output direcrory '" + + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } + catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } - private static void downloadFileFromURL(String urlString, File destination) throws Exception { - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } + private static void downloadFileFromURL(String urlString, File destination) + throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } } diff --git a/samples/standalone/yml/http-client/build.gradle b/samples/standalone/yml/http-client/build.gradle index 43a64b7db1..6e488c206b 100644 --- a/samples/standalone/yml/http-client/build.gradle +++ b/samples/standalone/yml/http-client/build.gradle @@ -56,7 +56,7 @@ test { } task wrapper(type: Wrapper) { - gradleVersion = '4.10' + gradleVersion = '4.10' } task resolveDependencies { diff --git a/samples/standalone/yml/http-client/pom.xml b/samples/standalone/yml/http-client/pom.xml index a0623d55bb..0918db4e01 100644 --- a/samples/standalone/yml/http-client/pom.xml +++ b/samples/standalone/yml/http-client/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 com.example @@ -14,13 +15,14 @@ org.springframework.boot spring-boot-starter-parent 2.1.2.RELEASE - + UTF-8 1.8 - Greenwich.BUILD-SNAPSHOT + Greenwich.BUILD-SNAPSHOT + @@ -169,7 +171,9 @@ clean build publishToMavenLocal - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + @@ -199,7 +203,9 @@ clean build publishToMavenLocal - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + diff --git a/samples/standalone/yml/http-client/src/main/java/com/example/loan/Application.java b/samples/standalone/yml/http-client/src/main/java/com/example/loan/Application.java index 6f36301172..ca4e1a4767 100644 --- a/samples/standalone/yml/http-client/src/main/java/com/example/loan/Application.java +++ b/samples/standalone/yml/http-client/src/main/java/com/example/loan/Application.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan; import org.springframework.boot.SpringApplication; diff --git a/samples/standalone/yml/http-client/src/main/java/com/example/loan/LoanApplicationService.java b/samples/standalone/yml/http-client/src/main/java/com/example/loan/LoanApplicationService.java index dea320a9c7..d6f10baac6 100644 --- a/samples/standalone/yml/http-client/src/main/java/com/example/loan/LoanApplicationService.java +++ b/samples/standalone/yml/http-client/src/main/java/com/example/loan/LoanApplicationService.java @@ -1,5 +1,29 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan; +import com.example.loan.model.FraudCheckStatus; +import com.example.loan.model.FraudServiceRequest; +import com.example.loan.model.FraudServiceResponse; +import com.example.loan.model.LoanApplication; +import com.example.loan.model.LoanApplicationResult; +import com.example.loan.model.LoanApplicationStatus; +import com.example.loan.model.Response; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.http.HttpEntity; @@ -10,14 +34,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; -import com.example.loan.model.FraudCheckStatus; -import com.example.loan.model.FraudServiceRequest; -import com.example.loan.model.FraudServiceResponse; -import com.example.loan.model.LoanApplication; -import com.example.loan.model.LoanApplicationResult; -import com.example.loan.model.LoanApplicationStatus; -import com.example.loan.model.Response; - @Service public class LoanApplicationService { @@ -31,11 +47,9 @@ public class LoanApplicationService { } public LoanApplicationResult loanApplication(LoanApplication loanApplication) { - FraudServiceRequest request = - new FraudServiceRequest(loanApplication); + FraudServiceRequest request = new FraudServiceRequest(loanApplication); - FraudServiceResponse response = - sendRequestToFraudDetectionService(request); + FraudServiceResponse response = sendRequestToFraudDetectionService(request); return buildResponseFromFraudResult(response); } @@ -46,43 +60,43 @@ public class LoanApplicationService { httpHeaders.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); // tag::client_call_server[] - ResponseEntity response = - restTemplate.exchange("http://localhost:" + port + "/fraudcheck", HttpMethod.PUT, - new HttpEntity<>(request, httpHeaders), - FraudServiceResponse.class); + ResponseEntity response = restTemplate.exchange( + "http://localhost:" + port + "/fraudcheck", HttpMethod.PUT, + new HttpEntity<>(request, httpHeaders), FraudServiceResponse.class); // end::client_call_server[] return response.getBody(); } - private LoanApplicationResult buildResponseFromFraudResult(FraudServiceResponse response) { + private LoanApplicationResult buildResponseFromFraudResult( + FraudServiceResponse response) { LoanApplicationStatus applicationStatus = null; if (FraudCheckStatus.OK == response.getFraudCheckStatus()) { applicationStatus = LoanApplicationStatus.LOAN_APPLIED; - } else if (FraudCheckStatus.FRAUD == response.getFraudCheckStatus()) { + } + else if (FraudCheckStatus.FRAUD == response.getFraudCheckStatus()) { applicationStatus = LoanApplicationStatus.LOAN_APPLICATION_REJECTED; } - return new LoanApplicationResult(applicationStatus, response.getRejectionReason()); + return new LoanApplicationResult(applicationStatus, + response.getRejectionReason()); } public int countAllFrauds() { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); - ResponseEntity response = - restTemplate.exchange("http://localhost:" + port + "/frauds", HttpMethod.GET, - new HttpEntity<>(httpHeaders), - Response.class); + ResponseEntity response = restTemplate.exchange( + "http://localhost:" + port + "/frauds", HttpMethod.GET, + new HttpEntity<>(httpHeaders), Response.class); return response.getBody().getCount(); } public int countDrunks() { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); - ResponseEntity response = - restTemplate.exchange("http://localhost:" + port + "/drunks", HttpMethod.GET, - new HttpEntity<>(httpHeaders), - Response.class); + ResponseEntity response = restTemplate.exchange( + "http://localhost:" + port + "/drunks", HttpMethod.GET, + new HttpEntity<>(httpHeaders), Response.class); return response.getBody().getCount(); } diff --git a/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/Client.java b/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/Client.java index abf66106b5..4c197f9a4e 100644 --- a/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/Client.java +++ b/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/Client.java @@ -1,9 +1,25 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public class Client { private String pesel; - + public Client() { } @@ -18,4 +34,5 @@ public class Client { public void setPesel(String pesel) { this.pesel = pesel; } + } diff --git a/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/FraudCheckStatus.java b/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/FraudCheckStatus.java index c5217ef471..762692e74a 100644 --- a/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/FraudCheckStatus.java +++ b/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/FraudCheckStatus.java @@ -1,5 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public enum FraudCheckStatus { + OK, FRAUD + } diff --git a/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/FraudServiceRequest.java b/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/FraudServiceRequest.java index 5cc40027bb..55fb7875f6 100644 --- a/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/FraudServiceRequest.java +++ b/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/FraudServiceRequest.java @@ -1,9 +1,25 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; -import com.fasterxml.jackson.annotation.JsonProperty; - import java.math.BigDecimal; +import com.fasterxml.jackson.annotation.JsonProperty; + public class FraudServiceRequest { @JsonProperty("client.id") @@ -34,4 +50,5 @@ public class FraudServiceRequest { public void setLoanAmount(BigDecimal loanAmount) { this.loanAmount = loanAmount; } + } diff --git a/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/FraudServiceResponse.java b/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/FraudServiceResponse.java index af58a03223..81d3864cab 100644 --- a/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/FraudServiceResponse.java +++ b/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/FraudServiceResponse.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; import com.fasterxml.jackson.annotation.JsonProperty; @@ -27,4 +43,5 @@ public class FraudServiceResponse { public void setRejectionReason(String rejectionReason) { this.rejectionReason = rejectionReason; } + } diff --git a/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/LoanApplication.java b/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/LoanApplication.java index 27d66f884c..e0cd87ec51 100644 --- a/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/LoanApplication.java +++ b/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/LoanApplication.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; import java.math.BigDecimal; @@ -41,4 +57,5 @@ public class LoanApplication { public void setLoanApplicationId(String loanApplicationId) { this.loanApplicationId = loanApplicationId; } + } diff --git a/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/LoanApplicationResult.java b/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/LoanApplicationResult.java index ffd44e1a26..44ea77ebce 100644 --- a/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/LoanApplicationResult.java +++ b/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/LoanApplicationResult.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public class LoanApplicationResult { @@ -9,7 +25,8 @@ public class LoanApplicationResult { public LoanApplicationResult() { } - public LoanApplicationResult(LoanApplicationStatus loanApplicationStatus, String rejectionReason) { + public LoanApplicationResult(LoanApplicationStatus loanApplicationStatus, + String rejectionReason) { this.loanApplicationStatus = loanApplicationStatus; this.rejectionReason = rejectionReason; } @@ -29,4 +46,5 @@ public class LoanApplicationResult { public void setRejectionReason(String rejectionReason) { this.rejectionReason = rejectionReason; } + } diff --git a/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/LoanApplicationStatus.java b/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/LoanApplicationStatus.java index 34cf91a89f..b5c85900d3 100644 --- a/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/LoanApplicationStatus.java +++ b/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/LoanApplicationStatus.java @@ -1,5 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public enum LoanApplicationStatus { + LOAN_APPLIED, LOAN_APPLICATION_REJECTED + } diff --git a/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/Response.java b/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/Response.java index 8335ee0cc6..d43a4cf298 100644 --- a/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/Response.java +++ b/samples/standalone/yml/http-client/src/main/java/com/example/loan/model/Response.java @@ -1,6 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan.model; public class Response { + private int count; public Response(int count) { @@ -17,4 +34,5 @@ public class Response { public void setCount(int count) { this.count = count; } -} \ No newline at end of file + +} diff --git a/samples/standalone/yml/http-client/src/test/java/com/example/loan/LoanApplicationServiceContextPathTests.java b/samples/standalone/yml/http-client/src/test/java/com/example/loan/LoanApplicationServiceContextPathTests.java index e418990149..36202a54af 100644 --- a/samples/standalone/yml/http-client/src/test/java/com/example/loan/LoanApplicationServiceContextPathTests.java +++ b/samples/standalone/yml/http-client/src/test/java/com/example/loan/LoanApplicationServiceContextPathTests.java @@ -1,9 +1,28 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan; -import static org.assertj.core.api.Assertions.assertThat; - +import com.example.loan.model.Client; +import com.example.loan.model.LoanApplication; +import com.example.loan.model.LoanApplicationResult; +import com.example.loan.model.LoanApplicationStatus; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -11,15 +30,12 @@ import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRun import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties; import org.springframework.test.context.junit4.SpringRunner; -import com.example.loan.model.Client; -import com.example.loan.model.LoanApplication; -import com.example.loan.model.LoanApplicationResult; -import com.example.loan.model.LoanApplicationStatus; +import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment=WebEnvironment.NONE, properties="server.context-path=/app") -@AutoConfigureStubRunner(ids = {"com.example:http-server-yml:+:stubs:6569"}, - stubsMode = StubRunnerProperties.StubsMode.LOCAL) +@SpringBootTest(webEnvironment = WebEnvironment.NONE, properties = "server.context-path=/app") +@AutoConfigureStubRunner(ids = { + "com.example:http-server-yml:+:stubs:6569" }, stubsMode = StubRunnerProperties.StubsMode.LOCAL) public class LoanApplicationServiceContextPathTests { @Autowired diff --git a/samples/standalone/yml/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java b/samples/standalone/yml/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java index a0949d753c..b41c104bf1 100644 --- a/samples/standalone/yml/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java +++ b/samples/standalone/yml/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java @@ -1,7 +1,28 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.loan; +import com.example.loan.model.Client; +import com.example.loan.model.LoanApplication; +import com.example.loan.model.LoanApplicationResult; +import com.example.loan.model.LoanApplicationStatus; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -9,20 +30,16 @@ import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRun import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties; import org.springframework.test.context.junit4.SpringRunner; -import com.example.loan.model.Client; -import com.example.loan.model.LoanApplication; -import com.example.loan.model.LoanApplicationResult; -import com.example.loan.model.LoanApplicationStatus; - import static org.assertj.core.api.Assertions.assertThat; // tag::autoconfigure_stubrunner[] @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment=WebEnvironment.NONE) -@AutoConfigureStubRunner(ids = {"com.example:http-server-yml:+:stubs:6569"}, - stubsMode = StubRunnerProperties.StubsMode.LOCAL) +@SpringBootTest(webEnvironment = WebEnvironment.NONE) +@AutoConfigureStubRunner(ids = { + "com.example:http-server-yml:+:stubs:6569" }, stubsMode = StubRunnerProperties.StubsMode.LOCAL) public class LoanApplicationServiceTests { -// end::autoconfigure_stubrunner[] + + // end::autoconfigure_stubrunner[] @Autowired private LoanApplicationService service; diff --git a/samples/standalone/yml/http-client/src/test/resources/application-gradle.yaml b/samples/standalone/yml/http-client/src/test/resources/application-gradle.yaml index 4fae7615ee..504cb4ec0a 100644 --- a/samples/standalone/yml/http-client/src/test/resources/application-gradle.yaml +++ b/samples/standalone/yml/http-client/src/test/resources/application-gradle.yaml @@ -1,3 +1,3 @@ stubrunner: stubs-mode: local - stubs.ids: 'com.example:http-server-yml-gradle:+:stubs:6569' \ No newline at end of file + stubs.ids: 'com.example:http-server-yml-gradle:+:stubs:6569' diff --git a/samples/standalone/yml/http-server/.mvn/wrapper/MavenWrapperDownloader.java b/samples/standalone/yml/http-server/.mvn/wrapper/MavenWrapperDownloader.java index d475a89ce1..44f295e331 100755 --- a/samples/standalone/yml/http-server/.mvn/wrapper/MavenWrapperDownloader.java +++ b/samples/standalone/yml/http-server/.mvn/wrapper/MavenWrapperDownloader.java @@ -1,3 +1,4 @@ + /* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -17,94 +18,100 @@ specific language governing permissions and limitations under the License. */ -import java.net.*; -import java.io.*; -import java.nio.channels.*; import java.util.Properties; public class MavenWrapperDownloader { - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = - "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is + * provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to - * use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = - ".mvn/wrapper/maven-wrapper.properties"; + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl + * property to use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = ".mvn/wrapper/maven-wrapper.properties"; - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = - ".mvn/wrapper/maven-wrapper.jar"; + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar"; - /** - * Name of the property which should be used to override the default download url for the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + /** + * Name of the property which should be used to override the default download url for + * the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - // If the maven-wrapper.properties exists, read it and check if it contains a custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } finally { - try { - if(mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: : " + url); + // If the maven-wrapper.properties exists, read it and check if it contains a + // custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, + MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if (mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream( + mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } + catch (IOException e) { + System.out.println( + "- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } + finally { + try { + if (mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } + catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { - System.out.println( - "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } + File outputFile = new File(baseDirectory.getAbsolutePath(), + MAVEN_WRAPPER_JAR_PATH); + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { + System.out.println("- ERROR creating output direcrory '" + + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } + catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } - private static void downloadFileFromURL(String urlString, File destination) throws Exception { - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } + private static void downloadFileFromURL(String urlString, File destination) + throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } } diff --git a/samples/standalone/yml/http-server/build.gradle b/samples/standalone/yml/http-server/build.gradle index cde3a68906..a6185b799c 100644 --- a/samples/standalone/yml/http-server/build.gradle +++ b/samples/standalone/yml/http-server/build.gradle @@ -67,7 +67,7 @@ test { } task wrapper(type: Wrapper) { - gradleVersion = '4.10' + gradleVersion = '4.10' } clean.doFirst { diff --git a/samples/standalone/yml/http-server/pom.xml b/samples/standalone/yml/http-server/pom.xml index 36a26889a5..55fa32dfd9 100644 --- a/samples/standalone/yml/http-server/pom.xml +++ b/samples/standalone/yml/http-server/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 com.example @@ -14,14 +15,16 @@ org.springframework.boot spring-boot-starter-parent 2.1.2.RELEASE - + UTF-8 1.8 - 2.1.1.BUILD-SNAPSHOT - Greenwich.BUILD-SNAPSHOT + 2.1.1.BUILD-SNAPSHOT + + Greenwich.BUILD-SNAPSHOT + @@ -123,8 +126,11 @@ org.springframework.cloud - spring-cloud-contract-maven-plugin - [${spring-cloud-contract.version},) + spring-cloud-contract-maven-plugin + + + [${spring-cloud-contract.version},) + convert generateTests @@ -216,7 +222,9 @@ clean build publishToMavenLocal - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + @@ -246,7 +254,9 @@ clean build publishToMavenLocal - -PverifierVersion=${spring-cloud-contract.version} + + -PverifierVersion=${spring-cloud-contract.version} + diff --git a/samples/standalone/yml/http-server/src/main/java/com/example/fraud/Application.java b/samples/standalone/yml/http-server/src/main/java/com/example/fraud/Application.java index 9117009b09..ef20bf067e 100644 --- a/samples/standalone/yml/http-server/src/main/java/com/example/fraud/Application.java +++ b/samples/standalone/yml/http-server/src/main/java/com/example/fraud/Application.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; import org.springframework.boot.SpringApplication; diff --git a/samples/standalone/yml/http-server/src/main/java/com/example/fraud/FraudDetectionController.java b/samples/standalone/yml/http-server/src/main/java/com/example/fraud/FraudDetectionController.java index 764f8a6e96..c8fe767530 100644 --- a/samples/standalone/yml/http-server/src/main/java/com/example/fraud/FraudDetectionController.java +++ b/samples/standalone/yml/http-server/src/main/java/com/example/fraud/FraudDetectionController.java @@ -1,28 +1,46 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; import java.math.BigDecimal; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - import com.example.fraud.model.FraudCheck; import com.example.fraud.model.FraudCheckResult; import com.example.fraud.model.FraudCheckStatus; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + import static org.springframework.web.bind.annotation.RequestMethod.PUT; @RestController public class FraudDetectionController { private static final String NO_REASON = null; + private static final String AMOUNT_TOO_HIGH = "Amount too high"; + private static final BigDecimal MAX_AMOUNT = new BigDecimal("5000"); // tag::server_api[] @RequestMapping(value = "/fraudcheck", method = PUT) public FraudCheckResult fraudCheck(@RequestBody FraudCheck fraudCheck) { - // end::server_api[] + // end::server_api[] // tag::new_impl[] if (amountGreaterThanThreshold(fraudCheck)) { return new FraudCheckResult(FraudCheckStatus.FRAUD, AMOUNT_TOO_HIGH); diff --git a/samples/standalone/yml/http-server/src/main/java/com/example/fraud/FraudNameController.java b/samples/standalone/yml/http-server/src/main/java/com/example/fraud/FraudNameController.java index 4ba6881594..76bbc68b83 100644 --- a/samples/standalone/yml/http-server/src/main/java/com/example/fraud/FraudNameController.java +++ b/samples/standalone/yml/http-server/src/main/java/com/example/fraud/FraudNameController.java @@ -1,9 +1,31 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; +interface FraudVerifier { + + boolean isFraudByName(String name); + +} + /** * @author Marcin Grzejszczak */ @@ -22,15 +44,14 @@ class FraudNameController { if (fraud) { return new NameResponse("Sorry " + request.getName() + " but you're a fraud"); } - return new NameResponse("Don't worry " + request.getName() + " you're not a fraud"); + return new NameResponse( + "Don't worry " + request.getName() + " you're not a fraud"); } -} -interface FraudVerifier { - boolean isFraudByName(String name); } class NameRequest { + private String name; public NameRequest(String name) { @@ -47,9 +68,11 @@ class NameRequest { public void setName(String name) { this.name = name; } + } class NameResponse { + private String result; public NameResponse(String result) { @@ -66,4 +89,5 @@ class NameResponse { public void setResult(String result) { this.result = result; } + } diff --git a/samples/standalone/yml/http-server/src/main/java/com/example/fraud/FraudStatsController.java b/samples/standalone/yml/http-server/src/main/java/com/example/fraud/FraudStatsController.java index ac9340611c..76a4886e3f 100644 --- a/samples/standalone/yml/http-server/src/main/java/com/example/fraud/FraudStatsController.java +++ b/samples/standalone/yml/http-server/src/main/java/com/example/fraud/FraudStatsController.java @@ -1,8 +1,36 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; +enum FraudType { + + DRUNKS, ALL + +} + +interface StatsProvider { + + int count(FraudType fraudType); + +} + @RestController public class FraudStatsController { @@ -21,17 +49,11 @@ public class FraudStatsController { public Response countAllDrunks() { return new Response(this.statsProvider.count(FraudType.DRUNKS)); } -} -enum FraudType { - DRUNKS, ALL -} - -interface StatsProvider { - int count(FraudType fraudType); } class Response { + private int count; public Response(int count) { @@ -48,4 +70,5 @@ class Response { public void setCount(int count) { this.count = count; } + } diff --git a/samples/standalone/yml/http-server/src/main/java/com/example/fraud/model/FraudCheck.java b/samples/standalone/yml/http-server/src/main/java/com/example/fraud/model/FraudCheck.java index e98c2b60d2..bc7dd3a936 100644 --- a/samples/standalone/yml/http-server/src/main/java/com/example/fraud/model/FraudCheck.java +++ b/samples/standalone/yml/http-server/src/main/java/com/example/fraud/model/FraudCheck.java @@ -1,9 +1,25 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud.model; -import com.fasterxml.jackson.annotation.JsonProperty; - import java.math.BigDecimal; +import com.fasterxml.jackson.annotation.JsonProperty; + public class FraudCheck { @JsonProperty("client.id") @@ -29,4 +45,5 @@ public class FraudCheck { public void setLoanAmount(BigDecimal loanAmount) { this.loanAmount = loanAmount; } + } diff --git a/samples/standalone/yml/http-server/src/main/java/com/example/fraud/model/FraudCheckResult.java b/samples/standalone/yml/http-server/src/main/java/com/example/fraud/model/FraudCheckResult.java index 2f30912063..dbf4ff8fef 100644 --- a/samples/standalone/yml/http-server/src/main/java/com/example/fraud/model/FraudCheckResult.java +++ b/samples/standalone/yml/http-server/src/main/java/com/example/fraud/model/FraudCheckResult.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud.model; import com.fasterxml.jackson.annotation.JsonProperty; @@ -32,4 +48,5 @@ public class FraudCheckResult { public void setRejectionReason(String rejectionReason) { this.rejectionReason = rejectionReason; } + } diff --git a/samples/standalone/yml/http-server/src/main/java/com/example/fraud/model/FraudCheckStatus.java b/samples/standalone/yml/http-server/src/main/java/com/example/fraud/model/FraudCheckStatus.java index 5a6adcf274..02d37adf46 100644 --- a/samples/standalone/yml/http-server/src/main/java/com/example/fraud/model/FraudCheckStatus.java +++ b/samples/standalone/yml/http-server/src/main/java/com/example/fraud/model/FraudCheckStatus.java @@ -1,5 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud.model; public enum FraudCheckStatus { + OK, FRAUD + } diff --git a/samples/standalone/yml/http-server/src/test/java/com/example/fraud/FraudBase.java b/samples/standalone/yml/http-server/src/test/java/com/example/fraud/FraudBase.java index 142bffa8df..22b788e8c3 100644 --- a/samples/standalone/yml/http-server/src/test/java/com/example/fraud/FraudBase.java +++ b/samples/standalone/yml/http-server/src/test/java/com/example/fraud/FraudBase.java @@ -1,10 +1,26 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; +import io.restassured.module.mockmvc.RestAssuredMockMvc; import org.junit.Before; -import io.restassured.module.mockmvc.RestAssuredMockMvc; - public class FraudBase { + @Before public void setup() { RestAssuredMockMvc.standaloneSetup(new FraudDetectionController(), @@ -26,4 +42,5 @@ public class FraudBase { public void assertThatRejectionReasonIsNull(Object rejectionReason) { assert rejectionReason == null; } -} \ No newline at end of file + +} diff --git a/samples/standalone/yml/http-server/src/test/java/com/example/fraud/FraudnameBase.java b/samples/standalone/yml/http-server/src/test/java/com/example/fraud/FraudnameBase.java index ab8288eeed..9e7196124e 100644 --- a/samples/standalone/yml/http-server/src/test/java/com/example/fraud/FraudnameBase.java +++ b/samples/standalone/yml/http-server/src/test/java/com/example/fraud/FraudnameBase.java @@ -1,8 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example.fraud; -import org.junit.Before; - import io.restassured.module.mockmvc.RestAssuredMockMvc; +import org.junit.Before; public class FraudnameBase { @@ -14,4 +29,5 @@ public class FraudnameBase { public void setup() { RestAssuredMockMvc.standaloneSetup(new FraudNameController(this.fraudVerifier)); } -} \ No newline at end of file + +} diff --git a/samples/standalone/yml/http-server/src/test/resources/contracts/fraud/shouldMarkClientAsNotFraud.yaml b/samples/standalone/yml/http-server/src/test/resources/contracts/fraud/shouldMarkClientAsNotFraud.yaml index 7857099211..c4101b048c 100644 --- a/samples/standalone/yml/http-server/src/test/resources/contracts/fraud/shouldMarkClientAsNotFraud.yaml +++ b/samples/standalone/yml/http-server/src/test/resources/contracts/fraud/shouldMarkClientAsNotFraud.yaml @@ -22,4 +22,4 @@ response: body: - path: $.['rejection.reason'] type: by_command - value: assertThatRejectionReasonIsNull($it) \ No newline at end of file + value: assertThatRejectionReasonIsNull($it) diff --git a/samples/standalone/yml/pom.xml b/samples/standalone/yml/pom.xml index e30233401f..6574016af8 100644 --- a/samples/standalone/yml/pom.xml +++ b/samples/standalone/yml/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 @@ -14,10 +15,12 @@ pom Spring Cloud Contract Standalone Dsl Test Samples - Spring Cloud Contract Standalone Test Samples used for end to end tests + Spring Cloud Contract Standalone Test Samples used for end to end tests + - 2.1.1.BUILD-SNAPSHOT + 2.1.1.BUILD-SNAPSHOT + diff --git a/samples/wiremock-jetty/pom.xml b/samples/wiremock-jetty/pom.xml index 550ea52e4e..3578dda6ce 100644 --- a/samples/wiremock-jetty/pom.xml +++ b/samples/wiremock-jetty/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 wiremock-jetty @@ -14,13 +15,14 @@ org.springframework.boot spring-boot-starter-parent 2.1.2.RELEASE - + UTF-8 1.8 - 2.1.1.BUILD-SNAPSHOT + 2.1.1.BUILD-SNAPSHOT + diff --git a/samples/wiremock-jetty/src/main/java/com/example/WiremockTestsApplication.java b/samples/wiremock-jetty/src/main/java/com/example/WiremockTestsApplication.java index 36dcdb988e..da00ef1756 100644 --- a/samples/wiremock-jetty/src/main/java/com/example/WiremockTestsApplication.java +++ b/samples/wiremock-jetty/src/main/java/com/example/WiremockTestsApplication.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example; import org.springframework.beans.factory.annotation.Value; @@ -13,15 +29,15 @@ import org.springframework.web.client.RestTemplate; @SpringBootApplication public class WiremockTestsApplication { + public static void main(String[] args) { + SpringApplication.run(WiremockTestsApplication.class, args); + } + @Bean public RestTemplate restTemplate(RestTemplateBuilder builder) { return builder.build(); } - public static void main(String[] args) { - SpringApplication.run(WiremockTestsApplication.class, args); - } - } @RestController @@ -29,7 +45,7 @@ class Controller { private final Service service; - public Controller(Service service) { + Controller(Service service) { this.service = service; } @@ -43,12 +59,12 @@ class Controller { @Component class Service { + private final RestTemplate restTemplate; + @Value("${app.baseUrl:http://example.org}") private String base; - private final RestTemplate restTemplate; - - public Service(RestTemplate restTemplate) { + Service(RestTemplate restTemplate) { this.restTemplate = restTemplate; } diff --git a/samples/wiremock-jetty/src/main/resources/application.properties b/samples/wiremock-jetty/src/main/resources/application.properties index 1c421cf2b7..cbe617ef03 100644 --- a/samples/wiremock-jetty/src/main/resources/application.properties +++ b/samples/wiremock-jetty/src/main/resources/application.properties @@ -1 +1 @@ -server.port=0 \ No newline at end of file +server.port=0 diff --git a/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsClassRuleTests.java b/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsClassRuleTests.java index b1608b8ce2..d6f765eef5 100644 --- a/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsClassRuleTests.java +++ b/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsClassRuleTests.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example; import com.github.tomakehurst.wiremock.junit.WireMockClassRule; @@ -30,6 +46,10 @@ public class WiremockForDocsClassRuleTests { public static WireMockClassRule wiremock = new WireMockClassRule( WireMockSpring.options().dynamicPort()); + // A service that calls out over HTTP to wiremock's port + @Autowired + private Service service; + // end::wiremock_test1[] // tag::wiremock_test2[] @Before @@ -37,10 +57,6 @@ public class WiremockForDocsClassRuleTests { this.service.setBase("http://localhost:" + wiremock.port()); } - // A service that calls out over HTTP to wiremock's port - @Autowired - private Service service; - // Using the WireMock APIs in the normal way: @Test public void contextLoads() throws Exception { @@ -52,4 +68,4 @@ public class WiremockForDocsClassRuleTests { } } -// end::wiremock_test2[] \ No newline at end of file +// end::wiremock_test2[] diff --git a/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsMockServerApplicationTests.java b/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsMockServerApplicationTests.java index 923ce4f974..67fd694e12 100644 --- a/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsMockServerApplicationTests.java +++ b/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsMockServerApplicationTests.java @@ -1,9 +1,24 @@ -package com.example; +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 static org.assertj.core.api.Assertions.assertThat; +package com.example; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -12,6 +27,8 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.web.client.RestTemplate; +import static org.assertj.core.api.Assertions.assertThat; + // tag::wiremock_test[] @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.NONE) diff --git a/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsTests.java b/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsTests.java index 29757ff067..820fdc9698 100644 --- a/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsTests.java +++ b/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsTests.java @@ -1,8 +1,25 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -29,17 +46,17 @@ public class WiremockForDocsTests { @Autowired Environment environment; - @Before - public void setup() { - service.setBase("http://localhost:" - + this.environment.getProperty("wiremock.server.port")); - } - // tag::wiremock_test2[] // A service that calls out over HTTP @Autowired private Service service; + @Before + public void setup() { + this.service.setBase("http://localhost:" + + this.environment.getProperty("wiremock.server.port")); + } + // Using the WireMock APIs in the normal way: @Test public void contextLoads() throws Exception { @@ -51,4 +68,4 @@ public class WiremockForDocsTests { } } -// end::wiremock_test2[] \ No newline at end of file +// end::wiremock_test2[] diff --git a/samples/wiremock-jetty/src/test/java/com/example/WiremockHttpsServerApplicationTests.java b/samples/wiremock-jetty/src/test/java/com/example/WiremockHttpsServerApplicationTests.java index f720c6faed..89fb834cf9 100644 --- a/samples/wiremock-jetty/src/test/java/com/example/WiremockHttpsServerApplicationTests.java +++ b/samples/wiremock-jetty/src/test/java/com/example/WiremockHttpsServerApplicationTests.java @@ -1,7 +1,22 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example; import com.github.tomakehurst.wiremock.junit.WireMockClassRule; - import org.junit.ClassRule; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/samples/wiremock-jetty/src/test/java/com/example/WiremockImportApplicationTests.java b/samples/wiremock-jetty/src/test/java/com/example/WiremockImportApplicationTests.java index 7dc6784e57..3ffa5d584d 100644 --- a/samples/wiremock-jetty/src/test/java/com/example/WiremockImportApplicationTests.java +++ b/samples/wiremock-jetty/src/test/java/com/example/WiremockImportApplicationTests.java @@ -1,19 +1,36 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock; +import org.springframework.test.context.junit4.SpringRunner; + import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock; -import org.springframework.test.context.junit4.SpringRunner; - @RunWith(SpringRunner.class) @SpringBootTest(properties = "app.baseUrl=http://localhost:6060", webEnvironment = WebEnvironment.NONE) @AutoConfigureWireMock(port = 6060) diff --git a/samples/wiremock-jetty/src/test/java/com/example/WiremockMockServerApplicationTests.java b/samples/wiremock-jetty/src/test/java/com/example/WiremockMockServerApplicationTests.java index ca7ad3d93a..3c21fc344c 100644 --- a/samples/wiremock-jetty/src/test/java/com/example/WiremockMockServerApplicationTests.java +++ b/samples/wiremock-jetty/src/test/java/com/example/WiremockMockServerApplicationTests.java @@ -1,9 +1,24 @@ -package com.example; +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 static org.assertj.core.api.Assertions.assertThat; +package com.example; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -12,6 +27,8 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.web.client.RestTemplate; +import static org.assertj.core.api.Assertions.assertThat; + @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.NONE) public class WiremockMockServerApplicationTests { diff --git a/samples/wiremock-jetty/src/test/java/com/example/WiremockServerApplicationTests.java b/samples/wiremock-jetty/src/test/java/com/example/WiremockServerApplicationTests.java index 14d868f2bc..80747c950e 100644 --- a/samples/wiremock-jetty/src/test/java/com/example/WiremockServerApplicationTests.java +++ b/samples/wiremock-jetty/src/test/java/com/example/WiremockServerApplicationTests.java @@ -1,8 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example; import com.github.tomakehurst.wiremock.http.Fault; import com.github.tomakehurst.wiremock.junit.WireMockClassRule; - import org.apache.http.MalformedChunkCodingException; import org.apache.http.NoHttpResponseException; import org.apache.http.client.ClientProtocolException; @@ -50,7 +65,7 @@ public class WiremockServerApplicationTests { public void randomData() throws Exception { stubFor(get(urlEqualTo("/resource")) .willReturn(aResponse().withFault(Fault.RANDOM_DATA_THEN_CLOSE))); - expected.expectCause(instanceOf(ClientProtocolException.class)); + this.expected.expectCause(instanceOf(ClientProtocolException.class)); assertThat(this.service.go()).isEqualTo("Oops!"); } @@ -58,7 +73,7 @@ public class WiremockServerApplicationTests { public void emptyResponse() throws Exception { stubFor(get(urlEqualTo("/resource")) .willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE))); - expected.expectCause(instanceOf(NoHttpResponseException.class)); + this.expected.expectCause(instanceOf(NoHttpResponseException.class)); assertThat(this.service.go()).isEqualTo("Oops!"); } @@ -66,7 +81,7 @@ public class WiremockServerApplicationTests { public void malformed() throws Exception { stubFor(get(urlEqualTo("/resource")) .willReturn(aResponse().withFault(Fault.MALFORMED_RESPONSE_CHUNK))); - expected.expectCause(instanceOf(MalformedChunkCodingException.class)); + this.expected.expectCause(instanceOf(MalformedChunkCodingException.class)); assertThat(this.service.go()).isEqualTo("Oops!"); } diff --git a/samples/wiremock-jetty/src/test/resources/application-classrule.yml b/samples/wiremock-jetty/src/test/resources/application-classrule.yml index aac0711d07..7b28247a2f 100644 --- a/samples/wiremock-jetty/src/test/resources/application-classrule.yml +++ b/samples/wiremock-jetty/src/test/resources/application-classrule.yml @@ -1 +1 @@ -app.baseUrl: http://localhost:9090 \ No newline at end of file +app.baseUrl: http://localhost:9090 diff --git a/samples/wiremock-jetty/src/test/resources/application-docs.yml b/samples/wiremock-jetty/src/test/resources/application-docs.yml index 662aebfb27..b783020a08 100644 --- a/samples/wiremock-jetty/src/test/resources/application-docs.yml +++ b/samples/wiremock-jetty/src/test/resources/application-docs.yml @@ -1 +1 @@ -app.baseUrl: http://localhost:8080 \ No newline at end of file +app.baseUrl: http://localhost:8080 diff --git a/samples/wiremock-jetty/src/test/resources/stubs/resource.json b/samples/wiremock-jetty/src/test/resources/stubs/resource.json index 41a9d4e920..5c73d668eb 100644 --- a/samples/wiremock-jetty/src/test/resources/stubs/resource.json +++ b/samples/wiremock-jetty/src/test/resources/stubs/resource.json @@ -1,10 +1,10 @@ { - "request" : { - "urlPath" : "/resource", - "method" : "GET" + "request": { + "urlPath": "/resource", + "method": "GET" }, - "response" : { - "status" : 200, - "body" : "Hello World" + "response": { + "status": 200, + "body": "Hello World" } -} \ No newline at end of file +} diff --git a/samples/wiremock-native/pom.xml b/samples/wiremock-native/pom.xml index 6e48697db3..f408ed41f0 100644 --- a/samples/wiremock-native/pom.xml +++ b/samples/wiremock-native/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 wiremock-native @@ -14,13 +15,14 @@ org.springframework.boot spring-boot-starter-parent 2.1.2.RELEASE - + UTF-8 1.8 - 2.1.1.BUILD-SNAPSHOT + 2.1.1.BUILD-SNAPSHOT + diff --git a/samples/wiremock-native/src/main/java/com/example/WiremockTestsApplication.java b/samples/wiremock-native/src/main/java/com/example/WiremockTestsApplication.java index 8ab6535d0c..df5f5cc14f 100644 --- a/samples/wiremock-native/src/main/java/com/example/WiremockTestsApplication.java +++ b/samples/wiremock-native/src/main/java/com/example/WiremockTestsApplication.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example; import org.springframework.beans.factory.annotation.Value; @@ -12,15 +28,15 @@ import org.springframework.web.client.RestTemplate; @SpringBootApplication public class WiremockTestsApplication { + public static void main(String[] args) { + SpringApplication.run(WiremockTestsApplication.class, args); + } + @Bean public RestTemplate restTemplate() { return new RestTemplate(); } - public static void main(String[] args) { - SpringApplication.run(WiremockTestsApplication.class, args); - } - } @RestController @@ -28,7 +44,7 @@ class Controller { private final Service service; - public Controller(Service service) { + Controller(Service service) { this.service = service; } @@ -42,12 +58,12 @@ class Controller { @Component class Service { + private final RestTemplate restTemplate; + @Value("${app.baseUrl:http://example.org}") private String base; - private final RestTemplate restTemplate; - - public Service(RestTemplate restTemplate) { + Service(RestTemplate restTemplate) { this.restTemplate = restTemplate; } diff --git a/samples/wiremock-native/src/main/resources/application.properties b/samples/wiremock-native/src/main/resources/application.properties index e69de29bb2..8b13789179 100644 --- a/samples/wiremock-native/src/main/resources/application.properties +++ b/samples/wiremock-native/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/samples/wiremock-native/src/test/java/com/example/WiremockServerApplicationTests.java b/samples/wiremock-native/src/test/java/com/example/WiremockServerApplicationTests.java index 8619b3efbf..6a276bb084 100644 --- a/samples/wiremock-native/src/test/java/com/example/WiremockServerApplicationTests.java +++ b/samples/wiremock-native/src/test/java/com/example/WiremockServerApplicationTests.java @@ -1,21 +1,37 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example; +import com.github.tomakehurst.wiremock.junit.WireMockClassRule; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.junit4.SpringRunner; + import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static org.assertj.core.api.Assertions.assertThat; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.test.context.junit4.SpringRunner; - -import com.github.tomakehurst.wiremock.junit.WireMockClassRule; - @RunWith(SpringRunner.class) @SpringBootTest(properties = "app.baseUrl=http://localhost:6063", webEnvironment = WebEnvironment.NONE) public class WiremockServerApplicationTests { diff --git a/samples/wiremock-native/src/test/resources/stubs/resource.json b/samples/wiremock-native/src/test/resources/stubs/resource.json index 41a9d4e920..5c73d668eb 100644 --- a/samples/wiremock-native/src/test/resources/stubs/resource.json +++ b/samples/wiremock-native/src/test/resources/stubs/resource.json @@ -1,10 +1,10 @@ { - "request" : { - "urlPath" : "/resource", - "method" : "GET" + "request": { + "urlPath": "/resource", + "method": "GET" }, - "response" : { - "status" : 200, - "body" : "Hello World" + "response": { + "status": 200, + "body": "Hello World" } -} \ No newline at end of file +} diff --git a/samples/wiremock-tomcat/pom.xml b/samples/wiremock-tomcat/pom.xml index ce7ac5af11..57d71718d3 100644 --- a/samples/wiremock-tomcat/pom.xml +++ b/samples/wiremock-tomcat/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 wiremock-tomcat @@ -14,13 +15,14 @@ org.springframework.boot spring-boot-starter-parent 2.1.2.RELEASE - + UTF-8 1.8 - 2.1.1.BUILD-SNAPSHOT + 2.1.1.BUILD-SNAPSHOT + diff --git a/samples/wiremock-tomcat/src/main/java/com/example/WiremockTestsApplication.java b/samples/wiremock-tomcat/src/main/java/com/example/WiremockTestsApplication.java index f552369004..6bc446b854 100644 --- a/samples/wiremock-tomcat/src/main/java/com/example/WiremockTestsApplication.java +++ b/samples/wiremock-tomcat/src/main/java/com/example/WiremockTestsApplication.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example; import org.springframework.beans.factory.annotation.Value; @@ -13,15 +29,15 @@ import org.springframework.web.client.RestTemplate; @SpringBootApplication public class WiremockTestsApplication { + public static void main(String[] args) { + SpringApplication.run(WiremockTestsApplication.class, args); + } + @Bean public RestTemplate restTemplate(RestTemplateBuilder builder) { return builder.build(); } - public static void main(String[] args) { - SpringApplication.run(WiremockTestsApplication.class, args); - } - } @RestController @@ -29,7 +45,7 @@ class Controller { private final Service service; - public Controller(Service service) { + Controller(Service service) { this.service = service; } @@ -43,12 +59,12 @@ class Controller { @Component class Service { + private final RestTemplate restTemplate; + @Value("${app.baseUrl:http://example.org}") private String base; - private final RestTemplate restTemplate; - - public Service(RestTemplate restTemplate) { + Service(RestTemplate restTemplate) { this.restTemplate = restTemplate; } diff --git a/samples/wiremock-tomcat/src/main/resources/application.properties b/samples/wiremock-tomcat/src/main/resources/application.properties index e69de29bb2..8b13789179 100644 --- a/samples/wiremock-tomcat/src/main/resources/application.properties +++ b/samples/wiremock-tomcat/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/samples/wiremock-tomcat/src/test/java/com/example/WiremockHttpsServerApplicationTests.java b/samples/wiremock-tomcat/src/test/java/com/example/WiremockHttpsServerApplicationTests.java index a1a98b691c..2c0829ff6d 100644 --- a/samples/wiremock-tomcat/src/test/java/com/example/WiremockHttpsServerApplicationTests.java +++ b/samples/wiremock-tomcat/src/test/java/com/example/WiremockHttpsServerApplicationTests.java @@ -1,21 +1,37 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example; -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static org.assertj.core.api.Assertions.assertThat; - +import com.github.tomakehurst.wiremock.junit.WireMockClassRule; import org.junit.ClassRule; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.contract.wiremock.AutoConfigureHttpClient; import org.springframework.cloud.contract.wiremock.WireMockSpring; import org.springframework.test.context.junit4.SpringRunner; -import com.github.tomakehurst.wiremock.junit.WireMockClassRule; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @SpringBootTest("app.baseUrl=https://localhost:6443") diff --git a/samples/wiremock-tomcat/src/test/java/com/example/WiremockImportApplicationTests.java b/samples/wiremock-tomcat/src/test/java/com/example/WiremockImportApplicationTests.java index f7ea1ea0da..7646a3242d 100644 --- a/samples/wiremock-tomcat/src/test/java/com/example/WiremockImportApplicationTests.java +++ b/samples/wiremock-tomcat/src/test/java/com/example/WiremockImportApplicationTests.java @@ -1,19 +1,36 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock; +import org.springframework.test.context.junit4.SpringRunner; + import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock; -import org.springframework.test.context.junit4.SpringRunner; - @RunWith(SpringRunner.class) @SpringBootTest(properties = "app.baseUrl=http://localhost:6065", webEnvironment = WebEnvironment.NONE) @AutoConfigureWireMock(port = 6065) diff --git a/samples/wiremock-tomcat/src/test/java/com/example/WiremockImportContextPathApplicationTests.java b/samples/wiremock-tomcat/src/test/java/com/example/WiremockImportContextPathApplicationTests.java index f377cf7b7d..e8998e1512 100644 --- a/samples/wiremock-tomcat/src/test/java/com/example/WiremockImportContextPathApplicationTests.java +++ b/samples/wiremock-tomcat/src/test/java/com/example/WiremockImportContextPathApplicationTests.java @@ -1,19 +1,36 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock; +import org.springframework.test.context.junit4.SpringRunner; + import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock; -import org.springframework.test.context.junit4.SpringRunner; - @RunWith(SpringRunner.class) @SpringBootTest(properties = { "app.baseUrl=http://localhost:6066", "server.context-path=/app" }, webEnvironment = WebEnvironment.NONE) diff --git a/samples/wiremock-tomcat/src/test/java/com/example/WiremockMockServerApplicationTests.java b/samples/wiremock-tomcat/src/test/java/com/example/WiremockMockServerApplicationTests.java index a9bd5cac59..9c913607be 100644 --- a/samples/wiremock-tomcat/src/test/java/com/example/WiremockMockServerApplicationTests.java +++ b/samples/wiremock-tomcat/src/test/java/com/example/WiremockMockServerApplicationTests.java @@ -1,9 +1,24 @@ -package com.example; +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 static org.assertj.core.api.Assertions.assertThat; +package com.example; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -12,6 +27,8 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.web.client.RestTemplate; +import static org.assertj.core.api.Assertions.assertThat; + @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.NONE) public class WiremockMockServerApplicationTests { diff --git a/samples/wiremock-tomcat/src/test/java/com/example/WiremockServerApplicationTests.java b/samples/wiremock-tomcat/src/test/java/com/example/WiremockServerApplicationTests.java index 5c97436a43..490be84007 100644 --- a/samples/wiremock-tomcat/src/test/java/com/example/WiremockServerApplicationTests.java +++ b/samples/wiremock-tomcat/src/test/java/com/example/WiremockServerApplicationTests.java @@ -1,10 +1,25 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example; import java.io.IOException; import com.github.tomakehurst.wiremock.http.Fault; import com.github.tomakehurst.wiremock.junit.WireMockClassRule; - import org.apache.http.NoHttpResponseException; import org.apache.http.client.ClientProtocolException; import org.junit.ClassRule; @@ -51,7 +66,7 @@ public class WiremockServerApplicationTests { public void randomData() throws Exception { stubFor(get(urlEqualTo("/resource")) .willReturn(aResponse().withFault(Fault.RANDOM_DATA_THEN_CLOSE))); - expected.expectCause(instanceOf(ClientProtocolException.class)); + this.expected.expectCause(instanceOf(ClientProtocolException.class)); assertThat(this.service.go()).isEqualTo("Oops!"); } @@ -59,7 +74,7 @@ public class WiremockServerApplicationTests { public void emptyResponse() throws Exception { stubFor(get(urlEqualTo("/resource")) .willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE))); - expected.expectCause(instanceOf(NoHttpResponseException.class)); + this.expected.expectCause(instanceOf(NoHttpResponseException.class)); assertThat(this.service.go()).isEqualTo("Oops!"); } @@ -68,8 +83,8 @@ public class WiremockServerApplicationTests { stubFor(get(urlEqualTo("/resource")) .willReturn(aResponse().withFault(Fault.MALFORMED_RESPONSE_CHUNK))); // It's a different exception type than Jetty, but it's in the right ballpark - expected.expectCause(instanceOf(IOException.class)); - expected.expectMessage("chunk"); + this.expected.expectCause(instanceOf(IOException.class)); + this.expected.expectMessage("chunk"); assertThat(this.service.go()).isEqualTo("Oops!"); } diff --git a/samples/wiremock-tomcat/src/test/resources/stubs/resource.json b/samples/wiremock-tomcat/src/test/resources/stubs/resource.json index 41a9d4e920..5c73d668eb 100644 --- a/samples/wiremock-tomcat/src/test/resources/stubs/resource.json +++ b/samples/wiremock-tomcat/src/test/resources/stubs/resource.json @@ -1,10 +1,10 @@ { - "request" : { - "urlPath" : "/resource", - "method" : "GET" + "request": { + "urlPath": "/resource", + "method": "GET" }, - "response" : { - "status" : 200, - "body" : "Hello World" + "response": { + "status": 200, + "body": "Hello World" } -} \ No newline at end of file +} diff --git a/samples/wiremock-undertow-ssl/pom.xml b/samples/wiremock-undertow-ssl/pom.xml index 5a469e25aa..7c83b71259 100644 --- a/samples/wiremock-undertow-ssl/pom.xml +++ b/samples/wiremock-undertow-ssl/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 wiremock-undertow-ssl @@ -14,13 +15,14 @@ org.springframework.boot spring-boot-starter-parent 2.1.2.RELEASE - + UTF-8 1.8 - 2.1.1.BUILD-SNAPSHOT + 2.1.1.BUILD-SNAPSHOT + diff --git a/samples/wiremock-undertow-ssl/src/main/java/com/example/WiremockTestsApplication.java b/samples/wiremock-undertow-ssl/src/main/java/com/example/WiremockTestsApplication.java index 8ab6535d0c..df5f5cc14f 100644 --- a/samples/wiremock-undertow-ssl/src/main/java/com/example/WiremockTestsApplication.java +++ b/samples/wiremock-undertow-ssl/src/main/java/com/example/WiremockTestsApplication.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example; import org.springframework.beans.factory.annotation.Value; @@ -12,15 +28,15 @@ import org.springframework.web.client.RestTemplate; @SpringBootApplication public class WiremockTestsApplication { + public static void main(String[] args) { + SpringApplication.run(WiremockTestsApplication.class, args); + } + @Bean public RestTemplate restTemplate() { return new RestTemplate(); } - public static void main(String[] args) { - SpringApplication.run(WiremockTestsApplication.class, args); - } - } @RestController @@ -28,7 +44,7 @@ class Controller { private final Service service; - public Controller(Service service) { + Controller(Service service) { this.service = service; } @@ -42,12 +58,12 @@ class Controller { @Component class Service { + private final RestTemplate restTemplate; + @Value("${app.baseUrl:http://example.org}") private String base; - private final RestTemplate restTemplate; - - public Service(RestTemplate restTemplate) { + Service(RestTemplate restTemplate) { this.restTemplate = restTemplate; } diff --git a/samples/wiremock-undertow-ssl/src/main/resources/application.properties b/samples/wiremock-undertow-ssl/src/main/resources/application.properties index baf7121779..7159285ff1 100644 --- a/samples/wiremock-undertow-ssl/src/main/resources/application.properties +++ b/samples/wiremock-undertow-ssl/src/main/resources/application.properties @@ -2,4 +2,4 @@ server.ssl.key-store-password=password server.ssl.key-password=password server.ssl.trust-store-password=password -server.port=-1 \ No newline at end of file +server.port=-1 diff --git a/samples/wiremock-undertow-ssl/src/test/java/com/example/WiremockHttpsServerApplicationTests.java b/samples/wiremock-undertow-ssl/src/test/java/com/example/WiremockHttpsServerApplicationTests.java index 6ac41b8879..71acd83efa 100644 --- a/samples/wiremock-undertow-ssl/src/test/java/com/example/WiremockHttpsServerApplicationTests.java +++ b/samples/wiremock-undertow-ssl/src/test/java/com/example/WiremockHttpsServerApplicationTests.java @@ -1,14 +1,26 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example; -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static org.assertj.core.api.Assertions.assertThat; - +import com.github.tomakehurst.wiremock.junit.WireMockClassRule; import org.junit.ClassRule; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.contract.wiremock.WireMockSpring; @@ -16,7 +28,11 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.SocketUtils; -import com.github.tomakehurst.wiremock.junit.WireMockClassRule; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @SpringBootTest("app.baseUrl=https://localhost:7443") diff --git a/samples/wiremock-undertow-ssl/src/test/resources/stubs/resource.json b/samples/wiremock-undertow-ssl/src/test/resources/stubs/resource.json index 41a9d4e920..5c73d668eb 100644 --- a/samples/wiremock-undertow-ssl/src/test/resources/stubs/resource.json +++ b/samples/wiremock-undertow-ssl/src/test/resources/stubs/resource.json @@ -1,10 +1,10 @@ { - "request" : { - "urlPath" : "/resource", - "method" : "GET" + "request": { + "urlPath": "/resource", + "method": "GET" }, - "response" : { - "status" : 200, - "body" : "Hello World" + "response": { + "status": 200, + "body": "Hello World" } -} \ No newline at end of file +} diff --git a/samples/wiremock-undertow/pom.xml b/samples/wiremock-undertow/pom.xml index 6eb1ef800d..9f7a176734 100644 --- a/samples/wiremock-undertow/pom.xml +++ b/samples/wiremock-undertow/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 wiremock-undertow @@ -14,13 +15,14 @@ org.springframework.boot spring-boot-starter-parent 2.1.2.RELEASE - + UTF-8 1.8 - 2.1.1.BUILD-SNAPSHOT + 2.1.1.BUILD-SNAPSHOT + diff --git a/samples/wiremock-undertow/src/main/java/com/example/WiremockTestsApplication.java b/samples/wiremock-undertow/src/main/java/com/example/WiremockTestsApplication.java index 8ab6535d0c..df5f5cc14f 100644 --- a/samples/wiremock-undertow/src/main/java/com/example/WiremockTestsApplication.java +++ b/samples/wiremock-undertow/src/main/java/com/example/WiremockTestsApplication.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example; import org.springframework.beans.factory.annotation.Value; @@ -12,15 +28,15 @@ import org.springframework.web.client.RestTemplate; @SpringBootApplication public class WiremockTestsApplication { + public static void main(String[] args) { + SpringApplication.run(WiremockTestsApplication.class, args); + } + @Bean public RestTemplate restTemplate() { return new RestTemplate(); } - public static void main(String[] args) { - SpringApplication.run(WiremockTestsApplication.class, args); - } - } @RestController @@ -28,7 +44,7 @@ class Controller { private final Service service; - public Controller(Service service) { + Controller(Service service) { this.service = service; } @@ -42,12 +58,12 @@ class Controller { @Component class Service { + private final RestTemplate restTemplate; + @Value("${app.baseUrl:http://example.org}") private String base; - private final RestTemplate restTemplate; - - public Service(RestTemplate restTemplate) { + Service(RestTemplate restTemplate) { this.restTemplate = restTemplate; } diff --git a/samples/wiremock-undertow/src/main/resources/application.properties b/samples/wiremock-undertow/src/main/resources/application.properties index 1e1d091b4f..5e44f2a6c5 100644 --- a/samples/wiremock-undertow/src/main/resources/application.properties +++ b/samples/wiremock-undertow/src/main/resources/application.properties @@ -1 +1 @@ -server.port=7070 \ No newline at end of file +server.port=7070 diff --git a/samples/wiremock-undertow/src/test/java/com/example/WiremockImportApplicationTests.java b/samples/wiremock-undertow/src/test/java/com/example/WiremockImportApplicationTests.java index cb8d333821..0d1cedb53f 100644 --- a/samples/wiremock-undertow/src/test/java/com/example/WiremockImportApplicationTests.java +++ b/samples/wiremock-undertow/src/test/java/com/example/WiremockImportApplicationTests.java @@ -1,19 +1,36 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock; +import org.springframework.test.context.junit4.SpringRunner; + import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock; -import org.springframework.test.context.junit4.SpringRunner; - @RunWith(SpringRunner.class) @SpringBootTest(properties = "app.baseUrl=http://localhost:7070", webEnvironment = WebEnvironment.NONE) @AutoConfigureWireMock(port = 7070) diff --git a/samples/wiremock-undertow/src/test/java/com/example/WiremockMockServerApplicationTests.java b/samples/wiremock-undertow/src/test/java/com/example/WiremockMockServerApplicationTests.java index 47743311a5..bf4bf51d2b 100644 --- a/samples/wiremock-undertow/src/test/java/com/example/WiremockMockServerApplicationTests.java +++ b/samples/wiremock-undertow/src/test/java/com/example/WiremockMockServerApplicationTests.java @@ -1,9 +1,24 @@ -package com.example; +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 static org.assertj.core.api.Assertions.assertThat; +package com.example; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -12,6 +27,8 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.web.client.RestTemplate; +import static org.assertj.core.api.Assertions.assertThat; + @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.NONE) public class WiremockMockServerApplicationTests { diff --git a/samples/wiremock-undertow/src/test/java/com/example/WiremockServerApplicationTests.java b/samples/wiremock-undertow/src/test/java/com/example/WiremockServerApplicationTests.java index 9c79695029..4c0e0d7b0f 100644 --- a/samples/wiremock-undertow/src/test/java/com/example/WiremockServerApplicationTests.java +++ b/samples/wiremock-undertow/src/test/java/com/example/WiremockServerApplicationTests.java @@ -1,21 +1,37 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example; -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static org.assertj.core.api.Assertions.assertThat; - +import com.github.tomakehurst.wiremock.junit.WireMockClassRule; import org.junit.ClassRule; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.cloud.contract.wiremock.WireMockSpring; import org.springframework.test.context.junit4.SpringRunner; -import com.github.tomakehurst.wiremock.junit.WireMockClassRule; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @SpringBootTest(properties = "app.baseUrl=http://localhost:7071", webEnvironment = WebEnvironment.NONE) diff --git a/samples/wiremock-undertow/src/test/resources/stubs/resource.json b/samples/wiremock-undertow/src/test/resources/stubs/resource.json index 41a9d4e920..5c73d668eb 100644 --- a/samples/wiremock-undertow/src/test/resources/stubs/resource.json +++ b/samples/wiremock-undertow/src/test/resources/stubs/resource.json @@ -1,10 +1,10 @@ { - "request" : { - "urlPath" : "/resource", - "method" : "GET" + "request": { + "urlPath": "/resource", + "method": "GET" }, - "response" : { - "status" : 200, - "body" : "Hello World" + "response": { + "status": 200, + "body": "Hello World" } -} \ No newline at end of file +} diff --git a/samples/wiremock/pom.xml b/samples/wiremock/pom.xml index 1b41445a9d..629ef3e579 100644 --- a/samples/wiremock/pom.xml +++ b/samples/wiremock/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 wiremock @@ -14,13 +15,14 @@ org.springframework.boot spring-boot-starter-parent 2.1.2.RELEASE - + UTF-8 1.8 - 2.1.1.BUILD-SNAPSHOT + 2.1.1.BUILD-SNAPSHOT + diff --git a/samples/wiremock/src/main/java/com/example/WiremockTestsApplication.java b/samples/wiremock/src/main/java/com/example/WiremockTestsApplication.java index 960d1b4b89..d30129204b 100644 --- a/samples/wiremock/src/main/java/com/example/WiremockTestsApplication.java +++ b/samples/wiremock/src/main/java/com/example/WiremockTestsApplication.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example; import java.net.URI; @@ -21,15 +37,15 @@ import org.springframework.web.client.RestTemplate; @Import({ Service.class, Controller.class }) public class WiremockTestsApplication { + public static void main(String[] args) { + SpringApplication.run(WiremockTestsApplication.class, args); + } + @Bean public RestTemplate restTemplate() { return new RestTemplate(); } - public static void main(String[] args) { - SpringApplication.run(WiremockTestsApplication.class, args); - } - } @RestController @@ -37,7 +53,7 @@ class Controller { private final Service service; - public Controller(Service service) { + Controller(Service service) { this.service = service; } @@ -56,7 +72,7 @@ class Service { private RestTemplate restTemplate; - public Service(RestTemplate restTemplate) { + Service(RestTemplate restTemplate) { this.restTemplate = restTemplate; } diff --git a/samples/wiremock/src/main/resources/application.properties b/samples/wiremock/src/main/resources/application.properties index 1c421cf2b7..cbe617ef03 100644 --- a/samples/wiremock/src/main/resources/application.properties +++ b/samples/wiremock/src/main/resources/application.properties @@ -1 +1 @@ -server.port=0 \ No newline at end of file +server.port=0 diff --git a/samples/wiremock/src/test/java/com/example/AutoConfigureWireMockFilesApplicationWithUrlResourceTests.java b/samples/wiremock/src/test/java/com/example/AutoConfigureWireMockFilesApplicationWithUrlResourceTests.java index d593b1f9fb..f1719a7e1c 100644 --- a/samples/wiremock/src/test/java/com/example/AutoConfigureWireMockFilesApplicationWithUrlResourceTests.java +++ b/samples/wiremock/src/test/java/com/example/AutoConfigureWireMockFilesApplicationWithUrlResourceTests.java @@ -1,7 +1,24 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 com.example; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -9,20 +26,19 @@ import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) -@SpringBootTest(classes = WiremockTestsApplication.class, - properties = "app.baseUrl=http://localhost:${wiremock.server.port}", - webEnvironment = WebEnvironment.NONE) +@SpringBootTest(classes = WiremockTestsApplication.class, properties = "app.baseUrl=http://localhost:${wiremock.server.port}", webEnvironment = WebEnvironment.NONE) // resource from a Initilizr stubs jar -@AutoConfigureWireMock(port = 0, - files = "classpath*:META-INF/io.spring.initializr/initializr-web/0.4.0.BUILD-SNAPSHOT") +@AutoConfigureWireMock(port = 0, files = "classpath*:META-INF/io.spring.initializr/initializr-web/0.4.0.BUILD-SNAPSHOT") public class AutoConfigureWireMockFilesApplicationWithUrlResourceTests { - @Autowired private Service service; + @Autowired + private Service service; - @Test public void contextLoads() throws Exception { + @Test + public void contextLoads() throws Exception { // Sth's wrong with the JAR ^^ - // assertThat(this.service.pom()) - // .contains("spring-boot-starter-parent"); + // assertThat(this.service.pom()) + // .contains("spring-boot-starter-parent"); } } diff --git a/spring-cloud-contract-dependencies/pom.xml b/spring-cloud-contract-dependencies/pom.xml index 64e49b667d..dc7c6f1b14 100644 --- a/spring-cloud-contract-dependencies/pom.xml +++ b/spring-cloud-contract-dependencies/pom.xml @@ -1,12 +1,13 @@ - 4.0.0 spring-cloud-dependencies-parent org.springframework.cloud 2.1.3.BUILD-SNAPSHOT - + spring-cloud-contract-dependencies 2.1.1.BUILD-SNAPSHOT diff --git a/spring-cloud-contract-shade/pom.xml b/spring-cloud-contract-shade/pom.xml index 4a1eb3ad7c..602adbcffe 100644 --- a/spring-cloud-contract-shade/pom.xml +++ b/spring-cloud-contract-shade/pom.xml @@ -1,5 +1,6 @@ - 4.0.0 @@ -118,27 +119,33 @@ false true true - true + true + org.eclipse.aether.connector - shaded.org.eclipse.aether.connector + shaded.org.eclipse.aether.connector + org.eclipse.aether.transport - shaded.org.eclipse.aether.transport + shaded.org.eclipse.aether.transport + org.eclipse.aether.impl - shaded.org.eclipse.aether.impl + shaded.org.eclipse.aether.impl + org.eclipse.aether.internal - shaded.org.eclipse.aether.internal + shaded.org.eclipse.aether.internal + org.eclipse.aether.spi - shaded.org.eclipse.aether.spi + shaded.org.eclipse.aether.spi + org.apache.maven @@ -176,7 +183,8 @@ sources jar false - ${project.build.directory}/sources + ${project.build.directory}/sources + @@ -211,4 +219,4 @@ - \ No newline at end of file + diff --git a/spring-cloud-contract-spec/pom.xml b/spring-cloud-contract-spec/pom.xml index bbb2143728..e3247cadb7 100644 --- a/spring-cloud-contract-spec/pom.xml +++ b/spring-cloud-contract-spec/pom.xml @@ -1,5 +1,6 @@ - 4.0.0 diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/Contract.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/Contract.groovy index ec2c2ec5d6..1edd77cb0b 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/Contract.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/Contract.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec @@ -19,6 +19,7 @@ package org.springframework.cloud.contract.spec import groovy.transform.EqualsAndHashCode import groovy.transform.ToString import groovy.transform.TypeChecked + import org.springframework.cloud.contract.spec.internal.Input import org.springframework.cloud.contract.spec.internal.OutputMessage import org.springframework.cloud.contract.spec.internal.Request @@ -95,14 +96,17 @@ class Contract { static void assertContract(Contract dsl) { if (dsl.request) { - if (!dsl.request.url && !dsl.request.urlPath) + if (!dsl.request.url && !dsl.request.urlPath) { throw new IllegalStateException("URL is missing for HTTP contract") - if (!dsl.request.method) + } + if (!dsl.request.method) { throw new IllegalStateException("Method is missing for HTTP contract") + } } if (dsl.response) { - if (!dsl.response.status) + if (!dsl.response.status) { throw new IllegalStateException("Status is missing for HTTP contract") + } } // Can't assert messaging part cause Pact doesn't require destinations it seems } diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/ContractConverter.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/ContractConverter.groovy index e8ec69d280..6457a659ca 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/ContractConverter.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/ContractConverter.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2016 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec @@ -20,7 +20,7 @@ package org.springframework.cloud.contract.spec * Converter to be used to convert FROM {@link File} TO {@link Contract} * and from {@link Contract} to {@code T} * - * @param - type to which we want to convert the contract + * @param - type to which we want to convert the contract * * @author Marcin Grzejszczak * @since 1.1.0 diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/ContractStorer.java b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/ContractStorer.java index 1df2b4dda9..a52f283837 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/ContractStorer.java +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/ContractStorer.java @@ -1,19 +1,36 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec; import java.util.HashMap; import java.util.Map; /** - * Defines how to store converted contracts to a byte array representation - * that can be stored to drive + * Defines how to store converted contracts to a byte array representation that can be + * stored to drive. * + * @param contracts type * @author Marcin Grzejszczak * @since 2.1.0 */ public interface ContractStorer { + /** - * Stores the contracts as a map of filename and String - * + * Stores the contracts as a map of filename and String. * @param contracts - to convert * @return mapping of filename to converted byte array representation of the contract */ @@ -22,4 +39,5 @@ public interface ContractStorer { map.put(String.valueOf(Math.abs(hashCode())), contracts.toString().getBytes()); return map; } + } diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/ContractTemplate.java b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/ContractTemplate.java index bafcec195b..f271096e9f 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/ContractTemplate.java +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/ContractTemplate.java @@ -1,201 +1,231 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec; /** * Contract for defining templated responses. *

- * If no implementation is provided then Handlebars will be picked as a default implementation. + * If no implementation is provided then Handlebars will be picked as a default + * implementation. * * @author Marcin Grzejszczak * @since 1.1.0 */ public interface ContractTemplate { + /** - * Asserts whether the given text starts with proper opening template + * @param text text to assert + * @return asserts whether the given text starts with proper opening template. */ default boolean startsWithTemplate(String text) { return text.startsWith(openingTemplate()); } /** - * Asserts whether the given text starts with proper opening template for escaped value + * @param text text to assert + * @return asserts whether the given text starts with proper opening template for + * escaped value. */ default boolean startsWithEscapedTemplate(String text) { return text.startsWith(escapedOpeningTemplate()); } /** - * Handlebars is using the Mustache template thus it looks like this - * {{ Mustache }}. In this case the opening template would return {{ + * Handlebars is using the Mustache template thus it looks like this {{ Mustache }}. + * In this case the opening template would return {{ + * @return opening template for a variable */ String openingTemplate(); /** - * Handlebars is using the Mustache template thus it looks like this - * {{ Mustache }}. In this case the closing template would return }} + * Handlebars is using the Mustache template thus it looks like this {{ Mustache }}. + * In this case the closing template would return }} + * @return closing template for a variable */ String closingTemplate(); /** - * Handlebars is using the Mustache template thus it looks like this - * {{{ Mustache }}}. In this case the opening template would return {{{ + * Handlebars is using the Mustache template thus it looks like this {{{ Mustache }}}. + * In this case the opening template would return {{{ + * @return escaped opening template for a variable */ default String escapedOpeningTemplate() { return openingTemplate(); } /** - * Handlebars is using the Mustache template thus it looks like this - * {{{ Mustache }}}. In this case the closing template would return }}} + * Handlebars is using the Mustache template thus it looks like this {{{ Mustache }}}. + * In this case the closing template would return }}} + * @return escaped closing template for a variable */ default String escapedClosingTemplate() { return closingTemplate(); } /** - * Returns the template for retrieving a URL path and query from request + * @return returns the template for retrieving a URL path and query from request */ String url(); /** - * Returns the template for retrieving first value of a query parameter e.g. {{ request.query.search }} - * - * @param key + * @param key query parameter key + * @return the template for retrieving first value of a query parameter e.g. {{ + * request.query.search }} */ String query(String key); /** - * Returns the template for retrieving nth value of a query parameter (zero indexed) e.g. {{ request.query.search.[5] }} - * - * @param key - * @param index + * @param key query parameter key + * @param index query parameter index + * @return the template for retrieving nth value of a query parameter (zero indexed) + * e.g. {{ request.query.search.[5] }} */ String query(String key, int index); /** - * Returns the template for retrieving a URL path + * @return the template for retrieving a URL path */ String path(); /** - * Returns the template for retrieving nth value of a URL path (zero indexed) e.g. {{ request.path.[2] }} - * - * @param index + * @param index request path index + * @return the template for retrieving nth value of a URL path (zero indexed) e.g. {{ + * request.path.[2] }} */ String path(int index); /** - * Returns the template for retrieving the first value of a request header e.g. {{ request.headers.X-Request-Id }} - * - * @param key + * @param key headers key + * @return the template for retrieving the first value of a request header e.g. {{ + * request.headers.X-Request-Id }} */ String header(String key); /** - * Returns the template for retrieving the nth value of a request header (zero indexed) e.g. {{ request.headers.X-Request-Id.[5] }} - * - * @param key - * @param index + * @param key headers key + * @param index headers index + * @return the template for retrieving the nth value of a request header (zero + * indexed) e.g. {{ request.headers.X-Request-Id.[5] }} */ String header(String key, int index); /** - * Retruns the template for retrieving the first value of a cookie with certain key - * - * @param key + * @param key cookie key + * @return the template for retrieving the first value of a cookie with certain key */ String cookie(String key); /** - * Request body text (avoid for non-text bodies) e.g. {{ request.body }} . The body will not be escaped - * so you won't be able to directly embed it in a JSON for example. + * @return request body text (avoid for non-text bodies) e.g. {{ request.body }} . The + * body will not be escaped so you won't be able to directly embed it in a JSON for + * example. */ String body(); /** - * Request body text for the given JsonPath. e.g. {{ jsonPath request.body '$.a.b.c' }} + * @param jsonPath json path value + * @return request body text for the given JsonPath. e.g. {{ jsonPath request.body + * '$.a.b.c' }} */ String body(String jsonPath); /** - * Returns the template for retrieving a escaped URL path and query from request + * @return the template for retrieving a escaped URL path and query from request */ default String escapedUrl() { return url(); } /** - * Returns the template for retrieving escaped first value of a query parameter e.g. {{{ request.query.search }}} - * - * @param key + * @param key query parameter key + * @return the template for retrieving escaped first value of a query parameter e.g. + * {{{ request.query.search }}} */ default String escapedQuery(String key) { return query(key); } /** - * Returns the template for retrieving esacped nth value of a query parameter (zero indexed) e.g. {{{ request.query.search.[5] }}} - * - * @param key - * @param index + * @param key query parameter key + * @param index query parameter index + * @return the template for retrieving esacped nth value of a query parameter (zero + * indexed) e.g. {{{ request.query.search.[5] }}} */ default String escapedQuery(String key, int index) { return query(key, index); } /** - * Returns the template for retrieving a escaped URL path + * @return the template for retrieving a escaped URL path */ default String escapedPath() { return path(); } /** - * Returns the template for retrieving escaped nth value of a URL path (zero indexed) e.g. {{{ request.path.[2] }}} - * - * @param index + * @param index path index + * @return the template for retrieving escaped nth value of a URL path (zero indexed) + * e.g. {{{ request.path.[2] }}} */ default String escapedPath(int index) { return path(index); } /** - * Returns the template for retrieving the escaped first value of a request header e.g. {{{ request.headers.X-Request-Id }}} - * - * @param key + * @param key headers key + * @return the template for retrieving the escaped first value of a request header + * e.g. {{{ request.headers.X-Request-Id }}} */ default String escapedHeader(String key) { return header(key); } /** - * Returns the template for retrieving the esacaped nth value of a request header (zero indexed) e.g. {{{ request.headers.X-Request-Id.[5] }}} - * - * @param key - * @param index + * @param key headers key + * @param index headers index + * @return the template for retrieving the esacaped nth value of a request header + * (zero indexed) e.g. {{{ request.headers.X-Request-Id.[5] }}} */ default String escapedHeader(String key, int index) { return header(key, index); } /** - * Retruns the template for retrieving the escaped first value of a cookie with certain key - * - * @param key + * @param key cookie key + * @return the template for retrieving the escaped first value of a cookie with + * certain key */ default String escapedCookie(String key) { return cookie(key); } /** - * Request body text (avoid for non-text bodies) e.g. {{{ request.body }}} . The body will not be escaped - * so you won't be able to directly embed it in a JSON for example. + * @return request body text (avoid for non-text bodies) e.g. {{{ request.body }}} . + * The body will not be escaped so you won't be able to directly embed it in a JSON + * for example. */ default String escapedBody() { return body(); } /** - * Request body text for the given JsonPath. e.g. {{{ jsonPath request.body '$.a.b.c' }}} + * @param jsonPath json path value + * @return request body text for the given JsonPath. e.g. {{{ jsonPath request.body + * '$.a.b.c' }}} */ default String escapedBody(String jsonPath) { return body(jsonPath); diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/ContractVerifierException.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/ContractVerifierException.groovy index 8c22210a52..f8131c94eb 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/ContractVerifierException.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/ContractVerifierException.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Body.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Body.groovy index 1a25fb0cb9..959113907e 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Body.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Body.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal @@ -31,7 +31,8 @@ import groovy.transform.ToString class Body extends DslProperty { Body(Map body) { - super(extractValue(body, { p -> p instanceof DslProperty ? ((DslProperty) p).clientValue : p }), + super( + extractValue(body, { p -> p instanceof DslProperty ? ((DslProperty) p).clientValue : p }), extractValue(body, { p -> p instanceof DslProperty ? ((DslProperty) p).serverValue : p })) } @@ -42,7 +43,8 @@ class Body extends DslProperty { } Body(List bodyAsList) { - super(bodyAsList.collect { DslProperty p -> p.clientValue }, bodyAsList.collect { DslProperty p -> p.serverValue }) + super(bodyAsList.collect { DslProperty p -> p.clientValue }, bodyAsList. + collect { DslProperty p -> p.serverValue }) } Body(Object bodyAsValue) { @@ -77,5 +79,4 @@ class Body extends DslProperty { super(matchingStrategy, matchingStrategy) } - } diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/BodyMatcher.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/BodyMatcher.groovy index fa67876b5f..188445921d 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/BodyMatcher.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/BodyMatcher.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal @@ -52,4 +52,4 @@ interface BodyMatcher { * Max no of occurrence when matching by type. In all other cases it will be ignored */ Integer maxTypeOccurrence() -} \ No newline at end of file +} diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/BodyMatchers.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/BodyMatchers.groovy index 79773607d3..7e494bc0bc 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/BodyMatchers.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/BodyMatchers.groovy @@ -1,18 +1,19 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal import java.util.regex.Pattern @@ -21,6 +22,7 @@ import groovy.transform.Canonical import groovy.transform.CompileStatic import groovy.transform.EqualsAndHashCode import groovy.transform.ToString + /** * Matching strategy of dynamic parts of the body. * @@ -48,7 +50,7 @@ class BodyMatchers { } /** - * @deprecated use {@link #matchers()} + * @deprecated use{@link #matchers()} */ @Deprecated List jsonPathMatchers() { @@ -72,7 +74,8 @@ class BodyMatchers { } MatchingTypeValue byTimestamp() { - return new MatchingTypeValue(MatchingType.TIMESTAMP, this.regexPatterns.isoDateTime()) + return new MatchingTypeValue(MatchingType.TIMESTAMP, this.regexPatterns. + isoDateTime()) } RegexMatchingTypeValue byRegex(String regex) { @@ -101,13 +104,21 @@ class BodyMatchers { } boolean equals(o) { - if (this.is(o)) return true - if (this.getClass() != o.class) return false + if (this.is(o)) { + return true + } + if (this.getClass() != o.class) { + return false + } BodyMatchers that = (BodyMatchers) o List thisMatchers = this.matchers List thatMatchers = that.matchers - if (thisMatchers.size() != thatMatchers.size()) return false - if (new HashSet<>(thisMatchers) != new HashSet(thatMatchers)) return false + if (thisMatchers.size() != thatMatchers.size()) { + return false + } + if (new HashSet<>(thisMatchers) != new HashSet(thatMatchers)) { + return false + } return true } @@ -216,4 +227,4 @@ class MatchingTypeValueHolder { this.matchingTypeValue.maxTypeOccurrence = number return this.matchingTypeValue } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/CanBeDynamic.java b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/CanBeDynamic.java index da82cba30b..87add6126f 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/CanBeDynamic.java +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/CanBeDynamic.java @@ -1,31 +1,33 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT 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.spec.internal; /** - * Some properties can contain dynamic values. - * If that's the case we need to know how to generate a concrete value for them. + * Some properties can contain dynamic values. If that's the case we need to know how to + * generate a concrete value for them. * + * @author Marcin Grzejszczak * @since 2.1.0 */ public interface CanBeDynamic { + /** * @return a generated, concrete value */ Object generateConcreteValue(); + } diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/ClientDslProperty.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/ClientDslProperty.groovy index 6212e6dc78..9f35b16f5a 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/ClientDslProperty.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/ClientDslProperty.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Common.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Common.groovy index e0a0332bb7..f34fc3079a 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Common.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Common.groovy @@ -1,27 +1,26 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal import java.nio.charset.Charset +import java.util.regex.Pattern import groovy.transform.TypeChecked -import java.util.regex.Pattern - /** * Contains useful common methods for the DSL. * @@ -33,7 +32,8 @@ import java.util.regex.Pattern @TypeChecked class Common { - @Delegate private final RegexPatterns regexPatterns = new RegexPatterns() + @Delegate + private final RegexPatterns regexPatterns = new RegexPatterns() Map convertObjectsToDslProperties(Map body) { return body.collectEntries { @@ -68,7 +68,7 @@ class Common { return property } - NamedProperty named(DslProperty name, DslProperty value){ + NamedProperty named(DslProperty name, DslProperty value) { return new NamedProperty(name, value) } @@ -76,7 +76,7 @@ class Common { return new NamedProperty(name, value, contentType) } - NamedProperty named(Map namedMap){ + NamedProperty named(Map namedMap) { return new NamedProperty(namedMap) } @@ -217,7 +217,8 @@ class Common { * @return file contents as an array of bytes */ private File fileLocation(String relativePath) { - URL resource = Thread.currentThread().getContextClassLoader().getResource(relativePath) + URL resource = Thread.currentThread().getContextClassLoader(). + getResource(relativePath) if (resource == null) { throw new IllegalStateException("File [${relativePath}] is not present") } @@ -268,4 +269,4 @@ class Common { void assertThatSidesMatch(Object firstSide, Object secondSide) { // do nothing } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/CompositeContractTemplate.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/CompositeContractTemplate.groovy index 08397e4438..3f7c0b25e1 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/CompositeContractTemplate.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/CompositeContractTemplate.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal import groovy.transform.CompileStatic diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Cookie.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Cookie.groovy index 8ce3f7f4a0..79095adce0 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Cookie.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Cookie.groovy @@ -1,49 +1,50 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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.spec.internal -import groovy.transform.CompileStatic -import groovy.transform.EqualsAndHashCode -import groovy.transform.ToString - -/** - * Represents a http cookie - * - * @author Alex Xandra Albert Sim - * @since 1.2.5 - */ -@EqualsAndHashCode(includeFields = true, callSuper = true) -@ToString(includePackage = false, includeFields = true, ignoreNulls = true, includeNames = true, includeSuper = true) -@CompileStatic -class Cookie extends DslProperty { - - String key - - Cookie(String key, DslProperty dslProperty) { - super(dslProperty.clientValue, dslProperty.serverValue) - this.key = key - } - - Cookie(String key, MatchingStrategy value) { - super(value) - this.key = key - } - - Cookie(String key, Object value) { - super(value) - this.key = key - } -} +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal + +import groovy.transform.CompileStatic +import groovy.transform.EqualsAndHashCode +import groovy.transform.ToString + +/** + * Represents a http cookie + * + * @author Alex Xandra Albert Sim + * @since 1.2.5 + */ +@EqualsAndHashCode(includeFields = true, callSuper = true) +@ToString(includePackage = false, includeFields = true, ignoreNulls = true, includeNames = true, includeSuper = true) +@CompileStatic +class Cookie extends DslProperty { + + String key + + Cookie(String key, DslProperty dslProperty) { + super(dslProperty.clientValue, dslProperty.serverValue) + this.key = key + } + + Cookie(String key, MatchingStrategy value) { + super(value) + this.key = key + } + + Cookie(String key, Object value) { + super(value) + this.key = key + } +} diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Cookies.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Cookies.groovy index 42ef282c60..c910913eb6 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Cookies.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Cookies.groovy @@ -1,90 +1,98 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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.spec.internal - -import groovy.transform.EqualsAndHashCode -import groovy.transform.ToString -import groovy.transform.TypeChecked - -/** - * Represents a set of http cookies - * - * @author Alex Xandra Albert Sim - * @since 1.2.5 - */ -@EqualsAndHashCode(includeFields = true) -@ToString(includePackage = false, includeFields = true, ignoreNulls = true, includeNames = true) -@TypeChecked -class Cookies { - - Set entries = [] - - void cookie(Map singleCookie) { - Map.Entry first = singleCookie.entrySet().first() - entries << new Cookie(first?.key, first?.value) - } - - void cookie(String cookieKey, Object cookieValue) { - entries << new Cookie(cookieKey, cookieValue) - } - - void executeForEachCookie(Closure closure) { - entries?.each { - cookie -> closure(cookie) - } - } - - DslProperty matching(String value) { - return new DslProperty(value) - } - - boolean equals(o) { - if (this.is(o)) return true - if (getClass() != o.class) return false - Cookies cookies = (Cookies) o - if (cookies != cookies.entries) return false - return true - } - - int hashCode() { - return entries.hashCode() - } - - /** - * 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, Cookie cookie -> - map[cookie.key] = cookie.clientValue - return map - } as Map - } - - /** - * Converts the headers into their stub side representations and returns as - * a map of String key => Object value. - */ - Map asTestSideMap() { - def acc = [:].withDefault { [] as Collection } - return entries.inject(acc as Map) { Map map, Cookie cookie -> - map[cookie.key] = cookie.serverValue - return map - } as Map - } -} +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal + +import groovy.transform.EqualsAndHashCode +import groovy.transform.ToString +import groovy.transform.TypeChecked + +/** + * Represents a set of http cookies + * + * @author Alex Xandra Albert Sim + * @since 1.2.5 + */ +@EqualsAndHashCode(includeFields = true) +@ToString(includePackage = false, includeFields = true, ignoreNulls = true, includeNames = true) +@TypeChecked +class Cookies { + + Set entries = [] + + void cookie(Map singleCookie) { + Map.Entry first = singleCookie.entrySet().first() + entries << new Cookie(first?.key, first?.value) + } + + void cookie(String cookieKey, Object cookieValue) { + entries << new Cookie(cookieKey, cookieValue) + } + + void executeForEachCookie(Closure closure) { + entries?.each { + cookie -> closure(cookie) + } + } + + DslProperty matching(String value) { + return new DslProperty(value) + } + + boolean equals(o) { + if (this.is(o)) { + return true + } + if (getClass() != o.class) { + return false + } + Cookies cookies = (Cookies) o + if (cookies != cookies.entries) { + return false + } + return true + } + + int hashCode() { + return entries.hashCode() + } + + /** + * 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, Cookie cookie -> + map[cookie.key] = cookie.clientValue + return map + } as Map + } + + /** + * Converts the headers into their stub side representations and returns as + * a map of String key => Object value. + */ + Map asTestSideMap() { + def acc = [:].withDefault { [] as Collection } + return entries. + inject(acc as Map) { Map map, Cookie cookie -> + map[cookie.key] = cookie.serverValue + return map + } as Map + } +} diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/CustomHandlebarsContractTemplate.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/CustomHandlebarsContractTemplate.groovy index 2598aace44..30896fa35e 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/CustomHandlebarsContractTemplate.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/CustomHandlebarsContractTemplate.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal import groovy.transform.CompileStatic @@ -10,9 +26,8 @@ import org.springframework.cloud.contract.spec.ContractTemplate * WireMock template model requirements. * * @author Marcin Grzejszczak - * @since 1.1.0 - * - * @deprecated use {@link HandlebarsContractTemplate} + * @since 1.1.0* + * @deprecated use{@link HandlebarsContractTemplate} */ @CompileStatic @PackageScope diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/DslProperty.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/DslProperty.groovy index 97ae01e08e..f46488fb88 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/DslProperty.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/DslProperty.groovy @@ -1,23 +1,24 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal import groovy.transform.CompileStatic import groovy.transform.ToString + /** * Represents an element of a DSL that can contain client or sever side values * @@ -42,23 +43,33 @@ class DslProperty implements Serializable { boolean isSingleValue() { return this.clientValue == this.serverValue || - (this.clientValue != null && this.serverValue == null ) || - (this.serverValue != null && this.clientValue == null ) + (this.clientValue != null && this.serverValue == null) || + (this.serverValue != null && this.clientValue == null) } boolean equals(o) { - if (this.is(o)) return true - if (getClass() != o.class) return false + if (this.is(o)) { + return true + } + if (getClass() != o.class) { + return false + } DslProperty that = (DslProperty) o - if (this.clientValue != that.clientValue) return false - if (this.serverValue != that.serverValue) return false + if (this.clientValue != that.clientValue) { + return false + } + if (this.serverValue != that.serverValue) { + return false + } return true } int hashCode() { int result result = (this.clientValue != null ? this.clientValue.hashCode() : 0) - result = 31 * result + (this.serverValue != null ? this.serverValue.hashCode() : 0) + result = 31 * result + +(this.serverValue != null ? this.serverValue. + hashCode() : 0) return result } } diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/ExecutionProperty.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/ExecutionProperty.groovy index e4bfc84355..912964e795 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/ExecutionProperty.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/ExecutionProperty.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/FromFileProperty.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/FromFileProperty.groovy index 0d25a805ef..cafd034faa 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/FromFileProperty.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/FromFileProperty.groovy @@ -1,27 +1,27 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal +import java.nio.charset.Charset + import groovy.transform.CompileStatic import groovy.transform.EqualsAndHashCode import groovy.transform.ToString -import java.nio.charset.Charset - /** * Represents a property that will become a File content * diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/FromRequest.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/FromRequest.groovy index 289e1f8d1c..13b8ba478a 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/FromRequest.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/FromRequest.groovy @@ -1,6 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal import groovy.transform.CompileStatic + import org.springframework.cloud.contract.spec.ContractTemplate /** @@ -54,8 +71,7 @@ class FromRequest { } /** - * nth value of a URL path (zero indexed) e.g. {{{ request.path.[2] }}} - * @param index + * nth value of a URL path (zero indexed) e.g. {{{ request.path.[2] }}}* @param index */ DslProperty path(int index) { return new DslProperty(template.escapedPath(index)) @@ -131,8 +147,7 @@ class FromRequest { } /** - * Unescaped nth value of a URL path (zero indexed) e.g. {{{ request.path.[2] }}} - * @param index + * Unescaped nth value of a URL path (zero indexed) e.g. {{{ request.path.[2] }}}* @param index */ DslProperty rawPath(int index) { return new DslProperty(template.path(index)) diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/HandlebarsContractTemplate.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/HandlebarsContractTemplate.groovy index 73b5270e2a..c20e416bba 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/HandlebarsContractTemplate.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/HandlebarsContractTemplate.groovy @@ -1,6 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal import groovy.transform.CompileStatic + import org.springframework.cloud.contract.spec.ContractTemplate /** diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Header.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Header.groovy index b2e356eaba..1cba525098 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Header.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Header.groovy @@ -1,20 +1,21 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal + import groovy.transform.CompileStatic import groovy.transform.EqualsAndHashCode import groovy.transform.ToString diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Headers.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Headers.groovy index 03cc579b5e..27cf0ab526 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Headers.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Headers.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal @@ -34,9 +34,12 @@ import groovy.transform.stc.SimpleType @TypeChecked class Headers { - @Delegate MediaTypes mediaTypes = new MediaTypes() - @Delegate HttpHeaders httpHeaders = new HttpHeaders() - @Delegate MessagingHeaders messagingHeaders = new MessagingHeaders() + @Delegate + MediaTypes mediaTypes = new MediaTypes() + @Delegate + HttpHeaders httpHeaders = new HttpHeaders() + @Delegate + MessagingHeaders messagingHeaders = new MessagingHeaders() Set
entries = [] @@ -88,23 +91,24 @@ class Headers { /** * Converts the headers via the provided closure */ - Map asMap(@ClosureParams(value = SimpleType.class, + Map asMap(@ClosureParams(value = SimpleType.class, options = [ "java.lang.String", "org.springframework.cloud.contract.spec.internal.DslProperty" ]) Closure closure) { def acc = [:].withDefault { [] as Collection } - return entries.inject(acc as Map) { Map map, Header header -> - map[header.name] = closure(header.name, header) - return map - } as Map + return entries. + inject(acc as Map) { Map map, Header header -> + map[header.name] = closure(header.name, header) + return map + } as Map } /** * Converts the headers into their stub side representations and returns as * a map of String key => Object value. */ - Map asStubSideMap() { + Map asStubSideMap() { return asMap({ String headerName, DslProperty prop -> prop.clientValue }) } @@ -112,15 +116,21 @@ class Headers { * Converts the headers into their stub side representations and returns as * a map of String key => Object value. */ - Map asTestSideMap() { + Map asTestSideMap() { return asMap({ String headerName, DslProperty prop -> prop.serverValue }) } boolean equals(o) { - if (this.is(o)) return true - if (getClass() != o.class) return false + if (this.is(o)) { + return true + } + if (getClass() != o.class) { + return false + } Headers headers = (Headers) o - if (entries != headers.entries) return false + if (entries != headers.entries) { + return false + } return true } diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/HttpHeaders.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/HttpHeaders.groovy index dfed48b49d..fac6128e6f 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/HttpHeaders.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/HttpHeaders.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal import groovy.transform.CompileStatic @@ -17,119 +33,119 @@ class HttpHeaders { /** * The HTTP {@code Accept} header field name. - * @see Section 5.3.2 of RFC 7231 + * @see Section 5.3.2 of RFC 7231 */ String accept() { return "Accept" } /** * The HTTP {@code Accept-Charset} header field name. - * @see Section 5.3.3 of RFC 7231 + * @see Section 5.3.3 of RFC 7231 */ String acceptCharset() { return "Accept-Charset" } /** * The HTTP {@code Accept-Encoding} header field name. - * @see Section 5.3.4 of RFC 7231 + * @see Section 5.3.4 of RFC 7231 */ String acceptEncoding() { return "Accept-Encoding" } /** * The HTTP {@code Accept-Language} header field name. - * @see Section 5.3.5 of RFC 7231 + * @see Section 5.3.5 of RFC 7231 */ String acceptLanguage() { return "Accept-Language" } /** * The HTTP {@code Accept-Ranges} header field name. - * @see Section 5.3.5 of RFC 7233 + * @see Section 5.3.5 of RFC 7233 */ String acceptRanges() { return "Accept-Ranges" } /** * The CORS {@code Access-Control-Allow-Credentials} response header field name. - * @see CORS W3C recommendation + * @see CORS W3C recommendation */ String accessControlAllowCredentials() { return "Access-Control-Allow-Credentials" } /** * The CORS {@code Access-Control-Allow-Headers} response header field name. - * @see CORS W3C recommendation + * @see CORS W3C recommendation */ String accessControlAllowHeaders() { return "Access-Control-Allow-Headers" } /** * The CORS {@code Access-Control-Allow-Methods} response header field name. - * @see CORS W3C recommendation + * @see CORS W3C recommendation */ String accessControlAllowMethods() { return "Access-Control-Allow-Methods" } /** * The CORS {@code Access-Control-Allow-Origin} response header field name. - * @see CORS W3C recommendation + * @see CORS W3C recommendation */ String accessControlAllowOrigin() { return "Access-Control-Allow-Origin" } /** * The CORS {@code Access-Control-Expose-Headers} response header field name. - * @see CORS W3C recommendation + * @see CORS W3C recommendation */ String accessControlExposeHeaders() { return "Access-Control-Expose-Headers" } /** * The CORS {@code Access-Control-Max-Age} response header field name. - * @see CORS W3C recommendation + * @see CORS W3C recommendation */ String accessControlMaxAge() { return "Access-Control-Max-Age" } /** * The CORS {@code Access-Control-Request-Headers} request header field name. - * @see CORS W3C recommendation + * @see CORS W3C recommendation */ String accessControlRequestHeaders() { return "Access-Control-Request-Headers" } /** * The CORS {@code Access-Control-Request-Method} request header field name. - * @see CORS W3C recommendation + * @see CORS W3C recommendation */ String accessControlRequestMethod() { return "Access-Control-Request-Method" } /** * The HTTP {@code Age} header field name. - * @see Section 5.1 of RFC 7234 + * @see Section 5.1 of RFC 7234 */ String age() { return "Age" } /** * The HTTP {@code Allow} header field name. - * @see Section 7.4.1 of RFC 7231 + * @see Section 7.4.1 of RFC 7231 */ String allow() { return "Allow" } /** * The HTTP {@code Authorization} header field name. - * @see Section 4.2 of RFC 7235 + * @see Section 4.2 of RFC 7235 */ String authorization() { return "Authorization" } /** * The HTTP {@code Cache-Control} header field name. - * @see Section 5.2 of RFC 7234 + * @see Section 5.2 of RFC 7234 */ String cacheControl() { return "Cache-Control" @@ -137,7 +153,7 @@ class HttpHeaders { /** * The HTTP {@code Connection} header field name. - * @see Section 6.1 of RFC 7230 + * @see Section 6.1 of RFC 7230 */ String connection() { return "Connection" @@ -145,7 +161,7 @@ class HttpHeaders { /** * The HTTP {@code Content-Encoding} header field name. - * @see Section 3.1.2.2 of RFC 7231 + * @see Section 3.1.2.2 of RFC 7231 */ String contentEncoding() { return "Content-Encoding" @@ -153,7 +169,7 @@ class HttpHeaders { /** * The HTTP {@code Content-Disposition} header field name - * @see RFC 6266 + * @see RFC 6266 */ String contentDisposition() { return "Content-Disposition" @@ -161,7 +177,7 @@ class HttpHeaders { /** * The HTTP {@code Content-Language} header field name. - * @see Section 3.1.3.2 of RFC 7231 + * @see Section 3.1.3.2 of RFC 7231 */ String contentLanguage() { return "Content-Language" @@ -169,7 +185,7 @@ class HttpHeaders { /** * The HTTP {@code Content-Length} header field name. - * @see Section 3.3.2 of RFC 7230 + * @see Section 3.3.2 of RFC 7230 */ String contentLength() { return "Content-Length" @@ -177,7 +193,7 @@ class HttpHeaders { /** * The HTTP {@code Content-Location} header field name. - * @see Section 3.1.4.2 of RFC 7231 + * @see Section 3.1.4.2 of RFC 7231 */ String contentLocation() { return "Content-Location" @@ -185,7 +201,7 @@ class HttpHeaders { /** * The HTTP {@code Content-Range} header field name. - * @see Section 4.2 of RFC 7233 + * @see Section 4.2 of RFC 7233 */ String contentRange() { return "Content-Range" @@ -193,7 +209,7 @@ class HttpHeaders { /** * The HTTP {@code Content-Type} header field name. - * @see Section 3.1.1.5 of RFC 7231 + * @see Section 3.1.1.5 of RFC 7231 */ String contentType() { return "Content-Type" @@ -201,7 +217,7 @@ class HttpHeaders { /** * The HTTP {@code Cookie} header field name. - * @see Section 4.3.4 of RFC 2109 + * @see Section 4.3.4 of RFC 2109 */ String cookie() { return "Cookie" @@ -209,7 +225,7 @@ class HttpHeaders { /** * The HTTP {@code Date} header field name. - * @see Section 7.1.1.2 of RFC 7231 + * @see Section 7.1.1.2 of RFC 7231 */ String date() { return "Date" @@ -217,7 +233,7 @@ class HttpHeaders { /** * The HTTP {@code ETag} header field name. - * @see Section 2.3 of RFC 7232 + * @see Section 2.3 of RFC 7232 */ String etag() { return "ETag" @@ -225,7 +241,7 @@ class HttpHeaders { /** * The HTTP {@code Expect} header field name. - * @see Section 5.1.1 of RFC 7231 + * @see Section 5.1.1 of RFC 7231 */ String expect() { return "Expect" @@ -233,7 +249,7 @@ class HttpHeaders { /** * The HTTP {@code Expires} header field name. - * @see Section 5.3 of RFC 7234 + * @see Section 5.3 of RFC 7234 */ String expires() { return "Expires" @@ -241,7 +257,7 @@ class HttpHeaders { /** * The HTTP {@code From} header field name. - * @see Section 5.5.1 of RFC 7231 + * @see Section 5.5.1 of RFC 7231 */ String from() { return "From" @@ -249,7 +265,7 @@ class HttpHeaders { /** * The HTTP {@code Host} header field name. - * @see Section 5.4 of RFC 7230 + * @see Section 5.4 of RFC 7230 */ String host() { return "Host" @@ -257,7 +273,7 @@ class HttpHeaders { /** * The HTTP {@code If-Match} header field name. - * @see Section 3.1 of RFC 7232 + * @see Section 3.1 of RFC 7232 */ String ifMatch() { return "If-Match" @@ -265,7 +281,7 @@ class HttpHeaders { /** * The HTTP {@code If-Modified-Since} header field name. - * @see Section 3.3 of RFC 7232 + * @see Section 3.3 of RFC 7232 */ String ifModifiedSince() { return "If-Modified-Since" @@ -273,7 +289,7 @@ class HttpHeaders { /** * The HTTP {@code If-None-Match} header field name. - * @see Section 3.2 of RFC 7232 + * @see Section 3.2 of RFC 7232 */ String ifNoneMatch() { return "If-None-Match" @@ -281,7 +297,7 @@ class HttpHeaders { /** * The HTTP {@code If-Range} header field name. - * @see Section 3.2 of RFC 7233 + * @see Section 3.2 of RFC 7233 */ String ifRange() { return "If-Range" @@ -289,7 +305,7 @@ class HttpHeaders { /** * The HTTP {@code If-Unmodified-Since} header field name. - * @see Section 3.4 of RFC 7232 + * @see Section 3.4 of RFC 7232 */ String ifUnmodifiedSince() { return "If-Unmodified-Since" @@ -297,7 +313,7 @@ class HttpHeaders { /** * The HTTP {@code Last-Modified} header field name. - * @see Section 2.2 of RFC 7232 + * @see Section 2.2 of RFC 7232 */ String lastModified() { return "Last-Modified" @@ -305,7 +321,7 @@ class HttpHeaders { /** * The HTTP {@code Link} header field name. - * @see RFC 5988 + * @see RFC 5988 */ String link() { return "Link" @@ -313,7 +329,7 @@ class HttpHeaders { /** * The HTTP {@code Location} header field name. - * @see Section 7.1.2 of RFC 7231 + * @see Section 7.1.2 of RFC 7231 */ String location() { return "Location" @@ -321,14 +337,14 @@ class HttpHeaders { /** * The HTTP {@code Max-Forwards} header field name. - * @see Section 5.1.2 of RFC 7231 + * @see Section 5.1.2 of RFC 7231 */ String max_forwards() { return "Max-Forwards" } /** * The HTTP {@code Origin} header field name. - * @see RFC 6454 + * @see RFC 6454 */ String origin() { return "Origin" @@ -336,7 +352,7 @@ class HttpHeaders { /** * The HTTP {@code Pragma} header field name. - * @see Section 5.4 of RFC 7234 + * @see Section 5.4 of RFC 7234 */ String pragma() { return "Pragma" @@ -344,7 +360,7 @@ class HttpHeaders { /** * The HTTP {@code Proxy-Authenticate} header field name. - * @see Section 4.3 of RFC 7235 + * @see Section 4.3 of RFC 7235 */ String proxyAuthenticate() { return "Proxy-Authenticate" @@ -352,7 +368,7 @@ class HttpHeaders { /** * The HTTP {@code Proxy-Authorization} header field name. - * @see Section 4.4 of RFC 7235 + * @see Section 4.4 of RFC 7235 */ String proxyAuthorization() { return "Proxy-Authorization" @@ -360,7 +376,7 @@ class HttpHeaders { /** * The HTTP {@code Range} header field name. - * @see Section 3.1 of RFC 7233 + * @see Section 3.1 of RFC 7233 */ String range() { return "Range" @@ -368,7 +384,7 @@ class HttpHeaders { /** * The HTTP {@code Referer} header field name. - * @see Section 5.5.2 of RFC 7231 + * @see Section 5.5.2 of RFC 7231 */ String referer() { return "Referer" @@ -376,7 +392,7 @@ class HttpHeaders { /** * The HTTP {@code Retry-After} header field name. - * @see Section 7.1.3 of RFC 7231 + * @see Section 7.1.3 of RFC 7231 */ String retryAfter() { return "Retry-After" @@ -384,7 +400,7 @@ class HttpHeaders { /** * The HTTP {@code Server} header field name. - * @see Section 7.4.2 of RFC 7231 + * @see Section 7.4.2 of RFC 7231 */ String server() { return "Server" @@ -392,7 +408,7 @@ class HttpHeaders { /** * The HTTP {@code Set-Cookie} header field name. - * @see Section 4.2.2 of RFC 2109 + * @see Section 4.2.2 of RFC 2109 */ String setCookie() { return "Set-Cookie" @@ -400,7 +416,7 @@ class HttpHeaders { /** * The HTTP {@code Set-Cookie2} header field name. - * @see RFC 2965 + * @see RFC 2965 */ String setCookie2() { return "Set-Cookie2" @@ -408,7 +424,7 @@ class HttpHeaders { /** * The HTTP {@code TE} header field name. - * @see Section 4.3 of RFC 7230 + * @see Section 4.3 of RFC 7230 */ String te() { return "TE" @@ -416,7 +432,7 @@ class HttpHeaders { /** * The HTTP {@code Trailer} header field name. - * @see Section 4.4 of RFC 7230 + * @see Section 4.4 of RFC 7230 */ String trailer() { return "Trailer" @@ -424,7 +440,7 @@ class HttpHeaders { /** * The HTTP {@code Transfer-Encoding} header field name. - * @see Section 3.3.1 of RFC 7230 + * @see Section 3.3.1 of RFC 7230 */ String transferEncoding() { return "Transfer-Encoding" @@ -432,7 +448,7 @@ class HttpHeaders { /** * The HTTP {@code Upgrade} header field name. - * @see Section 6.7 of RFC 7230 + * @see Section 6.7 of RFC 7230 */ String upgrade() { return "Upgrade" @@ -440,7 +456,7 @@ class HttpHeaders { /** * The HTTP {@code User-Agent} header field name. - * @see Section 5.5.3 of RFC 7231 + * @see Section 5.5.3 of RFC 7231 */ String user_agent() { return "User-Agent" @@ -448,7 +464,7 @@ class HttpHeaders { /** * The HTTP {@code Vary} header field name. - * @see Section 7.1.4 of RFC 7231 + * @see Section 7.1.4 of RFC 7231 */ String vary() { return "Vary" @@ -456,7 +472,7 @@ class HttpHeaders { /** * The HTTP {@code Via} header field name. - * @see Section 5.7.1 of RFC 7230 + * @see Section 5.7.1 of RFC 7230 */ String via() { return "Via" @@ -464,7 +480,7 @@ class HttpHeaders { /** * The HTTP {@code Warning} header field name. - * @see Section 5.5 of RFC 7234 + * @see Section 5.5 of RFC 7234 */ String warning() { return "Warning" @@ -472,7 +488,7 @@ class HttpHeaders { /** * The HTTP {@code WWW-Authenticate} header field name. - * @see Section 4.1 of RFC 7235 + * @see Section 4.1 of RFC 7235 */ String wwwAuthenticate() { return "WWW-Authenticate" diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/HttpMethods.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/HttpMethods.groovy index 29ec3c7fe3..f4e7403030 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/HttpMethods.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/HttpMethods.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal import groovy.transform.CompileStatic diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/HttpStatus.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/HttpStatus.groovy index 2dbea33264..f2487d63ec 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/HttpStatus.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/HttpStatus.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal import groovy.transform.CompileStatic @@ -5,7 +21,7 @@ import groovy.transform.EqualsAndHashCode /** * Helper functions for HTTP statuses - * + * * @author Marcin Grzejszczak * @since 2.0.0 */ @@ -17,27 +33,27 @@ class HttpStatus { /** * {@code 100 Continue}. - * @see HTTP/1.1: Semantics and Content, section 6.2.1 + * @see HTTP/1.1: Semantics and Content, section 6.2.1 */ int CONTINUE() { return 100 } - + /** * {@code 101 Switching Protocols}. - * @see HTTP/1.1: Semantics and Content, section 6.2.2 + * @see HTTP/1.1: Semantics and Content, section 6.2.2 */ int SWITCHING_PROTOCOLS() { return 101 } /** * {@code 102 Processing}. - * @see WebDAV + * @see WebDAV */ int PROCESSING() { return 102 } /** * {@code 103 Checkpoint}. - * @see A proposal for supporting + * @see A proposal for supporting * resumable POST/PUT HTTP requests in HTTP/1.0 */ int CHECKPOINT() { return 103 } @@ -46,52 +62,52 @@ class HttpStatus { /** * {@code 200 OK}. - * @see HTTP/1.1: Semantics and Content, section 6.3.1 + * @see HTTP/1.1: Semantics and Content, section 6.3.1 */ int OK() { return 200 } /** * {@code 201 Created}. - * @see HTTP/1.1: Semantics and Content, section 6.3.2 + * @see HTTP/1.1: Semantics and Content, section 6.3.2 */ int CREATED() { return 201 } /** * {@code 202 Accepted}. - * @see HTTP/1.1: Semantics and Content, section 6.3.3 + * @see HTTP/1.1: Semantics and Content, section 6.3.3 */ int ACCEPTED() { return 202 } /** * {@code 203 Non-Authoritative Information}. - * @see HTTP/1.1: Semantics and Content, section 6.3.4 + * @see HTTP/1.1: Semantics and Content, section 6.3.4 */ int NON_AUTHORITATIVE_INFORMATION() { return 203 } /** * {@code 204 No Content}. - * @see HTTP/1.1: Semantics and Content, section 6.3.5 + * @see HTTP/1.1: Semantics and Content, section 6.3.5 */ int NO_CONTENT() { return 204 } /** * {@code 205 Reset Content}. - * @see HTTP/1.1: Semantics and Content, section 6.3.6 + * @see HTTP/1.1: Semantics and Content, section 6.3.6 */ int RESET_CONTENT() { return 205 } /** * {@code 206 Partial Content}. - * @see HTTP/1.1: Range Requests, section 4.1 + * @see HTTP/1.1: Range Requests, section 4.1 */ int PARTIAL_CONTENT() { return 206 } /** * {@code 207 Multi-Status}. - * @see WebDAV + * @see WebDAV */ int MULTI_STATUS() { return 207 } /** * {@code 208 Already Reported}. - * @see WebDAV Binding Extensions + * @see WebDAV Binding Extensions */ int ALREADY_REPORTED() { return 208 } /** * {@code 226 IM Used}. - * @see Delta encoding in HTTP + * @see Delta encoding in HTTP */ int IM_USED() { return 226 } @@ -99,51 +115,51 @@ class HttpStatus { /** * {@code 300 Multiple Choices}. - * @see HTTP/1.1: Semantics and Content, section 6.4.1 + * @see HTTP/1.1: Semantics and Content, section 6.4.1 */ int MULTIPLE_CHOICES() { return 300 } /** * {@code 301 Moved Permanently}. - * @see HTTP/1.1: Semantics and Content, section 6.4.2 + * @see HTTP/1.1: Semantics and Content, section 6.4.2 */ int MOVED_PERMANENTLY() { return 301 } /** * {@code 302 Found}. - * @see HTTP/1.1: Semantics and Content, section 6.4.3 + * @see HTTP/1.1: Semantics and Content, section 6.4.3 */ int FOUND() { return 302 } /** * {@code 302 Moved Temporarily}. - * @see HTTP/1.0, section 9.3 + * @see HTTP/1.0, section 9.3 * @deprecated in favor of {@link #FOUND} which will be returned from {@code HttpStatus.valueOf(302)} */ @Deprecated int MOVED_TEMPORARILY() { return 302 } /** * {@code 303 See Other}. - * @see HTTP/1.1: Semantics and Content, section 6.4.4 + * @see HTTP/1.1: Semantics and Content, section 6.4.4 */ int SEE_OTHER() { return 303 } /** * {@code 304 Not Modified}. - * @see HTTP/1.1: Conditional Requests, section 4.1 + * @see HTTP/1.1: Conditional Requests, section 4.1 */ int NOT_MODIFIED() { return 304 } /** * {@code 305 Use Proxy}. - * @see HTTP/1.1: Semantics and Content, section 6.4.5 + * @see HTTP/1.1: Semantics and Content, section 6.4.5 * @deprecated due to security concerns regarding in-band configuration of a proxy */ @Deprecated int USE_PROXY() { return 305 } /** * {@code 307 Temporary Redirect}. - * @see HTTP/1.1: Semantics and Content, section 6.4.7 + * @see HTTP/1.1: Semantics and Content, section 6.4.7 */ int TEMPORARY_REDIRECT() { return 307 } /** * {@code 308 Permanent Redirect}. - * @see RFC 7238 + * @see RFC 7238 */ int PERMANENT_REDIRECT() { return 308 } @@ -151,113 +167,111 @@ class HttpStatus { /** * {@code 400 Bad Request}. - * @see HTTP/1.1: Semantics and Content, section 6.5.1 + * @see HTTP/1.1: Semantics and Content, section 6.5.1 */ int BAD_REQUEST() { return 400 } /** * {@code 401 Unauthorized}. - * @see HTTP/1.1: Authentication, section 3.1 + * @see HTTP/1.1: Authentication, section 3.1 */ int UNAUTHORIZED() { return 401 } /** * {@code 402 Payment Required}. - * @see HTTP/1.1: Semantics and Content, section 6.5.2 + * @see HTTP/1.1: Semantics and Content, section 6.5.2 */ int PAYMENT_REQUIRED() { return 402 } /** * {@code 403 Forbidden}. - * @see HTTP/1.1: Semantics and Content, section 6.5.3 + * @see HTTP/1.1: Semantics and Content, section 6.5.3 */ int FORBIDDEN() { return 403 } /** * {@code 404 Not Found}. - * @see HTTP/1.1: Semantics and Content, section 6.5.4 + * @see HTTP/1.1: Semantics and Content, section 6.5.4 */ int NOT_FOUND() { return 404 } /** * {@code 405 Method Not Allowed}. - * @see HTTP/1.1: Semantics and Content, section 6.5.5 + * @see HTTP/1.1: Semantics and Content, section 6.5.5 */ int METHOD_NOT_ALLOWED() { return 405 } /** * {@code 406 Not Acceptable}. - * @see HTTP/1.1: Semantics and Content, section 6.5.6 + * @see HTTP/1.1: Semantics and Content, section 6.5.6 */ int NOT_ACCEPTABLE() { return 406 } /** * {@code 407 Proxy Authentication Required}. - * @see HTTP/1.1: Authentication, section 3.2 + * @see HTTP/1.1: Authentication, section 3.2 */ int PROXY_AUTHENTICATION_REQUIRED() { return 407 } /** * {@code 408 Request Timeout}. - * @see HTTP/1.1: Semantics and Content, section 6.5.7 + * @see HTTP/1.1: Semantics and Content, section 6.5.7 */ int REQUEST_TIMEOUT() { return 408 } /** * {@code 409 Conflict}. - * @see HTTP/1.1: Semantics and Content, section 6.5.8 + * @see HTTP/1.1: Semantics and Content, section 6.5.8 */ int CONFLICT() { return 409 } /** * {@code 410 Gone}. - * @see HTTP/1.1: Semantics and Content, section 6.5.9 + * @see HTTP/1.1: Semantics and Content, section 6.5.9 */ int GONE() { return 410 } /** * {@code 411 Length Required}. - * @see HTTP/1.1: Semantics and Content, section 6.5.10 + * @see HTTP/1.1: Semantics and Content, section 6.5.10 */ int LENGTH_REQUIRED() { return 411 } /** * {@code 412 Precondition failed}. - * @see HTTP/1.1: Conditional Requests, section 4.2 + * @see HTTP/1.1: Conditional Requests, section 4.2 */ int PRECONDITION_FAILED() { return 412 } /** * {@code 413 Payload Too Large}. - * @since 4.1 - * @see HTTP/1.1: Semantics and Content, section 6.5.11 + * @since 4.1* @see HTTP/1.1: Semantics and Content, section 6.5.11 */ int PAYLOAD_TOO_LARGE() { return 413 } /** * {@code 413 Request Entity Too Large}. - * @see HTTP/1.1, section 10.4.14 + * @see HTTP/1.1, section 10.4.14 * @deprecated in favor of {@link #PAYLOAD_TOO_LARGE} which will be returned from {@code HttpStatus.valueOf(413)} */ @Deprecated int REQUEST_ENTITY_TOO_LARGE() { return 413 } /** * {@code 414 URI Too Long}. - * @since 4.1 - * @see HTTP/1.1: Semantics and Content, section 6.5.12 + * @since 4.1* @see HTTP/1.1: Semantics and Content, section 6.5.12 */ int URI_TOO_LONG() { return 414 } /** * {@code 414 Request-URI Too Long}. - * @see HTTP/1.1, section 10.4.15 + * @see HTTP/1.1, section 10.4.15 * @deprecated in favor of {@link #URI_TOO_LONG} which will be returned from {@code HttpStatus.valueOf(414)} */ @Deprecated int REQUEST_URI_TOO_LONG() { return 414 } /** * {@code 415 Unsupported Media Type}. - * @see HTTP/1.1: Semantics and Content, section 6.5.13 + * @see HTTP/1.1: Semantics and Content, section 6.5.13 */ int UNSUPPORTED_MEDIA_TYPE() { return 415 } /** * {@code 416 Requested Range Not Satisfiable}. - * @see HTTP/1.1: Range Requests, section 4.4 + * @see HTTP/1.1: Range Requests, section 4.4 */ int REQUESTED_RANGE_NOT_SATISFIABLE() { return 416 } /** * {@code 417 Expectation Failed}. - * @see HTTP/1.1: Semantics and Content, section 6.5.14 + * @see HTTP/1.1: Semantics and Content, section 6.5.14 */ int EXPECTATION_FAILED() { return 417 } /** * {@code 418 I'm a teapot}. - * @see HTCPCP/1.0 + * @see HTCPCP/1.0 */ int I_AM_A_TEAPOT() { return 418 } /** @@ -277,42 +291,42 @@ class HttpStatus { int DESTINATION_LOCKED() { return 421 } /** * {@code 422 Unprocessable Entity}. - * @see WebDAV + * @see WebDAV */ int UNPROCESSABLE_ENTITY() { return 422 } /** * {@code 423 Locked}. - * @see WebDAV + * @see WebDAV */ int LOCKED() { return 423 } /** * {@code 424 Failed Dependency}. - * @see WebDAV + * @see WebDAV */ int FAILED_DEPENDENCY() { return 424 } /** * {@code 426 Upgrade Required}. - * @see Upgrading to TLS Within HTTP/1.1 + * @see Upgrading to TLS Within HTTP/1.1 */ int UPGRADE_REQUIRED() { return 426 } /** * {@code 428 Precondition Required}. - * @see Additional HTTP Status Codes + * @see Additional HTTP Status Codes */ int PRECONDITION_REQUIRED() { return 428 } /** * {@code 429 Too Many Requests}. - * @see Additional HTTP Status Codes + * @see Additional HTTP Status Codes */ int TOO_MANY_REQUESTS() { return 429 } /** * {@code 431 Request Header Fields Too Large}. - * @see Additional HTTP Status Codes + * @see Additional HTTP Status Codes */ int REQUEST_HEADER_FIELDS_TOO_LARGE() { return 431 } /** * {@code 451 Unavailable For Legal Reasons}. - * @see + * @see * An HTTP Status Code to Report Legal Obstacles * @since 4.3 */ @@ -322,47 +336,47 @@ class HttpStatus { /** * {@code 500 Internal Server Error}. - * @see HTTP/1.1: Semantics and Content, section 6.6.1 + * @see HTTP/1.1: Semantics and Content, section 6.6.1 */ int INTERNAL_SERVER_ERROR() { return 500 } /** * {@code 501 Not Implemented}. - * @see HTTP/1.1: Semantics and Content, section 6.6.2 + * @see HTTP/1.1: Semantics and Content, section 6.6.2 */ int NOT_IMPLEMENTED() { return 501 } /** * {@code 502 Bad Gateway}. - * @see HTTP/1.1: Semantics and Content, section 6.6.3 + * @see HTTP/1.1: Semantics and Content, section 6.6.3 */ int BAD_GATEWAY() { return 502 } /** * {@code 503 Service Unavailable}. - * @see HTTP/1.1: Semantics and Content, section 6.6.4 + * @see HTTP/1.1: Semantics and Content, section 6.6.4 */ int SERVICE_UNAVAILABLE() { return 503 } /** * {@code 504 Gateway Timeout}. - * @see HTTP/1.1: Semantics and Content, section 6.6.5 + * @see HTTP/1.1: Semantics and Content, section 6.6.5 */ int GATEWAY_TIMEOUT() { return 504 } /** * {@code 505 HTTP Version Not Supported}. - * @see HTTP/1.1: Semantics and Content, section 6.6.6 + * @see HTTP/1.1: Semantics and Content, section 6.6.6 */ int HTTP_VERSION_NOT_SUPPORTED() { return 505 } /** * {@code 506 Variant Also Negotiates} - * @see Transparent Content Negotiation + * @see Transparent Content Negotiation */ int VARIANT_ALSO_NEGOTIATES() { return 506 } /** * {@code 507 Insufficient Storage} - * @see WebDAV + * @see WebDAV */ int INSUFFICIENT_STORAGE() { return 507 } /** * {@code 508 Loop Detected} - * @see WebDAV Binding Extensions + * @see WebDAV Binding Extensions */ int LOOP_DETECTED() { return 508 } /** @@ -371,12 +385,12 @@ class HttpStatus { int BANDWIDTH_LIMIT_EXCEEDED() { return 509 } /** * {@code 510 Not Extended} - * @see HTTP Extension Framework + * @see HTTP Extension Framework */ int NOT_EXTENDED() { return 510 } /** * {@code 511 Network Authentication Required}. - * @see Additional HTTP Status Codes + * @see Additional HTTP Status Codes */ int NETWORK_AUTHENTICATION_REQUIRED() { return 511 } } diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Input.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Input.groovy index 2db08f92cb..de87e1c476 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Input.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Input.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal @@ -23,6 +23,7 @@ import groovy.transform.EqualsAndHashCode import groovy.transform.ToString import groovy.transform.TypeChecked import groovy.util.logging.Commons + /** * Represents an input for messaging. The input can be a message or some * action inside the application. @@ -37,7 +38,8 @@ import groovy.util.logging.Commons @ToString(includePackage = false, includeNames = true) class Input extends Common { - @Delegate ClientPatternValueDslProperty property = new ClientPatternValueDslProperty() + @Delegate + ClientPatternValueDslProperty property = new ClientPatternValueDslProperty() DslProperty messageFrom ExecutionProperty triggeredBy diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/JSONCompareMode.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/JSONCompareMode.groovy index 4f57f422a8..540d9bffda 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/JSONCompareMode.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/JSONCompareMode.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal @@ -23,4 +23,4 @@ package org.springframework.cloud.contract.spec.internal */ enum JSONCompareMode { STRICT, LENIENT, NON_EXTENSIBLE, STRICT_ORDER -} \ No newline at end of file +} diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/MatchingStrategy.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/MatchingStrategy.groovy index 9fb25f9646..a157c5808d 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/MatchingStrategy.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/MatchingStrategy.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal @@ -55,7 +55,7 @@ class MatchingStrategy extends DslProperty { enum Type { EQUAL_TO("equalTo"), CONTAINS("containing"), MATCHING("matching"), NOT_MATCHING("notMatching"), - EQUAL_TO_JSON("equalToJson"), EQUAL_TO_XML("equalToXml"), ABSENT("absent"), BINARY_EQUAL_TO("binaryEqualTo") + EQUAL_TO_JSON("equalToJson"), EQUAL_TO_XML("equalToXml"), ABSENT("absent"), BINARY_EQUAL_TO("binaryEqualTo") final String name @@ -64,4 +64,4 @@ class MatchingStrategy extends DslProperty { } } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/MatchingType.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/MatchingType.groovy index 57051697d8..20ed62ec47 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/MatchingType.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/MatchingType.groovy @@ -1,18 +1,19 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal import groovy.transform.CompileStatic @@ -66,7 +67,7 @@ enum MatchingType { NULL static boolean regexRelated(MatchingType type) { - if (type == EQUALITY || type == TYPE || type == COMMAND || type == NULL ) { + if (type == EQUALITY || type == TYPE || type == COMMAND || type == NULL) { return false } return true diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/MediaTypes.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/MediaTypes.groovy index 8f10f64ce3..9a67676e2e 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/MediaTypes.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/MediaTypes.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal import groovy.transform.CompileStatic diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/MessagingHeaders.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/MessagingHeaders.groovy index 488be97ae8..2e97f53dda 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/MessagingHeaders.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/MessagingHeaders.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal import groovy.transform.CompileStatic diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Multipart.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Multipart.groovy index 924c5cc74b..23be3a15f1 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Multipart.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Multipart.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal @@ -25,33 +25,36 @@ import groovy.transform.ToString @CompileStatic class Multipart extends DslProperty { - Multipart(Map multipart) { - super(extractValue(multipart, { DslProperty p -> p.clientValue}), extractValue(multipart, {DslProperty p -> p.serverValue})) - } + Multipart(Map multipart) { + super( + extractValue(multipart, { DslProperty p -> p.clientValue }), + extractValue(multipart, { DslProperty p -> p.serverValue })) + } - private static Map extractValue(Map multipart, Closure valueProvider) { - return multipart.collectEntries { Map.Entry entry -> - [(entry.key): valueProvider(entry.value)] - } as Map - } + private static Map extractValue(Map multipart, Closure valueProvider) { + return multipart.collectEntries { Map.Entry entry -> + [(entry.key): valueProvider(entry.value)] + } as Map + } - Multipart(List multipartAsList) { - super(multipartAsList.collect { DslProperty p -> p.clientValue }, multipartAsList.collect { DslProperty p -> p.serverValue }) - } + Multipart(List multipartAsList) { + super(multipartAsList.collect { DslProperty p -> p.clientValue }, multipartAsList. + collect { DslProperty p -> p.serverValue }) + } - Multipart(Object multipartAsValue) { - this("${multipartAsValue}") - } + Multipart(Object multipartAsValue) { + this("${multipartAsValue}") + } - Multipart(GString multipartAsValue) { - super(multipartAsValue, multipartAsValue) - } + Multipart(GString multipartAsValue) { + super(multipartAsValue, multipartAsValue) + } - Multipart(DslProperty multipartAsValue) { - super(multipartAsValue.clientValue, multipartAsValue.serverValue) - } + Multipart(DslProperty multipartAsValue) { + super(multipartAsValue.clientValue, multipartAsValue.serverValue) + } - Multipart(MatchingStrategy matchingStrategy) { - super(matchingStrategy, matchingStrategy) - } + Multipart(MatchingStrategy matchingStrategy) { + super(matchingStrategy, matchingStrategy) + } } diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/NamedProperty.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/NamedProperty.groovy index 9ccdf5738c..2f303b6d5a 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/NamedProperty.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/NamedProperty.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal @@ -31,39 +31,39 @@ import groovy.transform.ToString @CompileStatic class NamedProperty { - private static final String NAME = 'name' - private static final String CONTENT = 'content' - private static final String CONTENT_TYPE = 'contentType' + private static final String NAME = 'name' + private static final String CONTENT = 'content' + private static final String CONTENT_TYPE = 'contentType' - DslProperty name - DslProperty value - DslProperty contentType + DslProperty name + DslProperty value + DslProperty contentType - NamedProperty(DslProperty name, DslProperty value) { - this.name = name - this.value = value - this.contentType = null - } + NamedProperty(DslProperty name, DslProperty value) { + this.name = name + this.value = value + this.contentType = null + } - NamedProperty(DslProperty name, DslProperty value, DslProperty contentType) { - this.name = name - this.value = value - this.contentType = contentType - } - - NamedProperty(Map namedMap) { - this(asDslProperty(namedMap?.get(NAME)), - asDslProperty(namedMap?.get(CONTENT)), - asDslProperty(namedMap?.get(CONTENT_TYPE))) - } + NamedProperty(DslProperty name, DslProperty value, DslProperty contentType) { + this.name = name + this.value = value + this.contentType = contentType + } - static DslProperty asDslProperty(Object o) { - if (o == null) { - return null - } - if (o instanceof DslProperty) { - return o - } - return new DslProperty(o) - } + NamedProperty(Map namedMap) { + this(asDslProperty(namedMap?.get(NAME)), + asDslProperty(namedMap?.get(CONTENT)), + asDslProperty(namedMap?.get(CONTENT_TYPE))) + } + + static DslProperty asDslProperty(Object o) { + if (o == null) { + return null + } + if (o instanceof DslProperty) { + return o + } + return new DslProperty(o) + } } diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/NotToEscapePattern.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/NotToEscapePattern.groovy index b72559bb0d..6e309274df 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/NotToEscapePattern.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/NotToEscapePattern.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal import java.util.regex.Pattern diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/OptionalProperty.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/OptionalProperty.groovy index 41ed100899..556d4bf358 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/OptionalProperty.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/OptionalProperty.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/OutputMessage.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/OutputMessage.groovy index 8ad4c6c196..1e649426bc 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/OutputMessage.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/OutputMessage.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal @@ -23,6 +23,7 @@ import groovy.transform.EqualsAndHashCode import groovy.transform.ToString import groovy.transform.TypeChecked import groovy.util.logging.Commons + /** * Represents an output for messaging. Used for verifying * the body and headers that are sent. @@ -37,7 +38,8 @@ import groovy.util.logging.Commons @ToString(includePackage = false, includeNames = true) class OutputMessage extends Common { - @Delegate ServerPatternValueDslProperty property = new ServerPatternValueDslProperty() + @Delegate + ServerPatternValueDslProperty property = new ServerPatternValueDslProperty() DslProperty sentTo Headers headers diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/PathBodyMatcher.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/PathBodyMatcher.groovy index 96da82362f..913a5f8014 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/PathBodyMatcher.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/PathBodyMatcher.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/PatternValueDslProperty.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/PatternValueDslProperty.groovy index f617c2595e..36229a8e68 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/PatternValueDslProperty.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/PatternValueDslProperty.groovy @@ -1,25 +1,27 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal +import java.util.regex.Pattern + import groovy.transform.CompileStatic import groovy.transform.PackageScope import org.apache.commons.lang3.RandomStringUtils -import java.util.regex.Pattern /** * @author Marcin Grzejszczak * @author Tim Ysewyn @@ -76,12 +78,15 @@ abstract class PatternValueDslProperty implements RegexCr @Override T anyPositiveInt() { - return createAndValidateProperty(RegexPatterns.POSITIVE_INT, Math.abs(this.random.nextInt() + 1)) + return createAndValidateProperty(RegexPatterns.POSITIVE_INT, Math. + abs(this.random.nextInt() + 1)) } @Override T anyDouble() { - return createAndValidateProperty(RegexPatterns.DOUBLE, this.random.nextInt(100) + this.random.nextDouble()) + return createAndValidateProperty(RegexPatterns.DOUBLE, this.random. + nextInt(100) + + this.random.nextDouble()) } @Override @@ -97,27 +102,41 @@ abstract class PatternValueDslProperty implements RegexCr @Override T anyIpAddress() { - return createAndValidateProperty(RegexPatterns.IP_ADDRESS, "192.168.0." + this.random.nextInt(10)) + return createAndValidateProperty(RegexPatterns.IP_ADDRESS, "192.168.0." + + this.random. + nextInt(10)) } @Override T anyHostname() { - return createAndValidateProperty(RegexPatterns.HOSTNAME_PATTERN, "http://foo" + this.random.nextInt() + ".com") + return createAndValidateProperty(RegexPatterns.HOSTNAME_PATTERN, "http://foo" + + this.random. + nextInt() + + ".com") } @Override T anyEmail() { - return createAndValidateProperty(RegexPatterns.EMAIL, "foo@bar" + this.random.nextInt() + ".com") + return createAndValidateProperty(RegexPatterns.EMAIL, "foo@bar" + + this.random. + nextInt() + + ".com") } @Override T anyUrl() { - return createAndValidateProperty(RegexPatterns.URL, "http://foo" + this.random.nextInt() + ".com") + return createAndValidateProperty(RegexPatterns.URL, "http://foo" + + this.random. + nextInt() + + ".com") } @Override T anyHttpsUrl() { - return createAndValidateProperty(RegexPatterns.HTTPS_URL, "https://baz" + this.random.nextInt() + ".com") + return createAndValidateProperty(RegexPatterns.HTTPS_URL, "https://baz" + + this.random. + nextInt() + + ".com") } @Override @@ -162,7 +181,7 @@ abstract class PatternValueDslProperty implements RegexCr } @Override - T anyOf(String... values){ + T anyOf(String... values) { return createAndValidateProperty(RegexPatterns.anyOf(values), values[0]) } } diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/QueryParameter.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/QueryParameter.groovy index 512e0ed133..f07b3d82ca 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/QueryParameter.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/QueryParameter.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/QueryParameters.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/QueryParameters.groovy index 773f788b83..8c2d2cc764 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/QueryParameters.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/QueryParameters.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal @@ -23,7 +23,7 @@ import groovy.transform.TypeChecked @EqualsAndHashCode @ToString(includePackage = false, ignoreNulls = true, includeNames = true) @TypeChecked -class QueryParameters { +class QueryParameters { List parameters = [] diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RandomStringGenerator.java b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RandomStringGenerator.java index 0cddf8713b..50a0b32c24 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RandomStringGenerator.java +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RandomStringGenerator.java @@ -1,8 +1,29 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal; import java.util.Random; -class RandomStringGenerator { +final class RandomStringGenerator { + + private RandomStringGenerator() { + throw new IllegalStateException("Can't instantiate a utility class"); + } + static String randomString(int length) { char[] characterSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray(); Random random = new Random(); @@ -14,4 +35,5 @@ class RandomStringGenerator { } return new String(result); } + } diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RegexCreatingProperty.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RegexCreatingProperty.groovy index 59041e479c..a1338dd3df 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RegexCreatingProperty.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RegexCreatingProperty.groovy @@ -1,24 +1,25 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT 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.spec.internal import groovy.transform.CompileStatic import groovy.transform.PackageScope + /** * @author Marcin Grzejszczak */ diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RegexPatterns.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RegexPatterns.groovy index c4a820f46a..7e5380e50b 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RegexPatterns.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RegexPatterns.groovy @@ -1,27 +1,27 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal +import java.util.regex.Pattern + import groovy.transform.CompileStatic import groovy.transform.EqualsAndHashCode import groovy.transform.ToString -import java.util.regex.Pattern - /** * Contains most common regular expression patterns * @@ -43,21 +43,29 @@ class RegexPatterns { protected static final Pattern POSITIVE_INT = Pattern.compile('([1-9]\\d*)') protected static final Pattern DOUBLE = Pattern.compile('-?(\\d*\\.\\d+)') protected static final Pattern HEX = Pattern.compile('[a-fA-F0-9]+') - protected static final Pattern IP_ADDRESS = Pattern.compile('([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])') - protected static final Pattern HOSTNAME_PATTERN = Pattern.compile('((http[s]?|ftp):/)/?([^:/\\s]+)(:[0-9]{1,5})?') - protected static final Pattern EMAIL = Pattern.compile('[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}') + protected static final Pattern IP_ADDRESS = Pattern. + compile('([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])') + protected static final Pattern HOSTNAME_PATTERN = Pattern. + compile('((http[s]?|ftp):/)/?([^:/\\s]+)(:[0-9]{1,5})?') + protected static final Pattern EMAIL = Pattern. + compile('[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}') protected static final Pattern URL = UrlHelper.URL protected static final Pattern HTTPS_URL = UrlHelper.HTTPS_URL - protected static final Pattern UUID = Pattern.compile('[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}') - protected static final Pattern ANY_DATE = Pattern.compile('(\\d\\d\\d\\d)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])') - protected static final Pattern ANY_DATE_TIME = Pattern.compile('([0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])') - protected static final Pattern ANY_TIME = Pattern.compile('(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])') + protected static final Pattern UUID = Pattern. + compile('[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}') + protected static final Pattern ANY_DATE = Pattern. + compile('(\\d\\d\\d\\d)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])') + protected static final Pattern ANY_DATE_TIME = Pattern. + compile('([0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])') + protected static final Pattern ANY_TIME = Pattern. + compile('(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])') protected static final Pattern NON_EMPTY = Pattern.compile(/[\S\s]+/) protected static final Pattern NON_BLANK = Pattern.compile(/^\s*\S[\S\s]*/) - protected static final Pattern ISO8601_WITH_OFFSET = Pattern.compile(/([0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\.\d{3})?(Z|[+-][01]\d:[0-5]\d)/) + protected static final Pattern ISO8601_WITH_OFFSET = Pattern. + compile(/([0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\.\d{3})?(Z|[+-][01]\d:[0-5]\d)/) - protected static Pattern anyOf(String... values){ - return Pattern.compile(values.collect({"^$it\$"}).join("|")) + protected static Pattern anyOf(String... values) { + return Pattern.compile(values.collect({ "^$it\$" }).join("|")) } RegexProperty onlyAlphaUnicode() { @@ -108,7 +116,7 @@ class RegexPatterns { return new RegexProperty(HTTPS_URL).asString() } - RegexProperty uuid(){ + RegexProperty uuid() { return new RegexProperty(UUID).asString() } @@ -137,7 +145,7 @@ class RegexPatterns { } // end::regexps[] - + static String multipartParam(Object name, Object value) { return ".*--(.*)\r\nContent-Disposition: form-data; name=\"$name\"\r\n(Content-Type: .*\r\n)?(Content-Transfer-Encoding: .*\r\n)?(Content-Length: \\d+\r\n)?\r\n$value\r\n--\\1.*" } @@ -197,9 +205,12 @@ class UrlHelper { //Example: "/user/heartrate?foo=bar#element1". private static final String REGEX_RESOURCE_PATH = "(?:/\\S*)?" - protected static final Pattern HTTPS_URL = Pattern.compile("^(?:" + HTTPS_REGEX_SCHEME + REGEX_AUTHORATIVE_DECLARATION + - REGEX_USERINFO + REGEX_HOST + REGEX_PORT + REGEX_RESOURCE_PATH + ")\$") + protected static final Pattern HTTPS_URL = Pattern. + compile("^(?:" + HTTPS_REGEX_SCHEME + REGEX_AUTHORATIVE_DECLARATION + + REGEX_USERINFO + REGEX_HOST + REGEX_PORT + REGEX_RESOURCE_PATH + ")\$") - protected static final Pattern URL = Pattern.compile("^(?:(?:" + REGEX_SCHEME + REGEX_AUTHORATIVE_DECLARATION + ")?" + - REGEX_USERINFO + REGEX_HOST + REGEX_PORT + REGEX_RESOURCE_PATH + ")\$") + protected static final Pattern URL = Pattern. + compile("^(?:(?:" + REGEX_SCHEME + REGEX_AUTHORATIVE_DECLARATION + ")?" + + REGEX_USERINFO + REGEX_HOST + REGEX_PORT + REGEX_RESOURCE_PATH + ")\$") } + diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RegexProperty.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RegexProperty.groovy index 7110e5ce7c..e377f768c1 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RegexProperty.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RegexProperty.groovy @@ -1,18 +1,17 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT 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.spec.internal @@ -25,6 +24,7 @@ import groovy.transform.ToString import groovy.transform.TypeChecked import org.apache.commons.text.StringEscapeUtils import repackaged.nl.flotsam.xeger.Xeger + /** * Represents a regular expression property * @@ -58,11 +58,13 @@ class RegexProperty extends DslProperty implements CanBeDynamic { if (dynamicValue instanceof Pattern) { this.pattern = dynamicValue this.clazz = clazz ?: String - } else if (dynamicValue instanceof RegexProperty) { + } + else if (dynamicValue instanceof RegexProperty) { RegexProperty regexProperty = ((RegexProperty) dynamicValue) this.pattern = regexProperty.pattern this.clazz = clazz ?: regexProperty.clazz - } else { + } + else { this.clazz = clazz } } @@ -110,13 +112,13 @@ class RegexProperty extends DslProperty implements CanBeDynamic { Object generate() { String generatedValue = new Xeger(this.pattern.pattern()).generate() switch (this.clazz) { - case Integer: return Integer.parseInt(generatedValue) - case Double: return Double.parseDouble(generatedValue) - case Float: return Float.parseFloat(generatedValue) - case Long: return Long.parseLong(generatedValue) - case Short: return Short.parseShort(generatedValue) - case Boolean: return Boolean.parseBoolean(generatedValue) - default: return generatedValue + case Integer: return Integer.parseInt(generatedValue) + case Double: return Double.parseDouble(generatedValue) + case Float: return Float.parseFloat(generatedValue) + case Long: return Long.parseLong(generatedValue) + case Short: return Short.parseShort(generatedValue) + case Boolean: return Boolean.parseBoolean(generatedValue) + default: return generatedValue } } @@ -141,20 +143,32 @@ class RegexProperty extends DslProperty implements CanBeDynamic { } RegexProperty concreteClientEscapedDynamicProducer() { - return new RegexProperty(generateAndEscapeJavaStringIfNeeded(), this.pattern, this.clazz) + return new RegexProperty( + generateAndEscapeJavaStringIfNeeded(), this.pattern, this.clazz) } RegexProperty dynamicClientEscapedConcreteProducer() { - return new RegexProperty(this.pattern, generateAndEscapeJavaStringIfNeeded(), this.clazz) + return new RegexProperty(this.pattern, + generateAndEscapeJavaStringIfNeeded(), this.clazz) } boolean equals(o) { - if (this.is(o)) return true - if (getClass() != o.class) return false - if (!super.equals(o)) return false + if (this.is(o)) { + return true + } + if (getClass() != o.class) { + return false + } + if (!super.equals(o)) { + return false + } RegexProperty that = (RegexProperty) o - if (this.clazz != that.clazz) return false - if (this.pattern != that.pattern) return false + if (this.clazz != that.clazz) { + return false + } + if (this.pattern != that.pattern) { + return false + } return true } diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Request.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Request.groovy index 2e2523b0a0..c8314af3b4 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Request.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Request.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal @@ -25,6 +25,7 @@ import groovy.transform.TypeChecked import groovy.util.logging.Commons import org.springframework.cloud.contract.spec.util.RegexpUtils + /** * Represents the request side of the HTTP communication * @@ -38,8 +39,10 @@ import org.springframework.cloud.contract.spec.util.RegexpUtils @ToString(includePackage = false, includeNames = true) class Request extends Common { - @Delegate ClientPatternValueDslProperty property = new ClientPatternValueDslProperty() - @Delegate HttpMethods httpMethods = new HttpMethods() + @Delegate + ClientPatternValueDslProperty property = new ClientPatternValueDslProperty() + @Delegate + HttpMethods httpMethods = new HttpMethods() DslProperty method Url url @@ -304,7 +307,8 @@ class Request extends Common { Object dynamicValue = client.clientValue if (dynamicValue instanceof RegexProperty && client.isSingleValue()) { return dynamicValue.dynamicClientEscapedConcreteProducer() - } else if (concreteValue instanceof RegexProperty && !client.isSingleValue()) { + } + else if (concreteValue instanceof RegexProperty && !client.isSingleValue()) { concreteValue = dynamicValue } return new DslProperty(dynamicValue, concreteValue) @@ -442,4 +446,4 @@ class Request extends Common { return new ClientDslProperty(pattern, generatedValue) } } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Response.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Response.groovy index afb93d1f71..22aeb16798 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Response.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Response.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal @@ -25,6 +25,7 @@ import groovy.transform.TypeChecked import groovy.util.logging.Commons import org.springframework.cloud.contract.spec.util.RegexpUtils + /** * Represents the response side of the HTTP communication * @@ -38,9 +39,11 @@ import org.springframework.cloud.contract.spec.util.RegexpUtils @ToString(includePackage = false, includeFields = true) class Response extends Common { - @Delegate ServerPatternValueDslProperty property = new ServerPatternValueDslProperty() - @Delegate HttpStatus httpStatus = new HttpStatus() - + @Delegate + ServerPatternValueDslProperty property = new ServerPatternValueDslProperty() + @Delegate + HttpStatus httpStatus = new HttpStatus() + DslProperty status DslProperty delay Headers headers @@ -111,7 +114,8 @@ class Response extends Common { void body(Object bodyAsValue) { if (bodyAsValue instanceof List) { body(bodyAsValue as List) - } else { + } + else { this.body = new Body(bodyAsValue) } } @@ -259,7 +263,8 @@ class Response extends Common { @Override DslProperty matching(String value) { - return $(p(notEscaped(Pattern.compile("${RegexpUtils.escapeSpecialRegexWithSingleEscape(value)}.*"))), + return $(p(notEscaped(Pattern. + compile("${RegexpUtils.escapeSpecialRegexWithSingleEscape(value)}.*"))), c(value)) } } @@ -271,7 +276,8 @@ class Response extends Common { @Override DslProperty matching(String value) { - return $(p(regex("${RegexpUtils.escapeSpecialRegexWithSingleEscape(value)}.*")), c(value)) + return $(p(regex("${RegexpUtils.escapeSpecialRegexWithSingleEscape(value)}.*")), + c(value)) } } diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/ResponseBodyMatchers.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/ResponseBodyMatchers.groovy index d335b288de..8684815657 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/ResponseBodyMatchers.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/ResponseBodyMatchers.groovy @@ -1,22 +1,24 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal import groovy.transform.CompileStatic import groovy.transform.ToString + /** * Body matchers for the response side (output message, REST response) * diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/ServerDslProperty.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/ServerDslProperty.groovy index e5b7040716..874aa6c2ee 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/ServerDslProperty.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/ServerDslProperty.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Url.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Url.groovy index e2357fe749..55852f002e 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Url.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Url.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal @@ -22,6 +22,7 @@ import groovy.transform.ToString import org.codehaus.groovy.runtime.GStringImpl import static org.springframework.cloud.contract.spec.util.ValidateUtils.validateServerValueIsAvailable + /** * Represents a URL that may contain query parameters * @@ -51,8 +52,9 @@ class Url extends DslProperty { return url } String newUrl = new GStringImpl( - url.values.collect { it instanceof RegexProperty ? - it.generate() : it + url.values.collect { + it instanceof RegexProperty ? + it.generate() : it } as String[], Arrays.copyOf(url.strings, url.strings.length) as String[] ).toString() diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/UrlPath.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/UrlPath.groovy index 66ffeb6668..3270695d87 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/UrlPath.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/UrlPath.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/util/RegexpUtils.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/util/RegexpUtils.groovy index d579cdcd8b..b6aa2be326 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/util/RegexpUtils.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/util/RegexpUtils.groovy @@ -1,25 +1,25 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.util -import groovy.transform.CompileStatic - import java.util.regex.Pattern +import groovy.transform.CompileStatic + /** * Useful utility methods to work with regular expressions * @@ -28,7 +28,8 @@ import java.util.regex.Pattern @CompileStatic class RegexpUtils { - private final static Pattern SPECIAL_REGEX_CHARS = Pattern.compile('[{}()\\[\\].+*?^$\\\\|]') + private final static Pattern SPECIAL_REGEX_CHARS = Pattern. + compile('[{}()\\[\\].+*?^$\\\\|]') static String escapeSpecialRegexChars(String str) { return SPECIAL_REGEX_CHARS.matcher(str).replaceAll('\\\\\\\\$0') diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/util/ValidateUtils.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/util/ValidateUtils.groovy index f004a97867..587743215b 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/util/ValidateUtils.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/util/ValidateUtils.groovy @@ -1,27 +1,28 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.util +import java.util.regex.Pattern + import groovy.transform.TypeChecked + import org.springframework.cloud.contract.spec.internal.DslProperty import org.springframework.cloud.contract.spec.internal.MatchingStrategy -import java.util.regex.Pattern - import static org.springframework.cloud.contract.spec.internal.MatchingStrategy.Type.ABSENT import static org.springframework.cloud.contract.spec.internal.MatchingStrategy.Type.EQUAL_TO diff --git a/spring-cloud-contract-spec/src/main/groovy/repackaged/nl/flotsam/xeger/Xeger.java b/spring-cloud-contract-spec/src/main/groovy/repackaged/nl/flotsam/xeger/Xeger.java index d26abc3f7f..c23254ea1f 100644 --- a/spring-cloud-contract-spec/src/main/groovy/repackaged/nl/flotsam/xeger/Xeger.java +++ b/spring-cloud-contract-spec/src/main/groovy/repackaged/nl/flotsam/xeger/Xeger.java @@ -18,6 +18,7 @@ * The class is bundled together with our code because it has not been * released to any central repository. */ + package repackaged.nl.flotsam.xeger; import java.util.List; @@ -30,34 +31,36 @@ import dk.brics.automaton.Transition; import org.apache.commons.lang3.StringUtils; /** - * An object that will generate text from a regular expression. In a way, it's the opposite of a regular expression - * matcher: an instance of this class will produce text that is guaranteed to match the regular expression passed in. + * An object that will generate text from a regular expression. In a way, it's the + * opposite of a regular expression matcher: an instance of this class will produce text + * that is guaranteed to match the regular expression passed in. * * slight modifications by Marcin Grzejszczak */ public class Xeger { - private final Automaton automaton; - private Random random; // Added by Marcin Grzejszczak // may lead to stackoverflow when regex is unbounded static int ITERATION_LIMIT = 200; + private final Automaton automaton; + + private Random random; + /** * Constructs a new instance, accepting the regular expression and the randomizer. - * - * @param regex The regular expression. (Not null.) - * @param random The object that will randomize the way the String is generated. (Not null.) + * @param regex The regular expression. (Not null.) + * @param random The object that will randomize the way the String is generated. (Not + * null.) * @throws IllegalArgumentException If the regular expression is invalid. */ public Xeger(String regex, Random random) { assert regex != null; assert random != null; // https://stackoverflow.com/questions/1578789/how-do-i-generate-text-matching-a-regular-expression-from-a-regular-expression - String pattern = regex - .replace("\\d", "[0-9]") // Used d=Digit + String pattern = regex.replace("\\d", "[0-9]") // Used d=Digit .replace("\\w", "[A-Za-z0-9_]") // Used =Word - .replace("\\s", "[ \t\r\n]"); // Used s="White"Space + .replace("\\s", "[ \t\r\n]"); // Used s="White"Space this.automaton = new RegExp(pattern).toAutomaton(); this.random = random; String generatedCharsSysProp = System @@ -66,15 +69,15 @@ public class Xeger { .getenv("SPRING_CLOUD_CONTRACT_GENERATED_CHARS_FROM_REGEX"); if (StringUtils.isNotEmpty(generatedCharsSysProp)) { ITERATION_LIMIT = Integer.parseInt(generatedCharsSysProp); - } else if (StringUtils.isNotEmpty(generatedCharsEnvVar)) { + } + else if (StringUtils.isNotEmpty(generatedCharsEnvVar)) { ITERATION_LIMIT = Integer.parseInt(generatedCharsEnvVar); } } /** - * As {@link Xeger#Xeger(String, java.util.Random)}, creating a {@link java.util.Random} instance - * implicityly. - * + * As {@link Xeger#Xeger(String, java.util.Random)}, creating a + * {@link java.util.Random} instance implicityly. * @param regex as string */ public Xeger(String regex) { @@ -82,7 +85,21 @@ public class Xeger { } /** - * Generates a random String that is guaranteed to match the regular expression passed to the constructor. + * Generates a random number within the given bounds. + * @param min The minimum number (inclusive). + * @param max The maximum number (inclusive). + * @param random The object used as the randomizer. + * @return A random number in the given range. + */ + static int getRandomInt(int min, int max, Random random) { + // Use random.nextInt as it guarantees a uniform distribution + int maxForRandom = max - min + 1; + return random.nextInt(maxForRandom) + min; + } + + /** + * Generates a random String that is guaranteed to match the regular expression passed + * to the constructor. * @return generated regexp */ public String generate() { @@ -103,7 +120,7 @@ public class Xeger { } int nroptions = state.isAccept() ? transitions.size() : transitions.size() - 1; int option = Xeger.getRandomInt(0, nroptions, this.random); - if (state.isAccept() && option == 0) { // 0 is considered stop + if (state.isAccept() && option == 0) { // 0 is considered stop return; } // Moving on to next transition @@ -113,8 +130,8 @@ public class Xeger { } private void appendChoice(StringBuilder builder, Transition transition) { - char c = (char) Xeger - .getRandomInt(transition.getMin(), transition.getMax(), this.random); + char c = (char) Xeger.getRandomInt(transition.getMin(), transition.getMax(), + this.random); builder.append(c); } @@ -126,17 +143,4 @@ public class Xeger { this.random = random; } - /** - * Generates a random number within the given bounds. - * - * @param min The minimum number (inclusive). - * @param max The maximum number (inclusive). - * @param random The object used as the randomizer. - * @return A random number in the given range. - */ - static int getRandomInt(int min, int max, Random random) { - // Use random.nextInt as it guarantees a uniform distribution - int maxForRandom = max - min + 1; - return random.nextInt(maxForRandom) + min; - } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/ContractSpec.groovy b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/ContractSpec.groovy index 3e29c6ba3f..1194512025 100644 --- a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/ContractSpec.groovy +++ b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/ContractSpec.groovy @@ -1,8 +1,25 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal -import org.springframework.cloud.contract.spec.Contract import spock.lang.Specification +import org.springframework.cloud.contract.spec.Contract + import static org.assertj.core.api.Assertions.assertThat /** @@ -18,11 +35,11 @@ class ContractSpec extends Specification { method('PUT') headers { header([ - foo: 'bar' + foo: 'bar' ]) } body([ - foo: 'bar' + foo: 'bar' ]) } response { @@ -162,9 +179,9 @@ class ContractSpec extends Specification { def 'should set a description'() { given: - // tag::description[] - org.springframework.cloud.contract.spec.Contract.make { - description(''' + // tag::description[] + org.springframework.cloud.contract.spec.Contract.make { + description(''' given: An input when: @@ -172,26 +189,26 @@ when: then: Output ''') - } - // end::description[] + } + // end::description[] } def 'should set a name'() { given: - // tag::name[] - org.springframework.cloud.contract.spec.Contract.make { - name("some_special_name") - } - // end::name[] + // tag::name[] + org.springframework.cloud.contract.spec.Contract.make { + name("some_special_name") + } + // end::name[] } def 'should mark a contract ignored'() { given: - // tag::ignored[] - org.springframework.cloud.contract.spec.Contract.make { - ignored() - } - // end::ignored[] + // tag::ignored[] + org.springframework.cloud.contract.spec.Contract.make { + ignored() + } + // end::ignored[] } def 'should make equals and hashcode work properly for URL'() { @@ -200,14 +217,14 @@ then: request { method("GET") url("/1") - } + } } def b = Contract.make { - request { - method("GET") - url("/1") - } + request { + method("GET") + url("/1") } + } a == b } @@ -217,7 +234,7 @@ then: request { method("GET") url($(c("/1"), p("/1"))) - } + } } == Contract.make { request { method("GET") diff --git a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/CookiesSpec.groovy b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/CookiesSpec.groovy index 6341a6dea5..b4091ae819 100644 --- a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/CookiesSpec.groovy +++ b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/CookiesSpec.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal import spock.lang.Specification diff --git a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/ExecutionPropertySpec.groovy b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/ExecutionPropertySpec.groovy index 9f8163e1b8..10d5b063b6 100644 --- a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/ExecutionPropertySpec.groovy +++ b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/ExecutionPropertySpec.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal diff --git a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/HttpStatusTests.java b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/HttpStatusTests.java index 8fad18951d..c3fc331eaa 100644 --- a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/HttpStatusTests.java +++ b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/HttpStatusTests.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal; import org.assertj.core.api.BDDAssertions; @@ -8,271 +24,346 @@ import org.junit.Test; */ public class HttpStatusTests { - @Test public void CONTINUE() { + @Test + public void CONTINUE() { BDDAssertions.then(new HttpStatus().CONTINUE()).isEqualTo(100); } - @Test public void SWITCHING_PROTOCOLS() { + @Test + public void SWITCHING_PROTOCOLS() { BDDAssertions.then(new HttpStatus().SWITCHING_PROTOCOLS()).isEqualTo(101); } - @Test public void PROCESSING() { + @Test + public void PROCESSING() { BDDAssertions.then(new HttpStatus().PROCESSING()).isEqualTo(102); } - @Test public void CHECKPOINT() { + @Test + public void CHECKPOINT() { BDDAssertions.then(new HttpStatus().CHECKPOINT()).isEqualTo(103); } - @Test public void OK() { + @Test + public void OK() { BDDAssertions.then(new HttpStatus().OK()).isEqualTo(200); } - @Test public void CREATED() { + @Test + public void CREATED() { BDDAssertions.then(new HttpStatus().CREATED()).isEqualTo(201); } - @Test public void ACCEPTED() { + @Test + public void ACCEPTED() { BDDAssertions.then(new HttpStatus().ACCEPTED()).isEqualTo(202); } - @Test public void NON_AUTHORITATIVE_INFORMATION() { - BDDAssertions.then(new HttpStatus().NON_AUTHORITATIVE_INFORMATION()).isEqualTo(203); + @Test + public void NON_AUTHORITATIVE_INFORMATION() { + BDDAssertions.then(new HttpStatus().NON_AUTHORITATIVE_INFORMATION()) + .isEqualTo(203); } - @Test public void NO_CONTENT() { + @Test + public void NO_CONTENT() { BDDAssertions.then(new HttpStatus().NO_CONTENT()).isEqualTo(204); } - @Test public void RESET_CONTENT() { + @Test + public void RESET_CONTENT() { BDDAssertions.then(new HttpStatus().RESET_CONTENT()).isEqualTo(205); } - @Test public void PARTIAL_CONTENT() { + @Test + public void PARTIAL_CONTENT() { BDDAssertions.then(new HttpStatus().PARTIAL_CONTENT()).isEqualTo(206); } - @Test public void MULTI_STATUS() { + @Test + public void MULTI_STATUS() { BDDAssertions.then(new HttpStatus().MULTI_STATUS()).isEqualTo(207); } - @Test public void ALREADY_REPORTED() { + @Test + public void ALREADY_REPORTED() { BDDAssertions.then(new HttpStatus().ALREADY_REPORTED()).isEqualTo(208); } - @Test public void IM_USED() { + @Test + public void IM_USED() { BDDAssertions.then(new HttpStatus().IM_USED()).isEqualTo(226); } - @Test public void MULTIPLE_CHOICES() { + @Test + public void MULTIPLE_CHOICES() { BDDAssertions.then(new HttpStatus().MULTIPLE_CHOICES()).isEqualTo(300); } - @Test public void MOVED_PERMANENTLY() { + @Test + public void MOVED_PERMANENTLY() { BDDAssertions.then(new HttpStatus().MOVED_PERMANENTLY()).isEqualTo(301); } - @Test public void FOUND() { + @Test + public void FOUND() { BDDAssertions.then(new HttpStatus().FOUND()).isEqualTo(302); } - @Test public void MOVED_TEMPORARILY() { + @Test + public void MOVED_TEMPORARILY() { BDDAssertions.then(new HttpStatus().MOVED_TEMPORARILY()).isEqualTo(302); } - @Test public void SEE_OTHER() { + @Test + public void SEE_OTHER() { BDDAssertions.then(new HttpStatus().SEE_OTHER()).isEqualTo(303); } - @Test public void NOT_MODIFIED() { + @Test + public void NOT_MODIFIED() { BDDAssertions.then(new HttpStatus().NOT_MODIFIED()).isEqualTo(304); } - @Test public void USE_PROXY() { + @Test + public void USE_PROXY() { BDDAssertions.then(new HttpStatus().USE_PROXY()).isEqualTo(305); } - @Test public void TEMPORARY_REDIRECT() { + @Test + public void TEMPORARY_REDIRECT() { BDDAssertions.then(new HttpStatus().TEMPORARY_REDIRECT()).isEqualTo(307); } - @Test public void PERMANENT_REDIRECT() { + @Test + public void PERMANENT_REDIRECT() { BDDAssertions.then(new HttpStatus().PERMANENT_REDIRECT()).isEqualTo(308); } - @Test public void BAD_REQUEST() { + @Test + public void BAD_REQUEST() { BDDAssertions.then(new HttpStatus().BAD_REQUEST()).isEqualTo(400); } - @Test public void UNAUTHORIZED() { + @Test + public void UNAUTHORIZED() { BDDAssertions.then(new HttpStatus().UNAUTHORIZED()).isEqualTo(401); } - @Test public void PAYMENT_REQUIRED() { + @Test + public void PAYMENT_REQUIRED() { BDDAssertions.then(new HttpStatus().PAYMENT_REQUIRED()).isEqualTo(402); } - @Test public void FORBIDDEN() { + @Test + public void FORBIDDEN() { BDDAssertions.then(new HttpStatus().FORBIDDEN()).isEqualTo(403); } - @Test public void NOT_FOUND() { + @Test + public void NOT_FOUND() { BDDAssertions.then(new HttpStatus().NOT_FOUND()).isEqualTo(404); } - @Test public void METHOD_NOT_ALLOWED() { + @Test + public void METHOD_NOT_ALLOWED() { BDDAssertions.then(new HttpStatus().METHOD_NOT_ALLOWED()).isEqualTo(405); } - @Test public void NOT_ACCEPTABLE() { + @Test + public void NOT_ACCEPTABLE() { BDDAssertions.then(new HttpStatus().NOT_ACCEPTABLE()).isEqualTo(406); } - @Test public void PROXY_AUTHENTICATION_REQUIRED() { - BDDAssertions.then(new HttpStatus().PROXY_AUTHENTICATION_REQUIRED()).isEqualTo(407); + @Test + public void PROXY_AUTHENTICATION_REQUIRED() { + BDDAssertions.then(new HttpStatus().PROXY_AUTHENTICATION_REQUIRED()) + .isEqualTo(407); } - @Test public void REQUEST_TIMEOUT() { + @Test + public void REQUEST_TIMEOUT() { BDDAssertions.then(new HttpStatus().REQUEST_TIMEOUT()).isEqualTo(408); } - @Test public void CONFLICT() { + @Test + public void CONFLICT() { BDDAssertions.then(new HttpStatus().CONFLICT()).isEqualTo(409); } - @Test public void GONE() { + @Test + public void GONE() { BDDAssertions.then(new HttpStatus().GONE()).isEqualTo(410); } - @Test public void LENGTH_REQUIRED() { + @Test + public void LENGTH_REQUIRED() { BDDAssertions.then(new HttpStatus().LENGTH_REQUIRED()).isEqualTo(411); } - @Test public void PRECONDITION_FAILED() { + @Test + public void PRECONDITION_FAILED() { BDDAssertions.then(new HttpStatus().PRECONDITION_FAILED()).isEqualTo(412); } - @Test public void PAYLOAD_TOO_LARGE() { + @Test + public void PAYLOAD_TOO_LARGE() { BDDAssertions.then(new HttpStatus().PAYLOAD_TOO_LARGE()).isEqualTo(413); } - @Test public void REQUEST_ENTITY_TOO_LARGE() { + @Test + public void REQUEST_ENTITY_TOO_LARGE() { BDDAssertions.then(new HttpStatus().REQUEST_ENTITY_TOO_LARGE()).isEqualTo(413); } - @Test public void URI_TOO_LONG() { + @Test + public void URI_TOO_LONG() { BDDAssertions.then(new HttpStatus().URI_TOO_LONG()).isEqualTo(414); } - @Test public void REQUEST_URI_TOO_LONG() { + @Test + public void REQUEST_URI_TOO_LONG() { BDDAssertions.then(new HttpStatus().REQUEST_URI_TOO_LONG()).isEqualTo(414); } - @Test public void UNSUPPORTED_MEDIA_TYPE() { + @Test + public void UNSUPPORTED_MEDIA_TYPE() { BDDAssertions.then(new HttpStatus().UNSUPPORTED_MEDIA_TYPE()).isEqualTo(415); } - @Test public void REQUESTED_RANGE_NOT_SATISFIABLE() { - BDDAssertions.then(new HttpStatus().REQUESTED_RANGE_NOT_SATISFIABLE()).isEqualTo(416); + @Test + public void REQUESTED_RANGE_NOT_SATISFIABLE() { + BDDAssertions.then(new HttpStatus().REQUESTED_RANGE_NOT_SATISFIABLE()) + .isEqualTo(416); } - @Test public void EXPECTATION_FAILED() { + @Test + public void EXPECTATION_FAILED() { BDDAssertions.then(new HttpStatus().EXPECTATION_FAILED()).isEqualTo(417); } - @Test public void I_AM_A_TEAPOT() { + @Test + public void I_AM_A_TEAPOT() { BDDAssertions.then(new HttpStatus().I_AM_A_TEAPOT()).isEqualTo(418); } - @Test public void INSUFFICIENT_SPACE_ON_RESOURCE() { - BDDAssertions.then(new HttpStatus().INSUFFICIENT_SPACE_ON_RESOURCE()).isEqualTo(419); + @Test + public void INSUFFICIENT_SPACE_ON_RESOURCE() { + BDDAssertions.then(new HttpStatus().INSUFFICIENT_SPACE_ON_RESOURCE()) + .isEqualTo(419); } - @Test public void METHOD_FAILURE() { + @Test + public void METHOD_FAILURE() { BDDAssertions.then(new HttpStatus().METHOD_FAILURE()).isEqualTo(420); } - @Test public void DESTINATION_LOCKED() { + @Test + public void DESTINATION_LOCKED() { BDDAssertions.then(new HttpStatus().DESTINATION_LOCKED()).isEqualTo(421); } - @Test public void UNPROCESSABLE_ENTITY() { + @Test + public void UNPROCESSABLE_ENTITY() { BDDAssertions.then(new HttpStatus().UNPROCESSABLE_ENTITY()).isEqualTo(422); } - @Test public void LOCKED() { + @Test + public void LOCKED() { BDDAssertions.then(new HttpStatus().LOCKED()).isEqualTo(423); } - @Test public void FAILED_DEPENDENCY() { + @Test + public void FAILED_DEPENDENCY() { BDDAssertions.then(new HttpStatus().FAILED_DEPENDENCY()).isEqualTo(424); } - @Test public void UPGRADE_REQUIRED() { + @Test + public void UPGRADE_REQUIRED() { BDDAssertions.then(new HttpStatus().UPGRADE_REQUIRED()).isEqualTo(426); } - @Test public void PRECONDITION_REQUIRED() { + @Test + public void PRECONDITION_REQUIRED() { BDDAssertions.then(new HttpStatus().PRECONDITION_REQUIRED()).isEqualTo(428); } - @Test public void TOO_MANY_REQUESTS() { + @Test + public void TOO_MANY_REQUESTS() { BDDAssertions.then(new HttpStatus().TOO_MANY_REQUESTS()).isEqualTo(429); } - @Test public void REQUEST_HEADER_FIELDS_TOO_LARGE() { - BDDAssertions.then(new HttpStatus().REQUEST_HEADER_FIELDS_TOO_LARGE()).isEqualTo(431); + @Test + public void REQUEST_HEADER_FIELDS_TOO_LARGE() { + BDDAssertions.then(new HttpStatus().REQUEST_HEADER_FIELDS_TOO_LARGE()) + .isEqualTo(431); } - @Test public void UNAVAILABLE_FOR_LEGAL_REASONS() { - BDDAssertions.then(new HttpStatus().UNAVAILABLE_FOR_LEGAL_REASONS()).isEqualTo(451); + @Test + public void UNAVAILABLE_FOR_LEGAL_REASONS() { + BDDAssertions.then(new HttpStatus().UNAVAILABLE_FOR_LEGAL_REASONS()) + .isEqualTo(451); } - @Test public void INTERNAL_SERVER_ERROR() { + @Test + public void INTERNAL_SERVER_ERROR() { BDDAssertions.then(new HttpStatus().INTERNAL_SERVER_ERROR()).isEqualTo(500); } - @Test public void NOT_IMPLEMENTED() { + @Test + public void NOT_IMPLEMENTED() { BDDAssertions.then(new HttpStatus().NOT_IMPLEMENTED()).isEqualTo(501); } - @Test public void BAD_GATEWAY() { + @Test + public void BAD_GATEWAY() { BDDAssertions.then(new HttpStatus().BAD_GATEWAY()).isEqualTo(502); } - @Test public void SERVICE_UNAVAILABLE() { + @Test + public void SERVICE_UNAVAILABLE() { BDDAssertions.then(new HttpStatus().SERVICE_UNAVAILABLE()).isEqualTo(503); } - @Test public void GATEWAY_TIMEOUT() { + @Test + public void GATEWAY_TIMEOUT() { BDDAssertions.then(new HttpStatus().GATEWAY_TIMEOUT()).isEqualTo(504); } - @Test public void HTTP_VERSION_NOT_SUPPORTED() { + @Test + public void HTTP_VERSION_NOT_SUPPORTED() { BDDAssertions.then(new HttpStatus().HTTP_VERSION_NOT_SUPPORTED()).isEqualTo(505); } - @Test public void VARIANT_ALSO_NEGOTIATES() { + @Test + public void VARIANT_ALSO_NEGOTIATES() { BDDAssertions.then(new HttpStatus().VARIANT_ALSO_NEGOTIATES()).isEqualTo(506); } - @Test public void INSUFFICIENT_STORAGE() { + @Test + public void INSUFFICIENT_STORAGE() { BDDAssertions.then(new HttpStatus().INSUFFICIENT_STORAGE()).isEqualTo(507); } - @Test public void LOOP_DETECTED() { + @Test + public void LOOP_DETECTED() { BDDAssertions.then(new HttpStatus().LOOP_DETECTED()).isEqualTo(508); } - @Test public void BANDWIDTH_LIMIT_EXCEEDED() { + @Test + public void BANDWIDTH_LIMIT_EXCEEDED() { BDDAssertions.then(new HttpStatus().BANDWIDTH_LIMIT_EXCEEDED()).isEqualTo(509); } - @Test public void NOT_EXTENDED() { + @Test + public void NOT_EXTENDED() { BDDAssertions.then(new HttpStatus().NOT_EXTENDED()).isEqualTo(510); } - @Test public void NETWORK_AUTHENTICATION_REQUIRED() { - BDDAssertions.then(new HttpStatus().NETWORK_AUTHENTICATION_REQUIRED()).isEqualTo(511); + @Test + public void NETWORK_AUTHENTICATION_REQUIRED() { + BDDAssertions.then(new HttpStatus().NETWORK_AUTHENTICATION_REQUIRED()) + .isEqualTo(511); } -} \ No newline at end of file + +} diff --git a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/InputSpec.groovy b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/InputSpec.groovy index 3ce89c0272..5748090ee6 100644 --- a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/InputSpec.groovy +++ b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/InputSpec.groovy @@ -1,6 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal import spock.lang.Specification + /** * @author Tim Ysewyn */ diff --git a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/MatchingTypeSpec.groovy b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/MatchingTypeSpec.groovy index 9abd39202e..1b895ac1d9 100644 --- a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/MatchingTypeSpec.groovy +++ b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/MatchingTypeSpec.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal import spock.lang.Specification diff --git a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/OutputMessageSpec.groovy b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/OutputMessageSpec.groovy index 6e1bd0b41f..894d16d199 100644 --- a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/OutputMessageSpec.groovy +++ b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/OutputMessageSpec.groovy @@ -1,6 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal import spock.lang.Specification + /** * @author Tim Ysewyn */ diff --git a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/RegexPatternsSpec.groovy b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/RegexPatternsSpec.groovy index 188f8ef561..306392b0d7 100644 --- a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/RegexPatternsSpec.groovy +++ b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/RegexPatternsSpec.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal @@ -48,9 +48,9 @@ class RegexPatternsSpec extends Specification { expect: shouldMatch == regexPatterns.email().matcher(textToMatch).matches() where: - textToMatch || shouldMatch - 'asd@asd.com' || true - 'a.b.' || false + textToMatch || shouldMatch + 'asd@asd.com' || true + 'a.b.' || false 'asdf@asdf.online' || true } @@ -307,20 +307,20 @@ class RegexPatternsSpec extends Specification { "23:59:60" || false } - def "should generate a regex with iso8601DateTimeWithTimezone [#textToMatch] in YYYY-MM-DDTHH:mm:ss.SSSZZ format that should match [#shouldMatch]"(){ + def "should generate a regex with iso8601DateTimeWithTimezone [#textToMatch] in YYYY-MM-DDTHH:mm:ss.SSSZZ format that should match [#shouldMatch]"() { expect: shouldMatch == regexPatterns.iso8601WithOffset().matcher(textToMatch).matches() where: - textToMatch || shouldMatch - '2014-03-01T12:23:45Z' || true - '2014-03-01T12:23:45+01:00' || true - '2014-03-01T12:23:45.123Z' || true - '2014-03-01T12:23:45.123+01:00' || true - '2014-03-01T12:23:45' || false - '2014-03-01T12:23:45.123' || false + textToMatch || shouldMatch + '2014-03-01T12:23:45Z' || true + '2014-03-01T12:23:45+01:00' || true + '2014-03-01T12:23:45.123Z' || true + '2014-03-01T12:23:45.123+01:00' || true + '2014-03-01T12:23:45' || false + '2014-03-01T12:23:45.123' || false } - def "should generate a regex for a non blank string [#textToMatch] that should match [#shouldMatch]"(){ + def "should generate a regex for a non blank string [#textToMatch] that should match [#shouldMatch]"() { expect: shouldMatch == regexPatterns.nonBlank().matcher(textToMatch).matches() where: @@ -348,13 +348,13 @@ class RegexPatternsSpec extends Specification { } - def "should generate a regex for an enumerated value [#textToMatch] that should match [#shouldMatch]"(){ + def "should generate a regex for an enumerated value [#textToMatch] that should match [#shouldMatch]"() { expect: shouldMatch == RegexPatterns.anyOf('foo', 'bar').matcher(textToMatch).matches() where: - textToMatch || shouldMatch - 'foo' || true - 'bar' || true - 'baz' || false + textToMatch || shouldMatch + 'foo' || true + 'bar' || true + 'baz' || false } } diff --git a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/RequestSpec.groovy b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/RequestSpec.groovy index 141c0fb175..fd5ed8ffa6 100644 --- a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/RequestSpec.groovy +++ b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/RequestSpec.groovy @@ -1,6 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal import spock.lang.Specification + /** * @author Marcin Grzejszczak */ @@ -22,6 +39,7 @@ class RequestSpec extends Specification { then: thrown(IllegalStateException) } + def 'should set property when using the $() convenience method'() { given: Request contract = new Request() diff --git a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/ResponseSpec.groovy b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/ResponseSpec.groovy index 583feee7be..5a413e94a2 100644 --- a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/ResponseSpec.groovy +++ b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/ResponseSpec.groovy @@ -1,6 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.internal -import spock.lang.Specification +import spock.lang.Specification + /** * @author Marcin Grzejszczak */ diff --git a/spring-cloud-contract-spec/src/test/groovy/repackaged/nl/flotsam/xeger/XegerTest.java b/spring-cloud-contract-spec/src/test/groovy/repackaged/nl/flotsam/xeger/XegerTest.java index 7816ff9305..6380c0475f 100644 --- a/spring-cloud-contract-spec/src/test/groovy/repackaged/nl/flotsam/xeger/XegerTest.java +++ b/spring-cloud-contract-spec/src/test/groovy/repackaged/nl/flotsam/xeger/XegerTest.java @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package repackaged.nl.flotsam.xeger; import java.util.ArrayList; @@ -102,4 +103,5 @@ public class XegerTest { } return regexList; } -} \ No newline at end of file + +} diff --git a/spring-cloud-contract-spec/src/test/groovy/repackaged/nl/flotsam/xeger/XegerUtilsTest.java b/spring-cloud-contract-spec/src/test/groovy/repackaged/nl/flotsam/xeger/XegerUtilsTest.java index 7c7d0e0968..0bac6815cd 100644 --- a/spring-cloud-contract-spec/src/test/groovy/repackaged/nl/flotsam/xeger/XegerUtilsTest.java +++ b/spring-cloud-contract-spec/src/test/groovy/repackaged/nl/flotsam/xeger/XegerUtilsTest.java @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package repackaged.nl.flotsam.xeger; import java.util.Random; @@ -26,7 +27,8 @@ import static org.junit.Assert.assertThat; public class XegerUtilsTest { - @Test public void shouldGenerateRandomNumberCorrectly() { + @Test + public void shouldGenerateRandomNumberCorrectly() { Random random = new Random(); for (int i = 0; i < 100; i++) { int number = Xeger.getRandomInt(3, 7, random); @@ -35,4 +37,4 @@ public class XegerUtilsTest { } } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-starters/pom.xml b/spring-cloud-contract-starters/pom.xml index bc60a2d494..77fb240b68 100644 --- a/spring-cloud-contract-starters/pom.xml +++ b/spring-cloud-contract-starters/pom.xml @@ -1,6 +1,6 @@ - 4.0.0 diff --git a/spring-cloud-contract-starters/spring-cloud-starter-contract-stub-runner-jetty/pom.xml b/spring-cloud-contract-starters/spring-cloud-starter-contract-stub-runner-jetty/pom.xml index 2c9433ed99..e0b45a9ebd 100644 --- a/spring-cloud-contract-starters/spring-cloud-starter-contract-stub-runner-jetty/pom.xml +++ b/spring-cloud-contract-starters/spring-cloud-starter-contract-stub-runner-jetty/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 org.springframework.cloud @@ -11,7 +12,9 @@ spring-cloud-starter-contract-stub-runner-jetty jar Spring Cloud Contract Stub Runner Starter Jetty - Spring Cloud Contract Stub Runner Jetty runs wiremock stubs with "native" jetty. Don't use this in a Spring Boot app with its own embedded container. + Spring Cloud Contract Stub Runner Jetty runs wiremock stubs with "native" + jetty. Don't use this in a Spring Boot app with its own embedded container. + org.springframework.cloud diff --git a/spring-cloud-contract-starters/spring-cloud-starter-contract-stub-runner/pom.xml b/spring-cloud-contract-starters/spring-cloud-starter-contract-stub-runner/pom.xml index 6f9b6e7ac4..9a72eb2857 100644 --- a/spring-cloud-contract-starters/spring-cloud-starter-contract-stub-runner/pom.xml +++ b/spring-cloud-contract-starters/spring-cloud-starter-contract-stub-runner/pom.xml @@ -16,7 +16,8 @@ ~ --> - 4.0.0 diff --git a/spring-cloud-contract-starters/spring-cloud-starter-contract-verifier/pom.xml b/spring-cloud-contract-starters/spring-cloud-starter-contract-verifier/pom.xml index f940e86ba1..3455dcb9b3 100644 --- a/spring-cloud-contract-starters/spring-cloud-starter-contract-verifier/pom.xml +++ b/spring-cloud-contract-starters/spring-cloud-starter-contract-verifier/pom.xml @@ -1,5 +1,6 @@ - 4.0.0 diff --git a/spring-cloud-contract-stub-runner-boot/pom.xml b/spring-cloud-contract-stub-runner-boot/pom.xml index 883c96024a..3f535883ba 100644 --- a/spring-cloud-contract-stub-runner-boot/pom.xml +++ b/spring-cloud-contract-stub-runner-boot/pom.xml @@ -1,5 +1,6 @@ - 4.0.0 diff --git a/spring-cloud-contract-stub-runner-boot/src/main/java/org/springframework/cloud/contract/stubrunner/server/StubRunnerBoot.java b/spring-cloud-contract-stub-runner-boot/src/main/java/org/springframework/cloud/contract/stubrunner/server/StubRunnerBoot.java index 84382192d7..4872341442 100644 --- a/spring-cloud-contract-stub-runner-boot/src/main/java/org/springframework/cloud/contract/stubrunner/server/StubRunnerBoot.java +++ b/spring-cloud-contract-stub-runner-boot/src/main/java/org/springframework/cloud/contract/stubrunner/server/StubRunnerBoot.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.server; diff --git a/spring-cloud-contract-stub-runner/pom.xml b/spring-cloud-contract-stub-runner/pom.xml index 79fdd8d4f9..6497c1a33e 100644 --- a/spring-cloud-contract-stub-runner/pom.xml +++ b/spring-cloud-contract-stub-runner/pom.xml @@ -1,5 +1,6 @@ - 4.0.0 diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherFactories.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherFactories.java index 2485218e2c..9b89476cfe 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherFactories.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherFactories.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -28,7 +28,6 @@ import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.repository.LocalRepository; import org.eclipse.aether.repository.RepositoryPolicy; -import org.springframework.util.StringUtils; import shaded.org.apache.maven.repository.internal.MavenRepositorySystemUtils; import shaded.org.apache.maven.settings.Settings; import shaded.org.apache.maven.settings.building.DefaultSettingsBuilderFactory; @@ -44,7 +43,9 @@ import shaded.org.eclipse.aether.spi.connector.transport.TransporterFactory; import shaded.org.eclipse.aether.transport.file.FileTransporterFactory; import shaded.org.eclipse.aether.transport.http.HttpTransporterFactory; -class AetherFactories { +import org.springframework.util.StringUtils; + +final class AetherFactories { private static final Log log = LogFactory.getLog(AetherFactories.class); @@ -56,6 +57,10 @@ class AetherFactories { private static final Random RANDOM = new Random(); + private AetherFactories() { + throw new IllegalStateException("Can't instantiate a utility class"); + } + public static RepositorySystem newRepositorySystem() { DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator(); locator.addService(RepositoryConnectorFactory.class, diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherStubDownloader.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherStubDownloader.java index 153ce27706..c19b651325 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherStubDownloader.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherStubDownloader.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -38,6 +38,7 @@ import org.eclipse.aether.resolution.VersionRangeRequest; import org.eclipse.aether.resolution.VersionRangeResolutionException; import org.eclipse.aether.resolution.VersionRangeResult; import org.eclipse.aether.util.repository.AuthenticationBuilder; + import org.springframework.cloud.contract.stubrunner.StubRunnerOptions.StubRunnerProxyOptions; import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties; import org.springframework.util.StringUtils; @@ -103,15 +104,11 @@ public class AetherStubDownloader implements StubDownloader { registerShutdownHook(); } - private boolean remoteReposMissing() { - return this.remoteRepos == null || this.remoteRepos.isEmpty(); - } - /** - * Used by the Maven Plugin - * @param repositorySystem - * @param remoteRepositories - remote artifact repositories - * @param session + * Used by the Maven Plugin. + * @param repositorySystem Maven repository system + * @param remoteRepositories remote artifact repositories + * @param session repository system session */ public AetherStubDownloader(RepositorySystem repositorySystem, List remoteRepositories, RepositorySystemSession session) { @@ -127,6 +124,19 @@ public class AetherStubDownloader implements StubDownloader { registerShutdownHook(); } + private static File unpackStubJarToATemporaryFolder(URI stubJarUri) { + File tmpDirWhereStubsWillBeUnzipped = TemporaryFileStorage + .createTempDir(TEMP_DIR_PREFIX); + log.info("Unpacking stub from JAR [URI: " + stubJarUri + "]"); + unzipTo(new File(stubJarUri), tmpDirWhereStubsWillBeUnzipped); + TemporaryFileStorage.add(tmpDirWhereStubsWillBeUnzipped); + return tmpDirWhereStubsWillBeUnzipped; + } + + private boolean remoteReposMissing() { + return this.remoteRepos == null || this.remoteRepos.isEmpty(); + } + private List remoteRepositories( StubRunnerOptions stubRunnerOptions) { if (stubRunnerOptions.stubRepositoryRoot == null) { @@ -262,18 +272,9 @@ public class AetherStubDownloader implements StubDownloader { : rangeResult.getHighestVersion().toString(); } - private static File unpackStubJarToATemporaryFolder(URI stubJarUri) { - File tmpDirWhereStubsWillBeUnzipped = TemporaryFileStorage - .createTempDir(TEMP_DIR_PREFIX); - log.info("Unpacking stub from JAR [URI: " + stubJarUri + "]"); - unzipTo(new File(stubJarUri), tmpDirWhereStubsWillBeUnzipped); - TemporaryFileStorage.add(tmpDirWhereStubsWillBeUnzipped); - return tmpDirWhereStubsWillBeUnzipped; - } - private void registerShutdownHook() { Runtime.getRuntime().addShutdownHook(new Thread(() -> TemporaryFileStorage .cleanup(AetherStubDownloader.this.deleteStubsAfterTest))); } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherStubDownloaderBuilder.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherStubDownloaderBuilder.java index 14c7de2902..18fba5a9e3 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherStubDownloaderBuilder.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherStubDownloaderBuilder.java @@ -1,7 +1,24 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties; /** diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/Arguments.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/Arguments.java index 1184329150..11c76df1a1 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/Arguments.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/Arguments.java @@ -1,23 +1,23 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; /** - * Arguments passed to the {@link StubRunner} application + * Arguments passed to the {@link StubRunner} application. * * @see StubRunner */ @@ -59,4 +59,4 @@ class Arguments { + this.stub + '}'; } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AvailablePortScanner.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AvailablePortScanner.java index f0685d9972..4550cb3a3d 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AvailablePortScanner.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AvailablePortScanner.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -24,7 +24,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** - * Tries to execute a closure with an available port from the given range + * Tries to execute a closure with an available port from the given range. */ class AvailablePortScanner { @@ -94,6 +94,12 @@ class AvailablePortScanner { } } + public interface PortCallback { + + T call(int port) throws IOException; + + } + @SuppressWarnings("serial") static class NoPortAvailableException extends RuntimeException { @@ -114,10 +120,4 @@ class AvailablePortScanner { } - public interface PortCallback { - - T call(int port) throws IOException; - - } - } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/BatchStubRunner.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/BatchStubRunner.java index 35b66502b0..659913bbfd 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/BatchStubRunner.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/BatchStubRunner.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -29,6 +29,7 @@ import org.springframework.cloud.contract.spec.Contract; /** * Manages lifecycle of multiple {@link StubRunner} instances. * + * @author Marcin Grzejszczak * @see StubRunner */ public class BatchStubRunner implements StubRunning { diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/BatchStubRunnerFactory.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/BatchStubRunnerFactory.java index 7ba92e3cef..c329070a2a 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/BatchStubRunnerFactory.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/BatchStubRunnerFactory.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -22,6 +22,7 @@ import org.springframework.cloud.contract.verifier.messaging.noop.NoOpStubMessag /** * Manages lifecycle of multiple {@link StubRunner} instances. * + * @author Marcin Grzejszczak * @see StubRunner * @see BatchStubRunner */ @@ -42,12 +43,6 @@ public class BatchStubRunnerFactory { this(stubRunnerOptions, aetherStubDownloader(stubRunnerOptions), verifier); } - private static StubDownloader aetherStubDownloader( - StubRunnerOptions stubRunnerOptions) { - StubDownloaderBuilderProvider provider = new StubDownloaderBuilderProvider(); - return provider.get(stubRunnerOptions); - } - public BatchStubRunnerFactory(StubRunnerOptions stubRunnerOptions, StubDownloader stubDownloader) { this(stubRunnerOptions, stubDownloader, new NoOpStubMessages()); @@ -60,6 +55,12 @@ public class BatchStubRunnerFactory { this.contractVerifierMessaging = contractVerifierMessaging; } + private static StubDownloader aetherStubDownloader( + StubRunnerOptions stubRunnerOptions) { + StubDownloaderBuilderProvider provider = new StubDownloaderBuilderProvider(); + return provider.get(stubRunnerOptions); + } + public BatchStubRunner buildBatchStubRunner() { StubRunnerFactory stubRunnerFactory = new StubRunnerFactory( this.stubRunnerOptions, this.stubDownloader, diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ClasspathStubProvider.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ClasspathStubProvider.java index 301d87095b..1dd2c646df 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ClasspathStubProvider.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ClasspathStubProvider.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 java.io.File; @@ -17,6 +33,7 @@ import java.util.regex.Pattern; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; @@ -235,4 +252,4 @@ public class ClasspathStubProvider implements StubDownloaderBuilder { } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/CompositeStubDownloaderBuilder.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/CompositeStubDownloaderBuilder.java index dfc55d0640..16e6011856 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/CompositeStubDownloaderBuilder.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/CompositeStubDownloaderBuilder.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ContractDownloader.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ContractDownloader.java index 86cd5b56cb..883778f9ed 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ContractDownloader.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ContractDownloader.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,12 +22,13 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties; import org.springframework.util.StringUtils; /** * Downloads a JAR with contracts and sets up the plugin configuration with proper - * inclusion patterns + * inclusion patterns. * * @author Marcin Grzejszczak * @since 1.0.0 diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ContractProjectUpdater.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ContractProjectUpdater.java index f5133e26e6..410a454733 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ContractProjectUpdater.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ContractProjectUpdater.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.cloud.contract.stubrunner; import java.io.File; @@ -66,9 +67,9 @@ public class ContractProjectUpdater { } /** - * Merges the folder with stubs with the project containing contracts - * @param projectName - * @param rootStubsFolder + * Merges the folder with stubs with the project containing contracts. + * @param projectName name of the project + * @param rootStubsFolder root folder of the stubs */ public void updateContractProject(String projectName, Path rootStubsFolder) { File clonedRepo = this.gitContractsRepo @@ -161,8 +162,8 @@ public class ContractProjectUpdater { class DirectoryCopyingVisitor extends SimpleFileVisitor { - private static final List FOLDERS_TO_DELETE = Arrays - .asList("contracts", "mappings"); + private static final List FOLDERS_TO_DELETE = Arrays.asList("contracts", + "mappings"); private static final Log log = LogFactory.getLog(DirectoryCopyingVisitor.class); @@ -220,21 +221,25 @@ class DirectoryCopyingVisitor extends SimpleFileVisitor { } Files.walkFileTree(root, new SimpleFileVisitor() { @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) + throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override - public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + public FileVisitResult postVisitDirectory(Path dir, IOException exc) + throws IOException { // a hack for Windows not to fail when directory is removed - // related to https://github.com/spring-cloud/spring-cloud-sleuth/issues/834 + // related to + // https://github.com/spring-cloud/spring-cloud-sleuth/issues/834 if (exc == null) { int maxTries = 5; int count = 0; boolean deleted; do { - if ((deleted = this.isDeleted(dir))) { + deleted = this.isDeleted(dir); + if (deleted) { if (log.isDebugEnabled()) { log.debug("Deleted [" + dir + "]"); } @@ -257,7 +262,8 @@ class DirectoryCopyingVisitor extends SimpleFileVisitor { while (count < maxTries); if (!deleted) { if (log.isDebugEnabled()) { - log.debug("Failed to delete [" + dir + "] after [" + maxTries + "] attempts to do it"); + log.debug("Failed to delete [" + dir + "] after [" + maxTries + + "] attempts to do it"); } throw new DirectoryNotEmptyException(dir.toString()); } @@ -272,7 +278,8 @@ class DirectoryCopyingVisitor extends SimpleFileVisitor { return true; } catch (DirectoryNotEmptyException e) { - // happens sometimes if Windows is too slow to remove children of a directory + // happens sometimes if Windows is too slow to remove children of a + // directory return false; } } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/GitRepo.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/GitRepo.java index 8f85412373..e756551ba4 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/GitRepo.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/GitRepo.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.cloud.contract.stubrunner; import java.io.File; @@ -57,6 +58,7 @@ import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.util.ResourceUtils; /** @@ -95,7 +97,7 @@ class GitRepo { } /** - * Clones the project + * Clones the project. * @param projectUri - URI of the project * @return file where the project was cloned */ @@ -116,7 +118,7 @@ class GitRepo { } /** - * Checks out a branch for a project + * Checks out a branch for a project. * @param project - a Git project * @param branch - branch to check out */ @@ -137,7 +139,7 @@ class GitRepo { } /** - * Pulls changes for the project + * Pulls changes for the project. * @param project - a Git project */ void pull(File project) { @@ -153,9 +155,10 @@ class GitRepo { } /** - * Performs a commit + * Performs a commit. * @param project - a Git project * @param message - commit message + * @return result of the commit */ CommitResult commit(File project, String message) { try (Git git = this.gitFactory.open(file(project))) { @@ -182,14 +185,8 @@ class GitRepo { } } - enum CommitResult { - - SUCCESSFUL, EMPTY - - } - /** - * Pushes the commits od current branch + * Pushes the commits od current branch. * @param project - Git project */ void pushCurrentBranch(File project) { @@ -304,6 +301,12 @@ class GitRepo { } } + enum CommitResult { + + SUCCESSFUL, EMPTY + + } + /** * Wraps the static method calls to {@link Git} and {@link CloneCommand} allowing for * easier unit testing. @@ -313,6 +316,8 @@ class GitRepo { private static final Logger log = LoggerFactory .getLogger(MethodHandles.lookup().lookupClass()); + final CredentialsProvider provider; + private final JschConfigSessionFactory factory = new JschConfigSessionFactory() { @Override @@ -347,7 +352,12 @@ class GitRepo { } }; - final CredentialsProvider provider; + private final TransportConfigCallback callback = transport -> { + if (transport instanceof SshTransport) { + SshTransport sshTransport = (SshTransport) transport; + sshTransport.setSshSessionFactory(this.factory); + } + }; JGitFactory(GitStubDownloaderProperties properties) { if (org.springframework.util.StringUtils.hasText(properties.username)) { @@ -363,22 +373,15 @@ class GitRepo { } } - CredentialsProvider credentialsProvider(GitStubDownloaderProperties properties) { - return new UsernamePasswordCredentialsProvider(properties.username, - properties.password); - } - // for tests JGitFactory() { this.provider = null; } - private final TransportConfigCallback callback = transport -> { - if (transport instanceof SshTransport) { - SshTransport sshTransport = (SshTransport) transport; - sshTransport.setSshSessionFactory(this.factory); - } - }; + CredentialsProvider credentialsProvider(GitStubDownloaderProperties properties) { + return new UsernamePasswordCredentialsProvider(properties.username, + properties.password); + } CloneCommand getCloneCommandByCloneRepository() { return Git.cloneRepository().setCredentialsProvider(this.provider) diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/HttpServerStub.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/HttpServerStub.java index 765e7aac5e..305d695431 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/HttpServerStub.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/HttpServerStub.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.cloud.contract.stubrunner; import java.io.File; import java.util.Collection; /** - * Describes an HTTP Server Stub + * Describes an HTTP Server Stub. * * @author Marcin Grzejszczak * @since 1.1.0 @@ -27,25 +28,27 @@ import java.util.Collection; public interface HttpServerStub { /** - * Port on which the server is running. Return {@code -1} if not applicable. + * @return port on which the server is running. Return {@code -1} if not applicable. */ int port(); /** - * Https port on which the server is running. Return {@code -1} if not applicable. + * @return https port on which the server is running. Return {@code -1} if not + * applicable. */ default int httpsPort() { return -1; } /** - * Returns {@code true} if the server is running + * @return {@code true} if the server is running */ boolean isRunning(); /** * Starts the server on a random port. Should return itself to allow chaining. * @deprecated use {@link HttpServerStub#start(HttpServerStubConfiguration)} + * @return this */ @Deprecated HttpServerStub start(); @@ -53,6 +56,8 @@ public interface HttpServerStub { /** * Starts the server on a given port. Should return itself to allow chaining. * @deprecated use {@link HttpServerStub#start(HttpServerStubConfiguration)} + * @param port port on which the server should be ran + * @return this */ @Deprecated HttpServerStub start(int port); @@ -60,6 +65,7 @@ public interface HttpServerStub { /** * Starts the server. Should return itself to allow chaining. * @param configuration - setup for the given stub + * @return this */ default HttpServerStub start(HttpServerStubConfiguration configuration) { if (configuration.isRandomPort()) { @@ -70,11 +76,13 @@ public interface HttpServerStub { /** * Stops the server. Should return itself to allow chaining. + * @return this */ HttpServerStub stop(); /** * Resets the server. Should return itself to allow chaining. + * @return this */ default HttpServerStub reset() { return this; @@ -83,16 +91,20 @@ public interface HttpServerStub { /** * Registers the stub files in the HTTP server stub. Should return itself to allow * chaining. + * @param stubFiles collection of files containing stubs + * @return this */ HttpServerStub registerMappings(Collection stubFiles); /** - * Returns a collection of registered mappings + * @return a collection of registered mappings. */ String registeredMappings(); /** - * Returns {@code true} if the file is a valid stub mapping + * @param file file to check if can be accepted. + * @return {@code true} if the file is a valid stub mapping */ boolean isAccepted(File file); + } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/HttpServerStubConfiguration.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/HttpServerStubConfiguration.java index a30a5a6996..8a3f24fdd5 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/HttpServerStubConfiguration.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/HttpServerStubConfiguration.java @@ -17,17 +17,36 @@ package org.springframework.cloud.contract.stubrunner; /** - * Configuration class for an {@link HttpServerStub} - * @since 2.1.0 + * Configuration class for an {@link HttpServerStub}. + * * @author Marcin Grzejszczak + * @since 2.1.0 */ public final class HttpServerStubConfiguration { + + /** + * Allows to perform additional configuration of the HTTP Server stub. + */ public final HttpServerStubConfigurer configurer; + + /** + * Options of Stub Runner itself. + */ public final StubRunnerOptions stubRunnerOptions; + + /** + * Configuration of a particular stub. + */ public final StubConfiguration stubConfiguration; + + /** + * Port at which the stub will be started. + */ public final Integer port; - public HttpServerStubConfiguration(HttpServerStubConfigurer configurer, StubRunnerOptions stubRunnerOptions, StubConfiguration stubConfiguration, Integer port) { + public HttpServerStubConfiguration(HttpServerStubConfigurer configurer, + StubRunnerOptions stubRunnerOptions, StubConfiguration stubConfiguration, + Integer port) { this.configurer = configurer; this.stubRunnerOptions = stubRunnerOptions; this.stubConfiguration = stubConfiguration; @@ -39,7 +58,8 @@ public final class HttpServerStubConfiguration { } public String toColonSeparatedDependencyNotation() { - return this.stubConfiguration != null ? - this.stubConfiguration.toColonSeparatedDependencyNotation() : ""; + return this.stubConfiguration != null + ? this.stubConfiguration.toColonSeparatedDependencyNotation() : ""; } -} \ No newline at end of file + +} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/HttpServerStubConfigurer.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/HttpServerStubConfigurer.java index f5037a3a28..60393c64b2 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/HttpServerStubConfigurer.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/HttpServerStubConfigurer.java @@ -17,24 +17,26 @@ package org.springframework.cloud.contract.stubrunner; /** - * Allows to perform additional configuration of the HTTP Server stub + * Allows to perform additional configuration of the HTTP Server stub. * + * @param type of the stub configuration * @author Marcin Grzejszczak * @since 2.1.0 */ public interface HttpServerStubConfigurer { /** - * Ensures that the HTTP server stub implementation configuration type is accepted + * Ensures that the HTTP server stub implementation configuration type is accepted. * @param httpStubConfiguration - HTTP server stub implementation * @return {@code true} when this configurer can be applied for this object */ boolean isAccepted(Object httpStubConfiguration); /** - * Performs additional configuration of the HTTP Server Stub + * Performs additional configuration of the HTTP Server Stub. * @param httpStubConfiguration - stub implementation to configure * @param httpServerStubConfiguration - Spring Cloud Contract stub configuration + * @return the modified stub configuration */ default T configure(T httpStubConfiguration, HttpServerStubConfiguration httpServerStubConfiguration) { @@ -42,14 +44,17 @@ public interface HttpServerStubConfigurer { } /** - * Implementation that does nothing + * Implementation that does nothing. */ class NoOpHttpServerStubConfigurer implements HttpServerStubConfigurer { + public static HttpServerStubConfigurer INSTANCE = new NoOpHttpServerStubConfigurer(); @Override public boolean isAccepted(Object httpStubConfiguration) { return false; } + } + } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/MessageNotMatchingException.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/MessageNotMatchingException.java index 5290a991e8..1554162e30 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/MessageNotMatchingException.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/MessageNotMatchingException.java @@ -1,23 +1,23 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; /** - * Exception thrown when message is not matched + * Exception thrown when message is not matched. * * @author Marcin Grzejszczak */ diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/NoOpHttpServerStub.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/NoOpHttpServerStub.java index d0d1606b12..d1ab4d88f6 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/NoOpHttpServerStub.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/NoOpHttpServerStub.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 java.io.File; diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ResourceResolver.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ResourceResolver.java index c290871244..accc42c42a 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ResourceResolver.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ResourceResolver.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,6 +21,7 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.ProtocolResolver; import org.springframework.core.io.Resource; @@ -38,7 +39,7 @@ import org.springframework.core.io.support.SpringFactoriesLoader; * @author Marcin Grzejszczak * @since 2.0.0 */ -public class ResourceResolver { +public final class ResourceResolver { private static final Log log = LogFactory.getLog(ResourceResolver.class); @@ -56,6 +57,10 @@ public class ResourceResolver { } } + private ResourceResolver() { + throw new IllegalStateException("Can't instantiate a utility class"); + } + /** * @param url - string url * @return corresponding {@link Resource} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/RunningStubs.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/RunningStubs.java index de2d341777..0d43934580 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/RunningStubs.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/RunningStubs.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -26,6 +26,8 @@ import java.util.Set; /** * Structure representing executed stubs. Contains the configuration of each stub together * with the port on which its executed. + * + * @author Marcin Grzejszczak */ public class RunningStubs { @@ -117,20 +119,25 @@ public class RunningStubs { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } RunningStubs other = (RunningStubs) obj; if (this.namesAndPorts == null) { - if (other.namesAndPorts != null) + if (other.namesAndPorts != null) { return false; + } } - else if (!this.namesAndPorts.equals(other.namesAndPorts)) + else if (!this.namesAndPorts.equals(other.namesAndPorts)) { return false; + } return true; } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ScmStubDownloaderBuilder.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ScmStubDownloaderBuilder.java index be9c73fd21..83b0701971 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ScmStubDownloaderBuilder.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ScmStubDownloaderBuilder.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -47,7 +47,7 @@ import org.springframework.core.io.ResourceLoader; import org.springframework.util.StringUtils; /** - * Builds a {@link StubDownloader} to work with contracts and stubs from a SCM + * Builds a {@link StubDownloader} to work with contracts and stubs from a SCM. * * @author Marcin Grzejszczak * @since 2.0.0 @@ -58,8 +58,9 @@ public final class ScmStubDownloaderBuilder implements StubDownloaderBuilder { .singletonList("git"); /** - * Does any of the accepted protocols matches the URL of the repository + * Does any of the accepted protocols matches the URL of the repository. * @param url - of the repository + * @return {@code true} if the protocol is accepted */ public static boolean isProtocolAccepted(String url) { return ACCEPTABLE_PROTOCOLS.stream().anyMatch(url::startsWith); @@ -89,7 +90,7 @@ public final class ScmStubDownloaderBuilder implements StubDownloaderBuilder { } /** - * Primitive version of a Git {@link Resource} + * Primitive version of a Git {@link Resource}. */ class GitResource extends AbstractResource { @@ -118,10 +119,11 @@ class GitResource extends AbstractResource { class GitContractsRepo { + static final Map CACHED_LOCATIONS = new ConcurrentHashMap<>(); + private static final Log log = LogFactory.getLog(GitContractsRepo.class); private static final String TEMP_DIR_PREFIX = "git-contracts"; - static final Map CACHED_LOCATIONS = new ConcurrentHashMap<>(); private final StubRunnerOptions options; @@ -201,8 +203,7 @@ class GitStubDownloader implements StubDownloader { } if (log.isWarnEnabled()) { log.warn("No matching contracts were found in the repo for [" - + stubConfiguration.toColonSeparatedDependencyNotation() - + "]"); + + stubConfiguration.toColonSeparatedDependencyNotation() + "]"); } return null; } @@ -281,22 +282,24 @@ class FileWalker extends SimpleFileVisitor { private static final Log log = LogFactory.getLog(FileWalker.class); private static final List LATEST = Arrays.asList("latest", "+"); + private static final String RELEASE = "release"; private final PathMatcher matcherWithDot; private final PathMatcher matcherWithoutDot; - Path foundFile; - private final boolean latestSnapshotVersion; private final boolean latestReleaseVersion; + Path foundFile; + FileWalker(StubConfiguration stubConfiguration) { - this.latestSnapshotVersion = LATEST.stream().anyMatch( - s -> s.equals(stubConfiguration.version.toLowerCase())); - this.latestReleaseVersion = RELEASE.equals(stubConfiguration.version.toLowerCase()); + this.latestSnapshotVersion = LATEST.stream() + .anyMatch(s -> s.equals(stubConfiguration.version.toLowerCase())); + this.latestReleaseVersion = RELEASE + .equals(stubConfiguration.version.toLowerCase()); this.matcherWithDot = FileSystems.getDefault() .getPathMatcher("glob:" + matcherGlob(stubConfiguration, ".")); this.matcherWithoutDot = FileSystems.getDefault() @@ -306,8 +309,9 @@ class FileWalker extends SimpleFileVisitor { private String matcherGlob(StubConfiguration stubConfiguration, String groupArtifactSeparator) { return "**" + stubConfiguration.groupId + groupArtifactSeparator - + stubConfiguration.artifactId + "/" + (this.latestSnapshotVersion || - this.latestReleaseVersion ? "**" : stubConfiguration.version); + + stubConfiguration.artifactId + "/" + + (this.latestSnapshotVersion || this.latestReleaseVersion ? "**" + : stubConfiguration.version); } @Override @@ -317,18 +321,21 @@ class FileWalker extends SimpleFileVisitor { || this.matcherWithoutDot.matches(dir.toAbsolutePath())) { if (this.latestSnapshotVersion || this.latestReleaseVersion) { // folders with name latest, release - File[] files = Objects.requireNonNull(dir.getParent().toFile() - .listFiles(File::isDirectory)); + File[] files = Objects.requireNonNull( + dir.getParent().toFile().listFiles(File::isDirectory)); File file = folderWithPredefinedName(files); if (file != null) { if (log.isDebugEnabled()) { - log.debug("Found folder with name corresponding to a latest version [" + file + "] "); + log.debug( + "Found folder with name corresponding to a latest version [" + + file + "] "); this.foundFile = file.toPath(); return FileVisitResult.TERMINATE; } } return latestVersionFromFolders(dir, files); - } else { + } + else { this.foundFile = dir; } return FileVisitResult.TERMINATE; @@ -340,26 +347,35 @@ class FileWalker extends SimpleFileVisitor { List versions = pickLatestVersion(files); if (versions.isEmpty()) { if (log.isDebugEnabled()) { - log.debug("Not a single version matching semver for path [" + dir.toAbsolutePath().toString() + "] was found"); + log.debug("Not a single version matching semver for path [" + + dir.toAbsolutePath().toString() + "] was found"); } return FileVisitResult.CONTINUE; } // 2.0.0.RELEASE, 2.0.0.BUILD-SNAPSHOT // 2.0.0.RELEASE - DefaultArtifactVersionWrapper latestFoundVersion = versions.get(versions.size() - 1); - latestFoundVersion = replaceWithSnapshotIfSameVersions(versions, latestFoundVersion); + DefaultArtifactVersionWrapper latestFoundVersion = versions + .get(versions.size() - 1); + latestFoundVersion = replaceWithSnapshotIfSameVersions(versions, + latestFoundVersion); this.foundFile = latestFoundVersion.file.toPath(); return FileVisitResult.TERMINATE; } - private DefaultArtifactVersionWrapper replaceWithSnapshotIfSameVersions(List versions, DefaultArtifactVersionWrapper latestFoundVersion) { + private DefaultArtifactVersionWrapper replaceWithSnapshotIfSameVersions( + List versions, + DefaultArtifactVersionWrapper latestFoundVersion) { if (versions.size() > 1 && this.latestSnapshotVersion) { // 2.0.0.BUILD-SNAPSHOT - DefaultArtifactVersionWrapper versionWrapper = versions.get(versions.size() - 2); + DefaultArtifactVersionWrapper versionWrapper = versions + .get(versions.size() - 2); // 2.0.0 vs 2.0.0 - boolean sameVersionsWithoutClassifier = Objects.equals(withoutClassifier(versionWrapper), withoutClassifier(latestFoundVersion)); + boolean sameVersionsWithoutClassifier = Objects.equals( + withoutClassifier(versionWrapper), + withoutClassifier(latestFoundVersion)); // replace the RELEASE one with SNAPSHOT - latestFoundVersion = sameVersionsWithoutClassifier && versionWrapper.isSnapshot() ? versionWrapper : latestFoundVersion; + latestFoundVersion = sameVersionsWithoutClassifier + && versionWrapper.isSnapshot() ? versionWrapper : latestFoundVersion; } return latestFoundVersion; } @@ -377,25 +393,24 @@ class FileWalker extends SimpleFileVisitor { .findFirst().orElse(null); } return Arrays.stream(files) - .filter(file -> RELEASE.equals(file.getName().toLowerCase())) - .findFirst().orElse(null); + .filter(file -> RELEASE.equals(file.getName().toLowerCase())).findFirst() + .orElse(null); } private List pickLatestVersion(File[] files) { - return Arrays.stream(files) - .map(DefaultArtifactVersionWrapper::new) - .filter(wrapper -> this.latestSnapshotVersion || wrapper - .isNotSnapshot()) - .sorted() - .collect(Collectors.toList()); + return Arrays.stream(files).map(DefaultArtifactVersionWrapper::new) + .filter(wrapper -> this.latestSnapshotVersion || wrapper.isNotSnapshot()) + .sorted().collect(Collectors.toList()); } } class DefaultArtifactVersionWrapper implements Comparable { + private static final String SNAPSHOT_SUBSTRING = "snapshot"; - + final DefaultArtifactVersion version; + final File file; DefaultArtifactVersionWrapper(File file) { @@ -415,4 +430,5 @@ class DefaultArtifactVersionWrapper implements Comparable downloadAndUnpackStubJar( StubConfiguration stubConfiguration); -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubDownloaderBuilder.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubDownloaderBuilder.java index 112aa9e9bd..e1405deac7 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubDownloaderBuilder.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubDownloaderBuilder.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2016 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -36,6 +36,7 @@ import org.springframework.core.io.ResourceLoader; public interface StubDownloaderBuilder extends ProtocolResolver { /** + * @param stubRunnerOptions options of Stub Runner * @return {@link StubDownloader} instance of {@code null} if current parameters don't * allow building the instance */ @@ -46,4 +47,4 @@ public interface StubDownloaderBuilder extends ProtocolResolver { return null; } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubDownloaderBuilderProvider.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubDownloaderBuilderProvider.java index b8b731b740..5fd2ad332c 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubDownloaderBuilderProvider.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubDownloaderBuilderProvider.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 java.util.ArrayList; @@ -27,7 +43,7 @@ public class StubDownloaderBuilderProvider { } /** - * @param stubRunnerOptions + * @param stubRunnerOptions options of Stub Runner * @param additionalBuilders - optional array of {@link StubDownloaderBuilder}s to * append to the list of builders * @return composite {@link StubDownloader} that iterates over a list of stub diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubFinder.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubFinder.java index fe4b0c45cf..cc762ce51e 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubFinder.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubFinder.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -22,6 +22,11 @@ import java.util.Map; import org.springframework.cloud.contract.spec.Contract; +/** + * Contract for finding registered stubs. + * + * @author Marcin Grzejszczak + */ public interface StubFinder extends StubTrigger { /** @@ -29,7 +34,9 @@ public interface StubFinder extends StubTrigger { * stub. * @param groupId - might be null. In that case a search only via artifactId takes * place + * @param artifactId - artifact id of the stub * @return URL of a running stub or throws exception if not found + * @throws StubNotFoundException in case of not finding a stub */ URL findStubUrl(String groupId, String artifactId) throws StubNotFoundException; @@ -39,17 +46,18 @@ public interface StubFinder extends StubTrigger { * {@code artifactId}. * @param ivyNotation - Ivy representation of the Maven artifact * @return URL of a running stub or throws exception if not found + * @throws StubNotFoundException in case of not finding a stub */ URL findStubUrl(String ivyNotation) throws StubNotFoundException; /** - * Returns all running stubs + * @return all running stubs */ RunningStubs findAllRunningStubs(); /** - * Returns the list of Contracts + * @return the list of Contracts */ Map> getContracts(); -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubNotFoundException.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubNotFoundException.java index 6a4f1e68ba..5fb07862dc 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubNotFoundException.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubNotFoundException.java @@ -1,7 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; /** - * Exception thrown when a stub was not found + * Exception thrown when a stub was not found. * * @author Marcin Grzejszczak * @since 1.0.1 diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRepository.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRepository.java index ac177a6689..7b31f7d675 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRepository.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRepository.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -31,6 +31,7 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.cloud.contract.spec.Contract; import org.springframework.cloud.contract.spec.ContractConverter; import org.springframework.cloud.contract.stubrunner.provider.wiremock.WireMockHttpServerStub; @@ -44,12 +45,12 @@ class StubRepository { private static final Log log = LogFactory.getLog(StubRepository.class); - private final File path; - final List stubs; final Collection contracts; + private final File path; + private final List contractConverters; private final List httpServerStubs; @@ -95,14 +96,14 @@ class StubRepository { } /** - * Returns a list of contracts + * @return a list of contracts */ private Collection contracts() { return new ArrayList<>(contractDescriptors()); } /** - * Returns the list of stubs + * @return the list of stubs */ private List stubs() { return new ArrayList<>(collectedStubs()); @@ -156,12 +157,12 @@ class StubRepository { } private Collection contractDescriptors() { - return (this.path.exists() ? - ContractScanner.collectContractDescriptors(this.path, this::isStubPerConsumerPathMatching) + return (this.path.exists() + ? ContractScanner.collectContractDescriptors(this.path, + this::isStubPerConsumerPathMatching) : Collections.emptySet()); } - private boolean isStubPerConsumerPathMatching(File file) { if (!this.options.isStubsPerConsumer()) { return true; diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunner.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunner.java index 672eb9d91e..94a93954c9 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunner.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunner.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -28,6 +28,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.cloud.contract.spec.Contract; import org.springframework.cloud.contract.verifier.messaging.MessageVerifier; import org.springframework.cloud.contract.verifier.messaging.noop.NoOpStubMessages; @@ -38,6 +39,8 @@ import org.springframework.util.StringUtils; * Represents a single instance of ready-to-run stubs. Can run the stubs and then will * return the name of the collaborator together with its URI. Can also be queried if the * current groupid and artifactid are matching the corresponding running stub. + * + * @author Marcin Grzejszczak */ public class StubRunner implements StubRunning { @@ -191,4 +194,4 @@ public class StubRunner implements StubRunning { } } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerExecutor.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerExecutor.java index 4066bd4a40..0bd999757d 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerExecutor.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerExecutor.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -43,22 +43,22 @@ import org.springframework.cloud.contract.verifier.messaging.noop.NoOpStubMessag import org.springframework.cloud.contract.verifier.util.BodyExtractor; /** - * Runs stubs for a particular {@link StubServer} + * Runs stubs for a particular {@link StubServer}. */ class StubRunnerExecutor implements StubFinder { - private static final Log log = LogFactory.getLog(StubRunnerExecutor.class); - static final Set STUB_SERVERS = new ConcurrentHashSet<>(); + private static final Log log = LogFactory.getLog(StubRunnerExecutor.class); + private final AvailablePortScanner portScanner; private final MessageVerifier contractVerifierMessaging; - private StubServer stubServer; - private final List serverStubs; + private StubServer stubServer; + StubRunnerExecutor(AvailablePortScanner portScanner, MessageVerifier contractVerifierMessaging, List serverStubs) { @@ -88,7 +88,8 @@ class StubRunnerExecutor implements StubFinder { try { HttpServerStubConfigurer configurer = stubRunnerOptions .getHttpServerStubConfigurer().newInstance(); - startStubServers(configurer, stubRunnerOptions, stubConfiguration, repository); + startStubServers(configurer, stubRunnerOptions, stubConfiguration, + repository); } catch (InstantiationException | IllegalAccessException ex) { log.error("Failed to instantiate the HTTP stub configurer", ex); @@ -272,8 +273,7 @@ class StubRunnerExecutor implements StubFinder { final Collection contracts = repository.contracts; Integer port = stubRunnerOptions.port(stubConfiguration); HttpServerStubConfiguration configuration = new HttpServerStubConfiguration( - configurer, stubRunnerOptions, stubConfiguration, port - ); + configurer, stubRunnerOptions, stubConfiguration, port); if (!hasRequest(contracts) && mappings.isEmpty()) { if (log.isDebugEnabled()) { log.debug("There are no HTTP related contracts. Won't start any servers"); @@ -293,9 +293,9 @@ class StubRunnerExecutor implements StubFinder { public StubServer call(int availablePort) { return new StubServer(stubConfiguration, mappings, contracts, httpServerStub()).start( - new HttpServerStubConfiguration( - configurer, stubRunnerOptions, stubConfiguration, availablePort - )); + new HttpServerStubConfiguration(configurer, + stubRunnerOptions, stubConfiguration, + availablePort)); } }); } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerFactory.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerFactory.java index 21349b8307..af7382e2f8 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerFactory.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerFactory.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -24,6 +24,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.cloud.contract.verifier.messaging.MessageVerifier; /** @@ -41,8 +42,8 @@ class StubRunnerFactory { private final MessageVerifier contractVerifierMessaging; - public StubRunnerFactory(StubRunnerOptions stubRunnerOptions, - StubDownloader stubDownloader, MessageVerifier contractVerifierMessaging) { + StubRunnerFactory(StubRunnerOptions stubRunnerOptions, StubDownloader stubDownloader, + MessageVerifier contractVerifierMessaging) { this.stubRunnerOptions = stubRunnerOptions; this.stubDownloader = stubDownloader; this.contractVerifierMessaging = contractVerifierMessaging; diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerMain.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerMain.java index bdf0f3deaa..fb78d6cd58 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerMain.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerMain.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -24,11 +24,13 @@ import joptsimple.OptionParser; import joptsimple.OptionSet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties; /** - * Class to run stub runner as a standalone process + * Class to run stub runner as a standalone process. * + * @author Marcin Grzejszczak * @deprecated - use Stub Runner Boot server */ @Deprecated @@ -51,15 +53,18 @@ public class StubRunnerMain { .withRequiredArg().ofType(Integer.class).defaultsTo(15000); ArgumentAcceptingOptionSpec stubsOpt = parser.acceptsAll( Arrays.asList("s", "stubs"), - "Comma separated list of Ivy representation of jars with stubs. Eg. groupid:artifactid1,groupid2:artifactid2:classifier") + "Comma separated list of Ivy representation " + + "of jars with stubs. Eg. groupid:artifactid1,groupid2:artifactid2:classifier") .withRequiredArg(); ArgumentAcceptingOptionSpec classifierOpt = parser.acceptsAll( Arrays.asList("c", "classifier"), - "Suffix for the jar containing stubs (e.g. 'stubs' if the stub jar would have a 'stubs' classifier for stubs: foobar-stubs ). Defaults to 'stubs'") + "Suffix for the jar containing stubs (e.g. 'stubs' " + + "if the stub jar would have a 'stubs' classifier for stubs: foobar-stubs ). Defaults to 'stubs'") .withRequiredArg().defaultsTo("stubs"); ArgumentAcceptingOptionSpec rootOpt = parser.acceptsAll( Arrays.asList("r", "root"), - "Location of a Jar containing server where you keep your stubs (e.g. http://nexus.net/content/repositories/repository)") + "Location of a Jar containing server where you keep " + + "your stubs (e.g. http://nexus.net/content/repositories/repository)") .withRequiredArg(); ArgumentAcceptingOptionSpec usernameOpt = parser .acceptsAll(Arrays.asList("u", "username"), @@ -112,6 +117,10 @@ public class StubRunnerMain { } } + public static void main(String[] args) throws Exception { + new StubRunnerMain(args).execute(); + } + private void printErrorMessage(Exception e, OptionParser parser) throws IOException { System.err.println(e.getMessage()); System.err.println("java -jar stub-runner.jar [options...] "); @@ -121,10 +130,6 @@ public class StubRunnerMain { "Example: java -jar stub-runner.jar ${parser.printExample(ALL)}"); } - public static void main(String[] args) throws Exception { - new StubRunnerMain(args).execute(); - } - private void execute() { try { if (log.isDebugEnabled()) { @@ -142,4 +147,4 @@ public class StubRunnerMain { } } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerOptions.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerOptions.java index fe333230d0..3957d90612 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerOptions.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerOptions.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -34,8 +34,9 @@ import org.springframework.util.StringUtils; /** * Technical options related to running StubRunner * - * Use {@see StubRunnerOptionsBuilder} to build this object. + * Use {@link StubRunnerOptionsBuilder} to build this object. * + * @author Marcin Grzejszczak * @see StubRunnerOptionsBuilder */ public class StubRunnerOptions { @@ -43,54 +44,62 @@ public class StubRunnerOptions { private static final Log log = LogFactory.getLog(StubRunnerOptions.class); /** - * min port value of the WireMock instance for the given collaborator + * min port value of the WireMock instance for the given collaborator. */ final Integer minPortValue; /** - * max port value of the WireMock instance for the given collaborator + * max port value of the WireMock instance for the given collaborator. */ final Integer maxPortValue; /** - * root URL from where the JAR with stub mappings will be downloaded + * root URL from where the JAR with stub mappings will be downloaded. */ final Resource stubRepositoryRoot; /** - * stub definition classifier + * stub definition classifier. */ final String stubsClassifier; final Collection dependencies; /** - * colon separated list of ids to the desired port + * colon separated list of ids to the desired port. */ final Map stubIdsToPortMapping; /** - * Optional username for authorization header + * Optional username for authorization header. */ final String username; /** - * Optional password for authorization header + * Optional password for authorization header. */ final String password; + final StubRunnerProperties.StubsMode stubsMode; + /** - * Optional proxy settings + * Optional proxy settings. */ private final StubRunnerProxyOptions stubRunnerProxyOptions; /** - * Should only stubs applicable for the given consumer get registered + * Configuration for an HTTP server stub class that allows to perform additional HTTP + * server stub configuration. + */ + private final Class httpServerStubConfigurer; + + /** + * Should only stubs applicable for the given consumer get registered. */ private boolean stubsPerConsumer = false; /** - * Name of the consumer. If not set should default to {@code spring.application.name} + * Name of the consumer. If not set should default to {@code spring.application.name}. */ private String consumerName; @@ -101,25 +110,17 @@ public class StubRunnerOptions { */ private String mappingsOutputFolder; - final StubRunnerProperties.StubsMode stubsMode; - /** * If set to {@code false} will NOT delete stubs from a temporary folder after running - * tests + * tests. */ private boolean deleteStubsAfterTest; /** * Map of properties that can be passed to custom - * {@link org.springframework.cloud.contract.stubrunner.StubDownloaderBuilder} + * {@link org.springframework.cloud.contract.stubrunner.StubDownloaderBuilder}. */ - private Map properties = new HashMap<>(); - - /** - * Configuration for an HTTP server stub - * @return class that allows to perform additional HTTP server stub configuration - */ - private final Class httpServerStubConfigurer; + private Map properties; StubRunnerOptions(Integer minPortValue, Integer maxPortValue, Resource stubRepositoryRoot, StubRunnerProperties.StubsMode stubsMode, @@ -148,15 +149,6 @@ public class StubRunnerOptions { this.httpServerStubConfigurer = httpServerStubConfigurer; } - public Integer port(StubConfiguration stubConfiguration) { - if (this.stubIdsToPortMapping != null) { - return this.stubIdsToPortMapping.get(stubConfiguration); - } - else { - return null; - } - } - public static StubRunnerOptions fromSystemProps() { StubRunnerOptionsBuilder builder = new StubRunnerOptionsBuilder() .withMinPort(Integer.valueOf( @@ -199,6 +191,15 @@ public class StubRunnerOptions { return map; } + public Integer port(StubConfiguration stubConfiguration) { + if (this.stubIdsToPortMapping != null) { + return this.stubIdsToPortMapping.get(stubConfiguration); + } + else { + return null; + } + } + public Integer getMinPortValue() { return this.minPortValue; } @@ -311,6 +312,28 @@ public class StubRunnerOptions { return this.httpServerStubConfigurer; } + @Override + public String toString() { + return "StubRunnerOptions{" + "minPortValue=" + this.minPortValue + + ", maxPortValue=" + this.maxPortValue + ", stubRepositoryRoot='" + + this.stubRepositoryRoot + '\'' + ", stubsMode='" + this.stubsMode + + "', stubsClassifier='" + this.stubsClassifier + '\'' + ", dependencies=" + + this.dependencies + ", stubIdsToPortMapping=" + + this.stubIdsToPortMapping + ", username='" + obfuscate(this.username) + + '\'' + ", password='" + obfuscate(this.password) + '\'' + + ", stubRunnerProxyOptions='" + this.stubRunnerProxyOptions + + "', stubsPerConsumer='" + this.stubsPerConsumer + '\'' + + ", httpServerStubConfigurer='" + this.httpServerStubConfigurer + '\'' + + '}'; + } + + private String obfuscate(String string) { + return StringUtils.hasText(string) ? "****" : ""; + } + + /** + * Options for a proxy. + */ public static class StubRunnerProxyOptions { private final String proxyHost; @@ -335,24 +358,7 @@ public class StubRunnerOptions { return "StubRunnerProxyOptions{" + "proxyHost='" + this.proxyHost + '\'' + ", proxyPort=" + this.proxyPort + '}'; } - } - @Override - public String toString() { - return "StubRunnerOptions{" + "minPortValue=" + this.minPortValue - + ", maxPortValue=" + this.maxPortValue + ", stubRepositoryRoot='" - + this.stubRepositoryRoot + '\'' + ", stubsMode='" + this.stubsMode - + "', stubsClassifier='" + this.stubsClassifier + '\'' + ", dependencies=" - + this.dependencies + ", stubIdsToPortMapping=" - + this.stubIdsToPortMapping + ", username='" + obfuscate(this.username) - + '\'' + ", password='" + obfuscate(this.password) + '\'' - + ", stubRunnerProxyOptions='" + this.stubRunnerProxyOptions - + "', stubsPerConsumer='" + this.stubsPerConsumer + '\'' - + ", httpServerStubConfigurer='" + this.httpServerStubConfigurer+ '\'' + '}'; - } - - private String obfuscate(String string) { - return StringUtils.hasText(string) ? "****" : ""; } } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilder.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilder.java index dce659b230..b6997e504b 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilder.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilder.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -30,6 +30,11 @@ import org.springframework.cloud.contract.stubrunner.util.StubsParser; import org.springframework.core.io.Resource; import org.springframework.util.StringUtils; +/** + * A builder object for {@link StubRunnerOptions}. + * + * @author Marcin Grzejszczak + */ public class StubRunnerOptionsBuilder { private static final String DELIMITER = ":"; @@ -66,9 +71,7 @@ public class StubRunnerOptionsBuilder { private Map properties = new HashMap<>(); - private Class httpServerStubConfigurer = - HttpServerStubConfigurer.NoOpHttpServerStubConfigurer.class; - + private Class httpServerStubConfigurer = HttpServerStubConfigurer.NoOpHttpServerStubConfigurer.class; public StubRunnerOptionsBuilder() { } @@ -77,6 +80,40 @@ public class StubRunnerOptionsBuilder { withOptions(options); } + private static List stubsToList(String[] stubIdsToPortMapping) { + List list = new ArrayList<>(); + if (stubIdsToPortMapping.length == 1 && !containsRange(stubIdsToPortMapping[0])) { + list.addAll(StringUtils.commaDelimitedListToSet(stubIdsToPortMapping[0])); + return list; + } + else if (stubIdsToPortMapping.length == 1 + && containsRange(stubIdsToPortMapping[0])) { + LinkedList linkedList = new LinkedList<>(); + String[] split = stubIdsToPortMapping[0].split(","); + for (String string : split) { + if (containsClosingRange(string)) { + String last = linkedList.pop(); + linkedList.push(last + "," + string); + } + else { + linkedList.push(string); + } + } + list.addAll(linkedList); + return list; + } + Collections.addAll(list, stubIdsToPortMapping); + return list; + } + + private static boolean containsRange(String s) { + return s.contains("[") || s.contains("("); + } + + private static boolean containsClosingRange(String s) { + return s.contains("]") || s.contains(")"); + } + public StubRunnerOptionsBuilder withStubs(String... stubs) { addStub(stubsToList(stubs)); return this; @@ -178,7 +215,8 @@ public class StubRunnerOptionsBuilder { return this; } - public StubRunnerOptionsBuilder withHttpServerStubConfigurer(Class httpServerStubConfigurer) { + public StubRunnerOptionsBuilder withHttpServerStubConfigurer( + Class httpServerStubConfigurer) { this.httpServerStubConfigurer = httpServerStubConfigurer; return this; } @@ -199,40 +237,6 @@ public class StubRunnerOptionsBuilder { return this.stubConfigurations; } - private static List stubsToList(String[] stubIdsToPortMapping) { - List list = new ArrayList<>(); - if (stubIdsToPortMapping.length == 1 && !containsRange(stubIdsToPortMapping[0])) { - list.addAll(StringUtils.commaDelimitedListToSet(stubIdsToPortMapping[0])); - return list; - } - else if (stubIdsToPortMapping.length == 1 - && containsRange(stubIdsToPortMapping[0])) { - LinkedList linkedList = new LinkedList<>(); - String[] split = stubIdsToPortMapping[0].split(","); - for (String string : split) { - if (containsClosingRange(string)) { - String last = linkedList.pop(); - linkedList.push(last + "," + string); - } - else { - linkedList.push(string); - } - } - list.addAll(linkedList); - return list; - } - Collections.addAll(list, stubIdsToPortMapping); - return list; - } - - private static boolean containsRange(String s) { - return s.contains("[") || s.contains("("); - } - - private static boolean containsClosingRange(String s) { - return s.contains("]") || s.contains(")"); - } - private void addStub(List notations) { for (String notation : notations) { addStub(notation); diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerPropertyUtils.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerPropertyUtils.java index 02b99c5321..11587ee974 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerPropertyUtils.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerPropertyUtils.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,29 +21,31 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.util.StringUtils; /** - * Reads property from system prop and from env var + * Reads property from system prop and from env var. * * @author Marcin Grzejszczak * @since 2.0.0 */ public final class StubRunnerPropertyUtils { - private StubRunnerPropertyUtils() { - throw new IllegalStateException("Can't instantiate a utility class"); - } - private static final Log log = LogFactory.getLog(StubRunnerPropertyUtils.class); private static final String STUBRUNNER_PROPERTIES = "stubrunner.properties"; static PropertyFetcher FETCHER = new PropertyFetcher(); + private StubRunnerPropertyUtils() { + throw new IllegalStateException("Can't instantiate a utility class"); + } + /** - * For Env vars takes the prop name, converts dots to underscores and applies upper - * case + * @param propName property name + * @return for Env vars takes the prop name, converts dots to underscores and applies + * upper case */ public static boolean isPropertySet(String propName) { String value = getProperty(new HashMap<>(), propName); @@ -51,7 +53,10 @@ public final class StubRunnerPropertyUtils { } /** - * For options, system props and env vars returns {@code true} when property is set + * @param options map of options + * @param propName property name + * @return For options, system props and env vars returns {@code true} when property + * is set */ public static boolean hasProperty(Map options, String propName) { String value = getProperty(options, propName); @@ -59,8 +64,10 @@ public final class StubRunnerPropertyUtils { } /** - * Tries to pick a value from options, for Env vars takes the prop name, converts dots - * to underscores and applies upper case + * @param options map of options + * @param propName property name + * @return Tries to pick a value from options, for Env vars takes the prop name, + * converts dots to underscores and applies upper case */ public static String getProperty(Map options, String propName) { if (options != null && options.containsKey(propName)) { diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunning.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunning.java index 8e3a5d32c7..a44899a407 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunning.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunning.java @@ -1,29 +1,34 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 java.io.Closeable; +/** + * Contract for running stubs. + * + * @author Marcin Grzejszczak + */ public interface StubRunning extends Closeable, StubFinder { /** - * Runs the stubs and returns the {@link RunningStubs}. If the stubs were already - * started then a cached version will be returned. + * @return runs the stubs and returns the {@link RunningStubs}. If the stubs were + * already started then a cached version will be returned. */ RunningStubs runStubs(); -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubServer.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubServer.java index d252488dcb..70c1b137a4 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubServer.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubServer.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -24,20 +24,21 @@ import java.util.Objects; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.cloud.contract.spec.Contract; class StubServer { private static final Log log = LogFactory.getLog(StubServer.class); - private final HttpServerStub httpServerStub; - final StubConfiguration stubConfiguration; final Collection mappings; final Collection contracts; + private final HttpServerStub httpServerStub; + StubServer(StubConfiguration stubConfiguration, Collection mappings, Collection contracts, HttpServerStub httpServerStub) { this.stubConfiguration = stubConfiguration; @@ -75,7 +76,8 @@ class StubServer { int httpsPort = this.httpServerStub.httpsPort(); int httpPort = this.httpServerStub.port(); if (log.isDebugEnabled()) { - log.debug("Ports for this server are https [" + httpsPort + "] and http [" + httpPort + "]"); + log.debug("Ports for this server are https [" + httpsPort + "] and http [" + + httpPort + "]"); } return httpsPort != -1 ? httpsPort : httpPort; } @@ -93,7 +95,8 @@ class StubServer { public URL getStubUrl() { try { - return new URL((hasHttps() ? "https:" : "http:") + "//localhost:" + getPort()); + return new URL( + (hasHttps() ? "https:" : "http:") + "//localhost:" + getPort()); } catch (MalformedURLException e) { throw new IllegalStateException("Cannot parse URL", e); @@ -118,10 +121,12 @@ class StubServer { @Override public boolean equals(Object o) { - if (this == o) + if (this == o) { return true; - if (o == null || getClass() != o.getClass()) + } + if (o == null || getClass() != o.getClass()) { return false; + } StubServer that = (StubServer) o; return Objects.equals(this.stubConfiguration, that.stubConfiguration) && Objects.equals(this.contracts, that.contracts); diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubTrigger.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubTrigger.java index 7031d725d7..8713b7ea2f 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubTrigger.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubTrigger.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -19,6 +19,11 @@ package org.springframework.cloud.contract.stubrunner; import java.util.Collection; import java.util.Map; +/** + * Contract for triggering stub messages. + * + * @author Marcin Grzejszczak + */ public interface StubTrigger { /** @@ -26,6 +31,8 @@ public interface StubTrigger { * You can use only {@code artifactId} too. * * Feature related to messaging. + * @param ivyNotation ivy notation of a stub + * @param labelName name of the label to trigger * @return true - if managed to run a trigger */ boolean trigger(String ivyNotation, String labelName); @@ -34,6 +41,7 @@ public interface StubTrigger { * Triggers an event by a given label. * * Feature related to messaging. + * @param labelName name of the label to trigger * @return true - if managed to run a trigger */ boolean trigger(String labelName); @@ -47,10 +55,9 @@ public interface StubTrigger { boolean trigger(); /** - * Returns a mapping of ivy notation of a dependency to all the labels it has. - * * Feature related to messaging. + * @return a mapping of ivy notation of a dependency to all the labels it has. */ Map> labels(); -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/TemporaryFileStorage.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/TemporaryFileStorage.java index 153e7654be..3b7eb642e9 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/TemporaryFileStorage.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/TemporaryFileStorage.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -32,12 +32,12 @@ import org.apache.commons.logging.LogFactory; import static java.nio.file.Files.createTempDirectory; /** - * Stores all generated temporary folders with stubs + * Stores all generated temporary folders with stubs. * * @author Marcin Grzejszczak * @since 2.0.0 */ -class TemporaryFileStorage { +final class TemporaryFileStorage { private static final Log log = LogFactory.getLog(TemporaryFileStorage.class); @@ -48,6 +48,10 @@ class TemporaryFileStorage { */ private static final Queue TEMP_FILES_LOG = new LinkedBlockingQueue<>(1000); + private TemporaryFileStorage() { + throw new IllegalStateException("Can't instantiate a utility class"); + } + static void add(File file) { TEMP_FILES_LOG.add(file); } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/ExceptionThrowingMessageVerifier.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/ExceptionThrowingMessageVerifier.java index 3724f595b1..f14f96bb0f 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/ExceptionThrowingMessageVerifier.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/ExceptionThrowingMessageVerifier.java @@ -1,52 +1,52 @@ /* - * Copyright 2018 the original author or authors. + * Copyright 2018-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.springframework.cloud.contract.verifier.messaging.MessageVerifier; - import java.util.Map; import java.util.concurrent.TimeUnit; +import org.springframework.cloud.contract.verifier.messaging.MessageVerifier; + /** * @author Olga Maciaszek-Sharma * @since 2.1.0 */ class ExceptionThrowingMessageVerifier implements MessageVerifier { - private static final String EXCEPTION_MESSAGE = "Please provide a custom MessageVerifier to use this feature"; + private static final String EXCEPTION_MESSAGE = "Please provide a custom MessageVerifier to use this feature"; - @Override - public void send(Object message, String destination) { - throw new UnsupportedOperationException(EXCEPTION_MESSAGE); - } + @Override + public void send(Object message, String destination) { + throw new UnsupportedOperationException(EXCEPTION_MESSAGE); + } - @Override - public Object receive(String destination, long timeout, TimeUnit timeUnit) { - throw new UnsupportedOperationException(EXCEPTION_MESSAGE); - } + @Override + public Object receive(String destination, long timeout, TimeUnit timeUnit) { + throw new UnsupportedOperationException(EXCEPTION_MESSAGE); + } - @Override - public Object receive(String destination) { - throw new UnsupportedOperationException(EXCEPTION_MESSAGE); - } + @Override + public Object receive(String destination) { + throw new UnsupportedOperationException(EXCEPTION_MESSAGE); + } - @Override - public void send(Object payload, Map headers, String destination) { - throw new UnsupportedOperationException(EXCEPTION_MESSAGE); - } + @Override + public void send(Object payload, Map headers, String destination) { + throw new UnsupportedOperationException(EXCEPTION_MESSAGE); + } } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/PortStubRunnerExtensionOptions.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/PortStubRunnerExtensionOptions.java index aece0f3369..58dc62a154 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/PortStubRunnerExtensionOptions.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/PortStubRunnerExtensionOptions.java @@ -1,17 +1,17 @@ /* - * Copyright 2018 the original author or authors. + * Copyright 2018-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -22,5 +22,6 @@ package org.springframework.cloud.contract.stubrunner.junit; */ interface PortStubRunnerExtensionOptions { - StubRunnerExtension withPort(Integer port); + StubRunnerExtension withPort(Integer port); + } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/PortStubRunnerRuleOptions.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/PortStubRunnerRuleOptions.java index a8985f57b8..2c8d007726 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/PortStubRunnerRuleOptions.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/PortStubRunnerRuleOptions.java @@ -1,9 +1,27 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; interface PortStubRunnerRuleOptions extends StubRunnerRuleOptions { /** - * Appends port to last added stub + * Appends port to last added stub. + * @param port port at which the stub will be ran + * @return this */ StubRunnerRule withPort(Integer port); diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerExtension.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerExtension.java index a8f9ad9478..44abc88a84 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerExtension.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerExtension.java @@ -1,17 +1,17 @@ /* - * Copyright 2018 the original author or authors. + * Copyright 2018-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -48,16 +48,22 @@ import org.springframework.cloud.contract.verifier.messaging.MessageVerifier; * @author Olga Maciaszek-Sharma * @since 2.1.0 */ -public class StubRunnerExtension implements BeforeAllCallback, AfterAllCallback, StubFinder, StubRunnerExtensionOptions { +public class StubRunnerExtension implements BeforeAllCallback, AfterAllCallback, + StubFinder, StubRunnerExtensionOptions { private static final String DELIMITER = ":"; + private static final String LATEST_VERSION = "+"; + private static final Log LOG = LogFactory.getLog(StubRunnerExtension.class); StubRunnerExtension delegate = this; + private BatchStubRunner stubFinder; + private StubRunnerOptionsBuilder stubRunnerOptionsBuilder = new StubRunnerOptionsBuilder( StubRunnerOptions.fromSystemProps()); + private MessageVerifier verifier = new ExceptionThrowingMessageVerifier(); public StubRunnerExtension() { @@ -85,7 +91,8 @@ public class StubRunnerExtension implements BeforeAllCallback, AfterAllCallback, } @Override - public URL findStubUrl(String groupId, String artifactId) throws StubNotFoundException { + public URL findStubUrl(String groupId, String artifactId) + throws StubNotFoundException { return stubFinder().findStubUrl(groupId, artifactId); } @@ -175,21 +182,24 @@ public class StubRunnerExtension implements BeforeAllCallback, AfterAllCallback, } @Override - public PortStubRunnerExtension downloadStub(String groupId, String artifactId, String version, String classifier) { + public PortStubRunnerExtension downloadStub(String groupId, String artifactId, + String version, String classifier) { builder().withStubs(groupId + DELIMITER + artifactId + DELIMITER + version + DELIMITER + classifier); return new PortStubRunnerExtension(this.delegate); } @Override - public PortStubRunnerExtension downloadLatestStub(String groupId, String artifactId, String classifier) { + public PortStubRunnerExtension downloadLatestStub(String groupId, String artifactId, + String classifier) { builder().withStubs(groupId + DELIMITER + artifactId + DELIMITER + LATEST_VERSION + DELIMITER + classifier); return new PortStubRunnerExtension(this.delegate); } @Override - public PortStubRunnerExtension downloadStub(String groupId, String artifactId, String version) { + public PortStubRunnerExtension downloadStub(String groupId, String artifactId, + String version) { builder().withStubs(groupId + DELIMITER + artifactId + DELIMITER + version); return new PortStubRunnerExtension(this.delegate); } @@ -249,7 +259,8 @@ public class StubRunnerExtension implements BeforeAllCallback, AfterAllCallback, } @Override - public StubRunnerExtension withHttpServerStubConfigurer(Class httpServerStubConfigurer) { + public StubRunnerExtension withHttpServerStubConfigurer( + Class httpServerStubConfigurer) { builder().withHttpServerStubConfigurer(httpServerStubConfigurer); return new PortStubRunnerExtension(this.delegate); } @@ -275,11 +286,13 @@ public class StubRunnerExtension implements BeforeAllCallback, AfterAllCallback, } /** - * Helper class with additional port, related methods once you pick a stub to download + * Helper class with additional port, related methods once you pick a stub to + * download. * * @since 1.2.0 */ - public static class PortStubRunnerExtension extends StubRunnerExtension implements PortStubRunnerExtensionOptions { + public static class PortStubRunnerExtension extends StubRunnerExtension + implements PortStubRunnerExtensionOptions { PortStubRunnerExtension(StubRunnerExtension delegate) { super(delegate); @@ -290,5 +303,7 @@ public class StubRunnerExtension implements BeforeAllCallback, AfterAllCallback, builder().withPort(port); return this.delegate; } + } + } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerExtensionOptions.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerExtensionOptions.java index 6d35a46682..adbc04d41a 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerExtensionOptions.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerExtensionOptions.java @@ -1,17 +1,17 @@ /* - * Copyright 2018 the original author or authors. + * Copyright 2018-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -32,109 +32,135 @@ interface StubRunnerExtensionOptions { /** * Pass the {@link MessageVerifier} that this rule should use. If you don't pass - * anything a {@link ExceptionThrowingMessageVerifier} will be used. - * That means that an exception will be thrown whenever you try to do sth messaging - * related. + * anything a {@link ExceptionThrowingMessageVerifier} will be used. That means that + * an exception will be thrown whenever you try to do sth messaging related. + * @param messageVerifier message verifier implementation + * @return the stub runner extension */ StubRunnerExtension messageVerifier(MessageVerifier messageVerifier); /** - * Override all options - * + * Override all options. + * @param stubRunnerOptions options of Stub Runner + * @return the stub runner extension * @see StubRunnerOptions */ StubRunnerExtension options(StubRunnerOptions stubRunnerOptions); /** - * Min value of port for WireMock server + * @param minPort min value of port for WireMock server + * @return the stub runner extension */ StubRunnerExtension minPort(int minPort); /** - * Max value of port for WireMock server + * @param maxPort max value of port for WireMock server + * @return the stub runner extension */ StubRunnerExtension maxPort(int maxPort); /** - * String URI of repository containing stubs + * @param repoRoot String URI of repository containing stubs + * @return the stub runner extension */ StubRunnerExtension repoRoot(String repoRoot); /** - * Stubs mode that should be used + * @param stubsMode Stubs mode that should be used + * @return the stub runner extension */ StubRunnerExtension stubsMode(StubRunnerProperties.StubsMode stubsMode); /** - * Group Id, artifact Id, version and classifier of a single stub to download + * @param groupId group id of the stub + * @param artifactId artifact id of the stub + * @param version version of the stub + * @param classifier classifier of the stub + * @return the stub runner extension with ports */ PortStubRunnerExtensionOptions downloadStub(String groupId, String artifactId, String version, String classifier); /** - * Group Id, artifact Id and classifier of a single stub to download in the latest - * version + * @param groupId group id of the stub + * @param artifactId artifact id of the stub + * @param classifier classifier of the stub + * @return the stub runner extension with ports */ PortStubRunnerExtensionOptions downloadLatestStub(String groupId, String artifactId, String classifier); /** - * Group Id, artifact Id and version of a single stub to download + * @param groupId group id of the stub + * @param artifactId artifact id of the stub + * @param version version of the stub + * @return the stub runner extension with ports */ PortStubRunnerExtensionOptions downloadStub(String groupId, String artifactId, String version); /** - * Group Id, artifact Id of a single stub to download. Default classifier will be - * picked. + * @param groupId group id of the stub + * @param artifactId artifact id of the stub + * @return the stub runner extension with ports */ PortStubRunnerExtensionOptions downloadStub(String groupId, String artifactId); /** - * Ivy notation of a single stub to download. + * @param ivyNotation Ivy notation of a single stub to download. + * @return the stub runner extension with ports */ PortStubRunnerExtensionOptions downloadStub(String ivyNotation); /** - * Stubs to download in Ivy notations + * @param ivyNotations Stubs to download in Ivy notations. + * @return the stub runner extension */ StubRunnerExtension downloadStubs(String... ivyNotations); /** - * Stubs to download in Ivy notations + * @param ivyNotations Stubs to download in Ivy notations. + * @return the stub runner extension */ StubRunnerExtension downloadStubs(List ivyNotations); /** - * Allows stub per consumer + * @param stubPerConsumer Allows stub per consumer. + * @return the stub runner extension */ StubRunnerExtension withStubPerConsumer(boolean stubPerConsumer); /** - * Allows setting consumer name + * @param consumerName given consumer name + * @return the stub runner extension */ StubRunnerExtension withConsumerName(String consumerName); /** - * Allows setting the output folder for mappings + * @param mappingsOutputFolder Allows setting the output folder for mappings + * @return the stub runner extension */ StubRunnerExtension withMappingsOutputFolder(String mappingsOutputFolder); /** - * If set to {@code false} will NOT delete stubs from a temporary folder after running - * tests + * @param deleteStubsAfterTest If set to {@code false} will NOT delete stubs from a + * temporary folder after running tests + * @return the stub runner extension */ StubRunnerExtension withDeleteStubsAfterTest(boolean deleteStubsAfterTest); /** - * Map of properties that can be passed to custom + * @param properties Map of properties that can be passed to custom * {@link org.springframework.cloud.contract.stubrunner.StubDownloaderBuilder} + * @return the stub runner extension */ StubRunnerExtension withProperties(Map properties); /** - * Configuration for an HTTP server stub + * @param httpServerStubConfigurer Configuration for an HTTP server stub + * @return the stub runner extension */ - StubRunnerExtension withHttpServerStubConfigurer(Class httpServerStubConfigurer); + StubRunnerExtension withHttpServerStubConfigurer( + Class httpServerStubConfigurer); } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRule.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRule.java index 156b46ebd6..4eeeadffec 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRule.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRule.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -61,6 +61,10 @@ public class StubRunnerRule implements TestRule, StubFinder, StubRunnerRuleOptio public StubRunnerRule() { } + StubRunnerRule(StubRunnerRule delegate) { + this.delegate = delegate; + } + @Override public Statement apply(final Statement base, Description description) { return new Statement() { @@ -193,7 +197,8 @@ public class StubRunnerRule implements TestRule, StubFinder, StubRunnerRuleOptio } @Override - public StubRunnerRule withHttpServerStubConfigurer(Class httpServerStubConfigurer) { + public StubRunnerRule withHttpServerStubConfigurer( + Class httpServerStubConfigurer) { builder().withHttpServerStubConfigurer(httpServerStubConfigurer); return this.delegate; } @@ -252,10 +257,6 @@ public class StubRunnerRule implements TestRule, StubFinder, StubRunnerRuleOptio return this.stubFinder().labels(); } - StubRunnerRule(StubRunnerRule delegate) { - this.delegate = delegate; - } - BatchStubRunner stubFinder() { return this.delegate.stubFinder; } @@ -277,7 +278,8 @@ public class StubRunnerRule implements TestRule, StubFinder, StubRunnerRuleOptio } /** - * Helper class with additional port, related methods once you pick a stub to download + * Helper class with additional port, related methods once you pick a stub to + * download. * * @since 1.2.0 */ diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleOptions.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleOptions.java index 870b6f5082..26b87fbf36 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleOptions.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleOptions.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -28,109 +28,135 @@ interface StubRunnerRuleOptions { /** * Pass the {@link MessageVerifier} that this rule should use. If you don't pass - * anything a {@link ExceptionThrowingMessageVerifier} will be used. - * That means that an exception will be thrown whenever you try to do sth messaging - * related. + * anything a {@link ExceptionThrowingMessageVerifier} will be used. That means that + * an exception will be thrown whenever you try to do sth messaging related. + * @param messageVerifier message verifier implementation + * @return the rule */ StubRunnerRule messageVerifier(MessageVerifier messageVerifier); /** - * Override all options - * + * Override all options. + * @param stubRunnerOptions options of Stub Runner + * @return the rule * @see StubRunnerOptions */ StubRunnerRule options(StubRunnerOptions stubRunnerOptions); /** - * Min value of port for WireMock server + * @param minPort min value of port for WireMock server + * @return the rule */ StubRunnerRule minPort(int minPort); /** - * Max value of port for WireMock server + * @param maxPort max value of port for WireMock server + * @return the rule */ StubRunnerRule maxPort(int maxPort); /** - * String URI of repository containing stubs + * @param repoRoot String URI of repository containing stubs + * @return the rule */ StubRunnerRule repoRoot(String repoRoot); /** - * Stubs mode that should be used + * @param stubsMode Stubs mode that should be used + * @return the rule */ StubRunnerRule stubsMode(StubRunnerProperties.StubsMode stubsMode); /** - * Group Id, artifact Id, version and classifier of a single stub to download + * @param groupId group id of the stub + * @param artifactId artifact id of the stub + * @param version version of the stub + * @param classifier classifier of the stub + * @return the rule with port */ PortStubRunnerRuleOptions downloadStub(String groupId, String artifactId, - String version, String classifier); + String version, String classifier); /** - * Group Id, artifact Id and classifier of a single stub to download in the latest - * version + * @param groupId group id of the stub + * @param artifactId artifact id of the stub + * @param classifier classifier of the stub + * @return the rule with port */ PortStubRunnerRuleOptions downloadLatestStub(String groupId, String artifactId, - String classifier); + String classifier); /** - * Group Id, artifact Id and version of a single stub to download + * @param groupId group id of the stub + * @param artifactId artifact id of the stub + * @param version version of the stub + * @return the rule with port */ PortStubRunnerRuleOptions downloadStub(String groupId, String artifactId, - String version); + String version); /** - * Group Id, artifact Id of a single stub to download. Default classifier will be - * picked. + * @param groupId group id of the stub + * @param artifactId artifact id of the stub + * @return the rule with port */ PortStubRunnerRuleOptions downloadStub(String groupId, String artifactId); /** - * Ivy notation of a single stub to download. + * @param ivyNotation Ivy notation of a single stub to download. + * @return the rule with port */ PortStubRunnerRuleOptions downloadStub(String ivyNotation); /** - * Stubs to download in Ivy notations + * @param ivyNotations Stubs to download in Ivy notations. + * @return the rule */ StubRunnerRule downloadStubs(String... ivyNotations); /** - * Stubs to download in Ivy notations + * @param ivyNotations Stubs to download in Ivy notations. + * @return the rule */ StubRunnerRule downloadStubs(List ivyNotations); /** - * Allows stub per consumer + * @param stubPerConsumer Allows stub per consumer. + * @return the rule */ StubRunnerRule withStubPerConsumer(boolean stubPerConsumer); /** - * Allows setting consumer name + * @param consumerName given consumer name + * @return the rule */ StubRunnerRule withConsumerName(String consumerName); /** - * Allows setting the output folder for mappings + * @param mappingsOutputFolder Allows setting the output folder for mappings + * @return the rule */ StubRunnerRule withMappingsOutputFolder(String mappingsOutputFolder); /** - * If set to {@code false} will NOT delete stubs from a temporary folder after running - * tests + * @param deleteStubsAfterTest If set to {@code false} will NOT delete stubs from a + * temporary folder after running tests + * @return the rule */ StubRunnerRule withDeleteStubsAfterTest(boolean deleteStubsAfterTest); /** - * Map of properties that can be passed to custom + * @param properties Map of properties that can be passed to custom * {@link org.springframework.cloud.contract.stubrunner.StubDownloaderBuilder} + * @return the rule */ StubRunnerRule withProperties(Map properties); /** - * Configuration for an HTTP server stub + * @param httpServerStubConfigurer Configuration for an HTTP server stub + * @return the rule */ - StubRunnerRule withHttpServerStubConfigurer(Class httpServerStubConfigurer); + StubRunnerRule withHttpServerStubConfigurer( + Class httpServerStubConfigurer); } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/StubRunnerStreamsIntegrationAutoConfiguration.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/StubRunnerStreamsIntegrationAutoConfiguration.java index b1bd8753d4..56d57215cf 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/StubRunnerStreamsIntegrationAutoConfiguration.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/StubRunnerStreamsIntegrationAutoConfiguration.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelConfiguration.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelConfiguration.java index aa07cbc43c..3f5e3210cd 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelConfiguration.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelConfiguration.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -66,28 +66,29 @@ public class StubRunnerCamelConfiguration { if (dsl == null) { continue; } - if (dsl.getInput() != null && dsl.getInput() - .getMessageFrom() != null - && StringUtils.hasText( - dsl.getInput().getMessageFrom().getClientValue())) { + if (dsl.getInput() != null + && dsl.getInput().getMessageFrom() != null + && StringUtils.hasText(dsl.getInput().getMessageFrom() + .getClientValue())) { String from = dsl.getInput().getMessageFrom() .getClientValue(); map.add(from, dsl); } } for (Map.Entry> entries : map.entrySet()) { - from(entries.getKey()) - .filter(new StubRunnerCamelPredicate(entries.getValue())) - .process(new StubRunnerCamelProcessor()) - .dynamicRouter(header(StubRunnerCamelConfiguration.STUBRUNNER_DESTINATION_URL_HEADER_NAME)); - } + from(entries.getKey()) + .filter(new StubRunnerCamelPredicate(entries.getValue())) + .process(new StubRunnerCamelProcessor()) + .dynamicRouter(header( + StubRunnerCamelConfiguration.STUBRUNNER_DESTINATION_URL_HEADER_NAME)); } } - }; - } + } + }; + } - - @Bean DummyProcessor dummyStubRunnerProcessor() { + @Bean + DummyProcessor dummyStubRunnerProcessor() { return new DummyProcessor(); } @@ -101,6 +102,7 @@ public class StubRunnerCamelConfiguration { log.debug("Got exchange [" + exchange + "]"); } } + } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelPayload.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelPayload.java index e50e59d536..6830a55435 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelPayload.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelPayload.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.springframework.cloud.contract.spec.Contract; @@ -6,11 +22,14 @@ import org.springframework.cloud.contract.spec.Contract; * @author Marcin Grzejszczak */ class StubRunnerCamelPayload { + final Object payload; + final Contract contract; StubRunnerCamelPayload(Contract contract) { this.contract = contract; this.payload = null; } + } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelPredicate.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelPredicate.java index e9934ed4ff..0d541c12c3 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelPredicate.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelPredicate.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -47,7 +47,7 @@ import org.springframework.cloud.contract.verifier.util.MapConverter; import org.springframework.cloud.contract.verifier.util.MethodBufferingJsonVerifiable; /** - * Passes through a message that matches the one defined in the DSL + * Passes through a message that matches the one defined in the DSL. * * @author Marcin Grzejszczak */ @@ -56,9 +56,10 @@ class StubRunnerCamelPredicate implements Predicate { private static final Log log = LogFactory.getLog(StubRunnerCamelPredicate.class); private final List groovyDsls; + private final ContractVerifierObjectMapper objectMapper = new ContractVerifierObjectMapper(); - public StubRunnerCamelPredicate(List groovyDsls) { + StubRunnerCamelPredicate(List groovyDsls) { this.groovyDsls = groovyDsls; } @@ -66,7 +67,8 @@ class StubRunnerCamelPredicate implements Predicate { public boolean matches(Exchange exchange) { Contract contract = getContract(exchange.getMessage()); if (log.isDebugEnabled()) { - log.debug("For exchange [" + exchange + "] found contract [" + contract + "]"); + log.debug( + "For exchange [" + exchange + "] found contract [" + contract + "]"); } if (contract == null) { return false; @@ -108,14 +110,19 @@ class StubRunnerCamelPredicate implements Predicate { } else if (!(inputMessage instanceof byte[])) { if (log.isDebugEnabled()) { - log.debug("Contract provided byte comparison, but the input message is of type [" + inputMessage.getClass() + "]. Can't compare the two."); + log.debug( + "Contract provided byte comparison, but the input message is of type [" + + inputMessage.getClass() + + "]. Can't compare the two."); } return null; } else { - boolean matches = Arrays.equals(property.asBytes(), (byte[]) inputMessage); + boolean matches = Arrays.equals(property.asBytes(), + (byte[]) inputMessage); if (log.isDebugEnabled() && !matches) { - log.debug("Contract provided byte comparison, but the byte arrays don't match"); + log.debug( + "Contract provided byte comparison, but the byte arrays don't match"); } return matches ? groovyDsl : null; } @@ -126,10 +133,11 @@ class StubRunnerCamelPredicate implements Predicate { return null; } - private boolean matchViaContent(Contract groovyDsl, Object inputMessage, Object dslBody) { + private boolean matchViaContent(Contract groovyDsl, Object inputMessage, + Object dslBody) { boolean matches; - ContentType type = ContentUtils - .getClientContentType(inputMessage, groovyDsl.getInput().getMessageHeaders()); + ContentType type = ContentUtils.getClientContentType(inputMessage, + groovyDsl.getInput().getMessageHeaders()); if (type == ContentType.JSON) { BodyMatchers matchers = groovyDsl.getInput().getBodyMatchers(); matches = matchesForJsonPayload(groovyDsl, inputMessage, matchers, dslBody); @@ -138,7 +146,8 @@ class StubRunnerCamelPredicate implements Predicate { Pattern pattern = ((RegexProperty) dslBody).getPattern(); matches = pattern.matcher((String) inputMessage).matches(); bodyUnmatchedLog(dslBody, matches, pattern); - } else { + } + else { matches = dslBody.equals(inputMessage); bodyUnmatchedLog(dslBody, matches, inputMessage); } @@ -147,12 +156,13 @@ class StubRunnerCamelPredicate implements Predicate { private void bodyUnmatchedLog(Object dslBody, boolean matches, Object pattern) { if (log.isDebugEnabled() && !matches) { - log.debug("Body was supposed to " + unmatchedText(pattern) + " but the value is [" + dslBody - .toString() + "]"); + log.debug("Body was supposed to " + unmatchedText(pattern) + + " but the value is [" + dslBody.toString() + "]"); } } - private boolean matchesForJsonPayload(Contract groovyDsl, Object inputMessage, BodyMatchers matchers, Object dslBody) { + private boolean matchesForJsonPayload(Contract groovyDsl, Object inputMessage, + BodyMatchers matchers, Object dslBody) { Object matchingInputMessage = JsonToJsonPathsConverter .removeMatchingJsonPaths(dslBody, matchers); JsonPaths jsonPaths = JsonToJsonPathsConverter diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelProcessor.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelProcessor.java index ff1261dbfd..f8114f68a5 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelProcessor.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelProcessor.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -65,8 +65,8 @@ class StubRunnerCamelProcessor implements Processor { } private Object outputBody(Contract groovyDsl) { - Object outputBody = - BodyExtractor.extractClientValueFromBody(groovyDsl.getOutputMessage().getBody()); + Object outputBody = BodyExtractor + .extractClientValueFromBody(groovyDsl.getOutputMessage().getBody()); if (outputBody instanceof FromFileProperty) { FromFileProperty property = (FromFileProperty) outputBody; return property.asBytes(); @@ -74,15 +74,18 @@ class StubRunnerCamelProcessor implements Processor { return BodyExtractor.extractStubValueFrom(outputBody); } - private void setStubRunnerDestinationHeader(Exchange exchange, StubRunnerCamelPayload body) { + private void setStubRunnerDestinationHeader(Exchange exchange, + StubRunnerCamelPayload body) { boolean outputPart = body.contract.getOutputMessage() != null; String url = DUMMY_BEAN_URL; if (outputPart && body.contract.getOutputMessage().getSentTo() != null) { url = body.contract.getOutputMessage().getSentTo().getClientValue(); } - exchange.getIn().setHeader(StubRunnerCamelConfiguration.STUBRUNNER_DESTINATION_URL_HEADER_NAME, url); + exchange.getIn().setHeader( + StubRunnerCamelConfiguration.STUBRUNNER_DESTINATION_URL_HEADER_NAME, url); if (log.isDebugEnabled()) { log.debug("Set stub runner destination header to [" + url + "]"); } } + } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationConfiguration.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationConfiguration.java index c66714e98c..dc272ceb33 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationConfiguration.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationConfiguration.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -59,9 +59,11 @@ public class StubRunnerIntegrationConfiguration { BatchStubRunner batchStubRunner) { Map> contracts = batchStubRunner .getContracts(); - IntegrationFlowBuilder dummyBuilder = IntegrationFlows.from(DummyMessageHandler.CHANNEL_NAME) + IntegrationFlowBuilder dummyBuilder = IntegrationFlows + .from(DummyMessageHandler.CHANNEL_NAME) .handle(new DummyMessageHandler(), "handle"); - beanFactory.initializeBean(dummyBuilder.get(), DummyMessageHandler.CHANNEL_NAME + ".flow"); + beanFactory.initializeBean(dummyBuilder.get(), + DummyMessageHandler.CHANNEL_NAME + ".flow"); for (Entry> entry : contracts .entrySet()) { StubConfiguration key = entry.getKey(); @@ -74,7 +76,7 @@ public class StubRunnerIntegrationConfiguration { } if (dsl.getInput() != null && dsl.getInput().getMessageFrom() != null && StringUtils.hasText( - dsl.getInput().getMessageFrom().getClientValue())) { + dsl.getInput().getMessageFrom().getClientValue())) { String from = dsl.getInput().getMessageFrom().getClientValue(); map.add(from, dsl); } @@ -82,15 +84,18 @@ public class StubRunnerIntegrationConfiguration { for (Entry> entries : map.entrySet()) { final String flowName = name + "_" + entries.getKey() + "_" + entries.getValue().hashCode(); - IntegrationFlowBuilder builder = IntegrationFlows.from(entries.getKey()) - .filter(new StubRunnerIntegrationMessageSelector(entries.getValue()), + IntegrationFlowBuilder builder = IntegrationFlows + .from(entries.getKey()).filter( + new StubRunnerIntegrationMessageSelector( + entries.getValue()), new Consumer() { @Override public void accept(FilterEndpointSpec e) { e.id(flowName + ".filter"); } }) - .transform(new StubRunnerIntegrationTransformer(entries.getValue()), + .transform( + new StubRunnerIntegrationTransformer(entries.getValue()), new Consumer>() { @Override public void accept( @@ -98,11 +103,11 @@ public class StubRunnerIntegrationConfiguration { e.id(flowName + ".transformer"); } }) - .route(new StubRunnerIntegrationRouter(entries.getValue(), beanFactory)); + .route(new StubRunnerIntegrationRouter(entries.getValue(), + beanFactory)); beanFactory.initializeBean(builder.get(), flowName); beanFactory.getBean(flowName + ".filter", Lifecycle.class).start(); - beanFactory.getBean(flowName + ".transformer", Lifecycle.class) - .start(); + beanFactory.getBean(flowName + ".transformer", Lifecycle.class).start(); } } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationMessageSelector.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationMessageSelector.java index 982fb63f2b..c93235505e 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationMessageSelector.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationMessageSelector.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -48,15 +48,15 @@ import org.springframework.integration.core.MessageSelector; import org.springframework.messaging.Message; /** - * Passes through a message that matches the one defined in the DSL + * Passes through a message that matches the one defined in the DSL. * * @author Marcin Grzejszczak * @author Tim Ysewyn */ class StubRunnerIntegrationMessageSelector implements MessageSelector { - private static final Map CACHE = - Collections.synchronizedMap(new WeakHashMap<>()); + private static final Map CACHE = Collections + .synchronizedMap(new WeakHashMap<>()); private static final Log log = LogFactory .getLog(StubRunnerIntegrationMessageSelector.class); @@ -126,14 +126,19 @@ class StubRunnerIntegrationMessageSelector implements MessageSelector { } else if (!(inputMessage instanceof byte[])) { if (log.isDebugEnabled()) { - log.debug("Contract provided byte comparison, but the input message is of type [" + inputMessage.getClass() + "]. Can't compare the two."); + log.debug( + "Contract provided byte comparison, but the input message is of type [" + + inputMessage.getClass() + + "]. Can't compare the two."); } return null; } else { - boolean matches = Arrays.equals(property.asBytes(), (byte[]) inputMessage); + boolean matches = Arrays.equals(property.asBytes(), + (byte[]) inputMessage); if (log.isDebugEnabled() && !matches) { - log.debug("Contract provided byte comparison, but the byte arrays don't match"); + log.debug( + "Contract provided byte comparison, but the byte arrays don't match"); } return matches ? groovyDsl : null; } @@ -144,10 +149,11 @@ class StubRunnerIntegrationMessageSelector implements MessageSelector { return null; } - private boolean matchViaContent(Contract groovyDsl, Object inputMessage, Object dslBody) { + private boolean matchViaContent(Contract groovyDsl, Object inputMessage, + Object dslBody) { boolean matches; - ContentType type = ContentUtils - .getClientContentType(inputMessage, groovyDsl.getInput().getMessageHeaders()); + ContentType type = ContentUtils.getClientContentType(inputMessage, + groovyDsl.getInput().getMessageHeaders()); if (type == ContentType.JSON) { BodyMatchers matchers = groovyDsl.getInput().getBodyMatchers(); matches = matchesForJsonPayload(groovyDsl, inputMessage, matchers, dslBody); @@ -156,7 +162,8 @@ class StubRunnerIntegrationMessageSelector implements MessageSelector { Pattern pattern = ((RegexProperty) dslBody).getPattern(); matches = pattern.matcher((String) inputMessage).matches(); bodyUnmatchedLog(dslBody, matches, pattern); - } else { + } + else { matches = dslBody.equals(inputMessage); bodyUnmatchedLog(dslBody, matches, inputMessage); } @@ -165,12 +172,13 @@ class StubRunnerIntegrationMessageSelector implements MessageSelector { private void bodyUnmatchedLog(Object dslBody, boolean matches, Object pattern) { if (log.isDebugEnabled() && !matches) { - log.debug("Body was supposed to " + unmatchedText(pattern) + " but the value is [" + dslBody - .toString() + "]"); + log.debug("Body was supposed to " + unmatchedText(pattern) + + " but the value is [" + dslBody.toString() + "]"); } } - private boolean matchesForJsonPayload(Contract groovyDsl, Object inputMessage, BodyMatchers matchers, Object dslBody) { + private boolean matchesForJsonPayload(Contract groovyDsl, Object inputMessage, + BodyMatchers matchers, Object dslBody) { Object matchingInputMessage = JsonToJsonPathsConverter .removeMatchingJsonPaths(dslBody, matchers); JsonPaths jsonPaths = JsonToJsonPathsConverter @@ -248,4 +256,5 @@ class StubRunnerIntegrationMessageSelector implements MessageSelector { ? "match pattern [" + ((RegexProperty) expectedValue).pattern() + "]" : "be equal to [" + expectedValue + "]"; } + } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationRouter.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationRouter.java index cc8a69a01e..ac55177142 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationRouter.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationRouter.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 java.util.Collection; @@ -16,6 +32,7 @@ import org.springframework.messaging.MessageChannel; class StubRunnerIntegrationRouter extends AbstractMessageRouter { private final StubRunnerIntegrationMessageSelector selector; + private final BeanFactory beanFactory; StubRunnerIntegrationRouter(List groovyDsls, BeanFactory beanFactory) { @@ -32,8 +49,8 @@ class StubRunnerIntegrationRouter extends AbstractMessageRouter { return Collections .singleton((MessageChannel) this.beanFactory.getBean(channelName)); } - return Collections - .singleton((MessageChannel) - this.beanFactory.getBean(StubRunnerIntegrationConfiguration.DummyMessageHandler.CHANNEL_NAME)); + return Collections.singleton((MessageChannel) this.beanFactory.getBean( + StubRunnerIntegrationConfiguration.DummyMessageHandler.CHANNEL_NAME)); } -} \ No newline at end of file + +} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationTransformer.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationTransformer.java index df6c23678e..7bd7a2ce13 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationTransformer.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationTransformer.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -63,8 +63,8 @@ class StubRunnerIntegrationTransformer } private Object outputBody(Contract groovyDsl) { - Object outputBody = - BodyExtractor.extractClientValueFromBody(groovyDsl.getOutputMessage().getBody()); + Object outputBody = BodyExtractor + .extractClientValueFromBody(groovyDsl.getOutputMessage().getBody()); if (outputBody instanceof FromFileProperty) { FromFileProperty property = (FromFileProperty) outputBody; return property.asBytes(); diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerMessageRouter.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerMessageRouter.java index 0b58ec2172..5755a9e8fa 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerMessageRouter.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerMessageRouter.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 java.util.Collection; @@ -16,6 +32,7 @@ import org.springframework.messaging.MessageChannel; class StubRunnerMessageRouter extends AbstractMessageRouter { private final StubRunnerStreamMessageSelector selector; + private final BeanFactory beanFactory; StubRunnerMessageRouter(List groovyDsls, BeanFactory beanFactory) { @@ -28,13 +45,14 @@ class StubRunnerMessageRouter extends AbstractMessageRouter { Contract dsl = this.selector.matchingContract(message); if (dsl != null && dsl.getOutputMessage() != null && dsl.getOutputMessage().getSentTo() != null) { - String channelName = StubRunnerStreamConfiguration.resolvedDestination(this.beanFactory, + String channelName = StubRunnerStreamConfiguration.resolvedDestination( + this.beanFactory, dsl.getOutputMessage().getSentTo().getClientValue()); return Collections .singleton((MessageChannel) this.beanFactory.getBean(channelName)); } - return Collections - .singleton((MessageChannel) - this.beanFactory.getBean(StubRunnerStreamConfiguration.DummyMessageHandler.CHANNEL_NAME)); + return Collections.singleton((MessageChannel) this.beanFactory + .getBean(StubRunnerStreamConfiguration.DummyMessageHandler.CHANNEL_NAME)); } -} \ No newline at end of file + +} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamConfiguration.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamConfiguration.java index 2f153c3ed2..58f32a3357 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamConfiguration.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamConfiguration.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -67,6 +67,28 @@ public class StubRunnerStreamConfiguration { private static final Log log = LogFactory.getLog(StubRunnerStreamConfiguration.class); + static String resolvedDestination(BeanFactory context, String destination) { + Map bindings = bindingProperties(context); + for (Map.Entry entry : bindings.entrySet()) { + if (destination.equals(entry.getValue().getDestination())) { + if (log.isDebugEnabled()) { + log.debug("Found a channel named [" + entry.getKey() + + "] with destination [" + destination + "]"); + } + return entry.getKey(); + } + } + if (log.isDebugEnabled()) { + log.debug("No destination named [" + destination + + "] was found. Assuming that the destination equals the channel name"); + } + return destination; + } + + private static Map bindingProperties(BeanFactory context) { + return context.getBean(BindingServiceProperties.class).getBindings(); + } + @Bean @ConditionalOnMissingBean(name = "stubFlowRegistrar") @ConditionalOnBean(BindingServiceProperties.class) @@ -74,9 +96,11 @@ public class StubRunnerStreamConfiguration { BatchStubRunner batchStubRunner) { Map> contracts = batchStubRunner .getContracts(); - IntegrationFlowBuilder dummyBuilder = IntegrationFlows.from(DummyMessageHandler.CHANNEL_NAME) + IntegrationFlowBuilder dummyBuilder = IntegrationFlows + .from(DummyMessageHandler.CHANNEL_NAME) .handle(new DummyMessageHandler(), "handle"); - beanFactory.initializeBean(dummyBuilder.get(), DummyMessageHandler.CHANNEL_NAME + ".flow"); + beanFactory.initializeBean(dummyBuilder.get(), + DummyMessageHandler.CHANNEL_NAME + ".flow"); for (Entry> entry : contracts .entrySet()) { StubConfiguration key = entry.getKey(); @@ -123,40 +147,17 @@ public class StubRunnerStreamConfiguration { e.id(flowName + ".transformer"); } }) - .route(new StubRunnerMessageRouter(entries.getValue(), beanFactory)); + .route(new StubRunnerMessageRouter(entries.getValue(), + beanFactory)); beanFactory.initializeBean(builder.get(), flowName); beanFactory.getBean(flowName + ".filter", Lifecycle.class).start(); - beanFactory.getBean(flowName + ".transformer", Lifecycle.class) - .start(); + beanFactory.getBean(flowName + ".transformer", Lifecycle.class).start(); } } return new FlowRegistrar(); } - static String resolvedDestination(BeanFactory context, - String destination) { - Map bindings = bindingProperties(context); - for (Map.Entry entry : bindings.entrySet()) { - if (destination.equals(entry.getValue().getDestination())) { - if (log.isDebugEnabled()) { - log.debug("Found a channel named [" + entry.getKey() - + "] with destination [" + destination + "]"); - } - return entry.getKey(); - } - } - if (log.isDebugEnabled()) { - log.debug("No destination named [" + destination - + "] was found. Assuming that the destination equals the channel name"); - } - return destination; - } - - private static Map bindingProperties(BeanFactory context) { - return context.getBean(BindingServiceProperties.class).getBindings(); - } - static class DummyMessageHandler { static String CHANNEL_NAME = "stub_runner_dummy_channel"; diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamMessageSelector.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamMessageSelector.java index b0980cc55e..b181550b2b 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamMessageSelector.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamMessageSelector.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -48,15 +48,15 @@ import org.springframework.integration.core.MessageSelector; import org.springframework.messaging.Message; /** - * Passes through a message that matches the one defined in the DSL + * Passes through a message that matches the one defined in the DSL. * * @author Marcin Grzejszczak * @author Tim Ysewyn */ class StubRunnerStreamMessageSelector implements MessageSelector { - private static final Map CACHE = - Collections.synchronizedMap(new WeakHashMap<>()); + private static final Map CACHE = Collections + .synchronizedMap(new WeakHashMap<>()); private static final Log log = LogFactory .getLog(StubRunnerStreamMessageSelector.class); @@ -126,14 +126,19 @@ class StubRunnerStreamMessageSelector implements MessageSelector { } else if (!(inputMessage instanceof byte[])) { if (log.isDebugEnabled()) { - log.debug("Contract provided byte comparison, but the input message is of type [" + inputMessage.getClass() + "]. Can't compare the two."); + log.debug( + "Contract provided byte comparison, but the input message is of type [" + + inputMessage.getClass() + + "]. Can't compare the two."); } return null; } else { - boolean matches = Arrays.equals(property.asBytes(), (byte[]) inputMessage); + boolean matches = Arrays.equals(property.asBytes(), + (byte[]) inputMessage); if (log.isDebugEnabled() && !matches) { - log.debug("Contract provided byte comparison, but the byte arrays don't match"); + log.debug( + "Contract provided byte comparison, but the byte arrays don't match"); } return matches ? groovyDsl : null; } @@ -144,9 +149,11 @@ class StubRunnerStreamMessageSelector implements MessageSelector { return null; } - private boolean matchViaContent(Contract groovyDsl, Object inputMessage, Object dslBody) { + private boolean matchViaContent(Contract groovyDsl, Object inputMessage, + Object dslBody) { boolean matches; - ContentType type = ContentUtils.getClientContentType(inputMessage, groovyDsl.getInput().getMessageHeaders()); + ContentType type = ContentUtils.getClientContentType(inputMessage, + groovyDsl.getInput().getMessageHeaders()); if (type == ContentType.JSON) { BodyMatchers matchers = groovyDsl.getInput().getBodyMatchers(); matches = matchesForJsonPayload(groovyDsl, inputMessage, matchers, dslBody); @@ -155,7 +162,8 @@ class StubRunnerStreamMessageSelector implements MessageSelector { Pattern pattern = ((RegexProperty) dslBody).getPattern(); matches = pattern.matcher((String) inputMessage).matches(); bodyUnmatchedLog(dslBody, matches, pattern); - } else { + } + else { matches = dslBody.equals(inputMessage); bodyUnmatchedLog(dslBody, matches, inputMessage); } @@ -164,12 +172,13 @@ class StubRunnerStreamMessageSelector implements MessageSelector { private void bodyUnmatchedLog(Object dslBody, boolean matches, Object pattern) { if (log.isDebugEnabled() && !matches) { - log.debug("Body was supposed to " + unmatchedText(pattern) + " but the value is [" + dslBody - .toString() + "]"); + log.debug("Body was supposed to " + unmatchedText(pattern) + + " but the value is [" + dslBody.toString() + "]"); } } - private boolean matchesForJsonPayload(Contract groovyDsl, Object inputMessage, BodyMatchers matchers, Object dslBody) { + private boolean matchesForJsonPayload(Contract groovyDsl, Object inputMessage, + BodyMatchers matchers, Object dslBody) { Object matchingInputMessage = JsonToJsonPathsConverter .removeMatchingJsonPaths(dslBody, matchers); JsonPaths jsonPaths = JsonToJsonPathsConverter @@ -247,4 +256,5 @@ class StubRunnerStreamMessageSelector implements MessageSelector { ? "match pattern [" + ((RegexProperty) expectedValue).pattern() + "]" : "be equal to [" + expectedValue + "]"; } + } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamTransformer.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamTransformer.java index e664a710ae..d2de8ebbca 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamTransformer.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamTransformer.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -62,8 +62,8 @@ class StubRunnerStreamTransformer implements GenericTransformer, Mess } private byte[] outputBodyAsBytes(Contract groovyDsl) { - Object outputBody = - BodyExtractor.extractClientValueFromBody(groovyDsl.getOutputMessage().getBody()); + Object outputBody = BodyExtractor + .extractClientValueFromBody(groovyDsl.getOutputMessage().getBody()); if (outputBody instanceof FromFileProperty) { FromFileProperty property = (FromFileProperty) outputBody; return property.asBytes(); diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/provider/wiremock/StubRunnerWireMockTestExecutionListener.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/provider/wiremock/StubRunnerWireMockTestExecutionListener.java index e78b726a49..5a82256a5d 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/provider/wiremock/StubRunnerWireMockTestExecutionListener.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/provider/wiremock/StubRunnerWireMockTestExecutionListener.java @@ -1,18 +1,17 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT 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.provider.wiremock; @@ -26,7 +25,7 @@ import org.springframework.test.context.TestContext; import org.springframework.test.context.support.AbstractTestExecutionListener; /** - * Marks context to be restarted if at least one stub has a fixed port + * Marks context to be restarted if at least one stub has a fixed port. * * @author Marcin Grzejszczak * @since 1.2.6 @@ -39,9 +38,11 @@ public final class StubRunnerWireMockTestExecutionListener @Override public void afterTestClass(TestContext testContext) { - if (testContext.getTestClass().getAnnotationsByType(AutoConfigureStubRunner.class).length == 0) { + if (testContext.getTestClass() + .getAnnotationsByType(AutoConfigureStubRunner.class).length == 0) { if (log.isDebugEnabled()) { - log.debug("No @AutoConfigureStubRunner annotation found on [" + testContext.getTestClass() + "]. Skipping"); + log.debug("No @AutoConfigureStubRunner annotation found on [" + + testContext.getTestClass() + "]. Skipping"); } return; } @@ -52,9 +53,11 @@ public final class StubRunnerWireMockTestExecutionListener + "as possible. Your tests will be faster and more reliable and this" + "warning will go away"); } - testContext.markApplicationContextDirty(DirtiesContext.HierarchyMode.EXHAUSTIVE); + testContext + .markApplicationContextDirty(DirtiesContext.HierarchyMode.EXHAUSTIVE); } // potential race condition WireMockHttpServerStub.SERVERS.clear(); } -} \ No newline at end of file + +} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/provider/wiremock/WireMockHttpServerStub.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/provider/wiremock/WireMockHttpServerStub.java index bbec5d33af..d9e1700dc1 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/provider/wiremock/WireMockHttpServerStub.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/provider/wiremock/WireMockHttpServerStub.java @@ -1,18 +1,17 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT 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.provider.wiremock; @@ -56,19 +55,19 @@ import org.springframework.util.StreamUtils; import org.springframework.util.StringUtils; /** - * Abstraction over WireMock as a HTTP Server Stub + * Abstraction over WireMock as a HTTP Server Stub. * * @author Marcin Grzejszczak * @since 1.1.0 */ public class WireMockHttpServerStub implements HttpServerStub { + static final Map SERVERS = new ConcurrentHashMap<>(); + private static final Log log = LogFactory.getLog(WireMockHttpServerStub.class); private static final int INVALID_PORT = -1; - static final Map SERVERS = new ConcurrentHashMap<>(); - private WireMockServer wireMockServer; private boolean https = false; @@ -99,9 +98,10 @@ public class WireMockHttpServerStub implements HttpServerStub { } /** - * Override this if you want to register your own helpers + * Override this if you want to register your own helpers. * @deprecated - please use the {@link WireMockExtensions} mechanism and pass the * helpers in your implementation + * @return a mapping of helper names to its implementations */ @Deprecated protected Map helpers() { @@ -113,9 +113,8 @@ public class WireMockHttpServerStub implements HttpServerStub { @Override public int port() { - return isRunning() ? (this.https ? - this.wireMockServer.httpsPort() : this.wireMockServer.port()) - : INVALID_PORT; + return isRunning() ? (this.https ? this.wireMockServer.httpsPort() + : this.wireMockServer.port()) : INVALID_PORT; } @Override @@ -138,7 +137,9 @@ public class WireMockHttpServerStub implements HttpServerStub { } private HttpServerStubConfiguration defaultConfiguration(int port) { - return new HttpServerStubConfiguration(HttpServerStubConfigurer.NoOpHttpServerStubConfigurer.INSTANCE, null, null, port); + return new HttpServerStubConfiguration( + HttpServerStubConfigurer.NoOpHttpServerStubConfigurer.INSTANCE, null, + null, port); } @Override @@ -147,8 +148,7 @@ public class WireMockHttpServerStub implements HttpServerStub { } @Override - public HttpServerStub start( - HttpServerStubConfiguration configuration) { + public HttpServerStub start(HttpServerStubConfiguration configuration) { if (isRunning()) { if (log.isTraceEnabled()) { log.trace("The server is already running at port [" + port() + "]"); @@ -161,16 +161,19 @@ public class WireMockHttpServerStub implements HttpServerStub { if (configuration.configurer.isAccepted(wireMockConfiguration)) { @SuppressWarnings("unchecked") HttpServerStubConfigurer configurer = configuration.configurer; - wireMockConfiguration = configurer.configure(wireMockConfiguration, configuration); + wireMockConfiguration = configurer.configure(wireMockConfiguration, + configuration); } this.wireMockConfiguration = wireMockConfiguration; this.https = wireMockConfiguration.httpsSettings().enabled(); - port = this.https ? wireMockConfiguration.httpsSettings().port() : - wireMockConfiguration.portNumber(); + port = this.https ? wireMockConfiguration.httpsSettings().port() + : wireMockConfiguration.portNumber(); this.wireMockServer = new WireMockServer(wireMockConfiguration); this.wireMockServer.start(); if (log.isDebugEnabled()) { - log.debug("For " + configuration.toColonSeparatedDependencyNotation() + " Started WireMock at [" + (this.https ? "https" : "http") + "] port [" + port + "]"); + log.debug("For " + configuration.toColonSeparatedDependencyNotation() + + " Started WireMock at [" + (this.https ? "https" : "http") + + "] port [" + port + "]"); } cacheStubServer(false, port); return this; @@ -255,8 +258,8 @@ public class WireMockHttpServerStub implements HttpServerStub { String proxyHost = this.wireMockConfiguration.proxyHostHeader(); int proxyPort = this.wireMockConfiguration.proxyVia().port(); ClientAuthenticator authenticator = NoClientAuthenticator.noClientAuthenticator(); - return new WireMock(scheme, host, port, urlPathPrefix, - hostHeader, proxyHost, proxyPort, authenticator); + return new WireMock(scheme, host, port, urlPathPrefix, hostHeader, proxyHost, + proxyPort, authenticator); } private void registerDefaultHealthChecks(WireMock wireMock) { @@ -282,7 +285,8 @@ public class WireMockHttpServerStub implements HttpServerStub { } } PortAndMappings portAndMappings = SERVERS.get(this); - SERVERS.put(this, new PortAndMappings(portAndMappings.random, portAndMappings.port, stubMappings)); + SERVERS.put(this, new PortAndMappings(portAndMappings.random, + portAndMappings.port, stubMappings)); } private StubMapping registerDescriptor(WireMock wireMock, File mappingDescriptor) { @@ -305,7 +309,9 @@ public class WireMockHttpServerStub implements HttpServerStub { class PortAndMappings { final boolean random; + final Integer port; + final List mappings; PortAndMappings(boolean random, Integer port, List mappings) { @@ -316,10 +322,8 @@ class PortAndMappings { @Override public String toString() { - return "PortAndMappings{" + - "random=" + this.random + - ", port=" + this.port + - ", mappings=" + this.mappings + - '}'; + return "PortAndMappings{" + "random=" + this.random + ", port=" + this.port + + ", mappings=" + this.mappings + '}'; } -} \ No newline at end of file + +} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/provider/wiremock/WireMockHttpServerStubConfigurer.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/provider/wiremock/WireMockHttpServerStubConfigurer.java index fbac9f4690..ac02dfa2c8 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/provider/wiremock/WireMockHttpServerStubConfigurer.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/provider/wiremock/WireMockHttpServerStubConfigurer.java @@ -21,14 +21,18 @@ import com.github.tomakehurst.wiremock.core.WireMockConfiguration; import org.springframework.cloud.contract.stubrunner.HttpServerStubConfigurer; /** - * Typed implementation of {@link HttpServerStubConfigurer} for WireMock's {@link WireMockConfiguration} + * Typed implementation of {@link HttpServerStubConfigurer} for WireMock's + * {@link WireMockConfiguration}. * * @author Marcin Grzejszczak * @since 2.1.0 */ -public class WireMockHttpServerStubConfigurer implements HttpServerStubConfigurer { +public class WireMockHttpServerStubConfigurer + implements HttpServerStubConfigurer { + @Override public boolean isAccepted(Object httpStubConfiguration) { return httpStubConfiguration instanceof WireMockConfiguration; } + } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/HttpStubsController.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/HttpStubsController.java index ebf072fa62..9bd3e6b867 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/HttpStubsController.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/HttpStubsController.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.server; diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/StubRunnerBackupAutoConfiguration.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/StubRunnerBackupAutoConfiguration.java index 9333c412b0..8eeeb96a0b 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/StubRunnerBackupAutoConfiguration.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/StubRunnerBackupAutoConfiguration.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.server; diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/StubRunnerBoot.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/StubRunnerBoot.java index 86f5a15d92..72705879ef 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/StubRunnerBoot.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/StubRunnerBoot.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.server; diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/TriggerController.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/TriggerController.java index bff80e1492..3887c222b4 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/TriggerController.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/TriggerController.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.server; @@ -22,6 +22,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.contract.stubrunner.StubFinder; import org.springframework.http.MediaType; diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/AutoConfigureStubRunner.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/AutoConfigureStubRunner.java index bf8fd75307..0c95cba342 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/AutoConfigureStubRunner.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/AutoConfigureStubRunner.java @@ -26,6 +26,7 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.test.autoconfigure.properties.PropertyMapping; import org.springframework.boot.test.autoconfigure.properties.SkipPropertyMapping; import org.springframework.cloud.contract.stubrunner.HttpServerStubConfigurer; +import org.springframework.cloud.contract.stubrunner.HttpServerStubConfigurer.NoOpHttpServerStubConfigurer; import org.springframework.cloud.contract.verifier.messaging.boot.AutoConfigureMessageVerifier; /** @@ -41,29 +42,29 @@ import org.springframework.cloud.contract.verifier.messaging.boot.AutoConfigureM public @interface AutoConfigureStubRunner { /** - * Min value of a port for the automatically started WireMock server + * @return Min value of a port for the automatically started WireMock server. */ int minPort() default 10000; /** - * Max value of a port for the automatically started WireMock server + * @return Max value of a port for the automatically started WireMock server. */ int maxPort() default 15000; /** - * The repository root to use (where the stubs should be downloaded from) + * @return The repository root to use (where the stubs should be downloaded from). */ String repositoryRoot() default ""; /** - * The ids of the stubs to run in "ivy" notation + * @return The ids of the stubs to run in "ivy" notation * ([groupId]:artifactId[:version][:classifier][:port]). {@code groupId}, * {@code version}, {@code classifier} and {@code port} can be optional. */ String[] ids() default {}; /** - * The classifier to use by default in ivy co-ordinates for a stub. + * @return The classifier to use by default in ivy co-ordinates for a stub. */ String classifier() default "stubs"; @@ -92,7 +93,7 @@ public @interface AutoConfigureStubRunner { * * @see issue 224 - * + * @return {@code true} to turn on the feature */ boolean stubsPerConsumer() default false; @@ -102,6 +103,7 @@ public @interface AutoConfigureStubRunner { * * @see issue 224 + * @return name of this application */ String consumerName() default ""; @@ -112,6 +114,7 @@ public @interface AutoConfigureStubRunner { * * @see issue 355 + * @return where the mappings output should be stored */ String mappingsOutputFolder() default ""; @@ -123,21 +126,21 @@ public @interface AutoConfigureStubRunner { StubRunnerProperties.StubsMode stubsMode() default StubRunnerProperties.StubsMode.CLASSPATH; /** - * Properties in form {@literal key=value} + * Properties in form {@literal key=value}. * @return the properties to add */ String[] properties() default {}; /** - * If set to {@code false} will NOT delete stubs from a temporary - * folder after running tests + * @return If set to {@code false} will NOT delete stubs from a temporary folder after + * running tests */ boolean deleteStubsAfterTest() default true; /** - * Configuration for an HTTP server stub + * Configuration for an HTTP server stub. * @return class that allows to perform additional HTTP server stub configuration */ - Class httpServerStubConfigurer() - default HttpServerStubConfigurer.NoOpHttpServerStubConfigurer.class; + Class httpServerStubConfigurer() default NoOpHttpServerStubConfigurer.class; + } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerConfiguration.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerConfiguration.java index b13f78c09b..0e0ab0ef99 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerConfiguration.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerConfiguration.java @@ -1,22 +1,21 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 java.util.HashMap; import java.util.Map; @@ -42,7 +41,10 @@ import org.springframework.util.StringUtils; /** * Configuration that initializes a {@link BatchStubRunner} that runs - * {@link org.springframework.cloud.contract.stubrunner.StubRunner} instance for each stub + * {@link org.springframework.cloud.contract.stubrunner.StubRunner} instance for each + * stub. + * + * @author Marcin Grzejszczak */ @Configuration @EnableConfigurationProperties(StubRunnerProperties.class) @@ -67,9 +69,10 @@ public class StubRunnerConfiguration { * Bean that initializes stub runners, runs them and on shutdown closes them. Upon its * instantiation JAR with stubs is downloaded and unpacked to a temporary folder and * WireMock server are started for each of those stubs + * @return the batch stub runner bean */ @Bean - public BatchStubRunner batchStubRunner() throws IOException { + public BatchStubRunner batchStubRunner() { StubRunnerOptionsBuilder builder = builder(); if (this.props.getProxyHost() != null) { builder.withProxy(this.props.getProxyHost(), this.props.getProxyPort()); @@ -85,7 +88,7 @@ public class StubRunnerConfiguration { return batchStubRunner; } - private StubRunnerOptionsBuilder builder() throws IOException { + private StubRunnerOptionsBuilder builder() { return new StubRunnerOptionsBuilder() .withMinMaxPort(this.props.getMinPort(), this.props.getMaxPort()) .withStubRepositoryRoot(this.props.getRepositoryRoot()) @@ -111,8 +114,8 @@ public class StubRunnerConfiguration { private void registerPort(RunningStubs runStubs) { MutablePropertySources propertySources = this.environment.getPropertySources(); if (!propertySources.contains(STUBRUNNER_PREFIX)) { - propertySources.addFirst(new MapPropertySource(STUBRUNNER_PREFIX, - new HashMap())); + propertySources + .addFirst(new MapPropertySource(STUBRUNNER_PREFIX, new HashMap<>())); } Map source = ((MapPropertySource) propertySources .get(STUBRUNNER_PREFIX)).getSource(); @@ -127,4 +130,4 @@ public class StubRunnerConfiguration { } } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerPort.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerPort.java index fcde1763cc..d91fb67e13 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerPort.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerPort.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.lang.annotation.Documented; @@ -18,8 +34,9 @@ import java.lang.annotation.Target; public @interface StubRunnerPort { /** - * The {@code artifactid} or {@code groupid:artifactid} notation of the started stub + * @return the {@code artifactid} or {@code groupid:artifactid} notation of the + * started stub. */ String value(); -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerPortBeanPostProcessor.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerPortBeanPostProcessor.java index daabea879c..c75748ed39 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerPortBeanPostProcessor.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerPortBeanPostProcessor.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.lang.reflect.Field; @@ -8,7 +24,7 @@ import org.springframework.core.env.Environment; import org.springframework.util.ReflectionUtils; /** - * Injects {@link StubRunnerPort} ports into fields + * Injects {@link StubRunnerPort} ports into fields. * * @author Marcin Grzejszczak * @since 2.0.0 @@ -64,4 +80,4 @@ class StubRunnerPortFieldCallback implements ReflectionUtils.FieldCallback { } } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerProperties.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerProperties.java index c9dd300058..fe11a38b23 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerProperties.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerProperties.java @@ -23,6 +23,7 @@ import java.util.Properties; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.cloud.contract.stubrunner.HttpServerStubConfigurer; +import org.springframework.cloud.contract.stubrunner.HttpServerStubConfigurer.NoOpHttpServerStubConfigurer; import org.springframework.cloud.contract.stubrunner.ResourceResolver; import org.springframework.core.io.Resource; import org.springframework.util.StringUtils; @@ -35,17 +36,17 @@ import org.springframework.util.StringUtils; public class StubRunnerProperties { /** - * Min value of a port for the automatically started WireMock server + * Min value of a port for the automatically started WireMock server. */ private int minPort = 10000; /** - * Max value of a port for the automatically started WireMock server + * Max value of a port for the automatically started WireMock server. */ private int maxPort = 15000; /** - * The repository root to use (where the stubs should be downloaded from) + * The repository root to use (where the stubs should be downloaded from). */ private Resource repositoryRoot; @@ -62,22 +63,22 @@ public class StubRunnerProperties { private String classifier = "stubs"; /** - * Repository username + * Repository username. */ private String username; /** - * Repository password + * Repository password. */ private String password; /** - * Repository proxy port + * Repository proxy port. */ private Integer proxyPort; /** - * Repository proxy host + * Repository proxy host. */ private String proxyHost; @@ -93,54 +94,31 @@ public class StubRunnerProperties { private String consumerName; /** - * Dumps the mappings of each HTTP server to the selected folder + * Dumps the mappings of each HTTP server to the selected folder. */ private String mappingsOutputFolder; /** - * Pick where the stubs should come from + * Pick where the stubs should come from. */ private StubsMode stubsMode; /** * If set to {@code false} will NOT delete stubs from a temporary folder after running - * tests + * tests. */ private boolean deleteStubsAfterTest = true; /** * Map of properties that can be passed to custom - * {@link org.springframework.cloud.contract.stubrunner.StubDownloaderBuilder} + * {@link org.springframework.cloud.contract.stubrunner.StubDownloaderBuilder}. */ private Map properties = new HashMap<>(); /** - * Configuration for an HTTP server stub + * Configuration for an HTTP server stub. */ - private Class httpServerStubConfigurer = - HttpServerStubConfigurer.NoOpHttpServerStubConfigurer.class; - - /** - * An enumeration stub modes. - */ - public enum StubsMode { - - /** - * Pick the stubs from classpath - */ - CLASSPATH, - - /** - * Fetch the stubs from local .m2 - */ - LOCAL, - - /** - * Fetch the stubs from a remote location - */ - REMOTE, - - } + private Class httpServerStubConfigurer = NoOpHttpServerStubConfigurer.class; public int getMinPort() { return this.minPort; @@ -258,14 +236,6 @@ public class StubRunnerProperties { return this.properties; } - public Class getHttpServerStubConfigurer() { - return this.httpServerStubConfigurer; - } - - public void setHttpServerStubConfigurer(Class httpServerStubConfigurer) { - this.httpServerStubConfigurer = httpServerStubConfigurer; - } - public void setProperties(String[] properties) { Properties elements = StringUtils.splitArrayElementsIntoProperties(properties, "="); @@ -277,6 +247,14 @@ public class StubRunnerProperties { } } + public Class getHttpServerStubConfigurer() { + return this.httpServerStubConfigurer; + } + + public void setHttpServerStubConfigurer(Class httpServerStubConfigurer) { + this.httpServerStubConfigurer = httpServerStubConfigurer; + } + @Override public String toString() { return "StubRunnerProperties{" + "minPort=" + this.minPort + ", maxPort=" @@ -287,4 +265,26 @@ public class StubRunnerProperties { + ", size of properties=" + this.properties.size() + '}'; } + /** + * An enumeration stub modes. + */ + public enum StubsMode { + + /** + * Pick the stubs from classpath. + */ + CLASSPATH, + + /** + * Fetch the stubs from local .m2. + */ + LOCAL, + + /** + * Fetch the stubs from a remote location. + */ + REMOTE, + + } + } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/ConditionalOnStubbedDiscoveryDisabled.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/ConditionalOnStubbedDiscoveryDisabled.java index cbd54032e7..d959a33940 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/ConditionalOnStubbedDiscoveryDisabled.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/ConditionalOnStubbedDiscoveryDisabled.java @@ -25,7 +25,7 @@ import java.lang.annotation.Target; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; /** - * Conditional that checks if the user turned off the stubbed discovery mode + * Conditional that checks if the user turned off the stubbed discovery mode. * * @author Marcin Grzejszczak * diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/StubMapperProperties.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/StubMapperProperties.java index cbbd86d5ca..ca5740839a 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/StubMapperProperties.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/StubMapperProperties.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -40,7 +40,7 @@ import org.springframework.util.StringUtils; public class StubMapperProperties { /** - * Mapping of Ivy notation based ids to serviceIds inside your application + * Mapping of Ivy notation based ids to serviceIds inside your application. * * Example * diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerDiscoveryClient.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerDiscoveryClient.java index e3c5d5c73c..7fc9605611 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerDiscoveryClient.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerDiscoveryClient.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -25,6 +25,7 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.contract.stubrunner.RunningStubs; @@ -33,7 +34,7 @@ import org.springframework.util.StringUtils; /** * Custom version of {@link DiscoveryClient} that tries to find an instance in one of the - * started WireMock servers + * started WireMock servers. * * @author Marcin Grzejszczak * @since 1.0.0 @@ -49,7 +50,7 @@ class StubRunnerDiscoveryClient implements DiscoveryClient { private final StubMapperProperties stubMapperProperties; - public StubRunnerDiscoveryClient(DiscoveryClient delegate, StubFinder stubFinder, + StubRunnerDiscoveryClient(DiscoveryClient delegate, StubFinder stubFinder, StubMapperProperties stubMapperProperties, String springAppName) { this.delegate = delegate instanceof StubRunnerDiscoveryClient ? noOpDiscoveryClient() : delegate; @@ -61,7 +62,7 @@ class StubRunnerDiscoveryClient implements DiscoveryClient { this.stubMapperProperties = stubMapperProperties; } - public StubRunnerDiscoveryClient(StubFinder stubFinder, + StubRunnerDiscoveryClient(StubFinder stubFinder, StubMapperProperties stubMapperProperties, String springAppName) { this.delegate = noOpDiscoveryClient(); if (log.isDebugEnabled()) { diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerServiceInstance.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerServiceInstance.java index b5b6287365..b48ebcaace 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerServiceInstance.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerServiceInstance.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -23,7 +23,7 @@ import java.util.Map; import org.springframework.cloud.client.ServiceInstance; /** - * {@link ServiceInstance} with a helpful constructor + * {@link ServiceInstance} with a helpful constructor. * * @author Marcin Grzejszczak * @since 1.0.0 @@ -38,7 +38,7 @@ class StubRunnerServiceInstance implements ServiceInstance { private final URI uri; - public StubRunnerServiceInstance(String serviceId, String host, int port, URI uri) { + StubRunnerServiceInstance(String serviceId, String host, int port, URI uri) { this.serviceId = serviceId; this.host = host; this.port = port; diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerSpringCloudAutoConfiguration.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerSpringCloudAutoConfiguration.java index 43869cd188..3dc24fffda 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerSpringCloudAutoConfiguration.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerSpringCloudAutoConfiguration.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -33,9 +33,10 @@ import org.springframework.core.env.Environment; /** * Wraps {@link DiscoveryClient} in a Stub Runner implementation that tries to find a - * corresponding WireMock server for a searched dependency + * corresponding WireMock server for a searched dependency. * * @since 1.0.0 + * @author Marcin Grzejszczak */ @Configuration @EnableConfigurationProperties(StubMapperProperties.class) @@ -149,4 +150,4 @@ class StubRunnerDiscoveryClientWrapper implements BeanPostProcessor { return this.cloudDelegateEnabled; } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/StubsRegistrar.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/StubsRegistrar.java index 5ef7755245..b44e9aefb3 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/StubsRegistrar.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/StubsRegistrar.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; /** @@ -10,4 +26,4 @@ public interface StubsRegistrar extends AutoCloseable { void registerStubs(); -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/consul/ConsulStubsRegistrar.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/consul/ConsulStubsRegistrar.java index 6aa61477f7..1a66e5161e 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/consul/ConsulStubsRegistrar.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/consul/ConsulStubsRegistrar.java @@ -1,13 +1,31 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.consul; -import com.ecwid.consul.v1.ConsulClient; -import com.ecwid.consul.v1.agent.model.NewService; import java.lang.invoke.MethodHandles; import java.util.LinkedList; import java.util.List; import java.util.Map; + +import com.ecwid.consul.v1.ConsulClient; +import com.ecwid.consul.v1.agent.model.NewService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.cloud.commons.util.InetUtils; import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties; import org.springframework.cloud.contract.stubrunner.StubConfiguration; @@ -17,7 +35,7 @@ import org.springframework.cloud.contract.stubrunner.spring.cloud.StubsRegistrar import org.springframework.util.StringUtils; /** - * Registers all stubs in Zookeeper Service Discovery + * Registers all stubs in Zookeeper Service Discovery. * * @author Marcin Grzejszczak * @since 1.0.0 diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/consul/StubRunnerSpringCloudConsulAutoConfiguration.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/consul/StubRunnerSpringCloudConsulAutoConfiguration.java index ae53fc100b..0a38919a46 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/consul/StubRunnerSpringCloudConsulAutoConfiguration.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/consul/StubRunnerSpringCloudConsulAutoConfiguration.java @@ -1,22 +1,23 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.consul; import com.ecwid.consul.v1.ConsulClient; + import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -32,13 +33,13 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** - * Autoconfiguration for registering stubs in a Zookeeper Service discovery + * Autoconfiguration for registering stubs in a Zookeeper Service discovery. * * @author Marcin Grzejszczak * @since 1.0.0 */ @Configuration -@AutoConfigureAfter(value = { StubRunnerConfiguration.class, +@AutoConfigureAfter({ StubRunnerConfiguration.class, ConsulServiceRegistryAutoConfiguration.class }) @ConditionalOnClass(ConsulClient.class) @ConditionalOnStubbedDiscoveryDisabled diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/eureka/ConditionalOnEurekaEnabled.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/eureka/ConditionalOnEurekaEnabled.java index 4fa0c722b2..fba0b1de75 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/eureka/ConditionalOnEurekaEnabled.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/eureka/ConditionalOnEurekaEnabled.java @@ -25,7 +25,7 @@ import java.lang.annotation.Target; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; /** - * Conditional that checks if Eureka is enabled + * Conditional that checks if Eureka is enabled. * * @author Marcin Grzejszczak * diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/eureka/EurekaStubsRegistrar.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/eureka/EurekaStubsRegistrar.java index d404e647c2..a49b8a3ec7 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/eureka/EurekaStubsRegistrar.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/eureka/EurekaStubsRegistrar.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.eureka; import java.lang.invoke.MethodHandles; @@ -6,8 +22,13 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import com.netflix.appinfo.ApplicationInfoManager; +import com.netflix.appinfo.InstanceInfo; +import com.netflix.discovery.AbstractDiscoveryClientOptionalArgs; +import com.netflix.discovery.EurekaClient; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.beans.BeansException; import org.springframework.cloud.client.serviceregistry.ServiceRegistry; import org.springframework.cloud.commons.util.InetUtils; @@ -23,13 +44,8 @@ import org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistrati import org.springframework.context.ApplicationContext; import org.springframework.util.StringUtils; -import com.netflix.appinfo.ApplicationInfoManager; -import com.netflix.appinfo.InstanceInfo; -import com.netflix.discovery.AbstractDiscoveryClientOptionalArgs; -import com.netflix.discovery.EurekaClient; - /** - * Registers all stubs in Eureka Service Discovery + * Registers all stubs in Eureka Service Discovery. * * @author Marcin Grzejszczak * @since 1.0.0 diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/eureka/StubRunnerSpringCloudEurekaAutoConfiguration.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/eureka/StubRunnerSpringCloudEurekaAutoConfiguration.java index 3cc6407ecb..e596cab146 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/eureka/StubRunnerSpringCloudEurekaAutoConfiguration.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/eureka/StubRunnerSpringCloudEurekaAutoConfiguration.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.eureka; @@ -20,6 +20,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -44,7 +45,7 @@ import org.springframework.context.annotation.Profile; import org.springframework.core.env.Environment; /** - * Autoconfiguration for registering stubs in a Eureka Service discovery + * Autoconfiguration for registering stubs in a Eureka Service discovery. * * @author Marcin Grzejszczak * @since 1.0.0 diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonAutoConfiguration.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonAutoConfiguration.java index 60abe257c4..2a7f7a19ec 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonAutoConfiguration.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonAutoConfiguration.java @@ -1,21 +1,23 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -26,8 +28,11 @@ import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration; import org.springframework.cloud.netflix.ribbon.RibbonClients; import org.springframework.context.annotation.Configuration; -import com.netflix.loadbalancer.ServerList; - +/** + * Auto configuration for stubbing out Ribbon. + * + * @author Marcin Grzejszczak + */ @Configuration @ConditionalOnClass(ServerList.class) @ConditionalOnBean(StubMapperProperties.class) diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonBeanPostProcessor.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonBeanPostProcessor.java index 721a0636b4..be8700538f 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonBeanPostProcessor.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonBeanPostProcessor.java @@ -1,30 +1,30 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.cloud.contract.stubrunner.StubFinder; import org.springframework.cloud.contract.stubrunner.spring.cloud.StubMapperProperties; -import com.netflix.client.config.IClientConfig; -import com.netflix.loadbalancer.ServerList; - /** * Ribbon AutoConfiguration that manipulates the service id to make the service be picked * from the list of available WireMock instance if one is available. diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonConfiguration.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonConfiguration.java index f11f6b23cc..eec26c1c5f 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonConfiguration.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonConfiguration.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -19,14 +19,14 @@ package org.springframework.cloud.contract.stubrunner.spring.cloud.ribbon; import java.util.ArrayList; import java.util.List; +import com.netflix.loadbalancer.Server; +import com.netflix.loadbalancer.ServerList; + import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; - -import com.netflix.loadbalancer.Server; -import com.netflix.loadbalancer.ServerList; import org.springframework.context.annotation.Role; @Configuration diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonServerList.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonServerList.java index 7933b53a5a..a3bac39208 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonServerList.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/ribbon/StubRunnerRibbonServerList.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -26,6 +26,7 @@ import com.netflix.loadbalancer.Server; import com.netflix.loadbalancer.ServerList; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.cloud.contract.stubrunner.RunningStubs; import org.springframework.cloud.contract.stubrunner.StubConfiguration; import org.springframework.cloud.contract.stubrunner.StubFinder; @@ -33,7 +34,7 @@ import org.springframework.cloud.contract.stubrunner.spring.cloud.StubMapperProp import org.springframework.util.StringUtils; /** - * Stub Runner representation of a server list + * Stub Runner representation of a server list. * * @author Marcin Grzejszczak * @since 1.0.0 diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/zookeeper/StubRunnerSpringCloudZookeeperAutoConfiguration.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/zookeeper/StubRunnerSpringCloudZookeeperAutoConfiguration.java index 29c9e98c06..593d967060 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/zookeeper/StubRunnerSpringCloudZookeeperAutoConfiguration.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/zookeeper/StubRunnerSpringCloudZookeeperAutoConfiguration.java @@ -1,22 +1,23 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.zookeeper; import org.apache.curator.framework.CuratorFramework; + import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -32,7 +33,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** - * Autoconfiguration for registering stubs in a Zookeeper Service discovery + * Autoconfiguration for registering stubs in a Zookeeper Service discovery. * * @author Marcin Grzejszczak * @since 1.0.0 diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/zookeeper/ZookeeperStubsRegistrar.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/zookeeper/ZookeeperStubsRegistrar.java index 5de594771b..4634cd6e9c 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/zookeeper/ZookeeperStubsRegistrar.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/cloud/zookeeper/ZookeeperStubsRegistrar.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.zookeeper; import java.lang.invoke.MethodHandles; @@ -12,6 +28,7 @@ import org.apache.curator.x.discovery.ServiceDiscovery; import org.apache.curator.x.discovery.ServiceDiscoveryBuilder; import org.apache.curator.x.discovery.ServiceInstance; import org.apache.curator.x.discovery.UriSpec; + import org.springframework.cloud.contract.stubrunner.StubConfiguration; import org.springframework.cloud.contract.stubrunner.StubRunning; import org.springframework.cloud.contract.stubrunner.spring.cloud.StubMapperProperties; @@ -20,7 +37,7 @@ import org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryPropertie import org.springframework.util.StringUtils; /** - * Registers all stubs in Zookeeper Service Discovery + * Registers all stubs in Zookeeper Service Discovery. * * @author Marcin Grzejszczak * @since 1.0.0 diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/util/StubsParser.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/util/StubsParser.java index 6cc80a9922..6d21c9465d 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/util/StubsParser.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/util/StubsParser.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -26,9 +26,15 @@ import org.springframework.cloud.contract.stubrunner.StubConfiguration; import org.springframework.util.StringUtils; /** - * Utility to parse string into a list of configuration of stubs + * Utility to parse string into a list of configuration of stubs. + * + * @author Marcin Grzejszczak */ -public class StubsParser { +public final class StubsParser { + + private StubsParser() { + throw new IllegalStateException("Can't instantiate a utility class"); + } /** * The string is expected to be a map with entry called "stubs" that contains a list @@ -46,6 +52,9 @@ public class StubsParser { * Example: * * "a:b,c:d:e" + * @param collection collection of ids + * @param defaultClassifier default classifier to append if one is missing + * @return parsed stub configurations */ public static List fromString(Collection collection, String defaultClassifier) { @@ -58,6 +67,10 @@ public class StubsParser { return stubs; } + /** + * @param notation ivy notation of stubs with ports + * @return mapping of parsed stub configurations to ports on which the stub is running + */ public static Map fromStringWithPort(String notation) { StubSpecification stub = StubSpecification.parse(notation, StubConfiguration.DEFAULT_CLASSIFIER); @@ -67,6 +80,11 @@ public class StubsParser { return Collections.singletonMap(stub.stub, stub.port); } + /** + * @param notation ivy notation of stubs with ports + * @return colon seprated dependency notation with port or empty string if no port is + * present + */ public static String ivyFromStringWithPort(String notation) { StubSpecification stub = StubSpecification.parse(notation, StubConfiguration.DEFAULT_CLASSIFIER); @@ -76,6 +94,10 @@ public class StubsParser { return stub.stub.toColonSeparatedDependencyNotation(); } + /** + * @param id string notation of a stub + * @return {@code true} if a port is there in the identifier + */ public static boolean hasPort(String id) { String[] splitEntry = id.split(":"); try { @@ -93,15 +115,11 @@ public class StubsParser { private final Integer port; - public StubSpecification(StubConfiguration stub, Integer port) { + StubSpecification(StubConfiguration stub, Integer port) { this.stub = stub; this.port = port; } - public boolean hasPort() { - return this.port != null; - } - private static StubSpecification parse(String id, String defaultClassifier) { String[] splitEntry = id.split(":"); Integer port = null; @@ -115,6 +133,10 @@ public class StubsParser { port); } + public boolean hasPort() { + return this.port != null; + } + } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/util/ZipCategory.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/util/ZipCategory.java index 4630da31f4..046e50d7c1 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/util/ZipCategory.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/util/ZipCategory.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -37,13 +37,18 @@ import org.springframework.util.StreamUtils; * Category for {@link File} that adds a method that allows you to unzip a given file to a * specified location * + * @author Marcin Grzejszczak */ -public class ZipCategory { +public final class ZipCategory { + + private ZipCategory() { + throw new IllegalStateException("Can't instantiate a utility class"); + } /** * Unzips this file. If the destination directory is not provided, it will * fall back to this file's parent directory. - * @param self + * @param self file * @param destination (optional), the destination directory where this file's content * will be unzipped to. * @return a {@link Collection} of unzipped {@link File} objects. @@ -52,8 +57,9 @@ public class ZipCategory { checkUnzipDestination(destination); // if destination directory is not given, we'll fall back to the parent directory // of 'self' - if (destination == null) + if (destination == null) { destination = new File(self.getParent()); + } List unzippedFiles = new ArrayList<>(); try (InputStream fileInputStream = Files.newInputStream(self.toPath())) { try (ZipInputStream zipInput = new ZipInputStream(fileInputStream)) { @@ -84,8 +90,9 @@ public class ZipCategory { } private static void checkUnzipDestination(File file) { - if (file != null && !file.isDirectory()) + if (file != null && !file.isDirectory()) { throw new IllegalArgumentException("'destination' has to be a directory."); + } } } diff --git a/spring-cloud-contract-stub-runner/src/main/resources/META-INF/spring.factories b/spring-cloud-contract-stub-runner/src/main/resources/META-INF/spring.factories index f8e3bc096f..f0d56cf795 100644 --- a/spring-cloud-contract-stub-runner/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-contract-stub-runner/src/main/resources/META-INF/spring.factories @@ -10,7 +10,6 @@ org.springframework.cloud.contract.stubrunner.spring.cloud.eureka.StubRunnerSpri org.springframework.cloud.contract.stubrunner.spring.cloud.consul.StubRunnerSpringCloudConsulAutoConfiguration,\ org.springframework.cloud.contract.stubrunner.messaging.StubRunnerStreamsIntegrationAutoConfiguration,\ org.springframework.cloud.contract.stubrunner.messaging.camel.StubRunnerCamelConfiguration - # Test Execution Listeners org.springframework.test.context.TestExecutionListener=\ -org.springframework.cloud.contract.stubrunner.provider.wiremock.StubRunnerWireMockTestExecutionListener \ No newline at end of file +org.springframework.cloud.contract.stubrunner.provider.wiremock.StubRunnerWireMockTestExecutionListener diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/AetherStubDownloaderSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/AetherStubDownloaderSpec.groovy index 1fde65126c..5fd5007be2 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/AetherStubDownloaderSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/AetherStubDownloaderSpec.groovy @@ -1,14 +1,30 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.specto.hoverfly.junit.HoverflyRule import org.eclipse.aether.RepositorySystemSession import org.junit.Rule import org.junit.rules.TemporaryFolder +import spock.lang.Specification +import spock.util.environment.RestoreSystemProperties import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties import org.springframework.util.ResourceUtils -import spock.lang.Specification -import spock.util.environment.RestoreSystemProperties class AetherStubDownloaderSpec extends Specification { diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/AvailablePortScannerSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/AvailablePortScannerSpec.groovy index 7870d31a9c..82a434112b 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/AvailablePortScannerSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/AvailablePortScannerSpec.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 @@ -26,45 +26,45 @@ class AvailablePortScannerSpec extends Specification { def 'should execute given closure with the next available port number'() { given: - AvailablePortScanner portScanner = new AvailablePortScanner(MIN_PORT, MAX_PORT) + AvailablePortScanner portScanner = new AvailablePortScanner(MIN_PORT, MAX_PORT) when: - int usedPort = portScanner.tryToExecuteWithFreePort { int port -> port } + int usedPort = portScanner.tryToExecuteWithFreePort { int port -> port } then: - noExceptionThrown() - usedPort == MIN_PORT || MAX_PORT + noExceptionThrown() + usedPort == MIN_PORT || MAX_PORT } def 'should execute given closure with the available port from specified range'() { given: - AvailablePortScanner portScanner = new AvailablePortScanner(MIN_PORT, MIN_PORT) + AvailablePortScanner portScanner = new AvailablePortScanner(MIN_PORT, MIN_PORT) when: - int usedPort = portScanner.tryToExecuteWithFreePort { int port -> port } + int usedPort = portScanner.tryToExecuteWithFreePort { int port -> port } then: - noExceptionThrown() - usedPort == MIN_PORT + noExceptionThrown() + usedPort == MIN_PORT } def 'should throw exception when improper range has been provided'() { when: - new AvailablePortScanner(minPort, maxPort, MAX_RETRY_COUNT_FOR_NEGATIVE_SCENARIOS) + new AvailablePortScanner(minPort, maxPort, MAX_RETRY_COUNT_FOR_NEGATIVE_SCENARIOS) then: - def ex = thrown(AvailablePortScanner.InvalidPortRange) - ex.message == "Invalid bounds exceptions, min port [$minPort] is greater to max port [$maxPort]" + def ex = thrown(AvailablePortScanner.InvalidPortRange) + ex.message == "Invalid bounds exceptions, min port [$minPort] is greater to max port [$maxPort]" where: - minPort | maxPort - MAX_PORT | MIN_PORT + minPort | maxPort + MAX_PORT | MIN_PORT } def 'should throw exception when there is no available port'() { given: - AvailablePortScanner portScanner = new AvailablePortScanner(MIN_PORT, MAX_PORT, MAX_RETRY_COUNT_FOR_NEGATIVE_SCENARIOS) + AvailablePortScanner portScanner = new AvailablePortScanner(MIN_PORT, MAX_PORT, MAX_RETRY_COUNT_FOR_NEGATIVE_SCENARIOS) when: - portScanner.tryToExecuteWithFreePort { - throw new BindException('Bind exception from closure') - } + portScanner.tryToExecuteWithFreePort { + throw new BindException('Bind exception from closure') + } then: - def ex = thrown(AvailablePortScanner.NoPortAvailableException) - ex.message == "Could not find available port in range $MIN_PORT:$MAX_PORT" + def ex = thrown(AvailablePortScanner.NoPortAvailableException) + ex.message == "Could not find available port in range $MIN_PORT:$MAX_PORT" } } diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/BatchStubRunnerSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/BatchStubRunnerSpec.groovy index 873b711700..3ff86b94a0 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/BatchStubRunnerSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/BatchStubRunnerSpec.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 @@ -26,28 +26,28 @@ class BatchStubRunnerSpec extends Specification { def 'should provide stub URL from enclosed stub runner'() { given: - BatchStubRunner batchStubRunner = new BatchStubRunner(runners()) + BatchStubRunner batchStubRunner = new BatchStubRunner(runners()) expect: - batchStubRunner.findStubUrl(KNOWN_STUB_PATH) == KNOWN_STUB_URL + batchStubRunner.findStubUrl(KNOWN_STUB_PATH) == KNOWN_STUB_URL } def 'should throw an exception for unknown stub path'() { given: - BatchStubRunner batchStubRunner = new BatchStubRunner(runners()) + BatchStubRunner batchStubRunner = new BatchStubRunner(runners()) when: - batchStubRunner.findStubUrl(UNKNOWN_STUB_PATH) + batchStubRunner.findStubUrl(UNKNOWN_STUB_PATH) then: - thrown(StubNotFoundException) + thrown(StubNotFoundException) } def 'should throw exception if trying to execute not available trigger'() { given: - BatchStubRunner batchStubRunner = new BatchStubRunner(runners()) + BatchStubRunner batchStubRunner = new BatchStubRunner(runners()) when: - batchStubRunner.trigger('non existing label') + batchStubRunner.trigger('non existing label') then: - IllegalArgumentException exception = thrown(IllegalArgumentException) - exception.message == "No label with name [non existing label] was found. Here you have the list of dependencies and their labels [Dependency [a:b:c] has labels [foo]]" + IllegalArgumentException exception = thrown(IllegalArgumentException) + exception.message == "No label with name [non existing label] was found. Here you have the list of dependencies and their labels [Dependency [a:b:c] has labels [foo]]" } Collection runners() { @@ -55,7 +55,7 @@ class BatchStubRunnerSpec extends Specification { runner.findStubUrl("group", "knownArtifact") >> KNOWN_STUB_URL runner.findStubUrl("group:knownArtifact") >> KNOWN_STUB_URL runner.findStubUrl("group:unknownArtifact") >> { throw new StubNotFoundException(UNKNOWN_STUB_PATH) } - runner.labels() >> ['a:b:c' : ['foo']] + runner.labels() >> ['a:b:c': ['foo']] return [runner] } diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/ContractDownloaderSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/ContractDownloaderSpec.groovy index 56b48a9773..cfbd83bd53 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/ContractDownloaderSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/ContractDownloaderSpec.groovy @@ -1,7 +1,25 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.config.ContractVerifierConfigProperties import spock.lang.Specification + +import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties + /** * @author Marcin Grzejszczak */ @@ -10,11 +28,11 @@ class ContractDownloaderSpec extends Specification { StubDownloader stubDownloader = Stub() StubConfiguration stubConfiguration = new StubConfiguration('') - File file = new File(File.separator + ['some','path','to','somewhere'].join(File.separator)) + File file = new File(File.separator + ['some', 'path', 'to', 'somewhere'].join(File.separator)) def 'should set inclusion pattern on config when path pattern was explicitly provided with a separator at the beginning'() { given: - String contractPath = File.separator + ['a','b','c','d'].join(File.separator) + String contractPath = File.separator + ['a', 'b', 'c', 'd'].join(File.separator) ContractDownloader contractDownloader = new ContractDownloader(stubDownloader, stubConfiguration, contractPath, '', '', '') ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties() @@ -31,7 +49,7 @@ class ContractDownloaderSpec extends Specification { def 'should set inclusion pattern on config when path pattern was explicitly provided without a separator at the beginning'() { given: - String contractPath = ['a','b','c','d'].join(File.separator) + String contractPath = ['a', 'b', 'c', 'd'].join(File.separator) ContractDownloader contractDownloader = new ContractDownloader(stubDownloader, stubConfiguration, contractPath, '', '', '') ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties() diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/GitStubDownloaderPropertiesSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/GitStubDownloaderPropertiesSpec.groovy index 253a47beb5..3613d5cc50 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/GitStubDownloaderPropertiesSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/GitStubDownloaderPropertiesSpec.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/RunningStubsSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/RunningStubsSpec.groovy index 23a8824693..c2e6150c5f 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/RunningStubsSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/RunningStubsSpec.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 @@ -22,7 +22,7 @@ import spock.lang.Specification * @author Marcin Grzejszczak */ class RunningStubsSpec extends Specification { - RunningStubs runningStubs = new RunningStubs([(new StubConfiguration('group', 'artifact', 'version', 'classifier')) : 100]) + RunningStubs runningStubs = new RunningStubs([(new StubConfiguration('group', 'artifact', 'version', 'classifier')): 100]) def "should get port by group and artifact id"() { expect: diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubConfigurationSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubConfigurationSpec.groovy index 0902f52d2a..e8907635b3 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubConfigurationSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubConfigurationSpec.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRepositorySpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRepositorySpec.groovy index 483f9ba7d2..91e82b468b 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRepositorySpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRepositorySpec.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 @@ -24,43 +24,43 @@ class StubRepositorySpec extends Specification { def 'should retrieve all descriptors for given project'() { given: - StubRepository repository = new StubRepository(REPOSITORY_LOCATION, - [], new StubRunnerOptionsBuilder().build()) - int expectedDescriptorsSize = 8 + StubRepository repository = new StubRepository(REPOSITORY_LOCATION, + [], new StubRunnerOptionsBuilder().build()) + int expectedDescriptorsSize = 8 when: - List descriptors = repository.getStubs() + List descriptors = repository.getStubs() then: - descriptors.size() == expectedDescriptorsSize + descriptors.size() == expectedDescriptorsSize } def 'should return empty list if files are missing'() { given: - StubRepository repository = new StubRepository(new File('src/test/resources/emptyrepo'), - [], new StubRunnerOptionsBuilder().build()) + StubRepository repository = new StubRepository(new File('src/test/resources/emptyrepo'), + [], new StubRunnerOptionsBuilder().build()) when: - List descriptors = repository.getStubs() + List descriptors = repository.getStubs() then: - descriptors.empty + descriptors.empty } def 'should throw an exception if directory with mappings is missing'() { when: - new StubRepository(new File('src/test/resources/nonexistingrepo'), [], - new StubRunnerOptionsBuilder().build()) + new StubRepository(new File('src/test/resources/nonexistingrepo'), [], + new StubRunnerOptionsBuilder().build()) then: - thrown(IllegalArgumentException) + thrown(IllegalArgumentException) } def 'should retrieve only those mappings that contain the consumer name'() { given: - StubRepository repository = new StubRepository(REPOSITORY_LOCATION, - [], new StubRunnerOptionsBuilder() - .withStubPerConsumer(true) - .withConsumerName("ping").build()) - int expectedDescriptorsSize = 1 + StubRepository repository = new StubRepository(REPOSITORY_LOCATION, + [], new StubRunnerOptionsBuilder() + .withStubPerConsumer(true) + .withConsumerName("ping").build()) + int expectedDescriptorsSize = 1 when: - List descriptors = repository.stubs + List descriptors = repository.stubs then: - descriptors.size() == expectedDescriptorsSize + descriptors.size() == expectedDescriptorsSize } } diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerExecutorSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerExecutorSpec.groovy index 1412c738ba..cd5ff3baf4 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerExecutorSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerExecutorSpec.groovy @@ -1,30 +1,29 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.json.JsonOutput -import org.springframework.util.SocketUtils - import java.util.concurrent.TimeUnit +import groovy.json.JsonOutput +import spock.lang.Specification + import org.springframework.cloud.contract.stubrunner.util.StubsParser import org.springframework.cloud.contract.verifier.messaging.MessageVerifier - -import spock.lang.Specification +import org.springframework.util.SocketUtils class StubRunnerExecutorSpec extends Specification { @@ -44,47 +43,47 @@ class StubRunnerExecutorSpec extends Specification { def 'should provide URL for given relative path of stub'() { given: - StubRunnerExecutor executor = new StubRunnerExecutor(portScanner) + StubRunnerExecutor executor = new StubRunnerExecutor(portScanner) when: - executor.runStubs(stubRunnerOptions, repository, stub) + executor.runStubs(stubRunnerOptions, repository, stub) then: - URL url = executor.findStubUrl("group", "artifact") - url.port >= MIN_PORT - url.port <= MAX_PORT + URL url = executor.findStubUrl("group", "artifact") + url.port >= MIN_PORT + url.port <= MAX_PORT and: - executor.findAllRunningStubs().isPresent('artifact') - executor.findAllRunningStubs().isPresent('group', 'artifact') - executor.findAllRunningStubs().isPresent('group:artifact') + executor.findAllRunningStubs().isPresent('artifact') + executor.findAllRunningStubs().isPresent('group', 'artifact') + executor.findAllRunningStubs().isPresent('group:artifact') cleanup: - executor.shutdown() + executor.shutdown() } def 'should provide no URL for unknown dependency path'() { given: - StubRunnerExecutor executor = new StubRunnerExecutor(portScanner) + StubRunnerExecutor executor = new StubRunnerExecutor(portScanner) when: - executor.runStubs(stubRunnerOptions, repository, stub) + executor.runStubs(stubRunnerOptions, repository, stub) and: - executor.findStubUrl("unkowngroup", "unknownartifact") + executor.findStubUrl("unkowngroup", "unknownartifact") then: - thrown(StubNotFoundException) + thrown(StubNotFoundException) cleanup: - executor.shutdown() + executor.shutdown() } def 'should start a stub on a given port'() { given: - int port = SocketUtils.findAvailableTcpPort() - StubRunnerExecutor executor = new StubRunnerExecutor(portScanner) - stubRunnerOptions = new StubRunnerOptionsBuilder(stubIdsToPortMapping: - stubIdsWithPortsFromString("group:artifact:${port},someotherartifact:${SocketUtils.findAvailableTcpPort()}")) - .build() + int port = SocketUtils.findAvailableTcpPort() + StubRunnerExecutor executor = new StubRunnerExecutor(portScanner) + stubRunnerOptions = new StubRunnerOptionsBuilder(stubIdsToPortMapping: + stubIdsWithPortsFromString("group:artifact:${port},someotherartifact:${SocketUtils.findAvailableTcpPort()}")) + .build() when: - executor.runStubs(stubRunnerOptions, repository, stub) + executor.runStubs(stubRunnerOptions, repository, stub) then: - executor.findStubUrl("group", "artifact") == "http://localhost:${port}".toURL() + executor.findStubUrl("group", "artifact") == "http://localhost:${port}".toURL() cleanup: - executor.shutdown() + executor.shutdown() } def 'should ensure that triggered contracts have properly parsed message body when a message is sent'() { @@ -96,7 +95,7 @@ class StubRunnerExecutorSpec extends Specification { then: noExceptionThrown() cleanup: - executor.shutdown() + executor.shutdown() } def 'should match stub with empty classifier'() { @@ -164,7 +163,7 @@ class StubRunnerExecutorSpec extends Specification { !it.toString().contains("cursor") }, { Map map -> println "Headers <${map}>" - !map.values().any { it.toString().contains("cursor")} + !map.values().any { it.toString().contains("cursor") } }, _) cleanup: executor.shutdown() @@ -177,7 +176,7 @@ class StubRunnerExecutorSpec extends Specification { } private class AssertingStubMessages implements MessageVerifier { - + @Override void send(Object message, String destination) { throw new UnsupportedOperationException() diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerFactorySpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerFactorySpec.groovy index c718c4c4a8..1b9ca52e29 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerFactorySpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerFactorySpec.groovy @@ -1,27 +1,27 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.junit.Rule import org.junit.rules.TemporaryFolder -import org.springframework.cloud.contract.verifier.messaging.noop.NoOpStubMessages - import spock.lang.Specification +import org.springframework.cloud.contract.verifier.messaging.noop.NoOpStubMessages + class StubRunnerFactorySpec extends Specification { @Rule @@ -41,13 +41,13 @@ class StubRunnerFactorySpec extends Specification { def "Should download stub definitions many times"() { given: - folder.newFolder("mappings") - 1 * downloader.downloadAndUnpackStubJar(_) >> new AbstractMap.SimpleEntry(new StubConfiguration('a:b'), folder.root) - 1 * downloader.downloadAndUnpackStubJar(_) >> new AbstractMap.SimpleEntry(new StubConfiguration('c:d'), folder.root) + folder.newFolder("mappings") + 1 * downloader.downloadAndUnpackStubJar(_) >> new AbstractMap.SimpleEntry(new StubConfiguration('a:b'), folder.root) + 1 * downloader.downloadAndUnpackStubJar(_) >> new AbstractMap.SimpleEntry(new StubConfiguration('c:d'), folder.root) when: - Collection stubRunners = collectOnlyPresentValues(factory.createStubsFromServiceConfiguration()) + Collection stubRunners = collectOnlyPresentValues(factory.createStubsFromServiceConfiguration()) then: - stubRunners.size() == 2 + stubRunners.size() == 2 } private List collectOnlyPresentValues(Collection stubRunners) { diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilderSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilderSpec.groovy index 71a4c5d4c6..eb557463f1 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilderSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilderSpec.groovy @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,13 +16,13 @@ package org.springframework.cloud.contract.stubrunner -import org.springframework.core.io.ClassPathResource -import org.springframework.core.io.FileSystemResource import spock.lang.Issue import spock.lang.Specification import spock.util.environment.RestoreSystemProperties import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties +import org.springframework.core.io.ClassPathResource +import org.springframework.core.io.FileSystemResource class StubRunnerOptionsBuilderSpec extends Specification { @@ -31,199 +31,199 @@ class StubRunnerOptionsBuilderSpec extends Specification { def shouldReturnURIOfAResourceFromString() { given: - builder.withStubRepositoryRoot("classpath:/logback.xml") + builder.withStubRepositoryRoot("classpath:/logback.xml") when: - StubRunnerOptions options = builder.build() + StubRunnerOptions options = builder.build() then: - options.getStubRepositoryRootAsString().startsWith("file:/") - options.getStubRepositoryRootAsString().endsWith("logback.xml") + options.getStubRepositoryRootAsString().startsWith("file:/") + options.getStubRepositoryRootAsString().endsWith("logback.xml") } def shouldReturnURIOfAResourceFromResource() { given: - builder.withStubRepositoryRoot(new ClassPathResource("logback.xml")) + builder.withStubRepositoryRoot(new ClassPathResource("logback.xml")) when: - StubRunnerOptions options = builder.build() + StubRunnerOptions options = builder.build() then: - options.getStubRepositoryRootAsString().startsWith("file:/") - options.getStubRepositoryRootAsString().endsWith("logback.xml") + options.getStubRepositoryRootAsString().startsWith("file:/") + options.getStubRepositoryRootAsString().endsWith("logback.xml") } def shouldReturnEmptyStringWhenFileNotFound() { given: - builder.withStubRepositoryRoot(new ClassPathResource("fileThatDoesNotExist.xml")) + builder.withStubRepositoryRoot(new ClassPathResource("fileThatDoesNotExist.xml")) when: - StubRunnerOptions options = builder.build() + StubRunnerOptions options = builder.build() then: - options.getStubRepositoryRootAsString() == "" + options.getStubRepositoryRootAsString() == "" } def shouldCreateDependenciesForStub() { given: - builder.withStubs('foo:bar') + builder.withStubs('foo:bar') when: - StubRunnerOptions options = builder.build() + StubRunnerOptions options = builder.build() then: - options.getDependencies().toString() == '[foo:bar:+:stubs]' + options.getDependencies().toString() == '[foo:bar:+:stubs]' } def shouldCreateDependenciesForStubWithSameGroupAndArtifactId() { given: - builder.withStubs('foo:bar:1.0', 'foo:bar:2.0') + builder.withStubs('foo:bar:1.0', 'foo:bar:2.0') when: - StubRunnerOptions options = builder.build() + StubRunnerOptions options = builder.build() then: - options.getDependencies().toString() == '[foo:bar:1.0:stubs, foo:bar:2.0:stubs]' + options.getDependencies().toString() == '[foo:bar:1.0:stubs, foo:bar:2.0:stubs]' } def shouldCreateDependenciesForMultipleStubsWithSameGroup() { given: - builder.withStubs('foo:bar', 'foo:baz', 'foo:baz2') + builder.withStubs('foo:bar', 'foo:baz', 'foo:baz2') when: - StubRunnerOptions options = builder.build() + StubRunnerOptions options = builder.build() then: - options.getDependencies().toString() == '[foo:bar:+:stubs, foo:baz:+:stubs, foo:baz2:+:stubs]' + options.getDependencies().toString() == '[foo:bar:+:stubs, foo:baz:+:stubs, foo:baz2:+:stubs]' } def shouldCreateDependenciesForMultipleStubsWithSameArtifactId() { given: - builder.withStubs('bar:foo', 'baz:foo', 'baz2:foo') + builder.withStubs('bar:foo', 'baz:foo', 'baz2:foo') when: - StubRunnerOptions options = builder.build() + StubRunnerOptions options = builder.build() then: - options.getDependencies().toString() == '[bar:foo:+:stubs, baz:foo:+:stubs, baz2:foo:+:stubs]' + options.getDependencies().toString() == '[bar:foo:+:stubs, baz:foo:+:stubs, baz2:foo:+:stubs]' } def shouldCreateDependenciesForCommaSeparatedStubs() { given: - builder.withStubs('foo:bar,bar:foo,foo:baz') + builder.withStubs('foo:bar,bar:foo,foo:baz') when: - StubRunnerOptions options = builder.build() + StubRunnerOptions options = builder.build() then: - options.getDependencies().size() == 3 + options.getDependencies().size() == 3 } def shouldCreateDependenciesForCommaSeparatedStubsWithSameArtifact() { given: - builder.withStubs('bar:foo,baz:foo,baz2:foo') + builder.withStubs('bar:foo,baz:foo,baz2:foo') when: - StubRunnerOptions options = builder.build() + StubRunnerOptions options = builder.build() then: - options.getDependencies().toString() == '[bar:foo:+:stubs, baz:foo:+:stubs, baz2:foo:+:stubs]' + options.getDependencies().toString() == '[bar:foo:+:stubs, baz:foo:+:stubs, baz2:foo:+:stubs]' } def shouldMapStubsWithPort() { given: - builder.withStubs('foo:bar:8080') + builder.withStubs('foo:bar:8080') when: - StubRunnerOptions options = builder.build() + StubRunnerOptions options = builder.build() then: - options.getStubIdsToPortMapping().toString() == '[foo:bar:+:stubs:8080]' + options.getStubIdsToPortMapping().toString() == '[foo:bar:+:stubs:8080]' } def shouldCreateDependenciesWithVersion() { given: - builder.withStubs('foo:1.2.3:bar') + builder.withStubs('foo:1.2.3:bar') when: - StubRunnerOptions options = builder.build() + StubRunnerOptions options = builder.build() then: - options.getDependencies().toString() == '[foo:1.2.3:bar:stubs]' + options.getDependencies().toString() == '[foo:1.2.3:bar:stubs]' } def shouldCreateDependenciesWithClassifier() { given: - builder.withStubs('foo:bar').withStubsClassifier('xxx') + builder.withStubs('foo:bar').withStubsClassifier('xxx') when: - StubRunnerOptions options = builder.build() + StubRunnerOptions options = builder.build() then: - options.getDependencies().toString() == '[foo:bar:+:xxx]' + options.getDependencies().toString() == '[foo:bar:+:xxx]' } @Issue("#176") def shouldCreateDependenciesWithEmptyPort() { given: - builder.withStubs('groupId:artifactId:version:classifier:') + builder.withStubs('groupId:artifactId:version:classifier:') when: - StubRunnerOptions options = builder.build() + StubRunnerOptions options = builder.build() then: - options.getDependencies().toString() == '[groupId:artifactId:version:classifier]' + options.getDependencies().toString() == '[groupId:artifactId:version:classifier]' } @Issue("#210") def shouldCreateDependenciesWithVersionRange() { given: - builder.withStubs('groupId:artifactId:[,0.0.1]:classifier','groupId2:artifactId2:[,0.0.2]:classifier2') + builder.withStubs('groupId:artifactId:[,0.0.1]:classifier', 'groupId2:artifactId2:[,0.0.2]:classifier2') when: - StubRunnerOptions options = builder.build() + StubRunnerOptions options = builder.build() then: - options.getDependencies().toString() == '[groupId:artifactId:[,0.0.1]:classifier, groupId2:artifactId2:[,0.0.2]:classifier2]' + options.getDependencies().toString() == '[groupId:artifactId:[,0.0.1]:classifier, groupId2:artifactId2:[,0.0.2]:classifier2]' } @Issue("#210") def shouldCreateDependenciesWithVersionRangeWhenSingleOneWasPassed() { given: - builder.withStubs('groupId:artifactId:[,0.0.1]:classifier') + builder.withStubs('groupId:artifactId:[,0.0.1]:classifier') when: - StubRunnerOptions options = builder.build() + StubRunnerOptions options = builder.build() then: - options.getDependencies().toString() == '[groupId:artifactId:[,0.0.1]:classifier]' + options.getDependencies().toString() == '[groupId:artifactId:[,0.0.1]:classifier]' } @Issue("#210") def shouldCreateDependenciesWithVersionRangeWhenManyWerePassedInASingleLine() { given: - builder.withStubs('groupId:artifactId:[,0.0.1]:classifier,groupId2:artifactId2:[,0.0.2]:classifier2') + builder.withStubs('groupId:artifactId:[,0.0.1]:classifier,groupId2:artifactId2:[,0.0.2]:classifier2') when: - StubRunnerOptions options = builder.build() + StubRunnerOptions options = builder.build() then: - options.getDependencies().toString() == '[groupId2:artifactId2:[,0.0.2]:classifier2, groupId:artifactId:[,0.0.1]:classifier]' + options.getDependencies().toString() == '[groupId2:artifactId2:[,0.0.2]:classifier2, groupId:artifactId:[,0.0.1]:classifier]' } @Issue("#466") diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerPropertyUtilsSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerPropertyUtilsSpec.groovy index c5ee4d3a42..bcb50d4f71 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerPropertyUtilsSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerPropertyUtilsSpec.groovy @@ -107,7 +107,7 @@ class StubRunnerPropertyUtilsSpec extends Specification { "foo.bar-baz" | [:] | "ab" | "bc" | true "foo.bar-baz" | [:] | "" | "bc" | true "foo.bar-baz" | null | "" | "bc" | true - "foo.bar-baz" | null | null | null | false + "foo.bar-baz" | null | null | null | false } def cleanupSpec() { diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerSpec.groovy index a97c86fcfe..44cbd91e12 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerSpec.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 @@ -26,28 +26,28 @@ class StubRunnerSpec extends Specification { def 'should provide stub URL for provided groupid and artifactId'() { given: - Arguments args = argumentsWithProjectDefinition() - StubRunner runner = new StubRunner(args.stubRunnerOptions, - args.repositoryPath, args.stub) + Arguments args = argumentsWithProjectDefinition() + StubRunner runner = new StubRunner(args.stubRunnerOptions, + args.repositoryPath, args.stub) when: - runner.runStubs() + runner.runStubs() then: - runner.findStubUrl("groupId", "artifactId") == EXPECTED_STUB_URL + runner.findStubUrl("groupId", "artifactId") == EXPECTED_STUB_URL cleanup: - runner.close() + runner.close() } def 'should provide stub URL if only artifactId was passed'() { given: - Arguments args = argumentsWithProjectDefinition() - StubRunner runner = new StubRunner(args.stubRunnerOptions, - args.repositoryPath, args.stub) + Arguments args = argumentsWithProjectDefinition() + StubRunner runner = new StubRunner(args.stubRunnerOptions, + args.repositoryPath, args.stub) when: - runner.runStubs() + runner.runStubs() then: - runner.findStubUrl(null, "artifactId") == EXPECTED_STUB_URL + runner.findStubUrl(null, "artifactId") == EXPECTED_STUB_URL cleanup: - runner.close() + runner.close() } Arguments argumentsWithProjectDefinition() { diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubServerSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubServerSpec.groovy index 015d70d698..2e4ce98279 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubServerSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubServerSpec.groovy @@ -1,24 +1,25 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.stubrunner.provider.wiremock.WireMockHttpServerStub import spock.lang.Specification +import org.springframework.cloud.contract.stubrunner.provider.wiremock.WireMockHttpServerStub + class StubServerSpec extends Specification { static final int STUB_SERVER_PORT = 12180 static final URL EXPECTED_URL = new URL("http://localhost:$STUB_SERVER_PORT") @@ -28,25 +29,25 @@ class StubServerSpec extends Specification { def 'should register stub mappings upon server start'() { given: - List mappingDescriptors = new StubRepository(repository).getStubs() - StubServer pingStubServer = new StubServer(stubConfiguration, mappingDescriptors, [], - new WireMockHttpServerStub()).start(STUB_SERVER_PORT) + List mappingDescriptors = new StubRepository(repository).getStubs() + StubServer pingStubServer = new StubServer(stubConfiguration, mappingDescriptors, [], + new WireMockHttpServerStub()).start(STUB_SERVER_PORT) when: - pingStubServer.start() + pingStubServer.start() then: - "http://localhost:$pingStubServer.port/bye".toURL().text == 'Goodbye world!' - pingStubServer.stop() + "http://localhost:$pingStubServer.port/bye".toURL().text == 'Goodbye world!' + pingStubServer.stop() } def 'should provide stub server URL'() { given: - List mappingDescriptors = new StubRepository(repository).getStubs() - StubServer pingStubServer = new StubServer(stubConfiguration, mappingDescriptors, [], - new WireMockHttpServerStub()).start(STUB_SERVER_PORT) + List mappingDescriptors = new StubRepository(repository).getStubs() + StubServer pingStubServer = new StubServer(stubConfiguration, mappingDescriptors, [], + new WireMockHttpServerStub()).start(STUB_SERVER_PORT) when: - pingStubServer.start() + pingStubServer.start() then: - pingStubServer.stubUrl == EXPECTED_URL - pingStubServer.stop() + pingStubServer.stubUrl == EXPECTED_URL + pingStubServer.stop() } } diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleCustomMsgVerifierSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleCustomMsgVerifierSpec.groovy index 70a46d7d58..6f91c25bdc 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleCustomMsgVerifierSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleCustomMsgVerifierSpec.groovy @@ -1,31 +1,31 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.util.concurrent.TimeUnit + import org.junit.AfterClass import org.junit.BeforeClass import org.junit.ClassRule - -import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties -import org.springframework.cloud.contract.verifier.messaging.MessageVerifier import spock.lang.Shared import spock.lang.Specification -import java.util.concurrent.TimeUnit +import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties +import org.springframework.cloud.contract.verifier.messaging.MessageVerifier /** * @author Marcin Grzejszczak @@ -39,7 +39,9 @@ class StubRunnerRuleCustomMsgVerifierSpec extends Specification { System.clearProperty("stubrunner.classifier") } - @ClassRule @Shared StubRunnerRule rule = new StubRunnerRule() + @ClassRule + @Shared + StubRunnerRule rule = new StubRunnerRule() .stubsMode(StubRunnerProperties.StubsMode.REMOTE) .repoRoot(StubRunnerRuleCustomMsgVerifierSpec.getResource("/m2repo/repository").toURI().toString()) .downloadStub("org.springframework.cloud.contract.verifier.stubs", "bootService") diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleCustomPortJUnitTest.java b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleCustomPortJUnitTest.java index 2d09fbd932..7b4653142e 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleCustomPortJUnitTest.java +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleCustomPortJUnitTest.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -35,54 +35,71 @@ import static org.assertj.core.api.BDDAssertions.then; */ public class StubRunnerRuleCustomPortJUnitTest { + // tag::classrule_with_port[] + @ClassRule + public static StubRunnerRule rule = new StubRunnerRule().repoRoot(repoRoot()) + .stubsMode(StubRunnerProperties.StubsMode.REMOTE) + .downloadStub("org.springframework.cloud.contract.verifier.stubs", + "loanIssuance") + .withPort(12345).downloadStub( + "org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer:12346"); + @BeforeClass @AfterClass public static void setupProps() { - System.clearProperty("stubrunner.repository.root"); - System.clearProperty("stubrunner.classifier"); + System.clearProperty("stubrunner.repository.root"); + System.clearProperty("stubrunner.classifier"); } - // tag::classrule_with_port[] - @ClassRule public static StubRunnerRule rule = new StubRunnerRule() - .repoRoot(repoRoot()) - .stubsMode(StubRunnerProperties.StubsMode.REMOTE) - .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: - then(rule.findAllRunningStubs().isPresent("loanIssuance")).isTrue(); - then(rule.findAllRunningStubs().isPresent("org.springframework.cloud.contract.verifier.stubs", "fraudDetectionServer")).isTrue(); - 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() { + private static String repoRoot() { try { - return StubRunnerRuleCustomPortJUnitTest.class.getResource("/m2repo/repository/").toURI().toString(); - } catch (Exception e) { + return StubRunnerRuleCustomPortJUnitTest.class + .getResource("/m2repo/repository/").toURI().toString(); + } + catch (Exception e) { return ""; } } + @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: + then(rule.findAllRunningStubs().isPresent("loanIssuance")).isTrue(); + then(rule.findAllRunningStubs().isPresent( + "org.springframework.cloud.contract.verifier.stubs", + "fraudDetectionServer")).isTrue(); + 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 String httpGet(String url) throws Exception { - try(InputStream stream = URI.create(url).toURL().openStream()) { + try (InputStream stream = URI.create(url).toURL().openStream()) { return StreamUtils.copyToString(stream, Charset.forName("UTF-8")); } } + } diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleExceptionThrowingSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleExceptionThrowingSpec.groovy index d3d23176cf..7e2290874f 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleExceptionThrowingSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleExceptionThrowingSpec.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 @@ -36,7 +36,9 @@ class StubRunnerRuleExceptionThrowingSpec extends Specification { System.clearProperty("stubrunner.classifier") } - @ClassRule @Shared StubRunnerRule rule = new StubRunnerRule() + @ClassRule + @Shared + StubRunnerRule rule = new StubRunnerRule() .stubsMode(StubRunnerProperties.StubsMode.REMOTE) .repoRoot(StubRunnerRuleExceptionThrowingSpec.getResource("/m2repo/repository").toURI().toString()) .downloadStub("org.springframework.cloud.contract.verifier.stubs", "bootService") diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleJUnitTest.java b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleJUnitTest.java index 6ca8e1c192..7a819f169f 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleJUnitTest.java +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleJUnitTest.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -35,50 +35,66 @@ import static org.assertj.core.api.BDDAssertions.then; */ public class StubRunnerRuleJUnitTest { + // tag::classrule[] + @ClassRule + public static StubRunnerRule rule = new StubRunnerRule().repoRoot(repoRoot()) + .stubsMode(StubRunnerProperties.StubsMode.REMOTE) + .downloadStub("org.springframework.cloud.contract.verifier.stubs", + "loanIssuance") + .downloadStub( + "org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer"); + @BeforeClass @AfterClass public static void setupProps() { - System.clearProperty("stubrunner.repository.root"); - System.clearProperty("stubrunner.classifier"); + System.clearProperty("stubrunner.repository.root"); + System.clearProperty("stubrunner.classifier"); } - // tag::classrule[] - @ClassRule public static StubRunnerRule rule = new StubRunnerRule() - .repoRoot(repoRoot()) - .stubsMode(StubRunnerProperties.StubsMode.REMOTE) - .downloadStub("org.springframework.cloud.contract.verifier.stubs", "loanIssuance") - .downloadStub("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer"); // end::classrule[] + private static String repoRoot() { + try { + return StubRunnerRuleJUnitTest.class.getResource("/m2repo/repository/") + .toURI().toString(); + } + catch (Exception e) { + return ""; + } + } + // end::test[] + // 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(); + 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: - then(rule.findAllRunningStubs().isPresent("loanIssuance")).isTrue(); - then(rule.findAllRunningStubs().isPresent("org.springframework.cloud.contract.verifier.stubs", "fraudDetectionServer")).isTrue(); - then(rule.findAllRunningStubs().isPresent("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isTrue(); + then(rule.findAllRunningStubs().isPresent("loanIssuance")).isTrue(); + then(rule.findAllRunningStubs().isPresent( + "org.springframework.cloud.contract.verifier.stubs", + "fraudDetectionServer")).isTrue(); + 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 ""; - } + then(httpGet(rule.findStubUrl("loanIssuance").toString() + "/name")) + .isEqualTo("loanIssuance"); + then(httpGet(rule.findStubUrl("fraudDetectionServer").toString() + "/name")) + .isEqualTo("fraudDetectionServer"); } private String httpGet(String url) throws Exception { - try(InputStream stream = URI.create(url).toURL().openStream()) { + try (InputStream stream = URI.create(url).toURL().openStream()) { return StreamUtils.copyToString(stream, Charset.forName("UTF-8")); } } + } diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleSpec.groovy index 4fd1fb970f..89765e0396 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleSpec.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 @@ -37,7 +37,9 @@ class StubRunnerRuleSpec extends Specification { } // tag::classrule[] - @ClassRule @Shared StubRunnerRule rule = new StubRunnerRule() + @ClassRule + @Shared + StubRunnerRule rule = new StubRunnerRule() .stubsMode(StubRunnerProperties.StubsMode.REMOTE) .repoRoot(StubRunnerRuleSpec.getResource("/m2repo/repository").toURI().toString()) .downloadStub("org.springframework.cloud.contract.verifier.stubs", "loanIssuance") diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelPredicateSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelPredicateSpec.groovy index 352eaea8c9..867aea46a6 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelPredicateSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/StubRunnerCamelPredicateSpec.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.Exchange @@ -5,9 +21,9 @@ import org.apache.camel.Message import org.apache.camel.impl.DefaultCamelContext import org.apache.camel.impl.DefaultExchange import org.apache.camel.impl.DefaultMessage +import spock.lang.Specification import org.springframework.cloud.contract.spec.Contract -import spock.lang.Specification /** * @author Marcin Grzejszczak @@ -30,8 +46,8 @@ class StubRunnerCamelPredicateSpec extends Specification { and: StubRunnerCamelPredicate predicate = new StubRunnerCamelPredicate([dsl]) exchange.in = message - message.headers = [ - foo: "non matching stuff" + message.headers = [ + foo: "non matching stuff" ] expect: !predicate.matches(exchange) @@ -155,7 +171,7 @@ class StubRunnerCamelPredicateSpec extends Specification { StubRunnerCamelPredicate predicate = new StubRunnerCamelPredicate([dsl]) exchange.in = message message.headers = [ - foo: 123, + foo : 123, contentType: "application/octet-stream" ] message.body = StubRunnerCamelPredicate.getResource("/request.pdf").bytes @@ -179,7 +195,7 @@ class StubRunnerCamelPredicateSpec extends Specification { StubRunnerCamelPredicate predicate = new StubRunnerCamelPredicate([dsl]) exchange.in = message message.headers = [ - foo: 123, + foo : 123, contentType: "application/octet-stream" ] message.body = "hello world" diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationMessageSelectorSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationMessageSelectorSpec.groovy index 896ceda7f7..4750972ae8 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationMessageSelectorSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/StubRunnerIntegrationMessageSelectorSpec.groovy @@ -1,29 +1,32 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 spock.lang.Specification + import org.springframework.cloud.contract.spec.Contract import org.springframework.messaging.Message -import spock.lang.Specification + /** * @author Marcin Grzejszczak */ class StubRunnerIntegrationMessageSelectorSpec extends Specification { Message message = Mock(Message) - + def "should return false if headers don't match"() { given: Contract dsl = Contract.make { @@ -108,7 +111,7 @@ class StubRunnerIntegrationMessageSelectorSpec extends Specification { and: StubRunnerIntegrationMessageSelector predicate = new StubRunnerIntegrationMessageSelector(dsl) message.headers >> [ - foo: 123, + foo : 123, contentType: "application/octet-stream" ] message.payload >> StubRunnerIntegrationMessageSelector.getResource("/request.pdf").bytes @@ -131,7 +134,7 @@ class StubRunnerIntegrationMessageSelectorSpec extends Specification { and: StubRunnerIntegrationMessageSelector predicate = new StubRunnerIntegrationMessageSelector(dsl) message.headers >> [ - foo: 123, + foo : 123, contentType: "application/octet-stream" ] message.payload >> "hello world" @@ -148,7 +151,7 @@ class StubRunnerIntegrationMessageSelectorSpec extends Specification { header("foo", 123) } messageBody(foo: $(c(regex("[0-9]{3}")), p(123))) - + } } and: diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamMessageSelectorSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamMessageSelectorSpec.groovy index 4050a32890..f29ce8135f 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamMessageSelectorSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StubRunnerStreamMessageSelectorSpec.groovy @@ -1,24 +1,27 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 spock.lang.Specification + import org.springframework.cloud.contract.spec.Contract import org.springframework.http.MediaType import org.springframework.messaging.Message -import spock.lang.Specification + /** * @author Marcin Grzejszczak */ @@ -111,10 +114,10 @@ class StubRunnerStreamMessageSelectorSpec extends Specification { and: StubRunnerStreamMessageSelector predicate = new StubRunnerStreamMessageSelector(dsl) message.headers >> [ - foo: 123, - bar: "bar", + foo : 123, + bar : "bar", contentType: MediaType.APPLICATION_JSON_UTF8, - regex: 234 + regex : 234 ] message.payload >> [ foo: 123 @@ -138,7 +141,7 @@ class StubRunnerStreamMessageSelectorSpec extends Specification { and: StubRunnerStreamMessageSelector predicate = new StubRunnerStreamMessageSelector(dsl) message.headers >> [ - foo: 123, + foo : 123, contentType: "text/plain" ] message.payload >> "123" @@ -161,7 +164,7 @@ class StubRunnerStreamMessageSelectorSpec extends Specification { and: StubRunnerStreamMessageSelector predicate = new StubRunnerStreamMessageSelector(dsl) message.headers >> [ - foo: 123, + foo : 123, contentType: "application/octet-stream" ] message.payload >> StubRunnerStreamMessageSelectorSpec.getResource("/request.pdf").bytes @@ -184,7 +187,7 @@ class StubRunnerStreamMessageSelectorSpec extends Specification { and: StubRunnerStreamMessageSelector predicate = new StubRunnerStreamMessageSelector(dsl) message.headers >> [ - foo: 123, + foo : 123, contentType: "application/octet-stream" ] message.payload >> "hello world" diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/provider/wiremock/TestWireMockExtensions.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/provider/wiremock/TestWireMockExtensions.groovy index a62b35c33b..26eeaba3c4 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/provider/wiremock/TestWireMockExtensions.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/provider/wiremock/TestWireMockExtensions.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.provider.wiremock import com.github.tomakehurst.wiremock.common.FileSource @@ -10,6 +26,7 @@ import com.github.tomakehurst.wiremock.http.Response import org.springframework.cloud.contract.verifier.dsl.wiremock.DefaultResponseTransformer import org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockExtensions + /** * Extension that registers the default response transformer and a custom one too */ diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/provider/wiremock/WireMockHttpServerStubSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/provider/wiremock/WireMockHttpServerStubSpec.groovy index 82e8eccdee..eccce00489 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/provider/wiremock/WireMockHttpServerStubSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/provider/wiremock/WireMockHttpServerStubSpec.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.provider.wiremock @@ -29,7 +29,8 @@ class WireMockHttpServerStubSpec extends Specification { public static final File MAPPING_DESCRIPTOR = new File('src/test/resources/transformers.json') - @Rule OutputCapture capture = new OutputCapture() + @Rule + OutputCapture capture = new OutputCapture() def 'should describe stub mapping'() { given: @@ -56,19 +57,19 @@ class WireMockHttpServerStubSpec extends Specification { def 'should make WireMock print out logs on INFO'() { given: - WireMockHttpServerStub mappingDescriptor = new WireMockHttpServerStub().start() as WireMockHttpServerStub - mappingDescriptor.registerMappings([ - new File(WireMockHttpServerStubSpec.classLoader.getResource("simple.json").toURI()) - ]) + WireMockHttpServerStub mappingDescriptor = new WireMockHttpServerStub().start() as WireMockHttpServerStub + mappingDescriptor.registerMappings([ + new File(WireMockHttpServerStubSpec.classLoader.getResource("simple.json").toURI()) + ]) when: - String response = new TestRestTemplate().getForObject("http://localhost:${mappingDescriptor.port()}/foobar", String) + String response = new TestRestTemplate().getForObject("http://localhost:${mappingDescriptor.port()}/foobar", String) then: - response == "foo" - capture.toString().contains("Matched response definition") + response == "foo" + capture.toString().contains("Matched response definition") cleanup: - mappingDescriptor?.stop() + mappingDescriptor?.stop() } } diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/server/StubRunnerBootSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/server/StubRunnerBootSpec.groovy index bcb2648845..06ae019069 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/server/StubRunnerBootSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/server/StubRunnerBootSpec.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.server @@ -26,6 +26,7 @@ import org.springframework.boot.test.context.SpringBootTest import org.springframework.cloud.contract.stubrunner.StubRunning import org.springframework.test.context.ActiveProfiles import org.springframework.test.context.ContextConfiguration + /** * @author Marcin Grzejszczak */ @@ -35,7 +36,8 @@ import org.springframework.test.context.ContextConfiguration @ActiveProfiles("test") class StubRunnerBootSpec extends Specification { - @Autowired StubRunning stubRunning + @Autowired + StubRunning stubRunning def setup() { RestAssuredMockMvc.standaloneSetup(new HttpStubsController(stubRunning), @@ -76,7 +78,7 @@ class StubRunnerBootSpec extends Specification { String response = RestAssuredMockMvc.get('/triggers').body.asString() then: def root = new JsonSlurper().parseText(response) - root.'org.springframework.cloud.contract.verifier.stubs:bootService:0.0.1-SNAPSHOT:stubs'?.containsAll(["delete_book","return_book_1","return_book_2"]) + root.'org.springframework.cloud.contract.verifier.stubs:bootService:0.0.1-SNAPSHOT:stubs'?.containsAll(["delete_book", "return_book_1", "return_book_2"]) } def 'should trigger a messaging label'() { diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/serverexamples/StubRunnerBootConsulExample.java b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/serverexamples/StubRunnerBootConsulExample.java index 6ffcd4392b..946063d7bf 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/serverexamples/StubRunnerBootConsulExample.java +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/serverexamples/StubRunnerBootConsulExample.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.serverexamples; @@ -37,17 +37,16 @@ public class StubRunnerBootConsulExample { } /* - --Dstubrunner.repositoryRoot=classpath:m2repo/repository/ --Dstubrunner.cloud.stubbed.discovery.enabled=false --Dstubrunner.ids=org.springframework.cloud.contract.verifier.stubs:loanIssuance,org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer,org.springframework.cloud.contract.verifier.stubs:bootService --Dstubrunner.idsToServiceIds.fraudDetectionServer=someNameThatShouldMapFraudDetectionServer --Dstubrunner.cloud.consul.enabled=true --Dstubrunner.camel.enabled=false --Dspring.cloud.zookeeper.enabled=false --Deureka.client.enabled=false --Dspring.cloud.zookeeper.discovery.enabled=false --Ddebug=true --Dspring.cloud.consul.host=192.168.99.100 - + * + * -Dstubrunner.repositoryRoot=classpath:m2repo/repository/ + * -Dstubrunner.cloud.stubbed.discovery.enabled=false + * -Dstubrunner.ids=org.springframework.cloud.contract.verifier.stubs:loanIssuance,org. + * springframework.cloud.contract.verifier.stubs:fraudDetectionServer,org.springframework. + * cloud.contract.verifier.stubs:bootService + * -Dstubrunner.idsToServiceIds.fraudDetectionServer= + * someNameThatShouldMapFraudDetectionServer -Dstubrunner.cloud.consul.enabled=true + * -Dstubrunner.camel.enabled=false -Dspring.cloud.zookeeper.enabled=false + * -Deureka.client.enabled=false -Dspring.cloud.zookeeper.discovery.enabled=false + * -Ddebug=true -Dspring.cloud.consul.host=192.168.99.100 + * */ diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/serverexamples/StubRunnerBootEurekaExample.java b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/serverexamples/StubRunnerBootEurekaExample.java index 218363542f..9e44ae3713 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/serverexamples/StubRunnerBootEurekaExample.java +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/serverexamples/StubRunnerBootEurekaExample.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.serverexamples; @@ -40,25 +40,25 @@ public class StubRunnerBootEurekaExample { // end::stubrunnereureka[] /* - -// tag::stubrunnereureka_args[] --Dstubrunner.repositoryRoot=http://repo.spring.io/snapshots (1) --Dstubrunner.cloud.stubbed.discovery.enabled=false (2) --Dstubrunner.ids=org.springframework.cloud.contract.verifier.stubs:loanIssuance,org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer,org.springframework.cloud.contract.verifier.stubs:bootService (3) --Dstubrunner.idsToServiceIds.fraudDetectionServer=someNameThatShouldMapFraudDetectionServer (4) - -(1) - we tell Stub Runner where all the stubs reside -(2) - we don't want the default behaviour where the discovery service is stubbed. That's why the stub registration will be picked -(3) - we provide a list of stubs to download -(4) - we provide a list of artifactId to serviceId mapping -// end::stubrunnereureka_args[] - - --Dstubrunner.cloud.eureka.enabled=true --Dstubrunner.repositoryRoot=classpath:m2repo/repository/ --Dstubrunner.camel.enabled=false --Dspring.cloud.zookeeper.enabled=false --Dspring.cloud.zookeeper.discovery.enabled=false --Ddebug=true - + * + * // tag::stubrunnereureka_args[] + * -Dstubrunner.repositoryRoot=http://repo.spring.io/snapshots (1) + * -Dstubrunner.cloud.stubbed.discovery.enabled=false (2) + * -Dstubrunner.ids=org.springframework.cloud.contract.verifier.stubs:loanIssuance,org. + * springframework.cloud.contract.verifier.stubs:fraudDetectionServer,org.springframework. + * cloud.contract.verifier.stubs:bootService (3) + * -Dstubrunner.idsToServiceIds.fraudDetectionServer= + * someNameThatShouldMapFraudDetectionServer (4) + * + * (1) - we tell Stub Runner where all the stubs reside (2) - we don't want the default + * behaviour where the discovery service is stubbed. That's why the stub registration will + * be picked (3) - we provide a list of stubs to download (4) - we provide a list of + * artifactId to serviceId mapping // end::stubrunnereureka_args[] + * + * + * -Dstubrunner.cloud.eureka.enabled=true + * -Dstubrunner.repositoryRoot=classpath:m2repo/repository/ + * -Dstubrunner.camel.enabled=false -Dspring.cloud.zookeeper.enabled=false + * -Dspring.cloud.zookeeper.discovery.enabled=false -Ddebug=true + * */ diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/serverexamples/StubRunnerBootZookeeperExample.java b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/serverexamples/StubRunnerBootZookeeperExample.java index 1e114ef682..e5cf66a5f7 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/serverexamples/StubRunnerBootZookeeperExample.java +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/serverexamples/StubRunnerBootZookeeperExample.java @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.serverexamples; @@ -37,14 +37,15 @@ public class StubRunnerBootZookeeperExample { } /* - --Dstubrunner.ids=org.springframework.cloud.contract.verifier.stubs:loanIssuance,org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer,org.springframework.cloud.contract.verifier.stubs:bootService --Dstubrunner.idsToServiceIds.fraudDetectionServer=someNameThatShouldMapFraudDetectionServer --Dstubrunner.cloud.stubbed.discovery.enabled=false --Dstubrunner.cloud.zookeepr.enabled=true --Dstubrunner.camel.enabled=false --Dstubrunner.repositoryRoot=classpath:m2repo/repository/ --Deureka.client.enabled=false --Ddebug=true - + * + * -Dstubrunner.ids=org.springframework.cloud.contract.verifier.stubs:loanIssuance,org. + * springframework.cloud.contract.verifier.stubs:fraudDetectionServer,org.springframework. + * cloud.contract.verifier.stubs:bootService + * -Dstubrunner.idsToServiceIds.fraudDetectionServer= + * someNameThatShouldMapFraudDetectionServer + * -Dstubrunner.cloud.stubbed.discovery.enabled=false + * -Dstubrunner.cloud.zookeepr.enabled=true -Dstubrunner.camel.enabled=false + * -Dstubrunner.repositoryRoot=classpath:m2repo/repository/ -Deureka.client.enabled=false + * -Ddebug=true + * */ diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/StubRunnerConfigurationSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/StubRunnerConfigurationSpec.groovy index 2f3586b4fe..b6b56ded2a 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/StubRunnerConfigurationSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/StubRunnerConfigurationSpec.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 @@ -47,21 +47,26 @@ import org.springframework.util.SocketUtils // Not necessary if Spring Cloud is used. TODO: make it work without this. // tag::test[] @ContextConfiguration(classes = Config, loader = SpringBootContextLoader) -@SpringBootTest(properties = [" stubrunner.cloud.enabled=false", +@SpringBootTest(properties = [" stubrunner.cloud.enabled=false", 'foo=${stubrunner.runningstubs.fraudDetectionServer.port}', 'fooWithGroup=${stubrunner.runningstubs.org.springframework.cloud.contract.verifier.stubs.fraudDetectionServer.port}']) // tag::annotation[] @AutoConfigureStubRunner(mappingsOutputFolder = "target/outputmappings/", - httpServerStubConfigurer = HttpsForFraudDetection) + httpServerStubConfigurer = HttpsForFraudDetection) // end::annotation[] @ActiveProfiles("test") class StubRunnerConfigurationSpec extends Specification { - @Autowired StubFinder stubFinder - @Autowired Environment environment - @StubRunnerPort("fraudDetectionServer") int fraudDetectionServerPort - @StubRunnerPort("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer") int fraudDetectionServerPortWithGroupId - @Value('${foo}') Integer foo + @Autowired + StubFinder stubFinder + @Autowired + Environment environment + @StubRunnerPort("fraudDetectionServer") + int fraudDetectionServerPort + @StubRunnerPort("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer") + int fraudDetectionServerPortWithGroupId + @Value('${foo}') + Integer foo @BeforeClass @AfterClass @@ -162,4 +167,4 @@ class StubRunnerConfigurationSpec extends Specification { } // end::wireMockHttpServerStubConfigurer[] } -// end::test[] \ No newline at end of file +// end::test[] diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubMapperPropertiesSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubMapperPropertiesSpec.groovy index a85ade9f73..caa695df1f 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubMapperPropertiesSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubMapperPropertiesSpec.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 spock.lang.Specification diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerSpringCloudAutoConfigurationSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerSpringCloudAutoConfigurationSpec.groovy index a6f2a6692a..5571dc5bda 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerSpringCloudAutoConfigurationSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerSpringCloudAutoConfigurationSpec.groovy @@ -1,23 +1,25 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.junit.AfterClass import org.junit.BeforeClass +import spock.lang.Specification + import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.autoconfigure.EnableAutoConfiguration import org.springframework.boot.test.context.SpringBootContextLoader @@ -34,7 +36,7 @@ import org.springframework.context.annotation.Configuration import org.springframework.test.context.ActiveProfiles import org.springframework.test.context.ContextConfiguration import org.springframework.web.client.RestTemplate -import spock.lang.Specification + /** * @author Marcin Grzejszczak */ @@ -44,15 +46,18 @@ import spock.lang.Specification // tag::autoconfigure[] @AutoConfigureStubRunner( ids = ["org.springframework.cloud.contract.verifier.stubs:loanIssuance", - "org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer", - "org.springframework.cloud.contract.verifier.stubs:bootService"], + "org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer", + "org.springframework.cloud.contract.verifier.stubs:bootService"], stubsMode = StubRunnerProperties.StubsMode.REMOTE, repositoryRoot = "classpath:m2repo/repository/") // end::autoconfigure[] class StubRunnerSpringCloudAutoConfigurationSpec extends Specification { - @Autowired StubFinder stubFinder - @Autowired @LoadBalanced RestTemplate restTemplate + @Autowired + StubFinder stubFinder + @Autowired + @LoadBalanced + RestTemplate restTemplate @BeforeClass @AfterClass diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerStubsPerConsumerSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerStubsPerConsumerSpec.groovy index b6c64c3436..aaa2904845 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerStubsPerConsumerSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerStubsPerConsumerSpec.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 @@ -35,6 +35,7 @@ import org.springframework.core.env.Environment import org.springframework.http.ResponseEntity import org.springframework.messaging.Message import org.springframework.test.context.ContextConfiguration + /** * @author Marcin Grzejszczak */ @@ -48,9 +49,12 @@ import org.springframework.test.context.ContextConfiguration class StubRunnerStubsPerConsumerSpec extends Specification { // end::test[] - @Autowired StubFinder stubFinder - @Autowired Environment environment - @Autowired MessageVerifier> messaging + @Autowired + StubFinder stubFinder + @Autowired + Environment environment + @Autowired + MessageVerifier> messaging TestRestTemplate template = new TestRestTemplate() def 'should start http stub servers for bar-consumer only'() { @@ -89,4 +93,4 @@ class StubRunnerStubsPerConsumerSpec extends Specification { @EnableAutoConfiguration @EnableBinding([Sink, Source]) static class Config {} -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerStubsPerConsumerWithConsumerNameSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerStubsPerConsumerWithConsumerNameSpec.groovy index 127e02db5a..d87189225b 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerStubsPerConsumerWithConsumerNameSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerStubsPerConsumerWithConsumerNameSpec.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 @@ -35,6 +35,7 @@ import org.springframework.core.env.Environment import org.springframework.http.ResponseEntity import org.springframework.messaging.Message import org.springframework.test.context.ContextConfiguration + /** * @author Marcin Grzejszczak */ @@ -49,9 +50,12 @@ import org.springframework.test.context.ContextConfiguration class StubRunnerStubsPerConsumerWithConsumerNameSpec extends Specification { // end::test[] - @Autowired StubFinder stubFinder - @Autowired Environment environment - @Autowired MessageVerifier> messaging + @Autowired + StubFinder stubFinder + @Autowired + Environment environment + @Autowired + MessageVerifier> messaging TestRestTemplate template = new TestRestTemplate() def 'should start http stub servers for foo-consumer only'() { @@ -90,4 +94,4 @@ class StubRunnerStubsPerConsumerWithConsumerNameSpec extends Specification { @EnableAutoConfiguration @EnableBinding([Sink, Source]) static class Config {} -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/consul/StubRunnerSpringCloudConsulAutoConfigurationSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/consul/StubRunnerSpringCloudConsulAutoConfigurationSpec.groovy index 1a9902ae48..0a68302a49 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/consul/StubRunnerSpringCloudConsulAutoConfigurationSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/consul/StubRunnerSpringCloudConsulAutoConfigurationSpec.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.consul @@ -21,7 +21,6 @@ import com.ecwid.consul.v1.agent.model.NewService import org.junit.AfterClass import org.junit.BeforeClass import org.mockito.ArgumentMatcher -import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties import spock.lang.Specification import org.springframework.beans.factory.annotation.Autowired @@ -29,6 +28,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration import org.springframework.boot.test.context.SpringBootContextLoader import org.springframework.boot.test.context.SpringBootTest import org.springframework.cloud.client.discovery.EnableDiscoveryClient +import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties import org.springframework.context.annotation.Bean @@ -38,6 +38,7 @@ import org.springframework.test.context.ContextConfiguration import static org.mockito.BDDMockito.then import static org.mockito.Matchers.argThat import static org.mockito.Mockito.mock + /** * @author Marcin Grzejszczak */ @@ -51,15 +52,16 @@ import static org.mockito.Mockito.mock "stubrunner.cloud.consul.enabled=true", "stubrunner.cloud.zookeeper.enabled=false", "debug=true"]) -@AutoConfigureStubRunner( ids = +@AutoConfigureStubRunner(ids = ["org.springframework.cloud.contract.verifier.stubs:loanIssuance", - "org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer", - "org.springframework.cloud.contract.verifier.stubs:bootService"], + "org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer", + "org.springframework.cloud.contract.verifier.stubs:bootService"], stubsMode = StubRunnerProperties.StubsMode.REMOTE, repositoryRoot = "classpath:m2repo/repository/") class StubRunnerSpringCloudConsulAutoConfigurationSpec extends Specification { - @Autowired ConsulClient client + @Autowired + ConsulClient client @BeforeClass @AfterClass diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/util/ZipCategorySpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/util/ZipCategorySpec.groovy index 40ed3bca02..d80e90778b 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/util/ZipCategorySpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/util/ZipCategorySpec.groovy @@ -1,39 +1,39 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 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() + File zipFile = new File(ZipCategorySpec.classLoader.getResource('file.zip').toURI()) + File tempDir = File.createTempDir() + tempDir.deleteOnExit() when: - use(ZipCategory) { - zipFile.unzipTo(tempDir) - } + use(ZipCategory) { + zipFile.unzipTo(tempDir) + } then: - tempDir.listFiles().find { - it.name == 'file.txt' - }?.text?.trim() == 'test' + tempDir.listFiles().find { + it.name == 'file.txt' + }?.text?.trim() == 'test' } } diff --git a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/AbstractGitTest.java b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/AbstractGitTest.java index 54e77dc83b..ecc00c99cf 100644 --- a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/AbstractGitTest.java +++ b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/AbstractGitTest.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/ClasspathStubProviderTest.java b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/ClasspathStubProviderTest.java index 8c318b3524..703d481a4d 100644 --- a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/ClasspathStubProviderTest.java +++ b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/ClasspathStubProviderTest.java @@ -1,6 +1,23 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.junit.Test; + import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties; import static org.assertj.core.api.BDDAssertions.then; @@ -19,4 +36,4 @@ public class ClasspathStubProviderTest { then(stubDownloader).isNull(); } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/CompositeStubDownloaderBuilderTests.java b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/CompositeStubDownloaderBuilderTests.java index 244afd435b..0cf07048cd 100644 --- a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/CompositeStubDownloaderBuilderTests.java +++ b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/CompositeStubDownloaderBuilderTests.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 java.io.File; @@ -101,4 +117,4 @@ class SomeStubDownloader implements StubDownloader { return new AbstractMap.SimpleEntry<>(stubConfiguration, new File(".")); } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/ContractProjectUpdaterTest.java b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/ContractProjectUpdaterTest.java index 7aebeab17e..f56a41ae89 100644 --- a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/ContractProjectUpdaterTest.java +++ b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/ContractProjectUpdaterTest.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -37,6 +37,9 @@ import static org.assertj.core.api.BDDAssertions.then; */ public class ContractProjectUpdaterTest extends AbstractGitTest { + @Rule + public OutputCapture outputCapture = new OutputCapture(); + File originalProject; File project; @@ -47,9 +50,6 @@ public class ContractProjectUpdaterTest extends AbstractGitTest { File origin; - @Rule - public OutputCapture outputCapture = new OutputCapture(); - @Before public void setup() throws Exception { GitContractsRepo.CACHED_LOCATIONS.clear(); @@ -85,8 +85,8 @@ public class ContractProjectUpdaterTest extends AbstractGitTest { BDDAssertions.then(new File(this.project, "META-INF/com.example/hello-world/0.0.2/mappings/someMapping.json")) .exists(); - BDDAssertions.then(gitRepo.gitFactory.provider).isNull(); - BDDAssertions.then(outputCapture.toString()) + BDDAssertions.then(this.gitRepo.gitFactory.provider).isNull(); + BDDAssertions.then(this.outputCapture.toString()) .contains("No custom credentials provider will be set"); } @@ -119,7 +119,7 @@ public class ContractProjectUpdaterTest extends AbstractGitTest { BDDAssertions.then(new File(this.project, "META-INF/com.example/hello-world/0.0.2/mappings/someMapping.json")) .exists(); - BDDAssertions.then(outputCapture.toString()).contains( + BDDAssertions.then(this.outputCapture.toString()).contains( "Passed username and password - will set a custom credentials provider"); } @@ -147,7 +147,7 @@ public class ContractProjectUpdaterTest extends AbstractGitTest { BDDAssertions.then(new File(this.project, "META-INF/com.example/hello-world/0.0.2/mappings/someMapping.json")) .exists(); - BDDAssertions.then(outputCapture.toString()).contains( + BDDAssertions.then(this.outputCapture.toString()).contains( "Passed username and password - will set a custom credentials provider"); } @@ -171,4 +171,4 @@ public class ContractProjectUpdaterTest extends AbstractGitTest { .doesNotExist(); } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/GitRepoTests.java b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/GitRepoTests.java index 1606ace92c..0651e16ba8 100644 --- a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/GitRepoTests.java +++ b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/GitRepoTests.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -178,8 +178,8 @@ class ExceptionThrowingJGitFactory extends GitRepo.JGitFactory { class CustomException extends RuntimeException { - public CustomException(String message) { + CustomException(String message) { super(message); } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/GitStubDownloaderTests.java b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/GitStubDownloaderTests.java index 54a0e7961d..2c50e20645 100644 --- a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/GitStubDownloaderTests.java +++ b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/GitStubDownloaderTests.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.cloud.contract.stubrunner; import java.io.File; @@ -24,6 +25,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; + import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties; import org.springframework.util.FileSystemUtils; @@ -109,28 +111,27 @@ public class GitStubDownloaderTests { .build(new StubRunnerOptionsBuilder() .withStubsMode(StubRunnerProperties.StubsMode.REMOTE) .withStubRepositoryRoot("git://" - + file("/git_samples/contract-git/").getAbsolutePath() + "/") + + file("/git_samples/contract-git/").getAbsolutePath() + + "/") .withProperties(props()).build()); Map.Entry entry = stubDownloader - .downloadAndUnpackStubJar( - new StubConfiguration("com.example:beer-api-producer-external:+")); + .downloadAndUnpackStubJar(new StubConfiguration( + "com.example:beer-api-producer-external:+")); then(entry).isNotNull(); then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator + "beer-api-producer-external" + File.separator + "1.0.0.BUILD-SNAPSHOT"); - entry = stubDownloader - .downloadAndUnpackStubJar( - new StubConfiguration("com.example:beer-api-producer-external:latest")); + entry = stubDownloader.downloadAndUnpackStubJar( + new StubConfiguration("com.example:beer-api-producer-external:latest")); then(entry).isNotNull(); then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator + "beer-api-producer-external" + File.separator + "1.0.0.BUILD-SNAPSHOT"); - entry = stubDownloader - .downloadAndUnpackStubJar( - new StubConfiguration("com.example:beer-api-producer-external:LATEST")); + entry = stubDownloader.downloadAndUnpackStubJar( + new StubConfiguration("com.example:beer-api-producer-external:LATEST")); then(entry).isNotNull(); then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator @@ -145,20 +146,20 @@ public class GitStubDownloaderTests { .build(new StubRunnerOptionsBuilder() .withStubsMode(StubRunnerProperties.StubsMode.REMOTE) .withStubRepositoryRoot("git://" - + file("/git_samples/contract-git/").getAbsolutePath() + "/") + + file("/git_samples/contract-git/").getAbsolutePath() + + "/") .withProperties(props()).build()); Map.Entry entry = stubDownloader - .downloadAndUnpackStubJar( - new StubConfiguration("com.example:beer-api-producer-external:release")); + .downloadAndUnpackStubJar(new StubConfiguration( + "com.example:beer-api-producer-external:release")); then(entry).isNotNull(); then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator + "beer-api-producer-external" + File.separator + "1.0.0.RELEASE"); - entry = stubDownloader - .downloadAndUnpackStubJar( - new StubConfiguration("com.example:beer-api-producer-external:RELEASE")); + entry = stubDownloader.downloadAndUnpackStubJar( + new StubConfiguration("com.example:beer-api-producer-external:RELEASE")); then(entry).isNotNull(); then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator @@ -173,28 +174,28 @@ public class GitStubDownloaderTests { .build(new StubRunnerOptionsBuilder() .withStubsMode(StubRunnerProperties.StubsMode.REMOTE) .withStubRepositoryRoot("git://" - + file("/git_samples/contract-predefined-names-git/").getAbsolutePath() + "/") + + file("/git_samples/contract-predefined-names-git/") + .getAbsolutePath() + + "/") .withProperties(props()).build()); Map.Entry entry = stubDownloader - .downloadAndUnpackStubJar( - new StubConfiguration("com.example:beer-api-producer-external:+")); + .downloadAndUnpackStubJar(new StubConfiguration( + "com.example:beer-api-producer-external:+")); then(entry).isNotNull(); then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator + "beer-api-producer-external" + File.separator + "latest"); - entry = stubDownloader - .downloadAndUnpackStubJar( - new StubConfiguration("com.example:beer-api-producer-external:latest")); + entry = stubDownloader.downloadAndUnpackStubJar( + new StubConfiguration("com.example:beer-api-producer-external:latest")); then(entry).isNotNull(); then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator + "beer-api-producer-external" + File.separator + "latest"); - entry = stubDownloader - .downloadAndUnpackStubJar( - new StubConfiguration("com.example:beer-api-producer-external:LATEST")); + entry = stubDownloader.downloadAndUnpackStubJar( + new StubConfiguration("com.example:beer-api-producer-external:LATEST")); then(entry).isNotNull(); then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator @@ -209,20 +210,21 @@ public class GitStubDownloaderTests { .build(new StubRunnerOptionsBuilder() .withStubsMode(StubRunnerProperties.StubsMode.REMOTE) .withStubRepositoryRoot("git://" - + file("/git_samples/contract-predefined-names-git/").getAbsolutePath() + "/") + + file("/git_samples/contract-predefined-names-git/") + .getAbsolutePath() + + "/") .withProperties(props()).build()); Map.Entry entry = stubDownloader - .downloadAndUnpackStubJar( - new StubConfiguration("com.example:beer-api-producer-external:release")); + .downloadAndUnpackStubJar(new StubConfiguration( + "com.example:beer-api-producer-external:release")); then(entry).isNotNull(); then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator + "beer-api-producer-external" + File.separator + "release"); - entry = stubDownloader - .downloadAndUnpackStubJar( - new StubConfiguration("com.example:beer-api-producer-external:RELEASE")); + entry = stubDownloader.downloadAndUnpackStubJar( + new StubConfiguration("com.example:beer-api-producer-external:RELEASE")); then(entry).isNotNull(); then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator @@ -238,7 +240,7 @@ public class GitStubDownloaderTests { .withStubsMode(StubRunnerProperties.StubsMode.REMOTE) .withStubRepositoryRoot("git://" + file("/git_samples/contract-git").getAbsolutePath() - + "/") + + "/") .withProperties(props()).build()); try { diff --git a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/StubDownloaderBuilderProviderTests.java b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/StubDownloaderBuilderProviderTests.java index 4e31b1e47c..0be0689180 100644 --- a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/StubDownloaderBuilderProviderTests.java +++ b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/StubDownloaderBuilderProviderTests.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 java.util.Collections; @@ -27,20 +43,21 @@ public class StubDownloaderBuilderProviderTests { @Test public void should_get_providers_from_factories_default_and_additional_ones() { StubDownloaderBuilderProvider provider = new StubDownloaderBuilderProvider( - Collections.singletonList(one)) { + Collections.singletonList(this.one)) { @Override List defaultStubDownloaderBuilders() { - return Collections.singletonList(two); + return Collections + .singletonList(StubDownloaderBuilderProviderTests.this.two); } }; StubRunnerOptions options = new StubRunnerOptionsBuilder().build(); - provider.get(options, three) + provider.get(options, this.three) .downloadAndUnpackStubJar(new StubConfiguration("a:b:c")); - BDDMockito.then(one).should().build(options); - BDDMockito.then(two).should().build(options); - BDDMockito.then(three).should().build(options); + BDDMockito.then(this.one).should().build(options); + BDDMockito.then(this.two).should().build(options); + BDDMockito.then(this.three).should().build(options); } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/StubRepositoryTest.java b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/StubRepositoryTest.java index f590702bed..6f3f7485e0 100644 --- a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/StubRepositoryTest.java +++ b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/StubRepositoryTest.java @@ -1,13 +1,29 @@ -package org.springframework.cloud.contract.stubrunner; +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.junit.Test; -import org.springframework.cloud.contract.spec.Contract; +package org.springframework.cloud.contract.stubrunner; import java.io.File; import java.util.ArrayList; import java.util.Collection; -import static org.junit.Assert.assertEquals; +import org.assertj.core.api.BDDAssertions; +import org.junit.Test; + +import org.springframework.cloud.contract.spec.Contract; /** * @author Sven Bayer @@ -28,7 +44,7 @@ public class StubRepositoryTest { Collection descriptors = repository.getContracts(); // then: - assertEquals(expectedDescriptorsSize, descriptors.size()); + BDDAssertions.then(descriptors).hasSize(expectedDescriptorsSize); } } diff --git a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/StubRunnerSliceTests.java b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/StubRunnerSliceTests.java index 314972813d..9c7df70582 100644 --- a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/StubRunnerSliceTests.java +++ b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/StubRunnerSliceTests.java @@ -1,23 +1,24 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringBootConfiguration; @@ -59,27 +60,27 @@ public class StubRunnerSliceTests { @Test public void testThatListedStubsAreRunning() { - assertThat(fraudDetectionServerPort).isBetween(10001, 10020); - assertThat(loanIssuancePort).isBetween(10001, 10020); + assertThat(this.fraudDetectionServerPort).isBetween(10001, 10020); + assertThat(this.loanIssuancePort).isBetween(10001, 10020); - assertThat(stubFinder.findStubUrl( + assertThat(this.stubFinder.findStubUrl( "org.springframework.cloud.contract.verifier.stubs", "loanIssuance")) .isNotNull(); - assertThat(stubFinder.findStubUrl("loanIssuance")).isNotNull(); - assertThat(stubFinder.findStubUrl("loanIssuance")).isEqualTo(stubFinder + assertThat(this.stubFinder.findStubUrl("loanIssuance")).isNotNull(); + assertThat(this.stubFinder.findStubUrl("loanIssuance")).isEqualTo(this.stubFinder .findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance")); - assertThat(stubFinder.findStubUrl("loanIssuance")) - .isEqualTo(stubFinder.findStubUrl( + assertThat(this.stubFinder.findStubUrl("loanIssuance")) + .isEqualTo(this.stubFinder.findStubUrl( "org.springframework.cloud.contract.verifier.stubs:loanIssuance")); - assertThat(stubFinder.findStubUrl( + assertThat(this.stubFinder.findStubUrl( "org.springframework.cloud.contract.verifier.stubs:loanIssuance:0.0.1-SNAPSHOT")) - .isEqualTo(stubFinder.findStubUrl( + .isEqualTo(this.stubFinder.findStubUrl( "org.springframework.cloud.contract.verifier.stubs:loanIssuance:0.0.1-SNAPSHOT:stubs")); - assertThat(stubFinder.findStubUrl( + assertThat(this.stubFinder.findStubUrl( "org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")) .isNotNull(); - assertThat(properties.getProperties()).containsEntry("hello", "world") + assertThat(this.properties.getProperties()).containsEntry("hello", "world") .containsEntry("foo", "bar"); } diff --git a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/TestCustomYamlContractConverter.java b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/TestCustomYamlContractConverter.java index 19d01a3da3..1e0a65d051 100644 --- a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/TestCustomYamlContractConverter.java +++ b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/TestCustomYamlContractConverter.java @@ -1,8 +1,20 @@ -package org.springframework.cloud.contract.stubrunner; +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 groovy.lang.Closure; -import org.springframework.cloud.contract.spec.Contract; -import org.springframework.cloud.contract.spec.ContractConverter; +package org.springframework.cloud.contract.stubrunner; import java.io.File; import java.io.IOException; @@ -11,6 +23,11 @@ import java.util.Collection; import java.util.Collections; import java.util.Optional; +import groovy.lang.Closure; + +import org.springframework.cloud.contract.spec.Contract; +import org.springframework.cloud.contract.spec.ContractConverter; + /** * @author Sven Bayer */ @@ -41,4 +58,4 @@ public class TestCustomYamlContractConverter implements ContractConverter { return new Object(); } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/TestUtils.java b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/TestUtils.java index b0a24b2791..51df7d2f93 100644 --- a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/TestUtils.java +++ b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/TestUtils.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -25,7 +25,8 @@ class TestUtils { public static void prepareLocalRepo() throws IOException { prepareLocalRepo("target/test-classes/git_samples/", "contract-git"); - prepareLocalRepo("target/test-classes/git_samples/", "contract-predefined-names-git"); + prepareLocalRepo("target/test-classes/git_samples/", + "contract-predefined-names-git"); } private static void prepareLocalRepo(String buildDir, String repoPath) @@ -40,4 +41,4 @@ class TestUtils { git.renameTo(dotGit); } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerJUnit5ExtensionCustomMessageVerifierTests.java b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerJUnit5ExtensionCustomMessageVerifierTests.java index 34b888f6d5..9e060e887d 100644 --- a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerJUnit5ExtensionCustomMessageVerifierTests.java +++ b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerJUnit5ExtensionCustomMessageVerifierTests.java @@ -1,31 +1,32 @@ /* - * Copyright 2018 the original author or authors. + * Copyright 2018-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.util.Map; +import java.util.concurrent.TimeUnit; + import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; + import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties; import org.springframework.cloud.contract.verifier.messaging.MessageVerifier; -import java.util.Map; -import java.util.concurrent.TimeUnit; - import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -35,62 +36,71 @@ import static org.junit.jupiter.api.Assertions.assertThrows; */ class StubRunnerJUnit5ExtensionCustomMessageVerifierTests { - @BeforeAll - @AfterAll - static void setupProps() { - System.clearProperty("stubrunner.repository.root"); - System.clearProperty("stubrunner.classifier"); - } + // Visible for testing + @RegisterExtension + static StubRunnerExtension stubRunnerExtension = new StubRunnerExtension() + .stubsMode(StubRunnerProperties.StubsMode.REMOTE).repoRoot(repoRoot()) + .downloadStub("org.springframework.cloud.contract.verifier.stubs", + "bootService") + .messageVerifier(new MyMessageVerifier()); - // Visible for testing - @RegisterExtension - static StubRunnerExtension stubRunnerExtension = new StubRunnerExtension() - .stubsMode(StubRunnerProperties.StubsMode.REMOTE) - .repoRoot(repoRoot()) - .downloadStub("org.springframework.cloud.contract.verifier.stubs", "bootService") - .messageVerifier(new MyMessageVerifier()); + @BeforeAll + @AfterAll + static void setupProps() { + System.clearProperty("stubrunner.repository.root"); + System.clearProperty("stubrunner.classifier"); + } - @Test - void should_use_provided_message_verifier_in_junit5_extension() { - IllegalStateException emptyTriggerException = assertThrows(IllegalStateException.class, - () -> stubRunnerExtension.trigger()); - assertThat(emptyTriggerException.getMessage()).contains("Failed to send a message with headers"); - IllegalStateException wrongLabelException = assertThrows(IllegalStateException.class, - () -> stubRunnerExtension.trigger("return_book_1")); - assertThat(wrongLabelException.getMessage()).contains("Failed to send a message with headers"); - IllegalStateException wrongLabelWithIvyNotation = assertThrows(IllegalStateException.class, - () -> stubRunnerExtension.trigger("bootService", "return_book_1")); - assertThat(wrongLabelWithIvyNotation.getMessage()).contains("Failed to send a message with headers"); - } + private static String repoRoot() { + try { + return StubRunnerRuleCustomPortJUnitTest.class + .getResource("/m2repo/repository/").toURI().toString(); + } + catch (Exception e) { + return ""; + } + } - static class MyMessageVerifier implements MessageVerifier { + @Test + void should_use_provided_message_verifier_in_junit5_extension() { + IllegalStateException emptyTriggerException = assertThrows( + IllegalStateException.class, () -> stubRunnerExtension.trigger()); + assertThat(emptyTriggerException.getMessage()) + .contains("Failed to send a message with headers"); + IllegalStateException wrongLabelException = assertThrows( + IllegalStateException.class, + () -> stubRunnerExtension.trigger("return_book_1")); + assertThat(wrongLabelException.getMessage()) + .contains("Failed to send a message with headers"); + IllegalStateException wrongLabelWithIvyNotation = assertThrows( + IllegalStateException.class, + () -> stubRunnerExtension.trigger("bootService", "return_book_1")); + assertThat(wrongLabelWithIvyNotation.getMessage()) + .contains("Failed to send a message with headers"); + } - @Override - public void send(Object message, String destination) { - throw new IllegalStateException("Failed to send a message"); - } + static class MyMessageVerifier implements MessageVerifier { - @Override - public Object receive(String destination, long timeout, TimeUnit timeUnit) { - throw new IllegalStateException("Failed to receive a message with timeout"); - } + @Override + public void send(Object message, String destination) { + throw new IllegalStateException("Failed to send a message"); + } - @Override - public Object receive(String destination) { - throw new IllegalStateException("Failed to receive a message"); - } + @Override + public Object receive(String destination, long timeout, TimeUnit timeUnit) { + throw new IllegalStateException("Failed to receive a message with timeout"); + } - @Override - public void send(Object payload, Map headers, String destination) { - throw new IllegalStateException("Failed to send a message with headers"); - } - } + @Override + public Object receive(String destination) { + throw new IllegalStateException("Failed to receive a message"); + } - private static String repoRoot() { - try { - return StubRunnerRuleCustomPortJUnitTest.class.getResource("/m2repo/repository/").toURI().toString(); - } catch (Exception e) { - return ""; - } - } -} \ No newline at end of file + @Override + public void send(Object payload, Map headers, String destination) { + throw new IllegalStateException("Failed to send a message with headers"); + } + + } + +} diff --git a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerJUnit5ExtensionCustomPortTests.java b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerJUnit5ExtensionCustomPortTests.java index 3a1b45e8c4..0e587d9c41 100644 --- a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerJUnit5ExtensionCustomPortTests.java +++ b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerJUnit5ExtensionCustomPortTests.java @@ -1,32 +1,33 @@ /* - * Copyright 2018 the original author or authors. + * Copyright 2018-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 java.nio.charset.Charset; + import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; + import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties; import org.springframework.util.StreamUtils; -import java.io.InputStream; -import java.net.URI; -import java.nio.charset.Charset; - import static org.assertj.core.api.BDDAssertions.then; /** @@ -35,51 +36,67 @@ import static org.assertj.core.api.BDDAssertions.then; */ class StubRunnerJUnit5ExtensionCustomPortTests { - @BeforeAll - @AfterAll - static void setupProps() { - System.clearProperty("stubrunner.repository.root"); - System.clearProperty("stubrunner.classifier"); - } + @RegisterExtension + static StubRunnerExtension stubRunnerExtension = new StubRunnerExtension() + .repoRoot(repoRoot()).stubsMode(StubRunnerProperties.StubsMode.REMOTE) + .downloadStub("org.springframework.cloud.contract.verifier.stubs", + "loanIssuance") + .withPort(12345).downloadStub( + "org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer:12346"); - @RegisterExtension - static StubRunnerExtension stubRunnerExtension = new StubRunnerExtension() - .repoRoot(repoRoot()) - .stubsMode(StubRunnerProperties.StubsMode.REMOTE) - .downloadStub("org.springframework.cloud.contract.verifier.stubs", "loanIssuance") - .withPort(12345) - .downloadStub("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer:12346"); + @BeforeAll + @AfterAll + static void setupProps() { + System.clearProperty("stubrunner.repository.root"); + System.clearProperty("stubrunner.classifier"); + } - @Test - void should_start_wiremock_servers() throws Exception { - then(stubRunnerExtension.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance")).isNotNull(); - then(stubRunnerExtension.findStubUrl("loanIssuance")).isNotNull(); - then(stubRunnerExtension.findStubUrl("loanIssuance")) - .isEqualTo(stubRunnerExtension.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance")); - then(stubRunnerExtension.findStubUrl("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isNotNull(); - then(stubRunnerExtension.findAllRunningStubs().isPresent("loanIssuance")).isTrue(); - then(stubRunnerExtension.findAllRunningStubs() - .isPresent("org.springframework.cloud.contract.verifier.stubs", "fraudDetectionServer")).isTrue(); - then(stubRunnerExtension.findAllRunningStubs() - .isPresent("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isTrue(); - then(httpGet(stubRunnerExtension.findStubUrl("loanIssuance").toString() + "/name")).isEqualTo("loanIssuance"); - then(httpGet(stubRunnerExtension.findStubUrl("fraudDetectionServer").toString() + "/name")).isEqualTo("fraudDetectionServer"); - then(stubRunnerExtension.findStubUrl("loanIssuance")).isEqualTo(URI.create("http://localhost:12345").toURL()); - then(stubRunnerExtension.findStubUrl("fraudDetectionServer")).isEqualTo(URI.create("http://localhost:12346").toURL()); - } + private static String repoRoot() { + try { + return StubRunnerJUnit5ExtensionCustomPortTests.class + .getResource("/m2repo/repository/").toURI().toString(); + } + catch (Exception e) { + return ""; + } + } - private static String repoRoot() { - try { - return StubRunnerJUnit5ExtensionCustomPortTests.class.getResource("/m2repo/repository/") - .toURI().toString(); - } catch (Exception e) { - return ""; - } - } + @Test + void should_start_wiremock_servers() throws Exception { + then(stubRunnerExtension.findStubUrl( + "org.springframework.cloud.contract.verifier.stubs", "loanIssuance")) + .isNotNull(); + then(stubRunnerExtension.findStubUrl("loanIssuance")).isNotNull(); + then(stubRunnerExtension.findStubUrl("loanIssuance")) + .isEqualTo(stubRunnerExtension.findStubUrl( + "org.springframework.cloud.contract.verifier.stubs", + "loanIssuance")); + then(stubRunnerExtension.findStubUrl( + "org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")) + .isNotNull(); + then(stubRunnerExtension.findAllRunningStubs().isPresent("loanIssuance")) + .isTrue(); + then(stubRunnerExtension.findAllRunningStubs().isPresent( + "org.springframework.cloud.contract.verifier.stubs", + "fraudDetectionServer")).isTrue(); + then(stubRunnerExtension.findAllRunningStubs().isPresent( + "org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")) + .isTrue(); + then(httpGet( + stubRunnerExtension.findStubUrl("loanIssuance").toString() + "/name")) + .isEqualTo("loanIssuance"); + then(httpGet(stubRunnerExtension.findStubUrl("fraudDetectionServer").toString() + + "/name")).isEqualTo("fraudDetectionServer"); + then(stubRunnerExtension.findStubUrl("loanIssuance")) + .isEqualTo(URI.create("http://localhost:12345").toURL()); + then(stubRunnerExtension.findStubUrl("fraudDetectionServer")) + .isEqualTo(URI.create("http://localhost:12346").toURL()); + } + + private String httpGet(String url) throws Exception { + try (InputStream stream = URI.create(url).toURL().openStream()) { + return StreamUtils.copyToString(stream, Charset.forName("UTF-8")); + } + } - private String httpGet(String url) throws Exception { - try (InputStream stream = URI.create(url).toURL().openStream()) { - return StreamUtils.copyToString(stream, Charset.forName("UTF-8")); - } - } } diff --git a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerJUnit5ExtensionExceptionThrowingTests.java b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerJUnit5ExtensionExceptionThrowingTests.java index 64bc403e37..324dff935a 100644 --- a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerJUnit5ExtensionExceptionThrowingTests.java +++ b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerJUnit5ExtensionExceptionThrowingTests.java @@ -1,17 +1,17 @@ /* - * Copyright 2018 the original author or authors. + * Copyright 2018-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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; @@ -20,6 +20,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; + import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -30,34 +31,39 @@ import static org.junit.jupiter.api.Assertions.assertThrows; */ public class StubRunnerJUnit5ExtensionExceptionThrowingTests { - @RegisterExtension - static StubRunnerExtension stubRunnerExtension = new StubRunnerExtension() - .stubsMode(StubRunnerProperties.StubsMode.REMOTE) - .repoRoot(repoRoot()) - .downloadStub("org.springframework.cloud.contract.verifier.stubs", "bootService"); + @RegisterExtension + static StubRunnerExtension stubRunnerExtension = new StubRunnerExtension() + .stubsMode(StubRunnerProperties.StubsMode.REMOTE).repoRoot(repoRoot()) + .downloadStub("org.springframework.cloud.contract.verifier.stubs", + "bootService"); - @BeforeAll - @AfterAll - static void setupProps() { - System.clearProperty("stubrunner.repository.root"); - System.clearProperty("stubrunner.classifier"); - } + @BeforeAll + @AfterAll + static void setupProps() { + System.clearProperty("stubrunner.repository.root"); + System.clearProperty("stubrunner.classifier"); + } - @Test - void should_throw_exception_when_no_message_verifier_was_passed_and_message_related_method_was_triggered() { - UnsupportedOperationException emptyTriggerException = assertThrows(UnsupportedOperationException.class, - () -> stubRunnerExtension.trigger()); - UnsupportedOperationException wrongLabelException = assertThrows(UnsupportedOperationException.class, - () -> stubRunnerExtension.trigger("return_book_1")); - UnsupportedOperationException wrongLabelWithIvyNotation = assertThrows(UnsupportedOperationException.class, - () -> stubRunnerExtension.trigger("bootService", "return_book_1")); - } + private static String repoRoot() { + try { + return StubRunnerRuleCustomPortJUnitTest.class + .getResource("/m2repo/repository/").toURI().toString(); + } + catch (Exception e) { + return ""; + } + } + + @Test + void should_throw_exception_when_no_message_verifier_was_passed_and_message_related_method_was_triggered() { + UnsupportedOperationException emptyTriggerException = assertThrows( + UnsupportedOperationException.class, () -> stubRunnerExtension.trigger()); + UnsupportedOperationException wrongLabelException = assertThrows( + UnsupportedOperationException.class, + () -> stubRunnerExtension.trigger("return_book_1")); + UnsupportedOperationException wrongLabelWithIvyNotation = assertThrows( + UnsupportedOperationException.class, + () -> stubRunnerExtension.trigger("bootService", "return_book_1")); + } - private static String repoRoot() { - try { - return StubRunnerRuleCustomPortJUnitTest.class.getResource("/m2repo/repository/").toURI().toString(); - } catch (Exception e) { - return ""; - } - } } diff --git a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerJUnit5ExtensionTests.java b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerJUnit5ExtensionTests.java index 3104b99c6f..76be6695ee 100644 --- a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerJUnit5ExtensionTests.java +++ b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerJUnit5ExtensionTests.java @@ -1,82 +1,91 @@ /* - * Copyright 2018 the original author or authors. + * Copyright 2018-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.File; +import java.net.URL; + import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; -import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties; -import java.io.File; -import java.net.URL; +import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties; import static org.assertj.core.api.Assertions.assertThat; /** - * @since 2.1.0 * @author Olga Maciaszek-Sharma + * @since 2.1.0 */ - class StubRunnerJUnit5ExtensionTests { - @BeforeAll - @AfterAll - static void setupProps() { - System.clearProperty("stubrunner.repository.root"); - System.clearProperty("stubrunner.classifier"); - } + // tag::extension[] + // Visible for Junit + @RegisterExtension + static StubRunnerExtension stubRunnerExtension = new StubRunnerExtension() + .repoRoot(repoRoot()).stubsMode(StubRunnerProperties.StubsMode.REMOTE) + .downloadStub("org.springframework.cloud.contract.verifier.stubs", + "loanIssuance") + .downloadStub( + "org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer") + .withMappingsOutputFolder("target/outputmappingsforrule"); - // tag::extension[] - // Visible for Junit - @RegisterExtension - static StubRunnerExtension stubRunnerExtension = new StubRunnerExtension() - .repoRoot(repoRoot()) - .stubsMode(StubRunnerProperties.StubsMode.REMOTE) - .downloadStub("org.springframework.cloud.contract.verifier.stubs", "loanIssuance") - .downloadStub("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer") - .withMappingsOutputFolder("target/outputmappingsforrule"); + @BeforeAll + @AfterAll + static void setupProps() { + System.clearProperty("stubrunner.repository.root"); + System.clearProperty("stubrunner.classifier"); + } - @Test - void should_start_WireMock_servers() { - assertThat(stubRunnerExtension.findStubUrl("org.springframework.cloud.contract.verifier.stubs", - "loanIssuance")).isNotNull(); - assertThat(stubRunnerExtension.findStubUrl("loanIssuance")).isNotNull(); - assertThat(stubRunnerExtension.findStubUrl("loanIssuance")).isEqualTo(stubRunnerExtension - .findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance")); - assertThat(stubRunnerExtension - .findStubUrl("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isNotNull(); - } - // end::extension[] + private static String repoRoot() { + try { + return StubRunnerRuleJUnitTest.class.getResource("/m2repo/repository/") + .toURI().toString(); + } + catch (Exception e) { + return ""; + } + } + // end::extension[] - @Test - void should_output_mappings_to_output_folder() { - // when - URL url = stubRunnerExtension.findStubUrl("fraudDetectionServer"); + @Test + void should_start_WireMock_servers() { + assertThat(stubRunnerExtension.findStubUrl( + "org.springframework.cloud.contract.verifier.stubs", "loanIssuance")) + .isNotNull(); + assertThat(stubRunnerExtension.findStubUrl("loanIssuance")).isNotNull(); + assertThat(stubRunnerExtension.findStubUrl("loanIssuance")) + .isEqualTo(stubRunnerExtension.findStubUrl( + "org.springframework.cloud.contract.verifier.stubs", + "loanIssuance")); + assertThat(stubRunnerExtension.findStubUrl( + "org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")) + .isNotNull(); + } - //then - assertThat(new File("target/outputmappingsforrule", "fraudDetectionServer_" + url.getPort())).exists(); - } + @Test + void should_output_mappings_to_output_folder() { + // when + URL url = stubRunnerExtension.findStubUrl("fraudDetectionServer"); + + // then + assertThat(new File("target/outputmappingsforrule", + "fraudDetectionServer_" + url.getPort())).exists(); + } - private static String repoRoot() { - try { - return StubRunnerRuleJUnitTest.class.getResource("/m2repo/repository/").toURI().toString(); - } catch (Exception e) { - return ""; - } - } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/META-INF/spring.factories b/spring-cloud-contract-stub-runner/src/test/resources/META-INF/spring.factories index 7b88e22c0b..d1a9007fa8 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/META-INF/spring.factories +++ b/spring-cloud-contract-stub-runner/src/test/resources/META-INF/spring.factories @@ -1,4 +1,4 @@ org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockExtensions=\ org.springframework.cloud.contract.stubrunner.provider.wiremock.TestWireMockExtensions org.springframework.cloud.contract.spec.ContractConverter=\ -org.springframework.cloud.contract.stubrunner.TestCustomYamlContractConverter \ No newline at end of file +org.springframework.cloud.contract.stubrunner.TestCustomYamlContractConverter diff --git a/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/mappings/spring/cloud/bar/bar.json b/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/mappings/spring/cloud/bar/bar.json index 0b71cbf35e..ed74e468ae 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/mappings/spring/cloud/bar/bar.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/mappings/spring/cloud/bar/bar.json @@ -1,13 +1,13 @@ { - "request": { - "method": "GET", - "url": "/bar" - }, - "response": { - "status": 200, - "body": "bar", - "headers": { - "Content-Type": "text/plain" - } + "request": { + "method": "GET", + "url": "/bar" + }, + "response": { + "status": 200, + "body": "bar", + "headers": { + "Content-Type": "text/plain" } -} \ No newline at end of file + } +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/mappings/spring/cloud/foo/bar/foobar.json b/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/mappings/spring/cloud/foo/bar/foobar.json index e231b2c0c5..7a50958518 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/mappings/spring/cloud/foo/bar/foobar.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/mappings/spring/cloud/foo/bar/foobar.json @@ -1,13 +1,13 @@ { - "request": { - "method": "GET", - "url": "/foobar" - }, - "response": { - "status": 200, - "body": "foobar", - "headers": { - "Content-Type": "text/plain" - } + "request": { + "method": "GET", + "url": "/foobar" + }, + "response": { + "status": 200, + "body": "foobar", + "headers": { + "Content-Type": "text/plain" } -} \ No newline at end of file + } +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/mappings/spring/cloud/foo/foo.json b/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/mappings/spring/cloud/foo/foo.json index 209061ef5e..c5e5d5eecd 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/mappings/spring/cloud/foo/foo.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/mappings/spring/cloud/foo/foo.json @@ -1,13 +1,13 @@ { - "request": { - "method": "GET", - "url": "/foo" - }, - "response": { - "status": 200, - "body": "foo", - "headers": { - "Content-Type": "text/plain" - } + "request": { + "method": "GET", + "url": "/foo" + }, + "response": { + "status": 200, + "body": "foo", + "headers": { + "Content-Type": "text/plain" } -} \ No newline at end of file + } +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/projects/brokers/brokers.json b/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/projects/brokers/brokers.json index fae6436ad8..f164f29c49 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/projects/brokers/brokers.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/projects/brokers/brokers.json @@ -1,5 +1,5 @@ { - "pl": [ - "spring/cloud/bar" - ] -} \ No newline at end of file + "pl": [ + "spring/cloud/bar" + ] +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/projects/brokers/nested/anotherDescriptor.json b/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/projects/brokers/nested/anotherDescriptor.json index b3a72bfbcf..65c5cde2b5 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/projects/brokers/nested/anotherDescriptor.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/projects/brokers/nested/anotherDescriptor.json @@ -1,5 +1,5 @@ { - "pl": [ - "spring/cloud/foo/bar" - ] -} \ No newline at end of file + "pl": [ + "spring/cloud/foo/bar" + ] +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/projects/descriptor.json b/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/projects/descriptor.json index a2384b0930..e83e99310f 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/projects/descriptor.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/anotherRepository/projects/descriptor.json @@ -1,5 +1,5 @@ { - "pl": [ - "spring/cloud/foo" - ] -} \ No newline at end of file + "pl": [ + "spring/cloud/foo" + ] +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/application-cloudtest.yml b/spring-cloud-contract-stub-runner/src/test/resources/application-cloudtest.yml index ea941760d1..ffdf85bd4a 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/application-cloudtest.yml +++ b/spring-cloud-contract-stub-runner/src/test/resources/application-cloudtest.yml @@ -8,4 +8,4 @@ spring.cloud: enabled: false discovery.enabled: false service-registry.enabled: false -eureka.client.enabled: false \ No newline at end of file +eureka.client.enabled: false diff --git a/spring-cloud-contract-stub-runner/src/test/resources/application-eureka.yml b/spring-cloud-contract-stub-runner/src/test/resources/application-eureka.yml index 4ebdf98ff4..f014420403 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/application-eureka.yml +++ b/spring-cloud-contract-stub-runner/src/test/resources/application-eureka.yml @@ -4,6 +4,6 @@ eureka: fetchRegistry: false initialInstanceInfoReplicationIntervalSeconds: 1 instance: - registryFetchIntervalSeconds: 5 - leaseRenewalIntervalInSeconds: 5 - leaseExpirationDurationInSeconds: 5 \ No newline at end of file + registryFetchIntervalSeconds: 5 + leaseRenewalIntervalInSeconds: 5 + leaseExpirationDurationInSeconds: 5 diff --git a/spring-cloud-contract-stub-runner/src/test/resources/application-test.yml b/spring-cloud-contract-stub-runner/src/test/resources/application-test.yml index 39817e6a5c..b442108385 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/application-test.yml +++ b/spring-cloud-contract-stub-runner/src/test/resources/application-test.yml @@ -6,10 +6,10 @@ stubrunner: - org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer - org.springframework.cloud.contract.verifier.stubs:bootService stubs-mode: remote -# end::test[] + # end::test[] cloud: enabled: false spring.cloud: consul.enabled: false - service-registry.enabled: false \ No newline at end of file + service-registry.enabled: false diff --git a/spring-cloud-contract-stub-runner/src/test/resources/application.yml b/spring-cloud-contract-stub-runner/src/test/resources/application.yml index f880e5f7ce..e9169ba808 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/application.yml +++ b/spring-cloud-contract-stub-runner/src/test/resources/application.yml @@ -8,4 +8,4 @@ stubrunner: idsToServiceIds: ivyNotation: someValueInsideYourCode fraudDetectionServer: someNameThatShouldMapFraudDetectionServer -# end::ids[] \ No newline at end of file +# end::ids[] diff --git a/spring-cloud-contract-stub-runner/src/test/resources/customYamlRepository/contracts/custom.yml b/spring-cloud-contract-stub-runner/src/test/resources/customYamlRepository/contracts/custom.yml index fce56b04db..b2a12da7f3 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/customYamlRepository/contracts/custom.yml +++ b/spring-cloud-contract-stub-runner/src/test/resources/customYamlRepository/contracts/custom.yml @@ -13,4 +13,4 @@ inbound: headers: foo2: bar body: - foo2: bar \ No newline at end of file + foo2: bar diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy index 247c62bae9..13661185fd 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy index 514f244883..62a3db01df 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy index 3e71c00ed5..38081e5a38 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy index ef84a9a58e..0f1e0d7e9e 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "NOT_OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json index 4e627786fd..5f25f6f934 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json @@ -1,24 +1,28 @@ { - "id" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[2-9][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[2-9][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" -} \ No newline at end of file + "uuid": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json index 932477d065..9a4d31b7e5 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json @@ -1,24 +1,28 @@ { - "id" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[0-1][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[0-1][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"NOT_OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"NOT_OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" -} \ No newline at end of file + "uuid": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy index 247c62bae9..13661185fd 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy index 514f244883..62a3db01df 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy index 3e71c00ed5..38081e5a38 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy index ef84a9a58e..0f1e0d7e9e 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "NOT_OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json index 4e627786fd..5f25f6f934 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json @@ -1,24 +1,28 @@ { - "id" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[2-9][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[2-9][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" -} \ No newline at end of file + "uuid": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json index 932477d065..9a4d31b7e5 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json @@ -1,24 +1,28 @@ { - "id" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[0-1][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[0-1][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"NOT_OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"NOT_OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" -} \ No newline at end of file + "uuid": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy index 247c62bae9..13661185fd 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy index 514f244883..62a3db01df 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy index 3e71c00ed5..38081e5a38 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy index ef84a9a58e..0f1e0d7e9e 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "NOT_OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json index 4e627786fd..5f25f6f934 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json @@ -1,24 +1,28 @@ { - "id" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[2-9][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[2-9][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" -} \ No newline at end of file + "uuid": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json index 932477d065..9a4d31b7e5 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json @@ -1,24 +1,28 @@ { - "id" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[0-1][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[0-1][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"NOT_OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"NOT_OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" -} \ No newline at end of file + "uuid": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy index 247c62bae9..13661185fd 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy index 514f244883..62a3db01df 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy index 3e71c00ed5..38081e5a38 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy index ef84a9a58e..0f1e0d7e9e 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "NOT_OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json index 4e627786fd..5f25f6f934 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json @@ -1,24 +1,28 @@ { - "id" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[2-9][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[2-9][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" -} \ No newline at end of file + "uuid": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json index 932477d065..9a4d31b7e5 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json @@ -1,24 +1,28 @@ { - "id" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[0-1][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[0-1][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"NOT_OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"NOT_OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" -} \ No newline at end of file + "uuid": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy index 247c62bae9..13661185fd 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy index 514f244883..62a3db01df 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy index 3e71c00ed5..38081e5a38 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy index ef84a9a58e..0f1e0d7e9e 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "NOT_OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json index 4e627786fd..5f25f6f934 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json @@ -1,24 +1,28 @@ { - "id" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[2-9][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[2-9][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" -} \ No newline at end of file + "uuid": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json index 932477d065..9a4d31b7e5 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json @@ -1,24 +1,28 @@ { - "id" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[0-1][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[0-1][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"NOT_OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"NOT_OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" -} \ No newline at end of file + "uuid": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/foo.bar/bazService/0.0.1-SNAPSHOT/contracts/bazConsumer1/rest/shouldSayHello.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/foo.bar/bazService/0.0.1-SNAPSHOT/contracts/bazConsumer1/rest/shouldSayHello.groovy index 5a99d7f0e1..3672b48973 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/foo.bar/bazService/0.0.1-SNAPSHOT/contracts/bazConsumer1/rest/shouldSayHello.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/foo.bar/bazService/0.0.1-SNAPSHOT/contracts/bazConsumer1/rest/shouldSayHello.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.foo.bar.bazService.bazConsumer.rest org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/foo.bar/bazService/0.0.1-SNAPSHOT/mappings/bazConsumer1/rest/shouldSayHello.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/foo.bar/bazService/0.0.1-SNAPSHOT/mappings/bazConsumer1/rest/shouldSayHello.json index 8ec1c01300..d25d733109 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/foo.bar/bazService/0.0.1-SNAPSHOT/mappings/bazConsumer1/rest/shouldSayHello.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-git/META-INF/foo.bar/bazService/0.0.1-SNAPSHOT/mappings/bazConsumer1/rest/shouldSayHello.json @@ -1,12 +1,14 @@ { - "id" : "f4080f7d-4cb2-4301-81d6-492570316aae", - "request" : { - "url" : "/hello", - "method" : "GET" + "id": "f4080f7d-4cb2-4301-81d6-492570316aae", + "request": { + "url": "/hello", + "method": "GET" }, - "response" : { - "status" : 200, - "transformers" : [ "response-template" ] + "response": { + "status": 200, + "transformers": [ + "response-template" + ] }, - "uuid" : "f4080f7d-4cb2-4301-81d6-492570316aae" -} \ No newline at end of file + "uuid": "f4080f7d-4cb2-4301-81d6-492570316aae" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy index 247c62bae9..13661185fd 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy index 514f244883..62a3db01df 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy index 3e71c00ed5..38081e5a38 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy index ef84a9a58e..0f1e0d7e9e 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "NOT_OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json index 4e627786fd..5f25f6f934 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json @@ -1,24 +1,28 @@ { - "id" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[2-9][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[2-9][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" -} \ No newline at end of file + "uuid": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json index 932477d065..9a4d31b7e5 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/0.0.1-SNAPSHOT/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json @@ -1,24 +1,28 @@ { - "id" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[0-1][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[0-1][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"NOT_OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"NOT_OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" -} \ No newline at end of file + "uuid": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy index 247c62bae9..13661185fd 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy index 514f244883..62a3db01df 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy index 3e71c00ed5..38081e5a38 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy index ef84a9a58e..0f1e0d7e9e 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "NOT_OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json index 4e627786fd..5f25f6f934 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json @@ -1,24 +1,28 @@ { - "id" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[2-9][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[2-9][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" -} \ No newline at end of file + "uuid": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json index 932477d065..9a4d31b7e5 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.BUILD-SNAPSHOT/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json @@ -1,24 +1,28 @@ { - "id" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[0-1][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[0-1][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"NOT_OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"NOT_OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" -} \ No newline at end of file + "uuid": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy index 247c62bae9..13661185fd 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy index 514f244883..62a3db01df 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy index 3e71c00ed5..38081e5a38 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy index ef84a9a58e..0f1e0d7e9e 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "NOT_OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json index 4e627786fd..5f25f6f934 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json @@ -1,24 +1,28 @@ { - "id" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[2-9][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[2-9][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" -} \ No newline at end of file + "uuid": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json index 932477d065..9a4d31b7e5 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.M1/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json @@ -1,24 +1,28 @@ { - "id" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[0-1][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[0-1][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"NOT_OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"NOT_OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" -} \ No newline at end of file + "uuid": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy index 247c62bae9..13661185fd 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy index 514f244883..62a3db01df 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy index 3e71c00ed5..38081e5a38 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy index ef84a9a58e..0f1e0d7e9e 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "NOT_OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json index 4e627786fd..5f25f6f934 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json @@ -1,24 +1,28 @@ { - "id" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[2-9][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[2-9][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" -} \ No newline at end of file + "uuid": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json index 932477d065..9a4d31b7e5 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RC1/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json @@ -1,24 +1,28 @@ { - "id" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[0-1][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[0-1][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"NOT_OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"NOT_OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" -} \ No newline at end of file + "uuid": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy index 247c62bae9..13661185fd 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy index 514f244883..62a3db01df 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy index 3e71c00ed5..38081e5a38 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy index ef84a9a58e..0f1e0d7e9e 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "NOT_OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json index 4e627786fd..5f25f6f934 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json @@ -1,24 +1,28 @@ { - "id" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[2-9][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[2-9][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" -} \ No newline at end of file + "uuid": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json index 932477d065..9a4d31b7e5 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/1.0.0.RELEASE/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json @@ -1,24 +1,28 @@ { - "id" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[0-1][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[0-1][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"NOT_OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"NOT_OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" -} \ No newline at end of file + "uuid": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy index 247c62bae9..13661185fd 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy index 514f244883..62a3db01df 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy index 3e71c00ed5..38081e5a38 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy index ef84a9a58e..0f1e0d7e9e 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "NOT_OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json index 4e627786fd..5f25f6f934 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json @@ -1,24 +1,28 @@ { - "id" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[2-9][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[2-9][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" -} \ No newline at end of file + "uuid": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json index 932477d065..9a4d31b7e5 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/latest/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json @@ -1,24 +1,28 @@ { - "id" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[0-1][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[0-1][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"NOT_OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"NOT_OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" -} \ No newline at end of file + "uuid": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy index 247c62bae9..13661185fd 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/contracts/beer-api-consumer/messaging/shouldSendAcceptedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy index 514f244883..62a3db01df 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/contracts/beer-api-consumer/messaging/shouldSendRejectedVerification.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.messaging org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy index 3e71c00ed5..38081e5a38 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/contracts/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy index ef84a9a58e..0f1e0d7e9e 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/contracts/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.beer.rest org.springframework.cloud.contract.spec.Contract.make { @@ -23,14 +39,15 @@ then: } response { status 200 - body( """ + body(""" { "status": "NOT_OK" } """) headers { header( - 'Content-Type', value(consumer('application/json'),producer(regex('application/json.*'))) + 'Content-Type', + value(consumer('application/json'), producer(regex('application/json.*'))) ) } } diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json index 4e627786fd..5f25f6f934 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/mappings/beer-api-consumer/rest/shouldGrantABeerIfOldEnough.json @@ -1,24 +1,28 @@ { - "id" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[2-9][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[2-9][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" -} \ No newline at end of file + "uuid": "e5413ef6-0f3e-4b81-9e78-7a90b53c6ed1" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json index 932477d065..9a4d31b7e5 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/com.example/beer-api-producer-external/release/mappings/beer-api-consumer/rest/shouldRejectABeerIfTooYoung.json @@ -1,24 +1,28 @@ { - "id" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", - "request" : { - "url" : "/check", - "method" : "POST", - "headers" : { - "Content-Type" : { - "equalTo" : "application/json" + "id": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08", + "request": { + "url": "/check", + "method": "POST", + "headers": { + "Content-Type": { + "equalTo": "application/json" } }, - "bodyPatterns" : [ { - "matchesJsonPath" : "$[?(@.['age'] =~ /[0-1][0-9]/)]" - } ] + "bodyPatterns": [ + { + "matchesJsonPath": "$[?(@.['age'] =~ /[0-1][0-9]/)]" + } + ] }, - "response" : { - "status" : 200, - "body" : "{\"status\":\"NOT_OK\"}", - "headers" : { - "Content-Type" : "application/json" + "response": { + "status": 200, + "body": "{\"status\":\"NOT_OK\"}", + "headers": { + "Content-Type": "application/json" }, - "transformers" : [ "response-template" ] + "transformers": [ + "response-template" + ] }, - "uuid" : "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" -} \ No newline at end of file + "uuid": "b54426aa-b2ef-4b12-adc9-a05fcf6a4e08" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/foo.bar/bazService/0.0.1-SNAPSHOT/contracts/bazConsumer1/rest/shouldSayHello.groovy b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/foo.bar/bazService/0.0.1-SNAPSHOT/contracts/bazConsumer1/rest/shouldSayHello.groovy index 5a99d7f0e1..3672b48973 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/foo.bar/bazService/0.0.1-SNAPSHOT/contracts/bazConsumer1/rest/shouldSayHello.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/foo.bar/bazService/0.0.1-SNAPSHOT/contracts/bazConsumer1/rest/shouldSayHello.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 contracts.foo.bar.bazService.bazConsumer.rest org.springframework.cloud.contract.spec.Contract.make { diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/foo.bar/bazService/0.0.1-SNAPSHOT/mappings/bazConsumer1/rest/shouldSayHello.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/foo.bar/bazService/0.0.1-SNAPSHOT/mappings/bazConsumer1/rest/shouldSayHello.json index 8ec1c01300..d25d733109 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/foo.bar/bazService/0.0.1-SNAPSHOT/mappings/bazConsumer1/rest/shouldSayHello.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/contract-predefined-names-git/META-INF/foo.bar/bazService/0.0.1-SNAPSHOT/mappings/bazConsumer1/rest/shouldSayHello.json @@ -1,12 +1,14 @@ { - "id" : "f4080f7d-4cb2-4301-81d6-492570316aae", - "request" : { - "url" : "/hello", - "method" : "GET" + "id": "f4080f7d-4cb2-4301-81d6-492570316aae", + "request": { + "url": "/hello", + "method": "GET" }, - "response" : { - "status" : 200, - "transformers" : [ "response-template" ] + "response": { + "status": 200, + "transformers": [ + "response-template" + ] }, - "uuid" : "f4080f7d-4cb2-4301-81d6-492570316aae" -} \ No newline at end of file + "uuid": "f4080f7d-4cb2-4301-81d6-492570316aae" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/sample_stubs/META-INF/com.example/hello-world/0.0.2/mappings/someMapping.json b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/sample_stubs/META-INF/com.example/hello-world/0.0.2/mappings/someMapping.json index d9339d85c5..126b353289 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/git_samples/sample_stubs/META-INF/com.example/hello-world/0.0.2/mappings/someMapping.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/git_samples/sample_stubs/META-INF/com.example/hello-world/0.0.2/mappings/someMapping.json @@ -1,13 +1,15 @@ { - "id" : "b54426bb-b2ef-4b12-adc9-a05fcf6a4e08", - "request" : { - "url" : "/hello", - "method" : "GET" + "id": "b54426bb-b2ef-4b12-adc9-a05fcf6a4e08", + "request": { + "url": "/hello", + "method": "GET" }, - "response" : { - "status" : 200, - "body" : "world", - "transformers" : [ "response-template" ] + "response": { + "status": 200, + "body": "world", + "transformers": [ + "response-template" + ] }, - "uuid" : "b54426bb-b2ef-4b12-adc9-a05fcf6a4e08" -} \ No newline at end of file + "uuid": "b54426bb-b2ef-4b12-adc9-a05fcf6a4e08" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/logback.xml b/spring-cloud-contract-stub-runner/src/test/resources/logback.xml index 73c7481480..1c94fe3c0f 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/logback.xml +++ b/spring-cloud-contract-stub-runner/src/test/resources/logback.xml @@ -20,6 +20,6 @@ - + - \ No newline at end of file + diff --git a/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/bootService/0.0.1-SNAPSHOT/bootService-0.0.1-SNAPSHOT.pom b/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/bootService/0.0.1-SNAPSHOT/bootService-0.0.1-SNAPSHOT.pom index caed694c89..efeeb0171b 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/bootService/0.0.1-SNAPSHOT/bootService-0.0.1-SNAPSHOT.pom +++ b/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/bootService/0.0.1-SNAPSHOT/bootService-0.0.1-SNAPSHOT.pom @@ -15,11 +15,13 @@ ~ limitations under the License. --> - - 4.0.0 - org.springframework.cloud.contract.verifier.stubs - bootService - 0.0.1-SNAPSHOT - pom + + 4.0.0 + org.springframework.cloud.contract.verifier.stubs + bootService + 0.0.1-SNAPSHOT + pom diff --git a/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/bootService/maven-metadata.xml b/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/bootService/maven-metadata.xml index d557f30f13..074e7119df 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/bootService/maven-metadata.xml +++ b/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/bootService/maven-metadata.xml @@ -16,13 +16,13 @@ --> - org.springframework.cloud.contract.verifier.stubs - bootService - 0.0.1-SNAPSHOT - - - 0.0.1-SNAPSHOT - - 20160409062112 - + org.springframework.cloud.contract.verifier.stubs + bootService + 0.0.1-SNAPSHOT + + + 0.0.1-SNAPSHOT + + 20160409062112 + diff --git a/spring-cloud-contract-stub-runner/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/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT.pom index e0ca593a0f..a1f4fa0705 100644 --- a/spring-cloud-contract-stub-runner/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/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/0.0.1-SNAPSHOT/fraudDetectionServer-0.0.1-SNAPSHOT.pom @@ -15,11 +15,13 @@ ~ limitations under the License. --> - - 4.0.0 - org.springframework.cloud.contract.verifier.stubs - fraudDetectionServer - 0.0.1-SNAPSHOT - pom + + 4.0.0 + org.springframework.cloud.contract.verifier.stubs + fraudDetectionServer + 0.0.1-SNAPSHOT + pom diff --git a/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/maven-metadata.xml b/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/maven-metadata.xml index 96f49ba165..fb922209a4 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/maven-metadata.xml +++ b/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/fraudDetectionServer/maven-metadata.xml @@ -16,13 +16,13 @@ --> - org.springframework.cloud.contract.verifier.stubs - fraudDetectionServer - 0.0.1-SNAPSHOT - - - 0.0.1-SNAPSHOT - - 20160409062112 - + org.springframework.cloud.contract.verifier.stubs + fraudDetectionServer + 0.0.1-SNAPSHOT + + + 0.0.1-SNAPSHOT + + 20160409062112 + diff --git a/spring-cloud-contract-stub-runner/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/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT.pom index 4e45f85e25..4e528dbfaa 100644 --- a/spring-cloud-contract-stub-runner/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/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/0.0.1-SNAPSHOT/loanIssuance-0.0.1-SNAPSHOT.pom @@ -15,11 +15,13 @@ ~ limitations under the License. --> - - 4.0.0 - org.springframework.cloud.contract.verifier.stubs - loanIssuance - 0.0.1-SNAPSHOT - pom + + 4.0.0 + org.springframework.cloud.contract.verifier.stubs + loanIssuance + 0.0.1-SNAPSHOT + pom diff --git a/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/maven-metadata.xml b/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/maven-metadata.xml index a2bb376632..c6fe854a9b 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/maven-metadata.xml +++ b/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/loanIssuance/maven-metadata.xml @@ -16,13 +16,13 @@ --> - org.springframework.cloud.contract.verifier.stubs - loanIssuance - 0.0.1-SNAPSHOT - - - 0.0.1-SNAPSHOT - - 20160409062111 - + org.springframework.cloud.contract.verifier.stubs + loanIssuance + 0.0.1-SNAPSHOT + + + 0.0.1-SNAPSHOT + + 20160409062111 + diff --git a/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/producerWithMultipleConsumers/0.0.1-SNAPSHOT/producerWithMultipleConsumers-0.0.1-SNAPSHOT.pom b/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/producerWithMultipleConsumers/0.0.1-SNAPSHOT/producerWithMultipleConsumers-0.0.1-SNAPSHOT.pom index f206a2e591..fb7bceaf22 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/producerWithMultipleConsumers/0.0.1-SNAPSHOT/producerWithMultipleConsumers-0.0.1-SNAPSHOT.pom +++ b/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/producerWithMultipleConsumers/0.0.1-SNAPSHOT/producerWithMultipleConsumers-0.0.1-SNAPSHOT.pom @@ -15,11 +15,13 @@ ~ limitations under the License. --> - - 4.0.0 - org.springframework.cloud.contract.verifier.stubs - producerWithMultipleConsumers - 0.0.1-SNAPSHOT - pom + + 4.0.0 + org.springframework.cloud.contract.verifier.stubs + producerWithMultipleConsumers + 0.0.1-SNAPSHOT + pom diff --git a/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/producerWithMultipleConsumers/maven-metadata.xml b/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/producerWithMultipleConsumers/maven-metadata.xml index 6746549780..f438aa659a 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/producerWithMultipleConsumers/maven-metadata.xml +++ b/spring-cloud-contract-stub-runner/src/test/resources/m2repo/repository/org/springframework/cloud/contract/verifier/stubs/producerWithMultipleConsumers/maven-metadata.xml @@ -16,13 +16,13 @@ --> - org.springframework.cloud.contract.verifier.stubs - producerWithMultipleConsumers - 0.0.1-SNAPSHOT - - - 0.0.1-SNAPSHOT - - 20160409062112 - + org.springframework.cloud.contract.verifier.stubs + producerWithMultipleConsumers + 0.0.1-SNAPSHOT + + + 0.0.1-SNAPSHOT + + 20160409062112 + diff --git a/spring-cloud-contract-stub-runner/src/test/resources/messages/message.groovy b/spring-cloud-contract-stub-runner/src/test/resources/messages/message.groovy index a6cf2980a3..b235e5c8f6 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/messages/message.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/messages/message.groovy @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + org.springframework.cloud.contract.spec.Contract.make { description 'issue #650' label 'trigger' @@ -16,8 +32,10 @@ org.springframework.cloud.contract.spec.Contract.make { } body([ "type" : 'CREATED', - "personId" : $(producer(regex(uuid())), consumer('0fd552ba-8043-42da-ab97-4fc77e1057c9')), - "userId" : $(producer(optional(regex(uuid()))), consumer('f043ccf1-0b72-423b-ad32-4ef123718897')), + "personId" : $(producer(regex(uuid())), + consumer('0fd552ba-8043-42da-ab97-4fc77e1057c9')), + "userId" : $(producer(optional(regex(uuid()))), + consumer('f043ccf1-0b72-423b-ad32-4ef123718897')), "firstName" : $(regex(nonEmpty())), "middleName": $(optional(regex(nonEmpty()))), "lastName" : $(regex(nonEmpty())), @@ -25,4 +43,4 @@ org.springframework.cloud.contract.spec.Contract.make { "uid" : $(producer(regex(uuid()))) ]) } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/repository/contracts/contract1.groovy b/spring-cloud-contract-stub-runner/src/test/resources/repository/contracts/contract1.groovy index 03a06b8b81..165216319d 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/repository/contracts/contract1.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/repository/contracts/contract1.groovy @@ -1,10 +1,28 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + org.springframework.cloud.contract.spec.Contract.make { request { method """PUT""" url """/fraudcheck""" body(""" { - "clientPesel":"${value(consumer(regex('[0-9]{10}')), producer('1234567890'))}", + "clientPesel":"${ + value(consumer(regex('[0-9]{10}')), producer('1234567890')) + }", "loanAmount":99999} """ ) @@ -15,7 +33,7 @@ org.springframework.cloud.contract.spec.Contract.make { } response { status OK() - body( """{ + body("""{ "fraudCheckStatus": "${value(c('FRAUD'), p(regex('[A-Z]{5}')))}", "rejectionReason": "Amount too high" }""") @@ -24,4 +42,4 @@ org.springframework.cloud.contract.spec.Contract.make { } } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/repository/contracts/contract2.groovy b/spring-cloud-contract-stub-runner/src/test/resources/repository/contracts/contract2.groovy index 94fc426530..bc699d3d7c 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/repository/contracts/contract2.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/repository/contracts/contract2.groovy @@ -1,4 +1,20 @@ -org.springframework.cloud.contract.spec.Contract.make { +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +org.springframework.cloud.contract.spec.Contract.make { // Human readable description description 'Sends an order message' // Label by means of which the output message can be triggered @@ -24,4 +40,4 @@ org.springframework.cloud.contract.spec.Contract.make { description: "This is the order description" ) } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/repository/httpcontract/contract1.groovy b/spring-cloud-contract-stub-runner/src/test/resources/repository/httpcontract/contract1.groovy index 03a06b8b81..165216319d 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/repository/httpcontract/contract1.groovy +++ b/spring-cloud-contract-stub-runner/src/test/resources/repository/httpcontract/contract1.groovy @@ -1,10 +1,28 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + org.springframework.cloud.contract.spec.Contract.make { request { method """PUT""" url """/fraudcheck""" body(""" { - "clientPesel":"${value(consumer(regex('[0-9]{10}')), producer('1234567890'))}", + "clientPesel":"${ + value(consumer(regex('[0-9]{10}')), producer('1234567890')) + }", "loanAmount":99999} """ ) @@ -15,7 +33,7 @@ org.springframework.cloud.contract.spec.Contract.make { } response { status OK() - body( """{ + body("""{ "fraudCheckStatus": "${value(c('FRAUD'), p(regex('[A-Z]{5}')))}", "rejectionReason": "Amount too high" }""") @@ -24,4 +42,4 @@ org.springframework.cloud.contract.spec.Contract.make { } } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/lv/spring/cloud/bye/lv_bye.json b/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/lv/spring/cloud/bye/lv_bye.json index a062cd4674..d93ef4731a 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/lv/spring/cloud/bye/lv_bye.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/lv/spring/cloud/bye/lv_bye.json @@ -1,13 +1,13 @@ { - "request": { - "method": "GET", - "url": "/lv/bye" - }, - "response": { - "status": 200, - "body": "Another goodbye world!", - "headers": { - "Content-Type": "text/plain" - } + "request": { + "method": "GET", + "url": "/lv/bye" + }, + "response": { + "status": 200, + "body": "Another goodbye world!", + "headers": { + "Content-Type": "text/plain" } -} \ No newline at end of file + } +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/pl/spring/cloud/bye/pl_bye.json b/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/pl/spring/cloud/bye/pl_bye.json index b7c5e4ebc9..fada15f45a 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/pl/spring/cloud/bye/pl_bye.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/pl/spring/cloud/bye/pl_bye.json @@ -1,13 +1,13 @@ { - "request": { - "method": "GET", - "url": "/pl/bye" - }, - "response": { - "status": 200, - "body": "pl-bye", - "headers": { - "Content-Type": "text/plain" - } + "request": { + "method": "GET", + "url": "/pl/bye" + }, + "response": { + "status": 200, + "body": "pl-bye", + "headers": { + "Content-Type": "text/plain" } -} \ No newline at end of file + } +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/pl/spring/cloud/bye/pl_overridden_bye.json b/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/pl/spring/cloud/bye/pl_overridden_bye.json index 9c54c98914..d08c92f1e5 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/pl/spring/cloud/bye/pl_overridden_bye.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/pl/spring/cloud/bye/pl_overridden_bye.json @@ -1,14 +1,13 @@ { - - "request": { - "method": "GET", - "url": "/bye" - }, - "response": { - "status": 200, - "body": "overridden-bye", - "headers": { - "Content-Type": "text/plain" - } + "request": { + "method": "GET", + "url": "/bye" + }, + "response": { + "status": 200, + "body": "overridden-bye", + "headers": { + "Content-Type": "text/plain" } -} \ No newline at end of file + } +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/bye/admin/admin.json b/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/bye/admin/admin.json index f730b7e3cf..a3ac323a5c 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/bye/admin/admin.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/bye/admin/admin.json @@ -1,9 +1,9 @@ { - "request": { - "method": "GET", - "url": "/admin" - }, - "response": { - "status": 401 - } -} \ No newline at end of file + "request": { + "method": "GET", + "url": "/admin" + }, + "response": { + "status": 401 + } +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/bye/bye.json b/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/bye/bye.json index 1a65830d4a..da1f754a1c 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/bye/bye.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/bye/bye.json @@ -1,13 +1,13 @@ { - "request": { - "method": "GET", - "url": "/bye" - }, - "response": { - "status": 200, - "body": "Goodbye world!", - "headers": { - "Content-Type": "text/plain" - } + "request": { + "method": "GET", + "url": "/bye" + }, + "response": { + "status": 200, + "body": "Goodbye world!", + "headers": { + "Content-Type": "text/plain" } -} \ No newline at end of file + } +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/hello/README.md b/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/hello/README.md index 484f8efe77..13f6cf17e3 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/hello/README.md +++ b/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/hello/README.md @@ -1 +1 @@ -### Hello service stub \ No newline at end of file +### Hello service stub diff --git a/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/hello/admin/admin.json b/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/hello/admin/admin.json index f730b7e3cf..a3ac323a5c 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/hello/admin/admin.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/hello/admin/admin.json @@ -1,9 +1,9 @@ { - "request": { - "method": "GET", - "url": "/admin" - }, - "response": { - "status": 401 - } -} \ No newline at end of file + "request": { + "method": "GET", + "url": "/admin" + }, + "response": { + "status": 401 + } +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/hello/hello.json b/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/hello/hello.json index 3cd9f7374b..13d165d71d 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/hello/hello.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/hello/hello.json @@ -1,13 +1,13 @@ { - "request": { - "method": "GET", - "url": "/hello" - }, - "response": { - "status": 200, - "body": "Hello world!", - "headers": { - "Content-Type": "text/plain" - } + "request": { + "method": "GET", + "url": "/hello" + }, + "response": { + "status": 200, + "body": "Hello world!", + "headers": { + "Content-Type": "text/plain" } -} \ No newline at end of file + } +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/ping/ping.json b/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/ping/ping.json index db01229c52..864f856445 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/ping/ping.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/repository/mappings/spring/cloud/ping/ping.json @@ -1,13 +1,13 @@ { - "request": { - "method": "GET", - "url": "/ping" - }, - "response": { - "status": 200, - "body": "pong", - "headers": { - "Content-Type": "text/plain" - } + "request": { + "method": "GET", + "url": "/ping" + }, + "response": { + "status": 200, + "body": "pong", + "headers": { + "Content-Type": "text/plain" } -} \ No newline at end of file + } +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/simple.json b/spring-cloud-contract-stub-runner/src/test/resources/simple.json index 17361a09b3..9835088dc3 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/simple.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/simple.json @@ -1,13 +1,15 @@ { - "id" : "77514bd4-a102-4478-a3c0-0fda8b905591", - "request" : { - "method" : "GET", + "id": "77514bd4-a102-4478-a3c0-0fda8b905591", + "request": { + "method": "GET", "url": "/foobar" }, - "response" : { - "status" : 200, - "body" : "foo", - "transformers": ["response-template"] + "response": { + "status": 200, + "body": "foo", + "transformers": [ + "response-template" + ] }, - "uuid" : "77514bd4-a102-4478-a3c0-0fda8b905591" -} \ No newline at end of file + "uuid": "77514bd4-a102-4478-a3c0-0fda8b905591" +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/simulation.json b/spring-cloud-contract-stub-runner/src/test/resources/simulation.json index 2f1571b1ce..b920f438aa 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/simulation.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/simulation.json @@ -1 +1,13 @@ -{"data":{"pairs":[],"globalActions":{"delays":[]}},"meta":{"schemaVersion":"v1","hoverflyVersion":"v0.9.0","timeExported":"2017-06-26T11:40:47+02:00"}} \ No newline at end of file +{ + "data": { + "pairs": [], + "globalActions": { + "delays": [] + } + }, + "meta": { + "schemaVersion": "v1", + "hoverflyVersion": "v0.9.0", + "timeExported": "2017-06-26T11:40:47+02:00" + } +} diff --git a/spring-cloud-contract-stub-runner/src/test/resources/transformers.json b/spring-cloud-contract-stub-runner/src/test/resources/transformers.json index 710b9846d2..fd4aa7923b 100644 --- a/spring-cloud-contract-stub-runner/src/test/resources/transformers.json +++ b/spring-cloud-contract-stub-runner/src/test/resources/transformers.json @@ -1,14 +1,17 @@ { - "request": { - "method": "GET", - "url": "/ping" + "request": { + "method": "GET", + "url": "/ping" + }, + "response": { + "status": 200, + "body": "pong", + "headers": { + "Content-Type": "text/plain" }, - "response": { - "status": 200, - "body": "pong", - "headers": { - "Content-Type": "text/plain" - }, - "transformers" : [ "response-template", "foo-transformer" ] - } -} \ No newline at end of file + "transformers": [ + "response-template", + "foo-transformer" + ] + } +} diff --git a/spring-cloud-contract-tools/pom.xml b/spring-cloud-contract-tools/pom.xml index 85f107f359..b99df33099 100644 --- a/spring-cloud-contract-tools/pom.xml +++ b/spring-cloud-contract-tools/pom.xml @@ -1,6 +1,6 @@ - 4.0.0 diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/pom.xml b/spring-cloud-contract-tools/spring-cloud-contract-converters/pom.xml index 5100d39116..583d537243 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/pom.xml +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/pom.xml @@ -1,5 +1,6 @@ - 4.0.0 diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/converter/ConversionContractVerifierException.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/converter/ConversionContractVerifierException.groovy index 36fee3e329..415166ce64 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/converter/ConversionContractVerifierException.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/converter/ConversionContractVerifierException.groovy @@ -17,6 +17,7 @@ package org.springframework.cloud.contract.verifier.converter import groovy.transform.CompileStatic + import org.springframework.cloud.contract.spec.ContractVerifierException /** diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/converter/RecursiveFilesConverter.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/converter/RecursiveFilesConverter.groovy index 7293bd8401..e9898039d4 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/converter/RecursiveFilesConverter.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/converter/RecursiveFilesConverter.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2016 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 @@ -32,6 +32,7 @@ import org.springframework.cloud.contract.verifier.file.ContractFileScannerBuild import org.springframework.cloud.contract.verifier.file.ContractMetadata import org.springframework.cloud.contract.verifier.util.NamesUtil import org.springframework.cloud.contract.verifier.wiremock.DslToWireMockClientConverter + /** * Recursively converts contracts into their stub representations * @@ -58,11 +59,12 @@ class RecursiveFilesConverter { } void processFiles() { - ContractFileScanner scanner = new ContractFileScannerBuilder().baseDir(props.contractsDslDir) - .excluded(props.excludedFiles as Set) - .ignored([] as Set).included([] as Set) - .includeMatcher(props.includedContracts) - .build() + ContractFileScanner scanner = new ContractFileScannerBuilder(). + baseDir(props.contractsDslDir) + .excluded(props.excludedFiles as Set) + .ignored([] as Set).included([] as Set) + .includeMatcher(props.includedContracts) + .build() ListMultimap contracts = scanner.findContracts() if (log.isDebugEnabled()) { log.debug("Found the following contracts $contracts") @@ -73,11 +75,14 @@ class RecursiveFilesConverter { log.debug("Will create a stub for contract [${contract}]") } File sourceFile = contract.path.toFile() - Collection stubGenerators = contract.convertedContract ? holder.allOrDefault(new DslToWireMockClientConverter()) : + Collection stubGenerators = contract.convertedContract ? holder. + allOrDefault(new DslToWireMockClientConverter()) : holder.converterForName(sourceFile.name) try { String path = sourceFile.path - if (props.isExcludeBuildFolders() && (matchesPath(path, "target") || matchesPath(path, "build"))) { + if (props.isExcludeBuildFolders() + && ( + matchesPath(path, "target") || matchesPath(path, "build"))) { if (log.isDebugEnabled()) { log.debug("Exclude build folder is set. Path [${path}] contains [target] or [build] in its path") } @@ -92,22 +97,28 @@ class RecursiveFilesConverter { log.debug("Stub Generators [${stubGenerators}] will convert contents of [${entryKey}]") } stubGenerators.each { StubGenerator stubGenerator -> - Map convertedContent = stubGenerator.convertContents(entryKey.last().toString(), contract) + Map convertedContent = stubGenerator. + convertContents(entryKey.last().toString(), contract) if (!convertedContent) { return } - convertedContent.entrySet().eachWithIndex { Map.Entry content, int index -> - Contract dsl = content.key - String converted = content.value - if (converted) { - Path absoluteTargetPath = createAndReturnTargetDirectory(sourceFile) - File newJsonFile = createTargetFileWithProperName(stubGenerator, absoluteTargetPath, - sourceFile, contractsSize, index, dsl) - newJsonFile.setText(converted, StandardCharsets.UTF_8.toString()) - } - } + convertedContent.entrySet(). + eachWithIndex { Map.Entry content, int index -> + Contract dsl = content.key + String converted = content.value + if (converted) { + Path absoluteTargetPath = + createAndReturnTargetDirectory(sourceFile) + File newJsonFile = + createTargetFileWithProperName(stubGenerator, absoluteTargetPath, + sourceFile, contractsSize, index, dsl) + newJsonFile.setText(converted, StandardCharsets.UTF_8. + toString()) + } + } } - } catch (Exception e) { + } + catch (Exception e) { throw new ConversionContractVerifierException("Unable to make conversion of ${sourceFile.name}", e) } } @@ -119,14 +130,15 @@ class RecursiveFilesConverter { } private Path createAndReturnTargetDirectory(File sourceFile) { - Path relativePath = Paths.get(props.contractsDslDir.toURI()).relativize(sourceFile.parentFile.toPath()) + Path relativePath = Paths.get(props.contractsDslDir.toURI()). + relativize(sourceFile.parentFile.toPath()) Path absoluteTargetPath = outMappingsDir.toPath().resolve(relativePath) Files.createDirectories(absoluteTargetPath) return absoluteTargetPath } private File createTargetFileWithProperName(StubGenerator stubGenerator, Path absoluteTargetPath, - File sourceFile, int contractsSize, int index, Contract dsl) { + File sourceFile, int contractsSize, int index, Contract dsl) { String name = generateName(dsl, contractsSize, stubGenerator, sourceFile, index) File newJsonFile = new File(absoluteTargetPath.toFile(), name) log.info("Creating new stub [$newJsonFile.path]") @@ -134,13 +146,14 @@ class RecursiveFilesConverter { } private String generateName(Contract dsl, int contractsSize, StubGenerator converter, - File sourceFile, int index) { + File sourceFile, int index) { String generatedName = converter.generateOutputFileNameForInput(sourceFile.name) boolean hasDot = NamesUtil.hasDot(generatedName) String extension = hasDot ? NamesUtil.afterLastDot(generatedName) : "" if (dsl.name && extension) { return "${dsl.name}.${extension}" - } else if (contractsSize == 1) { + } + else if (contractsSize == 1) { return generatedName } return "${index}_${generatedName}" diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/converter/StubGenerator.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/converter/StubGenerator.groovy index d8aa0ef2f8..be5afc2906 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/converter/StubGenerator.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/converter/StubGenerator.groovy @@ -1,22 +1,23 @@ /* - * Copyright 2013-2016 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.Contract import org.springframework.cloud.contract.verifier.file.ContractMetadata @@ -29,18 +30,18 @@ import org.springframework.cloud.contract.verifier.file.ContractMetadata interface StubGenerator { /** - * Returns {@code true} if the converter can handle the file to convert it into a stub. + * @return {@code true} if the converter can handle the file to convert it into a stub. */ boolean canHandleFileName(String fileName) /** - * Returns the collection of converted contracts into stubs. One contract can + * @return the collection of converted contracts into stubs. One contract can * result in multiple stubs. */ Map convertContents(String rootName, ContractMetadata content) /** - * Returns the name of the converted stub file. If you have multiple contracts + * @return the name of the converted stub file. If you have multiple contracts * in a single file then a prefix will be added to the generated file. If you * provide the {@link Contract#name} field then that field will override the * generated file name. @@ -50,4 +51,4 @@ interface StubGenerator { * converter will create two files {@code 0_foo.json} and {@code 1_foo.json} */ String generateOutputFileNameForInput(String inputFileName) -} \ No newline at end of file +} diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/converter/StubGeneratorProvider.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/converter/StubGeneratorProvider.groovy index 0bc23eeef0..16eb8c9acc 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/converter/StubGeneratorProvider.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/converter/StubGeneratorProvider.groovy @@ -1,17 +1,34 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.core.io.support.SpringFactoriesLoader /** * Retrieves file converters from the class path and operates on them. - * + * * @author Marcin Grzejszczak * @since 1.1.0 */ @CompileStatic class StubGeneratorProvider { - + private final List converters = [] StubGeneratorProvider() { diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockClientConverter.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockClientConverter.groovy index e91db1f6a8..ec022a6997 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockClientConverter.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockClientConverter.groovy @@ -1,29 +1,28 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.Contract import org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockStubStrategy import org.springframework.cloud.contract.verifier.file.ContractMetadata import org.springframework.cloud.contract.verifier.util.NamesUtil -import java.nio.charset.StandardCharsets /** * Converts DSLs to WireMock stubs * @@ -42,13 +41,17 @@ class DslToWireMockClientConverter extends DslToWireMockConverter { return [:] } if (contract.convertedContract.size() == 1) { - return [(contract.convertedContract.first()): convertASingleContract(rootName, contract, contract.convertedContract.first())] + return [(contract.convertedContract.first()): + convertASingleContract(rootName, contract, contract.convertedContract. + first())] } Map convertedContracts = [:] - contract.convertedContract.findAll { it.request }.eachWithIndex { Contract dsl, int index -> - String name = dsl.name ? NamesUtil.convertIllegalPackageChars(dsl.name) : "${rootName}_${index}" - convertedContracts << [(dsl) : convertASingleContract(name, contract, dsl)] - } + contract.convertedContract.findAll { it.request }. + eachWithIndex { Contract dsl, int index -> + String name = dsl.name ? NamesUtil. + convertIllegalPackageChars(dsl.name) : "${rootName}_${index}" + convertedContracts << [(dsl): convertASingleContract(name, contract, dsl)] + } return convertedContracts } diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockConverter.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockConverter.groovy index aa27cdf082..deb0549c51 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockConverter.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockConverter.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 @@ -19,6 +19,7 @@ package org.springframework.cloud.contract.verifier.wiremock import groovy.transform.CompileStatic import org.springframework.cloud.contract.verifier.converter.StubGenerator + /** * WireMock implementation of the {@link StubGenerator} * diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/WireMockToDslConverter.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/WireMockToDslConverter.groovy index b89ceaadef..3ffee61f12 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/WireMockToDslConverter.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/groovy/org/springframework/cloud/contract/verifier/wiremock/WireMockToDslConverter.groovy @@ -1,31 +1,32 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 java.nio.charset.StandardCharsets + 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 org.springframework.cloud.contract.spec.Contract import repackaged.nl.flotsam.xeger.Xeger -import java.nio.charset.StandardCharsets +import org.springframework.cloud.contract.spec.Contract import static org.apache.commons.text.StringEscapeUtils.escapeJava @@ -38,7 +39,7 @@ import static org.apache.commons.text.StringEscapeUtils.escapeJava class WireMockToDslConverter { /** - * Returns the string content of the contract + * @return the string content of the contract * * @param wireMockStringStub - string content of the WireMock JSON stub */ @@ -59,32 +60,50 @@ class WireMockToDslConverter { request { ${request.method ? "method \"\"\"$request.method\"\"\"" : ""} ${request.url ? "url \"\"\"$request.url\"\"\"" : ""} - ${urlPattern ? "url \$(consumer(regex('${escapeJava(urlPattern)}')), producer('${new Xeger(escapeJava(urlPattern)).generate()}'))" : ""} - ${urlPathPattern ? "urlPath \$(consumer(regex('${escapeJava(urlPattern)}')), producer('${new Xeger(escapeJava(urlPattern)).generate()}'))" : ""} + ${ + urlPattern ? "url \$(consumer(regex('${escapeJava(urlPattern)}')), producer('${new Xeger(escapeJava(urlPattern)).generate()}'))" : "" + } + ${ + urlPathPattern ? "urlPath \$(consumer(regex('${escapeJava(urlPattern)}')), producer('${new Xeger(escapeJava(urlPattern)).generate()}'))" : "" + } ${request.urlPath ? "url \"\"\"$request.urlPath\"\"\"" : ""} ${ - request.headers ? """headers { + request.headers ? """headers { ${ - request.headers.collect { - def assertion = it.value - String headerName = it.key as String - def entry = assertion.entrySet().first() - """header(\"\"\"$headerName\"\"\", ${buildHeader(entry.key, entry.value)})\n""" - }.join('') - } + request.headers.collect { + def assertion = it.value + String headerName = it.key as String + def entry = assertion.entrySet().first() + """header(\"\"\"$headerName\"\"\", ${ + buildHeader(entry.key, entry.value) + })\n""" + }.join('') + } } """ : "" - } - ${bodyPatterns?.equalTo?.every { it } ? "body('''${bodyPatterns.equalTo[0]}''')" : ''} - ${bodyPatterns?.equalToJson?.every { it } ? "body('''${bodyPatterns.equalToJson[0]}''')" : ''} - ${bodyPatterns?.matches?.every { it } ? "body \$(consumer(regex('${escapeJava(bodyPatterns.matches[0])}')), producer('${new Xeger(escapeJava(bodyPatterns.matches[0])).generate()}'))" : ""} + } + ${ + bodyPatterns?.equalTo?. + every { it } ? "body('''${bodyPatterns.equalTo[0]}''')" : '' + } + ${ + bodyPatterns?.equalToJson?. + every { it } ? "body('''${bodyPatterns.equalToJson[0]}''')" : '' + } + ${ + bodyPatterns?.matches?.every { + it + } ? "body \$(consumer(regex('${escapeJava(bodyPatterns.matches[0])}')), producer('${new Xeger(escapeJava(bodyPatterns.matches[0])).generate()}'))" : "" + } } response { ${response.status ? "status $response.status" : ""} ${response.body ? "body( ${buildBody(response.body)})" : ""} ${ response.headers ? """headers { - ${response.headers.collect { "header('$it.key': '${it.value}')\n" }.join('')} + ${ + response.headers.collect { "header('$it.key': '${it.value}')\n" }.join('') + } } """ : "" } @@ -98,19 +117,21 @@ class WireMockToDslConverter { private String buildHeader(String method, Object value) { switch (method) { - case 'equalTo': - return wrapWithMultilineGString(value) - default: - return "regex(${wrapWithMultilineGString(escapeJava(value as String))})" + case 'equalTo': + return wrapWithMultilineGString(value) + default: + return "regex(${wrapWithMultilineGString(escapeJava(value as String))})" } } private Object buildBody(Map responseBody) { - return responseBody.entrySet().collectAll(withQuotedMapStringElements()).inject([:], appendToIterable()) + return responseBody.entrySet().collectAll(withQuotedMapStringElements()). + inject([:], appendToIterable()) } private Object buildBody(List responseBody) { - return responseBody.collectAll(withQuotedStringElements()).inject([], appendToIterable()) + return responseBody.collectAll(withQuotedStringElements()). + inject([], appendToIterable()) } private Object buildBody(Integer responseBody) { @@ -121,11 +142,13 @@ class WireMockToDslConverter { try { def json = new JsonSlurper().parseText(responseBody) return wrapWithMultilineGString(JsonOutput.prettyPrint(responseBody)) - } catch (Exception jsonException) { + } + catch (Exception jsonException) { try { def xml = new XmlSlurper().parseText(responseBody) return wrapWithMultilineGString(XmlUtil.serialize(responseBody)) - } catch (Exception xmlException) { + } + catch (Exception xmlException) { return wrapWithMultilineGString(responseBody) } } @@ -187,12 +210,17 @@ class WireMockToDslConverter { if (!it.name.endsWith('json')) { return } - String dslFromWireMockStub = fromWireMockStub(it.getText(StandardCharsets.UTF_8.toString())) - String dslWrappedWithFactoryMethod = wrapWithFactoryMethod(dslFromWireMockStub) - File newGroovyFile = new File(it.parent, it.name.replaceAll('json', 'groovy')) + String dslFromWireMockStub = + fromWireMockStub(it.getText(StandardCharsets.UTF_8.toString())) + String dslWrappedWithFactoryMethod = + wrapWithFactoryMethod(dslFromWireMockStub) + File newGroovyFile = new File(it.parent, it.name. + replaceAll('json', 'groovy')) println("Creating new groovy file [$newGroovyFile.path]") - newGroovyFile.setText(dslWrappedWithFactoryMethod, StandardCharsets.UTF_8.toString()) - } catch (Exception e) { + newGroovyFile.setText(dslWrappedWithFactoryMethod, StandardCharsets.UTF_8. + toString()) + } + catch (Exception e) { System.err.println(e) } diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/resources/META-INF/spring.factories b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/resources/META-INF/spring.factories index 7078832188..9c00e75f2b 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/main/resources/META-INF/spring.factories @@ -1,3 +1,3 @@ # Stub converters org.springframework.cloud.contract.verifier.converter.StubGenerator=\ -org.springframework.cloud.contract.verifier.wiremock.DslToWireMockClientConverter \ No newline at end of file +org.springframework.cloud.contract.verifier.wiremock.DslToWireMockClientConverter diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/converter/RecursiveFilesConverterSpec.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/converter/RecursiveFilesConverterSpec.groovy index 7469d1f622..82e4e2a051 100755 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/converter/RecursiveFilesConverterSpec.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/converter/RecursiveFilesConverterSpec.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 @@ -52,7 +52,7 @@ class RecursiveFilesConverterSpec extends Specification { given: ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties() File originalSourceRootDirectory = new File(this.getClass() - .getResource("/converter/source").toURI()) + .getResource("/converter/source").toURI()) properties.contractsDslDir = tmpFolder.newFolder("source") properties.stubsOutputDir = tmpFolder.newFolder("target") FileSystemUtils @@ -76,7 +76,7 @@ class RecursiveFilesConverterSpec extends Specification { given: ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties() File originalSourceRootDirectory = new File(this.getClass() - .getResource("/converter/source").toURI()) + .getResource("/converter/source").toURI()) properties.contractsDslDir = tmpFolder.newFolder("source") properties.stubsOutputDir = tmpFolder.newFolder("target") properties.excludedFiles = ["dir1/**"] diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockClientConverterSpec.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockClientConverterSpec.groovy index 643f08e55c..e185de2809 100755 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockClientConverterSpec.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/DslToWireMockClientConverterSpec.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 @@ -43,8 +43,10 @@ import org.springframework.util.SocketUtils class DslToWireMockClientConverterSpec extends Specification { int port = SocketUtils.findAvailableTcpPort() - @Rule public WireMockRule wireMockRule = new WireMockRule(port) - @Rule public TemporaryFolder tmpFolder = new TemporaryFolder() + @Rule + public WireMockRule wireMockRule = new WireMockRule(port) + @Rule + public TemporaryFolder tmpFolder = new TemporaryFolder() TestRestTemplate restTemplate = new TestRestTemplate() String url @@ -70,9 +72,9 @@ class DslToWireMockClientConverterSpec extends Specification { """) when: String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null, - ContractVerifierDslConverter.convertAsCollection(new File("/"),file))).values().first() + ContractVerifierDslConverter.convertAsCollection(new File("/"), file))).values().first() then: - JSONAssert.assertEquals(''' + JSONAssert.assertEquals(''' {"request":{"method":"PUT","urlPattern":"/[0-9]{2}"},"response":{"status":200}} ''', json, false) and: @@ -114,9 +116,9 @@ class DslToWireMockClientConverterSpec extends Specification { """) when: String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null, - ContractVerifierDslConverter.convertAsCollection(new File("/"),file))).values().first() + ContractVerifierDslConverter.convertAsCollection(new File("/"), file))).values().first() then: - JSONAssert.assertEquals(''' + JSONAssert.assertEquals(''' {"request":{"url":"/multipart","method":"POST","headers":{"Content-Type":{"matches":"multipart/form-data.*"}},"bodyPatterns":[{"matches" : ".*--(.*)\\r\\nContent-Disposition: form-data; name=\\"file\\"; filename=\\".+\\"\\r\\n(Content-Type: .*\\r\\n)?(Content-Transfer-Encoding: .*\\r\\n)?(Content-Length: \\\\d+\\r\\n)?\\r\\n.+\\r\\n--\\\\1.*"}]},"response":{"status":200,"body":"hello","transformers":["response-template"]}} ''', json, false) and: @@ -127,7 +129,7 @@ class DslToWireMockClientConverterSpec extends Specification { MultiValueMap parameters = new LinkedMultiValueMap() parameters.add("file", new ByteArrayResource([100, 117, 100, 97] as byte[]) { @Override - String getFilename(){ + String getFilename() { return "file" } }) @@ -164,7 +166,7 @@ class DslToWireMockClientConverterSpec extends Specification { ''') when: Map convertedContents = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null, - ContractVerifierDslConverter.convertAsCollection(new File("/"),file))) + ContractVerifierDslConverter.convertAsCollection(new File("/"), file))) then: convertedContents.size() == 2 JSONAssert.assertEquals(jsonResponse(1), convertedContents.values().first(), false) @@ -177,11 +179,11 @@ class DslToWireMockClientConverterSpec extends Specification { wireMockRule.addStubMapping(mapping2) and: restTemplate.exchange(RequestEntity.put("${url}/1".toURI()) - .header('Content-Type', 'application/json') - .body(""), String) + .header('Content-Type', 'application/json') + .body(""), String) restTemplate.exchange(RequestEntity.put("${url}/2".toURI()) - .header('Content-Type', 'application/json') - .body(""), String) + .header('Content-Type', 'application/json') + .body(""), String) } private String jsonResponse(int index) { @@ -205,7 +207,7 @@ class DslToWireMockClientConverterSpec extends Specification { when: Map convertedContents = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null, - ContractVerifierDslConverter.convertAsCollection(new File("/"),file))) + ContractVerifierDslConverter.convertAsCollection(new File("/"), file))) then: convertedContents.isEmpty() } @@ -230,7 +232,7 @@ class DslToWireMockClientConverterSpec extends Specification { """) when: String json = converter.convertContents("test", new ContractMetadata(file.toPath(), false, 0, null, - ContractVerifierDslConverter.convertAsCollection(new File("/"),file))).values().first() + ContractVerifierDslConverter.convertAsCollection(new File("/"), file))).values().first() then: JSONAssert.assertEquals(''' {"request":{ @@ -299,9 +301,9 @@ class DslToWireMockClientConverterSpec extends Specification { """) when: String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null, - ContractVerifierDslConverter.convertAsCollection(new File("/"),file))).values().first() + ContractVerifierDslConverter.convertAsCollection(new File("/"), file))).values().first() then: - JSONAssert.assertEquals(''' + JSONAssert.assertEquals(''' { "request" : { "url" : "/api/12", @@ -356,8 +358,8 @@ class DslToWireMockClientConverterSpec extends Specification { wireMockRule.addStubMapping(mapping) and: restTemplate.exchange(RequestEntity.put("${url}/api/12".toURI()) - .header('Content-Type', 'application/vnd.org.springframework.cloud.contract.verifier.twitter-places-analyzer.v1+json') - .body(''' + .header('Content-Type', 'application/vnd.org.springframework.cloud.contract.verifier.twitter-places-analyzer.v1+json') + .body(''' [{ "created_at": "Sat Jul 26 09:38:57 +0000 2014", "id": 492967299297845248, @@ -417,7 +419,7 @@ class DslToWireMockClientConverterSpec extends Specification { """) when: String json = converter.convertContents("test", new ContractMetadata(file.toPath(), false, 0, null, - ContractVerifierDslConverter.convertAsCollection(new File("/"),file))).values().first() + ContractVerifierDslConverter.convertAsCollection(new File("/"), file))).values().first() then: JSONAssert.assertEquals(''' {"request":{"urlPath":"/foos","method":"GET"},"response":{"body":"[{\\"id\\":\\"123\\"},{\\"id\\":\\"567\\"}]"}} @@ -456,7 +458,7 @@ class DslToWireMockClientConverterSpec extends Specification { """) when: String json = converter.convertContents("test", new ContractMetadata(file.toPath(), false, 0, null, - ContractVerifierDslConverter.convertAsCollection(new File("/"),file))).values().first() + ContractVerifierDslConverter.convertAsCollection(new File("/"), file))).values().first() then: noExceptionThrown() and: @@ -503,10 +505,10 @@ class DslToWireMockClientConverterSpec extends Specification { ''') when: String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null, - ContractVerifierDslConverter.convertAsCollection(new File("/"),file))).values().first() + ContractVerifierDslConverter.convertAsCollection(new File("/"), file))).values().first() then: JSONAssert.assertEquals( // tag::wiremock[] -''' + ''' { "request" : { "url" : "/users/password", @@ -533,15 +535,15 @@ class DslToWireMockClientConverterSpec extends Specification { } ''' // end::wiremock[] - , json, false) + , json, false) and: StubMapping mapping = stubMappingIsValidWireMockStub(json) and: wireMockRule.addStubMapping(mapping) and: def response = restTemplate.exchange(RequestEntity.post("${url}/users/password".toURI()) - .header("Content-Type", "application/json") - .body('''{"email":"abc@abc.com", "callback_url":"http://partners.com"}''') + .header("Content-Type", "application/json") + .body('''{"email":"abc@abc.com", "callback_url":"http://partners.com"}''') , String) response.headers.get('Content-Type') == ['application/json'] response.statusCodeValue == 404 @@ -691,10 +693,10 @@ class DslToWireMockClientConverterSpec extends Specification { ''') when: String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null, - ContractVerifierDslConverter.convertAsCollection(new File("/"),file))).values().first() + ContractVerifierDslConverter.convertAsCollection(new File("/"), file))).values().first() then: JSONAssert.assertEquals(//tag::matchers[] - ''' + ''' { "request" : { "urlPath" : "/get", @@ -755,75 +757,75 @@ class DslToWireMockClientConverterSpec extends Specification { } ''' //end::matchers[] - , json, false) + , json, false) and: StubMapping mapping = stubMappingIsValidWireMockStub(json) and: wireMockRule.addStubMapping(mapping) and: def response = restTemplate.exchange(RequestEntity.post("${url}/get".toURI()) - .header("Content-Type", "application/json") - .body(JsonOutput.toJson([ - duck: 123, - alpha: "abc", - number: 123, - aBoolean: true, - date: "2017-01-01", - dateTime: "2017-01-01T01:23:45", - time: "01:02:34", - valueWithoutAMatcher: "foo", - valueWithTypeMatch: "string", - list: [ - some: [ - nested: [ - json: "with value", - anothervalue: 4 - ] - ], - someother: [ - nested: [ - json: "with value", - anothervalue: 4 - ] - ] - ], - valueWithMin: [ - 1,2,3 - ], - valueWithMax: [ - 1,2,3 - ], - valueWithMinMax: [ - 1,2,3 - ], - valueWithOccurrence: [ - 1,2,3,4 - ] - ])) + .header("Content-Type", "application/json") + .body(JsonOutput.toJson([ + duck : 123, + alpha : "abc", + number : 123, + aBoolean : true, + date : "2017-01-01", + dateTime : "2017-01-01T01:23:45", + time : "01:02:34", + valueWithoutAMatcher: "foo", + valueWithTypeMatch : "string", + list : [ + some : [ + nested: [ + json : "with value", + anothervalue: 4 + ] + ], + someother: [ + nested: [ + json : "with value", + anothervalue: 4 + ] + ] + ], + valueWithMin : [ + 1, 2, 3 + ], + valueWithMax : [ + 1, 2, 3 + ], + valueWithMinMax : [ + 1, 2, 3 + ], + valueWithOccurrence : [ + 1, 2, 3, 4 + ] + ])) , String) response.headers.get('Content-Type') == ['application/json'] response.statusCodeValue == 200 JSONAssert.assertEquals(JsonOutput.toJson([ - duck: 123, - alpha: "abc", - number: 123, - aBoolean: true, - date: "2017-01-01", - dateTime: "2017-01-01T01:23:45", - time: "01:02:34", + duck : 123, + alpha : "abc", + number : 123, + aBoolean : true, + date : "2017-01-01", + dateTime : "2017-01-01T01:23:45", + time : "01:02:34", valueWithoutAMatcher: "foo", - valueWithTypeMatch: "string", - valueWithMin: [ - 1,2,3 + valueWithTypeMatch : "string", + valueWithMin : [ + 1, 2, 3 ], - valueWithMax: [ - 1,2,3 + valueWithMax : [ + 1, 2, 3 ], - valueWithMinMax: [ - 1,2,3 + valueWithMinMax : [ + 1, 2, 3 ], - valueWithOccurrence: [ - 1,2,3,4 + valueWithOccurrence : [ + 1, 2, 3, 4 ], ]), response.body, false) } @@ -869,7 +871,7 @@ class DslToWireMockClientConverterSpec extends Specification { ''') when: String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null, - ContractVerifierDslConverter.convertAsCollection(new File("/"),file))).values().first() + ContractVerifierDslConverter.convertAsCollection(new File("/"), file))).values().first() then: JSONAssert.assertEquals( ''' @@ -898,15 +900,15 @@ class DslToWireMockClientConverterSpec extends Specification { "priority" : 1 } ''' - , json, false) + , json, false) and: StubMapping mapping = stubMappingIsValidWireMockStub(json) and: wireMockRule.addStubMapping(mapping) and: def response = restTemplate.exchange(RequestEntity.post("${url}/users/password2".toURI()) - .header("Content-Type", "application/json") - .body('''{"email":"abc@abc.com", "callback_url":"http://partners.com"}''') + .header("Content-Type", "application/json") + .body('''{"email":"abc@abc.com", "callback_url":"http://partners.com"}''') , String) response.headers.get('Content-Type') == ['application/json'] response.statusCodeValue == 404 @@ -964,7 +966,7 @@ class DslToWireMockClientConverterSpec extends Specification { ''') when: String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null, - ContractVerifierDslConverter.convertAsCollection(new File("/"),file))).values().first() + ContractVerifierDslConverter.convertAsCollection(new File("/"), file))).values().first() then: JSONAssert.assertEquals( ''' @@ -996,15 +998,15 @@ class DslToWireMockClientConverterSpec extends Specification { } } ''' - , json, false) + , json, false) and: StubMapping mapping = stubMappingIsValidWireMockStub(json) and: wireMockRule.addStubMapping(mapping) and: def response = restTemplate.exchange(RequestEntity.post("${url}/users/password2".toURI()) - .header("Content-Type", "application/json") - .body('''{"email":"abc@abc.com", "callback_url":"http://partners.com"}''') + .header("Content-Type", "application/json") + .body('''{"email":"abc@abc.com", "callback_url":"http://partners.com"}''') , String) response.headers.get('Content-Type') == ['application/json;charset=UTF-8'] response.statusCodeValue == 400 @@ -1039,7 +1041,7 @@ class DslToWireMockClientConverterSpec extends Specification { ''') when: String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null, - ContractVerifierDslConverter.convertAsCollection(new File("/"),file))).values().first() + ContractVerifierDslConverter.convertAsCollection(new File("/"), file))).values().first() then: JSONAssert.assertEquals( ''' @@ -1058,7 +1060,7 @@ class DslToWireMockClientConverterSpec extends Specification { } } ''' - , json, false) + , json, false) and: StubMapping mapping = stubMappingIsValidWireMockStub(json) and: diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/WireMockToDslConverterSpec.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/WireMockToDslConverterSpec.groovy index 888f237952..f0c06240bb 100755 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/WireMockToDslConverterSpec.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/WireMockToDslConverterSpec.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 @@ -134,7 +134,7 @@ class WireMockToDslConverterSpec extends Specification { } response { status OK() - body( """{ + body("""{ "status": "OK" }""") headers { @@ -239,7 +239,7 @@ class WireMockToDslConverterSpec extends Specification { } response { status OK() - body( """[ + body("""[ { "a": 1, "c": "3" @@ -349,7 +349,7 @@ class WireMockToDslConverterSpec extends Specification { request { method 'POST' url '/test' - body ('''{"property1":"abc", "property2":"2017-01", "property3":"666", "property4":1428566412}''') + body('''{"property1":"abc", "property2":"2017-01", "property3":"666", "property4":1428566412}''') } response { status OK() diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/WiremockScenarioConverterSpec.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/WiremockScenarioConverterSpec.groovy index e79c9c6f66..b9af6aaade 100755 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/WiremockScenarioConverterSpec.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/groovy/org/springframework/cloud/contract/verifier/wiremock/WiremockScenarioConverterSpec.groovy @@ -1,28 +1,29 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 org.springframework.cloud.contract.verifier.file.ContractMetadata -import org.springframework.cloud.contract.verifier.util.ContractVerifierDslConverter -import spock.lang.Specification - import java.nio.file.Path import java.nio.file.Paths +import spock.lang.Specification + +import org.springframework.cloud.contract.verifier.file.ContractMetadata +import org.springframework.cloud.contract.verifier.util.ContractVerifierDslConverter + class WiremockScenarioConverterSpec extends Specification { def "should generate first scenario step"() { diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/scenario/main_scenario/01_login.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/scenario/main_scenario/01_login.groovy index 90629128a6..e8b44c7f98 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/scenario/main_scenario/01_login.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/scenario/main_scenario/01_login.groovy @@ -1,21 +1,21 @@ -import org.springframework.cloud.contract.spec.Contract - /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.Contract + Contract.make { request { method('POST') diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/scenario/main_scenario/02_showCart.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/scenario/main_scenario/02_showCart.groovy index 783acfe662..331a51b20c 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/scenario/main_scenario/02_showCart.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/scenario/main_scenario/02_showCart.groovy @@ -1,21 +1,21 @@ -import org.springframework.cloud.contract.spec.Contract - /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.Contract + Contract.make { request { method('GET') diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/scenario/main_scenario/03_logout.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/scenario/main_scenario/03_logout.groovy index bbd0223e57..989ea6a0f0 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/scenario/main_scenario/03_logout.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/scenario/main_scenario/03_logout.groovy @@ -1,21 +1,21 @@ -import org.springframework.cloud.contract.spec.Contract - /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.Contract + Contract.make { request { method('POST') diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/1_scenario.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/1_scenario.groovy index d3926eea96..6e4ac7c84f 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/1_scenario.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/1_scenario.groovy @@ -1,18 +1,17 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT 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.spec.Contract diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/2_scenario.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/2_scenario.groovy index e09d8a13f9..6e4ac7c84f 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/2_scenario.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/2_scenario.groovy @@ -1,21 +1,21 @@ -import org.springframework.cloud.contract.spec.Contract - /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.Contract + Contract.make { request { method('PUT') diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1.groovy index e09d8a13f9..6e4ac7c84f 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1.groovy @@ -1,21 +1,21 @@ -import org.springframework.cloud.contract.spec.Contract - /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.Contract + Contract.make { request { method('PUT') diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1_list.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1_list.groovy index 2c412a2ca8..fa3aae3003 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1_list.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1_list.groovy @@ -1,21 +1,21 @@ -import org.springframework.cloud.contract.spec.Contract - /* - * Copyright 2013-2016 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.Contract + (1..2).collect { int index -> Contract.make { request { @@ -29,4 +29,4 @@ import org.springframework.cloud.contract.spec.Contract status OK() } } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1_list2.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1_list2.groovy index def698a873..ad7aa3db53 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1_list2.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1_list2.groovy @@ -1,21 +1,21 @@ -import org.springframework.cloud.contract.spec.Contract - /* - * Copyright 2013-2016 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.Contract + (1..2).collect { int index -> Contract.make { name("shouldHaveIndex${index}") @@ -30,4 +30,4 @@ import org.springframework.cloud.contract.spec.Contract status OK() } } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1b.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1b.groovy index e09d8a13f9..6e4ac7c84f 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1b.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/dsl1b.groovy @@ -1,21 +1,21 @@ -import org.springframework.cloud.contract.spec.Contract - /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.Contract + Contract.make { request { method('PUT') diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/scenario.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/scenario.groovy index bb28c0fb65..48d04b98a7 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/scenario.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir1/scenario.groovy @@ -1,47 +1,47 @@ -import org.springframework.cloud.contract.spec.Contract - /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT 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.spec.Contract + [ - Contract.make { - name("1_scenario_multiple") - request { - method('PUT') - headers { - header 'Content-Type': 'application/json' - } - url $(consumer('/[0-9]{2}'), producer('/12')) - } - response { - status OK() - } - }, - Contract.make { - name("2_scenario_multiple") - request { - method('PUT') - headers { - header 'Content-Type': 'application/json' - } - url $(consumer('/[0-9]{2}'), producer('/12')) - } - response { - status OK() + Contract.make { + name("1_scenario_multiple") + request { + method('PUT') + headers { + header 'Content-Type': 'application/json' } + url $(consumer('/[0-9]{2}'), producer('/12')) } + response { + status OK() + } + }, + Contract.make { + name("2_scenario_multiple") + request { + method('PUT') + headers { + header 'Content-Type': 'application/json' + } + url $(consumer('/[0-9]{2}'), producer('/12')) + } + response { + status OK() + } + } ] diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir2/dsl2.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir2/dsl2.groovy index e09d8a13f9..6e4ac7c84f 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir2/dsl2.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dir2/dsl2.groovy @@ -1,21 +1,21 @@ -import org.springframework.cloud.contract.spec.Contract - /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.Contract + Contract.make { request { method('PUT') diff --git a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dslRoot.groovy b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dslRoot.groovy index e09d8a13f9..6e4ac7c84f 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dslRoot.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-converters/src/test/resources/converter/source/dslRoot.groovy @@ -1,21 +1,21 @@ -import org.springframework.cloud.contract.spec.Contract - /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.spec.Contract + Contract.make { request { method('PUT') diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/build.gradle b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/build.gradle index afb2b31066..3620922ef6 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/build.gradle +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/build.gradle @@ -5,12 +5,16 @@ buildscript { mavenCentral() mavenLocal() maven { url 'https://repo.spring.io/plugins-release' } - if (project.hasProperty('fatJar')) jcenter() + if (project.hasProperty('fatJar')) { + jcenter() + } } dependencies { 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' + if (project.hasProperty('fatJar')) { + classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3' + } } } @@ -18,10 +22,10 @@ ext { repoUser = System.getenv('REPO_USERNAME') ?: project.findProperty('REPO_USERNAME') ?: '' repoPass = System.getenv('REPO_PASSWORD') ?: project.findProperty('REPO_PASSWORD') ?: '' - contractVerifierGradlePluginLibsDir ="$buildDir/contractVerifier-gradle-plugin-libs" + contractVerifierGradlePluginLibsDir = "$buildDir/contractVerifier-gradle-plugin-libs" testSystemProperties = [ 'contract-gradle-plugin-libs-dir': contractVerifierGradlePluginLibsDir, - "WORK_OFFLINE" : gradle.startParameter.isOffline() ? 'TRUE' : 'FALSE' + "WORK_OFFLINE" : gradle.startParameter.isOffline() ? 'TRUE' : 'FALSE' ] JavaVersion javaVer = JavaVersion.current() println "Current Java version equal to [${javaVer}]" @@ -86,7 +90,7 @@ dependencies { } task libtest() { - doLast{ + doLast { configurations.testCompile.files.each { println it } } } @@ -152,4 +156,4 @@ task resolveDependencies { task wrapper(type: Wrapper) { gradleVersion = '4.10.2' -} \ No newline at end of file +} diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradle.properties b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradle.properties index 30a420ed89..5bd673e0b2 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradle.properties +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradle.properties @@ -13,10 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - -nexusUsername = -nexusPassword = +nexusUsername= +nexusPassword= verifierVersion=2.1.1.BUILD-SNAPSHOT org.gradle.daemon=false aetherVersion=1.1.0 -springCloudBuildVersion=2.1.3.BUILD-SNAPSHOT \ No newline at end of file +springCloudBuildVersion=2.1.3.BUILD-SNAPSHOT diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradle/release.gradle b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradle/release.gradle index 62f1cc1206..9a439142ba 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradle/release.gradle +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradle/release.gradle @@ -38,8 +38,12 @@ ext { isReleaseToCentral = project.hasProperty('central') resolveVersion = { String version -> - if (isMilestoneVersion) return 'milestone' - if (isReleaseVersion) return 'release' + if (isMilestoneVersion) { + return 'milestone' + } + if (isReleaseVersion) { + return 'release' + } return 'snapshot' } @@ -109,4 +113,4 @@ afterEvaluate { } } } -} \ No newline at end of file +} diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/pom.xml b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/pom.xml index 2b69427f46..65da0e8d81 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/pom.xml +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/pom.xml @@ -1,7 +1,7 @@ - - 4.0.0 + + 4.0.0 org.springframework.cloud diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/ContractVerifierExtension.groovy b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/ContractVerifierExtension.groovy index c8432ca5e0..17f8863cbc 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/ContractVerifierExtension.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/ContractVerifierExtension.groovy @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties import org.springframework.cloud.contract.verifier.config.TestFramework import org.springframework.cloud.contract.verifier.config.TestMode + /** * @author Marcin Grzejszczak */ @@ -137,7 +138,7 @@ class ContractVerifierExtension { Boolean assertJsonSize = false ContractRepository contractRepository = new ContractRepository() - + /** * Dependency that contains packaged contracts */ @@ -248,8 +249,8 @@ class ContractVerifierExtension { nameSuffixForTests: this.nameSuffixForTests, ruleClassForTests: this.ruleClassForTests, excludedFiles: new ArrayList(this.excludedFiles), - includedFiles: new ArrayList(this.includedFiles), - ignoredFiles: new ArrayList(this.ignoredFiles), + includedFiles: new ArrayList(this.includedFiles), + ignoredFiles: new ArrayList(this.ignoredFiles), imports: Arrays.asList(this.imports).toArray(), staticImports: Arrays.asList(this.staticImports).toArray(), contractsDslDir: this.contractsDslDir, diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/ContractsCopyTask.groovy b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/ContractsCopyTask.groovy index 2610850713..113a2a465e 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/ContractsCopyTask.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/ContractsCopyTask.groovy @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/ExtensionHolderSpec.groovy b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/ExtensionHolderSpec.groovy index 9a29bd1ec6..72e4164dbc 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/ExtensionHolderSpec.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/ExtensionHolderSpec.groovy @@ -25,5 +25,6 @@ package org.springframework.cloud.contract.verifier.plugin */ interface ExtensionHolderSpec { Closure getExtensionClosure() + void setExtensionClosure(Closure closure) -} \ No newline at end of file +} diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/ExtensionToProperties.groovy b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/ExtensionToProperties.groovy index 21a8eecbbf..71099d0156 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/ExtensionToProperties.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/ExtensionToProperties.groovy @@ -2,6 +2,7 @@ package org.springframework.cloud.contract.verifier.plugin import groovy.transform.CompileStatic import groovy.transform.PackageScope + import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties /** diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/GenerateClientStubsFromDslTask.groovy b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/GenerateClientStubsFromDslTask.groovy index 343712eac4..7106d6b22e 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/GenerateClientStubsFromDslTask.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/GenerateClientStubsFromDslTask.groovy @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,10 +19,12 @@ package org.springframework.cloud.contract.verifier.plugin import org.gradle.api.Task import org.gradle.api.internal.ConventionTask import org.gradle.api.tasks.TaskAction + import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties import org.springframework.cloud.contract.verifier.converter.RecursiveFilesConverter import static org.springframework.cloud.contract.verifier.plugin.SpringCloudContractVerifierGradlePlugin.COPY_CONTRACTS_TASK_NAME + //TODO: Implement as an incremental task: https://gradle.org/docs/current/userguide/custom_tasks.html#incremental_tasks ? /** * Generates stubs from the contracts. The name is WireMock related but the implementation @@ -55,7 +57,8 @@ class GenerateClientStubsFromDslTask extends ConventionTask { private ContractVerifierConfigProperties props(Task task) { try { return task.ext.contractVerifierConfigProperties - } catch (Exception e) { + } + catch (Exception e) { project.logger.error("Couldn't retrieve the configuration property set by the copy contracts task", e) ContractVerifierConfigProperties props = ExtensionToProperties.fromExtension(getConfigProperties()) getDownloader().downloadAndUnpackContractsIfRequired(getConfigProperties(), props) @@ -66,7 +69,8 @@ class GenerateClientStubsFromDslTask extends ConventionTask { private File contractsDslDir(Task task, ContractVerifierConfigProperties props) { try { return task.ext.contractsDslDir - } catch (Exception e) { + } + catch (Exception e) { project.logger.error("Couldn't retrieve the contract dsl property set by the copy contracts task", e) return props.contractsDslDir } diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/GenerateServerTestsTask.groovy b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/GenerateServerTestsTask.groovy index 8f54283b54..016fbe4b34 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/GenerateServerTestsTask.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/GenerateServerTestsTask.groovy @@ -1,17 +1,17 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2019 the original author or authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 @@ -72,7 +72,8 @@ class GenerateServerTestsTask extends ConventionTask { TestGenerator generator = new TestGenerator(props) int generatedClasses = generator.generate() project.logger.info("Generated {} test classes", generatedClasses) - } catch (ContractVerifierException e) { + } + catch (ContractVerifierException e) { throw new GradleException("Spring Cloud Contract Verifier Plugin exception: ${e.message}", e) } } @@ -80,7 +81,8 @@ class GenerateServerTestsTask extends ConventionTask { private ContractVerifierConfigProperties props(Task task) { try { return task.ext.contractVerifierConfigProperties - } catch (Exception e) { + } + catch (Exception e) { project.logger.error("Couldn't retrieve the configuration property set by the copy contracts task", e) ContractVerifierConfigProperties props = ExtensionToProperties.fromExtension(getConfigProperties()) getDownloader().downloadAndUnpackContractsIfRequired(getConfigProperties(), props) @@ -91,7 +93,8 @@ class GenerateServerTestsTask extends ConventionTask { private File contractsDslDir(Task task, ContractVerifierConfigProperties props) { try { return task.ext.contractsDslDir - } catch (Exception e) { + } + catch (Exception e) { project.logger.error("Couldn't retrieve the contract dsl property set by the copy contracts task", e) return props.contractsDslDir } diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/GradleContractsDownloader.groovy b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/GradleContractsDownloader.groovy index 40339b9820..fe5e82b887 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/GradleContractsDownloader.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/GradleContractsDownloader.groovy @@ -1,9 +1,12 @@ package org.springframework.cloud.contract.verifier.plugin +import java.util.concurrent.ConcurrentHashMap + import groovy.transform.CompileStatic import groovy.transform.PackageScope import org.gradle.api.Project import org.gradle.api.logging.Logger + import org.springframework.cloud.contract.stubrunner.ContractDownloader import org.springframework.cloud.contract.stubrunner.StubConfiguration import org.springframework.cloud.contract.stubrunner.StubDownloader @@ -13,7 +16,6 @@ import org.springframework.cloud.contract.stubrunner.StubRunnerOptionsBuilder import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties import org.springframework.util.StringUtils -import java.util.concurrent.ConcurrentHashMap /** * @author Marcin Grzejszczak */ @@ -26,14 +28,14 @@ class GradleContractsDownloader { private final Project project private final Logger log protected static final Map downloadedContract = new ConcurrentHashMap<>() - + GradleContractsDownloader(Project project, Logger log) { this.project = project this.log = log } - + File downloadAndUnpackContractsIfRequired(ContractVerifierExtension extension, - ContractVerifierConfigProperties config) { + ContractVerifierConfigProperties config) { File defaultContractsDir = extension.contractsDslDir this.log.info("Project has group id [{}], artifact id [{}]", this.project.group, this.project.name) // download contracts, unzip them and pass as output directory @@ -73,12 +75,12 @@ class GradleContractsDownloader { } protected StubDownloader stubDownloader(ContractVerifierExtension extension) { - StubDownloaderBuilderProvider provider = new StubDownloaderBuilderProvider() + StubDownloaderBuilderProvider provider = new StubDownloaderBuilderProvider() return provider.get(options(extension)) } protected StubRunnerOptions options(ContractVerifierExtension extension) { - StubRunnerOptionsBuilder options = new StubRunnerOptionsBuilder() + StubRunnerOptionsBuilder options = new StubRunnerOptionsBuilder() .withOptions(StubRunnerOptions.fromSystemProps()) .withStubRepositoryRoot(extension.contractRepository.repositoryUrl) .withStubsMode(extension.contractsMode) @@ -92,7 +94,8 @@ class GradleContractsDownloader { return options.build() } - @PackageScope StubConfiguration stubConfiguration(ContractVerifierExtension.Dependency contractDependency) { + @PackageScope + StubConfiguration stubConfiguration(ContractVerifierExtension.Dependency contractDependency) { String groupId = contractDependency.groupId String artifactId = contractDependency.artifactId String version = StringUtils.hasText(contractDependency.version) ? diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/OutputFolderBuilder.groovy b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/OutputFolderBuilder.groovy index 80d4df0e58..78fb73066e 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/OutputFolderBuilder.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/OutputFolderBuilder.groovy @@ -12,14 +12,14 @@ import org.gradle.api.Project class OutputFolderBuilder { private static final String DEFAULT_MAPPINGS_FOLDER = 'mappings' - + static String buildRootPath(Project project) { String groupId = project.group as String String artifactId = project.name String version = project.version return "META-INF/${groupId}/${artifactId}/${version}" } - + static File outputMappingsDir(Project project, File stubsOutputDir) { String root = OutputFolderBuilder.buildRootPath(project) return stubsOutputDir != null ? diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/PublishStubsToScmTask.groovy b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/PublishStubsToScmTask.groovy index 00e86e41d5..66f1d80e98 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/PublishStubsToScmTask.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/PublishStubsToScmTask.groovy @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/SpringCloudContractVerifierGradlePlugin.groovy b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/SpringCloudContractVerifierGradlePlugin.groovy index 8899f07f9d..bb2d6da341 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/SpringCloudContractVerifierGradlePlugin.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/SpringCloudContractVerifierGradlePlugin.groovy @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -24,6 +24,7 @@ import org.gradle.api.plugins.GroovyPlugin import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.publish.maven.plugins.MavenPublishPlugin import org.gradle.jvm.tasks.Jar + /** * Gradle plugin for Spring Cloud Contract Verifier that from the DSL contract can *