1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.actions;
18
19
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.Iterator;
23 import java.util.List;
24
25 import org.junit.Test;
26 import org.kuali.rice.kew.actionitem.ActionItem;
27 import org.kuali.rice.kew.actionlist.service.ActionListService;
28 import org.kuali.rice.kew.dto.ActionTakenDTO;
29 import org.kuali.rice.kew.dto.NetworkIdDTO;
30 import org.kuali.rice.kew.service.KEWServiceLocator;
31 import org.kuali.rice.kew.service.WorkflowDocument;
32 import org.kuali.rice.kew.service.WorkflowInfo;
33 import org.kuali.rice.kew.test.KEWTestCase;
34 import org.kuali.rice.kew.util.KEWConstants;
35 import org.kuali.rice.kim.util.KimConstants;
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 public class TakeWorkgroupAuthorityTest extends KEWTestCase {
54
55 public static final String DOC_TYPE = "TakeWorkgroupAuthorityDoc";
56 public static List<String> WORKGROUP_MEMBERS = new ArrayList<String>();
57
58 static {
59 WORKGROUP_MEMBERS.add("ewestfal");
60 WORKGROUP_MEMBERS.add("rkirkend");
61 WORKGROUP_MEMBERS.add("jhopf");
62 WORKGROUP_MEMBERS.add("bmcgough");
63 WORKGROUP_MEMBERS.add("temay");
64 WORKGROUP_MEMBERS.add("xqi");
65 WORKGROUP_MEMBERS.add("natjohns");
66 WORKGROUP_MEMBERS.add("pmckown");
67 WORKGROUP_MEMBERS.add("jthomas");
68 WORKGROUP_MEMBERS.add("jitrue");
69 }
70
71 protected void loadTestData() throws Exception {
72 loadXmlFile("ActionsConfig.xml");
73 }
74
75 @Test public void testTakeWorkgroupAuthorityAction() throws Exception {
76
77 WorkflowDocument doc = new WorkflowDocument(new NetworkIdDTO("user1"), DOC_TYPE);
78 doc.routeDocument("");
79
80 String groupId = getGroupIdForName(KimConstants.KIM_GROUP_WORKFLOW_NAMESPACE_CODE, "TestWorkgroup");
81
82
83 ActionListService aiService = KEWServiceLocator.getActionListService();
84 Collection actionItems = aiService.findByRouteHeaderId(doc.getRouteHeaderId());
85 assertTrue("There should be more than one action item", actionItems.size() > 1);
86 for (Iterator iter = actionItems.iterator(); iter.hasNext();) {
87 ActionItem actionItem = (ActionItem) iter.next();
88 assertTrue("Action Item not to workgroup member", WORKGROUP_MEMBERS.contains(actionItem.getPerson().getPrincipalName()));
89 }
90
91
92 doc = new WorkflowDocument(new NetworkIdDTO("rkirkend"), doc.getRouteHeaderId());
93 doc.takeGroupAuthority("", groupId);
94
95
96 actionItems = aiService.findByRouteHeaderId(doc.getRouteHeaderId());
97 assertEquals("There should only be a single action item to rkirkend", 1, actionItems.size());
98 for (Iterator iter = actionItems.iterator(); iter.hasNext();) {
99 ActionItem actionItem = (ActionItem) iter.next();
100 assertEquals("Action item should be to rkirkend", "rkirkend", actionItem.getPerson().getPrincipalName());
101 }
102
103
104 WorkflowInfo wUtil = new WorkflowInfo();
105 ActionTakenDTO[] actionsTaken = wUtil.getActionsTaken(doc.getRouteHeaderId());
106 boolean rkirkendATFound = false;
107 for (int i = 0; i < actionsTaken.length; i++) {
108 ActionTakenDTO at = actionsTaken[i];
109 if (at.getPrincipalId().equals(getPrincipalIdForName("rkirkend"))) {
110 assertEquals("Incorrect action code recorded", KEWConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY_CD, at.getActionTaken());
111 rkirkendATFound = true;
112 }
113 }
114
115 assertTrue("should have found action taken for rkirkend", rkirkendATFound);
116 }
117 }