Merge branch '3.1.x' into 4.0.x
This commit is contained in:
@@ -53,7 +53,7 @@ public class WireMockApplicationListener implements ApplicationListener<Applicat
|
||||
private void registerPort(ConfigurableEnvironment environment) {
|
||||
Integer httpPortProperty = environment.getProperty("wiremock.server.port", Integer.class);
|
||||
// If the httpPortProperty is not found it means the AutoConfigureWireMock hasn't
|
||||
// been initialised.
|
||||
// been initialised or the default was used
|
||||
if (httpPortProperty != null && isHttpDynamic(httpPortProperty)) {
|
||||
registerPropertySourceForDynamicEntries(environment, "wiremock.server.port", 10000, 12500,
|
||||
"wiremock.server.port-dynamic");
|
||||
@@ -61,6 +61,13 @@ public class WireMockApplicationListener implements ApplicationListener<Applicat
|
||||
log.debug("Registered property source for dynamic http port");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Map<String, Object> source = getWireMockSource(environment);
|
||||
source.put("wiremock.server.port", 8080);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Registered WireMock server port property to the default <8080> value");
|
||||
}
|
||||
}
|
||||
int httpsPortProperty = environment.getProperty("wiremock.server.https-port", Integer.class, 0);
|
||||
if (isHttpsDynamic(httpsPortProperty)) {
|
||||
registerPropertySourceForDynamicEntries(environment, "wiremock.server.https-port", 12500, 15000,
|
||||
@@ -70,9 +77,7 @@ public class WireMockApplicationListener implements ApplicationListener<Applicat
|
||||
}
|
||||
}
|
||||
else if (httpsPortProperty == -1) {
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
addPropertySource(propertySources);
|
||||
Map<String, Object> source = ((MapPropertySource) propertySources.get("wiremock")).getSource();
|
||||
Map<String, Object> source = getWireMockSource(environment);
|
||||
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");
|
||||
@@ -81,6 +86,13 @@ public class WireMockApplicationListener implements ApplicationListener<Applicat
|
||||
|
||||
}
|
||||
|
||||
private Map<String, Object> getWireMockSource(ConfigurableEnvironment environment) {
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
addPropertySource(propertySources);
|
||||
Map<String, Object> source = ((MapPropertySource) propertySources.get("wiremock")).getSource();
|
||||
return source;
|
||||
}
|
||||
|
||||
private boolean isHttpsDynamic(int httpsPortProperty) {
|
||||
return httpsPortProperty == 0;
|
||||
}
|
||||
@@ -91,9 +103,7 @@ public class WireMockApplicationListener implements ApplicationListener<Applicat
|
||||
|
||||
private void registerPropertySourceForDynamicEntries(ConfigurableEnvironment environment, String portProperty,
|
||||
int minPort, int maxPort, String dynamicPortProperty) {
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
addPropertySource(propertySources);
|
||||
Map<String, Object> source = ((MapPropertySource) propertySources.get("wiremock")).getSource();
|
||||
Map<String, Object> source = getWireMockSource(environment);
|
||||
int port = TestSocketUtils.findAvailableTcpPort(minPort, maxPort);
|
||||
source.put(portProperty, port);
|
||||
if (log.isDebugEnabled()) {
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2013-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.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.wiremock;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = WiremockTestsApplication.class,
|
||||
properties = "app.baseUrl=http://localhost:${wiremock.server.port}", webEnvironment = WebEnvironment.NONE)
|
||||
@AutoConfigureWireMock
|
||||
public class AutoConfigureWireMockDefaultSetupTests {
|
||||
|
||||
@Value("${app.baseUrl}")
|
||||
String url;
|
||||
|
||||
@Test
|
||||
public void contextLoads() throws Exception {
|
||||
then(url).isEqualTo("http://localhost:8080");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user