Search in sources :

Example 86 with MapPropertySource

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");
}
Also used : HashMap(java.util.HashMap) MapPropertySource(org.springframework.core.env.MapPropertySource) Test(org.junit.jupiter.api.Test)

Example 87 with MapPropertySource

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");
}
Also used : HashMap(java.util.HashMap) MapPropertySource(org.springframework.core.env.MapPropertySource) Test(org.junit.jupiter.api.Test)

Example 88 with MapPropertySource

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("");
}
Also used : HashMap(java.util.HashMap) MapPropertySource(org.springframework.core.env.MapPropertySource) Test(org.junit.jupiter.api.Test)

Example 89 with MapPropertySource

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}\"");
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) Test(org.junit.jupiter.api.Test)

Example 90 with MapPropertySource

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("");
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) Test(org.junit.jupiter.api.Test)

Aggregations

MapPropertySource (org.springframework.core.env.MapPropertySource)213 HashMap (java.util.HashMap)103 Test (org.junit.jupiter.api.Test)80 MutablePropertySources (org.springframework.core.env.MutablePropertySources)66 Test (org.junit.Test)59 StandardEnvironment (org.springframework.core.env.StandardEnvironment)52 LinkedHashMap (java.util.LinkedHashMap)42 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)30 URI (java.net.URI)24 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)23 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)21 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)21 ArrayList (java.util.ArrayList)18 Map (java.util.Map)16 RestTemplate (org.springframework.web.client.RestTemplate)16 ProtobufMessageSerDe (com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe)15 ServiceError (com.kixeye.chassis.transport.dto.ServiceError)14 JsonJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe)14 XmlMessageSerDe (com.kixeye.chassis.transport.serde.converter.XmlMessageSerDe)14 YamlJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.YamlJacksonMessageSerDe)14