@Test public void extractApps() { Map<String, List<CoffeeNetApp>> apps = new HashMap<>(); CoffeeNetApp coffeeNetApp = new CoffeeNetApp("Coffee App", "coffeeapp.coffeenet", emptySet()); apps.put("cna1", singletonList(coffeeNetApp)); CoffeeNetApp profileApp = new CoffeeNetApp("Profile", "profile.coffeenet", emptySet()); apps.put("profile", singletonList(profileApp)); sut.registerService(CoffeeNetNavigationDataExtractor.CoffeeNetServices.APP_SERVICE, coffeeNetAppServiceMock); when(coffeeNetAppServiceMock.getApps(any())).thenReturn(apps); sut.registerService(CoffeeNetNavigationDataExtractor.CoffeeNetServices.USER_SERVICE, coffeeNetCurrentUserServiceMock); List<GrantedAuthority> authorities = singletonList(new SimpleGrantedAuthority("ROLE_COFFEENET-ADMIN")); Optional<CoffeeNetUserDetails> user = of(new HumanCoffeeNetUser("username", "email", authorities)); when(coffeeNetCurrentUserServiceMock.get()).thenReturn(user); Optional<Map<String, List<CoffeeNetApp>>> extractedApps = sut.extractApps(); Map<String, List<CoffeeNetApp>> coffeeNetApps = extractedApps.get(); assertThat(coffeeNetApps).hasSize(2); assertThat(coffeeNetApps.get("apps")).hasSize(1); assertThat(coffeeNetApps.get("apps").get(0)).isSameAs(coffeeNetApp); assertThat(coffeeNetApps.get("profile")).hasSize(1); assertThat(coffeeNetApps.get("profile").get(0)).isSameAs(profileApp); }
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(); Builder queryBuilder = AppQuery.builder(); userService.ifPresent(coffeeNetCurrentUserService -> coffeeNetCurrentUserService.get() .ifPresent(userDetails -> queryBuilder.withRoles(userDetails.getAuthoritiesAsString()))); Map<String, List<CoffeeNetApp>> filteredCoffeeNetApps = coffeeNetAppService.get() .getApps(queryBuilder.build()); String profileServiceName = coffeeNetNavigationProperties.getProfileServiceName(); List<CoffeeNetApp> profileApps = filteredCoffeeNetApps.get(profileServiceName); if (profileApps != null) { CoffeeNetApp profileApp = profileApps.get(0); filteredCoffeeNetApps.remove(profileServiceName); preparedCoffeeNetApps.put("profile", singletonList(profileApp)); } List<CoffeeNetApp> firstCoffeeNetApps = filteredCoffeeNetApps.entrySet() .stream() .map(entry -> entry.getValue().get(0)) .sorted(Comparator.comparing(CoffeeNetApp::getName, CASE_INSENSITIVE_ORDER)) .collect(toList()); preparedCoffeeNetApps.put("apps", firstCoffeeNetApps); return Optional.of(preparedCoffeeNetApps); }
CoffeeNetNavigationDataExtractor { 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(); Builder queryBuilder = AppQuery.builder(); userService.ifPresent(coffeeNetCurrentUserService -> coffeeNetCurrentUserService.get() .ifPresent(userDetails -> queryBuilder.withRoles(userDetails.getAuthoritiesAsString()))); Map<String, List<CoffeeNetApp>> filteredCoffeeNetApps = coffeeNetAppService.get() .getApps(queryBuilder.build()); String profileServiceName = coffeeNetNavigationProperties.getProfileServiceName(); List<CoffeeNetApp> profileApps = filteredCoffeeNetApps.get(profileServiceName); if (profileApps != null) { CoffeeNetApp profileApp = profileApps.get(0); filteredCoffeeNetApps.remove(profileServiceName); preparedCoffeeNetApps.put("profile", singletonList(profileApp)); } List<CoffeeNetApp> firstCoffeeNetApps = filteredCoffeeNetApps.entrySet() .stream() .map(entry -> entry.getValue().get(0)) .sorted(Comparator.comparing(CoffeeNetApp::getName, CASE_INSENSITIVE_ORDER)) .collect(toList()); preparedCoffeeNetApps.put("apps", firstCoffeeNetApps); return Optional.of(preparedCoffeeNetApps); } }
CoffeeNetNavigationDataExtractor { 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(); Builder queryBuilder = AppQuery.builder(); userService.ifPresent(coffeeNetCurrentUserService -> coffeeNetCurrentUserService.get() .ifPresent(userDetails -> queryBuilder.withRoles(userDetails.getAuthoritiesAsString()))); Map<String, List<CoffeeNetApp>> filteredCoffeeNetApps = coffeeNetAppService.get() .getApps(queryBuilder.build()); String profileServiceName = coffeeNetNavigationProperties.getProfileServiceName(); List<CoffeeNetApp> profileApps = filteredCoffeeNetApps.get(profileServiceName); if (profileApps != null) { CoffeeNetApp profileApp = profileApps.get(0); filteredCoffeeNetApps.remove(profileServiceName); preparedCoffeeNetApps.put("profile", singletonList(profileApp)); } List<CoffeeNetApp> firstCoffeeNetApps = filteredCoffeeNetApps.entrySet() .stream() .map(entry -> entry.getValue().get(0)) .sorted(Comparator.comparing(CoffeeNetApp::getName, CASE_INSENSITIVE_ORDER)) .collect(toList()); preparedCoffeeNetApps.put("apps", firstCoffeeNetApps); return Optional.of(preparedCoffeeNetApps); } CoffeeNetNavigationDataExtractor(CoffeeNetNavigationProperties coffeeNetNavigationProperties); }
CoffeeNetNavigationDataExtractor { 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(); Builder queryBuilder = AppQuery.builder(); userService.ifPresent(coffeeNetCurrentUserService -> coffeeNetCurrentUserService.get() .ifPresent(userDetails -> queryBuilder.withRoles(userDetails.getAuthoritiesAsString()))); Map<String, List<CoffeeNetApp>> filteredCoffeeNetApps = coffeeNetAppService.get() .getApps(queryBuilder.build()); String profileServiceName = coffeeNetNavigationProperties.getProfileServiceName(); List<CoffeeNetApp> profileApps = filteredCoffeeNetApps.get(profileServiceName); if (profileApps != null) { CoffeeNetApp profileApp = profileApps.get(0); filteredCoffeeNetApps.remove(profileServiceName); preparedCoffeeNetApps.put("profile", singletonList(profileApp)); } List<CoffeeNetApp> firstCoffeeNetApps = filteredCoffeeNetApps.entrySet() .stream() .map(entry -> entry.getValue().get(0)) .sorted(Comparator.comparing(CoffeeNetApp::getName, CASE_INSENSITIVE_ORDER)) .collect(toList()); preparedCoffeeNetApps.put("apps", firstCoffeeNetApps); return Optional.of(preparedCoffeeNetApps); } CoffeeNetNavigationDataExtractor(CoffeeNetNavigationProperties coffeeNetNavigationProperties);  }
CoffeeNetNavigationDataExtractor { 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(); Builder queryBuilder = AppQuery.builder(); userService.ifPresent(coffeeNetCurrentUserService -> coffeeNetCurrentUserService.get() .ifPresent(userDetails -> queryBuilder.withRoles(userDetails.getAuthoritiesAsString()))); Map<String, List<CoffeeNetApp>> filteredCoffeeNetApps = coffeeNetAppService.get() .getApps(queryBuilder.build()); String profileServiceName = coffeeNetNavigationProperties.getProfileServiceName(); List<CoffeeNetApp> profileApps = filteredCoffeeNetApps.get(profileServiceName); if (profileApps != null) { CoffeeNetApp profileApp = profileApps.get(0); filteredCoffeeNetApps.remove(profileServiceName); preparedCoffeeNetApps.put("profile", singletonList(profileApp)); } List<CoffeeNetApp> firstCoffeeNetApps = filteredCoffeeNetApps.entrySet() .stream() .map(entry -> entry.getValue().get(0)) .sorted(Comparator.comparing(CoffeeNetApp::getName, CASE_INSENSITIVE_ORDER)) .collect(toList()); preparedCoffeeNetApps.put("apps", firstCoffeeNetApps); return Optional.of(preparedCoffeeNetApps); } CoffeeNetNavigationDataExtractor(CoffeeNetNavigationProperties coffeeNetNavigationProperties);   }