@Test @SuppressWarnings("serial") public void testCleanUpLdapUsersWithoutGroup() throws AmbariException { final Configuration configuration = createNiceMock(Configuration.class); final Users users = createNiceMock(Users.class); final GroupEntity ldapGroup = new GroupEntity(); ldapGroup.setGroupId(1); ldapGroup.setGroupName("ldapGroup"); ldapGroup.setGroupType(GroupType.LDAP); ldapGroup.setMemberEntities(new HashSet<MemberEntity>()); final User ldapUserWithoutGroup = createLdapUserWithoutGroup(); final User ldapUserWithGroup = createLdapUserWithGroup(ldapGroup); final User localUserWithoutGroup = createLocalUserWithoutGroup(); final User localUserWithGroup = createLocalUserWithGroup(ldapGroup); final List<User> allUsers = new ArrayList<User>() { { add(ldapUserWithoutGroup); add(ldapUserWithGroup); add(localUserWithoutGroup); add(localUserWithGroup); } }; expect(users.getAllUsers()).andReturn(new ArrayList<User>(allUsers)); final List<User> removedUsers = new ArrayList<User>(); final Capture<User> userCapture = EasyMock.newCapture(); users.removeUser(capture(userCapture)); expectLastCall().andAnswer(new IAnswer<Void>() { @Override public Void answer() throws Throwable { removedUsers.add(userCapture.getValue()); allUsers.remove(userCapture.getValue()); return null; } }); replay(users); final AmbariLdapDataPopulatorTestInstance populator = new AmbariLdapDataPopulatorTestInstance(configuration, users); populator.setLdapTemplate(createNiceMock(LdapTemplate.class)); populator.setLdapServerProperties(createNiceMock(LdapServerProperties.class)); populator.cleanUpLdapUsersWithoutGroup(); assertEquals(removedUsers.size(), 1); assertEquals(allUsers.size(), 3); assertTrue(allUsers.contains(ldapUserWithGroup)); assertTrue(allUsers.contains(localUserWithoutGroup)); assertTrue(allUsers.contains(localUserWithGroup)); assertEquals(removedUsers.get(0), ldapUserWithoutGroup); verify(users); }
protected void cleanUpLdapUsersWithoutGroup() throws AmbariException { final List<User> allUsers = users.getAllUsers(); for (User user : allUsers) { if (user.isLdapUser() && user.getGroups().isEmpty()) { users.removeUser(user); } } }
AmbariLdapDataPopulator { protected void cleanUpLdapUsersWithoutGroup() throws AmbariException { final List<User> allUsers = users.getAllUsers(); for (User user : allUsers) { if (user.isLdapUser() && user.getGroups().isEmpty()) { users.removeUser(user); } } } }
AmbariLdapDataPopulator { protected void cleanUpLdapUsersWithoutGroup() throws AmbariException { final List<User> allUsers = users.getAllUsers(); for (User user : allUsers) { if (user.isLdapUser() && user.getGroups().isEmpty()) { users.removeUser(user); } } } @Inject  AmbariLdapDataPopulator(Configuration configuration, Users users); }
AmbariLdapDataPopulator { protected void cleanUpLdapUsersWithoutGroup() throws AmbariException { final List<User> allUsers = users.getAllUsers(); for (User user : allUsers) { if (user.isLdapUser() && user.getGroups().isEmpty()) { users.removeUser(user); } } } @Inject  AmbariLdapDataPopulator(Configuration configuration, Users users); boolean isLdapEnabled(); LdapSyncDto getLdapSyncInfo(); LdapBatchDto synchronizeAllLdapGroups(LdapBatchDto batchInfo); LdapBatchDto synchronizeAllLdapUsers(LdapBatchDto batchInfo); LdapBatchDto synchronizeLdapGroups(Set<String> groups, LdapBatchDto batchInfo); LdapBatchDto synchronizeLdapUsers(Set<String> users, LdapBatchDto batchInfo); LdapBatchDto synchronizeExistingLdapGroups(LdapBatchDto batchInfo); LdapBatchDto synchronizeExistingLdapUsers(LdapBatchDto batchInfo); }
AmbariLdapDataPopulator { protected void cleanUpLdapUsersWithoutGroup() throws AmbariException { final List<User> allUsers = users.getAllUsers(); for (User user : allUsers) { if (user.isLdapUser() && user.getGroups().isEmpty()) { users.removeUser(user); } } } @Inject  AmbariLdapDataPopulator(Configuration configuration, Users users); boolean isLdapEnabled(); LdapSyncDto getLdapSyncInfo(); LdapBatchDto synchronizeAllLdapGroups(LdapBatchDto batchInfo); LdapBatchDto synchronizeAllLdapUsers(LdapBatchDto batchInfo); LdapBatchDto synchronizeLdapGroups(Set<String> groups, LdapBatchDto batchInfo); LdapBatchDto synchronizeLdapUsers(Set<String> users, LdapBatchDto batchInfo); LdapBatchDto synchronizeExistingLdapGroups(LdapBatchDto batchInfo); LdapBatchDto synchronizeExistingLdapUsers(LdapBatchDto batchInfo);  }