Search in sources :

Example 21 with SpringApplication

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

the class ApplicationPidFileWriterTests method createReadyEvent.

private SpringApplicationEvent createReadyEvent(String propName, String propValue) {
    ConfigurableEnvironment environment = createEnvironment(propName, propValue);
    ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
    given(context.getEnvironment()).willReturn(environment);
    return new ApplicationReadyEvent(new SpringApplication(), new String[] {}, context);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) SpringApplication(org.springframework.boot.SpringApplication) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent)

Example 22 with SpringApplication

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

the class LiquibaseServiceLocatorApplicationListenerTests method replacesServiceLocator.

@Test
public void replacesServiceLocator() throws Exception {
    SpringApplication application = new SpringApplication(Conf.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    this.context = application.run();
    ServiceLocator instance = ServiceLocator.getInstance();
    Field field = ReflectionUtils.findField(ServiceLocator.class, "classResolver");
    field.setAccessible(true);
    Object resolver = field.get(instance);
    assertThat(resolver).isInstanceOf(SpringPackageScanClassResolver.class);
}
Also used : ServiceLocator(liquibase.servicelocator.ServiceLocator) Field(java.lang.reflect.Field) SpringApplication(org.springframework.boot.SpringApplication) Test(org.junit.Test)

Example 23 with SpringApplication

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

the class ApplicationPidFileWriterTests method createPreparedEvent.

private SpringApplicationEvent createPreparedEvent(String propName, String propValue) {
    ConfigurableEnvironment environment = createEnvironment(propName, propValue);
    ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
    given(context.getEnvironment()).willReturn(environment);
    return new ApplicationPreparedEvent(new SpringApplication(), new String[] {}, context);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) SpringApplication(org.springframework.boot.SpringApplication) ApplicationPreparedEvent(org.springframework.boot.context.event.ApplicationPreparedEvent)

Example 24 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 25 with SpringApplication

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

the class BasicErrorControllerDirectMockMvcTests method errorControllerWithAop.

@Test
public void errorControllerWithAop() throws Exception {
    setup((ConfigurableWebApplicationContext) new SpringApplication(WithAopConfiguration.class).run("--server.port=0"));
    MvcResult response = this.mockMvc.perform(get("/error").accept(MediaType.TEXT_HTML)).andExpect(status().is5xxServerError()).andReturn();
    String content = response.getResponse().getContentAsString();
    assertThat(content).contains("status=999");
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.Test)

Aggregations

SpringApplication (org.springframework.boot.SpringApplication)63 Test (org.junit.Test)45 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)14 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)7 HashMap (java.util.HashMap)6 ApplicationStartingEvent (org.springframework.boot.context.event.ApplicationStartingEvent)5 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)4 ApplicationFailedEvent (org.springframework.boot.context.event.ApplicationFailedEvent)4 JoranException (ch.qos.logback.core.joran.spi.JoranException)3 ObjectName (javax.management.ObjectName)3 ApplicationPreparedEvent (org.springframework.boot.context.event.ApplicationPreparedEvent)3 ApplicationReadyEvent (org.springframework.boot.context.event.ApplicationReadyEvent)3 JavaLoggingSystem (org.springframework.boot.logging.java.JavaLoggingSystem)3 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)3 StandardEnvironment (org.springframework.core.env.StandardEnvironment)3 File (java.io.File)2 LogConfigurationException (org.apache.commons.logging.LogConfigurationException)2 ApplicationEnvironmentPreparedEvent (org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent)2 AbstractLoggingSystem (org.springframework.boot.logging.AbstractLoggingSystem)2 LoggingSystem (org.springframework.boot.logging.LoggingSystem)2