Search in sources :

Example 1 with GenericXmlApplicationContext

use of cn.taketoday.context.support.GenericXmlApplicationContext in project today-infrastructure by TAKETODAY.

the class AsyncAnnotationBeanPostProcessorTests method configuredThroughNamespace.

@Test
public void configuredThroughNamespace() {
    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    context.load(new ClassPathResource("taskNamespaceTests.xml", getClass()));
    context.refresh();
    ITestBean testBean = context.getBean("target", ITestBean.class);
    testBean.test();
    testBean.await(3000);
    Thread asyncThread = testBean.getThread();
    assertThat(asyncThread.getName().startsWith("testExecutor")).isTrue();
    TestableAsyncUncaughtExceptionHandler exceptionHandler = context.getBean("exceptionHandler", TestableAsyncUncaughtExceptionHandler.class);
    assertThat(exceptionHandler.isCalled()).as("handler should not have been called yet").isFalse();
    testBean.failWithVoid();
    exceptionHandler.await(3000);
    Method m = ReflectionUtils.findMethod(TestBean.class, "failWithVoid");
    exceptionHandler.assertCalledWith(m, UnsupportedOperationException.class);
    context.close();
}
Also used : Method(java.lang.reflect.Method) GenericXmlApplicationContext(cn.taketoday.context.support.GenericXmlApplicationContext) ClassPathResource(cn.taketoday.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 2 with GenericXmlApplicationContext

use of cn.taketoday.context.support.GenericXmlApplicationContext in project today-infrastructure by TAKETODAY.

the class JCacheAspectJNamespaceConfigTests method getApplicationContext.

@Override
protected ApplicationContext getApplicationContext() {
    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    // Disallow bean definition overriding to test https://github.com/spring-projects/spring-framework/pull/27499
    context.setAllowBeanDefinitionOverriding(false);
    context.load("/cn/taketoday/cache/config/annotation-jcache-aspectj.xml");
    context.refresh();
    return context;
}
Also used : GenericXmlApplicationContext(cn.taketoday.context.support.GenericXmlApplicationContext)

Example 3 with GenericXmlApplicationContext

use of cn.taketoday.context.support.GenericXmlApplicationContext in project today-infrastructure by TAKETODAY.

the class EnvironmentSystemIntegrationTests method genericXmlApplicationContext.

@Test
void genericXmlApplicationContext() {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    assertHasStandardEnvironment(ctx);
    ctx.setEnvironment(prodEnv);
    ctx.load(Constants.XML_PATH);
    ctx.refresh();
    assertHasEnvironment(ctx, prodEnv);
    assertEnvironmentBeanRegistered(ctx);
    assertEnvironmentAwareInvoked(ctx, prodEnv);
    assertThat(ctx.containsBean(Constants.DEV_BEAN_NAME)).isFalse();
    assertThat(ctx.containsBean(Constants.PROD_BEAN_NAME)).isTrue();
}
Also used : GenericXmlApplicationContext(cn.taketoday.context.support.GenericXmlApplicationContext) Test(org.junit.jupiter.api.Test)

Example 4 with GenericXmlApplicationContext

use of cn.taketoday.context.support.GenericXmlApplicationContext in project today-infrastructure by TAKETODAY.

the class AnnotationNamespaceDrivenTests method cacheResolver.

@Test
public void cacheResolver() {
    try {
        ConfigurableApplicationContext context = new GenericXmlApplicationContext("cn/taketoday/cache/config/annotationDrivenCacheNamespace-resolver.xml");
        CacheInterceptor ci = context.getBean(CacheInterceptor.class);
        assertThat(ci.getCacheResolver()).isSameAs(context.getBean("cacheResolver"));
        context.close();
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : ConfigurableApplicationContext(cn.taketoday.context.ConfigurableApplicationContext) CacheInterceptor(cn.taketoday.cache.interceptor.CacheInterceptor) GenericXmlApplicationContext(cn.taketoday.context.support.GenericXmlApplicationContext) Test(org.junit.jupiter.api.Test)

Example 5 with GenericXmlApplicationContext

use of cn.taketoday.context.support.GenericXmlApplicationContext in project today-framework by TAKETODAY.

the class AsyncAnnotationBeanPostProcessorTests method configuredThroughNamespace.

@Test
public void configuredThroughNamespace() {
    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    context.load(new ClassPathResource("taskNamespaceTests.xml", getClass()));
    context.refresh();
    ITestBean testBean = context.getBean("target", ITestBean.class);
    testBean.test();
    testBean.await(3000);
    Thread asyncThread = testBean.getThread();
    assertThat(asyncThread.getName().startsWith("testExecutor")).isTrue();
    TestableAsyncUncaughtExceptionHandler exceptionHandler = context.getBean("exceptionHandler", TestableAsyncUncaughtExceptionHandler.class);
    assertThat(exceptionHandler.isCalled()).as("handler should not have been called yet").isFalse();
    testBean.failWithVoid();
    exceptionHandler.await(3000);
    Method m = ReflectionUtils.findMethod(TestBean.class, "failWithVoid");
    exceptionHandler.assertCalledWith(m, UnsupportedOperationException.class);
    context.close();
}
Also used : Method(java.lang.reflect.Method) GenericXmlApplicationContext(cn.taketoday.context.support.GenericXmlApplicationContext) ClassPathResource(cn.taketoday.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Aggregations

GenericXmlApplicationContext (cn.taketoday.context.support.GenericXmlApplicationContext)14 Test (org.junit.jupiter.api.Test)12 ConfigurableApplicationContext (cn.taketoday.context.ConfigurableApplicationContext)8 CacheInterceptor (cn.taketoday.cache.interceptor.CacheInterceptor)4 DefaultJCacheOperationSource (cn.taketoday.cache.jcache.interceptor.DefaultJCacheOperationSource)2 ClassPathResource (cn.taketoday.core.io.ClassPathResource)2 Method (java.lang.reflect.Method)2