Search in sources :

Example 21 with ConfigurableApplicationContext

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

the class DevToolsEmbeddedDataSourceAutoConfigurationTests method autoConfiguredDataSourceIsNotShutdown.

@Test
public void autoConfiguredDataSourceIsNotShutdown() throws SQLException {
    ConfigurableApplicationContext context = createContext(DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class);
    Statement statement = configureDataSourceBehaviour(context.getBean(DataSource.class));
    context.close();
    verify(statement, times(0)).execute("SHUTDOWN");
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Statement(java.sql.Statement) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 22 with ConfigurableApplicationContext

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

the class DevToolsPooledDataSourceAutoConfigurationTests method autoConfiguredInMemoryDataSourceIsShutdown.

@Test
public void autoConfiguredInMemoryDataSourceIsShutdown() throws SQLException {
    ConfigurableApplicationContext context = createContext(DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class);
    Statement statement = configureDataSourceBehaviour(context.getBean(DataSource.class));
    context.close();
    verify(statement).execute("SHUTDOWN");
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Statement(java.sql.Statement) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 23 with ConfigurableApplicationContext

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

the class DevToolsPooledDataSourceAutoConfigurationTests method autoConfiguredExternalDataSourceIsNotShutdown.

@Test
public void autoConfiguredExternalDataSourceIsNotShutdown() throws SQLException {
    ConfigurableApplicationContext context = createContext("org.postgresql.Driver", DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class);
    Statement statement = configureDataSourceBehaviour(context.getBean(DataSource.class));
    context.close();
    verify(statement, times(0)).execute("SHUTDOWN");
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Statement(java.sql.Statement) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 24 with ConfigurableApplicationContext

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

the class SpringBootContextLoader method loadContext.

@Override
public ApplicationContext loadContext(MergedContextConfiguration config) throws Exception {
    SpringApplication application = getSpringApplication();
    application.setMainApplicationClass(config.getTestClass());
    application.setSources(getSources(config));
    ConfigurableEnvironment environment = new StandardEnvironment();
    if (!ObjectUtils.isEmpty(config.getActiveProfiles())) {
        setActiveProfiles(environment, config.getActiveProfiles());
    }
    TestPropertySourceUtils.addPropertiesFilesToEnvironment(environment, application.getResourceLoader() == null ? new DefaultResourceLoader(getClass().getClassLoader()) : application.getResourceLoader(), config.getPropertySourceLocations());
    TestPropertySourceUtils.addInlinedPropertiesToEnvironment(environment, getInlinedProperties(config));
    application.setEnvironment(environment);
    List<ApplicationContextInitializer<?>> initializers = getInitializers(config, application);
    if (config instanceof WebMergedContextConfiguration) {
        application.setWebApplicationType(WebApplicationType.SERVLET);
        if (!isEmbeddedWebEnvironment(config)) {
            new WebConfigurer().configure(config, application, initializers);
        }
    } else if (config instanceof ReactiveWebMergedContextConfiguration) {
        application.setWebApplicationType(WebApplicationType.REACTIVE);
        if (!isEmbeddedWebEnvironment(config)) {
            new ReactiveWebConfigurer().configure(application);
        }
    } else {
        application.setWebApplicationType(WebApplicationType.NONE);
    }
    application.setInitializers(initializers);
    ConfigurableApplicationContext context = application.run();
    return context;
}
Also used : WebMergedContextConfiguration(org.springframework.test.context.web.WebMergedContextConfiguration) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) SpringApplication(org.springframework.boot.SpringApplication) ServletContextApplicationContextInitializer(org.springframework.boot.web.servlet.support.ServletContextApplicationContextInitializer) ApplicationContextInitializer(org.springframework.context.ApplicationContextInitializer) StandardEnvironment(org.springframework.core.env.StandardEnvironment) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader)

Example 25 with ConfigurableApplicationContext

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

the class SampleWebSocketsApplicationTests method echoEndpoint.

@Test
public void echoEndpoint() throws Exception {
    ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class).properties("websocket.uri:ws://localhost:" + this.port + "/echo/websocket").run("--spring.main.web_environment=false");
    long count = context.getBean(ClientConfiguration.class).latch.getCount();
    AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload;
    context.close();
    assertThat(count).isEqualTo(0);
    assertThat(messagePayloadReference.get()).isEqualTo("Did you say \"Hello world!\"?");
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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