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");
}
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");
}
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;
}
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));
}
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));
}
Aggregations