Search in sources :

Example 11 with ApplicationContext

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

the class JoinPointMonitorAtAspectJAspect method checkAtAspectJAspect.

private void checkAtAspectJAspect(String appContextFile) {
    ApplicationContext context = new ClassPathXmlApplicationContext(appContextFile, getClass());
    ICounter counter = (ICounter) context.getBean("counter");
    boolean condition = counter instanceof Advised;
    assertThat(condition).as("Proxy didn't get created").isTrue();
    counter.increment();
    JoinPointMonitorAtAspectJAspect callCountingAspect = (JoinPointMonitorAtAspectJAspect) context.getBean("monitoringAspect");
    assertThat(callCountingAspect.beforeExecutions).as("Advise didn't get executed").isEqualTo(1);
    assertThat(callCountingAspect.aroundExecutions).as("Advise didn't get executed").isEqualTo(1);
}
Also used : ClassPathXmlApplicationContext(cn.taketoday.context.support.ClassPathXmlApplicationContext) ApplicationContext(cn.taketoday.context.ApplicationContext) ClassPathXmlApplicationContext(cn.taketoday.context.support.ClassPathXmlApplicationContext) Advised(cn.taketoday.aop.framework.Advised)

Example 12 with ApplicationContext

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

the class JoinPointMonitorAtAspectJAspect method checkXmlAspect.

private void checkXmlAspect(String appContextFile) {
    ApplicationContext context = new ClassPathXmlApplicationContext(appContextFile, getClass());
    ICounter counter = (ICounter) context.getBean("counter");
    boolean condition = counter instanceof Advised;
    assertThat(condition).as("Proxy didn't get created").isTrue();
    counter.increment();
    JoinPointMonitorAspect callCountingAspect = (JoinPointMonitorAspect) context.getBean("monitoringAspect");
    assertThat(callCountingAspect.beforeExecutions).as("Advise didn't get executed").isEqualTo(1);
    assertThat(callCountingAspect.aroundExecutions).as("Advise didn't get executed").isEqualTo(1);
}
Also used : ClassPathXmlApplicationContext(cn.taketoday.context.support.ClassPathXmlApplicationContext) ApplicationContext(cn.taketoday.context.ApplicationContext) ClassPathXmlApplicationContext(cn.taketoday.context.support.ClassPathXmlApplicationContext) Advised(cn.taketoday.aop.framework.Advised)

Example 13 with ApplicationContext

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

the class CacheResolverCustomizationTests method setup.

@BeforeEach
public void setup() {
    ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
    this.cacheManager = context.getBean("cacheManager", CacheManager.class);
    this.anotherCacheManager = context.getBean("anotherCacheManager", CacheManager.class);
    this.simpleService = context.getBean(SimpleService.class);
}
Also used : AnnotationConfigApplicationContext(cn.taketoday.context.annotation.AnnotationConfigApplicationContext) ApplicationContext(cn.taketoday.context.ApplicationContext) AnnotationConfigApplicationContext(cn.taketoday.context.annotation.AnnotationConfigApplicationContext) CacheManager(cn.taketoday.cache.CacheManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 14 with ApplicationContext

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

Example 15 with ApplicationContext

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

the class AnnoTestBean method explicitConfigClassBeanNameIsRespected.

/**
 * Tests that specifying @Configuration(value="foo") results in registering
 * the configuration class with bean name 'foo'.
 */
@Test
void explicitConfigClassBeanNameIsRespected() {
    ApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithCustomName.class);
    // attempt to retrieve the instance by its specified name
    ConfigWithCustomName configObject = (ConfigWithCustomName) context.getBean("customConfigBeanName");
    assertThat(configObject).isNotNull();
}
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