Search in sources :

Example 26 with CompositePropertySource

use of org.springframework.core.env.CompositePropertySource in project cas by apereo.

the class DefaultCasConfigurationPropertiesSourceLocatorTests method verifyGroovySlurper.

@Test
public void verifyGroovySlurper() {
    val source = casCoreBootstrapPropertySourceLocator.locate(environment);
    assertTrue(source instanceof CompositePropertySource);
    val composite = (CompositePropertySource) source;
    assertEquals("Static", composite.getProperty("cas.authn.accept.name"));
    assertEquals("test::dev", composite.getProperty("cas.authn.accept.users"));
}
Also used : lombok.val(lombok.val) CompositePropertySource(org.springframework.core.env.CompositePropertySource) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 27 with CompositePropertySource

use of org.springframework.core.env.CompositePropertySource in project cas by apereo.

the class DefaultCasConfigurationPropertiesSourceLocatorTests method verifyLocator.

@Test
public void verifyLocator() {
    val source = casCoreBootstrapPropertySourceLocator.locate(environment);
    assertTrue(source instanceof CompositePropertySource);
    assertNotNull(casConfigurationWatchService);
    val composite = (CompositePropertySource) source;
    assertEquals("https://cas.example.org:9999", composite.getProperty("cas.server.name"));
    assertEquals("https://cas.example.org/something", composite.getProperty("cas.server.prefix"));
}
Also used : lombok.val(lombok.val) CompositePropertySource(org.springframework.core.env.CompositePropertySource) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 28 with CompositePropertySource

use of org.springframework.core.env.CompositePropertySource in project cas by apereo.

the class DefaultCasConfigurationPropertiesSourceLocatorTests method verifyPriority.

@Test
public void verifyPriority() {
    val source = casCoreBootstrapPropertySourceLocator.locate(environment);
    assertTrue(source instanceof CompositePropertySource);
    val composite = (CompositePropertySource) source;
    assertEquals("file", composite.getProperty("test.file"));
    assertEquals("dirAppYml", composite.getProperty("test.dir.app"));
    assertEquals("classpathAppYml", composite.getProperty("test.classpath"));
    assertEquals("devProfileProp", composite.getProperty("test.dir.profile"));
    assertEquals("standaloneProfileProp", composite.getProperty("profile.override.me"));
    assertEquals("dirCasProp", composite.getProperty("test.dir.cas"));
}
Also used : lombok.val(lombok.val) CompositePropertySource(org.springframework.core.env.CompositePropertySource) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 29 with CompositePropertySource

use of org.springframework.core.env.CompositePropertySource in project cas by apereo.

the class WebjarValidationTests method verifyValidation.

@Test
public void verifyValidation() throws IOException {
    val compositePropertySource = new CompositePropertySource("webjars");
    compositePropertySource.addPropertySource(new PropertiesPropertySource("messages", PropertiesLoaderUtils.loadProperties(new ClassPathResource("cas_common_messages.properties"))));
    compositePropertySource.addPropertySource(new PropertiesPropertySource("versions", PropertiesLoaderUtils.loadProperties(new FileSystemResource("../../gradle.properties"))));
    Arrays.stream(compositePropertySource.getPropertyNames()).filter(key -> key.startsWith("webjars.")).map(key -> new ClassPathResource("META-INF/resources" + compositePropertySource.getProperty(key))).forEach(resource -> assertTrue(resource.exists(), () -> "Webjar path bad: " + resource.getPath()));
}
Also used : lombok.val(lombok.val) Test(org.junit.jupiter.api.Test) CompositePropertySource(org.springframework.core.env.CompositePropertySource) PropertiesLoaderUtils(org.springframework.core.io.support.PropertiesLoaderUtils) Arrays(java.util.Arrays) lombok.val(lombok.val) PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) ClassPathResource(org.springframework.core.io.ClassPathResource) Assertions(org.junit.jupiter.api.Assertions) FileSystemResource(org.springframework.core.io.FileSystemResource) IOException(java.io.IOException) Tag(org.junit.jupiter.api.Tag) CompositePropertySource(org.springframework.core.env.CompositePropertySource) PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) FileSystemResource(org.springframework.core.io.FileSystemResource) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 30 with CompositePropertySource

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

the class SpringApplicationTests method commandLinePropertySourceEnhancesEnvironment.

@Test
void commandLinePropertySourceEnhancesEnvironment() {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    ConfigurableEnvironment environment = new StandardEnvironment();
    environment.getPropertySources().addFirst(new MapPropertySource("commandLineArgs", Collections.singletonMap("foo", "original")));
    application.setEnvironment(environment);
    this.context = application.run("--foo=bar", "--bar=foo");
    assertThat(environment).has(matchingPropertySource(CompositePropertySource.class, "commandLineArgs"));
    assertThat(environment.getProperty("bar")).isEqualTo("foo");
    // New command line properties take precedence
    assertThat(environment.getProperty("foo")).isEqualTo("bar");
    CompositePropertySource composite = (CompositePropertySource) environment.getPropertySources().get("commandLineArgs");
    assertThat(composite.getPropertySources()).hasSize(2);
    assertThat(composite.getPropertySources()).first().matches((source) -> source.getName().equals("springApplicationCommandLineArgs"), "is named springApplicationCommandLineArgs");
    assertThat(composite.getPropertySources()).element(1).matches((source) -> source.getName().equals("commandLineArgs"), "is named commandLineArgs");
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) CompositePropertySource(org.springframework.core.env.CompositePropertySource) MapPropertySource(org.springframework.core.env.MapPropertySource) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Aggregations

CompositePropertySource (org.springframework.core.env.CompositePropertySource)35 MapPropertySource (org.springframework.core.env.MapPropertySource)11 Test (org.junit.Test)10 MutablePropertySources (org.springframework.core.env.MutablePropertySources)10 lombok.val (lombok.val)9 HashMap (java.util.HashMap)7 Test (org.junit.jupiter.api.Test)7 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)6 StandardEnvironment (org.springframework.core.env.StandardEnvironment)5 IOException (java.io.IOException)4 Map (java.util.Map)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 EnumerablePropertySource (org.springframework.core.env.EnumerablePropertySource)4 PropertySource (org.springframework.core.env.PropertySource)4 Arrays (java.util.Arrays)3 List (java.util.List)3 FileSystemResource (org.springframework.core.io.FileSystemResource)3 Resource (org.springframework.core.io.Resource)3 Config (com.ctrip.framework.apollo.Config)2 File (java.io.File)2