use of org.springframework.boot.test.context.runner.ApplicationContextRunner in project spring-boot by spring-projects.
the class StartupEndpointTests method testStartupEndpoint.
private void testStartupEndpoint(ApplicationStartup applicationStartup, Consumer<StartupEndpoint> startupEndpoint) {
ApplicationContextRunner contextRunner = new ApplicationContextRunner().withInitializer((context) -> context.setApplicationStartup(applicationStartup)).withUserConfiguration(EndpointConfiguration.class);
contextRunner.run((context) -> {
assertThat(context).hasSingleBean(StartupEndpoint.class);
startupEndpoint.accept(context.getBean(StartupEndpoint.class));
});
}
use of org.springframework.boot.test.context.runner.ApplicationContextRunner in project spring-boot by spring-projects.
the class HazelcastHealthIndicatorTests method hazelcastUp.
@Test
void hazelcastUp() {
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class)).withPropertyValues("spring.hazelcast.config=hazelcast.xml").run((context) -> {
HazelcastInstance hazelcast = context.getBean(HazelcastInstance.class);
Health health = new HazelcastHealthIndicator(hazelcast).health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails()).containsOnlyKeys("name", "uuid").containsEntry("name", "actuator-hazelcast");
assertThat(health.getDetails().get("uuid")).asString().isNotEmpty();
});
}
use of org.springframework.boot.test.context.runner.ApplicationContextRunner in project spring-boot by spring-projects.
the class IntegrationGraphEndpointAutoConfigurationTests method runWhenSpringIntegrationIsNotEnabledShouldNotHaveEndpointBean.
@Test
void runWhenSpringIntegrationIsNotEnabledShouldNotHaveEndpointBean() {
ApplicationContextRunner noSpringIntegrationRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(IntegrationGraphEndpointAutoConfiguration.class));
noSpringIntegrationRunner.run((context) -> {
assertThat(context).doesNotHaveBean(IntegrationGraphEndpoint.class);
assertThat(context).doesNotHaveBean(IntegrationGraphServer.class);
});
}
use of org.springframework.boot.test.context.runner.ApplicationContextRunner in project spring-boot by spring-projects.
the class ConfigurationPropertiesReportEndpointFilteringTests method filterByPrefixNoMatches.
@Test
void filterByPrefixNoMatches() {
ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(Config.class).withPropertyValues("foo.primary.name:foo1", "foo.secondary.name:foo2", "only.bar.name:solo1");
contextRunner.run((context) -> {
ConfigurationPropertiesReportEndpoint endpoint = context.getBean(ConfigurationPropertiesReportEndpoint.class);
ApplicationConfigurationProperties applicationProperties = endpoint.configurationPropertiesWithPrefix("foo.third");
assertThat(applicationProperties.getContexts()).containsOnlyKeys(context.getId());
ContextConfigurationProperties contextProperties = applicationProperties.getContexts().get(context.getId());
assertThat(contextProperties.getBeans()).isEmpty();
});
}
use of org.springframework.boot.test.context.runner.ApplicationContextRunner in project spring-boot by spring-projects.
the class ConfigurationPropertiesReportEndpointParentTests method configurationPropertiesClass.
@Test
void configurationPropertiesClass() {
new ApplicationContextRunner().withUserConfiguration(Parent.class).run((parent) -> {
new ApplicationContextRunner().withUserConfiguration(ClassConfigurationProperties.class).withParent(parent).run((child) -> {
ConfigurationPropertiesReportEndpoint endpoint = child.getBean(ConfigurationPropertiesReportEndpoint.class);
ApplicationConfigurationProperties applicationProperties = endpoint.configurationProperties();
assertThat(applicationProperties.getContexts()).containsOnlyKeys(child.getId(), parent.getId());
assertThat(applicationProperties.getContexts().get(child.getId()).getBeans().keySet()).containsExactly("someProperties");
assertThat((applicationProperties.getContexts().get(parent.getId()).getBeans().keySet())).containsExactly("testProperties");
});
});
}
Aggregations