Search in sources :

Example 66 with SpringApplication

use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.

the class LoggingApplicationListenerTests method init.

@BeforeEach
void init(CapturedOutput output) throws IOException {
    this.systemPropertyNames = new HashSet<>(System.getProperties().keySet());
    this.output = output;
    this.logFile = new File(this.tempDir.toFile(), "foo.log");
    LogManager.getLogManager().readConfiguration(JavaLoggingSystem.class.getResourceAsStream("logging.properties"));
    multicastEvent(new ApplicationStartingEvent(this.bootstrapContext, new SpringApplication(), NO_ARGS));
    new File(this.tempDir.toFile(), "spring.log").delete();
    ConfigurableEnvironment environment = this.context.getEnvironment();
    ConfigurationPropertySources.attach(environment);
}
Also used : JavaLoggingSystem(org.springframework.boot.logging.java.JavaLoggingSystem) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) SpringApplication(org.springframework.boot.SpringApplication) ApplicationStartingEvent(org.springframework.boot.context.event.ApplicationStartingEvent) LogFile(org.springframework.boot.logging.LogFile) File(java.io.File) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 67 with SpringApplication

use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.

the class StartupTimeMetricsListenerTests method metricRecordedWithoutMainAppClassTag.

@Test
void metricRecordedWithoutMainAppClassTag() {
    SpringApplication application = mock(SpringApplication.class);
    this.listener.onApplicationEvent(new ApplicationStartedEvent(application, null, null, Duration.ofSeconds(2)));
    TimeGauge applicationStartedGague = this.registry.find("application.started.time").timeGauge();
    assertThat(applicationStartedGague).isNotNull();
    assertThat(applicationStartedGague.getId().getTags()).isEmpty();
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) ApplicationStartedEvent(org.springframework.boot.context.event.ApplicationStartedEvent) TimeGauge(io.micrometer.core.instrument.TimeGauge) Test(org.junit.jupiter.api.Test)

Example 68 with SpringApplication

use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.

the class ConditionEvaluationReportLoggingListenerTests method noErrorIfNotInitialized.

@Test
void noErrorIfNotInitialized(CapturedOutput output) {
    this.initializer.onApplicationEvent(new ApplicationFailedEvent(new SpringApplication(), new String[0], null, new RuntimeException("Planned")));
    assertThat(output).contains("Unable to provide the conditions report");
}
Also used : ApplicationFailedEvent(org.springframework.boot.context.event.ApplicationFailedEvent) SpringApplication(org.springframework.boot.SpringApplication) Test(org.junit.jupiter.api.Test)

Example 69 with SpringApplication

use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.

the class ConditionEvaluationReportLoggingListenerTests method logsDebugOnError.

@Test
void logsDebugOnError(CapturedOutput output) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    this.initializer.initialize(context);
    context.register(ErrorConfig.class);
    assertThatExceptionOfType(Exception.class).isThrownBy(context::refresh).satisfies((ex) -> withDebugLogging(() -> this.initializer.onApplicationEvent(new ApplicationFailedEvent(new SpringApplication(), new String[0], context, ex))));
    assertThat(output).contains("CONDITIONS EVALUATION REPORT");
}
Also used : ApplicationFailedEvent(org.springframework.boot.context.event.ApplicationFailedEvent) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) SpringApplication(org.springframework.boot.SpringApplication) Test(org.junit.jupiter.api.Test)

Example 70 with SpringApplication

use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.

the class RemoteUrlPropertyExtractorTests method doTest.

private ApplicationContext doTest(String... args) {
    SpringApplication application = new SpringApplication(Config.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    application.addListeners(new RemoteUrlPropertyExtractor());
    return application.run(args);
}
Also used : SpringApplication(org.springframework.boot.SpringApplication)

Aggregations

SpringApplication (org.springframework.boot.SpringApplication)205 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)56 Test (org.junit.Test)43 Test (org.junit.jupiter.api.Test)39 Environment (org.springframework.core.env.Environment)21 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)15 HashMap (java.util.HashMap)9 ApplicationFailedEvent (org.springframework.boot.context.event.ApplicationFailedEvent)9 ApplicationReadyEvent (org.springframework.boot.context.event.ApplicationReadyEvent)9 ApplicationStartingEvent (org.springframework.boot.context.event.ApplicationStartingEvent)9 File (java.io.File)7 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)7 BeforeEach (org.junit.jupiter.api.BeforeEach)6 JavaLoggingSystem (org.springframework.boot.logging.java.JavaLoggingSystem)6 ApplicationContext (org.springframework.context.ApplicationContext)6 ApplicationPreparedEvent (org.springframework.boot.context.event.ApplicationPreparedEvent)5 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)5 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)4 JoranException (ch.qos.logback.core.joran.spi.JoranException)3 IOException (java.io.IOException)3