Commit 865d8edc by Johannes Edmeier

Fix deprecation warnings

parent 4b0b99d1
package spring.boot.admin.turbine.config;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.Matchers.empty;
import static org.junit.Assert.assertThat;
import de.codecentric.boot.admin.config.AdminServerCoreConfiguration;
import de.codecentric.boot.admin.config.AdminServerWebConfiguration;
import de.codecentric.boot.admin.config.RevereseZuulProxyConfiguration;
import spring.boot.admin.turbine.web.TurbineController;
import org.junit.After;
import org.junit.Test;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration.RestTemplateConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.cloud.client.discovery.noop.NoopDiscoveryClientAutoConfiguration;
import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import de.codecentric.boot.admin.config.AdminServerCoreConfiguration;
import de.codecentric.boot.admin.config.AdminServerWebConfiguration;
import de.codecentric.boot.admin.config.RevereseZuulProxyConfiguration;
import spring.boot.admin.turbine.web.TurbineController;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.Matchers.empty;
import static org.junit.Assert.assertThat;
public class TurbineAutoConfigurationTest {
private AnnotationConfigWebApplicationContext context;
@After
public void close() {
if (this.context != null) {
this.context.close();
}
}
@Test
public void test_disabled() {
load("spring.boot.admin.turbine.enabled:false",
"spring.boot.admin.turbine.url:http://turbine.server:8989/turbine.stream");
assertThat(context.getBeansOfType(TurbineController.class).values(), empty());
}
@Test
public void test_enabled() {
load("spring.boot.admin.turbine.url:http://turbine.server:8989/turbine.stream");
assertThat(context.getBean(TurbineController.class), instanceOf(TurbineController.class));
}
private void load(String... environment) {
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
applicationContext.register(PropertyPlaceholderAutoConfiguration.class);
applicationContext.register(RestTemplateConfiguration.class);
applicationContext.register(ServerPropertiesAutoConfiguration.class);
applicationContext.register(NoopDiscoveryClientAutoConfiguration.class);
applicationContext.register(AdminServerCoreConfiguration.class);
applicationContext.register(AdminServerWebConfiguration.class);
applicationContext.register(RevereseZuulProxyConfiguration.class);
applicationContext.register(TurbineAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(applicationContext, environment);
applicationContext.refresh();
this.context = applicationContext;
}
private AnnotationConfigWebApplicationContext context;
@After
public void close() {
if (this.context != null) {
this.context.close();
}
}
@Test
public void test_disabled() {
load("spring.boot.admin.turbine.enabled:false",
"spring.boot.admin.turbine.url:http://turbine.server:8989/turbine.stream");
assertThat(context.getBeansOfType(TurbineController.class).values(), empty());
}
@Test
public void test_enabled() {
load("spring.boot.admin.turbine.url:http://turbine.server:8989/turbine.stream");
assertThat(context.getBean(TurbineController.class), instanceOf(TurbineController.class));
}
private void load(String... environment) {
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
applicationContext.register(PropertyPlaceholderAutoConfiguration.class);
applicationContext.register(RestTemplateConfiguration.class);
applicationContext.register(ServerPropertiesAutoConfiguration.class);
applicationContext.register(SimpleDiscoveryClientAutoConfiguration.class);
applicationContext.register(AdminServerCoreConfiguration.class);
applicationContext.register(AdminServerWebConfiguration.class);
applicationContext.register(RevereseZuulProxyConfiguration.class);
applicationContext.register(TurbineAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(applicationContext, environment);
applicationContext.refresh();
this.context = applicationContext;
}
}
package spring.boot.admin.turbine.zuul.filters;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import org.junit.Test;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.noop.NoopDiscoveryClient;
import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClient;
import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryProperties;
import org.springframework.cloud.netflix.zuul.filters.Route;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute;
public class TurbineRouteLocatorTest {
@Test
public void test_route_http_location() {
ZuulRoute route = new ZuulRoute("/path/**", "http://example.com/target");
TurbineRouteLocator locator = new TurbineRouteLocator(route, "", new ZuulProperties(),
null);
assertThat(locator.getRoutes().size(), is(1) );
assertThat(locator.getRoutes().get(0).getPath(), is("/**"));
assertThat(locator.getRoutes().get(0).getPrefix(), is("/path"));
assertThat(locator.getRoutes().get(0).getLocation(), is( "http://example.com/target"));
Route matchingRoute = locator.getMatchingRoute("/path/foo");
assertThat(matchingRoute.getLocation(), is("http://example.com/target"));
assertThat(matchingRoute.getPath(), is("/foo/turbine.stream"));
assertThat(locator.getMatchingRoute("/404/foo"), nullValue());
}
@Test
public void test_route_service_location() {
ZuulRoute route = new ZuulRoute("/path/**", "turbine");
DiscoveryClient discovery = mock(DiscoveryClient.class);
when(discovery.getInstances("turbine")).thenReturn(Arrays.<ServiceInstance>asList(
new DefaultServiceInstance("turbine", "example.com", 80, false)));
TurbineRouteLocator locator = new TurbineRouteLocator(route, "", new ZuulProperties(),
discovery);
Route matchingRoute = locator.getMatchingRoute("/path/foo");
assertThat(matchingRoute.getLocation(), is("http://example.com:80"));
assertThat(matchingRoute.getPath(), is("/foo/turbine.stream"));
}
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@Test(expected = IllegalStateException.class)
public void test_route_noservice() {
ZuulRoute route = new ZuulRoute("/path/**", "turbine");
DiscoveryClient discovery = new NoopDiscoveryClient(null);
TurbineRouteLocator locator = new TurbineRouteLocator(route, "", new ZuulProperties(),
discovery);
public class TurbineRouteLocatorTest {
locator.getMatchingRoute("/path/foo");
}
@Test
public void test_route_http_location() {
ZuulRoute route = new ZuulRoute("/path/**", "http://example.com/target");
TurbineRouteLocator locator = new TurbineRouteLocator(route, "", new ZuulProperties(), null);
assertThat(locator.getRoutes().size(), is(1));
assertThat(locator.getRoutes().get(0).getPath(), is("/**"));
assertThat(locator.getRoutes().get(0).getPrefix(), is("/path"));
assertThat(locator.getRoutes().get(0).getLocation(), is("http://example.com/target"));
Route matchingRoute = locator.getMatchingRoute("/path/foo");
assertThat(matchingRoute.getLocation(), is("http://example.com/target"));
assertThat(matchingRoute.getPath(), is("/foo/turbine.stream"));
assertThat(locator.getMatchingRoute("/404/foo"), nullValue());
}
@Test
public void test_route_service_location() {
ZuulRoute route = new ZuulRoute("/path/**", "turbine");
DiscoveryClient discovery = mock(DiscoveryClient.class);
when(discovery.getInstances("turbine")).thenReturn(
Arrays.<ServiceInstance>asList(new DefaultServiceInstance("turbine", "example.com", 80, false)));
TurbineRouteLocator locator = new TurbineRouteLocator(route, "", new ZuulProperties(), discovery);
Route matchingRoute = locator.getMatchingRoute("/path/foo");
assertThat(matchingRoute.getLocation(), is("http://example.com:80"));
assertThat(matchingRoute.getPath(), is("/foo/turbine.stream"));
}
@Test(expected = IllegalStateException.class)
public void test_route_noservice() {
ZuulRoute route = new ZuulRoute("/path/**", "turbine");
DiscoveryClient discovery = new SimpleDiscoveryClient(new SimpleDiscoveryProperties());
TurbineRouteLocator locator = new TurbineRouteLocator(route, "", new ZuulProperties(), discovery);
locator.getMatchingRoute("/path/foo");
}
}
......@@ -15,6 +15,12 @@
*/
package de.codecentric.boot.admin.config;
import de.codecentric.boot.admin.discovery.ApplicationDiscoveryListener;
import de.codecentric.boot.admin.discovery.DefaultServiceInstanceConverter;
import de.codecentric.boot.admin.discovery.EurekaServiceInstanceConverter;
import de.codecentric.boot.admin.discovery.ServiceInstanceConverter;
import de.codecentric.boot.admin.registry.ApplicationRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
......@@ -23,56 +29,47 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.noop.NoopDiscoveryClientAutoConfiguration;
import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.netflix.discovery.EurekaClient;
import de.codecentric.boot.admin.discovery.ApplicationDiscoveryListener;
import de.codecentric.boot.admin.discovery.DefaultServiceInstanceConverter;
import de.codecentric.boot.admin.discovery.EurekaServiceInstanceConverter;
import de.codecentric.boot.admin.discovery.ServiceInstanceConverter;
import de.codecentric.boot.admin.registry.ApplicationRegistry;
@Configuration
@ConditionalOnSingleCandidate(DiscoveryClient.class)
@ConditionalOnProperty(prefix = "spring.boot.admin.discovery", name = "enabled", matchIfMissing = true)
@AutoConfigureAfter({ NoopDiscoveryClientAutoConfiguration.class })
@AutoConfigureAfter({SimpleDiscoveryClientAutoConfiguration.class})
public class DiscoveryClientConfiguration {
@Autowired
private DiscoveryClient discoveryClient;
@Autowired
private DiscoveryClient discoveryClient;
@Autowired
private ApplicationRegistry registry;
@Autowired
private ApplicationRegistry registry;
@Bean
@ConditionalOnMissingBean
@ConfigurationProperties(prefix = "spring.boot.admin.discovery")
public ApplicationDiscoveryListener applicationDiscoveryListener(
ServiceInstanceConverter serviceInstanceConverter) {
ApplicationDiscoveryListener listener = new ApplicationDiscoveryListener(discoveryClient,
registry);
listener.setConverter(serviceInstanceConverter);
return listener;
}
@Bean
@ConditionalOnMissingBean
@ConfigurationProperties(prefix = "spring.boot.admin.discovery")
public ApplicationDiscoveryListener applicationDiscoveryListener(ServiceInstanceConverter serviceInstanceConverter) {
ApplicationDiscoveryListener listener = new ApplicationDiscoveryListener(discoveryClient, registry);
listener.setConverter(serviceInstanceConverter);
return listener;
}
@Configuration
@ConditionalOnBean(EurekaClient.class)
public static class EurekaConverterConfiguration {
@Bean
@ConditionalOnMissingBean({ ServiceInstanceConverter.class })
@ConfigurationProperties(prefix = "spring.boot.admin.discovery.converter")
public EurekaServiceInstanceConverter serviceInstanceConverter() {
return new EurekaServiceInstanceConverter();
}
}
@Configuration
@ConditionalOnBean(EurekaClient.class)
public static class EurekaConverterConfiguration {
@Bean
@ConditionalOnMissingBean({ServiceInstanceConverter.class})
@ConfigurationProperties(prefix = "spring.boot.admin.discovery.converter")
public EurekaServiceInstanceConverter serviceInstanceConverter() {
return new EurekaServiceInstanceConverter();
}
}
@Bean
@ConditionalOnMissingBean({ ServiceInstanceConverter.class })
@ConfigurationProperties(prefix = "spring.boot.admin.discovery.converter")
public DefaultServiceInstanceConverter serviceInstanceConverter() {
return new DefaultServiceInstanceConverter();
}
@Bean
@ConditionalOnMissingBean({ServiceInstanceConverter.class})
@ConfigurationProperties(prefix = "spring.boot.admin.discovery.converter")
public DefaultServiceInstanceConverter serviceInstanceConverter() {
return new DefaultServiceInstanceConverter();
}
}
......@@ -15,135 +15,126 @@
*/
package de.codecentric.boot.admin.config;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.isA;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import de.codecentric.boot.admin.discovery.ApplicationDiscoveryListener;
import de.codecentric.boot.admin.journal.store.HazelcastJournaledEventStore;
import de.codecentric.boot.admin.journal.store.JournaledEventStore;
import de.codecentric.boot.admin.journal.store.SimpleJournaledEventStore;
import de.codecentric.boot.admin.notify.MailNotifier;
import de.codecentric.boot.admin.registry.store.ApplicationStore;
import de.codecentric.boot.admin.registry.store.HazelcastApplicationStore;
import de.codecentric.boot.admin.registry.store.SimpleApplicationStore;
import java.util.ArrayList;
import java.util.List;
import org.junit.After;
import org.junit.Test;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration.RestTemplateConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.cloud.client.discovery.noop.NoopDiscoveryClientAutoConfiguration;
import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import com.hazelcast.config.Config;
import de.codecentric.boot.admin.discovery.ApplicationDiscoveryListener;
import de.codecentric.boot.admin.journal.store.HazelcastJournaledEventStore;
import de.codecentric.boot.admin.journal.store.JournaledEventStore;
import de.codecentric.boot.admin.journal.store.SimpleJournaledEventStore;
import de.codecentric.boot.admin.notify.MailNotifier;
import de.codecentric.boot.admin.registry.store.ApplicationStore;
import de.codecentric.boot.admin.registry.store.HazelcastApplicationStore;
import de.codecentric.boot.admin.registry.store.SimpleApplicationStore;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.isA;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public class AdminServerWebConfigurationTest {
private AnnotationConfigWebApplicationContext context;
@After
public void close() {
if (this.context != null) {
this.context.close();
}
}
@Test
public void jacksonMapperPresentFromDefault() {
AdminServerWebConfiguration config = new AdminServerWebConfiguration(null, null, null,
null);
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2HttpMessageConverter());
config.extendMessageConverters(converters);
assertThat(converters, hasItem(isA(MappingJackson2HttpMessageConverter.class)));
assertThat(converters.size(), is(1));
}
@Test
public void jacksonMapperPresentNeedExtend() {
AdminServerWebConfiguration config = new AdminServerWebConfiguration(null, null, null,
null);
List<HttpMessageConverter<?>> converters = new ArrayList<>();
config.extendMessageConverters(converters);
assertThat(converters, hasItem(isA(MappingJackson2HttpMessageConverter.class)));
assertThat(converters.size(), is(1));
}
@Test
public void simpleConfig() {
load();
assertThat(context.getBean(ApplicationStore.class),
is(instanceOf(SimpleApplicationStore.class)));
assertTrue(context.getBeansOfType(ApplicationDiscoveryListener.class).isEmpty());
assertTrue(context.getBeansOfType(MailNotifier.class).isEmpty());
assertThat(context.getBean(JournaledEventStore.class),
is(instanceOf(SimpleJournaledEventStore.class)));
}
@Test
public void hazelcastConfig() {
load(TestHazelcastConfig.class);
assertThat(context.getBean(ApplicationStore.class),
is(instanceOf(HazelcastApplicationStore.class)));
assertThat(context.getBean(JournaledEventStore.class),
is(instanceOf(HazelcastJournaledEventStore.class)));
assertTrue(context.getBeansOfType(ApplicationDiscoveryListener.class).isEmpty());
}
@Test
public void discoveryConfig() {
load(NoopDiscoveryClientAutoConfiguration.class);
assertThat(context.getBean(ApplicationStore.class),
is(instanceOf(SimpleApplicationStore.class)));
context.getBean(ApplicationDiscoveryListener.class);
}
@Configuration
static class TestHazelcastConfig {
@Bean
public Config config() {
return new Config();
}
}
private void load(String... environment) {
load(null, environment);
}
private void load(Class<?> config, String... environment) {
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
if (config != null) {
applicationContext.register(config);
}
applicationContext.register(PropertyPlaceholderAutoConfiguration.class);
applicationContext.register(RestTemplateConfiguration.class);
applicationContext.register(ServerPropertiesAutoConfiguration.class);
applicationContext.register(HazelcastAutoConfiguration.class);
applicationContext.register(HazelcastStoreConfiguration.class);
applicationContext.register(DiscoveryClientConfiguration.class);
applicationContext.register(AdminServerCoreConfiguration.class);
applicationContext.register(AdminServerWebConfiguration.class);
EnvironmentTestUtils.addEnvironment(applicationContext, environment);
applicationContext.refresh();
this.context = applicationContext;
}
private AnnotationConfigWebApplicationContext context;
@After
public void close() {
if (this.context != null) {
this.context.close();
}
}
@Test
public void jacksonMapperPresentFromDefault() {
AdminServerWebConfiguration config = new AdminServerWebConfiguration(null, null, null, null);
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2HttpMessageConverter());
config.extendMessageConverters(converters);
assertThat(converters, hasItem(isA(MappingJackson2HttpMessageConverter.class)));
assertThat(converters.size(), is(1));
}
@Test
public void jacksonMapperPresentNeedExtend() {
AdminServerWebConfiguration config = new AdminServerWebConfiguration(null, null, null, null);
List<HttpMessageConverter<?>> converters = new ArrayList<>();
config.extendMessageConverters(converters);
assertThat(converters, hasItem(isA(MappingJackson2HttpMessageConverter.class)));
assertThat(converters.size(), is(1));
}
@Test
public void simpleConfig() {
load();
assertThat(context.getBean(ApplicationStore.class), is(instanceOf(SimpleApplicationStore.class)));
assertTrue(context.getBeansOfType(ApplicationDiscoveryListener.class).isEmpty());
assertTrue(context.getBeansOfType(MailNotifier.class).isEmpty());
assertThat(context.getBean(JournaledEventStore.class), is(instanceOf(SimpleJournaledEventStore.class)));
}
@Test
public void hazelcastConfig() {
load(TestHazelcastConfig.class);
assertThat(context.getBean(ApplicationStore.class), is(instanceOf(HazelcastApplicationStore.class)));
assertThat(context.getBean(JournaledEventStore.class), is(instanceOf(HazelcastJournaledEventStore.class)));
assertTrue(context.getBeansOfType(ApplicationDiscoveryListener.class).isEmpty());
}
@Test
public void discoveryConfig() {
load(SimpleDiscoveryClientAutoConfiguration.class);
assertThat(context.getBean(ApplicationStore.class), is(instanceOf(SimpleApplicationStore.class)));
context.getBean(ApplicationDiscoveryListener.class);
}
@Configuration
static class TestHazelcastConfig {
@Bean
public Config config() {
return new Config();
}
}
private void load(String... environment) {
load(null, environment);
}
private void load(Class<?> config, String... environment) {
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
if (config != null) {
applicationContext.register(config);
}
applicationContext.register(PropertyPlaceholderAutoConfiguration.class);
applicationContext.register(RestTemplateConfiguration.class);
applicationContext.register(ServerPropertiesAutoConfiguration.class);
applicationContext.register(HazelcastAutoConfiguration.class);
applicationContext.register(HazelcastStoreConfiguration.class);
applicationContext.register(DiscoveryClientConfiguration.class);
applicationContext.register(AdminServerCoreConfiguration.class);
applicationContext.register(AdminServerWebConfiguration.class);
EnvironmentTestUtils.addEnvironment(applicationContext, environment);
applicationContext.refresh();
this.context = applicationContext;
}
}
package de.codecentric.boot.admin.config;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import de.codecentric.boot.admin.discovery.DefaultServiceInstanceConverter;
import de.codecentric.boot.admin.discovery.EurekaServiceInstanceConverter;
import de.codecentric.boot.admin.discovery.ServiceInstanceConverter;
import de.codecentric.boot.admin.model.Application;
import org.junit.After;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration.RestTemplateConfiguration;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.noop.NoopDiscoveryClientAutoConfiguration;
import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import com.netflix.discovery.EurekaClient;
import de.codecentric.boot.admin.discovery.DefaultServiceInstanceConverter;
import de.codecentric.boot.admin.discovery.EurekaServiceInstanceConverter;
import de.codecentric.boot.admin.discovery.ServiceInstanceConverter;
import de.codecentric.boot.admin.model.Application;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
public class DiscoveryClientConfigurationTest {
private AnnotationConfigWebApplicationContext context;
@After
public void close() {
if (this.context != null) {
this.context.close();
}
}
@Test
public void defaultServiceInstanceConverter() {
load(NoopDiscoveryClientAutoConfiguration.class);
assertThat(context.getBean(ServiceInstanceConverter.class),
is(instanceOf(DefaultServiceInstanceConverter.class)));
}
@Test
public void eurekaServiceInstanceConverter() {
load(EurekaClientConfig.class);
assertThat(context.getBean(ServiceInstanceConverter.class),
is(instanceOf(EurekaServiceInstanceConverter.class)));
}
@Test
public void customServiceInstanceConverter() {
load(NoopDiscoveryClientAutoConfiguration.class,
TestCustomServiceInstanceConverterConfig.class);
assertThat(context.getBean(ServiceInstanceConverter.class),
is(instanceOf(CustomServiceInstanceConverter.class)));
}
@Configuration
static class TestCustomServiceInstanceConverterConfig {
@Bean
public CustomServiceInstanceConverter converter() {
return new CustomServiceInstanceConverter();
}
}
static class CustomServiceInstanceConverter implements ServiceInstanceConverter {
@Override
public Application convert(ServiceInstance instance) {
return null;
}
}
@Configuration
protected static class EurekaClientConfig {
@Bean
public EurekaClient eurekaClient() {
return Mockito.mock(EurekaClient.class);
}
@Bean
public DiscoveryClient discoveryClient() {
return Mockito.mock(DiscoveryClient.class);
}
}
private void load(Class<?>... configs) {
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
for (Class<?> config : configs) {
applicationContext.register(config);
}
applicationContext.register(PropertyPlaceholderAutoConfiguration.class);
applicationContext.register(RestTemplateConfiguration.class);
applicationContext.register(ServerPropertiesAutoConfiguration.class);
applicationContext.register(AdminServerCoreConfiguration.class);
applicationContext.register(AdminServerWebConfiguration.class);
applicationContext.register(DiscoveryClientConfiguration.class);
applicationContext.refresh();
this.context = applicationContext;
}
private AnnotationConfigWebApplicationContext context;
@After
public void close() {
if (this.context != null) {
this.context.close();
}
}
@Test
public void defaultServiceInstanceConverter() {
load(SimpleDiscoveryClientAutoConfiguration.class);
assertThat(context.getBean(ServiceInstanceConverter.class),
is(instanceOf(DefaultServiceInstanceConverter.class)));
}
@Test
public void eurekaServiceInstanceConverter() {
load(EurekaClientConfig.class);
assertThat(context.getBean(ServiceInstanceConverter.class),
is(instanceOf(EurekaServiceInstanceConverter.class)));
}
@Test
public void customServiceInstanceConverter() {
load(SimpleDiscoveryClientAutoConfiguration.class, TestCustomServiceInstanceConverterConfig.class);
assertThat(context.getBean(ServiceInstanceConverter.class),
is(instanceOf(CustomServiceInstanceConverter.class)));
}
@Configuration
static class TestCustomServiceInstanceConverterConfig {
@Bean
public CustomServiceInstanceConverter converter() {
return new CustomServiceInstanceConverter();
}
}
static class CustomServiceInstanceConverter implements ServiceInstanceConverter {
@Override
public Application convert(ServiceInstance instance) {
return null;
}
}
@Configuration
protected static class EurekaClientConfig {
@Bean
public EurekaClient eurekaClient() {
return Mockito.mock(EurekaClient.class);
}
@Bean
public DiscoveryClient discoveryClient() {
return Mockito.mock(DiscoveryClient.class);
}
}
private void load(Class<?>... configs) {
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
for (Class<?> config : configs) {
applicationContext.register(config);
}
applicationContext.register(PropertyPlaceholderAutoConfiguration.class);
applicationContext.register(RestTemplateConfiguration.class);
applicationContext.register(ServerPropertiesAutoConfiguration.class);
applicationContext.register(AdminServerCoreConfiguration.class);
applicationContext.register(AdminServerWebConfiguration.class);
applicationContext.register(DiscoveryClientConfiguration.class);
applicationContext.refresh();
this.context = applicationContext;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment