| 
 | 1 | +/*  | 
 | 2 | + * Copyright 2013-2020 the original author or authors.  | 
 | 3 | + *  | 
 | 4 | + * Licensed under the Apache License, Version 2.0 (the "License");  | 
 | 5 | + * you may not use this file except in compliance with the License.  | 
 | 6 | + * You may obtain a copy of the License at  | 
 | 7 | + *  | 
 | 8 | + *      https://www.apache.org/licenses/LICENSE-2.0  | 
 | 9 | + *  | 
 | 10 | + * Unless required by applicable law or agreed to in writing, software  | 
 | 11 | + * distributed under the License is distributed on an "AS IS" BASIS,  | 
 | 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
 | 13 | + * See the License for the specific language governing permissions and  | 
 | 14 | + * limitations under the License.  | 
 | 15 | + */  | 
 | 16 | + | 
 | 17 | +package org.springframework.cloud.kubernetes.discovery;  | 
 | 18 | + | 
 | 19 | +import java.util.Collections;  | 
 | 20 | + | 
 | 21 | +import io.fabric8.kubernetes.api.model.EndpointAddress;  | 
 | 22 | +import io.fabric8.kubernetes.api.model.EndpointPort;  | 
 | 23 | +import org.junit.Test;  | 
 | 24 | + | 
 | 25 | +import static org.assertj.core.api.Assertions.assertThat;  | 
 | 26 | + | 
 | 27 | +public class KubernetesServiceInstanceTests {  | 
 | 28 | + | 
 | 29 | +	@Test  | 
 | 30 | +	public void schemeIsHttp() {  | 
 | 31 | +		assertServiceInstance(false);  | 
 | 32 | +	}  | 
 | 33 | + | 
 | 34 | +	private KubernetesServiceInstance assertServiceInstance(boolean secure) {  | 
 | 35 | +		EndpointAddress address = new EndpointAddress();  | 
 | 36 | +		address.setIp("1.2.3.4");  | 
 | 37 | +		EndpointPort port = new EndpointPort();  | 
 | 38 | +		port.setPort(8080);  | 
 | 39 | +		KubernetesServiceInstance instance = new KubernetesServiceInstance("123",  | 
 | 40 | +			"myservice", address, port, Collections.emptyMap(), secure);  | 
 | 41 | + | 
 | 42 | +		assertThat(instance.getInstanceId()).isEqualTo("123");  | 
 | 43 | +		assertThat(instance.getServiceId()).isEqualTo("myservice");  | 
 | 44 | +		assertThat(instance.getHost()).isEqualTo("1.2.3.4");  | 
 | 45 | +		assertThat(instance.getPort()).isEqualTo(8080);  | 
 | 46 | +		assertThat(instance.isSecure()).isEqualTo(secure);  | 
 | 47 | +		assertThat(instance.getScheme()).isEqualTo(secure ? "https" : "http");  | 
 | 48 | +		return instance;  | 
 | 49 | +	}  | 
 | 50 | + | 
 | 51 | +	@Test  | 
 | 52 | +	public void schemeIsHttps() {  | 
 | 53 | +		assertServiceInstance(true);  | 
 | 54 | +	}  | 
 | 55 | + | 
 | 56 | +}  | 
0 commit comments