Search in sources :

Example 81 with MapPropertySource

use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.

the class EnvironmentEndpointWebIntegrationTests method nestedPathWhenPlaceholderCannotBeResolvedShouldReturnUnresolvedProperty.

@WebEndpointTest
void nestedPathWhenPlaceholderCannotBeResolvedShouldReturnUnresolvedProperty() {
    Map<String, Object> map = new HashMap<>();
    map.put("my.foo", "${my.bar}");
    this.context.getEnvironment().getPropertySources().addFirst(new MapPropertySource("unresolved-placeholder", map));
    this.client.get().uri("/actuator/env/my.foo").exchange().expectStatus().isOk().expectBody().jsonPath("property.value").isEqualTo("${my.bar}").jsonPath(forPropertyEntry("unresolved-placeholder")).isEqualTo("${my.bar}");
}
Also used : HashMap(java.util.HashMap) MapPropertySource(org.springframework.core.env.MapPropertySource) WebEndpointTest(org.springframework.boot.actuate.endpoint.web.test.WebEndpointTest)

Example 82 with MapPropertySource

use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.

the class EnvironmentEndpointTests method compositeSourceIsHandledCorrectly.

@Test
void compositeSourceIsHandledCorrectly() {
    ConfigurableEnvironment environment = emptyEnvironment();
    CompositePropertySource source = new CompositePropertySource("composite");
    source.addPropertySource(new MapPropertySource("one", Collections.singletonMap("foo", "bar")));
    source.addPropertySource(new MapPropertySource("two", Collections.singletonMap("foo", "spam")));
    environment.getPropertySources().addFirst(source);
    EnvironmentDescriptor descriptor = new EnvironmentEndpoint(environment).environment(null);
    Map<String, PropertySourceDescriptor> sources = propertySources(descriptor);
    assertThat(sources.keySet()).containsExactly("composite:one", "composite:two");
    assertThat(sources.get("composite:one").getProperties().get("foo").getValue()).isEqualTo("bar");
    assertThat(sources.get("composite:two").getProperties().get("foo").getValue()).isEqualTo("spam");
}
Also used : PropertySourceDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.PropertySourceDescriptor) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) CompositePropertySource(org.springframework.core.env.CompositePropertySource) MapPropertySource(org.springframework.core.env.MapPropertySource) EnvironmentDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor) Test(org.junit.jupiter.api.Test)

Example 83 with MapPropertySource

use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.

the class SpringBootTestRandomPortEnvironmentPostProcessorTests method postProcessWhenTestServerPortIsZeroAndManagementPortMinusOne.

@Test
void postProcessWhenTestServerPortIsZeroAndManagementPortMinusOne() {
    addTestPropertySource("0", null);
    this.propertySources.addLast(new MapPropertySource("other", Collections.singletonMap("management.server.port", "-1")));
    this.postProcessor.postProcessEnvironment(this.environment, null);
    assertThat(this.environment.getProperty("server.port")).isEqualTo("0");
    assertThat(this.environment.getProperty("management.server.port")).isEqualTo("-1");
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) Test(org.junit.jupiter.api.Test)

Example 84 with MapPropertySource

use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.

the class SpringBootTestRandomPortEnvironmentPostProcessorTests method postProcessWhenTestServerPortIsZeroAndManagementPortIsNotNullAndDifferentInProduction.

@Test
void postProcessWhenTestServerPortIsZeroAndManagementPortIsNotNullAndDifferentInProduction() {
    addTestPropertySource("0", null);
    this.propertySources.addLast(new MapPropertySource("other", Collections.singletonMap("management.server.port", "8081")));
    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 : MapPropertySource(org.springframework.core.env.MapPropertySource) Test(org.junit.jupiter.api.Test)

Example 85 with MapPropertySource

use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.

the class SpringBootTestRandomPortEnvironmentPostProcessorTests method postProcessWhenTestServerPortIsZeroAndManagementPortIsAnInteger.

@Test
void postProcessWhenTestServerPortIsZeroAndManagementPortIsAnInteger() {
    addTestPropertySource("0", null);
    this.propertySources.addLast(new MapPropertySource("other", Collections.singletonMap("management.server.port", 8081)));
    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 : 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