Search in sources :

Example 91 with XmlBeanDefinitionReader

use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.

the class ComponentScanParserBeanDefinitionDefaultsTests method testLazyInitTrue.

@Test
public void testLazyInitTrue() {
    GenericApplicationContext context = new GenericApplicationContext();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultLazyInitTrueTests.xml");
    assertTrue("lazy-init should be true", context.getBeanDefinition(TEST_BEAN_NAME).isLazyInit());
    assertEquals("initCount should be 0", 0, DefaultsTestBean.INIT_COUNT);
    context.refresh();
    assertEquals("bean should not have been instantiated yet", 0, DefaultsTestBean.INIT_COUNT);
    context.getBean(TEST_BEAN_NAME);
    assertEquals("bean should have been instantiated", 1, DefaultsTestBean.INIT_COUNT);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) Test(org.junit.Test)

Example 92 with XmlBeanDefinitionReader

use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.

the class ComponentScanParserBeanDefinitionDefaultsTests method testDefaultLazyInit.

@Test
public void testDefaultLazyInit() {
    GenericApplicationContext context = new GenericApplicationContext();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultWithNoOverridesTests.xml");
    assertFalse("lazy-init should be false", context.getBeanDefinition(TEST_BEAN_NAME).isLazyInit());
    assertEquals("initCount should be 0", 0, DefaultsTestBean.INIT_COUNT);
    context.refresh();
    assertEquals("bean should have been instantiated", 1, DefaultsTestBean.INIT_COUNT);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) Test(org.junit.Test)

Example 93 with XmlBeanDefinitionReader

use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.

the class ComponentScanParserBeanDefinitionDefaultsTests method testLazyInitFalse.

@Test
public void testLazyInitFalse() {
    GenericApplicationContext context = new GenericApplicationContext();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultLazyInitFalseTests.xml");
    assertFalse("lazy-init should be false", context.getBeanDefinition(TEST_BEAN_NAME).isLazyInit());
    assertEquals("initCount should be 0", 0, DefaultsTestBean.INIT_COUNT);
    context.refresh();
    assertEquals("bean should have been instantiated", 1, DefaultsTestBean.INIT_COUNT);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) Test(org.junit.Test)

Example 94 with XmlBeanDefinitionReader

use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.

the class ComponentScanParserBeanDefinitionDefaultsTests method testDefaultDependencyCheck.

@Test
public void testDefaultDependencyCheck() {
    GenericApplicationContext context = new GenericApplicationContext();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultWithNoOverridesTests.xml");
    context.refresh();
    DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME);
    assertNull("constructor dependency should not have been autowired", bean.getConstructorDependency());
    assertNull("property dependencies should not have been autowired", bean.getPropertyDependency1());
    assertNull("property dependencies should not have been autowired", bean.getPropertyDependency2());
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) Test(org.junit.Test)

Example 95 with XmlBeanDefinitionReader

use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.

the class ComponentScanParserBeanDefinitionDefaultsTests method testAutowireNo.

@Test
public void testAutowireNo() {
    GenericApplicationContext context = new GenericApplicationContext();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultAutowireNoTests.xml");
    context.refresh();
    DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME);
    assertNull("no dependencies should have been autowired", bean.getConstructorDependency());
    assertNull("no dependencies should have been autowired", bean.getPropertyDependency1());
    assertNull("no dependencies should have been autowired", bean.getPropertyDependency2());
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) Test(org.junit.Test)

Aggregations

XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)152 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)82 Test (org.junit.Test)80 ClassPathResource (org.springframework.core.io.ClassPathResource)62 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)38 Before (org.junit.Before)30 ITestBean (org.springframework.tests.sample.beans.ITestBean)18 TestBean (org.springframework.tests.sample.beans.TestBean)11 BeansException (org.springframework.beans.BeansException)9 Resource (org.springframework.core.io.Resource)8 UrlResource (org.springframework.core.io.UrlResource)8 URL (java.net.URL)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)6 HashMap (java.util.HashMap)5 Person (org.springframework.tests.sample.beans.Person)5 ArrayList (java.util.ArrayList)4 BeanCreationException (org.springframework.beans.factory.BeanCreationException)4 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)4 ResourceEntityResolver (org.springframework.beans.factory.xml.ResourceEntityResolver)4