diff --git a/README.adoc b/README.adoc index e307964a1c..73a9160050 100644 --- a/README.adoc +++ b/README.adoc @@ -2193,6 +2193,7 @@ $ touch .springformat ==== Intellij IDEA In order to setup Intellij you should import our coding conventions, inspection profiles and set up the checkstyle plugin. +The following files can be found in the https://github.com/spring-cloud/spring-cloud-build/tree/master/spring-cloud-build-tools[Spring Cloud Build] project. .spring-cloud-build-tools/ ---- @@ -2233,7 +2234,7 @@ image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring 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.header.file` - please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/main/resources/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`. diff --git a/docs/src/main/asciidoc/verifier_setup.adoc b/docs/src/main/asciidoc/verifier_setup.adoc index e65288d9f6..b4ad5dc138 100644 --- a/docs/src/main/asciidoc/verifier_setup.adoc +++ b/docs/src/main/asciidoc/verifier_setup.adoc @@ -37,19 +37,90 @@ WARNING: If you want to use Spock in your projects, you must add separately the docs for more information] [[gradle-add-gradle-plugin]] -==== Add Gradle Plugin with Dependencies +== Add Gradle Plugin with Dependencies -To add a Gradle plugin with dependencies, use code similar to this: +To add a Gradle plugin with dependencies, you can use code similar to the following: -[source,groovy,indent=0] +==== +[source,groovy,indent=0,subs="verbatim,attributes",role="primary"] +.Plugin DSL GA versions ---- +// build.gradle +plugins { + id "groovy" + // this will work only for GA versions of Spring Cloud Contract + id "org.springframework.cloud.contract" version "${GAVerifierVersion}" +} + +dependencyManagement { + imports { + mavenBom "org.springframework.cloud:spring-cloud-contract-dependencies:${GAVerifierVersion}" + } +} + +dependencies { + testCompile "org.codehaus.groovy:groovy-all:${groovyVersion}" + // example with adding Spock core and Spock Spring + testCompile "org.spockframework:spock-core:${spockVersion}" + testCompile "org.spockframework:spock-spring:${spockVersion}" + testCompile 'org.springframework.cloud:spring-cloud-starter-contract-verifier' +} +---- + +[source,groovy,indent=0,subs="verbatim,attributes",role="secondary"] +.Plugin DSL non GA versions +---- +// settings.gradle +pluginManagement { + plugins { + id "org.springframework.cloud.contract" version "${verifierVersion}" + } + repositories { + // to pick from local .m2 + mavenLocal() + // for snapshots + maven { url "https://repo.spring.io/snapshot" } + // for milestones + maven { url "https://repo.spring.io/milestone" } + // for GA versions + gradlePluginPortal() + } +} + +// build.gradle +plugins { + id "groovy" + id "org.springframework.cloud.contract" +} + +dependencyManagement { + imports { + mavenBom "org.springframework.cloud:spring-cloud-contract-dependencies:${verifierVersion}" + } +} + +dependencies { + testCompile "org.codehaus.groovy:groovy-all:${groovyVersion}" + // example with adding Spock core and Spock Spring + testCompile "org.spockframework:spock-core:${spockVersion}" + testCompile "org.spockframework:spock-spring:${spockVersion}" + testCompile 'org.springframework.cloud:spring-cloud-starter-contract-verifier' +} +---- + +[source,groovy,indent=0,subs="verbatim,attributes",role="secondary"] +.Legacy Plugin Application +---- +// build.gradle buildscript { repositories { mavenCentral() } dependencies { - classpath "org.springframework.boot:spring-boot-gradle-plugin:${springboot_version}" + classpath "org.springframework.boot:spring-boot-gradle-plugin:${springboot_version}" classpath "org.springframework.cloud:spring-cloud-contract-gradle-plugin:${verifier_version}" + // here you can also pass additional dependencies such as Pact or Kotlin spec e.g.: + // classpath "org.springframework.cloud:spring-cloud-contract-spec-kotlin:${verifier_version}" } } @@ -63,13 +134,14 @@ dependencyManagement { } dependencies { - testCompile 'org.codehaus.groovy:groovy-all:2.4.6' + testCompile "org.codehaus.groovy:groovy-all:${groovyVersion}" // example with adding Spock core and Spock Spring - testCompile 'org.spockframework:spock-core:1.0-groovy-2.4' - testCompile 'org.spockframework:spock-spring:1.0-groovy-2.4' + testCompile "org.spockframework:spock-core:${spockVersion}" + testCompile "org.spockframework:spock-spring:${spockVersion}" testCompile 'org.springframework.cloud:spring-cloud-starter-contract-verifier' } ---- +==== [[gradle-and-rest-assured]] ==== Gradle and Rest Assured 2.0 diff --git a/samples/standalone/dsl/http-server/build.gradle b/samples/standalone/dsl/http-server/build.gradle index 32364c36de..fe18dc4be7 100644 --- a/samples/standalone/dsl/http-server/build.gradle +++ b/samples/standalone/dsl/http-server/build.gradle @@ -1,4 +1,25 @@ // tag::repos[] +/* + We need to use the [buildscript {}] section when we have to modify + the classpath for the plugins. If that's not the case this section + can be skipped. + + If you don't need to modify the classpath (e.g. add a Pact dependency), + then you can just set the [pluginManagement {}] section in [settings.gradle] file. + + // settings.gradle + pluginManagement { + repositories { + // for snapshots + maven {url "https://repo.spring.io/snapshot"} + // for milestones + maven {url "https://repo.spring.io/milestone"} + // for GA versions + gradlePluginPortal() + } + } + + */ buildscript { repositories { mavenCentral() diff --git a/samples/standalone/webclient/http-server/build.gradle b/samples/standalone/webclient/http-server/build.gradle index 2703c06a79..b33c746ae6 100644 --- a/samples/standalone/webclient/http-server/build.gradle +++ b/samples/standalone/webclient/http-server/build.gradle @@ -1,17 +1,10 @@ -buildscript { - repositories { - mavenCentral() - mavenLocal() - maven { url "https://repo.spring.io/snapshot" } - maven { url "https://repo.spring.io/milestone" } - maven { url "https://repo.spring.io/release" } - maven { url 'https://repo.spring.io/plugins-snapshot' } - maven { url "https://repo.spring.io/plugins-release-local" } - maven { url "https://repo.spring.io/plugins-staging-local/" } - } - dependencies { - classpath "org.springframework.boot:spring-boot-gradle-plugin:2.1.2.RELEASE" - } +plugins { + id "groovy" + id "org.springframework.boot" + id "io.spring.dependency-management" + id "maven-publish" + id "maven" + id "org.springframework.cloud.contract" } group = 'com.example' @@ -25,12 +18,6 @@ repositories { maven { url "https://repo.spring.io/release" } } -apply plugin: 'groovy' -apply plugin: 'org.springframework.boot' -apply plugin: 'io.spring.dependency-management' -apply plugin: 'maven-publish' -apply plugin: 'maven' - dependencyManagement { imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:$BOM_VERSION" diff --git a/samples/standalone/webclient/http-server/gradle.properties b/samples/standalone/webclient/http-server/gradle.properties index d9243d5405..fd7e4fdaf9 100644 --- a/samples/standalone/webclient/http-server/gradle.properties +++ b/samples/standalone/webclient/http-server/gradle.properties @@ -1,3 +1,4 @@ org.gradle.daemon=false verifierVersion=2.1.4.BUILD-SNAPSHOT -BOM_VERSION=Greenwich.BUILD-SNAPSHOT \ No newline at end of file +BOM_VERSION=Greenwich.BUILD-SNAPSHOT +bootVersion=2.1.7.RELEASE \ No newline at end of file diff --git a/samples/standalone/webclient/http-server/gradle/wrapper/gradle-wrapper.jar b/samples/standalone/webclient/http-server/gradle/wrapper/gradle-wrapper.jar index 1948b9074f..5c2d1cf016 100644 Binary files a/samples/standalone/webclient/http-server/gradle/wrapper/gradle-wrapper.jar and b/samples/standalone/webclient/http-server/gradle/wrapper/gradle-wrapper.jar differ diff --git a/samples/standalone/webclient/http-server/gradle/wrapper/gradle-wrapper.properties b/samples/standalone/webclient/http-server/gradle/wrapper/gradle-wrapper.properties index e0b3fb8d70..7c4388a921 100644 --- a/samples/standalone/webclient/http-server/gradle/wrapper/gradle-wrapper.properties +++ b/samples/standalone/webclient/http-server/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/samples/standalone/webclient/http-server/gradlew b/samples/standalone/webclient/http-server/gradlew index cccdd3d517..83f2acfdc3 100755 --- a/samples/standalone/webclient/http-server/gradlew +++ b/samples/standalone/webclient/http-server/gradlew @@ -1,5 +1,21 @@ #!/usr/bin/env sh +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + ############################################################################## ## ## Gradle start up script for UN*X @@ -28,7 +44,7 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" @@ -109,8 +125,8 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` JAVACMD=`cygpath --unix "$JAVACMD"` diff --git a/samples/standalone/webclient/http-server/gradlew.bat b/samples/standalone/webclient/http-server/gradlew.bat index e95643d6a2..9618d8d960 100644 --- a/samples/standalone/webclient/http-server/gradlew.bat +++ b/samples/standalone/webclient/http-server/gradlew.bat @@ -1,84 +1,100 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/samples/standalone/webclient/http-server/settings.gradle b/samples/standalone/webclient/http-server/settings.gradle index 2cc07be60c..deaca9637d 100644 --- a/samples/standalone/webclient/http-server/settings.gradle +++ b/samples/standalone/webclient/http-server/settings.gradle @@ -1 +1,26 @@ +pluginManagement { + plugins { + id 'org.springframework.boot' + id "org.springframework.cloud.contract" version "${verifierVersion}" + id "io.spring.dependency-management" version "1.0.8.RELEASE" + } + repositories { + // to pick from local .m2 + mavenLocal() + // for snapshots + maven { url "https://repo.spring.io/libs-snapshot-local" } + // for milestones + maven { url "https://repo.spring.io/libs-milestone-local" } + // for GA versions + gradlePluginPortal() + } + resolutionStrategy { + eachPlugin { + if (requested.id.id == 'org.springframework.boot') { + useModule("org.springframework.boot:spring-boot-gradle-plugin:${bootVersion}") + } + } + } +} rootProject.name = 'http-server-webclient-gradle' + 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 c47a1dc17d..88c91b1f15 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 @@ -46,7 +46,8 @@ public final class StubRunnerWireMockTestExecutionListener } return; } - if (WireMockHttpServerStub.SERVERS.values().stream().noneMatch(p -> p.random)) { + if (!WireMockHttpServerStub.SERVERS.isEmpty() && WireMockHttpServerStub.SERVERS + .values().stream().noneMatch(p -> p.random)) { if (log.isWarnEnabled()) { log.warn("You've used fixed ports for WireMock setup - " + "will mark context as dirty. Please use random ports, as much " 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 f97628ff88..54a4e33abb 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 @@ -18,8 +18,12 @@ package org.springframework.cloud.contract.stubrunner.spring; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.TimeUnit; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.contract.stubrunner.BatchStubRunner; @@ -54,9 +58,6 @@ public class StubRunnerConfiguration { static final String STUBRUNNER_PREFIX = "stubrunner.runningstubs"; - @Autowired(required = false) - private MessageVerifier contractVerifierMessaging; - private StubDownloaderBuilderProvider provider = new StubDownloaderBuilderProvider(); @Autowired @@ -72,7 +73,7 @@ public class StubRunnerConfiguration { * @return the batch stub runner bean */ @Bean - public BatchStubRunner batchStubRunner() { + public BatchStubRunner batchStubRunner(BeanFactory beanFactory) { StubRunnerOptionsBuilder builder = builder(); if (this.props.getProxyHost() != null) { builder.withProxy(this.props.getProxyHost(), this.props.getProxyPort()); @@ -80,14 +81,19 @@ public class StubRunnerConfiguration { StubRunnerOptions stubRunnerOptions = builder.build(); BatchStubRunner batchStubRunner = new BatchStubRunnerFactory(stubRunnerOptions, this.provider.get(stubRunnerOptions), - this.contractVerifierMessaging != null ? this.contractVerifierMessaging - : new NoOpStubMessages()).buildBatchStubRunner(); + new LazyMessageVerifier(beanFactory)).buildBatchStubRunner(); // TODO: Consider running it in a separate thread RunningStubs runningStubs = batchStubRunner.runStubs(); registerPort(runningStubs); return batchStubRunner; } + @Bean + public BeanPostProcessor batchStubRunnerBeanPostProcessor(BatchStubRunner runner) { + return new BeanPostProcessor() { + }; + } + private StubRunnerOptionsBuilder builder() { return new StubRunnerOptionsBuilder() .withMinMaxPort(this.props.getMinPort(), this.props.getMaxPort()) @@ -131,3 +137,47 @@ public class StubRunnerConfiguration { } } + +class LazyMessageVerifier implements MessageVerifier { + + private MessageVerifier messageVerifier; + + private final BeanFactory beanFactory; + + LazyMessageVerifier(BeanFactory beanFactory) { + this.beanFactory = beanFactory; + } + + private MessageVerifier messageVerifier() { + if (this.messageVerifier == null) { + try { + this.messageVerifier = this.beanFactory.getBean(MessageVerifier.class); + } + catch (BeansException ex) { + this.messageVerifier = new NoOpStubMessages(); + } + } + return this.messageVerifier; + } + + @Override + public void send(Object message, String destination) { + messageVerifier().send(message, destination); + } + + @Override + public Object receive(String destination, long timeout, TimeUnit timeUnit) { + return messageVerifier().receive(destination, timeout, timeUnit); + } + + @Override + public Object receive(String destination) { + return messageVerifier().receive(destination); + } + + @Override + public void send(Object payload, Map headers, String destination) { + messageVerifier().send(payload, headers, destination); + } + +} \ No newline at end of file diff --git a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/issue1225/Issue1225Tests.java b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/issue1225/Issue1225Tests.java new file mode 100644 index 0000000000..0168b647c4 --- /dev/null +++ b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/issue1225/Issue1225Tests.java @@ -0,0 +1,80 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY 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.issue1225; + +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; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner; +import org.springframework.cloud.contract.stubrunner.spring.StubRunnerPort; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.bind.annotation.RestController; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests that stub runner specific auto-configuration can be loaded up in combination with + * other slice tests + * + * @author Biju Kunjummen + */ +@RunWith(SpringRunner.class) +@SpringBootTest(properties = { + "ping.url=http://localhost:${stubrunner.runningstubs.loanIssuance.port}" }) +@AutoConfigureStubRunner(ids = { + "org.springframework.cloud.contract.verifier.stubs:loanIssuance:+:stubs", + "org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer:+:stubs" }) +@ActiveProfiles("test") +public class Issue1225Tests { + + @StubRunnerPort("loanIssuance") + private int stubRunnerLoanIssuancePort; + + @Autowired + private PingProxyController pingProxyController; + + @Test + public void shouldInjectTheStubPortsAsEarlyAsPossible() { + assertThat(this.stubRunnerLoanIssuancePort).isPositive(); + assertThat(this.pingProxyController.pingUrl) + .contains(":" + this.stubRunnerLoanIssuancePort); + } + + @ComponentScan + @SpringBootConfiguration + static class Config { + + } + +} + +@RestController +class PingProxyController { + + String pingUrl; + + public PingProxyController(@Value("${ping.url}") String pingUrl) { + this.pingUrl = pingUrl; + } + +} \ No newline at end of file diff --git a/spring-cloud-contract-tools/pom.xml b/spring-cloud-contract-tools/pom.xml index 6bd5ab27a8..cec5654a5b 100644 --- a/spring-cloud-contract-tools/pom.xml +++ b/spring-cloud-contract-tools/pom.xml @@ -22,6 +22,7 @@ spring-cloud-contract-pact spring-cloud-contract-maven-plugin spring-cloud-contract-gradle-plugin + spring-cloud-contract-gradle-portal-plugin 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 ed56730aa4..5e7dbcf66c 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 @@ -158,7 +158,3 @@ task resolveDependencies { } } } - -task wrapper(type: Wrapper) { - gradleVersion = '4.10.2' -} diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradle/wrapper/gradle-wrapper.jar b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradle/wrapper/gradle-wrapper.jar index 1948b9074f..5c2d1cf016 100644 Binary files a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradle/wrapper/gradle-wrapper.jar and b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradle/wrapper/gradle-wrapper.jar differ diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradle/wrapper/gradle-wrapper.properties b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradle/wrapper/gradle-wrapper.properties index e0b3fb8d70..7c4388a921 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradle/wrapper/gradle-wrapper.properties +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradlew b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradlew index cccdd3d517..83f2acfdc3 100755 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradlew +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradlew @@ -1,5 +1,21 @@ #!/usr/bin/env sh +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + ############################################################################## ## ## Gradle start up script for UN*X @@ -28,7 +44,7 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" @@ -109,8 +125,8 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` JAVACMD=`cygpath --unix "$JAVACMD"` diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradlew.bat b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradlew.bat index e95643d6a2..9618d8d960 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradlew.bat +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/gradlew.bat @@ -1,84 +1,100 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/ContractVerifierSpec.groovy b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/ContractVerifierSpec.groovy index 44af04e6a1..9474b89e7c 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/ContractVerifierSpec.groovy +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/groovy/org/springframework/cloud/contract/verifier/plugin/ContractVerifierSpec.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 + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.cloud.contract.verifier.plugin import org.gradle.api.Task diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-portal-plugin/pom.xml b/spring-cloud-contract-tools/spring-cloud-contract-gradle-portal-plugin/pom.xml new file mode 100644 index 0000000000..fbb5101e56 --- /dev/null +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-portal-plugin/pom.xml @@ -0,0 +1,27 @@ + + + 4.0.0 + + + org.springframework.cloud + spring-cloud-contract-tools + 2.1.4.BUILD-SNAPSHOT + .. + + + org.springframework.cloud.contract + org.springframework.cloud.contract.gradle.plugin + jar + + Spring Cloud Contract Gradle Portal Plugin + Spring Cloud Contract Gradle Portal Plugin + + + + org.springframework.cloud + spring-cloud-contract-gradle-plugin + + + + diff --git a/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/WireMockApplicationListener.java b/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/WireMockApplicationListener.java index 460fcfa231..34ee3960f7 100644 --- a/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/WireMockApplicationListener.java +++ b/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/WireMockApplicationListener.java @@ -19,6 +19,9 @@ package org.springframework.cloud.contract.wiremock; import java.util.HashMap; import java.util.Map; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import org.springframework.boot.context.event.ApplicationPreparedEvent; import org.springframework.context.ApplicationListener; import org.springframework.core.Ordered; @@ -41,6 +44,8 @@ import org.springframework.util.SocketUtils; public class WireMockApplicationListener implements ApplicationListener { + private static final Log log = LogFactory.getLog(WireMockApplicationListener.class); + @Override public void onApplicationEvent(ApplicationPreparedEvent event) { registerPort(event.getApplicationContext().getEnvironment()); @@ -54,26 +59,22 @@ public class WireMockApplicationListener if (httpPortProperty == null) { return; } - - if (httpPortProperty.equals(0)) { - MutablePropertySources propertySources = environment.getPropertySources(); - addPropertySource(propertySources); - Map source = ((MapPropertySource) propertySources - .get("wiremock")).getSource(); - source.put("wiremock.server.port", - SocketUtils.findAvailableTcpPort(10000, 12500)); - source.put("wiremock.server.port-dynamic", true); + if (isHttpDynamic(httpPortProperty)) { + registerPropertySourceForDynamicEntries(environment, "wiremock.server.port", + 10000, 12500, "wiremock.server.port-dynamic"); + if (log.isDebugEnabled()) { + log.debug("Registered property source for dynamic http port"); + } } int httpsPortProperty = environment.getProperty("wiremock.server.https-port", Integer.class, 0); - if (httpsPortProperty == 0) { - MutablePropertySources propertySources = environment.getPropertySources(); - addPropertySource(propertySources); - Map source = ((MapPropertySource) propertySources - .get("wiremock")).getSource(); - source.put("wiremock.server.https-port", - SocketUtils.findAvailableTcpPort(12500, 15000)); - source.put("wiremock.server.https-port-dynamic", true); + if (isHttpsDynamic(httpsPortProperty)) { + registerPropertySourceForDynamicEntries(environment, + "wiremock.server.https-port", 12500, 15000, + "wiremock.server.https-port-dynamic"); + if (log.isDebugEnabled()) { + log.debug("Registered property source for dynamic https port"); + } } else if (httpsPortProperty == -1) { MutablePropertySources propertySources = environment.getPropertySources(); @@ -81,10 +82,33 @@ public class WireMockApplicationListener Map source = ((MapPropertySource) propertySources .get("wiremock")).getSource(); source.put("wiremock.server.https-port-dynamic", true); + if (log.isDebugEnabled()) { + log.debug( + "Registered property source for dynamic https with https port property set to -1"); + } } } + private boolean isHttpsDynamic(int httpsPortProperty) { + return httpsPortProperty == 0; + } + + private boolean isHttpDynamic(Integer httpPortProperty) { + return httpPortProperty.equals(0); + } + + private void registerPropertySourceForDynamicEntries( + ConfigurableEnvironment environment, String portProperty, int minPort, + int maxPort, String dynamicPortProperty) { + MutablePropertySources propertySources = environment.getPropertySources(); + addPropertySource(propertySources); + Map source = ((MapPropertySource) propertySources.get("wiremock")) + .getSource(); + source.put(portProperty, SocketUtils.findAvailableTcpPort(minPort, maxPort)); + source.put(dynamicPortProperty, true); + } + private void addPropertySource(MutablePropertySources propertySources) { if (!propertySources.contains("wiremock")) { propertySources.addFirst( diff --git a/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/WireMockConfiguration.java b/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/WireMockConfiguration.java index abebd1632a..c8b39b8065 100644 --- a/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/WireMockConfiguration.java +++ b/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/WireMockConfiguration.java @@ -109,8 +109,7 @@ public class WireMockConfiguration implements SmartLifecycle { } this.server = new WireMockServer(this.options); } - registerStubs(); - logRegisteredMappings(); + resetMappings(); if (!this.beanFactory.containsBean(WIREMOCK_SERVER_BEAN_NAME)) { this.beanFactory.registerSingleton(WIREMOCK_SERVER_BEAN_NAME, this.server); } @@ -125,10 +124,11 @@ public class WireMockConfiguration implements SmartLifecycle { void resetMappings() { this.server.resetAll(); + registerStubs(); logRegisteredMappings(); } - private void registerStubs() throws IOException { + private void registerStubs() { if (log.isDebugEnabled()) { log.debug("Will register [" + this.wireMock.getServer().getStubs().length + "] stubs"); @@ -144,11 +144,16 @@ public class WireMockConfiguration implements SmartLifecycle { } pattern = pattern + "**/*.json"; } - for (Resource resource : resolver.getResources(pattern)) { - StubMapping stubMapping = WireMockStubMapping - .buildFrom(StreamUtils.copyToString(resource.getInputStream(), - Charset.forName("UTF-8"))); - this.server.addStubMapping(stubMapping); + try { + for (Resource resource : resolver.getResources(pattern)) { + StubMapping stubMapping = WireMockStubMapping.buildFrom( + StreamUtils.copyToString(resource.getInputStream(), + Charset.forName("UTF-8"))); + this.server.addStubMapping(stubMapping); + } + } + catch (IOException ex) { + throw new IllegalStateException(ex); } } } diff --git a/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/WireMockSpring.java b/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/WireMockSpring.java index e4d1baea08..fb89b4a9f7 100644 --- a/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/WireMockSpring.java +++ b/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/WireMockSpring.java @@ -22,7 +22,6 @@ import com.github.tomakehurst.wiremock.core.WireMockConfiguration; import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.apache.http.conn.ssl.TrustSelfSignedStrategy; import org.apache.http.ssl.SSLContexts; -import org.junit.Assert; import org.springframework.util.ClassUtils; @@ -58,8 +57,8 @@ public abstract class WireMockSpring { .build().getSocketFactory()); } catch (Exception e) { - Assert.fail("Cannot install custom socket factory: [" + e.getMessage() - + "]"); + throw new AssertionError("Cannot install custom socket factory: [" + + e.getMessage() + "]"); } } initialized = true; diff --git a/spring-cloud-contract-wiremock/src/test/java/org/springframework/cloud/contract/wiremock/AutoConfigureWireMockRandomPortApplicationTests.java b/spring-cloud-contract-wiremock/src/test/java/org/springframework/cloud/contract/wiremock/AutoConfigureWireMockRandomPortApplicationTests.java index 3bb8b56ecc..1c3df111c6 100644 --- a/spring-cloud-contract-wiremock/src/test/java/org/springframework/cloud/contract/wiremock/AutoConfigureWireMockRandomPortApplicationTests.java +++ b/spring-cloud-contract-wiremock/src/test/java/org/springframework/cloud/contract/wiremock/AutoConfigureWireMockRandomPortApplicationTests.java @@ -53,7 +53,6 @@ public class AutoConfigureWireMockRandomPortApplicationTests { .withHeader("Content-Type", "text/plain").withBody("Hello World!"))); assertThat(this.service.go()).isEqualTo("Hello World!"); - wireMockServer.verify(1, RequestPatternBuilder.allRequests()); } diff --git a/spring-cloud-contract-wiremock/src/test/java/org/springframework/cloud/contract/wiremock/AutoConfigureWireMockRandomPortInheretedApplicationTests.java b/spring-cloud-contract-wiremock/src/test/java/org/springframework/cloud/contract/wiremock/AutoConfigureWireMockRandomPortInheretedApplicationTests.java index 8076b0b4c6..a388466818 100644 --- a/spring-cloud-contract-wiremock/src/test/java/org/springframework/cloud/contract/wiremock/AutoConfigureWireMockRandomPortInheretedApplicationTests.java +++ b/spring-cloud-contract-wiremock/src/test/java/org/springframework/cloud/contract/wiremock/AutoConfigureWireMockRandomPortInheretedApplicationTests.java @@ -16,6 +16,7 @@ package org.springframework.cloud.contract.wiremock; -public class AutoConfigureWireMockRandomPortInheretedApplicationTests extends AutoConfigureWireMockRandomPortApplicationTests { +public class AutoConfigureWireMockRandomPortInheretedApplicationTests + extends AutoConfigureWireMockRandomPortApplicationTests { } diff --git a/tests/spring-cloud-contract-stub-runner-context-path/src/test/java/com/example/loan/FailFastLoanApplicationServiceTests.java b/tests/spring-cloud-contract-stub-runner-context-path/src/test/java/com/example/loan/FailFastLoanApplicationServiceTests.java index 98da40bca1..de31af7ca2 100644 --- a/tests/spring-cloud-contract-stub-runner-context-path/src/test/java/com/example/loan/FailFastLoanApplicationServiceTests.java +++ b/tests/spring-cloud-contract-stub-runner-context-path/src/test/java/com/example/loan/FailFastLoanApplicationServiceTests.java @@ -46,9 +46,8 @@ public class FailFastLoanApplicationServiceTests { // Then assertThat(throwable).isInstanceOf(BeanCreationException.class); - assertThat(throwable.getCause()).isInstanceOf(BeanInstantiationException.class); assertThat(throwable.getCause().getCause()) - .isInstanceOf(IllegalArgumentException.class).hasMessageContaining( + .isInstanceOf(BeanInstantiationException.class).hasMessageContaining( "For groupId [org.springframework.cloud.contract.verifier.stubs] artifactId [should-not-be-found] " + "and classifier [stubs] the version was not resolved! The following exceptions took place"); } @@ -66,9 +65,8 @@ public class FailFastLoanApplicationServiceTests { // Then assertThat(throwable).isInstanceOf(BeanCreationException.class); - assertThat(throwable.getCause()).isInstanceOf(BeanInstantiationException.class); assertThat(throwable.getCause().getCause()) - .isInstanceOf(IllegalStateException.class) + .isInstanceOf(BeanInstantiationException.class) .hasMessageContaining("No stubs were found on classpath "); }