Search in sources :

Example 1 with SpringApplication

use of org.springframework.boot.SpringApplication in project logback-access-spring-boot-starter by akihyro.

the class AbstractMainConfigurationFileInvalidTest method logbackAccessConfigurationExceptionWhereMainConfigurationFileIsInvalid.

/**
     * Tests a Logback-access configuration exception in the case where the main configuration file is invalid.
     */
@Test
public void logbackAccessConfigurationExceptionWhereMainConfigurationFileIsInvalid() {
    Map<String, Object> properties = new HashMap<>();
    properties.put("server.port", findAvailableTcpPort());
    SpringApplication application = new SpringApplication(contextConfiguration);
    application.setDefaultProperties(properties);
    Throwable throwable = catchThrowable(application::run);
    Optional<LogbackAccessConfigurationException> exc = findLogbackAccessConfigurationException(throwable);
    assertThat(exc).hasValueSatisfying(value -> assertThat(value).hasMessageStartingWith("Could not configure Logback-access:").hasMessageContaining("config=[classpath:logback-access.xml]").hasCauseInstanceOf(JoranException.class));
}
Also used : HashMap(java.util.HashMap) JoranException(ch.qos.logback.core.joran.spi.JoranException) SpringApplication(org.springframework.boot.SpringApplication) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.Test)

Example 2 with SpringApplication

use of org.springframework.boot.SpringApplication in project logback-access-spring-boot-starter by akihyro.

the class AbstractTestConfigurationFileInvalidTest method logbackAccessConfigurationExceptionWhereTestConfigurationFileIsInvalid.

/**
     * Tests a Logback-access configuration exception in the case where the test configuration file is invalid.
     */
@Test
public void logbackAccessConfigurationExceptionWhereTestConfigurationFileIsInvalid() {
    Map<String, Object> properties = new HashMap<>();
    properties.put("server.port", findAvailableTcpPort());
    SpringApplication application = new SpringApplication(contextConfiguration);
    application.setDefaultProperties(properties);
    Throwable throwable = catchThrowable(application::run);
    Optional<LogbackAccessConfigurationException> exc = findLogbackAccessConfigurationException(throwable);
    assertThat(exc).hasValueSatisfying(value -> assertThat(value).hasMessageStartingWith("Could not configure Logback-access:").hasMessageContaining("config=[classpath:logback-access-test.xml]").hasCauseInstanceOf(JoranException.class));
}
Also used : HashMap(java.util.HashMap) JoranException(ch.qos.logback.core.joran.spi.JoranException) SpringApplication(org.springframework.boot.SpringApplication) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.Test)

Example 3 with SpringApplication

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

the class AutoConfigurationReportLoggingInitializerTests method logsInfoOnErrorIfDebugDisabled.

@Test
public void logsInfoOnErrorIfDebugDisabled() {
    setupLogging(false, true);
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    this.initializer.initialize(context);
    context.register(ErrorConfig.class);
    try {
        context.refresh();
        fail("Did not error");
    } catch (Exception ex) {
        this.initializer.onApplicationEvent(new ApplicationFailedEvent(new SpringApplication(), new String[0], context, ex));
    }
    assertThat(this.debugLog.size()).isEqualTo(0);
    assertThat(this.infoLog.size()).isNotEqualTo(0);
}
Also used : ApplicationFailedEvent(org.springframework.boot.context.event.ApplicationFailedEvent) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) SpringApplication(org.springframework.boot.SpringApplication) LogConfigurationException(org.apache.commons.logging.LogConfigurationException) Test(org.junit.Test)

Example 4 with SpringApplication

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

the class LoggingApplicationListenerTests method shutdownHookIsNotRegisteredByDefault.

@Test
public void shutdownHookIsNotRegisteredByDefault() throws Exception {
    TestLoggingApplicationListener listener = new TestLoggingApplicationListener();
    System.setProperty(LoggingSystem.class.getName(), TestShutdownHandlerLoggingSystem.class.getName());
    multicastEvent(listener, new ApplicationStartingEvent(new SpringApplication(), NO_ARGS));
    listener.initialize(this.context.getEnvironment(), this.context.getClassLoader());
    assertThat(listener.shutdownHook).isNull();
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) ApplicationStartingEvent(org.springframework.boot.context.event.ApplicationStartingEvent) LoggingSystem(org.springframework.boot.logging.LoggingSystem) JavaLoggingSystem(org.springframework.boot.logging.java.JavaLoggingSystem) AbstractLoggingSystem(org.springframework.boot.logging.AbstractLoggingSystem) Test(org.junit.Test)

Example 5 with SpringApplication

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

the class LoggingApplicationListenerTests method shutdownHookCanBeRegistered.

@Test
public void shutdownHookCanBeRegistered() throws Exception {
    TestLoggingApplicationListener listener = new TestLoggingApplicationListener();
    System.setProperty(LoggingSystem.class.getName(), TestShutdownHandlerLoggingSystem.class.getName());
    TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "logging.register_shutdown_hook=true");
    multicastEvent(listener, new ApplicationStartingEvent(new SpringApplication(), NO_ARGS));
    listener.initialize(this.context.getEnvironment(), this.context.getClassLoader());
    assertThat(listener.shutdownHook).isNotNull();
    listener.shutdownHook.start();
    assertThat(TestShutdownHandlerLoggingSystem.shutdownLatch.await(30, TimeUnit.SECONDS)).isTrue();
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) ApplicationStartingEvent(org.springframework.boot.context.event.ApplicationStartingEvent) LoggingSystem(org.springframework.boot.logging.LoggingSystem) JavaLoggingSystem(org.springframework.boot.logging.java.JavaLoggingSystem) AbstractLoggingSystem(org.springframework.boot.logging.AbstractLoggingSystem) Test(org.junit.Test)

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