Search in sources :

Example 11 with PropertyResolver

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

the class ImageBanner method printBanner.

private void printBanner(Environment environment, PrintStream out) throws IOException {
    PropertyResolver properties = new RelaxedPropertyResolver(environment, "banner.image.");
    int width = properties.getProperty("width", Integer.class, 76);
    int height = properties.getProperty("height", Integer.class, 0);
    int margin = properties.getProperty("margin", Integer.class, 2);
    boolean invert = properties.getProperty("invert", Boolean.class, false);
    BufferedImage image = readImage(width, height);
    printBanner(image, margin, invert, out);
}
Also used : RelaxedPropertyResolver(org.springframework.boot.bind.RelaxedPropertyResolver) RelaxedPropertyResolver(org.springframework.boot.bind.RelaxedPropertyResolver) PropertyResolver(org.springframework.core.env.PropertyResolver) BufferedImage(java.awt.image.BufferedImage)

Example 12 with PropertyResolver

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

the class ResourceBanner method printBanner.

@Override
public void printBanner(Environment environment, Class<?> sourceClass, PrintStream out) {
    try {
        String banner = StreamUtils.copyToString(this.resource.getInputStream(), environment.getProperty("banner.charset", Charset.class, Charset.forName("UTF-8")));
        for (PropertyResolver resolver : getPropertyResolvers(environment, sourceClass)) {
            banner = resolver.resolvePlaceholders(banner);
        }
        out.println(banner);
    } catch (Exception ex) {
        logger.warn("Banner not printable: " + this.resource + " (" + ex.getClass() + ": '" + ex.getMessage() + "')", ex);
    }
}
Also used : Charset(java.nio.charset.Charset) PropertyResolver(org.springframework.core.env.PropertyResolver) PropertySourcesPropertyResolver(org.springframework.core.env.PropertySourcesPropertyResolver)

Example 13 with PropertyResolver

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

the class LogFileTests method loggingFile.

@Test
public void loggingFile() throws Exception {
    PropertyResolver resolver = getPropertyResolver("log.file", null);
    LogFile logFile = LogFile.get(resolver);
    Properties properties = new Properties();
    logFile.applyTo(properties);
    assertThat(logFile.toString()).isEqualTo("log.file");
    assertThat(properties.getProperty("LOG_FILE")).isEqualTo("log.file");
    assertThat(properties.getProperty("LOG_PATH")).isNull();
}
Also used : PropertyResolver(org.springframework.core.env.PropertyResolver) PropertySourcesPropertyResolver(org.springframework.core.env.PropertySourcesPropertyResolver) Properties(java.util.Properties) Test(org.junit.Test)

Example 14 with PropertyResolver

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

the class LogFileTests method noProperties.

@Test
public void noProperties() throws Exception {
    PropertyResolver resolver = getPropertyResolver(null, null);
    LogFile logFile = LogFile.get(resolver);
    assertThat(logFile).isNull();
}
Also used : PropertyResolver(org.springframework.core.env.PropertyResolver) PropertySourcesPropertyResolver(org.springframework.core.env.PropertySourcesPropertyResolver) Test(org.junit.Test)

Example 15 with PropertyResolver

use of org.springframework.core.env.PropertyResolver in project uPortal by Jasig.

the class BasicAuthInterceptorTest method testInterceptorWithUsernamePassword.

@Test
public void testInterceptorWithUsernamePassword() throws Exception {
    final String id = "test";
    final String username = "test";
    final String password = "test";
    PropertyResolver resolver = mock(PropertyResolver.class);
    when(resolver.getProperty(eq("org.jasig.rest.interceptor.basic-auth." + id + ".username"))).thenReturn(username);
    when(resolver.getProperty(eq("org.jasig.rest.interceptor.basic-auth." + id + ".password"))).thenReturn(password);
    doInterceptorTest(resolver, id, "dGVzdDp0ZXN0");
}
Also used : PropertyResolver(org.springframework.core.env.PropertyResolver) Test(org.junit.Test)

Aggregations

PropertyResolver (org.springframework.core.env.PropertyResolver)15 Test (org.junit.Test)7 PropertySourcesPropertyResolver (org.springframework.core.env.PropertySourcesPropertyResolver)7 RelaxedPropertyResolver (org.springframework.boot.bind.RelaxedPropertyResolver)5 Properties (java.util.Properties)3 BufferedImage (java.awt.image.BufferedImage)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 URI (java.net.URI)1 Charset (java.nio.charset.Charset)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 CompositePropertySource (org.springframework.core.env.CompositePropertySource)1 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)1 EnumerablePropertySource (org.springframework.core.env.EnumerablePropertySource)1 PropertySource (org.springframework.core.env.PropertySource)1 HttpHeaders (org.springframework.http.HttpHeaders)1 HttpMethod (org.springframework.http.HttpMethod)1 ClientHttpRequest (org.springframework.http.client.ClientHttpRequest)1 ClientHttpRequestFactory (org.springframework.http.client.ClientHttpRequestFactory)1