Search in sources :

Example 36 with SpringApplication

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

the class SpringApplicationAdminMXBeanRegistrarTests method validateReadyFlag.

@Test
public void validateReadyFlag() {
    final ObjectName objectName = createObjectName(OBJECT_NAME);
    SpringApplication application = new SpringApplication(Config.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    application.addListeners(new ApplicationListener<ContextRefreshedEvent>() {

        @Override
        public void onApplicationEvent(ContextRefreshedEvent event) {
            try {
                assertThat(isApplicationReady(objectName)).isFalse();
            } catch (Exception ex) {
                throw new IllegalStateException("Could not contact spring application admin bean", ex);
            }
        }
    });
    this.context = application.run();
    assertThat(isApplicationReady(objectName)).isTrue();
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ExpectedException(org.junit.rules.ExpectedException) ObjectName(javax.management.ObjectName) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) Test(org.junit.Test)

Example 37 with SpringApplication

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

the class SpringApplicationAdminMXBeanRegistrarTests method shutdownApp.

@Test
public void shutdownApp() throws InstanceNotFoundException {
    final ObjectName objectName = createObjectName(OBJECT_NAME);
    SpringApplication application = new SpringApplication(Config.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    this.context = application.run();
    assertThat(this.context.isRunning()).isTrue();
    invokeShutdown(objectName);
    assertThat(this.context.isRunning()).isFalse();
    // JMX cleanup
    this.thrown.expect(InstanceNotFoundException.class);
    this.mBeanServer.getObjectInstance(objectName);
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 38 with SpringApplication

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

the class AutoConfigurationReproTests method doesNotEarlyInitializeFactoryBeans.

@Test
public void doesNotEarlyInitializeFactoryBeans() throws Exception {
    SpringApplication application = new SpringApplication(EarlyInitConfig.class, PropertySourcesPlaceholderConfigurer.class, ServletWebServerFactoryAutoConfiguration.class);
    this.context = application.run("--server.port=0");
    String bean = (String) this.context.getBean("earlyInit");
    assertThat(bean).isEqualTo("bucket");
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) Test(org.junit.Test)

Example 39 with SpringApplication

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

the class BasicErrorControllerDirectMockMvcTests method errorPageAvailableWithMvcIncluded.

@Test
public void errorPageAvailableWithMvcIncluded() throws Exception {
    setup((ConfigurableWebApplicationContext) new SpringApplication(WebMvcIncludedConfiguration.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)

Example 40 with SpringApplication

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

the class BasicErrorControllerDirectMockMvcTests method errorPageNotAvailableWithWhitelabelDisabled.

@Test
public void errorPageNotAvailableWithWhitelabelDisabled() throws Exception {
    setup((ConfigurableWebApplicationContext) new SpringApplication(WebMvcIncludedConfiguration.class).run("--server.port=0", "--server.error.whitelabel.enabled=false"));
    this.thrown.expect(ServletException.class);
    this.mockMvc.perform(get("/error").accept(MediaType.TEXT_HTML));
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) 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