Added props to @AutoConfigureStubRunner
This commit is contained in:
@@ -114,4 +114,10 @@ public @interface AutoConfigureStubRunner {
|
||||
* JAR was downloaded from a remote location or a local one
|
||||
*/
|
||||
boolean snapshotCheckSkip() default false;
|
||||
|
||||
/**
|
||||
* Properties in form {@literal key=value}
|
||||
* @return the properties to add
|
||||
*/
|
||||
String[] properties() default {};
|
||||
}
|
||||
|
||||
@@ -95,7 +95,8 @@ public class StubRunnerConfiguration {
|
||||
.withConsumerName(consumerName())
|
||||
.withMappingsOutputFolder(this.props.getMappingsOutputFolder())
|
||||
.withSnapshotCheckSkip(this.props.isSnapshotCheckSkip())
|
||||
.withDeleteStubsAfterTest(this.props.isDeleteStubsAfterTest());
|
||||
.withDeleteStubsAfterTest(this.props.isDeleteStubsAfterTest())
|
||||
.withProperties(this.props.getProperties());
|
||||
}
|
||||
|
||||
private String consumerName() {
|
||||
|
||||
@@ -19,10 +19,12 @@ package org.springframework.cloud.contract.stubrunner.spring;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.contract.stubrunner.ResourceResolver;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -259,8 +261,15 @@ public class StubRunnerProperties {
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
public void setProperties(Map<String, String> properties) {
|
||||
this.properties = properties;
|
||||
public void setProperties(String[] properties) {
|
||||
Properties elements = StringUtils
|
||||
.splitArrayElementsIntoProperties(properties, "=");
|
||||
if (elements == null) {
|
||||
return;
|
||||
}
|
||||
for (String key : elements.stringPropertyNames()) {
|
||||
this.properties.put(key, elements.getProperty(key));
|
||||
}
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner;
|
||||
import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
@@ -44,7 +45,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
},
|
||||
minPort = 10001,
|
||||
maxPort = 10020,
|
||||
mappingsOutputFolder = "target/outputmappings/")
|
||||
mappingsOutputFolder = "target/outputmappings/",
|
||||
properties = {"hello=world", "foo=bar"})
|
||||
@DirtiesContext
|
||||
@ActiveProfiles("test")
|
||||
public class StubRunnerSliceTests {
|
||||
@@ -52,6 +54,9 @@ public class StubRunnerSliceTests {
|
||||
@Autowired
|
||||
private StubFinder stubFinder;
|
||||
|
||||
@Autowired
|
||||
private StubRunnerProperties properties;
|
||||
|
||||
@Value("${stubrunner.runningstubs.fraudDetectionServer.port}")
|
||||
private Integer fraudDetectionServerPort;
|
||||
|
||||
@@ -81,6 +86,9 @@ public class StubRunnerSliceTests {
|
||||
assertThat(stubFinder.findStubUrl(
|
||||
"org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer"))
|
||||
.isNotNull();
|
||||
assertThat(properties.getProperties())
|
||||
.containsEntry("hello", "world")
|
||||
.containsEntry("foo", "bar");
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
|
||||
Reference in New Issue
Block a user