Search in sources :

Example 1 with BeanFactory

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);
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) BeanFactory(cn.taketoday.beans.factory.BeanFactory) MethodCounter(cn.taketoday.aop.testfixture.advice.MethodCounter) Test(org.junit.jupiter.api.Test)

Example 2 with BeanFactory

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);
}
Also used : CallCountingTransactionManager(cn.taketoday.testfixture.transaction.CallCountingTransactionManager) BeanFactory(cn.taketoday.beans.factory.BeanFactory) NoTransactionException(cn.taketoday.transaction.NoTransactionException) IOException(java.io.IOException) ServletException(jakarta.servlet.ServletException) Test(org.junit.jupiter.api.Test)

Example 3 with BeanFactory

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();
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) BeanFactory(cn.taketoday.beans.factory.BeanFactory) Test(org.junit.jupiter.api.Test)

Example 4 with BeanFactory

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();
}
Also used : BeanFactory(cn.taketoday.beans.factory.BeanFactory) Test(org.junit.jupiter.api.Test)

Example 5 with BeanFactory

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);
}
Also used : BeanFactory(cn.taketoday.beans.factory.BeanFactory)

Aggregations

BeanFactory (cn.taketoday.beans.factory.BeanFactory)80 Test (org.junit.jupiter.api.Test)60 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)24 StandardBeanFactory (cn.taketoday.beans.factory.support.StandardBeanFactory)16 PlatformTransactionManager (cn.taketoday.transaction.PlatformTransactionManager)16 ClassPathXmlApplicationContext (cn.taketoday.context.support.ClassPathXmlApplicationContext)10 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)8 CallCountingTransactionManager (cn.taketoday.testfixture.transaction.CallCountingTransactionManager)8 TransactionManager (cn.taketoday.transaction.TransactionManager)8 NestedTestBean (cn.taketoday.beans.testfixture.beans.NestedTestBean)6 List (java.util.List)6 DataSource (javax.sql.DataSource)6 Advised (cn.taketoday.aop.framework.Advised)4 BeansException (cn.taketoday.beans.BeansException)4 FatalBeanException (cn.taketoday.beans.FatalBeanException)4 NoSuchBeanDefinitionException (cn.taketoday.beans.factory.NoSuchBeanDefinitionException)4 Nullable (cn.taketoday.lang.Nullable)4 Collection (java.util.Collection)4 Set (java.util.Set)4 ServletException (jakarta.servlet.ServletException)3