1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.actions;
17
18 import org.junit.Test;
19 import org.kuali.rice.kew.actionitem.ActionItem;
20 import org.kuali.rice.kew.actionlist.service.ActionListService;
21 import org.kuali.rice.kew.api.WorkflowDocument;
22 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
23 import org.kuali.rice.kew.service.KEWServiceLocator;
24 import org.kuali.rice.kew.test.KEWTestCase;
25 import org.kuali.rice.kim.api.KimConstants;
26
27 import java.util.Collection;
28 import java.util.Iterator;
29
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertTrue;
32
33
34
35
36 public class ReleaseWorkgroupAuthorityTest extends KEWTestCase {
37
38 protected void loadTestData() throws Exception {
39 loadXmlFile("ActionsConfig.xml");
40 }
41
42 @Test public void testReleaseWorkgroupAuthority() throws Exception {
43 WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), TakeWorkgroupAuthorityTest.DOC_TYPE);
44 doc.route("");
45
46 String groupId = getGroupIdForName(KimConstants.KIM_GROUP_WORKFLOW_NAMESPACE_CODE, "TestWorkgroup");
47
48 doc = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), doc.getDocumentId());
49 doc.takeGroupAuthority("", groupId);
50
51
52 ActionListService aiService = KEWServiceLocator.getActionListService();
53 Collection<ActionItem> actionItems = aiService.findByDocumentId(doc.getDocumentId());
54 assertEquals("There should be only one action item", 1, actionItems.size());
55 ActionItem ai = (ActionItem)actionItems.iterator().next();
56 assertEquals("action item should be to rkirkend", getPrincipalIdForName("rkirkend"), ai.getPrincipalId());
57 assertEquals("action item should be to group", groupId, ai.getGroupId());
58
59
60 doc = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), doc.getDocumentId());
61
62 doc.releaseGroupAuthority("", groupId);
63
64
65 actionItems = aiService.findByDocumentId(doc.getDocumentId());
66 assertTrue("There should be more than one action item", actionItems.size() > 1);
67 for (Iterator<ActionItem> iter = actionItems.iterator(); iter.hasNext();) {
68 ActionItem actionItem = iter.next();
69 assertTrue("Action Item not to workgroup member", TakeWorkgroupAuthorityTest.WORKGROUP_MEMBERS.contains(actionItem.getPerson().getPrincipalName()));
70 }
71 }
72 }