/** * Note that prototype/singleton distinction is <b>not</b> inherited. It's possible for a subclass * singleton not to return independent instances even if derived from a prototype * * @throws Exception */ public void testSingletonInheritsFromParentFactoryPrototype() throws Exception { InputStream pis = getClass().getResourceAsStream("parent.xml"); XmlBeanFactory parent = new XmlBeanFactory(pis); InputStream is = getClass().getResourceAsStream("child.xml"); XmlBeanFactory child = new XmlBeanFactory(is, parent); TestBean inherits = (TestBean) child.getBean("singletonInheritsFromParentFactoryPrototype"); // Name property value is overriden assertTrue(inherits.getName().equals("prototype-override")); // Age property is inherited from bean in parent factory assertTrue(inherits.getAge() == 2); TestBean inherits2 = (TestBean) child.getBean("singletonInheritsFromParentFactoryPrototype"); assertTrue(inherits2 == inherits); }
public void testPrototypeInheritanceFromParentFactorySingleton() throws Exception { InputStream pis = getClass().getResourceAsStream("parent.xml"); XmlBeanFactory parent = new XmlBeanFactory(pis); InputStream is = getClass().getResourceAsStream("child.xml"); XmlBeanFactory child = new XmlBeanFactory(is, parent); TestBean inherits = (TestBean) child.getBean("protoypeInheritsFromParentFactorySingleton"); // Name property value is overriden assertTrue(inherits.getName().equals("prototypeOverridesInheritedSingleton")); // Age property is inherited from bean in parent factory assertTrue(inherits.getAge() == 1); TestBean inherits2 = (TestBean) child.getBean("protoypeInheritsFromParentFactorySingleton"); assertFalse(inherits2 == inherits); inherits2.setAge(13); assertTrue(inherits2.getAge() == 13); // Shouldn't have changed first instance assertTrue(inherits.getAge() == 1); }
public void testPropertyWithLiteralValueSubelement() throws Exception { InputStream is = getClass().getResourceAsStream("collections.xml"); XmlBeanFactory xbf = new XmlBeanFactory(is); TestBean verbose = (TestBean) xbf.getBean("verbose"); assertTrue(verbose.getName().equals("verbose")); }