View Javadoc
1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * @author Kuali Rice Team (rice.collab@kuali.org)
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          //verify that all members have the action item
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(getPrincipalNameForId(actionItem.getPrincipalId())));
78          }
79  
80          //have member rkirkend take authority
81          doc = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), doc.getDocumentId());
82          doc.takeGroupAuthority("", groupId);
83  
84          //verify that only rkirkend has an action item now.
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", getPrincipalNameForId(actionItem.getPrincipalId()));
90          }
91  
92          //verify the action was recorded and by rkirkend
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 }