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/samples/standalone/webclient/http-server/build.gradle b/samples/standalone/webclient/http-server/build.gradle index 3131a01d12..b33c746ae6 100644 --- a/samples/standalone/webclient/http-server/build.gradle +++ b/samples/standalone/webclient/http-server/build.gradle @@ -34,10 +34,6 @@ dependencies { testCompile 'org.springframework.cloud:spring-cloud-contract-wiremock' } -contracts { - failOnNoContracts = false -} - test { systemProperty 'spring.profiles.active', 'gradle' testLogging { 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/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-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 { }