Search in sources :

Example 11 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project spring-boot by spring-projects.

the class ConfigFileApplicationListenerTests method propertySourceAnnotationWithPlaceholder.

@Test
public void propertySourceAnnotationWithPlaceholder() throws Exception {
    TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, "source.location=specificlocation");
    SpringApplication application = new SpringApplication(WithPropertySourcePlaceholders.class);
    application.setEnvironment(this.environment);
    application.setWebApplicationType(WebApplicationType.NONE);
    ConfigurableApplicationContext context = application.run();
    String property = context.getEnvironment().getProperty("the.property");
    assertThat(property).isEqualTo("fromspecificlocation");
    assertThat(context.getEnvironment()).has(matchingPropertySource("class path resource " + "[specificlocation.properties]"));
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringApplication(org.springframework.boot.SpringApplication) Test(org.junit.Test)

Example 12 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project spring-boot by spring-projects.

the class ConfigFileApplicationListenerTests method propertySourceAnnotation.

@Test
public void propertySourceAnnotation() throws Exception {
    SpringApplication application = new SpringApplication(WithPropertySource.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    ConfigurableApplicationContext context = application.run();
    String property = context.getEnvironment().getProperty("the.property");
    assertThat(property).isEqualTo("fromspecificlocation");
    property = context.getEnvironment().getProperty("my.property");
    assertThat(property).isEqualTo("fromapplicationproperties");
    assertThat(context.getEnvironment()).has(matchingPropertySource("class path resource " + "[specificlocation.properties]"));
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringApplication(org.springframework.boot.SpringApplication) Test(org.junit.Test)

Example 13 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project spring-boot by spring-projects.

the class ConfigFileApplicationListenerTests method propertySourceAnnotationMultipleLocationsAndName.

@Test
public void propertySourceAnnotationMultipleLocationsAndName() throws Exception {
    SpringApplication application = new SpringApplication(WithPropertySourceMultipleLocationsAndName.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    ConfigurableApplicationContext context = application.run();
    String property = context.getEnvironment().getProperty("the.property");
    assertThat(property).isEqualTo("frommorepropertiesfile");
    assertThat(context.getEnvironment()).has(matchingPropertySource("foo"));
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringApplication(org.springframework.boot.SpringApplication) Test(org.junit.Test)

Example 14 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project spring-boot by spring-projects.

the class LoggingApplicationListenerIntegrationTests method loggingSystemRegisteredInTheContext.

@Test
public void loggingSystemRegisteredInTheContext() {
    ConfigurableApplicationContext context = new SpringApplicationBuilder(SampleService.class).web(WebApplicationType.NONE).run();
    try {
        SampleService service = context.getBean(SampleService.class);
        assertThat(service.loggingSystem).isNotNull();
    } finally {
        context.close();
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Test(org.junit.Test)

Example 15 with ConfigurableApplicationContext

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

the class EnableCachingTests method bothSetOnlyResolverIsUsed.

@Test
public void bothSetOnlyResolverIsUsed() {
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(FullCachingConfig.class);
    CacheInterceptor ci = context.getBean(CacheInterceptor.class);
    assertSame(context.getBean("cacheResolver"), ci.getCacheResolver());
    assertSame(context.getBean("keyGenerator"), ci.getKeyGenerator());
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) CacheInterceptor(org.springframework.cache.interceptor.CacheInterceptor) Test(org.junit.Test)

Aggregations

ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)162 Test (org.junit.Test)108 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)42 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)17 ApplicationContext (org.springframework.context.ApplicationContext)15 SpringApplication (org.springframework.boot.SpringApplication)14 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)13 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)12 DataSource (javax.sql.DataSource)8 JmsListenerContainerTestFactory (org.springframework.jms.config.JmsListenerContainerTestFactory)7 MBeanServer (javax.management.MBeanServer)6 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)6 Statement (java.sql.Statement)5 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)5 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)5 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)5 GenericXmlApplicationContext (org.springframework.context.support.GenericXmlApplicationContext)5 ObjectName (javax.management.ObjectName)4 RedisRunner (org.redisson.RedisRunner)4 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)4