EurekaServiceInstanceConverterTest.java 2.75 KB
Newer Older
1 2 3 4 5 6 7 8 9
package de.codecentric.boot.admin.discovery;

import static java.util.Collections.singletonMap;
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;

10
import java.net.URI;
11 12 13 14 15 16 17 18 19 20 21

import org.junit.Test;
import org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance;

import com.netflix.appinfo.InstanceInfo;

import de.codecentric.boot.admin.model.Application;

public class EurekaServiceInstanceConverterTest {

	@Test
22
	public void convert_secure() {
23
		InstanceInfo instanceInfo = mock(InstanceInfo.class);
24
		when(instanceInfo.getSecureHealthCheckUrl()).thenReturn("");
25 26 27
		when(instanceInfo.getHealthCheckUrl()).thenReturn("http://localhost:80/mgmt/ping");
		EurekaServiceInstance service = mock(EurekaServiceInstance.class);
		when(service.getInstanceInfo()).thenReturn(instanceInfo);
28 29 30
		when(service.getUri()).thenReturn(URI.create("http://localhost:80"));
		when(service.getServiceId()).thenReturn("test");
		when(service.getMetadata()).thenReturn(singletonMap("management.context-path", "/mgmt"));
31

32
		Application application = new EurekaServiceInstanceConverter().convert(service);
33 34 35 36 37 38

		assertThat(application.getId(), nullValue());
		assertThat(application.getName(), is("test"));
		assertThat(application.getServiceUrl(), is("http://localhost:80"));
		assertThat(application.getManagementUrl(), is("http://localhost:80/mgmt"));
		assertThat(application.getHealthUrl(), is("http://localhost:80/mgmt/ping"));
39 40 41 42 43 44 45 46 47 48 49 50
	}

	@Test
	public void convert_missing_mgmtpath() {
		InstanceInfo instanceInfo = mock(InstanceInfo.class);
		when(instanceInfo.getHealthCheckUrl()).thenReturn("http://localhost:80/mgmt/ping");
		EurekaServiceInstance service = mock(EurekaServiceInstance.class);
		when(service.getInstanceInfo()).thenReturn(instanceInfo);
		when(service.getUri()).thenReturn(URI.create("http://localhost:80"));
		when(service.getServiceId()).thenReturn("test");

		Application application = new EurekaServiceInstanceConverter().convert(service);
51 52 53

		assertThat(application.getManagementUrl(), is("http://localhost:80"));
	}
54 55 56 57 58 59 60 61 62 63 64 65 66 67

	@Test
	public void convert_secure_healthUrl() {
		InstanceInfo instanceInfo = mock(InstanceInfo.class);
		when(instanceInfo.getSecureHealthCheckUrl()).thenReturn("https://localhost:80/health");
		EurekaServiceInstance service = mock(EurekaServiceInstance.class);
		when(service.getInstanceInfo()).thenReturn(instanceInfo);
		when(service.getUri()).thenReturn(URI.create("http://localhost:80"));
		when(service.getServiceId()).thenReturn("test");

		Application application = new EurekaServiceInstanceConverter().convert(service);

		assertThat(application.getHealthUrl(), is("https://localhost:80/health"));
	}
68
}