use of cn.taketoday.test.context.web.WebMergedContextConfiguration 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;
}
use of cn.taketoday.test.context.web.WebMergedContextConfiguration in project today-infrastructure by TAKETODAY.
the class BootstrapTestUtilsMergedConfigTests method buildMergedConfigWithAtWebAppConfigurationWithAnnotationAndClassesOnSuperclass.
/**
* Introduced to investigate claims made in a discussion on
* <a href="https://stackoverflow.com/questions/24725438/what-could-cause-a-class-implementing-applicationlistenercontextrefreshedevent">Stack Overflow</a>.
*/
@Test
void buildMergedConfigWithAtWebAppConfigurationWithAnnotationAndClassesOnSuperclass() {
Class<?> webTestClass = WebClassesFoo.class;
Class<?> standardTestClass = ClassesFoo.class;
WebMergedContextConfiguration webMergedConfig = (WebMergedContextConfiguration) buildMergedContextConfiguration(webTestClass);
MergedContextConfiguration standardMergedConfig = buildMergedContextConfiguration(standardTestClass);
assertThat(webMergedConfig).isEqualTo(webMergedConfig);
assertThat(standardMergedConfig).isEqualTo(standardMergedConfig);
assertThat(webMergedConfig).isNotEqualTo(standardMergedConfig);
assertThat(standardMergedConfig).isNotEqualTo(webMergedConfig);
assertMergedConfig(webMergedConfig, webTestClass, EMPTY_STRING_ARRAY, array(FooConfig.class), WebDelegatingSmartContextLoader.class);
assertMergedConfig(standardMergedConfig, standardTestClass, EMPTY_STRING_ARRAY, array(FooConfig.class), DelegatingSmartContextLoader.class);
}
use of cn.taketoday.test.context.web.WebMergedContextConfiguration in project today-framework by TAKETODAY.
the class BootstrapTestUtilsMergedConfigTests method buildMergedConfigWithAtWebAppConfigurationWithAnnotationAndClassesOnSuperclass.
/**
* Introduced to investigate claims made in a discussion on
* <a href="https://stackoverflow.com/questions/24725438/what-could-cause-a-class-implementing-applicationlistenercontextrefreshedevent">Stack Overflow</a>.
*/
@Test
void buildMergedConfigWithAtWebAppConfigurationWithAnnotationAndClassesOnSuperclass() {
Class<?> webTestClass = WebClassesFoo.class;
Class<?> standardTestClass = ClassesFoo.class;
WebMergedContextConfiguration webMergedConfig = (WebMergedContextConfiguration) buildMergedContextConfiguration(webTestClass);
MergedContextConfiguration standardMergedConfig = buildMergedContextConfiguration(standardTestClass);
assertThat(webMergedConfig).isEqualTo(webMergedConfig);
assertThat(standardMergedConfig).isEqualTo(standardMergedConfig);
assertThat(webMergedConfig).isNotEqualTo(standardMergedConfig);
assertThat(standardMergedConfig).isNotEqualTo(webMergedConfig);
assertMergedConfig(webMergedConfig, webTestClass, EMPTY_STRING_ARRAY, array(FooConfig.class), WebDelegatingSmartContextLoader.class);
assertMergedConfig(standardMergedConfig, standardTestClass, EMPTY_STRING_ARRAY, array(FooConfig.class), DelegatingSmartContextLoader.class);
}
use of cn.taketoday.test.context.web.WebMergedContextConfiguration in project today-framework by TAKETODAY.
the class ApplicationContextLoader method loadContext.
@Override
public ApplicationContext loadContext(MergedContextConfiguration config) throws Exception {
Class<?>[] configClasses = config.getClasses();
String[] configLocations = config.getLocations();
Assert.state(ObjectUtils.isNotEmpty(configClasses) || ObjectUtils.isNotEmpty(configLocations), () -> "No configuration classes or locations found in @SpringApplicationConfiguration. " + "For default configuration detection to work you need Spring 4.0.3 or better (found " + cn.taketoday.lang.Version.get() + ").");
Application 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.setApplicationType(ApplicationType.SERVLET_WEB);
if (!isEmbeddedWebEnvironment(config)) {
new WebConfigurer().configure(config, application, initializers);
}
} else if (config instanceof ReactiveWebMergedContextConfiguration) {
application.setApplicationType(ApplicationType.REACTIVE_WEB);
if (!isEmbeddedWebEnvironment(config)) {
application.setApplicationContextFactory(ApplicationContextFactory.from(GenericReactiveWebApplicationContext::new));
}
} else {
application.setApplicationType(ApplicationType.NONE_WEB);
}
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 = ApplicationTestArgs.get(config.getContextCustomizers());
return application.run(args);
}
use of cn.taketoday.test.context.web.WebMergedContextConfiguration 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;
}
Aggregations