refactored .context module's .beans.factory and .context.access tests in preparation for moving .beans.factory.xml tests from .testsuite -> .context
This commit is contained in:
parent
78c692b0cb
commit
d083432478
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,127 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
||||
|
||||
<beans>
|
||||
|
||||
<bean id="validEmptyWithDescription" class="org.springframework.beans.TestBean">
|
||||
<description>
|
||||
I have no properties and I'm happy without them.
|
||||
</description>
|
||||
</bean>
|
||||
|
||||
<!--
|
||||
Check automatic creation of alias, to allow for names that are illegal as XML ids.
|
||||
-->
|
||||
<bean id="aliased" class=" org.springframework.beans.TestBean " name="myalias">
|
||||
<property name="name"><value>aliased</value></property>
|
||||
</bean>
|
||||
|
||||
<alias name="aliased" alias="youralias"/>
|
||||
|
||||
<alias name="multiAliased" alias="alias3"/>
|
||||
|
||||
<bean id="multiAliased" class="org.springframework.beans.TestBean" name="alias1,alias2">
|
||||
<property name="name"><value>aliased</value></property>
|
||||
</bean>
|
||||
|
||||
<alias name="multiAliased" alias="alias4"/>
|
||||
|
||||
<bean class="org.springframework.beans.TestBean" name="aliasWithoutId1,aliasWithoutId2,aliasWithoutId3">
|
||||
<property name="name"><value>aliased</value></property>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.beans.TestBean">
|
||||
<property name="name"><null/></property>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.beans.factory.xml.DummyReferencer"/>
|
||||
|
||||
<bean class="org.springframework.beans.factory.xml.DummyReferencer"/>
|
||||
|
||||
<bean class="org.springframework.beans.factory.xml.DummyReferencer"/>
|
||||
|
||||
<bean id="rod" class="org.springframework.beans.TestBean">
|
||||
<property name="name"><value><!-- a comment -->Rod</value></property>
|
||||
<property name="age"><value>31</value></property>
|
||||
<property name="spouse"><ref bean="father"/></property>
|
||||
<property name="touchy"><value/></property>
|
||||
</bean>
|
||||
|
||||
<bean id="roderick" parent="rod">
|
||||
<property name="name"><value>Roderick<!-- a comment --></value></property>
|
||||
<!-- Should inherit age -->
|
||||
</bean>
|
||||
|
||||
<bean id="kerry" class="org.springframework.beans.TestBean">
|
||||
<property name="name"><value>Ker<!-- a comment -->ry</value></property>
|
||||
<property name="age"><value>34</value></property>
|
||||
<property name="spouse"><ref local="rod"/></property>
|
||||
<property name="touchy"><value></value></property>
|
||||
</bean>
|
||||
|
||||
<bean id="kathy" class="org.springframework.beans.TestBean" scope="prototype">
|
||||
<property name="name"><value>Kathy</value></property>
|
||||
<property name="age"><value>28</value></property>
|
||||
<property name="spouse"><ref bean="father"/></property>
|
||||
</bean>
|
||||
|
||||
<bean id="typeMismatch" class="org.springframework.beans.TestBean" scope="prototype">
|
||||
<property name="name"><value>typeMismatch</value></property>
|
||||
<property name="age"><value>34x</value></property>
|
||||
<property name="spouse"><ref local="rod"/></property>
|
||||
</bean>
|
||||
|
||||
<!-- Test of lifecycle callbacks -->
|
||||
<bean id="mustBeInitialized" class="org.springframework.beans.factory.MustBeInitialized"/>
|
||||
|
||||
<bean id="lifecycle" class="org.springframework.beans.factory.LifecycleBean"
|
||||
init-method="declaredInitMethod">
|
||||
<property name="initMethodDeclared"><value>true</value></property>
|
||||
</bean>
|
||||
|
||||
<bean id="protectedLifecycle" class="org.springframework.beans.factory.xml.ProtectedLifecycleBean"
|
||||
init-method="declaredInitMethod">
|
||||
<property name="initMethodDeclared"><value>true</value></property>
|
||||
</bean>
|
||||
|
||||
<!-- Factory beans are automatically treated differently -->
|
||||
<bean id="singletonFactory" class="org.springframework.beans.factory.DummyFactory">
|
||||
</bean>
|
||||
|
||||
<bean id="prototypeFactory" class="org.springframework.beans.factory.DummyFactory">
|
||||
<property name="singleton"><value>false</value></property>
|
||||
</bean>
|
||||
|
||||
<!-- Check that the circular reference resolution mechanism doesn't break
|
||||
repeated references to the same FactoryBean -->
|
||||
<bean id="factoryReferencer" class="org.springframework.beans.factory.xml.DummyReferencer">
|
||||
<property name="testBean1"><ref bean="singletonFactory"/></property>
|
||||
<property name="testBean2"><ref local="singletonFactory"/></property>
|
||||
<property name="dummyFactory"><ref bean="&singletonFactory"/></property>
|
||||
</bean>
|
||||
|
||||
<bean id="factoryReferencerWithConstructor" class="org.springframework.beans.factory.xml.DummyReferencer">
|
||||
<constructor-arg><ref bean="&singletonFactory"/></constructor-arg>
|
||||
<property name="testBean1"><ref bean="singletonFactory"/></property>
|
||||
<property name="testBean2"><ref local="singletonFactory"/></property>
|
||||
</bean>
|
||||
|
||||
<!-- Check that the circular reference resolution mechanism doesn't break
|
||||
prototype instantiation -->
|
||||
<bean id="prototypeReferencer" class="org.springframework.beans.factory.xml.DummyReferencer" scope="prototype">
|
||||
<property name="testBean1"><ref local="kathy"/></property>
|
||||
<property name="testBean2"><ref bean="kathy"/></property>
|
||||
</bean>
|
||||
|
||||
<bean id="listenerVeto" class="org.springframework.beans.TestBean">
|
||||
<property name="name"><value>listenerVeto</value></property>
|
||||
<property name="age"><value>66</value></property>
|
||||
</bean>
|
||||
|
||||
<bean id="validEmpty" class="org.springframework.beans.TestBean"/>
|
||||
|
||||
<bean id="commentsInValue" class="org.springframework.beans.TestBean">
|
||||
<property name="name"><value>this is<!-- don't mind me --> a <![CDATA[<!--comment-->]]></value></property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@
|
|||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="jumble" class="org.springframework.beans.factory.xml.MixedCollectionBean">
|
||||
<bean id="jumble" class="org.springframework.context.access.MixedCollectionBean">
|
||||
<property name="jumble">
|
||||
<list>
|
||||
<ref local="david"/>
|
||||
|
@ -85,7 +85,7 @@
|
|||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="jumble2" class="org.springframework.beans.factory.xml.MixedCollectionBean" lazy-init="true">
|
||||
<bean id="jumble2" class="org.springframework.context.access.MixedCollectionBean" lazy-init="true">
|
||||
<property name="jumble">
|
||||
<list>
|
||||
<ref local="david"/>
|
||||
|
@ -352,7 +352,7 @@
|
|||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="setAndMap" class="org.springframework.beans.factory.xml.MapAndSet">
|
||||
<bean id="setAndMap" class="org.springframework.context.access.MapAndSet">
|
||||
<constructor-arg>
|
||||
<map>
|
||||
<description>My Map</description>
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
<beans>
|
||||
|
||||
<import resource="resourceImport.xml"/>
|
||||
<import resource="ClassPathXmlApplicationContextTests-resourceImport.xml"/>
|
||||
|
||||
<bean id="resource2" class="org.springframework.beans.ResourceTestBean">
|
||||
<constructor-arg index="0">
|
|
@ -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<Resource> 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<?, StaticMessageSource> 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());
|
||||
|
|
Loading…
Reference in New Issue