use of coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp in project coffeenet-starter by coffeenet.
the class CoffeeNetWebServiceImplTest method getNoProfileApp.
@Test
public void getNoProfileApp() {
Optional<CoffeeNetWebUser> coffeeNetWebUser = Optional.of(new CoffeeNetWebUser("username", "email"));
when(coffeeNetWebExtractorMock.extractUser()).thenReturn(coffeeNetWebUser);
Map<String, List<CoffeeNetApp>> apps = new HashMap<>();
CoffeeNetApp coffeeNetApp = new CoffeeNetApp("Coffee App", "coffeeapp.coffeenet", emptySet());
apps.put("apps", singletonList(coffeeNetApp));
when(coffeeNetWebExtractorMock.extractApps()).thenReturn(Optional.of(apps));
when(coffeeNetWebExtractorMock.extractLogoutPath()).thenReturn("/logout");
CoffeeNetWeb coffeeNetWeb = sut.get();
assertThat(coffeeNetWeb.getLogoutPath()).isEqualTo("/logout");
assertThat(coffeeNetWeb.getCoffeeNetWebUser().getUsername()).isSameAs("username");
assertThat(coffeeNetWeb.getCoffeeNetWebUser().getEmail()).isSameAs("email");
assertThat(coffeeNetWeb.getProfileApp()).isNull();
assertThat(coffeeNetWeb.getCoffeeNetApps()).hasSize(1);
assertThat(coffeeNetWeb.getCoffeeNetApps().get(0)).isSameAs(coffeeNetApp);
}
use of coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp in project coffeenet-starter by coffeenet.
the class CoffeeNetWebServiceImplTest method get.
@Test
public void get() {
Optional<CoffeeNetWebUser> coffeeNetWebUser = Optional.of(new CoffeeNetWebUser("username", "email"));
when(coffeeNetWebExtractorMock.extractUser()).thenReturn(coffeeNetWebUser);
Map<String, List<CoffeeNetApp>> apps = new HashMap<>();
CoffeeNetApp coffeeNetApp = new CoffeeNetApp("Coffee App", "coffeeapp.coffeenet", emptySet());
apps.put("apps", singletonList(coffeeNetApp));
CoffeeNetApp profileApp = new CoffeeNetApp("Profile", "profile.coffeenet", emptySet());
apps.put("profile", singletonList(profileApp));
when(coffeeNetWebExtractorMock.extractApps()).thenReturn(Optional.of(apps));
when(coffeeNetWebExtractorMock.extractLogoutPath()).thenReturn("/logout");
CoffeeNetWeb coffeeNetWeb = sut.get();
assertThat(coffeeNetWeb.getLogoutPath()).isEqualTo("/logout");
assertThat(coffeeNetWeb.getCoffeeNetWebUser().getUsername()).isSameAs("username");
assertThat(coffeeNetWeb.getCoffeeNetWebUser().getEmail()).isSameAs("email");
assertThat(coffeeNetWeb.getProfileApp()).isSameAs(profileApp);
assertThat(coffeeNetWeb.getCoffeeNetApps()).hasSize(1);
assertThat(coffeeNetWeb.getCoffeeNetApps().get(0)).isSameAs(coffeeNetApp);
}
use of coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp in project coffeenet-starter by coffeenet.
the class CoffeeNetWebServiceImplTest method getNoUser.
@Test
public void getNoUser() {
when(coffeeNetWebExtractorMock.extractUser()).thenReturn(Optional.empty());
Map<String, List<CoffeeNetApp>> apps = new HashMap<>();
CoffeeNetApp coffeeNetApp = new CoffeeNetApp("Coffee App", "coffeeapp.coffeenet", emptySet());
apps.put("apps", singletonList(coffeeNetApp));
CoffeeNetApp profileApp = new CoffeeNetApp("Profile", "profile.coffeenet", emptySet());
apps.put("profile", singletonList(profileApp));
when(coffeeNetWebExtractorMock.extractApps()).thenReturn(Optional.of(apps));
when(coffeeNetWebExtractorMock.extractLogoutPath()).thenReturn("/logout");
CoffeeNetWeb coffeeNetWeb = sut.get();
assertThat(coffeeNetWeb.getLogoutPath()).isEqualTo("/logout");
assertThat(coffeeNetWeb.getCoffeeNetWebUser()).isNull();
assertThat(coffeeNetWeb.getProfileApp()).isSameAs(profileApp);
assertThat(coffeeNetWeb.getCoffeeNetApps()).hasSize(1);
assertThat(coffeeNetWeb.getCoffeeNetApps().get(0)).isSameAs(coffeeNetApp);
}
use of coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp in project coffeenet-starter by coffeenet.
the class CoffeeNetWebExtractor method extractApps.
/**
* Extracts a map of bundled {@link CoffeeNetApp}s by their category. At this time there are only 'apps' and
* 'profile' as keys
*
* @return map of {@link CoffeeNetApp}s
*/
Optional<Map<String, List<CoffeeNetApp>>> extractApps() {
Optional<CoffeeNetAppService> coffeeNetAppService = getCoffeeNetAppService();
if (!coffeeNetAppService.isPresent()) {
return Optional.empty();
}
Map<String, List<CoffeeNetApp>> preparedCoffeeNetApps = new HashMap<>();
Optional<CoffeeNetCurrentUserService> userService = getCoffeeNetCurrentUserService();
// create to retrieve CoffeeNet apps
Builder queryBuilder = AppQuery.builder();
// add user roles to query if there is a CoffeeNet user
userService.ifPresent(coffeeNetCurrentUserService -> coffeeNetCurrentUserService.get().ifPresent(userDetails -> queryBuilder.withRoles(userDetails.getAuthoritiesAsString())));
Map<String, List<CoffeeNetApp>> filteredCoffeeNetApps = coffeeNetAppService.get().getApps(queryBuilder.build());
// extract profile application
String profileServiceName = coffeeNetWebProperties.getProfileServiceName();
List<CoffeeNetApp> profileApps = filteredCoffeeNetApps.get(profileServiceName);
if (profileApps != null) {
CoffeeNetApp profileApp = profileApps.get(0);
filteredCoffeeNetApps.remove(profileServiceName);
preparedCoffeeNetApps.put("profile", singletonList(profileApp));
}
// retrieve all CoffeeNetApps
List<CoffeeNetApp> firstCoffeeNetApps = filteredCoffeeNetApps.entrySet().stream().map(entry -> entry.getValue().get(0)).sorted(Comparator.comparing(CoffeeNetApp::getName)).collect(toList());
preparedCoffeeNetApps.put("apps", firstCoffeeNetApps);
return Optional.of(preparedCoffeeNetApps);
}
use of coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp in project coffeenet-starter by coffeenet.
the class CoffeeNetWebServiceImpl method get.
@Override
public CoffeeNetWeb get() {
CoffeeNetWebUser coffeeNetWebUser = coffeeNetWebExtractor.extractUser().orElse(null);
Map<String, List<CoffeeNetApp>> apps = coffeeNetWebExtractor.extractApps().orElseGet(Collections::emptyMap);
String logoutPath = coffeeNetWebExtractor.extractLogoutPath();
List<CoffeeNetApp> profileApps = apps.get("profile");
CoffeeNetApp profileApp = null;
if (profileApps != null && !profileApps.isEmpty()) {
profileApp = profileApps.get(0);
}
List<CoffeeNetApp> coffeeNetApps = apps.get("apps");
return new CoffeeNetWeb(coffeeNetWebUser, coffeeNetApps, profileApp, logoutPath);
}
Aggregations