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()));
}
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;
}
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);
}
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));
}
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()));
}
Aggregations