From 98d0da973e6949f5464c1b295bf1899d4cb235ed Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Fri, 25 Jul 2014 06:17:05 -0700 Subject: [PATCH] Clarify serviceUrls --- .../eureka/EurekaClientConfigBean.java | 1 - .../eureka/EurekaClientConfigBeanTests.java | 89 +++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 spring-platform-netflix-core/src/test/java/org/springframework/platform/netflix/eureka/EurekaClientConfigBeanTests.java diff --git a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaClientConfigBean.java b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaClientConfigBean.java index f0ef21c4..58300738 100644 --- a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaClientConfigBean.java +++ b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaClientConfigBean.java @@ -154,7 +154,6 @@ public class EurekaClientConfigBean implements EurekaClientConfig { String serviceUrls = serviceUrl.get(myZone); if (serviceUrls == null || serviceUrls.isEmpty()) { serviceUrls = serviceUrl.get("default"); - } if (serviceUrls != null) { return Arrays.asList(serviceUrls.split(",")); diff --git a/spring-platform-netflix-core/src/test/java/org/springframework/platform/netflix/eureka/EurekaClientConfigBeanTests.java b/spring-platform-netflix-core/src/test/java/org/springframework/platform/netflix/eureka/EurekaClientConfigBeanTests.java new file mode 100644 index 00000000..e68d8aca --- /dev/null +++ b/spring-platform-netflix-core/src/test/java/org/springframework/platform/netflix/eureka/EurekaClientConfigBeanTests.java @@ -0,0 +1,89 @@ +/* + * Copyright 2013-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.platform.netflix.eureka; + +import static org.junit.Assert.assertEquals; + +import org.junit.After; +import org.junit.Test; +import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.test.EnvironmentTestUtils; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Configuration; + +/** + * @author Dave Syer + * + */ +public class EurekaClientConfigBeanTests { + + private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); + + @After + public void init() { + if (context != null) { + context.close(); + } + } + + @Test + public void basicBinding() { + EnvironmentTestUtils.addEnvironment(context, + "eureka.client.proxyHost=example.com"); + context.register(PropertyPlaceholderAutoConfiguration.class, + TestConfiguration.class); + context.refresh(); + assertEquals("example.com", context.getBean(EurekaClientConfigBean.class) + .getProxyHost()); + } + + @Test + public void serviceUrl() { + EnvironmentTestUtils.addEnvironment(context, + "eureka.client.serviceUrl.defaultZone:http://example.com"); + context.register(PropertyPlaceholderAutoConfiguration.class, + TestConfiguration.class); + context.refresh(); + assertEquals("{defaultZone=http://example.com}", + context.getBean(EurekaClientConfigBean.class).getServiceUrl().toString()); + assertEquals( + "[http://example.com]", + context.getBean(EurekaClientConfigBean.class) + .getEurekaServerServiceUrls("defaultZone").toString()); + } + + @Test + public void serviceUrlWithDefault() { + EnvironmentTestUtils.addEnvironment(context, + "eureka.client.serviceUrl.defaultZone:", + "eureka.client.serviceUrl.default:http://example.com"); + context.register(PropertyPlaceholderAutoConfiguration.class, + TestConfiguration.class); + context.refresh(); + assertEquals( + "[http://example.com]", + context.getBean(EurekaClientConfigBean.class) + .getEurekaServerServiceUrls("defaultZone").toString()); + } + + @Configuration + @EnableConfigurationProperties(EurekaClientConfigBean.class) + protected static class TestConfiguration { + + } + +}