Search in sources :

Example 6 with ApplicationStartingEvent

use of org.springframework.boot.context.event.ApplicationStartingEvent in project spring-boot by spring-projects.

the class ApplicationPidFileWriterTests method withNoEnvironment.

@Test
public void withNoEnvironment() throws Exception {
    File file = this.temporaryFolder.newFile();
    ApplicationPidFileWriter listener = new ApplicationPidFileWriter(file);
    listener.setTriggerEventType(ApplicationStartingEvent.class);
    listener.onApplicationEvent(new ApplicationStartingEvent(new SpringApplication(), new String[] {}));
    assertThat(FileCopyUtils.copyToString(new FileReader(file))).isNotEmpty();
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) FileReader(java.io.FileReader) ApplicationStartingEvent(org.springframework.boot.context.event.ApplicationStartingEvent) File(java.io.File) Test(org.junit.Test)

Example 7 with ApplicationStartingEvent

use of org.springframework.boot.context.event.ApplicationStartingEvent 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));
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationFailedEvent(org.springframework.boot.context.event.ApplicationFailedEvent) SpringApplication(org.springframework.boot.SpringApplication) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) ApplicationPreparedEvent(org.springframework.boot.context.event.ApplicationPreparedEvent) ApplicationStartingEvent(org.springframework.boot.context.event.ApplicationStartingEvent)

Example 8 with ApplicationStartingEvent

use of org.springframework.boot.context.event.ApplicationStartingEvent in project spring-boot by spring-projects.

the class LoggingApplicationListenerTests method parseArgsDoesntReplace.

@Test
public void parseArgsDoesntReplace() throws Exception {
    this.initializer.setSpringBootLogging(LogLevel.ERROR);
    this.initializer.setParseArgs(false);
    multicastEvent(new ApplicationStartingEvent(this.springApplication, new String[] { "--debug" }));
    this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
    this.logger.debug("testatdebug");
    assertThat(this.outputCapture.toString()).doesNotContain("testatdebug");
}
Also used : ApplicationStartingEvent(org.springframework.boot.context.event.ApplicationStartingEvent) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 9 with ApplicationStartingEvent

use of org.springframework.boot.context.event.ApplicationStartingEvent in project spring-boot by spring-projects.

the class LoggingApplicationListenerTests method init.

@Before
public void init() throws SecurityException, IOException {
    LogManager.getLogManager().readConfiguration(JavaLoggingSystem.class.getResourceAsStream("logging.properties"));
    multicastEvent(new ApplicationStartingEvent(new SpringApplication(), NO_ARGS));
    new File("target/foo.log").delete();
    new File(tmpDir() + "/spring.log").delete();
}
Also used : JavaLoggingSystem(org.springframework.boot.logging.java.JavaLoggingSystem) SpringApplication(org.springframework.boot.SpringApplication) ApplicationStartingEvent(org.springframework.boot.context.event.ApplicationStartingEvent) LogFile(org.springframework.boot.logging.LogFile) File(java.io.File) Before(org.junit.Before)

Example 10 with ApplicationStartingEvent

use of org.springframework.boot.context.event.ApplicationStartingEvent in project spring-boot by spring-projects.

the class LoggingApplicationListenerTests method closingContextCleansUpLoggingSystem.

@Test
public void closingContextCleansUpLoggingSystem() {
    System.setProperty(LoggingSystem.SYSTEM_PROPERTY, TestCleanupLoggingSystem.class.getName());
    multicastEvent(new ApplicationStartingEvent(this.springApplication, new String[0]));
    TestCleanupLoggingSystem loggingSystem = (TestCleanupLoggingSystem) ReflectionTestUtils.getField(this.initializer, "loggingSystem");
    assertThat(loggingSystem.cleanedUp).isFalse();
    multicastEvent(new ContextClosedEvent(this.context));
    assertThat(loggingSystem.cleanedUp).isTrue();
}
Also used : ApplicationStartingEvent(org.springframework.boot.context.event.ApplicationStartingEvent) Matchers.containsString(org.hamcrest.Matchers.containsString) ContextClosedEvent(org.springframework.context.event.ContextClosedEvent) Test(org.junit.Test)

Aggregations

ApplicationStartingEvent (org.springframework.boot.context.event.ApplicationStartingEvent)10 Test (org.junit.Test)8 SpringApplication (org.springframework.boot.SpringApplication)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 JavaLoggingSystem (org.springframework.boot.logging.java.JavaLoggingSystem)3 File (java.io.File)2 ApplicationFailedEvent (org.springframework.boot.context.event.ApplicationFailedEvent)2 AbstractLoggingSystem (org.springframework.boot.logging.AbstractLoggingSystem)2 LoggingSystem (org.springframework.boot.logging.LoggingSystem)2 ContextClosedEvent (org.springframework.context.event.ContextClosedEvent)2 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)2 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 Before (org.junit.Before)1 ExpectedException (org.junit.rules.ExpectedException)1 Logger (org.slf4j.Logger)1 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)1 ApplicationPreparedEvent (org.springframework.boot.context.event.ApplicationPreparedEvent)1 ApplicationReadyEvent (org.springframework.boot.context.event.ApplicationReadyEvent)1 LogFile (org.springframework.boot.logging.LogFile)1