|
|
|
|
@@ -33,6 +33,7 @@ import org.springframework.boot.SpringBootConfiguration;
|
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|
|
|
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
|
|
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
|
|
|
|
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
|
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
|
|
|
|
import org.springframework.boot.test.system.OutputCaptureRule;
|
|
|
|
|
import org.springframework.cloud.config.client.ConfigServerInstanceProvider;
|
|
|
|
|
@@ -53,38 +54,119 @@ import static org.mockito.Mockito.when;
|
|
|
|
|
*/
|
|
|
|
|
@RunWith(ModifiedClassPathRunner.class)
|
|
|
|
|
@ClassPathExclusions("spring-webflux-*")
|
|
|
|
|
class EurekaConfigServerBootstrapConfigurationTests {
|
|
|
|
|
public class EurekaConfigServerBootstrapConfigurationTests {
|
|
|
|
|
|
|
|
|
|
@Rule
|
|
|
|
|
public OutputCaptureRule output = new OutputCaptureRule();
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void offByDefault() {
|
|
|
|
|
public void offByDefault() {
|
|
|
|
|
new ApplicationContextRunner()
|
|
|
|
|
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
|
|
|
|
|
.run(context -> {
|
|
|
|
|
assertThat(context).doesNotHaveBean(EurekaClientConfigBean.class);
|
|
|
|
|
assertThat(context).doesNotHaveBean(EurekaHttpClient.class);
|
|
|
|
|
assertThat(context).doesNotHaveBean(ConfigServerInstanceProvider.Function.class);
|
|
|
|
|
assertEurekaBeansNotPresent(context);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void properBeansCreatedWhenEnabled() {
|
|
|
|
|
public void properBeansCreatedWhenDiscoveryEnabled() {
|
|
|
|
|
new ApplicationContextRunner()
|
|
|
|
|
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
|
|
|
|
|
.withPropertyValues("spring.cloud.config.discovery.enabled=true").run(context -> {
|
|
|
|
|
assertThat(context).hasSingleBean(EurekaClientConfigBean.class);
|
|
|
|
|
assertThat(context).hasSingleBean(RestTemplateEurekaHttpClient.class);
|
|
|
|
|
assertThat(context).hasSingleBean(ConfigServerInstanceProvider.Function.class);
|
|
|
|
|
assertEurekaBeansNotPresent(context);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void eurekaDnsConfigurationWorks() {
|
|
|
|
|
public void beansNotCreatedWhenDiscoveryNotEnabled() {
|
|
|
|
|
new ApplicationContextRunner()
|
|
|
|
|
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
|
|
|
|
|
.withPropertyValues("spring.cloud.config.discovery.enabled=true",
|
|
|
|
|
.withPropertyValues("spring.cloud.config.discovery.enabled=false").run(context -> {
|
|
|
|
|
assertEurekaBeansNotPresent(context);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void beansNotCreatedWhenDiscoveryDisabled() {
|
|
|
|
|
new ApplicationContextRunner()
|
|
|
|
|
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
|
|
|
|
|
.withPropertyValues("spring.cloud.config.discovery.disabled").run(context -> {
|
|
|
|
|
assertEurekaBeansNotPresent(context);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void beansNotCreatedWhenEurekaClientEnabled() {
|
|
|
|
|
new ApplicationContextRunner()
|
|
|
|
|
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
|
|
|
|
|
.withPropertyValues("eureka.client.enabled=true").run(context -> {
|
|
|
|
|
assertEurekaBeansNotPresent(context);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void beansNotCreatedWhenEurekaClientNotEnabled() {
|
|
|
|
|
new ApplicationContextRunner()
|
|
|
|
|
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
|
|
|
|
|
.withPropertyValues("eureka.client.enabled=false").run(context -> {
|
|
|
|
|
assertEurekaBeansNotPresent(context);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void beansNotCreatedWhenEurekaClientDisabled() {
|
|
|
|
|
new ApplicationContextRunner()
|
|
|
|
|
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
|
|
|
|
|
.withPropertyValues("eureka.client.disabled").run(context -> {
|
|
|
|
|
assertEurekaBeansNotPresent(context);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void properBeansCreatedWhenDiscoveryEnabled_EurekaEnabled() {
|
|
|
|
|
new ApplicationContextRunner()
|
|
|
|
|
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
|
|
|
|
|
.withPropertyValues("spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=true")
|
|
|
|
|
.run(context -> {
|
|
|
|
|
assertEurekaBeansPresent(context);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void beansNotCreatedWhenDiscoveryEnabled_EurekaNotEnabled() {
|
|
|
|
|
new ApplicationContextRunner()
|
|
|
|
|
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
|
|
|
|
|
.withPropertyValues("spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=false")
|
|
|
|
|
.run(context -> {
|
|
|
|
|
assertEurekaBeansNotPresent(context);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void beansNotCreatedWhenDiscoveryNotEnabled_EurekaEnabled() {
|
|
|
|
|
new ApplicationContextRunner()
|
|
|
|
|
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
|
|
|
|
|
.withPropertyValues("spring.cloud.config.discovery.enabled=false", "eureka.client.enabled=true")
|
|
|
|
|
.run(context -> {
|
|
|
|
|
assertEurekaBeansNotPresent(context);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void beansNotCreatedWhenDiscoveryNotEnabled_EurekaNotEnabled() {
|
|
|
|
|
new ApplicationContextRunner()
|
|
|
|
|
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
|
|
|
|
|
.withPropertyValues("spring.cloud.config.discovery.enabled=false", "eureka.client.enabled=false")
|
|
|
|
|
.run(context -> {
|
|
|
|
|
assertEurekaBeansNotPresent(context);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void eurekaDnsConfigurationWorks() {
|
|
|
|
|
new ApplicationContextRunner()
|
|
|
|
|
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
|
|
|
|
|
.withPropertyValues("spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=true",
|
|
|
|
|
"eureka.instance.hostname=eurekaclient1",
|
|
|
|
|
"eureka.client.use-dns-for-fetching-service-urls=true",
|
|
|
|
|
"eureka.client.eureka-server-d-n-s-name=myeurekahost",
|
|
|
|
|
@@ -95,11 +177,12 @@ class EurekaConfigServerBootstrapConfigurationTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void eurekaConfigServerInstanceProviderCalled() {
|
|
|
|
|
public void eurekaConfigServerInstanceProviderCalled() {
|
|
|
|
|
// FIXME: why do I need to do this? (fails in maven build without it.
|
|
|
|
|
TomcatURLStreamHandlerFactory.disable();
|
|
|
|
|
new SpringApplicationBuilder(TestConfigDiscoveryConfiguration.class)
|
|
|
|
|
.properties("spring.config.use-legacy-processing=true", "spring.cloud.config.discovery.enabled=true",
|
|
|
|
|
"eureka.client.enabled=true",
|
|
|
|
|
"spring.main.sources=" + TestConfigDiscoveryBootstrapConfiguration.class.getName(),
|
|
|
|
|
"logging.level.org.springframework.cloud.netflix.eureka.config=DEBUG")
|
|
|
|
|
.run();
|
|
|
|
|
@@ -107,6 +190,18 @@ class EurekaConfigServerBootstrapConfigurationTests {
|
|
|
|
|
.contains("eurekaConfigServerInstanceProvider found 1 instance(s) for configserver");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void assertEurekaBeansPresent(AssertableApplicationContext context) {
|
|
|
|
|
assertThat(context).hasSingleBean(EurekaClientConfigBean.class);
|
|
|
|
|
assertThat(context).hasSingleBean(RestTemplateEurekaHttpClient.class);
|
|
|
|
|
assertThat(context).hasSingleBean(ConfigServerInstanceProvider.Function.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void assertEurekaBeansNotPresent(AssertableApplicationContext context) {
|
|
|
|
|
assertThat(context).doesNotHaveBean(EurekaClientConfigBean.class);
|
|
|
|
|
assertThat(context).doesNotHaveBean(EurekaHttpClient.class);
|
|
|
|
|
assertThat(context).doesNotHaveBean(ConfigServerInstanceProvider.Function.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SpringBootConfiguration
|
|
|
|
|
@EnableAutoConfiguration
|
|
|
|
|
protected static class TestConfigDiscoveryConfiguration {
|
|
|
|
|
|