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);
}
}
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()));
}
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()));
}
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));
}
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);
}
}
Aggregations