Search in sources :

Example 31 with SpringApplication

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

the class AutoConfigurationReportLoggingInitializerTests method noErrorIfNotInitialized.

@Test
public void noErrorIfNotInitialized() throws Exception {
    this.initializer.onApplicationEvent(new ApplicationFailedEvent(new SpringApplication(), new String[0], null, new RuntimeException("Planned")));
    assertThat(this.infoLog.get(0)).contains("Unable to provide auto-configuration report");
}
Also used : ApplicationFailedEvent(org.springframework.boot.context.event.ApplicationFailedEvent) SpringApplication(org.springframework.boot.SpringApplication) Test(org.junit.Test)

Example 32 with SpringApplication

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

the class RemoteSpringApplication method run.

private void run(String[] args) {
    Restarter.initialize(args, RestartInitializer.NONE);
    SpringApplication application = new SpringApplication(RemoteClientConfiguration.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    application.setBanner(getBanner());
    application.setInitializers(getInitializers());
    application.setListeners(getListeners());
    application.run(args);
    waitIndefinitely();
}
Also used : SpringApplication(org.springframework.boot.SpringApplication)

Example 33 with SpringApplication

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

the class SpringBootDependencyInjectionTestExecutionListenerTests method prepareFailingTestInstanceShouldPrintReport.

@Test
public void prepareFailingTestInstanceShouldPrintReport() throws Exception {
    TestContext testContext = mock(TestContext.class);
    given(testContext.getTestInstance()).willThrow(new IllegalStateException());
    SpringApplication application = new SpringApplication(Config.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    ConfigurableApplicationContext applicationContext = application.run();
    given(testContext.getApplicationContext()).willReturn(applicationContext);
    try {
        this.reportListener.prepareTestInstance(testContext);
    } catch (IllegalStateException ex) {
    // Expected
    }
    this.out.expect(containsString("AUTO-CONFIGURATION REPORT"));
    this.out.expect(containsString("Positive matches"));
    this.out.expect(containsString("Negative matches"));
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringApplication(org.springframework.boot.SpringApplication) TestContext(org.springframework.test.context.TestContext) Test(org.junit.Test)

Example 34 with SpringApplication

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

the class SpringApplicationAdminMXBeanRegistrarTests method eventsFromOtherContextsAreIgnored.

@Test
public void eventsFromOtherContextsAreIgnored() throws MalformedObjectNameException {
    SpringApplicationAdminMXBeanRegistrar registrar = new SpringApplicationAdminMXBeanRegistrar(OBJECT_NAME);
    ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
    registrar.setApplicationContext(context);
    registrar.onApplicationEvent(new ApplicationReadyEvent(new SpringApplication(), null, mock(ConfigurableApplicationContext.class)));
    assertThat(isApplicationReady(registrar)).isFalse();
    registrar.onApplicationEvent(new ApplicationReadyEvent(new SpringApplication(), null, context));
    assertThat(isApplicationReady(registrar)).isTrue();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringApplication(org.springframework.boot.SpringApplication) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) Test(org.junit.Test)

Example 35 with SpringApplication

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

the class SpringApplicationAdminMXBeanRegistrarTests method environmentIsExposed.

@Test
public void environmentIsExposed() {
    final ObjectName objectName = createObjectName(OBJECT_NAME);
    SpringApplication application = new SpringApplication(Config.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    this.context = application.run("--foo.bar=blam");
    assertThat(isApplicationReady(objectName)).isTrue();
    assertThat(isApplicationEmbeddedWebApplication(objectName)).isFalse();
    assertThat(getProperty(objectName, "foo.bar")).isEqualTo("blam");
    assertThat(getProperty(objectName, "does.not.exist.test")).isNull();
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

SpringApplication (org.springframework.boot.SpringApplication)64 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