use of cn.taketoday.beans.factory.BeanFactory in project today-infrastructure by TAKETODAY.
the class Rollback method testRegexpApplied.
@Test
void testRegexpApplied() throws Exception {
BeanFactory bf = getBeanFactory();
ITestBean test = (ITestBean) bf.getBean("test");
MethodCounter counter = (MethodCounter) bf.getBean("countingAdvice");
assertThat(counter.getCalls()).isEqualTo(0);
test.getName();
assertThat(counter.getCalls()).isEqualTo(1);
}
use of cn.taketoday.beans.factory.BeanFactory in project today-infrastructure by TAKETODAY.
the class Rollback method testRollbackRulesOnMethodCauseRollback.
/**
* Should not roll back on servlet exception.
*/
@Test
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");
assertThat(txc.getCountingBeforeAdvice().getCalls()).isEqualTo(0);
assertThat(txMan.commits).isEqualTo(0);
rb.echoException(null);
// Fires only on setters
assertThat(txc.getCountingBeforeAdvice().getCalls()).isEqualTo(0);
assertThat(txMan.commits).as("Transaction counts match").isEqualTo(1);
assertThat(txMan.rollbacks).isEqualTo(0);
Exception ex = new Exception();
try {
rb.echoException(ex);
} catch (Exception actual) {
assertThat(actual).isEqualTo(ex);
}
assertThat(txMan.rollbacks).as("Transaction counts match").isEqualTo(1);
}
use of cn.taketoday.beans.factory.BeanFactory in project today-infrastructure by TAKETODAY.
the class Rollback method testTxIsProxied.
@Test
void testTxIsProxied() throws Exception {
BeanFactory bf = getBeanFactory();
ITestBean test = (ITestBean) bf.getBean("test");
assertThat(AopUtils.isAopProxy(test)).isTrue();
}
use of cn.taketoday.beans.factory.BeanFactory in project today-infrastructure by TAKETODAY.
the class Rollback method testNoProxy.
/**
* If no pointcuts match (no attrs) there should be proxying.
*/
@Test
void testNoProxy() throws Exception {
BeanFactory bf = getBeanFactory();
Object o = bf.getBean("noSetters");
assertThat(AopUtils.isAopProxy(o)).isFalse();
}
use of cn.taketoday.beans.factory.BeanFactory in project today-infrastructure by TAKETODAY.
the class ControllerAdviceBeanTests method assertOrder.
@SuppressWarnings({ "rawtypes", "unchecked" })
private void assertOrder(Class beanType, int expectedOrder) {
String beanName = "myBean";
BeanFactory beanFactory = mock(BeanFactory.class);
given(beanFactory.containsBean(beanName)).willReturn(true);
given(beanFactory.getType(beanName)).willReturn(beanType);
given(beanFactory.getBean(beanName)).willReturn(BeanUtils.newInstance(beanType));
ControllerAdviceBean controllerAdviceBean = new ControllerAdviceBean(beanName, beanFactory);
assertThat(controllerAdviceBean.getOrder()).isEqualTo(expectedOrder);
verify(beanFactory).containsBean(beanName);
verify(beanFactory).getType(beanName);
verify(beanFactory).getBean(beanName);
}
Aggregations