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());
});
}
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);
});
});
}
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"));
}
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();
}
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"));
});
}
Aggregations