RestTemplateTeamOperations implements TeamOperations { @Override @Cacheable(cacheNames = "aws-accounts-by-user", cacheManager = "oneMinuteTTLCacheManager") public List<Account> getAwsAccountsByUser(final String userId) { Assert.hasText(userId, "userId must not be blank"); final String url = baseUrl + "/api/accounts/aws?member={member}&role={role}"; return Stream.of(teamServiceProperties.getAwsMembershipRolesAsArray()) .parallel() .map(role -> ImmutableMap.of("role", role, "member", userId)) .map(queryParams -> restOperations.exchange(url, HttpMethod.GET, null, userTeamListType, queryParams)) .flatMap(response -> response.getBody().stream()) .distinct() .collect(toList()); } RestTemplateTeamOperations(final RestOperations restOperations,
                                      final String baseUrl,
                                      final TeamServiceProperties teamServiceProperties); @Override @Cacheable(cacheNames = "aws-accounts-by-user", cacheManager = "oneMinuteTTLCacheManager") List<Account> getAwsAccountsByUser(final String userId); @Override @Cacheable(cacheNames = "team-ids-by-user", cacheManager = "oneMinuteTTLCacheManager") Set<String> getTeamIdsByUser(final String userId); @Override @Cacheable(cacheNames = "active-aws-accounts", cacheManager = "oneMinuteTTLCacheManager") List<Account> getActiveAccounts();  }
@Test public void getAwsAccountsByUser() throws Exception { properties.setAwsMembershipRoles("PowerUser,MasterOfDisaster"); final String uid = "mickeymouse"; mockAccountsRequest(uid, "PowerUser", "power-user-accounts.json"); mockAccountsRequest(uid, "MasterOfDisaster", "master-of-disaster-accounts.json"); final List<Account> accounts = teamOperations.getAwsAccountsByUser(uid); assertThat(accounts).containsOnly( new Account("111222333444", "firstaccount", "aws", "", "dagobert", false), new Account("555666777888", "secondaccount", "aws", "", "dagobert", false), new Account("999000111222", "thirdaccount", "aws", "", "ticktricktrack", true) ); mockServer.verify(); }