Search in sources :

Example 6 with StandardEnvironment

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

the class SpringApplicationTests method addProfilesOrderWithProperties.

@Test
public void addProfilesOrderWithProperties() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    application.setAdditionalProfiles("other");
    ConfigurableEnvironment environment = new StandardEnvironment();
    application.setEnvironment(environment);
    this.context = application.run();
    // Active profile should win over default
    assertThat(environment.getProperty("my.property")).isEqualTo("fromotherpropertiesfile");
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.Test)

Example 7 with StandardEnvironment

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

the class SpringApplicationTests method addProfilesOrder.

@Test
public void addProfilesOrder() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    application.setAdditionalProfiles("foo");
    ConfigurableEnvironment environment = new StandardEnvironment();
    application.setEnvironment(environment);
    this.context = application.run("--spring.profiles.active=bar,spam");
    // Command line should always come last
    assertThat(environment.getActiveProfiles()).containsExactly("foo", "bar", "spam");
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.Test)

Example 8 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project spring-framework by spring-projects.

the class ProfileXmlBeanDefinitionTests method beanFactoryFor.

private BeanDefinitionRegistry beanFactoryFor(String xmlName, String... activeProfiles) {
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
    StandardEnvironment env = new StandardEnvironment();
    env.setActiveProfiles(activeProfiles);
    reader.setEnvironment(env);
    reader.loadBeanDefinitions(new ClassPathResource(xmlName, getClass()));
    return beanFactory;
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) StandardEnvironment(org.springframework.core.env.StandardEnvironment)

Example 9 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project spring-framework by spring-projects.

the class ClassPathScanningCandidateComponentProviderTests method testWithActiveProfile.

@Test
public void testWithActiveProfile() {
    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
    ConfigurableEnvironment env = new StandardEnvironment();
    env.setActiveProfiles(ProfileAnnotatedComponent.PROFILE_NAME);
    provider.setEnvironment(env);
    Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_PROFILE_PACKAGE);
    assertThat(containsBeanClass(candidates, ProfileAnnotatedComponent.class), is(true));
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) ProfileAnnotatedComponent(example.profilescan.ProfileAnnotatedComponent) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) AnnotatedGenericBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.Test)

Example 10 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project spring-framework by spring-projects.

the class ClassPathScanningCandidateComponentProviderTests method testWithInactiveProfile.

@Test
public void testWithInactiveProfile() {
    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
    ConfigurableEnvironment env = new StandardEnvironment();
    env.setActiveProfiles("other");
    provider.setEnvironment(env);
    Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_PROFILE_PACKAGE);
    assertThat(containsBeanClass(candidates, ProfileAnnotatedComponent.class), is(false));
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) ProfileAnnotatedComponent(example.profilescan.ProfileAnnotatedComponent) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) AnnotatedGenericBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.Test)

Aggregations

StandardEnvironment (org.springframework.core.env.StandardEnvironment)52 Test (org.junit.Test)41 MapPropertySource (org.springframework.core.env.MapPropertySource)27 URI (java.net.URI)23 HashMap (java.util.HashMap)23 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)23 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)21 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)18 ProtobufMessageSerDe (com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe)15 RestTemplate (org.springframework.web.client.RestTemplate)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 SerDeHttpMessageConverter (com.kixeye.chassis.transport.http.SerDeHttpMessageConverter)13 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)13 QueuingWebSocketListener (com.kixeye.chassis.transport.websocket.QueuingWebSocketListener)9 WebSocketMessageRegistry (com.kixeye.chassis.transport.websocket.WebSocketMessageRegistry)9 Envelope (com.kixeye.chassis.transport.dto.Envelope)7 ArrayList (java.util.ArrayList)7