use of org.springframework.boot.context.event.SpringApplicationEvent in project spring-boot by spring-projects.
the class ApplicationPidFileWriterTests method overridePidFileWithSpring.
@Test
public void overridePidFileWithSpring() throws Exception {
File file = this.temporaryFolder.newFile();
SpringApplicationEvent event = createPreparedEvent("spring.pid.file", file.getAbsolutePath());
ApplicationPidFileWriter listener = new ApplicationPidFileWriter();
listener.onApplicationEvent(event);
assertThat(FileCopyUtils.copyToString(new FileReader(file))).isNotEmpty();
}
use of org.springframework.boot.context.event.SpringApplicationEvent in project spring-boot by spring-projects.
the class ApplicationPidFileWriterTests method tryEnvironmentPreparedEvent.
@Test
public void tryEnvironmentPreparedEvent() throws Exception {
File file = this.temporaryFolder.newFile();
SpringApplicationEvent event = createEnvironmentPreparedEvent("spring.pid.file", file.getAbsolutePath());
ApplicationPidFileWriter listener = new ApplicationPidFileWriter();
listener.onApplicationEvent(event);
assertThat(FileCopyUtils.copyToString(new FileReader(file))).isEmpty();
listener.setTriggerEventType(ApplicationEnvironmentPreparedEvent.class);
listener.onApplicationEvent(event);
assertThat(FileCopyUtils.copyToString(new FileReader(file))).isNotEmpty();
}
use of org.springframework.boot.context.event.SpringApplicationEvent in project spring-boot by spring-projects.
the class ApplicationPidFileWriterTests method tryReadyEvent.
@Test
public void tryReadyEvent() throws Exception {
File file = this.temporaryFolder.newFile();
SpringApplicationEvent event = createReadyEvent("spring.pid.file", file.getAbsolutePath());
ApplicationPidFileWriter listener = new ApplicationPidFileWriter();
listener.onApplicationEvent(event);
assertThat(FileCopyUtils.copyToString(new FileReader(file))).isEmpty();
listener.setTriggerEventType(ApplicationReadyEvent.class);
listener.onApplicationEvent(event);
assertThat(FileCopyUtils.copyToString(new FileReader(file))).isNotEmpty();
}
use of org.springframework.boot.context.event.SpringApplicationEvent in project spring-boot by spring-projects.
the class ApplicationPidFileWriterTests method throwWhenPidFileIsReadOnlyWithSpring.
@Test
public void throwWhenPidFileIsReadOnlyWithSpring() throws Exception {
File file = this.temporaryFolder.newFile();
file.setReadOnly();
SpringApplicationEvent event = createPreparedEvent("spring.pid.fail-on-write-error", "true");
ApplicationPidFileWriter listener = new ApplicationPidFileWriter(file);
this.exception.expect(IllegalStateException.class);
this.exception.expectMessage("Cannot create pid file");
listener.onApplicationEvent(event);
}
use of org.springframework.boot.context.event.SpringApplicationEvent in project spring-boot by spring-projects.
the class SpringApplicationTests method applicationRunnerFailureCausesApplicationFailedEventToBePublished.
@Test
void applicationRunnerFailureCausesApplicationFailedEventToBePublished() throws Exception {
SpringApplication application = new SpringApplication(ExampleConfig.class);
application.setWebApplicationType(WebApplicationType.NONE);
@SuppressWarnings("unchecked") ApplicationListener<SpringApplicationEvent> listener = mock(ApplicationListener.class);
application.addListeners(listener);
ApplicationRunner runner = mock(ApplicationRunner.class);
Exception failure = new Exception();
willThrow(failure).given(runner).run(isA(ApplicationArguments.class));
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));
}
Aggregations