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.KewApiServiceLocator;
22 import org.kuali.rice.kew.api.WorkflowDocument;
23 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
24 import org.kuali.rice.kew.api.action.ActionTaken;
25 import org.kuali.rice.kew.service.KEWServiceLocator;
26 import org.kuali.rice.kew.test.KEWTestCase;
27 import org.kuali.rice.kew.api.KewApiConstants;
28 import org.kuali.rice.kim.api.KimConstants;
29
30 import java.util.ArrayList;
31 import java.util.Collection;
32 import java.util.Iterator;
33 import java.util.List;
34
35 import static org.junit.Assert.assertEquals;
36 import static org.junit.Assert.assertTrue;
37
38
39
40
41
42 public class TakeWorkgroupAuthorityTest extends KEWTestCase {
43
44 public static final String DOC_TYPE = "TakeWorkgroupAuthorityDoc";
45 public static List<String> WORKGROUP_MEMBERS = new ArrayList<String>();
46
47 static {
48 WORKGROUP_MEMBERS.add("ewestfal");
49 WORKGROUP_MEMBERS.add("rkirkend");
50 WORKGROUP_MEMBERS.add("jhopf");
51 WORKGROUP_MEMBERS.add("bmcgough");
52 WORKGROUP_MEMBERS.add("temay");
53 WORKGROUP_MEMBERS.add("xqi");
54 WORKGROUP_MEMBERS.add("natjohns");
55 WORKGROUP_MEMBERS.add("pmckown");
56 WORKGROUP_MEMBERS.add("jthomas");
57 WORKGROUP_MEMBERS.add("jitrue");
58 }
59
60 protected void loadTestData() throws Exception {
61 loadXmlFile("ActionsConfig.xml");
62 }
63
64 @Test public void testTakeWorkgroupAuthorityAction() throws Exception {
65
66 WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), DOC_TYPE);
67 doc.route("");
68
69 String groupId = getGroupIdForName(KimConstants.KIM_GROUP_WORKFLOW_NAMESPACE_CODE, "TestWorkgroup");
70
71
72 ActionListService aiService = KEWServiceLocator.getActionListService();
73 Collection<ActionItem> actionItems = aiService.findByDocumentId(doc.getDocumentId());
74 assertTrue("There should be more than one action item", actionItems.size() > 1);
75 for (Iterator<ActionItem> iter = actionItems.iterator(); iter.hasNext();) {
76 ActionItem actionItem = iter.next();
77 assertTrue("Action Item not to workgroup member", WORKGROUP_MEMBERS.contains(actionItem.getPerson().getPrincipalName()));
78 }
79
80
81 doc = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), doc.getDocumentId());
82 doc.takeGroupAuthority("", groupId);
83
84
85 actionItems = aiService.findByDocumentId(doc.getDocumentId());
86 assertEquals("There should only be a single action item to rkirkend", 1, actionItems.size());
87 for (Iterator<ActionItem> iter = actionItems.iterator(); iter.hasNext();) {
88 ActionItem actionItem = iter.next();
89 assertEquals("Action item should be to rkirkend", "rkirkend", actionItem.getPerson().getPrincipalName());
90 }
91
92
93 List<ActionTaken> actionsTaken = KewApiServiceLocator.getWorkflowDocumentService().getActionsTaken(
94 doc.getDocumentId());
95 boolean rkirkendATFound = false;
96 for (ActionTaken at : actionsTaken) {
97 if (at.getPrincipalId().equals(getPrincipalIdForName("rkirkend"))) {
98 assertEquals("Incorrect action code recorded", KewApiConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY_CD, at.getActionTaken().getCode());
99 rkirkendATFound = true;
100 }
101 }
102
103 assertTrue("should have found action taken for rkirkend", rkirkendATFound);
104 }
105 }