Search in sources :

Example 26 with ApplicationContextRunner

use of org.springframework.boot.test.context.runner.ApplicationContextRunner in project spring-boot by spring-projects.

the class ShutdownEndpointTests method shutdown.

@Test
void shutdown() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(EndpointConfig.class);
    contextRunner.run((context) -> {
        EndpointConfig config = context.getBean(EndpointConfig.class);
        ClassLoader previousTccl = Thread.currentThread().getContextClassLoader();
        Map<String, String> result;
        Thread.currentThread().setContextClassLoader(new URLClassLoader(new URL[0], getClass().getClassLoader()));
        try {
            result = context.getBean(ShutdownEndpoint.class).shutdown();
        } finally {
            Thread.currentThread().setContextClassLoader(previousTccl);
        }
        assertThat(result.get("message")).startsWith("Shutting down");
        assertThat(((ConfigurableApplicationContext) context).isActive()).isTrue();
        assertThat(config.latch.await(10, TimeUnit.SECONDS)).isTrue();
        assertThat(config.threadContextClassLoader).isEqualTo(getClass().getClassLoader());
    });
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Example 27 with ApplicationContextRunner

use of org.springframework.boot.test.context.runner.ApplicationContextRunner in project spring-boot by spring-projects.

the class LifecycleAutoConfigurationTests method lifecycleProcessorIsConfiguredWithCustomTimeoutInAChildContext.

@Test
void lifecycleProcessorIsConfiguredWithCustomTimeoutInAChildContext() {
    new ApplicationContextRunner().run((parent) -> {
        this.contextRunner.withParent(parent).withPropertyValues("spring.lifecycle.timeout-per-shutdown-phase=15s").run((child) -> {
            assertThat(child).hasBean(AbstractApplicationContext.LIFECYCLE_PROCESSOR_BEAN_NAME);
            Object processor = child.getBean(AbstractApplicationContext.LIFECYCLE_PROCESSOR_BEAN_NAME);
            assertThat(processor).extracting("timeoutPerShutdownPhase").isEqualTo(15000L);
        });
    });
}
Also used : ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) Test(org.junit.jupiter.api.Test)

Example 28 with ApplicationContextRunner

use of org.springframework.boot.test.context.runner.ApplicationContextRunner in project spring-boot by spring-projects.

the class ConditionalOnWarDeploymentTests method nonWebApplicationShouldNotMatch.

@Test
void nonWebApplicationShouldNotMatch() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner();
    contextRunner.withUserConfiguration(TestConfiguration.class).run((context) -> assertThat(context).doesNotHaveBean("forWar"));
}
Also used : ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) Test(org.junit.jupiter.api.Test)

Example 29 with ApplicationContextRunner

use of org.springframework.boot.test.context.runner.ApplicationContextRunner in project joinfaces by joinfaces.

the class JoinfacesApplicationAnalyzerTest method setUp.

@Before
public void setUp() {
    this.joinfacesApplicationAnalyzer = new JoinfacesApplicationAnalyzer();
    this.applicationContextRunner = new ApplicationContextRunner();
}
Also used : ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) Before(org.junit.Before)

Example 30 with ApplicationContextRunner

use of org.springframework.boot.test.context.runner.ApplicationContextRunner in project spring-cloud-netflix by spring-cloud.

the class HystrixDashboardConfigurationTests method initParameters.

@Test
public void initParameters() {
    new ApplicationContextRunner().withUserConfiguration(HystrixDashboardConfiguration.class).withPropertyValues("hystrix.dashboard.init-parameters.wl-dispatch-polixy=work-manager-hystrix").run(context -> {
        final ServletRegistrationBean registration = context.getBean(ServletRegistrationBean.class);
        assertNotNull(registration);
        final Map<String, String> initParameters = registration.getInitParameters();
        assertNotNull(initParameters);
        assertThat(initParameters.get("wl-dispatch-polixy"), is("work-manager-hystrix"));
    });
}
Also used : ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) Test(org.junit.Test)

Aggregations

ApplicationContextRunner (org.springframework.boot.test.context.runner.ApplicationContextRunner)53 Test (org.junit.jupiter.api.Test)49 ApplicationConfigurationProperties (org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties)21 ConfigurationPropertiesBeanDescriptor (org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ConfigurationPropertiesBeanDescriptor)16 Map (java.util.Map)7 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)6 CompositeMeterRegistry (io.micrometer.core.instrument.composite.CompositeMeterRegistry)6 HashMap (java.util.HashMap)6 List (java.util.List)6 ArrayList (java.util.ArrayList)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 ContextConfigurationProperties (org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ContextConfigurationProperties)5 Bean (org.springframework.context.annotation.Bean)5 Configuration (org.springframework.context.annotation.Configuration)5 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)4 GraphiteMeterRegistry (io.micrometer.graphite.GraphiteMeterRegistry)4 JmxMeterRegistry (io.micrometer.jmx.JmxMeterRegistry)4 ApplicationBeans (org.springframework.boot.actuate.beans.BeansEndpoint.ApplicationBeans)4 Test (org.junit.Test)3 ContextBeans (org.springframework.boot.actuate.beans.BeansEndpoint.ContextBeans)3