Search in sources :

Example 1 with AnnotationConfigApplicationContext

use of cn.taketoday.context.annotation.AnnotationConfigApplicationContext in project today-infrastructure by TAKETODAY.

the class AnnotatedServiceWithoutInterface method annotatedService_PTC_true.

@Test
void annotatedService_PTC_true() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(PTCTrue.class, NonAnnotatedServiceImpl.class);
    ctx.refresh();
    AnnotatedService s = ctx.getBean(AnnotatedService.class);
    assertThat(AopUtils.isCglibProxy(s)).isTrue();
    assertThat(s).isInstanceOf(NonAnnotatedServiceImpl.class);
}
Also used : AnnotationConfigApplicationContext(cn.taketoday.context.annotation.AnnotationConfigApplicationContext) Test(org.junit.jupiter.api.Test)

Example 2 with AnnotationConfigApplicationContext

use of cn.taketoday.context.annotation.AnnotationConfigApplicationContext in project today-infrastructure by TAKETODAY.

the class AnnotatedServiceWithoutInterface method nonAnnotatedService_PTC_false.

@Test
void nonAnnotatedService_PTC_false() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(PTCFalse.class, AnnotatedServiceImpl.class);
    ctx.refresh();
    NonAnnotatedService s = ctx.getBean(NonAnnotatedService.class);
    assertThat(AopUtils.isJdkDynamicProxy(s)).isTrue();
    assertThat(s).isNotInstanceOf(AnnotatedServiceImpl.class);
}
Also used : AnnotationConfigApplicationContext(cn.taketoday.context.annotation.AnnotationConfigApplicationContext) Test(org.junit.jupiter.api.Test)

Example 3 with AnnotationConfigApplicationContext

use of cn.taketoday.context.annotation.AnnotationConfigApplicationContext in project today-infrastructure by TAKETODAY.

the class EnableTransactionManagementIntegrationTests method repositoryUsesAspectJAdviceMode.

@Test
void repositoryUsesAspectJAdviceMode() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(Config.class, AspectJTxConfig.class);
    // this test is a bit fragile, but gets the job done, proving that an
    // attempt was made to look up the AJ aspect. It's due to classpath issues
    // in .integration-tests that it's not found.
    assertThatExceptionOfType(NestedRuntimeException.class).isThrownBy(ctx::refresh).satisfies(ex -> {
        assertThat(ex.getNestedMessage()).contains("AspectJJtaTransactionManagementConfiguration");
    });
}
Also used : AnnotationConfigApplicationContext(cn.taketoday.context.annotation.AnnotationConfigApplicationContext) Test(org.junit.jupiter.api.Test)

Example 4 with AnnotationConfigApplicationContext

use of cn.taketoday.context.annotation.AnnotationConfigApplicationContext in project today-infrastructure by TAKETODAY.

the class EnableTransactionManagementIntegrationTests method explicitTxManager.

@Test
void explicitTxManager() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ExplicitTxManagerConfig.class);
    FooRepository fooRepository = ctx.getBean(FooRepository.class);
    fooRepository.findAll();
    CallCountingTransactionManager txManager1 = ctx.getBean("txManager1", CallCountingTransactionManager.class);
    assertThat(txManager1.begun).isEqualTo(1);
    assertThat(txManager1.commits).isEqualTo(1);
    assertThat(txManager1.rollbacks).isEqualTo(0);
    CallCountingTransactionManager txManager2 = ctx.getBean("txManager2", CallCountingTransactionManager.class);
    assertThat(txManager2.begun).isEqualTo(0);
    assertThat(txManager2.commits).isEqualTo(0);
    assertThat(txManager2.rollbacks).isEqualTo(0);
}
Also used : AnnotationConfigApplicationContext(cn.taketoday.context.annotation.AnnotationConfigApplicationContext) CallCountingTransactionManager(cn.taketoday.testfixture.transaction.CallCountingTransactionManager) Test(org.junit.jupiter.api.Test)

Example 5 with AnnotationConfigApplicationContext

use of cn.taketoday.context.annotation.AnnotationConfigApplicationContext in project today-infrastructure by TAKETODAY.

the class EnableTransactionManagementIntegrationTests method implicitTxManager.

@Test
void implicitTxManager() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImplicitTxManagerConfig.class);
    FooRepository fooRepository = ctx.getBean(FooRepository.class);
    fooRepository.findAll();
    CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
    assertThat(txManager.begun).isEqualTo(1);
    assertThat(txManager.commits).isEqualTo(1);
    assertThat(txManager.rollbacks).isEqualTo(0);
}
Also used : AnnotationConfigApplicationContext(cn.taketoday.context.annotation.AnnotationConfigApplicationContext) CallCountingTransactionManager(cn.taketoday.testfixture.transaction.CallCountingTransactionManager) Test(org.junit.jupiter.api.Test)

Aggregations

AnnotationConfigApplicationContext (cn.taketoday.context.annotation.AnnotationConfigApplicationContext)383 Test (org.junit.jupiter.api.Test)276 Test (org.junit.Test)40 ConfigurableApplicationContext (cn.taketoday.context.ConfigurableApplicationContext)36 BeforeEach (org.junit.jupiter.api.BeforeEach)21 ApplicationContext (cn.taketoday.context.ApplicationContext)20 EnabledForTestGroups (cn.taketoday.core.testfixture.EnabledForTestGroups)18 ConcurrentMapCache (cn.taketoday.cache.concurrent.ConcurrentMapCache)14 BeanCreationException (cn.taketoday.beans.factory.BeanCreationException)12 Cache (cn.taketoday.cache.Cache)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)10 ConcurrentMapCacheManager (cn.taketoday.cache.concurrent.ConcurrentMapCacheManager)10 SimpleCacheManager (cn.taketoday.cache.support.SimpleCacheManager)10 RootBeanDefinition (cn.taketoday.beans.factory.support.RootBeanDefinition)8 DefaultJCacheOperationSource (cn.taketoday.cache.jcache.interceptor.DefaultJCacheOperationSource)8 CallCountingTransactionManager (cn.taketoday.testfixture.transaction.CallCountingTransactionManager)8 Method (java.lang.reflect.Method)7 NoSuchBeanDefinitionException (cn.taketoday.beans.factory.NoSuchBeanDefinitionException)6