From 34b1a071241856460eafe9b6706d3d7e5ad00c0f Mon Sep 17 00:00:00 2001 From: Dmitrii_Priporov Date: Sun, 26 Jan 2020 11:07:31 +0300 Subject: [PATCH] Implements ServiceInstance.getScheme() using InstanceInfo. fixes gh-3727 --- .../netflix/eureka/EurekaServiceInstance.java | 4 +++ .../eureka/EurekaServiceInstanceTests.java | 33 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaServiceInstanceTests.java diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaServiceInstance.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaServiceInstance.java index e51be55cf..89e7cd7da 100644 --- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaServiceInstance.java +++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaServiceInstance.java @@ -87,4 +87,8 @@ public class EurekaServiceInstance implements ServiceInstance { return this.instance.getMetadata(); } + @Override + public String getScheme() { + return getUri().getScheme(); + } } diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaServiceInstanceTests.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaServiceInstanceTests.java new file mode 100644 index 000000000..2f7c8624a --- /dev/null +++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaServiceInstanceTests.java @@ -0,0 +1,33 @@ +/* + * Copyright 2013-2020 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.cloud.netflix.eureka; + +import com.netflix.appinfo.InstanceInfo; +import org.assertj.core.api.Assertions; +import org.junit.Test; + +public class EurekaServiceInstanceTests { + + @Test + public void getSchemeReturnsNonNull() { + InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder().setAppName("test") + .setHostName("myhost").setPort(8080).build(); + EurekaServiceInstance instance = new EurekaServiceInstance(instanceInfo); + Assertions.assertThat(instance.getScheme()).isEqualTo("http"); + } +}