Search in sources :

Example 6 with ConfigurableApplicationContext

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

the class ContextIdApplicationContextInitializerTests method testNameAndPort.

@Test
public void testNameAndPort() {
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
    TestPropertySourceUtils.addInlinedPropertiesToEnvironment(context, "spring.application.name=foo", "PORT=8080");
    this.initializer.initialize(context);
    assertThat(context.getId()).isEqualTo("foo:8080");
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Test(org.junit.Test)

Example 7 with ConfigurableApplicationContext

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

the class ContextIdApplicationContextInitializerTests method testNameAndProfiles.

@Test
public void testNameAndProfiles() {
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
    TestPropertySourceUtils.addInlinedPropertiesToEnvironment(context, "spring.application.name=foo", "spring.profiles.active=spam,bar", "spring.application.index=12");
    this.initializer.initialize(context);
    assertThat(context.getId()).isEqualTo("foo:spam,bar:12");
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Test(org.junit.Test)

Example 8 with ConfigurableApplicationContext

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

the class ContextIdApplicationContextInitializerTests method testCloudFoundry.

@Test
public void testCloudFoundry() {
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
    TestPropertySourceUtils.addInlinedPropertiesToEnvironment(context, "spring.config.name=foo", "PORT=8080", "vcap.application.name=bar", "vcap.application.instance_index=2");
    this.initializer.initialize(context);
    assertThat(context.getId()).isEqualTo("bar:2");
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Test(org.junit.Test)

Example 9 with ConfigurableApplicationContext

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

the class BeanNotOfRequiredTypeFailureAnalyzerTests method createFailure.

private Exception createFailure(Class<?> configuration) {
    ConfigurableApplicationContext context = null;
    try {
        context = new AnnotationConfigApplicationContext(configuration);
    } catch (Exception ex) {
        return ex;
    } finally {
        if (context != null) {
            context.close();
        }
    }
    fail("Expected failure did not occur");
    return null;
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext)

Example 10 with ConfigurableApplicationContext

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

the class ConfigFileApplicationListenerTests method propertySourceAnnotationMultipleLocations.

@Test
public void propertySourceAnnotationMultipleLocations() throws Exception {
    SpringApplication application = new SpringApplication(WithPropertySourceMultipleLocations.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("class path resource " + "[specificlocation.properties]"));
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringApplication(org.springframework.boot.SpringApplication) 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