use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.
the class TransactionInterceptorTests method determineTransactionManagerWithQualifierAndDefaultName.
@Test
public void determineTransactionManagerWithQualifierAndDefaultName() {
BeanFactory beanFactory = mock(BeanFactory.class);
associateTransactionManager(beanFactory, "defaultTransactionManager");
TransactionInterceptor ti = transactionInterceptorWithTransactionManagerName("defaultTransactionManager", beanFactory);
PlatformTransactionManager fooTransactionManager = associateTransactionManager(beanFactory, "fooTransactionManager");
DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
attribute.setQualifier("fooTransactionManager");
assertSame(fooTransactionManager, ti.determineTransactionManager(attribute));
}
use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.
the class TransactionInterceptorTests method determineTransactionManagerWithEmptyQualifierAndDefaultName.
@Test
public void determineTransactionManagerWithEmptyQualifierAndDefaultName() {
BeanFactory beanFactory = mock(BeanFactory.class);
PlatformTransactionManager defaultTransactionManager = associateTransactionManager(beanFactory, "defaultTransactionManager");
TransactionInterceptor ti = transactionInterceptorWithTransactionManagerName("defaultTransactionManager", beanFactory);
DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
attribute.setQualifier("");
assertSame(defaultTransactionManager, ti.determineTransactionManager(attribute));
}
use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.
the class ObjectFactoryCreatingFactoryBeanTests method testDoesNotComplainWhenTargetBeanNameRefersToSingleton.
@Test
public void testDoesNotComplainWhenTargetBeanNameRefersToSingleton() throws Exception {
final String targetBeanName = "singleton";
final String expectedSingleton = "Alicia Keys";
BeanFactory beanFactory = mock(BeanFactory.class);
given(beanFactory.getBean(targetBeanName)).willReturn(expectedSingleton);
ObjectFactoryCreatingFactoryBean factory = new ObjectFactoryCreatingFactoryBean();
factory.setTargetBeanName(targetBeanName);
factory.setBeanFactory(beanFactory);
factory.afterPropertiesSet();
ObjectFactory<?> objectFactory = factory.getObject();
Object actualSingleton = objectFactory.getObject();
assertSame(expectedSingleton, actualSingleton);
}
use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.
the class Rollback method testProgrammaticRollback.
@Test
public void testProgrammaticRollback() throws Exception {
BeanFactory bf = getBeanFactory();
Object bean = bf.getBean(TXMANAGER_BEAN_NAME);
assertTrue(bean instanceof CallCountingTransactionManager);
CallCountingTransactionManager txMan = (CallCountingTransactionManager) bf.getBean(TXMANAGER_BEAN_NAME);
Rollback rb = (Rollback) bf.getBean("rollback");
assertEquals(0, txMan.commits);
rb.rollbackOnly(false);
assertEquals("Transaction counts match", 1, txMan.commits);
assertEquals(0, txMan.rollbacks);
// Will cause rollback only
rb.rollbackOnly(true);
assertEquals(1, txMan.rollbacks);
}
use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.
the class Rollback method testRollbackRulesOnMethodCauseRollback.
/**
* Should not roll back on servlet exception.
*/
@Test
public void testRollbackRulesOnMethodCauseRollback() throws Exception {
BeanFactory bf = getBeanFactory();
Rollback rb = (Rollback) bf.getBean("rollback");
CallCountingTransactionManager txMan = (CallCountingTransactionManager) bf.getBean(TXMANAGER_BEAN_NAME);
OrderedTxCheckAdvisor txc = (OrderedTxCheckAdvisor) bf.getBean("orderedBeforeTransaction");
assertEquals(0, txc.getCountingBeforeAdvice().getCalls());
assertEquals(0, txMan.commits);
rb.echoException(null);
// Fires only on setters
assertEquals(0, txc.getCountingBeforeAdvice().getCalls());
assertEquals("Transaction counts match", 1, txMan.commits);
assertEquals(0, txMan.rollbacks);
Exception ex = new Exception();
try {
rb.echoException(ex);
} catch (Exception actual) {
assertEquals(ex, actual);
}
assertEquals("Transaction counts match", 1, txMan.rollbacks);
}
Aggregations