Java Code Examples for org.springframework.context.support.GenericXmlApplicationContext#setEnvironment()

The following examples show how to use org.springframework.context.support.GenericXmlApplicationContext#setEnvironment() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContextNamespaceHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void propertyPlaceholderEnvironmentProperties() {
	MockEnvironment env = new MockEnvironment().withProperty("foo", "spam");
	GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
	applicationContext.setEnvironment(env);
	applicationContext.load(new ClassPathResource("contextNamespaceHandlerTests-simple.xml", getClass()));
	applicationContext.refresh();
	assertEquals("spam", applicationContext.getBean("string"));
	assertEquals("none", applicationContext.getBean("fallback"));
}
 
Example 2
Source File: EnvironmentSystemIntegrationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void genericXmlApplicationContext() {
	GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
	assertHasStandardEnvironment(ctx);
	ctx.setEnvironment(prodEnv);
	ctx.load(XML_PATH);
	ctx.refresh();

	assertHasEnvironment(ctx, prodEnv);
	assertEnvironmentBeanRegistered(ctx);
	assertEnvironmentAwareInvoked(ctx, prodEnv);
	assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
	assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
 
Example 3
Source File: ContextNamespaceHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void propertyPlaceholderEnvironmentProperties() throws Exception {
	MockEnvironment env = new MockEnvironment().withProperty("foo", "spam");
	GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
	applicationContext.setEnvironment(env);
	applicationContext.load(new ClassPathResource("contextNamespaceHandlerTests-simple.xml", getClass()));
	applicationContext.refresh();
	assertEquals("spam", applicationContext.getBean("string"));
	assertEquals("none", applicationContext.getBean("fallback"));
}
 
Example 4
Source File: EnvironmentSystemIntegrationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void genericXmlApplicationContext() {
	GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
	assertHasStandardEnvironment(ctx);
	ctx.setEnvironment(prodEnv);
	ctx.load(XML_PATH);
	ctx.refresh();

	assertHasEnvironment(ctx, prodEnv);
	assertEnvironmentBeanRegistered(ctx);
	assertEnvironmentAwareInvoked(ctx, prodEnv);
	assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
	assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
 
Example 5
Source File: ContextNamespaceHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void propertyPlaceholderEnvironmentProperties() throws Exception {
	MockEnvironment env = new MockEnvironment().withProperty("foo", "spam");
	GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
	applicationContext.setEnvironment(env);
	applicationContext.load(new ClassPathResource("contextNamespaceHandlerTests-simple.xml", getClass()));
	applicationContext.refresh();
	Map<String, PlaceholderConfigurerSupport> beans = applicationContext
			.getBeansOfType(PlaceholderConfigurerSupport.class);
	assertFalse("No PropertyPlaceholderConfigurer found", beans.isEmpty());
	assertEquals("spam", applicationContext.getBean("string"));
	assertEquals("none", applicationContext.getBean("fallback"));
}
 
Example 6
Source File: EnvironmentSystemIntegrationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void genericXmlApplicationContext() {
	GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
	assertHasStandardEnvironment(ctx);
	ctx.setEnvironment(prodEnv);
	ctx.load(XML_PATH);
	ctx.refresh();

	assertHasEnvironment(ctx, prodEnv);
	assertEnvironmentBeanRegistered(ctx);
	assertEnvironmentAwareInvoked(ctx, prodEnv);
	assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
	assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}