@Test
public void testGetUsers()
throws Exception
{
LdapManager ldapManager = this.lookup(LdapManager.class);
List<String> userIds = new ArrayList<String>();
userIds.add("brianf"); // 1
userIds.add("cstamas"); // 1
userIds.add("ehearn"); // 3
userIds.add("jcoder");// 2
userIds.add("jgoodman");// 3
userIds.add("jvanzyl"); // 1
userIds.add("mpowers");// 2
userIds.add("rwalker");// 3
userIds.add("toby");// 2
// exact number
List<String> actualUserIds = new ArrayList<String>();
SortedSet<LdapUser> users = ldapManager.getUsers(userIds.size());
for (LdapUser ldapUser : users) {
actualUserIds.add(ldapUser.getUsername());
}
Assert.assertEquals(userIds, actualUserIds);
// all + 1
actualUserIds.clear();
users = ldapManager.getUsers(userIds.size() + 1);
for (LdapUser ldapUser : users) {
actualUserIds.add(ldapUser.getUsername());
}
Assert.assertEquals(userIds, actualUserIds);
// all -1
userIds = new ArrayList<String>();
actualUserIds.clear();
userIds.add("brianf");
userIds.add("cstamas");
userIds.add("jvanzyl");
userIds.add("jcoder");// 2
userIds.add("mpowers");// 2
userIds.add("toby");// 2
actualUserIds.clear();
users = ldapManager.getUsers(8);
for (LdapUser ldapUser : users) {
actualUserIds.add(ldapUser.getUsername());
}
// we should have all of the first server and then part of the second
Assert.assertTrue("actualUserIds: " + actualUserIds + " does not contain all of: " + userIds, actualUserIds
.containsAll(userIds));
Assert.assertEquals(8, actualUserIds.size());
// 3 but just the first server
userIds = new ArrayList<String>();
actualUserIds.clear();
userIds.add("brianf");
userIds.add("cstamas");
userIds.add("jvanzyl");
actualUserIds.clear();
users = ldapManager.getUsers(3);
for (LdapUser ldapUser : users) {
actualUserIds.add(ldapUser.getUsername());
}
Assert.assertEquals(userIds, actualUserIds);