Search in sources :

Example 21 with XmlBeanDefinitionReader

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

the class PropertyPathFactoryBeanTests method testPropertyPathFactoryBeanWithNullResult.

@Test
public void testPropertyPathFactoryBeanWithNullResult() {
    DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT);
    assertNull(xbf.getType("tb.spouse.spouse"));
    assertNull(xbf.getBean("tb.spouse.spouse"));
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Test(org.junit.Test)

Example 22 with XmlBeanDefinitionReader

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

the class FieldRetrievingFactoryBeanTests method testBeanNameSyntaxWithBeanFactory.

@Test
public void testBeanNameSyntaxWithBeanFactory() throws Exception {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT);
    TestBean testBean = (TestBean) bf.getBean("testBean");
    assertEquals(new Integer(Connection.TRANSACTION_SERIALIZABLE), testBean.getSomeIntegerArray()[0]);
    assertEquals(new Integer(Connection.TRANSACTION_SERIALIZABLE), testBean.getSomeIntegerArray()[1]);
}
Also used : TestBean(org.springframework.tests.sample.beans.TestBean) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Test(org.junit.Test)

Example 23 with XmlBeanDefinitionReader

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

the class ObjectFactoryCreatingFactoryBeanTests method setUp.

@Before
public void setUp() {
    this.beanFactory = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(CONTEXT);
    this.beanFactory.setSerializationId("test");
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Before(org.junit.Before)

Example 24 with XmlBeanDefinitionReader

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

the class SimpleScopeTests method setUp.

@Before
public void setUp() {
    beanFactory = new DefaultListableBeanFactory();
    Scope scope = new NoOpScope() {

        private int index;

        private List<TestBean> objects = new LinkedList<>();

        {
            objects.add(new TestBean());
            objects.add(new TestBean());
        }

        @Override
        public Object get(String name, ObjectFactory<?> objectFactory) {
            if (index >= objects.size()) {
                index = 0;
            }
            return objects.get(index++);
        }
    };
    beanFactory.registerScope("myScope", scope);
    String[] scopeNames = beanFactory.getRegisteredScopeNames();
    assertEquals(1, scopeNames.length);
    assertEquals("myScope", scopeNames[0]);
    assertSame(scope, beanFactory.getRegisteredScope("myScope"));
    XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(beanFactory);
    xbdr.loadBeanDefinitions(CONTEXT);
}
Also used : ObjectFactory(org.springframework.beans.factory.ObjectFactory) TestBean(org.springframework.tests.sample.beans.TestBean) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) List(java.util.List) LinkedList(java.util.LinkedList) Before(org.junit.Before)

Example 25 with XmlBeanDefinitionReader

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

the class ProxyFactoryBeanTests method testTargetSourceNotAtEndOfInterceptorNamesIsRejected.

@Test
public void testTargetSourceNotAtEndOfInterceptorNamesIsRejected() {
    try {
        DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
        new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(NOTLAST_TARGETSOURCE_CONTEXT, CLASS));
        bf.getBean("targetSourceNotLast");
        fail("TargetSource or non-advised object must be last in interceptorNames");
    } catch (BeanCreationException ex) {
        // Root cause of the problem must be an AOP exception
        AopConfigException aex = (AopConfigException) ex.getCause();
        assertTrue(aex.getMessage().contains("interceptorNames"));
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Aggregations

XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)138 Test (org.junit.Test)79 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)74 ClassPathResource (org.springframework.core.io.ClassPathResource)59 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)36 Before (org.junit.Before)24 ITestBean (org.springframework.tests.sample.beans.ITestBean)18 TestBean (org.springframework.tests.sample.beans.TestBean)11 BeansException (org.springframework.beans.BeansException)9 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 Resource (org.springframework.core.io.Resource)7 UrlResource (org.springframework.core.io.UrlResource)7 URL (java.net.URL)6 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 NopInterceptor (org.springframework.tests.aop.interceptor.NopInterceptor)4 Map (java.util.Map)3