use of org.springframework.boot.context.event.ApplicationPreparedEvent 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.context.event.ApplicationPreparedEvent in project spring-boot by spring-projects.
the class RestartApplicationListenerTests method testInitialize.
private void testInitialize(boolean failed) {
Restarter.clearInstance();
RestartApplicationListener listener = new RestartApplicationListener();
SpringApplication application = new SpringApplication();
ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
listener.onApplicationEvent(new ApplicationStartingEvent(application, ARGS));
assertThat(Restarter.getInstance()).isNotEqualTo(nullValue());
assertThat(Restarter.getInstance().isFinished()).isFalse();
listener.onApplicationEvent(new ApplicationPreparedEvent(application, ARGS, context));
if (failed) {
listener.onApplicationEvent(new ApplicationFailedEvent(application, ARGS, context, new RuntimeException()));
} else {
listener.onApplicationEvent(new ApplicationReadyEvent(application, ARGS, context));
}
}
use of org.springframework.boot.context.event.ApplicationPreparedEvent 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());
}
}
Aggregations