Search in sources :

Example 1 with WebEnvironment

use of cn.taketoday.framework.test.context.ApplicationTest.WebEnvironment in project today-infrastructure by TAKETODAY.

the class ApplicationTestContextBootstrapper 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)) {
        ApplicationType webApplicationType = getApplicationType(mergedConfig);
        if (webApplicationType == ApplicationType.SERVLET_WEB && (webEnvironment.isEmbedded() || webEnvironment == WebEnvironment.MOCK)) {
            mergedConfig = new WebMergedContextConfiguration(mergedConfig, determineResourceBasePath(mergedConfig));
        } else if (webApplicationType == ApplicationType.REACTIVE_WEB && (webEnvironment.isEmbedded() || webEnvironment == WebEnvironment.MOCK)) {
            return new ReactiveWebMergedContextConfiguration(mergedConfig);
        }
    }
    return mergedConfig;
}
Also used : WebMergedContextConfiguration(cn.taketoday.test.context.web.WebMergedContextConfiguration) ApplicationType(cn.taketoday.framework.ApplicationType) WebEnvironment(cn.taketoday.framework.test.context.ApplicationTest.WebEnvironment)

Example 2 with WebEnvironment

use of cn.taketoday.framework.test.context.ApplicationTest.WebEnvironment in project today-infrastructure by TAKETODAY.

the class ApplicationTestContextBootstrapper method buildTestContext.

@Override
public TestContext buildTestContext() {
    TestContext context = super.buildTestContext();
    verifyConfiguration(context.getTestClass());
    WebEnvironment webEnvironment = getWebEnvironment(context.getTestClass());
    if (webEnvironment == WebEnvironment.MOCK && deduceWebApplicationType() == ApplicationType.SERVLET_WEB) {
        context.setAttribute(ACTIVATE_SERVLET_LISTENER, true);
    } else if (webEnvironment != null && webEnvironment.isEmbedded()) {
        context.setAttribute(ACTIVATE_SERVLET_LISTENER, false);
    }
    return context;
}
Also used : WebEnvironment(cn.taketoday.framework.test.context.ApplicationTest.WebEnvironment) TestContext(cn.taketoday.test.context.TestContext)

Example 3 with WebEnvironment

use of cn.taketoday.framework.test.context.ApplicationTest.WebEnvironment in project today-framework by TAKETODAY.

the class ApplicationTestContextBootstrapper method buildTestContext.

@Override
public TestContext buildTestContext() {
    TestContext context = super.buildTestContext();
    verifyConfiguration(context.getTestClass());
    WebEnvironment webEnvironment = getWebEnvironment(context.getTestClass());
    if (webEnvironment == WebEnvironment.MOCK && deduceWebApplicationType() == ApplicationType.SERVLET_WEB) {
        context.setAttribute(ACTIVATE_SERVLET_LISTENER, true);
    } else if (webEnvironment != null && webEnvironment.isEmbedded()) {
        context.setAttribute(ACTIVATE_SERVLET_LISTENER, false);
    }
    return context;
}
Also used : WebEnvironment(cn.taketoday.framework.test.context.ApplicationTest.WebEnvironment) TestContext(cn.taketoday.test.context.TestContext)

Example 4 with WebEnvironment

use of cn.taketoday.framework.test.context.ApplicationTest.WebEnvironment in project today-framework by TAKETODAY.

the class ApplicationTestContextBootstrapper 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)) {
        ApplicationType webApplicationType = getApplicationType(mergedConfig);
        if (webApplicationType == ApplicationType.SERVLET_WEB && (webEnvironment.isEmbedded() || webEnvironment == WebEnvironment.MOCK)) {
            mergedConfig = new WebMergedContextConfiguration(mergedConfig, determineResourceBasePath(mergedConfig));
        } else if (webApplicationType == ApplicationType.REACTIVE_WEB && (webEnvironment.isEmbedded() || webEnvironment == WebEnvironment.MOCK)) {
            return new ReactiveWebMergedContextConfiguration(mergedConfig);
        }
    }
    return mergedConfig;
}
Also used : WebMergedContextConfiguration(cn.taketoday.test.context.web.WebMergedContextConfiguration) ApplicationType(cn.taketoday.framework.ApplicationType) WebEnvironment(cn.taketoday.framework.test.context.ApplicationTest.WebEnvironment)

Aggregations

WebEnvironment (cn.taketoday.framework.test.context.ApplicationTest.WebEnvironment)4 ApplicationType (cn.taketoday.framework.ApplicationType)2 TestContext (cn.taketoday.test.context.TestContext)2 WebMergedContextConfiguration (cn.taketoday.test.context.web.WebMergedContextConfiguration)2