use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.
the class SpringBootDependencyInjectionTestExecutionListenerTests method prepareFailingTestInstanceShouldPrintReport.
@Test
public void prepareFailingTestInstanceShouldPrintReport() throws Exception {
TestContext testContext = mock(TestContext.class);
given(testContext.getTestInstance()).willThrow(new IllegalStateException());
SpringApplication application = new SpringApplication(Config.class);
application.setWebApplicationType(WebApplicationType.NONE);
ConfigurableApplicationContext applicationContext = application.run();
given(testContext.getApplicationContext()).willReturn(applicationContext);
try {
this.reportListener.prepareTestInstance(testContext);
} catch (IllegalStateException ex) {
// Expected
}
this.out.expect(containsString("AUTO-CONFIGURATION REPORT"));
this.out.expect(containsString("Positive matches"));
this.out.expect(containsString("Negative matches"));
}
use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.
the class ConfigFileApplicationListenerTests method customDefaultProfile.
@Test
public void customDefaultProfile() throws Exception {
SpringApplication application = new SpringApplication(Config.class);
application.setWebApplicationType(WebApplicationType.NONE);
this.context = application.run("--spring.profiles.default=customdefault");
String property = this.context.getEnvironment().getProperty("customdefault");
assertThat(property).isEqualTo("true");
}
use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.
the class ConfigFileApplicationListenerTests method profileCanBeIncludedWithoutAnyBeingActive.
@Test
public void profileCanBeIncludedWithoutAnyBeingActive() throws Exception {
SpringApplication application = new SpringApplication(Config.class);
application.setWebApplicationType(WebApplicationType.NONE);
this.context = application.run("--spring.profiles.include=dev");
String property = this.context.getEnvironment().getProperty("my.property");
assertThat(property).isEqualTo("fromdevpropertiesfile");
}
use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.
the class ConfigFileApplicationListenerTests method validateProfilePrecedence.
private void validateProfilePrecedence(String... profiles) {
ApplicationPreparedEvent event = new ApplicationPreparedEvent(new SpringApplication(), new String[0], new AnnotationConfigApplicationContext());
this.initializer.onApplicationEvent(event);
String log = this.out.toString();
// First make sure that each profile got processed only once
for (String profile : profiles) {
String reason = "Wrong number of occurrences for profile '" + profile + "' --> " + log;
assertThat(StringUtils.countOccurrencesOf(log, createLogForProfile(profile))).as(reason).isEqualTo(1);
}
// Make sure the order of loading is the right one
for (String profile : profiles) {
String line = createLogForProfile(profile);
int index = log.indexOf(line);
assertThat(index).as("Loading profile '" + profile + "' not found in '" + log + "'").isNotEqualTo(-1);
log = log.substring(index + line.length());
}
}
use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.
the class ConfigFileApplicationListenerTests method customDefaultProfileAndActiveFromFile.
@Test
public void customDefaultProfileAndActiveFromFile() throws Exception {
// gh-5998
SpringApplication application = new SpringApplication(Config.class);
application.setWebApplicationType(WebApplicationType.NONE);
this.context = application.run("--spring.config.name=customprofile", "--spring.profiles.default=customdefault");
ConfigurableEnvironment environment = this.context.getEnvironment();
assertThat(environment.containsProperty("customprofile")).isTrue();
assertThat(environment.containsProperty("customprofile-specific")).isTrue();
assertThat(environment.containsProperty("customprofile-customdefault")).isTrue();
assertThat(environment.acceptsProfiles("customdefault")).isTrue();
}
Aggregations