use of org.springframework.boot.context.event.SpringApplicationEvent in project spring-boot by spring-projects.
the class ApplicationPidFileWriterTests method overridePidFileWithSpring.
@Test
void overridePidFileWithSpring() {
File file = new File(this.tempDir, "pid");
SpringApplicationEvent event = createPreparedEvent("spring.pid.file", file.getAbsolutePath());
ApplicationPidFileWriter listener = new ApplicationPidFileWriter();
listener.onApplicationEvent(event);
assertThat(contentOf(file)).isNotEmpty();
}
use of org.springframework.boot.context.event.SpringApplicationEvent in project spring-boot by spring-projects.
the class ApplicationPidFileWriterTests method tryReadyEvent.
@Test
void tryReadyEvent() throws Exception {
File file = new File(this.tempDir, "pid");
file.createNewFile();
SpringApplicationEvent event = createReadyEvent("spring.pid.file", file.getAbsolutePath());
ApplicationPidFileWriter listener = new ApplicationPidFileWriter();
listener.onApplicationEvent(event);
assertThat(contentOf(file)).isEmpty();
listener.setTriggerEventType(ApplicationReadyEvent.class);
listener.onApplicationEvent(event);
assertThat(contentOf(file)).isNotEmpty();
}
use of org.springframework.boot.context.event.SpringApplicationEvent in project spring-boot by spring-projects.
the class SpringApplicationTests method commandLineRunnerFailureCausesApplicationFailedEventToBePublished.
@Test
void commandLineRunnerFailureCausesApplicationFailedEventToBePublished() throws Exception {
SpringApplication application = new SpringApplication(ExampleConfig.class);
application.setWebApplicationType(WebApplicationType.NONE);
@SuppressWarnings("unchecked") ApplicationListener<SpringApplicationEvent> listener = mock(ApplicationListener.class);
application.addListeners(listener);
CommandLineRunner runner = mock(CommandLineRunner.class);
Exception failure = new Exception();
willThrow(failure).given(runner).run();
application.addInitializers((context) -> context.getBeanFactory().registerSingleton("runner", runner));
assertThatIllegalStateException().isThrownBy(application::run).withCause(failure);
then(listener).should().onApplicationEvent(isA(ApplicationStartedEvent.class));
then(listener).should().onApplicationEvent(isA(ApplicationFailedEvent.class));
then(listener).should(never()).onApplicationEvent(isA(ApplicationReadyEvent.class));
}
use of org.springframework.boot.context.event.SpringApplicationEvent in project spring-boot by spring-projects.
the class ApplicationPidFileWriterTests method throwWhenPidFileIsReadOnlyWithSpring.
@Test
void throwWhenPidFileIsReadOnlyWithSpring() throws Exception {
withReadOnlyPidFile((file) -> {
SpringApplicationEvent event = createPreparedEvent("spring.pid.fail-on-write-error", "true");
ApplicationPidFileWriter listener = new ApplicationPidFileWriter(file);
assertThatIllegalStateException().isThrownBy(() -> listener.onApplicationEvent(event)).withMessageContaining("Cannot create pid file");
});
}
use of org.springframework.boot.context.event.SpringApplicationEvent in project spring-boot by spring-projects.
the class ApplicationPidFileWriterTests method tryEnvironmentPreparedEvent.
@Test
void tryEnvironmentPreparedEvent() throws Exception {
File file = new File(this.tempDir, "pid");
file.createNewFile();
SpringApplicationEvent event = createEnvironmentPreparedEvent("spring.pid.file", file.getAbsolutePath());
ApplicationPidFileWriter listener = new ApplicationPidFileWriter();
listener.onApplicationEvent(event);
assertThat(contentOf(file)).isEmpty();
listener.setTriggerEventType(ApplicationEnvironmentPreparedEvent.class);
listener.onApplicationEvent(event);
assertThat(contentOf(file)).isNotEmpty();
}
Aggregations