Search in sources :

Example 16 with ApplicationContext

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

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

the class AnnoTestBean method getBeanByTypeRaisesNoSuchBeanDefinitionException.

@Test
void getBeanByTypeRaisesNoSuchBeanDefinitionException() {
    ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
    // attempt to retrieve a bean that does not exist
    Class<?> targetType = Pattern.class;
    assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() -> context.getBean(targetType)).withMessageContaining(format("No qualifying bean of type '%s'", targetType.getName()));
}
Also used : Pattern(java.util.regex.Pattern) ApplicationContext(cn.taketoday.context.ApplicationContext) Test(org.junit.jupiter.api.Test)

Example 18 with ApplicationContext

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

the class AvailabilityChangeEventTests method publishPublishesEvent.

@Test
void publishPublishesEvent() {
    ApplicationContext context = mock(ApplicationContext.class);
    AvailabilityState state = LivenessState.CORRECT;
    AvailabilityChangeEvent.publish(context, state);
    ArgumentCaptor<ApplicationEvent> captor = ArgumentCaptor.forClass(ApplicationEvent.class);
    then(context).should().publishEvent(captor.capture());
    AvailabilityChangeEvent<?> event = (AvailabilityChangeEvent<?>) captor.getValue();
    assertThat(event.getSource()).isEqualTo(context);
    assertThat(event.getState()).isEqualTo(state);
}
Also used : AnnotationConfigApplicationContext(cn.taketoday.context.annotation.AnnotationConfigApplicationContext) ApplicationContext(cn.taketoday.context.ApplicationContext) ApplicationEvent(cn.taketoday.context.ApplicationEvent) Test(org.junit.jupiter.api.Test)

Example 19 with ApplicationContext

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

the class UnsupportedInterceptor method testWithDependencyChecking.

@Test
@SuppressWarnings("resource")
public void testWithDependencyChecking() {
    ApplicationContext ctx = new ClassPathXmlApplicationContext(DEPENDENCY_CHECK_CONTEXT, getClass());
    ctx.getBean("testBean");
}
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 20 with ApplicationContext

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

the class ObjenesisProxyTests method appliesAspectToClassWithComplexConstructor.

@Test
public void appliesAspectToClassWithComplexConstructor() {
    @SuppressWarnings("resource") ApplicationContext context = new ClassPathXmlApplicationContext("ObjenesisProxyTests-context.xml", getClass());
    ClassWithComplexConstructor bean = context.getBean(ClassWithComplexConstructor.class);
    bean.method();
    DebugInterceptor interceptor = context.getBean(DebugInterceptor.class);
    assertThat(interceptor.getCount()).isEqualTo(1L);
    assertThat(bean.getDependency().getValue()).isEqualTo(1);
}
Also used : ClassPathXmlApplicationContext(cn.taketoday.context.support.ClassPathXmlApplicationContext) ApplicationContext(cn.taketoday.context.ApplicationContext) ClassPathXmlApplicationContext(cn.taketoday.context.support.ClassPathXmlApplicationContext) DebugInterceptor(cn.taketoday.aop.interceptor.DebugInterceptor) 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