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));
}
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;
}
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);
}
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");
}
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");
}
Aggregations