use of org.springframework.boot.SpringApplication 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.boot.SpringApplication in project spring-boot by spring-projects.
the class AnsiOutputApplicationListenerTests method enabled.
@Test
void enabled() {
SpringApplication application = new SpringApplication(Config.class);
application.setWebApplicationType(WebApplicationType.NONE);
Map<String, Object> props = new HashMap<>();
props.put("spring.output.ansi.enabled", "ALWAYS");
application.setDefaultProperties(props);
this.context = application.run();
assertThat(AnsiOutputEnabledValue.get()).isEqualTo(Enabled.ALWAYS);
}
use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.
the class AnsiOutputApplicationListenerTests method disabled.
@Test
void disabled() {
SpringApplication application = new SpringApplication(Config.class);
application.setWebApplicationType(WebApplicationType.NONE);
Map<String, Object> props = new HashMap<>();
props.put("spring.output.ansi.enabled", "never");
application.setDefaultProperties(props);
this.context = application.run();
assertThat(AnsiOutputEnabledValue.get()).isEqualTo(Enabled.NEVER);
}
use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.
the class ApplicationPidFileWriterTests method createPreparedEvent.
private SpringApplicationEvent createPreparedEvent(String propName, String propValue) {
ConfigurableEnvironment environment = createEnvironment(propName, propValue);
ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
given(context.getEnvironment()).willReturn(environment);
return new ApplicationPreparedEvent(new SpringApplication(), new String[] {}, context);
}
use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.
the class ConfigDataEnvironmentPostProcessorBootstrapContextIntegrationTests method setup.
@BeforeEach
void setup() {
this.application = new SpringApplication(Config.class);
this.application.setWebApplicationType(WebApplicationType.NONE);
}
Aggregations