use of org.springframework.core.io.ClassPathResource 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()));
}
use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.
the class ProxyFactoryBeanTests method testPrototypeInstancesAreIndependent.
/**
* Uses its own bean factory XML for clarity
* @param beanName name of the ProxyFactoryBean definition that should
* be a prototype
*/
private Object testPrototypeInstancesAreIndependent(String beanName) {
// Initial count value set in bean factory XML
int INITIAL_COUNT = 10;
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(PROTOTYPE_CONTEXT, CLASS));
// Check it works without AOP
SideEffectBean raw = (SideEffectBean) bf.getBean("prototypeTarget");
assertEquals(INITIAL_COUNT, raw.getCount());
raw.doWork();
assertEquals(INITIAL_COUNT + 1, raw.getCount());
raw = (SideEffectBean) bf.getBean("prototypeTarget");
assertEquals(INITIAL_COUNT, raw.getCount());
// Now try with advised instances
SideEffectBean prototype2FirstInstance = (SideEffectBean) bf.getBean(beanName);
assertEquals(INITIAL_COUNT, prototype2FirstInstance.getCount());
prototype2FirstInstance.doWork();
assertEquals(INITIAL_COUNT + 1, prototype2FirstInstance.getCount());
SideEffectBean prototype2SecondInstance = (SideEffectBean) bf.getBean(beanName);
assertFalse("Prototypes are not ==", prototype2FirstInstance == prototype2SecondInstance);
assertEquals(INITIAL_COUNT, prototype2SecondInstance.getCount());
assertEquals(INITIAL_COUNT + 1, prototype2FirstInstance.getCount());
return prototype2FirstInstance;
}
use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.
the class ProxyFactoryBeanTests method testSerializablePrototypeProxy.
@Test
public void testSerializablePrototypeProxy() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
Person p = (Person) bf.getBean("serializablePrototype");
assertNotSame("Should not be a Singleton", p, bf.getBean("serializablePrototype"));
Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(p);
assertEquals(p, p2);
assertNotSame(p, p2);
assertEquals("serializablePrototype", p2.getName());
}
use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.
the class ProxyFactoryBeanTests method testPrototypeInterceptorSingletonTarget.
@Test
public void testPrototypeInterceptorSingletonTarget() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(CONTEXT, CLASS));
ITestBean bean1 = (ITestBean) bf.getBean("prototypeTestBeanProxySingletonTarget");
ITestBean bean2 = (ITestBean) bf.getBean("prototypeTestBeanProxySingletonTarget");
bean1.setAge(1);
bean2.setAge(2);
assertEquals(2, bean1.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.core.io.ClassPathResource in project spring-framework by spring-projects.
the class ProxyFactoryBeanTests method setUp.
@Before
public void setUp() throws Exception {
DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
parent.registerBeanDefinition("target2", new RootBeanDefinition(TestListener.class));
this.factory = new DefaultListableBeanFactory(parent);
new XmlBeanDefinitionReader((BeanDefinitionRegistry) this.factory).loadBeanDefinitions(new ClassPathResource(CONTEXT, getClass()));
}
Aggregations