From bfb5e0240be448901d59dac4e426a9d1df060422 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Thu, 13 May 2021 14:03:19 +0200 Subject: [PATCH] Making the tests less brittle --- .../stubrunner/provider/wiremock/WireMockHttpServerStub.java | 4 ++-- .../cloud/contract/stubrunner/StubServerSpec.groovy | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) 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 c541237b88..9170dce2d9 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 @@ -227,8 +227,8 @@ public class WireMockHttpServerStub implements HttpServerStub { String scheme = this.https ? "https" : "http"; String host = "localhost"; int port = port(); - String urlPathPrefix = null; - String hostHeader = null; + String urlPathPrefix = ""; + String hostHeader = ""; String proxyHost = this.wireMockConfiguration.proxyHostHeader(); int proxyPort = this.wireMockConfiguration.proxyVia().port(); ClientAuthenticator authenticator = NoClientAuthenticator.noClientAuthenticator(); 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 74feb443c6..60102e5b38 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 @@ -19,9 +19,10 @@ package org.springframework.cloud.contract.stubrunner import spock.lang.Specification import org.springframework.cloud.contract.stubrunner.provider.wiremock.WireMockHttpServerStub +import org.springframework.util.SocketUtils class StubServerSpec extends Specification { - static final int STUB_SERVER_PORT = 12180 + static final int STUB_SERVER_PORT = SocketUtils.findAvailableTcpPort() static final URL EXPECTED_URL = new URL("http://localhost:$STUB_SERVER_PORT") File repository = new File('src/test/resources/repository/mappings/spring/cloud/bye') @@ -36,6 +37,7 @@ class StubServerSpec extends Specification { pingStubServer.start() then: "http://localhost:$pingStubServer.port/bye".toURL().text == 'Goodbye world!' + cleanup: pingStubServer.stop() } @@ -48,6 +50,7 @@ class StubServerSpec extends Specification { pingStubServer.start() then: pingStubServer.stubUrl == EXPECTED_URL + cleanup: pingStubServer.stop() } }