Search in sources :

Example 1 with GenericReactiveWebApplicationContext

use of org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext in project spring-boot by spring-projects.

the class SpringBootContextLoader method loadContext.

@Override
public ApplicationContext loadContext(MergedContextConfiguration config) throws Exception {
    Class<?>[] configClasses = config.getClasses();
    String[] configLocations = config.getLocations();
    Assert.state(!ObjectUtils.isEmpty(configClasses) || !ObjectUtils.isEmpty(configLocations), () -> "No configuration classes or locations found in @SpringApplicationConfiguration. " + "For default configuration detection to work you need Spring 4.0.3 or better (found " + SpringVersion.getVersion() + ").");
    SpringApplication application = getSpringApplication();
    application.setMainApplicationClass(config.getTestClass());
    application.addPrimarySources(Arrays.asList(configClasses));
    application.getSources().addAll(Arrays.asList(configLocations));
    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)) {
            application.setApplicationContextFactory(ApplicationContextFactory.of(GenericReactiveWebApplicationContext::new));
        }
    } else {
        application.setWebApplicationType(WebApplicationType.NONE);
    }
    application.setInitializers(initializers);
    ConfigurableEnvironment environment = getEnvironment();
    if (environment != null) {
        prepareEnvironment(config, application, environment, false);
        application.setEnvironment(environment);
    } else {
        application.addListeners(new PrepareEnvironmentListener(config));
    }
    String[] args = SpringBootTestArgs.get(config.getContextCustomizers());
    return application.run(args);
}
Also used : GenericReactiveWebApplicationContext(org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext) SpringApplication(org.springframework.boot.SpringApplication) WebMergedContextConfiguration(org.springframework.test.context.web.WebMergedContextConfiguration) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) ServletContextApplicationContextInitializer(org.springframework.boot.web.servlet.support.ServletContextApplicationContextInitializer) ApplicationContextInitializer(org.springframework.context.ApplicationContextInitializer)

Example 2 with GenericReactiveWebApplicationContext

use of org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext in project spring-boot by spring-projects.

the class ConditionalOnNotWebApplicationTests method testNotWebApplicationWithReactiveContext.

@Test
public void testNotWebApplicationWithReactiveContext() {
    GenericReactiveWebApplicationContext ctx = new GenericReactiveWebApplicationContext();
    ctx.register(ReactiveApplicationConfig.class, NotWebApplicationConfiguration.class);
    ctx.refresh();
    this.context = ctx;
    assertThat(this.context.getBeansOfType(String.class)).isEmpty();
}
Also used : GenericReactiveWebApplicationContext(org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext) Test(org.junit.Test)

Example 3 with GenericReactiveWebApplicationContext

use of org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext in project spring-boot by spring-projects.

the class HttpHandlerAutoConfigurationTests method load.

private void load(Class<?> config, String... environment) {
    this.context = new GenericReactiveWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, environment);
    if (this.context != null) {
        this.context.register(config);
    }
    this.context.register(HttpHandlerAutoConfiguration.class);
    this.context.refresh();
}
Also used : GenericReactiveWebApplicationContext(org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext)

Example 4 with GenericReactiveWebApplicationContext

use of org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext in project spring-boot by spring-projects.

the class WebFluxAnnotationAutoConfigurationTests method load.

private void load(Class<?> config, String... environment) {
    this.context = new GenericReactiveWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, environment);
    if (config != null) {
        this.context.register(config);
    }
    this.context.register(BaseConfiguration.class);
    this.context.refresh();
}
Also used : GenericReactiveWebApplicationContext(org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext)

Aggregations

GenericReactiveWebApplicationContext (org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext)4 Test (org.junit.Test)1 SpringApplication (org.springframework.boot.SpringApplication)1 ServletContextApplicationContextInitializer (org.springframework.boot.web.servlet.support.ServletContextApplicationContextInitializer)1 ApplicationContextInitializer (org.springframework.context.ApplicationContextInitializer)1 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)1 WebMergedContextConfiguration (org.springframework.test.context.web.WebMergedContextConfiguration)1