@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2012 the original author or authors .
* Copyright 2002 - 2014 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -67,7 +67,6 @@ import static org.springframework.beans.factory.support.BeanDefinitionBuilder.*;
@@ -67,7 +67,6 @@ import static org.springframework.beans.factory.support.BeanDefinitionBuilder.*;
import static org.springframework.context.ConfigurableApplicationContext.* ;
import static org.springframework.core.env.EnvironmentIntegrationTests.Constants.* ;
/ * *
* Integration tests for container support of { @link Environment }
* interface .
@ -84,29 +83,15 @@ import static org.springframework.core.env.EnvironmentIntegrationTests.Constants
@@ -84,29 +83,15 @@ import static org.springframework.core.env.EnvironmentIntegrationTests.Constants
*
* @author Chris Beams
* /
@SuppressWarnings ( "resource" )
public class EnvironmentIntegrationTests {
private ConfigurableEnvironment prodEnv ;
private ConfigurableEnvironment devEnv ;
private ConfigurableEnvironment prodWebEnv ;
/ * *
* Constants used both locally and in scan * sub - packages
* /
public static class Constants {
public static final String XML_PATH = "org/springframework/core/env/EnvironmentIntegrationTests-context.xml" ;
public static final String ENVIRONMENT_AWARE_BEAN_NAME = "envAwareBean" ;
private ConfigurableEnvironment devEnv ;
public static final String PROD_BEAN_NAME = "prodBean" ;
public static final String DEV_BEAN_NAME = "devBean" ;
public static final String DERIVED_DEV_BEAN_NAME = "derivedDevBean" ;
public static final String TRANSITIVE_BEAN_NAME = "transitiveBean" ;
private ConfigurableEnvironment prodWebEnv ;
public static final String PROD_ENV_NAME = "prod" ;
public static final String DEV_ENV_NAME = "dev" ;
public static final String DERIVED_DEV_ENV_NAME = "derivedDev" ;
}
@Before
public void setUp ( ) {
@ -122,9 +107,7 @@ public class EnvironmentIntegrationTests {
@@ -122,9 +107,7 @@ public class EnvironmentIntegrationTests {
@Test
public void genericApplicationContext_standardEnv ( ) {
ConfigurableApplicationContext ctx =
new GenericApplicationContext ( newBeanFactoryWithEnvironmentAwareBean ( ) ) ;
ConfigurableApplicationContext ctx = new GenericApplicationContext ( newBeanFactoryWithEnvironmentAwareBean ( ) ) ;
ctx . refresh ( ) ;
assertHasStandardEnvironment ( ctx ) ;
@ -134,8 +117,7 @@ public class EnvironmentIntegrationTests {
@@ -134,8 +117,7 @@ public class EnvironmentIntegrationTests {
@Test
public void genericApplicationContext_customEnv ( ) {
GenericApplicationContext ctx =
new GenericApplicationContext ( newBeanFactoryWithEnvironmentAwareBean ( ) ) ;
GenericApplicationContext ctx = new GenericApplicationContext ( newBeanFactoryWithEnvironmentAwareBean ( ) ) ;
ctx . setEnvironment ( prodEnv ) ;
ctx . refresh ( ) ;
@ -191,11 +173,8 @@ public class EnvironmentIntegrationTests {
@@ -191,11 +173,8 @@ public class EnvironmentIntegrationTests {
@Test
public void genericXmlApplicationContext ( ) {
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext ( ) ;
assertHasStandardEnvironment ( ctx ) ;
ctx . setEnvironment ( prodEnv ) ;
ctx . load ( XML_PATH ) ;
ctx . refresh ( ) ;
@ -208,8 +187,7 @@ public class EnvironmentIntegrationTests {
@@ -208,8 +187,7 @@ public class EnvironmentIntegrationTests {
@Test
public void classPathXmlApplicationContext ( ) {
ConfigurableApplicationContext ctx =
new ClassPathXmlApplicationContext ( new String [ ] { XML_PATH } ) ;
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext ( XML_PATH ) ;
ctx . setEnvironment ( prodEnv ) ;
ctx . refresh ( ) ;
@ -228,7 +206,7 @@ public class EnvironmentIntegrationTests {
@@ -228,7 +206,7 @@ public class EnvironmentIntegrationTests {
// strange - FSXAC strips leading '/' unless prefixed with 'file:'
ConfigurableApplicationContext ctx =
new FileSystemXmlApplicationContext ( new String [ ] { "file:" + tmpFile . getPath ( ) } , false ) ;
new FileSystemXmlApplicationContext ( new String [ ] { "file:" + tmpFile . getPath ( ) } , false ) ;
ctx . setEnvironment ( prodEnv ) ;
ctx . refresh ( ) ;
assertEnvironmentBeanRegistered ( ctx ) ;
@ -336,11 +314,8 @@ public class EnvironmentIntegrationTests {
@@ -336,11 +314,8 @@ public class EnvironmentIntegrationTests {
@Test
public void webApplicationContext ( ) {
GenericWebApplicationContext ctx =
new GenericWebApplicationContext ( newBeanFactoryWithEnvironmentAwareBean ( ) ) ;
GenericWebApplicationContext ctx = new GenericWebApplicationContext ( newBeanFactoryWithEnvironmentAwareBean ( ) ) ;
assertHasStandardServletEnvironment ( ctx ) ;
ctx . setEnvironment ( prodWebEnv ) ;
ctx . refresh ( ) ;
@ -588,7 +563,8 @@ public class EnvironmentIntegrationTests {
@@ -588,7 +563,8 @@ public class EnvironmentIntegrationTests {
try {
ctx . refresh ( ) ;
fail ( "expected missing property exception" ) ;
} catch ( MissingRequiredPropertiesException ex ) {
}
catch ( MissingRequiredPropertiesException ex ) {
}
}
@ -598,7 +574,6 @@ public class EnvironmentIntegrationTests {
@@ -598,7 +574,6 @@ public class EnvironmentIntegrationTests {
ctx . setEnvironment ( new MockEnvironment ( ) . withProperty ( "foo" , "fooValue" ) ) ;
ctx . refresh ( ) ; // should succeed
}
}
@ -652,6 +627,7 @@ public class EnvironmentIntegrationTests {
@@ -652,6 +627,7 @@ public class EnvironmentIntegrationTests {
assertThat ( ctx . getBean ( EnvironmentAwareBean . class ) . environment , is ( expectedEnv ) ) ;
}
private static class EnvironmentAwareBean implements EnvironmentAware {
public Environment environment ;
@ -660,9 +636,9 @@ public class EnvironmentIntegrationTests {
@@ -660,9 +636,9 @@ public class EnvironmentIntegrationTests {
public void setEnvironment ( Environment environment ) {
this . environment = environment ;
}
}
/ * *
* Mirrors the structure of beans and environment - specific config files
* in EnvironmentIntegrationTests - context . xml
@ -711,4 +687,25 @@ public class EnvironmentIntegrationTests {
@@ -711,4 +687,25 @@ public class EnvironmentIntegrationTests {
return new Object ( ) ;
}
}
/ * *
* Constants used both locally and in scan * sub - packages
* /
public static class Constants {
public static final String XML_PATH = "org/springframework/core/env/EnvironmentIntegrationTests-context.xml" ;
public static final String ENVIRONMENT_AWARE_BEAN_NAME = "envAwareBean" ;
public static final String PROD_BEAN_NAME = "prodBean" ;
public static final String DEV_BEAN_NAME = "devBean" ;
public static final String DERIVED_DEV_BEAN_NAME = "derivedDevBean" ;
public static final String TRANSITIVE_BEAN_NAME = "transitiveBean" ;
public static final String PROD_ENV_NAME = "prod" ;
public static final String DEV_ENV_NAME = "dev" ;
public static final String DERIVED_DEV_ENV_NAME = "derivedDev" ;
}
}