Package org.springframework.beans.factory.support

Examples of org.springframework.beans.factory.support.DefaultListableBeanFactory


  public void testXsdValidationAutodetect() throws Exception {
    doTestValidation("validateWithXsd.xml");
  }

  private void doTestValidation(String resourceName) throws Exception {
    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();;
    Resource resource = new ClassPathResource(resourceName, getClass());
    new XmlBeanDefinitionReader(factory).loadBeanDefinitions(resource);
    TestBean bean = (TestBean) factory.getBean("testBean");
    assertNotNull(bean);
  }
View Full Code Here


* @author Rob Harrop
*/
public class SchemaValidationTests extends TestCase {

  public void testWithAutodetection() throws Exception {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
    try {
      reader.loadBeanDefinitions(new ClassPathResource("invalidPerSchema.xml", getClass()));
      fail("Should not be able to parse a file with errors");
    }
View Full Code Here

      assertTrue(ex.getCause() instanceof SAXParseException);
    }
  }

  public void testWithExplicitValidationMode() throws Exception {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
    reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
    try {
      reader.loadBeanDefinitions(new ClassPathResource("invalidPerSchema.xml", getClass()));
      fail("Should not be able to parse a file with errors");
View Full Code Here

      assertTrue(ex.getCause() instanceof SAXParseException);
    }
  }

  public void testLoadDefinitions() throws Exception {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
    reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
    reader.loadBeanDefinitions(new ClassPathResource("schemaValidated.xml", getClass()));

    TestBean foo = (TestBean) bf.getBean("fooBean");
    assertNotNull("Spouse is null", foo.getSpouse());
    assertEquals("Incorrect number of friends", 2, foo.getFriends().size());
  }
View Full Code Here

  private static final Log factoryLog = LogFactory.getLog(DefaultListableBeanFactory.class);


  public void testUnreferencedSingletonWasInstantiated() {
    KnowsIfInstantiated.clearInstantiationRecord();
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    Properties p = new Properties();
    p.setProperty("x1.(class)", KnowsIfInstantiated.class.getName());
    assertTrue("singleton not instantiated", !KnowsIfInstantiated.wasInstantiated());
    (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
    lbf.preInstantiateSingletons();
    assertTrue("singleton was instantiated", KnowsIfInstantiated.wasInstantiated());
  }
View Full Code Here


  protected 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();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
    reader.setNamespaceHandlerResolver(resolver);
    reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
    reader.setEntityResolver(new DummySchemaResolver());
    reader.loadBeanDefinitions(getResource());
View Full Code Here

    assertTrue("singleton was instantiated", KnowsIfInstantiated.wasInstantiated());
  }

  public void testLazyInitialization() {
    KnowsIfInstantiated.clearInstantiationRecord();
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    Properties p = new Properties();
    p.setProperty("x1.(class)", KnowsIfInstantiated.class.getName());
    p.setProperty("x1.(lazy-init)", "true");
    assertTrue("singleton not instantiated", !KnowsIfInstantiated.wasInstantiated());
    (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
    assertTrue("singleton not instantiated", !KnowsIfInstantiated.wasInstantiated());
    lbf.preInstantiateSingletons();

    assertTrue("singleton not instantiated", !KnowsIfInstantiated.wasInstantiated());
    lbf.getBean("x1");
    assertTrue("singleton was instantiated", KnowsIfInstantiated.wasInstantiated());
  }
View Full Code Here

    lbf.getBean("x1");
    assertTrue("singleton was instantiated", KnowsIfInstantiated.wasInstantiated());
  }

  public void testFactoryBeanDidNotCreatePrototype() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    Properties p = new Properties();
    p.setProperty("x1.(class)", DummyFactory.class.getName());
    // Reset static state
    DummyFactory.reset();
    p.setProperty("x1.singleton", "false");
    assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
    (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
    assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
    assertEquals(TestBean.class, lbf.getType("x1"));
    lbf.preInstantiateSingletons();

    assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
    lbf.getBean("x1");
    assertEquals(TestBean.class, lbf.getType("x1"));
    assertTrue(lbf.containsBean("x1"));
    assertTrue(lbf.containsBean("&x1"));
    assertTrue("prototype was instantiated", DummyFactory.wasPrototypeCreated());
  }
View Full Code Here

    assertTrue(lbf.containsBean("&x1"));
    assertTrue("prototype was instantiated", DummyFactory.wasPrototypeCreated());
  }

  public void testPrototypeFactoryBeanIgnoredByNonEagerTypeMatching() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    Properties p = new Properties();
    p.setProperty("x1.(class)", DummyFactory.class.getName());
    // Reset static state
    DummyFactory.reset();
    p.setProperty("x1.(singleton)", "false");
    p.setProperty("x1.singleton", "false");
    (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);

    assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
    String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
    assertEquals(0, beanNames.length);
    assertFalse(lbf.containsSingleton("x1"));
    assertTrue(lbf.containsBean("x1"));
    assertTrue(lbf.containsBean("&x1"));
    assertFalse(lbf.isSingleton("x1"));
    assertFalse(lbf.isSingleton("&x1"));
    assertTrue(lbf.isPrototype("x1"));
    assertTrue(lbf.isPrototype("&x1"));
    assertTrue(lbf.isTypeMatch("x1", TestBean.class));
    assertFalse(lbf.isTypeMatch("&x1", TestBean.class));
    assertTrue(lbf.isTypeMatch("&x1", DummyFactory.class));
    assertEquals(TestBean.class, lbf.getType("x1"));
    assertEquals(DummyFactory.class, lbf.getType("&x1"));
    assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
  }
View Full Code Here

    assertEquals(DummyFactory.class, lbf.getType("&x1"));
    assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
  }

  public void testPrototypeSingletonFactoryBeanIgnoredByNonEagerTypeMatching() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    Properties p = new Properties();
    p.setProperty("x1.(class)", DummyFactory.class.getName());
    // Reset static state
    DummyFactory.reset();
    p.setProperty("x1.(singleton)", "false");
    p.setProperty("x1.singleton", "true");
    (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);

    assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
    String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
    assertEquals(0, beanNames.length);
    assertFalse(lbf.containsSingleton("x1"));
    assertTrue(lbf.containsBean("x1"));
    assertTrue(lbf.containsBean("&x1"));
    assertFalse(lbf.isSingleton("x1"));
    assertFalse(lbf.isSingleton("&x1"));
    assertTrue(lbf.isPrototype("x1"));
    assertTrue(lbf.isPrototype("&x1"));
    assertTrue(lbf.isTypeMatch("x1", TestBean.class));
    assertFalse(lbf.isTypeMatch("&x1", TestBean.class));
    assertTrue(lbf.isTypeMatch("&x1", DummyFactory.class));
    assertEquals(TestBean.class, lbf.getType("x1"));
    assertEquals(DummyFactory.class, lbf.getType("&x1"));
    assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
  }
View Full Code Here

TOP

Related Classes of org.springframework.beans.factory.support.DefaultListableBeanFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.