Search in sources :

Example 1 with WebEnvironment

use of org.springframework.boot.test.context.SpringBootTest.WebEnvironment in project spring-boot by spring-projects.

the class SpringBootTestContextBootstrapper method processMergedContextConfiguration.

@Override
protected MergedContextConfiguration processMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
    Class<?>[] classes = getOrFindConfigurationClasses(mergedConfig);
    List<String> propertySourceProperties = getAndProcessPropertySourceProperties(mergedConfig);
    mergedConfig = createModifiedConfig(mergedConfig, classes, StringUtils.toStringArray(propertySourceProperties));
    WebEnvironment webEnvironment = getWebEnvironment(mergedConfig.getTestClass());
    if (webEnvironment != null && isWebEnvironmentSupported(mergedConfig)) {
        WebApplicationType webApplicationType = getWebApplicationType(mergedConfig);
        if (webApplicationType == WebApplicationType.SERVLET && (webEnvironment.isEmbedded() || webEnvironment == WebEnvironment.MOCK)) {
            mergedConfig = new WebMergedContextConfiguration(mergedConfig, determineResourceBasePath(mergedConfig));
        } else if (webApplicationType == WebApplicationType.REACTIVE && (webEnvironment.isEmbedded() || webEnvironment == WebEnvironment.MOCK)) {
            return new ReactiveWebMergedContextConfiguration(mergedConfig);
        }
    }
    return mergedConfig;
}
Also used : WebMergedContextConfiguration(org.springframework.test.context.web.WebMergedContextConfiguration) WebEnvironment(org.springframework.boot.test.context.SpringBootTest.WebEnvironment) WebApplicationType(org.springframework.boot.WebApplicationType)

Example 2 with WebEnvironment

use of org.springframework.boot.test.context.SpringBootTest.WebEnvironment in project spring-boot by spring-projects.

the class SpringBootTestContextBootstrapper method buildTestContext.

@Override
public TestContext buildTestContext() {
    TestContext context = super.buildTestContext();
    verifyConfiguration(context.getTestClass());
    WebEnvironment webEnvironment = getWebEnvironment(context.getTestClass());
    if (webEnvironment == WebEnvironment.MOCK && deduceWebApplicationType() == WebApplicationType.SERVLET) {
        context.setAttribute(ACTIVATE_SERVLET_LISTENER, true);
    } else if (webEnvironment != null && webEnvironment.isEmbedded()) {
        context.setAttribute(ACTIVATE_SERVLET_LISTENER, false);
    }
    return context;
}
Also used : WebEnvironment(org.springframework.boot.test.context.SpringBootTest.WebEnvironment) TestContext(org.springframework.test.context.TestContext)

Aggregations

WebEnvironment (org.springframework.boot.test.context.SpringBootTest.WebEnvironment)2 WebApplicationType (org.springframework.boot.WebApplicationType)1 TestContext (org.springframework.test.context.TestContext)1 WebMergedContextConfiguration (org.springframework.test.context.web.WebMergedContextConfiguration)1