1   package com.atlassian.user.impl.ldap.adaptor;
2   
3   import com.atlassian.user.Group;
4   import com.atlassian.user.User;
5   import com.atlassian.user.impl.ldap.AbstractLdapTest;
6   import com.atlassian.user.impl.ldap.LDAPUserManagerReadOnly;
7   import com.atlassian.user.search.page.Pager;
8   
9   import java.util.Iterator;
10  
11  public class TestLDAPStaticGroupAdaptor extends AbstractLdapTest
12  {
13      private LDAPUserManagerReadOnly userManager;
14      private LDAPGroupAdaptor groupAdaptor;
15  
16      public void setLdapUserManager(LDAPUserManagerReadOnly userManager)
17      {
18          this.userManager = userManager;
19      }
20  
21      public void setLdapGroupAdaptor(LDAPGroupAdaptor groupAdaptor)
22      {
23          this.groupAdaptor = groupAdaptor;
24      }
25  
26      protected String getLdapConfigLocation()
27      {
28          return "classpath:com/atlassian/user/impl/ldap/static/ldapStaticJDoeAnd101GroupsContext.xml";
29      }
30  
31      /**
32       * Currently we only prefetch 100 results. So in the case of getGroups() do only fetch 100 groups (even if the user belongs to more).
33       * We want to test here that getGroups() does in fact return a pager that contains all these groups.
34       * We also want to test that membership checks work on groups the user belongs to that are beyond the initial 100.
35       *
36       * @throws Exception
37       */
38      public void testGetGroupsReturnsAllGroupsAndHasMembershipOnLastGroupWorks() throws Exception
39      {
40          User jdoe = userManager.getUser("jdoe");
41          Pager groups = groupAdaptor.getGroups(jdoe);
42  
43          int i = 0;
44          for (Iterator iterator = groups.iterator(); iterator.hasNext();)
45          {
46              Group group = (Group) iterator.next();
47              if (++i == 101)
48                  assertEquals("group101", group.getName()); // 101st group john belongs to is called "group101"
49          }
50  
51          assertEquals(101, i);
52  
53          // check that john doe is a member of group101
54          Group group101 = groupAdaptor.getGroup("group101");
55          groupAdaptor.hasMembership(group101, jdoe);
56      }
57  }