Search in sources :

Example 6 with EurekaServiceInstance

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

the class IntegrationCoffeeNetAppServiceTest method getAppsFilteredByNames.

@Test
public void getAppsFilteredByNames() {
    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("Frontpage").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)

Example 7 with EurekaServiceInstance

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

the class IntegrationCoffeeNetAppServiceTest method getServiceInstance.

private EurekaServiceInstance getServiceInstance(String name, String roles) {
    InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder().setAppName(name).setVIPAddress(name).build();
    if (roles != null) {
        instanceInfo.getMetadata().put("allowedAuthorities", roles);
    }
    EurekaServiceInstance eurekaServiceInstance = mock(EurekaServiceInstance.class);
    when(eurekaServiceInstance.getInstanceInfo()).thenReturn(instanceInfo);
    return eurekaServiceInstance;
}
Also used : EurekaServiceInstance(org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 8 with EurekaServiceInstance

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

the class IntegrationCoffeeNetAppService method toApp.

private static CoffeeNetApp toApp(ServiceInstance serviceInstance) {
    if (!(serviceInstance instanceof EurekaServiceInstance)) {
        return null;
    }
    EurekaServiceInstance eurekaServiceInstance = (EurekaServiceInstance) serviceInstance;
    InstanceInfo instanceInfo = eurekaServiceInstance.getInstanceInfo();
    Set<String> allowedAuthorities = commaDelimitedListToSet(instanceInfo.getMetadata().get("allowedAuthorities")).stream().map(String::trim).collect(toSet());
    return new CoffeeNetApp(instanceInfo.getVIPAddress(), instanceInfo.getHomePageUrl(), allowedAuthorities);
}
Also used : EurekaServiceInstance(org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 9 with EurekaServiceInstance

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

the class IntegrationCoffeeNetAppServiceTest method getAppsFilteredByCaseInsensitiveNames.

@Test
public void getAppsFilteredByCaseInsensitiveNames() {
    String frontPageName = "Frontpage";
    String frontPageNameCI = "frontpage";
    EurekaServiceInstance frontPageWithAdminAndUser = getServiceInstance(frontPageName, null);
    when(discoveryClientMock.getInstances(frontPageName)).thenReturn(singletonList(frontPageWithAdminAndUser));
    when(discoveryClientMock.getServices()).thenReturn(singletonList(frontPageName));
    AppQuery query = AppQuery.builder().withAppName(frontPageNameCI).build();
    Map<String, List<CoffeeNetApp>> coffeeNetApps = coffeeNetAppService.getApps(query);
    assertThat(coffeeNetApps.entrySet(), hasSize(1));
    assertThat(coffeeNetApps.get(frontPageNameCI).get(0).getName(), is(frontPageName));
}
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)

Example 10 with EurekaServiceInstance

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

the class IntegrationCoffeeNetAppServiceTest method getAppsFilteredByRoles.

@Test
public void getAppsFilteredByRoles() {
    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().withRole("ROLE_USER").build();
    Map<String, List<CoffeeNetApp>> coffeeNetApps = coffeeNetAppService.getApps(query);
    assertThat(coffeeNetApps.entrySet(), hasSize(2));
    assertThat(coffeeNetApps.get(backPageName), hasSize(1));
    assertThat(coffeeNetApps.get(backPageName).get(0).getName(), is(backPageName));
    assertThat(coffeeNetApps.get(backPageName).get(0).getAuthorities(), hasItem("ROLE_USER"));
    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