Search in sources :

Example 1 with ApplicationContextRunner

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

the class ConditionalOnRefreshScopeTests method refreshScopeIncluded.

@Test
public void refreshScopeIncluded() {
    new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class)).withUserConfiguration(Beans.class).run(c -> {
        assertThat(c).hasSingleBean(org.springframework.cloud.context.scope.refresh.RefreshScope.class);
        assertThat(c.getBean("foo")).isEqualTo("foo");
    });
}
Also used : ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) RefreshAutoConfiguration(org.springframework.cloud.autoconfigure.RefreshAutoConfiguration) Test(org.junit.Test)

Example 2 with ApplicationContextRunner

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

the class EurekaClientConfigServerAutoConfigurationTests method onWhenRequested.

@Test
public void onWhenRequested() {
    new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(EurekaClientConfigServerAutoConfiguration.class, ConfigServerProperties.class, EurekaInstanceConfigBean.class)).withPropertyValues("spring.cloud.config.server.prefix=/config").run(c -> {
        assertEquals(1, c.getBeanNamesForType(EurekaInstanceConfig.class).length);
        EurekaInstanceConfig instance = c.getBean(EurekaInstanceConfig.class);
        assertEquals("/config", instance.getMetadataMap().get("configPath"));
    });
}
Also used : EurekaInstanceConfigBean(org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) ConfigServerProperties(org.springframework.cloud.config.server.config.ConfigServerProperties) EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) Test(org.junit.Test)

Example 3 with ApplicationContextRunner

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

the class SpringBootAdminClientAutoConfigurationTest method nonWebEnvironment.

@Test
public void nonWebEnvironment() {
    ApplicationContextRunner nonWebcontextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(SpringBootAdminClientAutoConfiguration.class));
    nonWebcontextRunner.withPropertyValues("spring.boot.admin.client.url:http://localhost:8081").run((context) -> assertThat(context).doesNotHaveBean(ApplicationRegistrator.class));
}
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) ApplicationRegistrator(de.codecentric.boot.admin.client.registration.ApplicationRegistrator) Test(org.junit.jupiter.api.Test)

Example 4 with ApplicationContextRunner

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

the class MetricsAutoConfigurationIntegrationTests method emptyCompositeIsCreatedWhenNoMeterRegistriesAreAutoConfigured.

@Test
void emptyCompositeIsCreatedWhenNoMeterRegistriesAreAutoConfigured() {
    new ApplicationContextRunner().with(MetricsRun.limitedTo()).run((context) -> {
        MeterRegistry registry = context.getBean(MeterRegistry.class);
        assertThat(registry).isInstanceOf(CompositeMeterRegistry.class);
        assertThat(((CompositeMeterRegistry) registry).getRegistries()).isEmpty();
    });
}
Also used : CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) GraphiteMeterRegistry(io.micrometer.graphite.GraphiteMeterRegistry) CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) JmxMeterRegistry(io.micrometer.jmx.JmxMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 5 with ApplicationContextRunner

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

the class ConditionsReportEndpointTests method invoke.

@Test
void invoke() {
    new ApplicationContextRunner().withUserConfiguration(Config.class).run((context) -> {
        ContextConditionEvaluation report = context.getBean(ConditionsReportEndpoint.class).applicationConditionEvaluation().getContexts().get(context.getId());
        assertThat(report.getPositiveMatches()).isEmpty();
        assertThat(report.getNegativeMatches()).containsKey("a");
        assertThat(report.getUnconditionalClasses()).contains("b");
        assertThat(report.getExclusions()).contains("com.foo.Bar");
    });
}
Also used : ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) ContextConditionEvaluation(org.springframework.boot.actuate.autoconfigure.condition.ConditionsReportEndpoint.ContextConditionEvaluation) Test(org.junit.jupiter.api.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