Search in sources :

Example 6 with ApplicationContext

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

the class Spr7816Tests method spr7816.

@Test
public void spr7816() {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("spr7816.xml", getClass());
    FilterAdapter adapter = ctx.getBean(FilterAdapter.class);
    assertThat(adapter.getSupportedTypes().get("Building")).isEqualTo(Building.class);
    assertThat(adapter.getSupportedTypes().get("Entrance")).isEqualTo(Entrance.class);
    assertThat(adapter.getSupportedTypes().get("Dwelling")).isEqualTo(Dwelling.class);
}
Also used : ClassPathXmlApplicationContext(cn.taketoday.context.support.ClassPathXmlApplicationContext) ApplicationContext(cn.taketoday.context.ApplicationContext) ClassPathXmlApplicationContext(cn.taketoday.context.support.ClassPathXmlApplicationContext) Test(org.junit.jupiter.api.Test)

Example 7 with ApplicationContext

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

the class GenericXmlApplicationContextTests method classRelativeResourceLoading_ctor.

@Test
public void classRelativeResourceLoading_ctor() {
    ApplicationContext ctx = new GenericXmlApplicationContext(RELATIVE_CLASS, RESOURCE_NAME);
    assertThat(ctx.containsBean(TEST_BEAN_NAME)).isTrue();
}
Also used : ApplicationContext(cn.taketoday.context.ApplicationContext) Test(org.junit.jupiter.api.Test)

Example 8 with ApplicationContext

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

the class PayloadApplicationEventTests method testEventClassWithInterface.

@Test
@SuppressWarnings("resource")
void testEventClassWithInterface() {
    ApplicationContext ac = new AnnotationConfigApplicationContext(AuditableListener.class);
    AuditablePayloadEvent<String> event = new AuditablePayloadEvent<>(this, "xyz");
    ac.publishEvent(event);
    assertThat(ac.getBean(AuditableListener.class).events.contains(event)).isTrue();
}
Also used : GenericApplicationContext(cn.taketoday.context.support.GenericApplicationContext) ConfigurableApplicationContext(cn.taketoday.context.ConfigurableApplicationContext) AnnotationConfigApplicationContext(cn.taketoday.context.annotation.AnnotationConfigApplicationContext) ApplicationContext(cn.taketoday.context.ApplicationContext) AnnotationConfigApplicationContext(cn.taketoday.context.annotation.AnnotationConfigApplicationContext) Test(org.junit.jupiter.api.Test)

Example 9 with ApplicationContext

use of cn.taketoday.context.ApplicationContext in project today-infrastructure 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 10 with ApplicationContext

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

the class ConfigurationClassAspectIntegrationTests method withInnerClassAndLambdaExpression.

// @Test
// public void aspectAnnotatedConfiguration() {
// assertAdviceWasApplied(AspectConfig.class);
// }
// 
// @Test
// public void configurationIncludesAspect() {
// assertAdviceWasApplied(ConfigurationWithAspect.class);
// }
// 
// private void assertAdviceWasApplied(Class<?> configClass) {
// StandardBeanFactory factory = new StandardBeanFactory();
// new XmlBeanDefinitionReader(factory).loadBeanDefinitions(
// new ClassPathResource("aspectj-autoproxy-config.xml", ConfigurationClassAspectIntegrationTests.class));
// DefaultApplicationContext ctx = new DefaultApplicationContext(factory);
// ctx.addBeanFactoryPostProcessor(new ConfigurationClassPostProcessor(loadingContext));
// ctx.registerBeanDefinition("config", new BeanDefinition(configClass));
// ctx.refresh();
// 
// TestBean testBean = ctx.getBean("testBean", TestBean.class);
// assertThat(testBean.getName()).isEqualTo("name");
// testBean.absquatulate();
// assertThat(testBean.getName()).isEqualTo("advisedName");
// }
@Test
public void withInnerClassAndLambdaExpression() {
    ApplicationContext ctx = new StandardApplicationContext(Application.class, CountingAspect.class);
    ctx.getBeansOfType(Runnable.class).forEach((k, v) -> v.run());
// TODO: returns just 1 as of AspectJ 1.9 beta 3, not detecting the applicable lambda expression anymore
// assertEquals(2, ctx.getBean(CountingAspect.class).count);
}
Also used : StandardApplicationContext(cn.taketoday.context.support.StandardApplicationContext) ApplicationContext(cn.taketoday.context.ApplicationContext) StandardApplicationContext(cn.taketoday.context.support.StandardApplicationContext) 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