Moved tests from testsuite to beans

This commit is contained in:
Arjen Poutsma
2008-10-29 18:03:15 +00:00
parent 7f90f08705
commit dcaf024e76
9 changed files with 294 additions and 9 deletions

View File

@@ -22,7 +22,7 @@ import org.springframework.beans.TestBean;
* @author Juergen Hoeller
*/
public class CountingFactory implements FactoryBean {
private static int factoryBeanInstanceCount = 0;
@@ -61,4 +61,4 @@ public class CountingFactory implements FactoryBean {
return true;
}
}
}

View File

@@ -17,6 +17,7 @@
package org.springframework.beans.factory.xml;
import junit.framework.TestCase;
import junit.framework.Assert;
import org.springframework.beans.TestBean;
import org.springframework.beans.factory.CountingFactory;
@@ -40,7 +41,7 @@ public class AutowireWithExclusionTests extends TestCase {
TestBean rob = (TestBean) beanFactory.getBean("rob");
TestBean sally = (TestBean) beanFactory.getBean("sally");
assertEquals(sally, rob.getSpouse());
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
Assert.assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
public void testByTypeAutowireWithExclusion() throws Exception {
@@ -49,7 +50,7 @@ public class AutowireWithExclusionTests extends TestCase {
beanFactory.preInstantiateSingletons();
TestBean rob = (TestBean) beanFactory.getBean("rob");
assertEquals("props1", rob.getSomeProperties().getProperty("name"));
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
Assert.assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
public void testByTypeAutowireWithExclusionInParentFactory() throws Exception {
@@ -62,7 +63,7 @@ public class AutowireWithExclusionTests extends TestCase {
child.registerBeanDefinition("rob2", robDef);
TestBean rob = (TestBean) child.getBean("rob2");
assertEquals("props1", rob.getSomeProperties().getProperty("name"));
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
Assert.assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
public void testByTypeAutowireWithPrimaryInParentFactory() throws Exception {
@@ -79,7 +80,7 @@ public class AutowireWithExclusionTests extends TestCase {
child.registerBeanDefinition("props3", propsDef);
TestBean rob = (TestBean) child.getBean("rob2");
assertEquals("props1", rob.getSomeProperties().getProperty("name"));
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
Assert.assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
public void testByTypeAutowireWithPrimaryOverridingParentFactory() throws Exception {
@@ -96,7 +97,7 @@ public class AutowireWithExclusionTests extends TestCase {
child.registerBeanDefinition("props3", propsDef);
TestBean rob = (TestBean) child.getBean("rob2");
assertEquals("props3", rob.getSomeProperties().getProperty("name"));
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
Assert.assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
public void testByTypeAutowireWithInclusion() throws Exception {
@@ -105,7 +106,7 @@ public class AutowireWithExclusionTests extends TestCase {
beanFactory.preInstantiateSingletons();
TestBean rob = (TestBean) beanFactory.getBean("rob");
assertEquals("props1", rob.getSomeProperties().getProperty("name"));
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
Assert.assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
public void testByTypeAutowireWithSelectiveInclusion() throws Exception {
@@ -114,7 +115,7 @@ public class AutowireWithExclusionTests extends TestCase {
beanFactory.preInstantiateSingletons();
TestBean rob = (TestBean) beanFactory.getBean("rob");
assertEquals("props1", rob.getSomeProperties().getProperty("name"));
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
Assert.assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
public void testConstructorAutowireWithAutoSelfExclusion() throws Exception {

View File

@@ -0,0 +1,18 @@
<?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 class="org.springframework.beans.factory.xml.GeneratedNameBean">
<property name="child">
<bean class="org.springframework.beans.factory.xml.GeneratedNameBean"/>
</property>
</bean>
<bean class="org.springframework.beans.factory.xml.GeneratedNameBean">
<property name="child">
<bean class="org.springframework.beans.factory.xml.GeneratedNameBean"/>
</property>
</bean>
</beans>

View File

@@ -0,0 +1,205 @@
<?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="parentWithList" class="org.springframework.beans.TestBean">
<property name="someList">
<list>
<value>Rob Harrop</value>
<value>Rod Johnson</value>
</list>
</property>
</bean>
<bean id="childWithList" parent="parentWithList">
<property name="someList">
<list merge="true">
<value>Juergen Hoeller</value>
</list>
</property>
</bean>
<bean id="childWithListOfRefs" parent="parentWithList">
<property name="someList">
<list merge="true">
<bean class="org.springframework.beans.TestBean"/>
</list>
</property>
</bean>
<bean id="parentWithSet" class="org.springframework.beans.TestBean">
<property name="someSet">
<set>
<value>Rob Harrop</value>
</set>
</property>
</bean>
<bean id="childWithSet" parent="parentWithSet">
<property name="someSet">
<set merge="true">
<value>Sally Greenwood</value>
</set>
</property>
</bean>
<bean id="childWithSetOfRefs" parent="parentWithSet">
<property name="someSet">
<set merge="true">
<bean class="org.springframework.beans.TestBean">
<property name="name" value="Sally"/>
</bean>
</set>
</property>
</bean>
<bean id="parentWithMap" class="org.springframework.beans.TestBean">
<property name="someMap">
<map>
<entry key="Rob" value="Sall"/>
<entry key="Juergen" value="Eva"/>
</map>
</property>
</bean>
<bean id="childWithMap" parent="parentWithMap">
<property name="someMap">
<map merge="true">
<entry key="Rod" value="Kerry"/>
<entry key="Rob" value="Sally"/>
</map>
</property>
</bean>
<bean id="childWithMapOfRefs" parent="parentWithMap">
<property name="someMap">
<map merge="true">
<entry key="Rob">
<bean class="org.springframework.beans.TestBean">
<property name="name" value="Sally"/>
</bean>
</entry>
</map>
</property>
</bean>
<bean id="parentWithProps" class="org.springframework.beans.TestBean">
<property name="someProperties">
<props>
<prop key="Rob">Sall</prop>
<prop key="Rod">Kerry</prop>
</props>
</property>
</bean>
<bean id="childWithProps" parent="parentWithProps">
<property name="someProperties">
<props merge="true">
<prop key="Juergen">Eva</prop>
<prop key="Rob">Sally</prop>
</props>
</property>
</bean>
<bean id="parentWithListInConstructor" class="org.springframework.beans.TestBean">
<constructor-arg index="0">
<list>
<value>Rob Harrop</value>
<value>Rod Johnson</value>
</list>
</constructor-arg>
</bean>
<bean id="childWithListInConstructor" parent="parentWithListInConstructor">
<constructor-arg index="0">
<list merge="true">
<value>Juergen Hoeller</value>
</list>
</constructor-arg>
</bean>
<bean id="childWithListOfRefsInConstructor" parent="parentWithListInConstructor">
<constructor-arg index="0">
<list merge="true">
<bean class="org.springframework.beans.TestBean"/>
</list>
</constructor-arg>
</bean>
<bean id="parentWithSetInConstructor" class="org.springframework.beans.TestBean">
<constructor-arg index="0">
<set>
<value>Rob Harrop</value>
</set>
</constructor-arg>
</bean>
<bean id="childWithSetInConstructor" parent="parentWithSetInConstructor">
<constructor-arg index="0">
<set merge="true">
<value>Sally Greenwood</value>
</set>
</constructor-arg>
</bean>
<bean id="childWithSetOfRefsInConstructor" parent="parentWithSetInConstructor">
<constructor-arg index="0">
<set merge="true">
<bean class="org.springframework.beans.TestBean">
<property name="name" value="Sally"/>
</bean>
</set>
</constructor-arg>
</bean>
<bean id="parentWithMapInConstructor" class="org.springframework.beans.TestBean">
<constructor-arg index="0">
<map>
<entry key="Rob" value="Sall"/>
<entry key="Juergen" value="Eva"/>
</map>
</constructor-arg>
</bean>
<bean id="childWithMapInConstructor" parent="parentWithMapInConstructor">
<constructor-arg index="0">
<map merge="true">
<entry key="Rod" value="Kerry"/>
<entry key="Rob" value="Sally"/>
</map>
</constructor-arg>
</bean>
<bean id="childWithMapOfRefsInConstructor" parent="parentWithMapInConstructor">
<constructor-arg index="0">
<map merge="true">
<entry key="Rob">
<bean class="org.springframework.beans.TestBean">
<property name="name" value="Sally"/>
</bean>
</entry>
</map>
</constructor-arg>
</bean>
<bean id="parentWithPropsInConstructor" class="org.springframework.beans.TestBean">
<constructor-arg index="0">
<props>
<prop key="Rob">Sall</prop>
<prop key="Rod">Kerry</prop>
</props>
</constructor-arg>
</bean>
<bean id="childWithPropsInConstructor" parent="parentWithPropsInConstructor">
<constructor-arg index="0">
<props merge="true">
<prop key="Juergen">Eva</prop>
<prop key="Rob">Sally</prop>
</props>
</constructor-arg>
</bean>
</beans>

View File

@@ -0,0 +1,61 @@
<?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="testBean" class="org.springframework.beans.TestBean">
<property name="someList">
<list value-type="java.lang.Integer">
<value>1</value>
<value>2</value>
<value>3</value>
</list>
</property>
<property name="someSet">
<set value-type="java.lang.Integer">
<value>1</value>
<value>2</value>
<value>3</value>
</set>
</property>
<property name="someMap">
<map key-type="java.lang.Integer" value-type="java.lang.Boolean">
<entry key="1" value="true"/>
<entry key="2" value="false"/>
<entry key="3" value="false"/>
<entry key="4" value="true"/>
</map>
</property>
</bean>
<bean id="testBean2" class="org.springframework.beans.TestBean">
<property name="someMap">
<map key-type="java.lang.Integer" value-type="java.lang.Boolean">
<entry>
<key>
<value>1</value>
</key>
<value>true</value>
</entry>
<entry>
<key>
<value>2</value>
</key>
<value>false</value>
</entry>
<entry>
<key>
<value>3</value>
</key>
<value>false</value>
</entry>
<entry>
<key>
<value>4</value>
</key>
<value>true</value>
</entry>
</map>
</property>
</bean>
</beans>