diff --git a/org.springframework.context/src/test/java/org/springframework/beans/factory/xml/MapAndSet.java b/org.springframework.context/src/test/java/org/springframework/beans/factory/xml/MapAndSet.java deleted file mode 100644 index 1d059ea569..0000000000 --- a/org.springframework.context/src/test/java/org/springframework/beans/factory/xml/MapAndSet.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2002-2006 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.beans.factory.xml; - -import java.util.Map; -import java.util.Set; - -/** - * @author Chris Beams - */ -public class MapAndSet { - - private Object obj; - - public MapAndSet(Map map) { - this.obj = map; - } - - public MapAndSet(Set set) { - this.obj = set; - } - - public Object getObject() { - return obj; - } -} diff --git a/org.springframework.context/src/test/java/org/springframework/beans/factory/xml/MixedCollectionBean.java b/org.springframework.context/src/test/java/org/springframework/beans/factory/xml/MixedCollectionBean.java deleted file mode 100644 index 8ed5f2517e..0000000000 --- a/org.springframework.context/src/test/java/org/springframework/beans/factory/xml/MixedCollectionBean.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2002-2006 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.beans.factory.xml; - -import java.util.Collection; - -/** - * Bean that exposes a simple property that can be set - * to a mix of references and individual values. - * - * @author Rod Johnson - * @since 27.05.2003 - */ -public class MixedCollectionBean { - - private Collection jumble; - - - public void setJumble(Collection jumble) { - this.jumble = jumble; - } - - public Collection getJumble() { - return jumble; - } - -} diff --git a/org.springframework.context/src/test/java/org/springframework/beans/factory/xml/test.xml b/org.springframework.context/src/test/java/org/springframework/beans/factory/xml/test.xml deleted file mode 100644 index e67e310136..0000000000 --- a/org.springframework.context/src/test/java/org/springframework/beans/factory/xml/test.xml +++ /dev/null @@ -1,127 +0,0 @@ - - - - - - - - I have no properties and I'm happy without them. - - - - - - aliased - - - - - - - - aliased - - - - - - aliased - - - - - - - - - - - - - - Rod - 31 - - - - - - Roderick - - - - - Kerry - 34 - - - - - - Kathy - 28 - - - - - typeMismatch - 34x - - - - - - - - true - - - - true - - - - - - - - false - - - - - - - - - - - - - - - - - - - - - - - listenerVeto - 66 - - - - - - this is a ]]> - - - diff --git a/org.springframework.context/src/test/java/org/springframework/context/access/ContextBeanFactoryReferenceTests.java b/org.springframework.context/src/test/java/org/springframework/context/access/ContextBeanFactoryReferenceTests.java index 11d79f4e81..ca79f530b3 100644 --- a/org.springframework.context/src/test/java/org/springframework/context/access/ContextBeanFactoryReferenceTests.java +++ b/org.springframework.context/src/test/java/org/springframework/context/access/ContextBeanFactoryReferenceTests.java @@ -16,24 +16,26 @@ package org.springframework.context.access; -import junit.framework.TestCase; +import static org.easymock.EasyMock.*; +import static org.junit.Assert.assertNotNull; -import org.easymock.MockControl; +import org.junit.Test; import org.springframework.context.ConfigurableApplicationContext; /** - * Unit test for ContextBeanFactoryReference + * Unit test for {@link ContextBeanFactoryReference} * * @author Colin Sampaleanu + * @author Chris Beams */ -public class ContextBeanFactoryReferenceTests extends TestCase { +public class ContextBeanFactoryReferenceTests { + @Test public void testAllOperations() { - MockControl control = MockControl.createControl(ConfigurableApplicationContext.class); - ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) control.getMock(); + ConfigurableApplicationContext ctx = createMock(ConfigurableApplicationContext.class); ctx.close(); - control.replay(); + replay(ctx); ContextBeanFactoryReference bfr = new ContextBeanFactoryReference(ctx); @@ -47,6 +49,6 @@ public class ContextBeanFactoryReferenceTests extends TestCase { // expected } - control.verify(); + verify(ctx); } } diff --git a/org.springframework.context/src/test/java/org/springframework/beans/factory/xml/collections.xml b/org.springframework.context/src/test/java/org/springframework/context/access/ContextJndiBeanFactoryLocatorTests-collections.xml similarity index 97% rename from org.springframework.context/src/test/java/org/springframework/beans/factory/xml/collections.xml rename to org.springframework.context/src/test/java/org/springframework/context/access/ContextJndiBeanFactoryLocatorTests-collections.xml index f2fd356460..30b7c590c8 100644 --- a/org.springframework.context/src/test/java/org/springframework/beans/factory/xml/collections.xml +++ b/org.springframework.context/src/test/java/org/springframework/context/access/ContextJndiBeanFactoryLocatorTests-collections.xml @@ -74,7 +74,7 @@ - + @@ -85,7 +85,7 @@ - + @@ -352,7 +352,7 @@ - + My Map diff --git a/org.springframework.context/src/test/java/org/springframework/beans/factory/xml/parent.xml b/org.springframework.context/src/test/java/org/springframework/context/access/ContextJndiBeanFactoryLocatorTests-parent.xml similarity index 100% rename from org.springframework.context/src/test/java/org/springframework/beans/factory/xml/parent.xml rename to org.springframework.context/src/test/java/org/springframework/context/access/ContextJndiBeanFactoryLocatorTests-parent.xml diff --git a/org.springframework.context/src/test/java/org/springframework/context/access/ContextJndiBeanFactoryLocatorTests.java b/org.springframework.context/src/test/java/org/springframework/context/access/ContextJndiBeanFactoryLocatorTests.java index 551102540a..2f6728e96d 100644 --- a/org.springframework.context/src/test/java/org/springframework/context/access/ContextJndiBeanFactoryLocatorTests.java +++ b/org.springframework.context/src/test/java/org/springframework/context/access/ContextJndiBeanFactoryLocatorTests.java @@ -16,6 +16,10 @@ package org.springframework.context.access; +import java.util.Collection; +import java.util.Map; +import java.util.Set; + import junit.framework.TestCase; import org.springframework.beans.BeansException; @@ -26,10 +30,20 @@ import org.springframework.mock.jndi.SimpleNamingContextBuilder; /** * @author Colin Sampaleanu + * @author Chris Beams */ -public class ContextJndiBeanFactoryLocatorTests extends TestCase { +public final class ContextJndiBeanFactoryLocatorTests extends TestCase { - public static final String BEAN_FACTORY_PATH_ENVIRONMENT_KEY = "java:comp/env/ejb/BeanFactoryPath"; + private static final String BEAN_FACTORY_PATH_ENVIRONMENT_KEY = "java:comp/env/ejb/BeanFactoryPath"; + + private static final Class CLASS = ContextJndiBeanFactoryLocatorTests.class; + private static final String CLASSNAME = CLASS.getSimpleName(); + + private static final String FQ_PATH = "/org/springframework/context/access/"; + + private static final String COLLECTIONS_CONTEXT = FQ_PATH + CLASSNAME + "-collections.xml"; + private static final String PARENT_CONTEXT = FQ_PATH + CLASSNAME + "-parent.xml"; + public void testBeanFactoryPathRequiredFromJndiEnvironment() throws Exception { // Set up initial context but don't bind anything @@ -87,10 +101,8 @@ public class ContextJndiBeanFactoryLocatorTests extends TestCase { public void testBeanFactoryPathFromJndiEnvironmentWithSingleFile() throws Exception { SimpleNamingContextBuilder sncb = SimpleNamingContextBuilder.emptyActivatedContextBuilder(); - String path = "org/springframework/beans/factory/xml/collections.xml"; - // Set up initial context - sncb.bind(BEAN_FACTORY_PATH_ENVIRONMENT_KEY, path); + sncb.bind(BEAN_FACTORY_PATH_ENVIRONMENT_KEY, COLLECTIONS_CONTEXT); ContextJndiBeanFactoryLocator jbfl = new ContextJndiBeanFactoryLocator(); BeanFactory bf = jbfl.useBeanFactory(BEAN_FACTORY_PATH_ENVIRONMENT_KEY).getFactory(); @@ -101,7 +113,7 @@ public class ContextJndiBeanFactoryLocatorTests extends TestCase { public void testBeanFactoryPathFromJndiEnvironmentWithMultipleFiles() throws Exception { SimpleNamingContextBuilder sncb = SimpleNamingContextBuilder.emptyActivatedContextBuilder(); - String path = "/org/springframework/beans/factory/xml/collections.xml /org/springframework/beans/factory/xml/parent.xml"; + String path = String.format("%s %s", COLLECTIONS_CONTEXT, PARENT_CONTEXT); // Set up initial context sncb.bind(BEAN_FACTORY_PATH_ENVIRONMENT_KEY, path); @@ -113,3 +125,42 @@ public class ContextJndiBeanFactoryLocatorTests extends TestCase { } } + + +class MapAndSet { + + private Object obj; + + public MapAndSet(Map map) { + this.obj = map; + } + + public MapAndSet(Set set) { + this.obj = set; + } + + public Object getObject() { + return obj; + } +} + + + +/** + * Bean that exposes a simple property that can be set + * to a mix of references and individual values. + */ +class MixedCollectionBean { + + private Collection jumble; + + + public void setJumble(Collection jumble) { + this.jumble = jumble; + } + + public Collection getJumble() { + return jumble; + } + +} \ No newline at end of file diff --git a/org.springframework.context/src/test/java/org/springframework/context/access/ContextSingletonBeanFactoryLocatorTests.xml b/org.springframework.context/src/test/java/org/springframework/context/access/ContextSingletonBeanFactoryLocatorTests-context.xml similarity index 100% rename from org.springframework.context/src/test/java/org/springframework/context/access/ContextSingletonBeanFactoryLocatorTests.xml rename to org.springframework.context/src/test/java/org/springframework/context/access/ContextSingletonBeanFactoryLocatorTests-context.xml diff --git a/org.springframework.context/src/test/java/org/springframework/context/access/ContextSingletonBeanFactoryLocatorTests.java b/org.springframework.context/src/test/java/org/springframework/context/access/ContextSingletonBeanFactoryLocatorTests.java index 7bc6e1c2e3..1afbdac7cd 100644 --- a/org.springframework.context/src/test/java/org/springframework/context/access/ContextSingletonBeanFactoryLocatorTests.java +++ b/org.springframework.context/src/test/java/org/springframework/context/access/ContextSingletonBeanFactoryLocatorTests.java @@ -34,6 +34,10 @@ import org.springframework.util.ClassUtils; * @author Chris Beams */ public class ContextSingletonBeanFactoryLocatorTests extends SingletonBeanFactoryLocatorTests { + + private static final Class CLASS = ContextSingletonBeanFactoryLocatorTests.class; + private static final String CONTEXT = CLASS.getSimpleName() + "-context.xml"; + @Test public void testBaseBeanFactoryDefs() { @@ -46,8 +50,7 @@ public class ContextSingletonBeanFactoryLocatorTests extends SingletonBeanFactor @Test public void testBasicFunctionality() { ContextSingletonBeanFactoryLocator facLoc = new ContextSingletonBeanFactoryLocator( - "classpath*:" + ClassUtils.addResourcePathToPackagePath( - getClass(), "ContextSingletonBeanFactoryLocatorTests.xml")); + "classpath*:" + ClassUtils.addResourcePathToPackagePath(CLASS, CONTEXT)); basicFunctionalityTest(facLoc); @@ -65,26 +68,23 @@ public class ContextSingletonBeanFactoryLocatorTests extends SingletonBeanFactor /** * This test can run multiple times, but due to static keyed lookup of the locators, - * 2nd and subsequent calls will actuall get back same locator instance. This is not + * 2nd and subsequent calls will actually get back same locator instance. This is not * really an issue, since the contained bean factories will still be loaded and released. */ @Test public void testGetInstance() { // Try with and without 'classpath*:' prefix, and with 'classpath:' prefix. BeanFactoryLocator facLoc = ContextSingletonBeanFactoryLocator.getInstance( - ClassUtils.addResourcePathToPackagePath( - getClass(), "ContextSingletonBeanFactoryLocatorTests.xml")); + ClassUtils.addResourcePathToPackagePath(CLASS, CONTEXT)); getInstanceTest1(facLoc); facLoc = ContextSingletonBeanFactoryLocator.getInstance( - "classpath*:" + ClassUtils.addResourcePathToPackagePath( - getClass(), "ContextSingletonBeanFactoryLocatorTests.xml")); + "classpath*:" + ClassUtils.addResourcePathToPackagePath(CLASS, CONTEXT)); getInstanceTest2(facLoc); // This will actually get another locator instance, as the key is the resource name. facLoc = ContextSingletonBeanFactoryLocator.getInstance( - "classpath:" + ClassUtils.addResourcePathToPackagePath( - getClass(), "ContextSingletonBeanFactoryLocatorTests.xml")); + "classpath:" + ClassUtils.addResourcePathToPackagePath(CLASS, CONTEXT)); getInstanceTest3(facLoc); } diff --git a/org.springframework.context/src/test/java/org/springframework/beans/factory/xml/resource.xml b/org.springframework.context/src/test/java/org/springframework/context/support/ClassPathXmlApplicationContextTests-resource.xml similarity index 86% rename from org.springframework.context/src/test/java/org/springframework/beans/factory/xml/resource.xml rename to org.springframework.context/src/test/java/org/springframework/context/support/ClassPathXmlApplicationContextTests-resource.xml index 0bf9399d30..141cb3f1d6 100644 --- a/org.springframework.context/src/test/java/org/springframework/beans/factory/xml/resource.xml +++ b/org.springframework.context/src/test/java/org/springframework/context/support/ClassPathXmlApplicationContextTests-resource.xml @@ -3,7 +3,7 @@ - + diff --git a/org.springframework.context/src/test/java/org/springframework/beans/factory/xml/resourceImport.xml b/org.springframework.context/src/test/java/org/springframework/context/support/ClassPathXmlApplicationContextTests-resourceImport.xml similarity index 100% rename from org.springframework.context/src/test/java/org/springframework/beans/factory/xml/resourceImport.xml rename to org.springframework.context/src/test/java/org/springframework/context/support/ClassPathXmlApplicationContextTests-resourceImport.xml diff --git a/org.springframework.context/src/test/java/org/springframework/context/support/ClassPathXmlApplicationContextTests.java b/org.springframework.context/src/test/java/org/springframework/context/support/ClassPathXmlApplicationContextTests.java index 4f1c6c0b6a..bff30a11ad 100644 --- a/org.springframework.context/src/test/java/org/springframework/context/support/ClassPathXmlApplicationContextTests.java +++ b/org.springframework.context/src/test/java/org/springframework/context/support/ClassPathXmlApplicationContextTests.java @@ -16,6 +16,8 @@ package org.springframework.context.support; +import static org.junit.Assert.*; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -26,8 +28,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map; -import junit.framework.TestCase; - +import org.junit.Test; import org.springframework.aop.support.AopUtils; import org.springframework.beans.ResourceTestBean; import org.springframework.beans.TypeMismatchException; @@ -45,22 +46,43 @@ import org.springframework.util.ObjectUtils; /** * @author Juergen Hoeller + * @author Chris Beams */ -public class ClassPathXmlApplicationContextTests extends TestCase { +public final class ClassPathXmlApplicationContextTests { + + private static final String PATH = "/org/springframework/context/support/"; + private static final String RESOURCE_CONTEXT = PATH + "ClassPathXmlApplicationContextTests-resource.xml"; + private static final String CONTEXT_WILDCARD = PATH + "test/context*.xml"; + private static final String CONTEXT_A = "test/contextA.xml"; + private static final String CONTEXT_B = "test/contextB.xml"; + private static final String CONTEXT_C = "test/contextC.xml"; + private static final String FQ_CONTEXT_A = PATH + CONTEXT_A; + private static final String FQ_CONTEXT_B = PATH + CONTEXT_B; + private static final String FQ_CONTEXT_C = PATH + CONTEXT_C; + private static final String SIMPLE_CONTEXT = "simpleContext.xml"; + private static final String FQ_SIMPLE_CONTEXT = PATH + "simpleContext.xml"; + private static final String FQ_ALIASED_CONTEXT_C = PATH + "test/aliased-contextC.xml"; + private static final String INVALID_VALUE_TYPE_CONTEXT = PATH + "invalidValueType.xml"; + private static final String CHILD_WITH_PROXY_CONTEXT = PATH + "childWithProxy.xml"; + private static final String INVALID_CLASS_CONTEXT = "invalidClass.xml"; + private static final String CLASS_WITH_PLACEHOLDER_CONTEXT = "classWithPlaceholder.xml"; + private static final String ALIAS_THAT_OVERRIDES_PARENT_CONTEXT = PATH + "aliasThatOverridesParent.xml"; + private static final String ALIAS_FOR_PARENT_CONTEXT = PATH + "aliasForParent.xml"; + private static final String TEST_PROPERTIES = "test.properties"; + private static final String FQ_TEST_PROPERTIES = "classpath:org/springframework/beans/factory/xml/" + TEST_PROPERTIES; + + @Test public void testSingleConfigLocation() { - ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( - "/org/springframework/context/support/simpleContext.xml"); + ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(FQ_SIMPLE_CONTEXT); assertTrue(ctx.containsBean("someMessageSource")); ctx.close(); } + @Test public void testMultipleConfigLocations() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( - new String[] { - "/org/springframework/context/support/test/contextB.xml", - "/org/springframework/context/support/test/contextC.xml", - "/org/springframework/context/support/test/contextA.xml"}); + new String[] { FQ_CONTEXT_B, FQ_CONTEXT_C, FQ_CONTEXT_A}); assertTrue(ctx.containsBean("service")); assertTrue(ctx.containsBean("logicOne")); assertTrue(ctx.containsBean("logicTwo")); @@ -72,9 +94,9 @@ public class ClassPathXmlApplicationContextTests extends TestCase { assertTrue(service.isProperlyDestroyed()); } + @Test public void testConfigLocationPattern() { - ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( - "/org/springframework/context/support/test/context*.xml"); + ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(CONTEXT_WILDCARD); assertTrue(ctx.containsBean("service")); assertTrue(ctx.containsBean("logicOne")); assertTrue(ctx.containsBean("logicTwo")); @@ -83,28 +105,28 @@ public class ClassPathXmlApplicationContextTests extends TestCase { assertTrue(service.isProperlyDestroyed()); } + @Test public void testSingleConfigLocationWithClass() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( - "simpleContext.xml", getClass()); + SIMPLE_CONTEXT, getClass()); assertTrue(ctx.containsBean("someMessageSource")); ctx.close(); } + @Test public void testAliasWithPlaceholder() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( - new String[] { - "/org/springframework/context/support/test/contextB.xml", - "/org/springframework/context/support/test/aliased-contextC.xml", - "/org/springframework/context/support/test/contextA.xml"}); + new String[] { FQ_CONTEXT_B, FQ_ALIASED_CONTEXT_C, FQ_CONTEXT_A}); assertTrue(ctx.containsBean("service")); assertTrue(ctx.containsBean("logicOne")); assertTrue(ctx.containsBean("logicTwo")); ctx.refresh(); } + @Test public void testContextWithInvalidValueType() throws IOException { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - new String[] {"/org/springframework/context/support/invalidValueType.xml"}, false); + new String[] {INVALID_VALUE_TYPE_CONTEXT}, false); try { context.refresh(); fail("Should have thrown BeanCreationException"); @@ -128,9 +150,10 @@ public class ClassPathXmlApplicationContextTests extends TestCase { assertTrue(dump.indexOf("useCodeAsDefaultMessage") != -1); } + @Test public void testContextWithInvalidLazyClass() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( - "invalidClass.xml", getClass()); + INVALID_CLASS_CONTEXT, getClass()); assertTrue(ctx.containsBean("someMessageSource")); try { ctx.getBean("someMessageSource"); @@ -142,34 +165,36 @@ public class ClassPathXmlApplicationContextTests extends TestCase { ctx.close(); } + @Test public void testContextWithClassNameThatContainsPlaceholder() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( - "classWithPlaceholder.xml", getClass()); + CLASS_WITH_PLACEHOLDER_CONTEXT, getClass()); assertTrue(ctx.containsBean("someMessageSource")); assertTrue(ctx.getBean("someMessageSource") instanceof StaticMessageSource); ctx.close(); } + @Test public void testMultipleConfigLocationsWithClass() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( - new String[] {"test/contextB.xml", "test/contextC.xml", "test/contextA.xml"}, getClass()); + new String[] {CONTEXT_B, CONTEXT_C, CONTEXT_A}, getClass()); assertTrue(ctx.containsBean("service")); assertTrue(ctx.containsBean("logicOne")); assertTrue(ctx.containsBean("logicTwo")); ctx.close(); } + @Test public void testFactoryBeanAndApplicationListener() { - ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( - "/org/springframework/context/support/test/context*.xml"); + ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(CONTEXT_WILDCARD); ctx.getBeanFactory().registerSingleton("manualFBAAL", new FactoryBeanAndApplicationListener()); assertEquals(2, ctx.getBeansOfType(ApplicationListener.class).size()); ctx.close(); } + @Test public void testMessageSourceAware() { - ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( - "/org/springframework/context/support/test/context*.xml"); + ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(CONTEXT_WILDCARD); MessageSource messageSource = (MessageSource) ctx.getBean("messageSource"); Service service1 = (Service) ctx.getBean("service"); assertEquals(ctx, service1.getMessageSource()); @@ -182,38 +207,35 @@ public class ClassPathXmlApplicationContextTests extends TestCase { ctx.close(); } + @Test public void testResourceArrayPropertyEditor() throws IOException { - ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( - "/org/springframework/context/support/test/context*.xml"); + ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(CONTEXT_WILDCARD); Service service = (Service) ctx.getBean("service"); assertEquals(3, service.getResources().length); - List resources = Arrays.asList(service.getResources()); - assertTrue(resources.contains( - new FileSystemResource(new ClassPathResource("/org/springframework/context/support/test/contextA.xml").getFile()))); - assertTrue(resources.contains( - new FileSystemResource(new ClassPathResource("/org/springframework/context/support/test/contextB.xml").getFile()))); - assertTrue(resources.contains( - new FileSystemResource(new ClassPathResource("/org/springframework/context/support/test/contextC.xml").getFile()))); + List resources = Arrays.asList(service.getResources()); + assertTrue(resources.contains(new FileSystemResource(new ClassPathResource(FQ_CONTEXT_A).getFile()))); + assertTrue(resources.contains(new FileSystemResource(new ClassPathResource(FQ_CONTEXT_B).getFile()))); + assertTrue(resources.contains(new FileSystemResource(new ClassPathResource(FQ_CONTEXT_C).getFile()))); ctx.close(); } + @Test public void testChildWithProxy() throws Exception { - ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( - "/org/springframework/context/support/test/context*.xml"); + ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(CONTEXT_WILDCARD); ClassPathXmlApplicationContext child = new ClassPathXmlApplicationContext( - new String[] {"/org/springframework/context/support/childWithProxy.xml"}, ctx); + new String[] {CHILD_WITH_PROXY_CONTEXT}, ctx); assertTrue(AopUtils.isAopProxy(child.getBean("assemblerOne"))); assertTrue(AopUtils.isAopProxy(child.getBean("assemblerTwo"))); ctx.close(); } + @Test public void testAliasForParentContext() { - ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( - "/org/springframework/context/support/simpleContext.xml"); + ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(FQ_SIMPLE_CONTEXT); assertTrue(ctx.containsBean("someMessageSource")); ClassPathXmlApplicationContext child = new ClassPathXmlApplicationContext( - new String[] {"/org/springframework/context/support/aliasForParent.xml"}, ctx); + new String[] {ALIAS_FOR_PARENT_CONTEXT}, ctx); assertTrue(child.containsBean("someMessageSource")); assertTrue(child.containsBean("yourMessageSource")); assertTrue(child.containsBean("myMessageSource")); @@ -243,13 +265,13 @@ public class ClassPathXmlApplicationContextTests extends TestCase { ctx.close(); } + @Test public void testAliasThatOverridesParent() { - ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( - "/org/springframework/context/support/simpleContext.xml"); + ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(FQ_SIMPLE_CONTEXT); Object someMs = ctx.getBean("someMessageSource"); ClassPathXmlApplicationContext child = new ClassPathXmlApplicationContext( - new String[] {"/org/springframework/context/support/aliasThatOverridesParent.xml"}, ctx); + new String[] {ALIAS_THAT_OVERRIDES_PARENT_CONTEXT}, ctx); Object myMs = child.getBean("myMessageSource"); Object someMs2 = child.getBean("someMessageSource"); assertSame(myMs, someMs2); @@ -257,10 +279,10 @@ public class ClassPathXmlApplicationContextTests extends TestCase { assertOneMessageSourceOnly(child, myMs); } + @Test public void testAliasThatOverridesEarlierBean() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( - new String[] {"/org/springframework/context/support/simpleContext.xml", - "/org/springframework/context/support/aliasThatOverridesParent.xml"}); + new String[] {FQ_SIMPLE_CONTEXT, ALIAS_THAT_OVERRIDES_PARENT_CONTEXT}); Object myMs = ctx.getBean("myMessageSource"); Object someMs2 = ctx.getBean("someMessageSource"); assertSame(myMs, someMs2); @@ -281,7 +303,7 @@ public class ClassPathXmlApplicationContextTests extends TestCase { assertEquals(1, beanNamesForType.length); assertEquals("myMessageSource", beanNamesForType[0]); - Map beansOfType = ctx.getBeansOfType(StaticMessageSource.class); + Map beansOfType = ctx.getBeansOfType(StaticMessageSource.class); assertEquals(1, beansOfType.size()); assertSame(myMessageSource, beansOfType.values().iterator().next()); beansOfType = ctx.getBeansOfType(StaticMessageSource.class, true, true); @@ -295,12 +317,13 @@ public class ClassPathXmlApplicationContextTests extends TestCase { assertSame(myMessageSource, beansOfType.values().iterator().next()); } + @Test public void testResourceAndInputStream() throws IOException { ClassPathXmlApplicationContext ctx = - new ClassPathXmlApplicationContext("/org/springframework/beans/factory/xml/resource.xml") { + new ClassPathXmlApplicationContext(RESOURCE_CONTEXT) { public Resource getResource(String location) { - if ("classpath:org/springframework/beans/factory/xml/test.properties".equals(location)) { - return new ClassPathResource("test.properties", ClassPathXmlApplicationContextTests.class); + if (FQ_TEST_PROPERTIES.equals(location)) { + return new ClassPathResource(TEST_PROPERTIES, ClassPathXmlApplicationContextTests.class); } return super.getResource(location); } @@ -323,12 +346,13 @@ public class ClassPathXmlApplicationContextTests extends TestCase { ctx.close(); } + @Test public void testGenericApplicationContextWithXmlBeanDefinitions() { GenericApplicationContext ctx = new GenericApplicationContext(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx); - reader.loadBeanDefinitions(new ClassPathResource("test/contextB.xml", getClass())); - reader.loadBeanDefinitions(new ClassPathResource("test/contextC.xml", getClass())); - reader.loadBeanDefinitions(new ClassPathResource("test/contextA.xml", getClass())); + reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_B, getClass())); + reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_C, getClass())); + reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_A, getClass())); ctx.refresh(); assertTrue(ctx.containsBean("service")); assertTrue(ctx.containsBean("logicOne")); @@ -336,13 +360,14 @@ public class ClassPathXmlApplicationContextTests extends TestCase { ctx.close(); } + @Test public void testGenericApplicationContextWithXmlBeanDefinitionsAndClassLoaderNull() { GenericApplicationContext ctx = new GenericApplicationContext(); ctx.setClassLoader(null); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx); - reader.loadBeanDefinitions(new ClassPathResource("test/contextB.xml", getClass())); - reader.loadBeanDefinitions(new ClassPathResource("test/contextC.xml", getClass())); - reader.loadBeanDefinitions(new ClassPathResource("test/contextA.xml", getClass())); + reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_B, getClass())); + reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_C, getClass())); + reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_A, getClass())); ctx.refresh(); assertEquals(ObjectUtils.identityToString(ctx), ctx.getId()); assertEquals(ObjectUtils.identityToString(ctx), ctx.getDisplayName()); @@ -352,13 +377,14 @@ public class ClassPathXmlApplicationContextTests extends TestCase { ctx.close(); } + @Test public void testGenericApplicationContextWithXmlBeanDefinitionsAndSpecifiedId() { GenericApplicationContext ctx = new GenericApplicationContext(); ctx.setId("testContext"); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx); - reader.loadBeanDefinitions(new ClassPathResource("test/contextB.xml", getClass())); - reader.loadBeanDefinitions(new ClassPathResource("test/contextC.xml", getClass())); - reader.loadBeanDefinitions(new ClassPathResource("test/contextA.xml", getClass())); + reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_B, getClass())); + reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_C, getClass())); + reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_A, getClass())); ctx.refresh(); assertEquals("testContext", ctx.getId()); assertEquals("testContext", ctx.getDisplayName());