use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class SpringBootTestRandomPortEnvironmentPostProcessorTests method postProcessWhenServerPortAndManagementPortIsZeroInDifferentPropertySources.
@Test
void postProcessWhenServerPortAndManagementPortIsZeroInDifferentPropertySources() {
addTestPropertySource("0", null);
Map<String, Object> source = new HashMap<>();
source.put("management.server.port", "0");
this.propertySources.addLast(new MapPropertySource("other", source));
this.postProcessor.postProcessEnvironment(this.environment, null);
assertThat(this.environment.getProperty("server.port")).isEqualTo("0");
assertThat(this.environment.getProperty("management.server.port")).isEqualTo("0");
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class SpringBootTestRandomPortEnvironmentPostProcessorTests method postProcessWhenServerPortPlaceholderPresentShouldResolvePlaceholder.
@Test
void postProcessWhenServerPortPlaceholderPresentShouldResolvePlaceholder() {
addTestPropertySource("0", null);
MapPropertySource testPropertySource = (MapPropertySource) this.propertySources.get(TestPropertySourceUtils.INLINED_PROPERTIES_PROPERTY_SOURCE_NAME);
testPropertySource.getSource().put("port", "8080");
Map<String, Object> source = new HashMap<>();
source.put("server.port", "${port}");
source.put("management.server.port", "9090");
this.propertySources.addLast(new MapPropertySource("other", source));
this.postProcessor.postProcessEnvironment(this.environment, null);
assertThat(this.environment.getProperty("server.port")).isEqualTo("0");
assertThat(this.environment.getProperty("management.server.port")).isEqualTo("0");
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class SpringBootTestRandomPortEnvironmentPostProcessorTests method postProcessWhenTestServerPortIsZeroAndManagementPortIsNotNullAndSameInProduction.
@Test
void postProcessWhenTestServerPortIsZeroAndManagementPortIsNotNullAndSameInProduction() {
addTestPropertySource("0", null);
Map<String, Object> other = new HashMap<>();
other.put("server.port", "8081");
other.put("management.server.port", "8081");
MapPropertySource otherSource = new MapPropertySource("other", other);
this.propertySources.addLast(otherSource);
this.postProcessor.postProcessEnvironment(this.environment, null);
assertThat(this.environment.getProperty("server.port")).isEqualTo("0");
assertThat(this.environment.getProperty("management.server.port")).isEqualTo("");
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class SpringBootTestRandomPortEnvironmentPostProcessorTests method postProcessWhenManagementServerPortPlaceholderAbsentShouldFail.
@Test
void postProcessWhenManagementServerPortPlaceholderAbsentShouldFail() {
addTestPropertySource("0", null);
this.propertySources.addLast(new MapPropertySource("other", Collections.singletonMap("management.server.port", "${port}")));
assertThatIllegalArgumentException().isThrownBy(() -> this.postProcessor.postProcessEnvironment(this.environment, null)).withMessage("Could not resolve placeholder 'port' in value \"${port}\"");
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class SpringBootTestRandomPortEnvironmentPostProcessorTests method postProcessWhenTestServerPortIsZeroAndManagementPortIsNotNullAndDefaultSameInProduction.
@Test
void postProcessWhenTestServerPortIsZeroAndManagementPortIsNotNullAndDefaultSameInProduction() {
// mgmt port is 8080 which means it's on the same port as main server since that
// is null in app properties
addTestPropertySource("0", null);
this.propertySources.addLast(new MapPropertySource("other", Collections.singletonMap("management.server.port", "8080")));
this.postProcessor.postProcessEnvironment(this.environment, null);
assertThat(this.environment.getProperty("server.port")).isEqualTo("0");
assertThat(this.environment.getProperty("management.server.port")).isEqualTo("");
}
Aggregations