1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.test.service;
17
18 import org.junit.Ignore;
19 import org.junit.Test;
20 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
21 import org.kuali.rice.kim.api.KimApiConstants;
22 import org.kuali.rice.kim.api.group.Group;
23 import org.kuali.rice.kim.api.group.GroupMember;
24 import org.kuali.rice.kim.impl.group.GroupServiceImpl;
25 import org.kuali.rice.kim.test.KIMTestCase;
26
27 import javax.xml.namespace.QName;
28 import java.util.ArrayList;
29 import java.util.Collection;
30 import java.util.List;
31
32 import static org.junit.Assert.assertFalse;
33 import static org.junit.Assert.assertTrue;
34
35
36
37
38
39
40
41 @Ignore
42 public class GroupServiceImplTest extends KIMTestCase {
43
44 private GroupServiceImpl groupService;
45
46 public void setUp() throws Exception {
47 super.setUp();
48 groupService = (GroupServiceImpl)GlobalResourceLoader.getService(KimApiConstants.ServiceNames.GROUP_SERVICE_SOAP);
49 }
50
51 @Test
52 public void testGetDirectMemberGroupIds() {
53 List<String> groupIds = groupService.getDirectMemberGroupIds("g1");
54
55 assertTrue( "g1 must contain group g2", groupIds.contains( "g2" ) );
56 assertFalse( "g1 must not contain group g3", groupIds.contains( "g3" ) );
57
58 groupIds = groupService.getDirectMemberGroupIds("g2");
59
60 assertTrue( "g2 must contain group g3", groupIds.contains( "g3" ) );
61 assertFalse( "g2 must not contain group g4 (inactive)", groupIds.contains( "g4" ) );
62
63 }
64
65 @Test
66 public void testGetMemberGroupIds() {
67 List<String> groupIds = groupService.getMemberGroupIds("g1");
68
69 assertTrue( "g1 must contain group g2", groupIds.contains( "g2" ) );
70 assertTrue( "g1 must contain group g3", groupIds.contains( "g3" ) );
71 assertFalse( "g1 must not contain group g4 (inactive)", groupIds.contains( "g4" ) );
72
73 groupIds = groupService.getMemberGroupIds("g2");
74
75 assertTrue( "g2 must contain group g3", groupIds.contains( "g3" ) );
76 assertFalse( "g2 must not contain group g1", groupIds.contains( "g1" ) );
77 }
78
79
80 @Test
81 public void testPrincipalMembership() {
82 assertTrue( "p1 must be in g2", groupService.isMemberOfGroup("p1", "g2") );
83 assertTrue( "p1 must be direct member of g2", groupService.isDirectMemberOfGroup("p1", "g2") );
84 assertTrue( "p3 must be in g2", groupService.isMemberOfGroup("p3", "g2") );
85 assertFalse( "p3 should not be a direct member of g2", groupService.isDirectMemberOfGroup("p3", "g2") );
86 assertFalse( "p4 should not be reported as a member of g2 (g4 is inactive)", groupService.isMemberOfGroup("p4", "g2") );
87
88
89 Group g4Info = groupService.getGroup("g4");
90 Group.Builder builder = Group.Builder.create(g4Info);
91 builder.setActive(true);
92 groupService.updateGroup("g4", builder.build());
93
94 assertTrue( "p4 should be reported as a member of g2 (now that g4 is active)", groupService.isMemberOfGroup("p4", "g2") );
95
96 }
97
98
99
100 @Test
101 public void testCircularGetMembers() {
102
103 List<String> pIds = groupService.getMemberPrincipalIds("g101");
104 assertTrue( "group A should have 3 members", pIds.size() == 3 );
105 assertTrue( "group A should have member p1", pIds.contains( "p1" ) );
106 assertTrue( "group A should have member p3", pIds.contains( "p3" ) );
107 assertTrue( "group A should have member p5", pIds.contains( "p5" ) );
108
109
110
111 boolean isIt = groupService.isMemberOfGroup("p2", "g101");
112 assertFalse( "p2 should not be a member of Group A", isIt );
113
114 List<String> gIds = groupService.getGroupIdsForPrincipal("p1");
115 assertTrue( "p1 should be a member of Group A", gIds.contains("g101"));
116 assertTrue( "p1 should be a member of Group B", gIds.contains("g102"));
117 assertTrue( "p1 should be a member of Group C", gIds.contains("g103"));
118
119 gIds = groupService.getGroupIdsForPrincipalByNamespace("p1", "ADDL_GROUPS_TESTS");
120 assertTrue( "p1 should be a member of Group A", gIds.contains("g101"));
121 assertTrue( "p1 should be a member of Group B", gIds.contains("g102"));
122 assertTrue( "p1 should be a member of Group C", gIds.contains("g103"));
123
124 List<String> inList = new ArrayList<String>();
125 inList.add("g101");
126 inList.add("g102");
127 Collection<GroupMember> gMembership = groupService.getMembers(inList);
128 assertTrue( "Should return 4 members total.", gMembership.size() == 4);
129
130 gMembership = groupService.getMembersOfGroup("g102");
131 assertTrue( "Group B should have 2 members.", gMembership.size() == 2);
132
133 List<Group> gInfo = groupService.getGroupsForPrincipal("p1");
134 assertTrue( "p1 should be a member of at least 3 groups.", gInfo.size() >= 3);
135
136 gInfo = groupService.getGroupsForPrincipalByNamespace("p1", "ADDL_GROUPS_TESTS");
137 assertTrue( "p1 should be a member of exactly 3 groups with namespace = ADDL_GROUPS_TESTS.", gInfo.size() == 3);
138
139 gIds = groupService.getMemberGroupIds("g101");
140 assertTrue( "Group A should have 3 member groups", gIds.size() == 3);
141 assertTrue( "Group B should be a member Group of Group A", gIds.contains("g102"));
142 assertTrue( "Group C should be a member Group of Group A", gIds.contains("g103"));
143 assertTrue( "Since these groups have a circular membership, Group A should have itself as a group member", gIds.contains("g101"));
144
145 gIds = groupService.getParentGroupIds("g101");
146 assertTrue( "Group A should have 3 parent groups", gIds.size() == 3);
147 assertTrue( "Group B should be a parent of Group A", gIds.contains("g102"));
148 assertTrue( "Group C should be a parent of Group A", gIds.contains("g103"));
149 assertTrue( "Since these groups have a circular membership, Group A should be a parent of itself", gIds.contains("g101"));
150 }
151
152
153 }