View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    *
4    *
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.opensource.org/licenses/ecl2.php
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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   * @author Kuali Rice Team (rice.collab@kuali.org)
40   *
41   *<authenticationId>ewestfal</authenticationId>
42  					<authenticationId>rkirkend</authenticationId>
43  					<authenticationId>jhopf</authenticationId>
44  					<authenticationId>bmcgough</authenticationId>
45  					<authenticationId>temay</authenticationId>
46  					<authenticationId>xqi</authenticationId>
47  					<authenticationId>natjohns</authenticationId>
48  					<authenticationId>pmckown</authenticationId>
49  					<authenticationId>jthomas</authenticationId>
50  					<authenticationId>jitrue</authenticationId>
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          //verify that all members have the action item
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          //have member rkirkend take authority
92          doc = new WorkflowDocument(new NetworkIdDTO("rkirkend"), doc.getRouteHeaderId());
93          doc.takeGroupAuthority("", groupId);
94  
95          //verify that only rkirkend has an action item now.
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         //verify the action was recorded and by rkirkend
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 }