Search in sources :

Example 1 with EurekaServiceInstance

use of org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance in project spring-boot-admin by codecentric.

the class EurekaServiceInstanceConverterTest method convert_secure_healthUrl.

@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"));
}
Also used : EurekaServiceInstance(org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance) InstanceInfo(com.netflix.appinfo.InstanceInfo) Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Example 2 with EurekaServiceInstance

use of org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance in project spring-boot-admin by codecentric.

the class EurekaServiceInstanceConverterTest method convert_secure.

@Test
public void convert_secure() {
    InstanceInfo instanceInfo = mock(InstanceInfo.class);
    when(instanceInfo.getSecureHealthCheckUrl()).thenReturn("");
    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");
    when(service.getMetadata()).thenReturn(singletonMap("management.context-path", "/mgmt"));
    Application application = new EurekaServiceInstanceConverter().convert(service);
    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"));
}
Also used : EurekaServiceInstance(org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance) InstanceInfo(com.netflix.appinfo.InstanceInfo) Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Example 3 with EurekaServiceInstance

use of org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance in project spring-boot-admin by codecentric.

the class EurekaServiceInstanceConverterTest method convert_missing_mgmtpath.

@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);
    assertThat(application.getManagementUrl(), is("http://localhost:80"));
}
Also used : EurekaServiceInstance(org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance) InstanceInfo(com.netflix.appinfo.InstanceInfo) Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Example 4 with EurekaServiceInstance

use of org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance in project spring-boot-admin by codecentric.

the class EurekaServiceInstanceConverter method getHealthUrl.

@Override
protected URI getHealthUrl(ServiceInstance instance) {
    Assert.isInstanceOf(EurekaServiceInstance.class, instance, "serviceInstance must be of type EurekaServiceInstance");
    InstanceInfo instanceInfo = ((EurekaServiceInstance) instance).getInstanceInfo();
    String healthUrl = instanceInfo.getSecureHealthCheckUrl();
    if (StringUtils.isEmpty(healthUrl)) {
        healthUrl = instanceInfo.getHealthCheckUrl();
    }
    return URI.create(healthUrl);
}
Also used : EurekaServiceInstance(org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 5 with EurekaServiceInstance

use of org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance in project coffeenet-starter by coffeenet.

the class IntegrationCoffeeNetAppServiceTest method getAppsFilteredByAppNamesAndRoles.

@Test
public void getAppsFilteredByAppNamesAndRoles() {
    String frontPageName = "Frontpage";
    EurekaServiceInstance frontPage = getServiceInstance(frontPageName, null);
    EurekaServiceInstance frontPageWithUser = getServiceInstance(frontPageName, "ROLE_USER");
    EurekaServiceInstance frontPageWithAdminAndUser = getServiceInstance(frontPageName, "ROLE_USER, ROLE_ADMIN");
    when(discoveryClientMock.getInstances(frontPageName)).thenReturn(asList(frontPageWithUser, frontPageWithAdminAndUser, frontPage));
    String backPageName = "Backpage";
    EurekaServiceInstance backPage = getServiceInstance(backPageName, "ROLE_USER, ROLE_ADMIN");
    when(discoveryClientMock.getInstances(backPageName)).thenReturn(singletonList(backPage));
    when(discoveryClientMock.getServices()).thenReturn(asList(frontPageName, backPageName));
    AppQuery query = AppQuery.builder().withAppName(frontPageName).withRole("ROLE_USER").build();
    Map<String, List<CoffeeNetApp>> coffeeNetApps = coffeeNetAppService.getApps(query);
    assertThat(coffeeNetApps.entrySet(), hasSize(1));
    assertThat(coffeeNetApps.get(frontPageName), hasSize(3));
    assertThat(coffeeNetApps.get(frontPageName).get(0).getName(), is(frontPageName));
    assertThat(coffeeNetApps.get(frontPageName).get(0).getAuthorities(), hasItem("ROLE_USER"));
    assertThat(coffeeNetApps.get(frontPageName).get(1).getName(), is(frontPageName));
    assertThat(coffeeNetApps.get(frontPageName).get(1).getAuthorities(), hasItem("ROLE_USER"));
    assertThat(coffeeNetApps.get(frontPageName).get(2).getName(), is(frontPageName));
    assertThat(coffeeNetApps.get(frontPageName).get(2).getAuthorities(), is(empty()));
}
Also used : EurekaServiceInstance(org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance) Collections.emptyList(java.util.Collections.emptyList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Test(org.junit.Test)

Aggregations

EurekaServiceInstance (org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance)11 Test (org.junit.Test)8 InstanceInfo (com.netflix.appinfo.InstanceInfo)6 Arrays.asList (java.util.Arrays.asList)5 Collections.emptyList (java.util.Collections.emptyList)5 Collections.singletonList (java.util.Collections.singletonList)5 List (java.util.List)5 Application (de.codecentric.boot.admin.model.Application)3