Search in sources :

Example 46 with BeanFactory

use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.

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(org.springframework.beans.testfixture.beans.ITestBean) BeanFactory(org.springframework.beans.factory.BeanFactory) Test(org.junit.jupiter.api.Test)

Example 47 with BeanFactory

use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.

the class Rollback method testRollbackRulesOnMethodPreventRollback.

@Test
void testRollbackRulesOnMethodPreventRollback() throws Exception {
    BeanFactory bf = getBeanFactory();
    Rollback rb = (Rollback) bf.getBean("rollback");
    CallCountingTransactionManager txMan = (CallCountingTransactionManager) bf.getBean(TXMANAGER_BEAN_NAME);
    assertThat(txMan.commits).isEqualTo(0);
    // Should NOT roll back on ServletException
    try {
        rb.echoException(new ServletException());
    } catch (ServletException ex) {
    }
    assertThat(txMan.commits).as("Transaction counts match").isEqualTo(1);
}
Also used : ServletException(jakarta.servlet.ServletException) CallCountingTransactionManager(org.springframework.transaction.testfixture.CallCountingTransactionManager) BeanFactory(org.springframework.beans.factory.BeanFactory) Test(org.junit.jupiter.api.Test)

Example 48 with BeanFactory

use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.

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(org.springframework.beans.factory.BeanFactory) Test(org.junit.jupiter.api.Test)

Example 49 with BeanFactory

use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.

the class Rollback method testTransactionAttributeOnMethod.

@Test
void testTransactionAttributeOnMethod() throws Exception {
    BeanFactory bf = getBeanFactory();
    ITestBean test = (ITestBean) bf.getBean("test");
    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);
    assertThat(test.getAge()).as("Initial value was correct").isEqualTo(4);
    int newAge = 5;
    test.setAge(newAge);
    assertThat(txc.getCountingBeforeAdvice().getCalls()).isEqualTo(1);
    assertThat(test.getAge()).as("New value set correctly").isEqualTo(newAge);
    assertThat(txMan.commits).as("Transaction counts match").isEqualTo(1);
}
Also used : ITestBean(org.springframework.beans.testfixture.beans.ITestBean) CallCountingTransactionManager(org.springframework.transaction.testfixture.CallCountingTransactionManager) BeanFactory(org.springframework.beans.factory.BeanFactory) Test(org.junit.jupiter.api.Test)

Example 50 with BeanFactory

use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.

the class ServiceLocatorFactoryBeanTests method testRequiresListableBeanFactoryAndChokesOnAnythingElse.

@Test
public void testRequiresListableBeanFactoryAndChokesOnAnythingElse() throws Exception {
    BeanFactory beanFactory = mock(BeanFactory.class);
    try {
        ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean();
        factory.setBeanFactory(beanFactory);
    } catch (FatalBeanException ex) {
    // expected
    }
}
Also used : BeanFactory(org.springframework.beans.factory.BeanFactory) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) FatalBeanException(org.springframework.beans.FatalBeanException) Test(org.junit.jupiter.api.Test)

Aggregations

BeanFactory (org.springframework.beans.factory.BeanFactory)121 Test (org.junit.jupiter.api.Test)30 ConfigurableBeanFactory (org.springframework.beans.factory.config.ConfigurableBeanFactory)25 Test (org.junit.Test)20 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)16 ListableBeanFactory (org.springframework.beans.factory.ListableBeanFactory)15 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)12 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)11 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)11 CountDownLatch (java.util.concurrent.CountDownLatch)9 ExecutorService (java.util.concurrent.ExecutorService)8 PlatformTransactionManager (org.springframework.transaction.PlatformTransactionManager)8 AutowireCapableBeanFactory (org.springframework.beans.factory.config.AutowireCapableBeanFactory)7 GenericMessage (org.springframework.messaging.support.GenericMessage)7 ThreadPoolTaskScheduler (org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler)7 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)6 JmsTemplate (org.springframework.jms.core.JmsTemplate)6 Bucket4JAutoConfigurationServletFilter (com.giffing.bucket4j.spring.boot.starter.config.servlet.Bucket4JAutoConfigurationServletFilter)4 Bucket4JAutoConfigurationZuul (com.giffing.bucket4j.spring.boot.starter.config.zuul.Bucket4JAutoConfigurationZuul)4