@Test public void getStaffMemberDataOfUserReturnsDataAfterInitializationWhenPresent() { var sort = Sort.unsorted(); var otherUserId = "other-user"; var expectedId = 1337L; var expectedFirstName = "First"; var expectedLastName = "Last"; var expectedMail = "mail@test.de"; var expectedLob = "LoB Test"; var expectedThumbnail = new byte[] {2, 1, 32, 4, 7, 42}; var expectedData = new UserData(otherUserMock, expectedFirstName, expectedLastName, expectedMail, expectedLob, expectedThumbnail) .setId(expectedId) .setPictureInitialized(true); var uninitializedData = new UserData(otherUserMock, expectedFirstName, expectedLastName, expectedMail, expectedLob) .setId(expectedId); given(otherUserMock.getId()).willReturn(otherUserId); given(hierarchyTreeNodeRepoMock.findByUser(userMock)).willReturn(Optional.of(hierarchyTreeNodeMock)); given(hierarchyTreeNodeMock.getDirectStaff()).willReturn(List.of(otherHierarchyTreeNodeMock)); given(otherHierarchyTreeNodeMock.getUser()).willReturn(otherUserMock); given(ldapAdapterMock.getThumbnailPhotos(List.of(otherUserId))).willReturn(Map.of( otherUserId, expectedThumbnail )); given(userDataRepoMock.findByUserIn(List.of(otherUserMock), sort)).willReturn(List.of(uninitializedData)); given(userDataRepoMock.saveAll(List.of(expectedData))).willReturn(List.of(expectedData)); var actualData = repoUserService.getStaffMemberUserDataOfUser(userMock, sort); assertThat(actualData).containsExactly(expectedData); }
@Override public List<UserData> getStaffMemberUserDataOfUser(@NonNull User user, @NonNull Sort sort) { var directStaff = getStaffMembersOfUser(user); var directStaffData = dataRepo.findByUserIn(directStaff, sort); if(directStaffData.size() != directStaff.size()) { throw new IllegalStateException("Data for some staff members is not present!"); } return initializeThumbnailPhotos(directStaffData); }
RepositoryUserService implements UserService { @Override public List<UserData> getStaffMemberUserDataOfUser(@NonNull User user, @NonNull Sort sort) { var directStaff = getStaffMembersOfUser(user); var directStaffData = dataRepo.findByUserIn(directStaff, sort); if(directStaffData.size() != directStaff.size()) { throw new IllegalStateException("Data for some staff members is not present!"); } return initializeThumbnailPhotos(directStaffData); } }
RepositoryUserService implements UserService { @Override public List<UserData> getStaffMemberUserDataOfUser(@NonNull User user, @NonNull Sort sort) { var directStaff = getStaffMembersOfUser(user); var directStaffData = dataRepo.findByUserIn(directStaff, sort); if(directStaffData.size() != directStaff.size()) { throw new IllegalStateException("Data for some staff members is not present!"); } return initializeThumbnailPhotos(directStaffData); } RepositoryUserService(UserRepository userRepo,
                                 UserDataRepository dataRepo,
                                 LdapAdapter ldapAdapter,
                                 HierarchyTreeNodeRepository hierarchyTreeNodeRepo,
                                 HibernateSearchService hibernateSearchService); }
RepositoryUserService implements UserService { @Override public List<UserData> getStaffMemberUserDataOfUser(@NonNull User user, @NonNull Sort sort) { var directStaff = getStaffMembersOfUser(user); var directStaffData = dataRepo.findByUserIn(directStaff, sort); if(directStaffData.size() != directStaff.size()) { throw new IllegalStateException("Data for some staff members is not present!"); } return initializeThumbnailPhotos(directStaffData); } RepositoryUserService(UserRepository userRepo,
                                 UserDataRepository dataRepo,
                                 LdapAdapter ldapAdapter,
                                 HierarchyTreeNodeRepository hierarchyTreeNodeRepo,
                                 HibernateSearchService hibernateSearchService); @Override boolean userExists(@NonNull String userId); @Override boolean userIsManager(@NonNull User user); @Override HierarchyTreeNode getHierarchyForUser(@NonNull User user); @Override UserData getUserData(@NonNull User user); @Override User getUserById(@NonNull String userId); @Override boolean userHasStaffMember(@NonNull User user, @NonNull User staffMember); @Override User getManagerOfUser(@NonNull User user); @Override List<UserData> getStaffMemberUserDataOfUser(@NonNull User user, @NonNull Sort sort); @Override List<UserData> searchStaffMemberDataOfUser(User user, String query, Sort sort); @Override List<User> getStaffMembersOfUser(@NonNull User user); @Override User save(@NonNull User user); @Override void delete(User user); @Override void deleteUserById(String userId); @Override Map<User, Boolean> usersAreManagers(@NonNull Set<User> users); User getOrCreateUserById(@NonNull String userId); @Override void removeAllApplicationsOfUser(User user); }
RepositoryUserService implements UserService { @Override public List<UserData> getStaffMemberUserDataOfUser(@NonNull User user, @NonNull Sort sort) { var directStaff = getStaffMembersOfUser(user); var directStaffData = dataRepo.findByUserIn(directStaff, sort); if(directStaffData.size() != directStaff.size()) { throw new IllegalStateException("Data for some staff members is not present!"); } return initializeThumbnailPhotos(directStaffData); } RepositoryUserService(UserRepository userRepo,
                                 UserDataRepository dataRepo,
                                 LdapAdapter ldapAdapter,
                                 HierarchyTreeNodeRepository hierarchyTreeNodeRepo,
                                 HibernateSearchService hibernateSearchService); @Override boolean userExists(@NonNull String userId); @Override boolean userIsManager(@NonNull User user); @Override HierarchyTreeNode getHierarchyForUser(@NonNull User user); @Override UserData getUserData(@NonNull User user); @Override User getUserById(@NonNull String userId); @Override boolean userHasStaffMember(@NonNull User user, @NonNull User staffMember); @Override User getManagerOfUser(@NonNull User user); @Override List<UserData> getStaffMemberUserDataOfUser(@NonNull User user, @NonNull Sort sort); @Override List<UserData> searchStaffMemberDataOfUser(User user, String query, Sort sort); @Override List<User> getStaffMembersOfUser(@NonNull User user); @Override User save(@NonNull User user); @Override void delete(User user); @Override void deleteUserById(String userId); @Override Map<User, Boolean> usersAreManagers(@NonNull Set<User> users); User getOrCreateUserById(@NonNull String userId); @Override void removeAllApplicationsOfUser(User user);  }