use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.
the class ProxyFactoryBeanTests method testPrototypeAdvisor.
@Test
public void testPrototypeAdvisor() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(CONTEXT, CLASS));
ITestBean bean1 = (ITestBean) bf.getBean("prototypeTestBeanProxy");
ITestBean bean2 = (ITestBean) bf.getBean("prototypeTestBeanProxy");
bean1.setAge(3);
bean2.setAge(4);
assertEquals(3, bean1.getAge());
assertEquals(4, bean2.getAge());
((Lockable) bean1).lock();
try {
bean1.setAge(5);
fail("expected LockedException");
} catch (LockedException ex) {
// expected
}
try {
bean2.setAge(6);
} catch (LockedException ex) {
fail("did not expect LockedException");
}
}
use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.
the class ProxyFactoryBeanTests method testSerializableSingletonProxyFactoryBean.
@Test
public void testSerializableSingletonProxyFactoryBean() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
Person p = (Person) bf.getBean("serializableSingleton");
ProxyFactoryBean pfb = (ProxyFactoryBean) bf.getBean("&serializableSingleton");
ProxyFactoryBean pfb2 = (ProxyFactoryBean) SerializationTestUtils.serializeAndDeserialize(pfb);
Person p2 = (Person) pfb2.getObject();
assertEquals(p, p2);
assertNotSame(p, p2);
assertEquals("serializableSingleton", p2.getName());
}
use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.
the class ScopedProxyTests method testCglibScopedProxy.
@Test
public void testCglibScopedProxy() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(LIST_CONTEXT);
bf.setSerializationId("Y");
SimpleMapScope scope = new SimpleMapScope();
bf.registerScope("request", scope);
TestBean tb = (TestBean) bf.getBean("testBean");
assertTrue(AopUtils.isCglibProxy(tb.getFriends()));
assertTrue(tb.getFriends() instanceof ScopedObject);
ScopedObject scoped = (ScopedObject) tb.getFriends();
assertEquals(ArrayList.class, scoped.getTargetObject().getClass());
tb.getFriends().add("myFriend");
assertTrue(scope.getMap().containsKey("scopedTarget.scopedList"));
assertEquals(ArrayList.class, scope.getMap().get("scopedTarget.scopedList").getClass());
ArrayList<?> deserialized = (ArrayList<?>) SerializationTestUtils.serializeAndDeserialize(tb.getFriends());
assertNotNull(deserialized);
assertTrue(AopUtils.isCglibProxy(deserialized));
assertTrue(deserialized.contains("myFriend"));
assertTrue(deserialized instanceof ScopedObject);
ScopedObject scopedDeserialized = (ScopedObject) deserialized;
assertEquals(ArrayList.class, scopedDeserialized.getTargetObject().getClass());
bf.setSerializationId(null);
}
use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.
the class ScopedProxyTests method testScopedOverride.
@Test
public void testScopedOverride() throws Exception {
GenericApplicationContext ctx = new GenericApplicationContext();
new XmlBeanDefinitionReader(ctx).loadBeanDefinitions(OVERRIDE_CONTEXT);
SimpleMapScope scope = new SimpleMapScope();
ctx.getBeanFactory().registerScope("request", scope);
ctx.refresh();
ITestBean bean = (ITestBean) ctx.getBean("testBean");
assertEquals("male", bean.getName());
assertEquals(99, bean.getAge());
assertTrue(scope.getMap().containsKey("scopedTarget.testBean"));
assertEquals(TestBean.class, scope.getMap().get("scopedTarget.testBean").getClass());
}
use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.
the class CommonsPool2TargetSourceTests method setUp.
@Before
public void setUp() throws Exception {
this.beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-context.xml", getClass()));
}
Aggregations