Search in sources :

Example 96 with ApplicationContext

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

the class ApplicationContextEventTests method testEventPublicationInterceptor.

@Test
public void testEventPublicationInterceptor() throws Throwable {
    MethodInvocation invocation = mock(MethodInvocation.class);
    ApplicationContext ctx = mock(ApplicationContext.class);
    EventPublicationInterceptor interceptor = new EventPublicationInterceptor();
    interceptor.setApplicationEventClass(MyEvent.class);
    interceptor.setApplicationEventPublisher(ctx);
    interceptor.afterPropertiesSet();
    given(invocation.proceed()).willReturn(new Object());
    given(invocation.getThis()).willReturn(new Object());
    interceptor.invoke(invocation);
    verify(ctx).publishEvent(isA(MyEvent.class));
}
Also used : GenericApplicationContext(cn.taketoday.context.support.GenericApplicationContext) StaticApplicationContext(cn.taketoday.context.support.StaticApplicationContext) ApplicationContext(cn.taketoday.context.ApplicationContext) AbstractApplicationContext(cn.taketoday.context.support.AbstractApplicationContext) MethodInvocation(org.aopalliance.intercept.MethodInvocation) Test(org.junit.jupiter.api.Test)

Example 97 with ApplicationContext

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

the class WebApplicationContextSupport method obtainApplicationContext.

@Override
public WebApplicationContext obtainApplicationContext() {
    ApplicationContext context = this.applicationContext;
    Assert.state(context != null, "No WebApplicationContext");
    return (WebApplicationContext) context;
}
Also used : ApplicationContext(cn.taketoday.context.ApplicationContext)

Example 98 with ApplicationContext

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

the class ExceptionHandlerAnnotationExceptionHandler method afterPropertiesSet.

@Override
public void afterPropertiesSet() {
    ApplicationContext context = getApplicationContext();
    Assert.state(context != null, "No ApplicationContext");
    if (handlerFactory == null) {
        handlerFactory = new AnnotationHandlerFactory(context);
        handlerFactory.initDefaults();
    }
    initExceptionHandlerAdviceCache(context);
}
Also used : ApplicationContext(cn.taketoday.context.ApplicationContext)

Example 99 with ApplicationContext

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

the class AnnoTestBean method autowiringIsEnabledByDefault.

@Test
void autowiringIsEnabledByDefault() {
    ApplicationContext context = new AnnotationConfigApplicationContext(AutowiredConfig.class);
    assertThat(context.getBean(AnnoTestBean.class).name).isEqualTo("foo");
}
Also used : ApplicationContext(cn.taketoday.context.ApplicationContext) Test(org.junit.jupiter.api.Test)

Example 100 with ApplicationContext

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

the class AnnoTestBean method getBeanByTypeAmbiguityRaisesException.

@Test
void getBeanByTypeAmbiguityRaisesException() {
    ApplicationContext context = new AnnotationConfigApplicationContext(TwoTestBeanConfig.class);
    assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() -> context.getBean(AnnoTestBean.class)).withMessageContaining("No qualifying bean of type '" + AnnoTestBean.class.getName() + "'").withMessageContaining("tb1").withMessageContaining("tb2");
}
Also used : ApplicationContext(cn.taketoday.context.ApplicationContext) Test(org.junit.jupiter.api.Test)

Aggregations

ApplicationContext (cn.taketoday.context.ApplicationContext)200 Test (org.junit.jupiter.api.Test)158 StandardApplicationContext (cn.taketoday.context.support.StandardApplicationContext)44 ConfigurableApplicationContext (cn.taketoday.context.ConfigurableApplicationContext)29 AnnotationConfigApplicationContext (cn.taketoday.context.annotation.AnnotationConfigApplicationContext)24 GenericWebServletApplicationContext (cn.taketoday.web.context.support.GenericWebServletApplicationContext)22 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)14 ClassPathXmlApplicationContext (cn.taketoday.context.support.ClassPathXmlApplicationContext)12 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)10 WebServletApplicationContext (cn.taketoday.web.servlet.WebServletApplicationContext)8 GenericApplicationContext (cn.taketoday.context.support.GenericApplicationContext)6 ConfigurableEnvironment (cn.taketoday.core.env.ConfigurableEnvironment)6 PropertySources (cn.taketoday.core.env.PropertySources)6 Resource (cn.taketoday.core.io.Resource)6 Nullable (cn.taketoday.lang.Nullable)6 FooService (example.scannable.FooService)6 ServletContext (jakarta.servlet.ServletContext)6 WebApplicationContext (cn.taketoday.web.WebApplicationContext)5 AutowireCapableBeanFactory (cn.taketoday.beans.factory.config.AutowireCapableBeanFactory)4 Advised (cn.taketoday.aop.framework.Advised)3