Search in sources :

Example 1 with ConsulTestcontainers

use of org.springframework.cloud.consul.test.ConsulTestcontainers in project spring-cloud-consul by spring-cloud.

the class ConsulConfigBootstrapConfigurationTests method testConfigPropsBeanBacksOff.

/**
 * Tests that the auto-config bean backs off if a user provided their own.
 */
@Test
public void testConfigPropsBeanBacksOff() {
    this.contextRunner.withUserConfiguration(TestConfig.class).withInitializer(new ConsulTestcontainers()).withUserConfiguration(ConsulConfigBootstrapConfiguration.class).run(context -> {
        ConsulConfigProperties config = context.getBean(ConsulConfigProperties.class);
        assertThat(config.getPrefixes().get(0)).as("Prefix did not match").isEqualTo("platform-config");
        assertThat(config.getDefaultContext()).as("Default context did not match").isEqualTo("defaults");
    });
}
Also used : ConsulTestcontainers(org.springframework.cloud.consul.test.ConsulTestcontainers) Test(org.junit.Test)

Example 2 with ConsulTestcontainers

use of org.springframework.cloud.consul.test.ConsulTestcontainers in project spring-cloud-consul by spring-cloud.

the class ConsulAutoServiceRegistrationDisabledTests method testAutoRegistrationDisabled.

private void testAutoRegistrationDisabled(String testName, String disableProperty) {
    new WebApplicationContextRunner().withUserConfiguration(TestConfig.class).withPropertyValues("spring.application.name=" + testName, disableProperty + "=false", "server.port=0").withInitializer(new ConsulTestcontainers()).run(context -> {
        assertThat(context).doesNotHaveBean(ConsulAutoServiceRegistration.class);
        assertThat(context).doesNotHaveBean(ConsulAutoServiceRegistrationListener.class);
        assertThat(context).doesNotHaveBean(ConsulAutoRegistration.class);
        assertThat(context).doesNotHaveBean(ConsulRegistrationCustomizer.class);
        ConsulClient consul = context.getBean(ConsulClient.class);
        Response<Map<String, Service>> response = consul.getAgentServices();
        Map<String, Service> services = response.getValue();
        Service service = services.get(testName);
        assertThat(service).as("service was registered").isNull();
    });
}
Also used : WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) ConsulClient(com.ecwid.consul.v1.ConsulClient) Service(com.ecwid.consul.v1.agent.model.Service) Map(java.util.Map) ConsulTestcontainers(org.springframework.cloud.consul.test.ConsulTestcontainers)

Example 3 with ConsulTestcontainers

use of org.springframework.cloud.consul.test.ConsulTestcontainers in project spring-cloud-consul by spring-cloud.

the class ConsulServiceRegistryDisabledTests method testAutoRegistrationDisabled.

private void testAutoRegistrationDisabled(String testName, String disableProperty) {
    new WebApplicationContextRunner().withUserConfiguration(TestConfig.class).withPropertyValues("spring.application.name=" + testName, disableProperty + "=false", "server.port=0").withInitializer(new ConsulTestcontainers()).run(context -> {
        assertThat(context).doesNotHaveBean(ConsulServiceRegistry.class);
        assertThat(context).doesNotHaveBean(HeartbeatProperties.class);
        ConsulClient consul = context.getBean(ConsulClient.class);
        Response<Map<String, Service>> response = consul.getAgentServices();
        Map<String, Service> services = response.getValue();
        Service service = services.get(testName);
        assertThat(service).as("service was registered").isNull();
    });
}
Also used : WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) ConsulClient(com.ecwid.consul.v1.ConsulClient) Service(com.ecwid.consul.v1.agent.model.Service) Map(java.util.Map) ConsulTestcontainers(org.springframework.cloud.consul.test.ConsulTestcontainers)

Example 4 with ConsulTestcontainers

use of org.springframework.cloud.consul.test.ConsulTestcontainers in project spring-cloud-consul by spring-cloud.

the class ConsulBinderConfigurationTests method consulDisabledDisablesBinder.

@Test
// FIXME 2.0.0 need stream fix
@Ignore
public void consulDisabledDisablesBinder() {
    this.exception.expectMessage(containsString("no proper implementation found"));
    new SpringApplicationBuilder(Application.class).initializers(new ConsulTestcontainers()).properties("spring.cloud.consul.enabled=false").run();
}
Also used : SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) ConsulTestcontainers(org.springframework.cloud.consul.test.ConsulTestcontainers) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with ConsulTestcontainers

use of org.springframework.cloud.consul.test.ConsulTestcontainers in project spring-cloud-consul by spring-cloud.

the class ConsulBinderConfigurationTests method consulBinderDisabledWorks.

@Test
// FIXME 2.0.0 need stream fix
@Ignore
public void consulBinderDisabledWorks() {
    this.exception.expectMessage(containsString("no proper implementation found"));
    new SpringApplicationBuilder(Application.class).initializers(new ConsulTestcontainers()).properties("spring.cloud.consul.binder.enabled=false").run();
}
Also used : SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) ConsulTestcontainers(org.springframework.cloud.consul.test.ConsulTestcontainers) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ConsulTestcontainers (org.springframework.cloud.consul.test.ConsulTestcontainers)5 Test (org.junit.Test)3 ConsulClient (com.ecwid.consul.v1.ConsulClient)2 Service (com.ecwid.consul.v1.agent.model.Service)2 Map (java.util.Map)2 Ignore (org.junit.Ignore)2 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)2 WebApplicationContextRunner (org.springframework.boot.test.context.runner.WebApplicationContextRunner)2