1 16 17 package org.springframework.beans.factory.config; 18 19 import junit.framework.TestCase; 20 21 import org.springframework.beans.ITestBean; 22 import org.springframework.beans.TestBean; 23 import org.springframework.beans.factory.xml.XmlBeanFactory; 24 import org.springframework.core.io.ClassPathResource; 25 26 30 public class PropertyPathFactoryBeanTests extends TestCase { 31 32 public void testPropertyPathFactoryBeanWithSingletonResult() { 33 XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("propertyPath.xml", getClass())); 34 assertEquals(new Integer (12), xbf.getBean("propertyPath1")); 35 assertEquals(new Integer (11), xbf.getBean("propertyPath2")); 36 assertEquals(new Integer (10), xbf.getBean("tb.age")); 37 assertEquals(ITestBean.class, xbf.getType("otb.spouse")); 38 Object result1 = xbf.getBean("otb.spouse"); 39 Object result2 = xbf.getBean("otb.spouse"); 40 assertTrue(result1 instanceof TestBean); 41 assertTrue(result1 == result2); 42 assertEquals(99, ((TestBean) result1).getAge()); 43 } 44 45 public void testPropertyPathFactoryBeanWithPrototypeResult() { 46 XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("propertyPath.xml", getClass())); 47 assertNull(xbf.getType("tb.spouse")); 48 assertEquals(TestBean.class, xbf.getType("propertyPath3")); 49 Object result1 = xbf.getBean("tb.spouse"); 50 Object result2 = xbf.getBean("propertyPath3"); 51 Object result3 = xbf.getBean("propertyPath3"); 52 assertTrue(result1 instanceof TestBean); 53 assertTrue(result2 instanceof TestBean); 54 assertTrue(result3 instanceof TestBean); 55 assertEquals(11, ((TestBean) result1).getAge()); 56 assertEquals(11, ((TestBean) result2).getAge()); 57 assertEquals(11, ((TestBean) result3).getAge()); 58 assertTrue(result1 != result2); 59 assertTrue(result1 != result3); 60 assertTrue(result2 != result3); 61 } 62 63 public void testBeanReferenceFactoryBean() { 64 XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("propertyPath.xml", getClass())); 65 66 TestBean tb = (TestBean) xbf.getBean("tbAlias"); 67 assertEquals(10, tb.getAge()); 68 assertEquals(TestBean.class, xbf.getType("tbAlias")); 69 assertFalse(xbf.isSingleton("tbAlias")); 70 71 Object otb = xbf.getBean("otb"); 72 assertEquals(otb, xbf.getBean("otbAlias")); 73 assertEquals(TestBean.class, xbf.getType("otbAlias")); 74 assertTrue(xbf.isSingleton("otbAlias")); 75 } 76 77 } 78 | Popular Tags |