Search in sources :

Example 11 with Origin

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

the class ConfigDataLocationTests method splitWhenHasOriginReturnsElementsWithOriginSet.

@Test
void splitWhenHasOriginReturnsElementsWithOriginSet() {
    Origin origin = mock(Origin.class);
    ConfigDataLocation location = ConfigDataLocation.of("a;b").withOrigin(origin);
    ConfigDataLocation[] split = location.split();
    assertThat(split[0].getOrigin()).isEqualTo(origin);
    assertThat(split[1].getOrigin()).isEqualTo(origin);
}
Also used : Origin(org.springframework.boot.origin.Origin) Test(org.junit.jupiter.api.Test)

Example 12 with Origin

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

the class InputStreamSourceToByteArrayConverterTests method convertWhenFailsWithIOExceptionFromOriginProviderThrowsException.

@ConversionServiceTest
void convertWhenFailsWithIOExceptionFromOriginProviderThrowsException(ConversionService conversionService) throws Exception {
    Origin origin = new TestOrigin("mylocation");
    InputStreamSource source = mock(InputStreamSource.class, withSettings().extraInterfaces(OriginProvider.class));
    given(source.getInputStream()).willThrow(IOException.class);
    given(((OriginProvider) source).getOrigin()).willReturn(origin);
    assertThatExceptionOfType(ConversionFailedException.class).isThrownBy(() -> conversionService.convert(source, byte[].class)).withCauseExactlyInstanceOf(IllegalStateException.class).withMessageContaining("Unable to read from mylocation");
}
Also used : Origin(org.springframework.boot.origin.Origin) InputStreamSource(org.springframework.core.io.InputStreamSource) ConversionFailedException(org.springframework.core.convert.ConversionFailedException) OriginProvider(org.springframework.boot.origin.OriginProvider)

Example 13 with Origin

use of org.springframework.boot.origin.Origin 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)

Example 14 with Origin

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

the class ConfigurationPropertiesReportEndpoint method getInput.

private Map<String, Object> getInput(ConfigurationProperty candidate, Object sanitizedValue) {
    Map<String, Object> input = new LinkedHashMap<>();
    Origin origin = Origin.from(candidate);
    List<Origin> originParents = Origin.parentsFrom(candidate);
    input.put("value", sanitizedValue);
    input.put("origin", (origin != null) ? origin.toString() : "none");
    if (!originParents.isEmpty()) {
        input.put("originParents", originParents.stream().map(Object::toString).toArray(String[]::new));
    }
    return input;
}
Also used : Origin(org.springframework.boot.origin.Origin) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Origin (org.springframework.boot.origin.Origin)14 Test (org.junit.jupiter.api.Test)7 ArrayList (java.util.ArrayList)2 ConfigurationProperty (org.springframework.boot.context.properties.source.ConfigurationProperty)2 ConfigurationPropertyName (org.springframework.boot.context.properties.source.ConfigurationPropertyName)2 OriginProvider (org.springframework.boot.origin.OriginProvider)2 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 BindContext (org.springframework.boot.context.properties.bind.BindContext)1 BindHandler (org.springframework.boot.context.properties.bind.BindHandler)1 Bindable (org.springframework.boot.context.properties.bind.Bindable)1 Binder (org.springframework.boot.context.properties.bind.Binder)1 FailureAnalysis (org.springframework.boot.diagnostics.FailureAnalysis)1 MockOrigin (org.springframework.boot.origin.MockOrigin)1 OriginLookup (org.springframework.boot.origin.OriginLookup)1 TextResourceOrigin (org.springframework.boot.origin.TextResourceOrigin)1 Location (org.springframework.boot.origin.TextResourceOrigin.Location)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 ConversionFailedException (org.springframework.core.convert.ConversionFailedException)1 InputStreamSource (org.springframework.core.io.InputStreamSource)1