Browse Source
- TextContext now works with MergedContextConfiguration instead of locations and loader - TextContext now builds context caching key from MergedContextConfiguration - Test context caching is now based on locations, classes, active profiles, and context loader - TextContext now delegates to SmartContextLoader or ContextLoader as appropriate - AbstractContextLoader now implements SmartContextLoader - AbstractGenericContextLoader now sets active profiles in the GenericApplicationContext - Introduced integration tests for profile support in the TCF for both XML and annotation configpull/7/head
17 changed files with 493 additions and 44 deletions
@ -0,0 +1,14 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<beansProjectDescription> |
||||||
|
<version>1</version> |
||||||
|
<pluginVersion><![CDATA[2.6.0.201104111100-PATCH]]></pluginVersion> |
||||||
|
<configSuffixes> |
||||||
|
<configSuffix><![CDATA[xml]]></configSuffix> |
||||||
|
</configSuffixes> |
||||||
|
<enableImports><![CDATA[false]]></enableImports> |
||||||
|
<configs> |
||||||
|
<config>src/test/java/org/springframework/test/context/junit4/profile/xml/DefaultProfileXmlConfigTests-context.xml</config> |
||||||
|
</configs> |
||||||
|
<configSets> |
||||||
|
</configSets> |
||||||
|
</beansProjectDescription> |
@ -0,0 +1,58 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2011 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. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.springframework.test.context.junit4.profile.annotation; |
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals; |
||||||
|
import static org.junit.Assert.assertNotNull; |
||||||
|
import static org.junit.Assert.assertNull; |
||||||
|
|
||||||
|
import org.junit.Test; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.springframework.beans.Employee; |
||||||
|
import org.springframework.beans.Pet; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.test.context.ContextConfiguration; |
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
||||||
|
import org.springframework.test.context.support.AnnotationConfigContextLoader; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Sam Brannen |
||||||
|
* @since 3.1 |
||||||
|
*/ |
||||||
|
@RunWith(SpringJUnit4ClassRunner.class) |
||||||
|
@ContextConfiguration(classes = { DefaultProfileConfig.class, DevProfileConfig.class }, loader = AnnotationConfigContextLoader.class) |
||||||
|
public class DefaultProfileAnnotationConfigTests { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
protected Pet pet; |
||||||
|
|
||||||
|
@Autowired(required = false) |
||||||
|
protected Employee employee; |
||||||
|
|
||||||
|
|
||||||
|
@Test |
||||||
|
public void pet() { |
||||||
|
assertNotNull(pet); |
||||||
|
assertEquals("Fido", pet.getName()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void employee() { |
||||||
|
assertNull("employee bean should not be created for the default profile", employee); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,35 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2011 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. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.springframework.test.context.junit4.profile.annotation; |
||||||
|
|
||||||
|
import org.springframework.beans.Pet; |
||||||
|
import org.springframework.context.annotation.Bean; |
||||||
|
import org.springframework.context.annotation.Configuration; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Sam Brannen |
||||||
|
* @since 3.1 |
||||||
|
*/ |
||||||
|
@Configuration |
||||||
|
public class DefaultProfileConfig { |
||||||
|
|
||||||
|
@Bean |
||||||
|
public Pet pet() { |
||||||
|
return new Pet("Fido"); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,38 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2011 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. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.springframework.test.context.junit4.profile.annotation; |
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals; |
||||||
|
import static org.junit.Assert.assertNotNull; |
||||||
|
|
||||||
|
import org.junit.Test; |
||||||
|
import org.springframework.test.context.ActiveProfiles; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Sam Brannen |
||||||
|
* @since 3.1 |
||||||
|
*/ |
||||||
|
@ActiveProfiles("dev") |
||||||
|
public class DevProfileAnnotationConfigTests extends DefaultProfileAnnotationConfigTests { |
||||||
|
|
||||||
|
@Test |
||||||
|
public void employee() { |
||||||
|
assertNotNull("employee bean should be loaded for the 'dev' profile", employee); |
||||||
|
assertEquals("John Smith", employee.getName()); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2011 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. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.springframework.test.context.junit4.profile.annotation; |
||||||
|
|
||||||
|
import org.springframework.beans.Employee; |
||||||
|
import org.springframework.context.annotation.Bean; |
||||||
|
import org.springframework.context.annotation.Configuration; |
||||||
|
import org.springframework.context.annotation.Profile; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Sam Brannen |
||||||
|
* @since 3.1 |
||||||
|
*/ |
||||||
|
@Profile("dev") |
||||||
|
@Configuration |
||||||
|
public class DevProfileConfig { |
||||||
|
|
||||||
|
@Bean |
||||||
|
public Employee employee() { |
||||||
|
Employee employee = new Employee(); |
||||||
|
employee.setName("John Smith"); |
||||||
|
employee.setAge(42); |
||||||
|
employee.setCompany("Acme Widgets, Inc."); |
||||||
|
return employee; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2002-2011 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. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.springframework.test.context.junit4.profile.annotation; |
||||||
|
|
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.junit.runners.Suite; |
||||||
|
import org.junit.runners.Suite.SuiteClasses; |
||||||
|
|
||||||
|
/** |
||||||
|
* JUnit test suite for <em>bean definition profile</em> support in the |
||||||
|
* Spring TestContext Framework with XML-based configuration. |
||||||
|
* |
||||||
|
* @author Sam Brannen |
||||||
|
* @since 3.1 |
||||||
|
*/ |
||||||
|
@RunWith(Suite.class) |
||||||
|
// Note: the following 'multi-line' layout is for enhanced code readability.
|
||||||
|
@SuiteClasses({//
|
||||||
|
DefaultProfileAnnotationConfigTests.class,//
|
||||||
|
DevProfileAnnotationConfigTests.class //
|
||||||
|
}) |
||||||
|
public class ProfileAnnotationConfigTestSuite { |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"> |
||||||
|
|
||||||
|
<bean id="pet" class="org.springframework.beans.Pet"> |
||||||
|
<constructor-arg value="Fido" /> |
||||||
|
</bean> |
||||||
|
|
||||||
|
<beans profile="dev"> |
||||||
|
<bean id="employee" class="org.springframework.beans.Employee"> |
||||||
|
<property name="name" value="John Smith" /> |
||||||
|
<property name="age" value="42" /> |
||||||
|
<property name="company" value="Acme Widgets, Inc." /> |
||||||
|
</bean> |
||||||
|
</beans> |
||||||
|
|
||||||
|
</beans> |
@ -0,0 +1,59 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2011 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. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.springframework.test.context.junit4.profile.xml; |
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals; |
||||||
|
import static org.junit.Assert.assertNotNull; |
||||||
|
import static org.junit.Assert.assertNull; |
||||||
|
|
||||||
|
import org.junit.Test; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.springframework.beans.Employee; |
||||||
|
import org.springframework.beans.Pet; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.test.context.ContextConfiguration; |
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
||||||
|
|
||||||
|
/** |
||||||
|
* TODO Document DefaultProfileXmlConfigTests. |
||||||
|
* |
||||||
|
* @author Sam Brannen |
||||||
|
* @since 3.1 |
||||||
|
*/ |
||||||
|
@RunWith(SpringJUnit4ClassRunner.class) |
||||||
|
@ContextConfiguration |
||||||
|
public class DefaultProfileXmlConfigTests { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
protected Pet pet; |
||||||
|
|
||||||
|
@Autowired(required = false) |
||||||
|
protected Employee employee; |
||||||
|
|
||||||
|
|
||||||
|
@Test |
||||||
|
public void pet() { |
||||||
|
assertNotNull(pet); |
||||||
|
assertEquals("Fido", pet.getName()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void employee() { |
||||||
|
assertNull("employee bean should not be created for the default profile", employee); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,40 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2011 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. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.springframework.test.context.junit4.profile.xml; |
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals; |
||||||
|
import static org.junit.Assert.assertNotNull; |
||||||
|
|
||||||
|
import org.junit.Test; |
||||||
|
import org.springframework.test.context.ActiveProfiles; |
||||||
|
|
||||||
|
/** |
||||||
|
* TODO Document DefaultProfileXmlConfigTests. |
||||||
|
* |
||||||
|
* @author Sam Brannen |
||||||
|
* @since 3.1 |
||||||
|
*/ |
||||||
|
@ActiveProfiles("dev") |
||||||
|
public class DevProfileXmlConfigTests extends DefaultProfileXmlConfigTests { |
||||||
|
|
||||||
|
@Test |
||||||
|
public void employee() { |
||||||
|
assertNotNull("employee bean should be loaded for the 'dev' profile", employee); |
||||||
|
assertEquals("John Smith", employee.getName()); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2002-2011 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. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.springframework.test.context.junit4.profile.xml; |
||||||
|
|
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.junit.runners.Suite; |
||||||
|
import org.junit.runners.Suite.SuiteClasses; |
||||||
|
|
||||||
|
/** |
||||||
|
* JUnit test suite for <em>bean definition profile</em> support in the |
||||||
|
* Spring TestContext Framework with XML-based configuration. |
||||||
|
* |
||||||
|
* @author Sam Brannen |
||||||
|
* @since 3.1 |
||||||
|
*/ |
||||||
|
@RunWith(Suite.class) |
||||||
|
// Note: the following 'multi-line' layout is for enhanced code readability.
|
||||||
|
@SuiteClasses({//
|
||||||
|
DefaultProfileXmlConfigTests.class,//
|
||||||
|
DevProfileXmlConfigTests.class //
|
||||||
|
}) |
||||||
|
public class ProfileXmlConfigTestSuite { |
||||||
|
} |
Loading…
Reference in new issue