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.Test;
19 import org.kuali.rice.kim.api.group.Group;
20 import org.kuali.rice.kim.api.group.GroupService;
21 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
22 import org.kuali.rice.kim.test.KIMTestCase;
23 import org.kuali.rice.test.BaselineTestCase;
24
25 import java.util.List;
26
27 import static org.junit.Assert.*;
28
29
30
31
32
33
34
35 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.ROLLBACK_CLEAR_DB)
36 public class GroupServiceTest extends KIMTestCase {
37
38 private GroupService groupService;
39
40 public void setUp() throws Exception {
41 super.setUp();
42 setGroupService(KimApiServiceLocator.getGroupService());
43 }
44
45 @Test
46 public void testGetGroup() {
47 Group g7 = groupService.getGroup("g7");
48 assertNotNull(g7);
49 assertEquals("GroupSeven", g7.getName());
50 assertEquals("KUALI", g7.getNamespaceCode());
51 assertEquals("Group Seven", g7.getDescription());
52
53
54
55 Group g8 = groupService.getGroup("g8");
56 assertNotNull(g8);
57 assertEquals("GroupEight", g8.getName());
58 assertEquals("KUALI", g8.getNamespaceCode());
59 assertEquals("Group Eight", g8.getDescription());
60 }
61
62 @Test
63 public void testGetDirectMemberGroupIds() {
64 List<String> groupIds = groupService.getDirectMemberGroupIds("g1");
65
66 assertTrue( "g1 must contain group g2", groupIds.contains( "g2" ) );
67 assertFalse( "g1 must not contain group g3", groupIds.contains( "g3" ) );
68
69 groupIds = groupService.getDirectMemberGroupIds("g2");
70
71 assertTrue( "g2 must contain group g3", groupIds.contains( "g3" ) );
72 assertFalse( "g2 must not contain group g4 (inactive)", groupIds.contains( "g4" ) );
73
74 }
75
76 @Test
77 public void testGetMemberGroupIds() {
78 List<String> groupIds = groupService.getMemberGroupIds("g1");
79
80 assertTrue( "g1 must contain group g2", groupIds.contains( "g2" ) );
81 assertTrue( "g1 must contain group g3", groupIds.contains( "g3" ) );
82 assertFalse( "g1 must not contain group g4 (inactive)", groupIds.contains( "g4" ) );
83
84 groupIds = groupService.getMemberGroupIds("g2");
85
86 assertTrue( "g2 must contain group g3", groupIds.contains( "g3" ) );
87 assertFalse( "g2 must not contain group g1", groupIds.contains( "g1" ) );
88 }
89
90
91 @Test
92 public void testPrincipalMembership() {
93 assertTrue( "p1 must be in g2", groupService.isMemberOfGroup("p1", "g2") );
94 assertTrue( "p1 must be direct member of g2", groupService.isDirectMemberOfGroup("p1", "g2") );
95 assertTrue( "p3 must be in g2", groupService.isMemberOfGroup("p3", "g2") );
96 assertFalse( "p3 should not be a direct member of g2", groupService.isDirectMemberOfGroup("p3", "g2") );
97 assertFalse( "p4 should not be reported as a member of g2 (g4 is inactive)", groupService.isMemberOfGroup("p4", "g2") );
98
99
100 Group g4Info = groupService.getGroup("g4");
101 Group.Builder builder = Group.Builder.create(g4Info);
102 builder.setActive(true);
103
104 Group ug = groupService.updateGroup("g4", builder.build());
105 assertTrue(ug.isActive());
106
107 Group gg = groupService.getGroup("g4");
108 assertTrue(gg.isActive());
109 assertTrue( "p4 should be reported as a member of g2 (now that g4 is active)", groupService.isMemberOfGroup("p4", "g2") );
110
111 builder = Group.Builder.create(gg);
112 builder.setActive(false);
113 groupService.updateGroup(builder.build());
114 assertFalse( "p4 should be reported as a member of g2 (now that g4 is active)", groupService.isMemberOfGroup("p4", "g2") );
115 }
116
117 public GroupService getGroupService() {
118 return this.groupService;
119 }
120
121 public void setGroupService(GroupService groupService) {
122 this.groupService = groupService;
123 }
124
125
126 }