use of org.springframework.test.context.web.WebMergedContextConfiguration 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);
}
use of org.springframework.test.context.web.WebMergedContextConfiguration 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;
}
use of org.springframework.test.context.web.WebMergedContextConfiguration in project spring-framework by spring-projects.
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);
}
Aggregations