Search in sources :

Example 81 with XmlBeanDefinitionReader

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

the class ProxyFactoryBeanTests method testDoubleTargetSourceIsRejected.

private void testDoubleTargetSourceIsRejected(String name) {
    try {
        DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
        new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(DBL_TARGETSOURCE_CONTEXT, CLASS));
        bf.getBean(name);
        fail("Should not allow TargetSource to be specified in interceptorNames as well as targetSource property");
    } catch (BeanCreationException ex) {
        // Root cause of the problem must be an AOP exception
        AopConfigException aex = (AopConfigException) ex.getCause();
        assertTrue(aex.getMessage().indexOf("TargetSource") != -1);
    }
}
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)

Example 82 with XmlBeanDefinitionReader

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

the class ProxyFactoryBeanTests method testGetObjectTypeWithNoTargetOrTargetSource.

@Test
public void testGetObjectTypeWithNoTargetOrTargetSource() {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(TARGETSOURCE_CONTEXT, CLASS));
    ITestBean tb = (ITestBean) bf.getBean("noTarget");
    try {
        tb.getName();
        fail();
    } catch (UnsupportedOperationException ex) {
        assertEquals("getName", ex.getMessage());
    }
    FactoryBean<?> pfb = (ProxyFactoryBean) bf.getBean("&noTarget");
    assertTrue("Has correct object type", ITestBean.class.isAssignableFrom(pfb.getObjectType()));
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 83 with XmlBeanDefinitionReader

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

the class ProxyFactoryBeanTests method testGetObjectTypeWithTargetViaTargetSource.

@Test
public void testGetObjectTypeWithTargetViaTargetSource() {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(TARGETSOURCE_CONTEXT, CLASS));
    ITestBean tb = (ITestBean) bf.getBean("viaTargetSource");
    assertTrue(tb.getName().equals("Adam"));
    ProxyFactoryBean pfb = (ProxyFactoryBean) bf.getBean("&viaTargetSource");
    assertTrue("Has correct object type", TestBean.class.isAssignableFrom(pfb.getObjectType()));
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 84 with XmlBeanDefinitionReader

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

the class ProxyFactoryBeanTests method testProxyNotSerializableBecauseOfAdvice.

@Test
public void testProxyNotSerializableBecauseOfAdvice() throws Exception {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
    Person p = (Person) bf.getBean("interceptorNotSerializableSingleton");
    assertFalse("Not serializable because an interceptor isn't serializable", SerializationTestUtils.isSerializable(p));
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Person(org.springframework.tests.sample.beans.Person) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 85 with XmlBeanDefinitionReader

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

the class ProxyFactoryBeanTests method testGlobalsWithoutTarget.

/**
	 * Globals must be followed by a target.
	 */
@Test
public void testGlobalsWithoutTarget() {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(INVALID_CONTEXT, CLASS));
    try {
        bf.getBean("globalsWithoutTarget");
        fail("Should require target name");
    } catch (BeanCreationException ex) {
        assertTrue(ex.getCause() instanceof AopConfigException);
    }
}
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)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