moving unit tests from .testsuite -> .beans
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.beans.factory.xml;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -28,9 +30,7 @@ import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.hibernate.FlushMode;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
@@ -44,10 +44,12 @@ import org.springframework.core.io.ClassPathResource;
|
||||
* Tests for collections in XML bean definitions.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @since 19.12.2004
|
||||
*/
|
||||
public class XmlBeanCollectionTests extends TestCase {
|
||||
public class XmlBeanCollectionTests {
|
||||
|
||||
@Test
|
||||
public void testCollectionFactoryDefaults() throws Exception {
|
||||
ListFactoryBean listFactory = new ListFactoryBean();
|
||||
listFactory.setSourceList(new LinkedList());
|
||||
@@ -65,6 +67,7 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
assertTrue(mapFactory.getObject() instanceof LinkedHashMap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefSubelement() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
//assertTrue("5 beans in reftypes, not " + xbf.getBeanDefinitionCount(), xbf.getBeanDefinitionCount() == 5);
|
||||
@@ -73,24 +76,28 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
assertTrue(jen.getSpouse() == dave);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyWithLiteralValueSubelement() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
TestBean verbose = (TestBean) xbf.getBean("verbose");
|
||||
assertTrue(verbose.getName().equals("verbose"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyWithIdRefLocalAttrSubelement() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
TestBean verbose = (TestBean) xbf.getBean("verbose2");
|
||||
assertTrue(verbose.getName().equals("verbose"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyWithIdRefBeanAttrSubelement() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
TestBean verbose = (TestBean) xbf.getBean("verbose3");
|
||||
assertTrue(verbose.getName().equals("verbose"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefSubelementsBuildCollection() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
TestBean jen = (TestBean) xbf.getBean("jenny");
|
||||
@@ -108,6 +115,7 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
// Should be ordered
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefSubelementsBuildCollectionWithPrototypes() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
|
||||
@@ -132,6 +140,7 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
assertTrue("Dave not same instance", friends2[1] != friends[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefSubelementsBuildCollectionFromSingleElement() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
TestBean loner = (TestBean) xbf.getBean("loner");
|
||||
@@ -140,6 +149,7 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
assertTrue(loner.getFriends().contains(dave));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildCollectionFromMixtureOfReferencesAndValues() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
MixedCollectionBean jumble = (MixedCollectionBean) xbf.getBean("jumble");
|
||||
@@ -152,6 +162,7 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
assertTrue(l.get(3).equals("rod"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidBeanNameReference() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
try {
|
||||
@@ -164,12 +175,14 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyMap() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
HasMap hasMap = (HasMap) xbf.getBean("emptyMap");
|
||||
assertTrue(hasMap.getMap().size() == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapWithLiteralsOnly() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
HasMap hasMap = (HasMap) xbf.getBean("literalMap");
|
||||
@@ -179,6 +192,7 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
assertTrue(hasMap.getMap().get("fa") == null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapWithLiteralsAndReferences() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
HasMap hasMap = (HasMap) xbf.getBean("mixedMap");
|
||||
@@ -189,6 +203,7 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
assertTrue(hasMap.getMap().get(new Integer(5)).equals("david"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapWithLiteralsAndPrototypeReferences() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
|
||||
@@ -206,6 +221,7 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
assertTrue("Not same instance", hasMap2.getMap().get("jenny") != hasMap.getMap().get("jenny"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapWithLiteralsReferencesAndList() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
HasMap hasMap = (HasMap) xbf.getBean("mixedMapWithList");
|
||||
@@ -245,12 +261,14 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
m.get("jenny").equals(jenny));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptySet() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
HasMap hasMap = (HasMap) xbf.getBean("emptySet");
|
||||
assertTrue(hasMap.getSet().size() == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPopulatedSet() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
HasMap hasMap = (HasMap) xbf.getBean("set");
|
||||
@@ -265,6 +283,7 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
assertEquals(null, it.next());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyProps() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
HasMap hasMap = (HasMap) xbf.getBean("emptyProps");
|
||||
@@ -272,6 +291,7 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
assertEquals(hasMap.getProps().getClass(), Properties.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPopulatedProps() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
HasMap hasMap = (HasMap) xbf.getBean("props");
|
||||
@@ -280,6 +300,7 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
assertTrue(hasMap.getProps().get("2").equals("TWO"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectArray() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
HasMap hasMap = (HasMap) xbf.getBean("objectArray");
|
||||
@@ -288,6 +309,7 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
assertTrue(hasMap.getObjectArray()[1].equals(xbf.getBean("jenny")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassArray() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
HasMap hasMap = (HasMap) xbf.getBean("classArray");
|
||||
@@ -296,6 +318,7 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
assertTrue(hasMap.getClassArray()[1].equals(Exception.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntegerArray() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
HasMap hasMap = (HasMap) xbf.getBean("integerArray");
|
||||
@@ -305,6 +328,7 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
assertTrue(hasMap.getIntegerArray()[2].intValue() == 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProps() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
|
||||
@@ -319,6 +343,7 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
assertEquals("TWO", hasMap2.getProps().getProperty("2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListFactory() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
List list = (List) xbf.getBean("listFactory");
|
||||
@@ -328,6 +353,7 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
assertEquals("jenny", list.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrototypeListFactory() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
List list = (List) xbf.getBean("pListFactory");
|
||||
@@ -337,6 +363,7 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
assertEquals("jenny", list.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetFactory() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
Set set = (Set) xbf.getBean("setFactory");
|
||||
@@ -346,6 +373,7 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
assertTrue(set.contains("jenny"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrototypeSetFactory() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
Set set = (Set) xbf.getBean("pSetFactory");
|
||||
@@ -355,6 +383,7 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
assertTrue(set.contains("jenny"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapFactory() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
Map map = (Map) xbf.getBean("mapFactory");
|
||||
@@ -364,6 +393,7 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
assertEquals("jenny", map.get("jen"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrototypeMapFactory() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
Map map = (Map) xbf.getBean("pMapFactory");
|
||||
@@ -373,6 +403,7 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
assertEquals("jenny", map.get("jen"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChoiceBetweenSetAndMap() {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
MapAndSet sam = (MapAndSet) xbf.getBean("setAndMap");
|
||||
@@ -384,15 +415,15 @@ public class XmlBeanCollectionTests extends TestCase {
|
||||
assertEquals("val3", map.get("key3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnumSetFactory() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
|
||||
Set set = (Set) xbf.getBean("enumSetFactory");
|
||||
assertTrue(set.size() == 2);
|
||||
assertTrue(set.contains(FlushMode.NEVER));
|
||||
assertTrue(set.contains(FlushMode.COMMIT));
|
||||
assertTrue(set.contains("ONE"));
|
||||
assertTrue(set.contains("TWO"));
|
||||
}
|
||||
|
||||
|
||||
public static class MapAndSet {
|
||||
|
||||
private Object obj;
|
||||
@@ -0,0 +1,376 @@
|
||||
<?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-2.5.xsd">
|
||||
|
||||
<bean id="jenny" class="org.springframework.beans.TestBean">
|
||||
<property name="name"><value>Jenny</value></property>
|
||||
<property name="age"><value>30</value></property>
|
||||
<property name="spouse">
|
||||
<!-- Could use id and href -->
|
||||
<ref local="david"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="david" class="org.springframework.beans.TestBean">
|
||||
<description>
|
||||
Simple bean, without any collections.
|
||||
</description>
|
||||
<property name="name">
|
||||
<description>The name of the user</description>
|
||||
<value>David</value>
|
||||
</property>
|
||||
<property name="age"><value>27</value></property>
|
||||
</bean>
|
||||
|
||||
<bean id="rod" class="org.springframework.beans.TestBean">
|
||||
<property name="name"><value>Rod</value></property>
|
||||
<property name="age"><value>32</value></property>
|
||||
<property name="friends">
|
||||
<description>List of Rod's friends</description>
|
||||
<list>
|
||||
<ref local="jenny"/>
|
||||
<ref local="david"/>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="pJenny" class="org.springframework.beans.TestBean" scope="prototype">
|
||||
<property name="name"><value>Jenny</value></property>
|
||||
<property name="age"><value>30</value></property>
|
||||
<property name="spouse">
|
||||
<!-- Could use id and href -->
|
||||
<ref local="david"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="pDavid" class="org.springframework.beans.TestBean" scope="prototype">
|
||||
<property name="name"><value>David</value></property>
|
||||
<property name="age"><value>27</value></property>
|
||||
</bean>
|
||||
|
||||
<bean id="pRod" class="org.springframework.beans.TestBean" scope="prototype">
|
||||
<property name="name"><value>Rod</value></property>
|
||||
<property name="age"><value>32</value></property>
|
||||
<property name="friends">
|
||||
<list>
|
||||
<ref local="pJenny"/>
|
||||
<ref local="pDavid"/>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!--
|
||||
Try setting a collection property to a single value
|
||||
-->
|
||||
<bean id="loner" class="org.springframework.beans.TestBean">
|
||||
<property name="name"><value>loner</value></property>
|
||||
<property name="age"><value>26</value></property>
|
||||
<property name="friends">
|
||||
<list>
|
||||
<description>My List</description>
|
||||
<ref local="david"/>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="jumble" class="org.springframework.beans.factory.xml.MixedCollectionBean">
|
||||
<property name="jumble">
|
||||
<list>
|
||||
<ref local="david"/>
|
||||
<value>literal</value>
|
||||
<ref local="jenny"/>
|
||||
<idref local="rod"/>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="jumble2" class="org.springframework.beans.factory.xml.MixedCollectionBean" lazy-init="true">
|
||||
<property name="jumble">
|
||||
<list>
|
||||
<ref local="david"/>
|
||||
<value>literal</value>
|
||||
<ref local="jenny"/>
|
||||
<idref bean="rod"/>
|
||||
<idref bean="rod2"/>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="verbose" class="org.springframework.beans.TestBean">
|
||||
<property name="name"><value>verbose</value></property>
|
||||
</bean>
|
||||
|
||||
<bean id="verbose2" class="org.springframework.beans.TestBean">
|
||||
<property name="name"><idref local="verbose"/></property>
|
||||
</bean>
|
||||
|
||||
<bean id="verbose3" class="org.springframework.beans.TestBean">
|
||||
<property name="name"><idref bean="verbose"/></property>
|
||||
</bean>
|
||||
|
||||
<bean id="emptyMap" class="org.springframework.beans.factory.HasMap">
|
||||
<property name="map">
|
||||
<map>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="literalMap" class="org.springframework.beans.factory.HasMap">
|
||||
<property name="map">
|
||||
<map>
|
||||
<entry key="foo" value="bar"/>
|
||||
<entry key="fi" value="fum"/>
|
||||
<entry key="fa"><null/></entry>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="mixedMap" class="org.springframework.beans.factory.HasMap">
|
||||
<property name="map">
|
||||
<map>
|
||||
<entry key-ref="fooKey">
|
||||
<value type="java.lang.Integer">10</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>
|
||||
<ref bean="jennyKey"/>
|
||||
</key>
|
||||
<ref local="jenny"/>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>
|
||||
<bean class="java.lang.Integer">
|
||||
<constructor-arg value="5"/>
|
||||
</bean>
|
||||
</key>
|
||||
<idref bean="david"/>
|
||||
</entry>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="fooKey" class="java.lang.String">
|
||||
<constructor-arg value="foo"/>
|
||||
</bean>
|
||||
|
||||
<bean id="jennyKey" class="java.lang.String">
|
||||
<constructor-arg value="jenny"/>
|
||||
</bean>
|
||||
|
||||
<bean id="pMixedMap" class="org.springframework.beans.factory.HasMap" scope="prototype">
|
||||
<property name="map">
|
||||
<map>
|
||||
<entry key="foo" value="bar"/>
|
||||
<entry key="jenny" value-ref="pJenny"/>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="mixedMapWithList" class="org.springframework.beans.factory.HasMap">
|
||||
<property name="map">
|
||||
<map>
|
||||
<entry>
|
||||
<key><null/></key>
|
||||
<value>bar</value>
|
||||
</entry>
|
||||
<entry key="jenny"><ref local="jenny"/></entry>
|
||||
<entry key="list">
|
||||
<list>
|
||||
<value>zero</value>
|
||||
<map>
|
||||
<entry key="fo"><value>bar</value></entry>
|
||||
<entry key="jen"><ref local="jenny"/></entry>
|
||||
</map>
|
||||
<list>
|
||||
<ref local="jenny"/>
|
||||
<value>ba</value>
|
||||
</list>
|
||||
<null/>
|
||||
</list>
|
||||
</entry>
|
||||
<entry key="map">
|
||||
<map>
|
||||
<entry key="foo"><value>bar</value></entry>
|
||||
<entry key="jenny"><ref local="jenny"/></entry>
|
||||
</map>
|
||||
</entry>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="emptySet" class="org.springframework.beans.factory.HasMap">
|
||||
<property name="set">
|
||||
<set>
|
||||
</set>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="set" class="org.springframework.beans.factory.HasMap">
|
||||
<property name="set">
|
||||
<set>
|
||||
<value>bar</value>
|
||||
<ref local="jenny"/>
|
||||
<null/>
|
||||
</set>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="emptyProps" class="org.springframework.beans.factory.HasMap">
|
||||
<property name="props">
|
||||
<props>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="props" class="org.springframework.beans.factory.HasMap">
|
||||
<property name="props">
|
||||
<props>
|
||||
<prop key="foo">bar</prop>
|
||||
<prop key="2">TWO</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="propsViaMap" class="org.springframework.beans.factory.HasMap">
|
||||
<property name="props">
|
||||
<map>
|
||||
<entry key="foo" value="bar"/>
|
||||
<entry key="2" value="TWO"/>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="objectArray" class="org.springframework.beans.factory.HasMap">
|
||||
<property name="objectArray">
|
||||
<list>
|
||||
<value>one</value>
|
||||
<ref local="jenny"/>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="classArray" class="org.springframework.beans.factory.HasMap">
|
||||
<property name="classArray">
|
||||
<list>
|
||||
<value>java.lang.String</value>
|
||||
<value>java.lang.Exception</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="integerArray" class="org.springframework.beans.factory.HasMap">
|
||||
<property name="integerArray">
|
||||
<list>
|
||||
<value>0</value>
|
||||
<value>1</value>
|
||||
<value>2</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="listFactory" class="org.springframework.beans.factory.config.ListFactoryBean">
|
||||
<property name="sourceList">
|
||||
<list>
|
||||
<value>bar</value>
|
||||
<value>jenny</value>
|
||||
</list>
|
||||
</property>
|
||||
<property name="targetListClass">
|
||||
<value>java.util.LinkedList</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="pListFactory" class="org.springframework.beans.factory.config.ListFactoryBean">
|
||||
<property name="sourceList">
|
||||
<list>
|
||||
<value>bar</value>
|
||||
<value>jenny</value>
|
||||
</list>
|
||||
</property>
|
||||
<property name="targetListClass">
|
||||
<value>java.util.LinkedList</value>
|
||||
</property>
|
||||
<property name="singleton">
|
||||
<value>true</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="setFactory" class="org.springframework.beans.factory.config.SetFactoryBean">
|
||||
<property name="sourceSet">
|
||||
<set>
|
||||
<value>bar</value>
|
||||
<value>jenny</value>
|
||||
</set>
|
||||
</property>
|
||||
<property name="targetSetClass">
|
||||
<value>java.util.TreeSet</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="pSetFactory" class="org.springframework.beans.factory.config.SetFactoryBean">
|
||||
<property name="sourceSet">
|
||||
<set>
|
||||
<value>bar</value>
|
||||
<value>jenny</value>
|
||||
</set>
|
||||
</property>
|
||||
<property name="targetSetClass">
|
||||
<value>java.util.TreeSet</value>
|
||||
</property>
|
||||
<property name="singleton">
|
||||
<value>true</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="mapFactory" class="org.springframework.beans.factory.config.MapFactoryBean">
|
||||
<property name="sourceMap">
|
||||
<map>
|
||||
<entry key="foo"><value>bar</value></entry>
|
||||
<entry key="jen"><value>jenny</value></entry>
|
||||
</map>
|
||||
</property>
|
||||
<property name="targetMapClass">
|
||||
<value>java.util.TreeMap</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="pMapFactory" class="org.springframework.beans.factory.config.MapFactoryBean">
|
||||
<property name="sourceMap">
|
||||
<map>
|
||||
<entry key="foo"><value>bar</value></entry>
|
||||
<entry key="jen"><value>jenny</value></entry>
|
||||
</map>
|
||||
</property>
|
||||
<property name="targetMapClass">
|
||||
<value>java.util.TreeMap</value>
|
||||
</property>
|
||||
<property name="singleton">
|
||||
<value>true</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="setAndMap" class="org.springframework.beans.factory.xml.XmlBeanCollectionTests$MapAndSet">
|
||||
<constructor-arg>
|
||||
<map>
|
||||
<description>My Map</description>
|
||||
<entry key="key1" value="val1"/>
|
||||
<entry key="key2" value="val2"/>
|
||||
<entry key="key3" value="val3"/>
|
||||
</map>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="enumSetFactory" class="org.springframework.beans.factory.config.SetFactoryBean">
|
||||
<property name="sourceSet">
|
||||
<set>
|
||||
<description>My Set</description>
|
||||
<value type="java.lang.String">ONE</value>
|
||||
<value type="java.lang.String">TWO</value>
|
||||
</set>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.springframework.beans.factory.xml.support;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver;
|
||||
import org.springframework.beans.factory.xml.NamespaceHandler;
|
||||
import org.springframework.beans.factory.xml.UtilNamespaceHandler;
|
||||
import org.springframework.test.AssertThrows;
|
||||
|
||||
/**
|
||||
* Unit and integration tests for the {@link DefaultNamespaceHandlerResolver} class.
|
||||
@@ -29,8 +29,9 @@ import org.springframework.test.AssertThrows;
|
||||
* @author Rob Harrop
|
||||
* @author Rick Evans
|
||||
*/
|
||||
public class DefaultNamespaceHandlerResolverTests extends TestCase {
|
||||
public class DefaultNamespaceHandlerResolverTests {
|
||||
|
||||
@Test
|
||||
public void testResolvedMappedHandler() {
|
||||
DefaultNamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver(getClass().getClassLoader());
|
||||
NamespaceHandler handler = resolver.resolve("http://www.springframework.org/schema/util");
|
||||
@@ -38,6 +39,7 @@ public class DefaultNamespaceHandlerResolverTests extends TestCase {
|
||||
assertEquals("Incorrect handler loaded", UtilNamespaceHandler.class, handler.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolvedMappedHandlerWithNoArgCtor() {
|
||||
DefaultNamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver();
|
||||
NamespaceHandler handler = resolver.resolve("http://www.springframework.org/schema/util");
|
||||
@@ -45,6 +47,7 @@ public class DefaultNamespaceHandlerResolverTests extends TestCase {
|
||||
assertEquals("Incorrect handler loaded", UtilNamespaceHandler.class, handler.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonExistentHandlerClass() throws Exception {
|
||||
String mappingPath = "org/springframework/beans/factory/xml/support/nonExistent.properties";
|
||||
try {
|
||||
@@ -56,6 +59,7 @@ public class DefaultNamespaceHandlerResolverTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveInvalidHandler() throws Exception {
|
||||
String mappingPath = "org/springframework/beans/factory/xml/support/invalid.properties";
|
||||
try {
|
||||
@@ -66,19 +70,18 @@ public class DefaultNamespaceHandlerResolverTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCtorWithNullClassLoaderArgument() throws Exception {
|
||||
// simply must not bail...
|
||||
new DefaultNamespaceHandlerResolver(null);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testCtorWithNullClassLoaderArgumentAndNullMappingLocationArgument() throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
new DefaultNamespaceHandlerResolver(null, null);
|
||||
}
|
||||
}.runTest();
|
||||
new DefaultNamespaceHandlerResolver(null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCtorWithNonExistentMappingLocationArgument() throws Exception {
|
||||
// simply must not bail; we don't want non-existent resources to result in an Exception
|
||||
new DefaultNamespaceHandlerResolver(null, "738trbc bobabloobop871");
|
||||
@@ -367,8 +367,8 @@
|
||||
<property name="sourceSet">
|
||||
<set>
|
||||
<description>My Set</description>
|
||||
<value type="org.hibernate.FlushMode">NEVER</value>
|
||||
<value type="org.hibernate.FlushMode">COMMIT</value>
|
||||
<value type="java.lang.String">ONE</value>
|
||||
<value type="java.lang.String">TWO</value>
|
||||
</set>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
@@ -16,14 +16,15 @@
|
||||
|
||||
package org.springframework.beans.factory.xml.support;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.aop.Advisor;
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.aop.interceptor.DebugInterceptor;
|
||||
@@ -39,17 +40,20 @@ import org.springframework.beans.factory.xml.PluggableSchemaResolver;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
* @author Rick Evans
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class CustomNamespaceHandlerTests extends TestCase {
|
||||
public final class CustomNamespaceHandlerTests {
|
||||
|
||||
private DefaultListableBeanFactory beanFactory;
|
||||
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
String location = "org/springframework/beans/factory/xml/support/customNamespace.properties";
|
||||
NamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver(getClass().getClassLoader(), location);
|
||||
this.beanFactory = new DefaultListableBeanFactory();
|
||||
@@ -61,16 +65,19 @@ public final class CustomNamespaceHandlerTests extends TestCase {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimpleParser() throws Exception {
|
||||
TestBean bean = (TestBean) this.beanFactory.getBean("testBean");
|
||||
assetTestBean(bean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleDecorator() throws Exception {
|
||||
TestBean bean = (TestBean) this.beanFactory.getBean("customisedTestBean");
|
||||
assetTestBean(bean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProxyingDecorator() throws Exception {
|
||||
ITestBean bean = (ITestBean) this.beanFactory.getBean("debuggingTestBean");
|
||||
assetTestBean(bean);
|
||||
@@ -80,6 +87,7 @@ public final class CustomNamespaceHandlerTests extends TestCase {
|
||||
assertEquals("Incorrect advice class.", DebugInterceptor.class, advisors[0].getAdvice().getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChainedDecorators() throws Exception {
|
||||
ITestBean bean = (ITestBean) this.beanFactory.getBean("chainedTestBean");
|
||||
assetTestBean(bean);
|
||||
@@ -90,6 +98,7 @@ public final class CustomNamespaceHandlerTests extends TestCase {
|
||||
assertEquals("Incorrect advice class.", NopInterceptor.class, advisors[1].getAdvice().getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecorationViaAttribute() throws Exception {
|
||||
BeanDefinition beanDefinition = this.beanFactory.getBeanDefinition("decorateWithAttribute");
|
||||
assertEquals("foo", beanDefinition.getAttribute("objectName"));
|
||||
@@ -98,8 +107,9 @@ public final class CustomNamespaceHandlerTests extends TestCase {
|
||||
/**
|
||||
* http://opensource.atlassian.com/projects/spring/browse/SPR-2728
|
||||
*/
|
||||
@Test
|
||||
public void testCustomElementNestedWithinUtilList() throws Exception {
|
||||
List things = (List) this.beanFactory.getBean("list.of.things");
|
||||
List<?> things = (List<?>) this.beanFactory.getBean("list.of.things");
|
||||
assertNotNull(things);
|
||||
assertEquals(2, things.size());
|
||||
}
|
||||
@@ -107,8 +117,9 @@ public final class CustomNamespaceHandlerTests extends TestCase {
|
||||
/**
|
||||
* http://opensource.atlassian.com/projects/spring/browse/SPR-2728
|
||||
*/
|
||||
@Test
|
||||
public void testCustomElementNestedWithinUtilSet() throws Exception {
|
||||
Set things = (Set) this.beanFactory.getBean("set.of.things");
|
||||
Set<?> things = (Set<?>) this.beanFactory.getBean("set.of.things");
|
||||
assertNotNull(things);
|
||||
assertEquals(2, things.size());
|
||||
}
|
||||
@@ -116,8 +127,9 @@ public final class CustomNamespaceHandlerTests extends TestCase {
|
||||
/**
|
||||
* http://opensource.atlassian.com/projects/spring/browse/SPR-2728
|
||||
*/
|
||||
@Test
|
||||
public void testCustomElementNestedWithinUtilMap() throws Exception {
|
||||
Map things = (Map) this.beanFactory.getBean("map.of.things");
|
||||
Map<?, ?> things = (Map<?, ?>) this.beanFactory.getBean("map.of.things");
|
||||
assertNotNull(things);
|
||||
assertEquals(2, things.size());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user