Search in sources :

Example 1 with OriginLookup

use of org.springframework.boot.origin.OriginLookup in project spring-boot by spring-projects.

the class IntegrationPropertiesEnvironmentPostProcessorTests method registerIntegrationPropertiesPropertySourceWithResourceCanRetrieveOrigin.

@Test
@SuppressWarnings("unchecked")
void registerIntegrationPropertiesPropertySourceWithResourceCanRetrieveOrigin() {
    ConfigurableEnvironment environment = new StandardEnvironment();
    ClassPathResource resource = new ClassPathResource("spring.integration.properties", getClass());
    new IntegrationPropertiesEnvironmentPostProcessor().registerIntegrationPropertiesPropertySource(environment, resource);
    PropertySource<?> ps = environment.getPropertySources().get("META-INF/spring.integration.properties");
    assertThat(ps).isNotNull().isInstanceOf(OriginLookup.class);
    OriginLookup<String> originLookup = (OriginLookup<String>) ps;
    assertThat(originLookup.getOrigin("spring.integration.channel.auto-create")).satisfies(textOrigin(resource, 0, 39));
    assertThat(originLookup.getOrigin("spring.integration.channel.max-unicast-subscribers")).satisfies(textOrigin(resource, 1, 50));
    assertThat(originLookup.getOrigin("spring.integration.channel.max-broadcast-subscribers")).satisfies(textOrigin(resource, 2, 52));
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) OriginLookup(org.springframework.boot.origin.OriginLookup) ClassPathResource(org.springframework.core.io.ClassPathResource) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 2 with OriginLookup

use of org.springframework.boot.origin.OriginLookup in project spring-boot by spring-projects.

the class EnvironmentEndpoint method describeValueOf.

@SuppressWarnings("unchecked")
private PropertyValueDescriptor describeValueOf(String name, PropertySource<?> source, PlaceholdersResolver resolver) {
    Object resolved = resolver.resolvePlaceholders(source.getProperty(name));
    Origin origin = ((source instanceof OriginLookup) ? ((OriginLookup<Object>) source).getOrigin(name) : null);
    Object sanitizedValue = sanitize(source, name, resolved);
    return new PropertyValueDescriptor(stringifyIfNecessary(sanitizedValue), origin);
}
Also used : Origin(org.springframework.boot.origin.Origin) OriginLookup(org.springframework.boot.origin.OriginLookup)

Aggregations

OriginLookup (org.springframework.boot.origin.OriginLookup)2 Test (org.junit.jupiter.api.Test)1 Origin (org.springframework.boot.origin.Origin)1 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)1 StandardEnvironment (org.springframework.core.env.StandardEnvironment)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1