use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.
the class SelectivePrototypeTargetSourceCreator method testLazyInitTargetSource.
@Test
public void testLazyInitTargetSource() throws Exception {
CountingTestBean.count = 0;
BeanFactory bf = new ClassPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLASS);
ITestBean test = (ITestBean) bf.getBean("lazyInitTest");
assertTrue(AopUtils.isAopProxy(test));
Advised advised = (Advised) test;
assertTrue(advised.getTargetSource() instanceof LazyInitTargetSource);
assertEquals("No CountingTestBean instantiated yet", 0, CountingTestBean.count);
assertEquals("Rod", test.getName());
assertEquals("Kerry", test.getSpouse().getName());
assertEquals("Only 1 CountingTestBean instantiated", 1, CountingTestBean.count);
CountingTestBean.count = 0;
}
use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.
the class SelectivePrototypeTargetSourceCreator method testCustomTargetSourceNoMatch.
/**
* We have custom TargetSourceCreators but there's no match, and
* hence no proxying, for this bean
*/
@Test
public void testCustomTargetSourceNoMatch() throws Exception {
BeanFactory bf = new ClassPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLASS);
ITestBean test = (ITestBean) bf.getBean("test");
assertFalse(AopUtils.isAopProxy(test));
assertEquals("Rod", test.getName());
assertEquals("Kerry", test.getSpouse().getName());
}
use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.
the class TransactionInterceptorTests method determineTransactionManagerWithQualifierSeveralTimes.
@Test
public void determineTransactionManagerWithQualifierSeveralTimes() {
BeanFactory beanFactory = mock(BeanFactory.class);
TransactionInterceptor ti = simpleTransactionInterceptor(beanFactory);
PlatformTransactionManager txManager = associateTransactionManager(beanFactory, "fooTransactionManager");
DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
attribute.setQualifier("fooTransactionManager");
PlatformTransactionManager actual = ti.determineTransactionManager(attribute);
assertSame(txManager, actual);
// Call again, should be cached
PlatformTransactionManager actual2 = ti.determineTransactionManager(attribute);
assertSame(txManager, actual2);
verify(beanFactory, times(1)).containsBean("fooTransactionManager");
verify(beanFactory, times(1)).getBean("fooTransactionManager", PlatformTransactionManager.class);
}
use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.
the class TransactionInterceptorTests method determineTransactionManagerWithNoTransactionAttribute.
@Test
public void determineTransactionManagerWithNoTransactionAttribute() {
BeanFactory beanFactory = mock(BeanFactory.class);
TransactionInterceptor ti = simpleTransactionInterceptor(beanFactory);
assertNull(ti.determineTransactionManager(null));
}
use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.
the class TransactionInterceptorTests method determineTransactionManagerWithBeanNameSeveralTimes.
@Test
public void determineTransactionManagerWithBeanNameSeveralTimes() {
BeanFactory beanFactory = mock(BeanFactory.class);
TransactionInterceptor ti = transactionInterceptorWithTransactionManagerName("fooTransactionManager", beanFactory);
PlatformTransactionManager txManager = associateTransactionManager(beanFactory, "fooTransactionManager");
DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
PlatformTransactionManager actual = ti.determineTransactionManager(attribute);
assertSame(txManager, actual);
// Call again, should be cached
PlatformTransactionManager actual2 = ti.determineTransactionManager(attribute);
assertSame(txManager, actual2);
verify(beanFactory, times(1)).getBean("fooTransactionManager", PlatformTransactionManager.class);
}
Aggregations