Search in sources :

Example 96 with AnnotationConfigApplicationContext

use of org.springframework.context.annotation.AnnotationConfigApplicationContext in project spring-framework by spring-projects.

the class ConfigurationClassWithPlaceholderConfigurerBeanTests method valueFieldsResolveToPlaceholderSpecifiedDefaultValue.

@Test
public void valueFieldsResolveToPlaceholderSpecifiedDefaultValue() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(ConfigWithValueField.class);
    ctx.register(ConfigWithPlaceholderConfigurer.class);
    ctx.refresh();
    TestBean testBean = ctx.getBean(TestBean.class);
    assertThat(testBean.getName(), equalTo("bar"));
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) Test(org.junit.Test)

Example 97 with AnnotationConfigApplicationContext

use of org.springframework.context.annotation.AnnotationConfigApplicationContext in project spring-framework by spring-projects.

the class ConfigurationMetaAnnotationTests method customConfigurationStereotype.

@Test
public void customConfigurationStereotype() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(Config.class);
    ctx.refresh();
    assertThat(ctx.containsBean("customName"), is(true));
    TestBean a = ctx.getBean("a", TestBean.class);
    TestBean b = ctx.getBean("b", TestBean.class);
    assertThat(b, sameInstance(a.getSpouse()));
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) TestBean(org.springframework.tests.sample.beans.TestBean) Test(org.junit.Test)

Example 98 with AnnotationConfigApplicationContext

use of org.springframework.context.annotation.AnnotationConfigApplicationContext in project spring-framework by spring-projects.

the class ImportAnnotationDetectionTests method localAndMetaImportsAreProcessed.

@Test
public void localAndMetaImportsAreProcessed() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(MultiMetaImportConfigWithLocalImport.class);
    ctx.refresh();
    assertThat(ctx.containsBean("testBean1"), is(true));
    assertThat(ctx.containsBean("testBean2"), is(true));
    assertThat(ctx.containsBean("testBean3"), is(true));
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Test(org.junit.Test)

Example 99 with AnnotationConfigApplicationContext

use of org.springframework.context.annotation.AnnotationConfigApplicationContext in project spring-framework by spring-projects.

the class BeanMethodQualificationTests method testCustomWithAttributeOverride.

@Test
public void testCustomWithAttributeOverride() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(CustomConfigWithAttributeOverride.class, CustomPojo.class);
    assertFalse(ctx.getBeanFactory().containsSingleton("testBeanX"));
    CustomPojo pojo = ctx.getBean(CustomPojo.class);
    assertThat(pojo.testBean.getName(), equalTo("interesting"));
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Test(org.junit.Test)

Example 100 with AnnotationConfigApplicationContext

use of org.springframework.context.annotation.AnnotationConfigApplicationContext in project spring-framework by spring-projects.

the class BeanMethodQualificationTests method testCustomWithAsm.

@Test
public void testCustomWithAsm() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.registerBeanDefinition("customConfig", new RootBeanDefinition(CustomConfig.class.getName()));
    RootBeanDefinition customPojo = new RootBeanDefinition(CustomPojo.class.getName());
    customPojo.setLazyInit(true);
    ctx.registerBeanDefinition("customPojo", customPojo);
    ctx.refresh();
    assertFalse(ctx.getBeanFactory().containsSingleton("testBean1"));
    CustomPojo pojo = ctx.getBean(CustomPojo.class);
    assertThat(pojo.testBean.getName(), equalTo("interesting"));
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Aggregations

AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)694 Test (org.junit.Test)513 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)42 Before (org.junit.Before)21 ApplicationContext (org.springframework.context.ApplicationContext)19 Filter (javax.servlet.Filter)15 OncePerRequestFilter (org.springframework.web.filter.OncePerRequestFilter)14 Map (java.util.Map)13 TestBean (org.springframework.tests.sample.beans.TestBean)13 PropertyPlaceholderAutoConfiguration (org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration)12 MockMvc (org.springframework.test.web.servlet.MockMvc)12 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)10 MockEnvironment (org.springframework.mock.env.MockEnvironment)10 MapPropertySource (org.springframework.core.env.MapPropertySource)9 HashMap (java.util.HashMap)8 ConcurrentMapCache (org.springframework.cache.concurrent.ConcurrentMapCache)7 MBeanExporter (org.springframework.jmx.export.MBeanExporter)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7 Ignore (org.junit.Ignore)6 Method (java.lang.reflect.Method)5