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.Collection;
21  import java.util.Iterator;
22  
23  import org.junit.Test;
24  import org.kuali.rice.kew.actionitem.ActionItem;
25  import org.kuali.rice.kew.actionlist.service.ActionListService;
26  import org.kuali.rice.kew.dto.NetworkIdDTO;
27  import org.kuali.rice.kew.service.KEWServiceLocator;
28  import org.kuali.rice.kew.service.WorkflowDocument;
29  import org.kuali.rice.kew.test.KEWTestCase;
30  import org.kuali.rice.kim.util.KimConstants;
31  
32  /**
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   */
35  public class ReleaseWorkgroupAuthorityTest extends KEWTestCase {
36  
37      protected void loadTestData() throws Exception {
38          loadXmlFile("ActionsConfig.xml");
39      }
40  
41      @Test public void testReleaseWorkgroupAuthority() throws Exception {
42          WorkflowDocument doc = new WorkflowDocument(new NetworkIdDTO("user1"), TakeWorkgroupAuthorityTest.DOC_TYPE);
43          doc.routeDocument("");
44  
45          String groupId = getGroupIdForName(KimConstants.KIM_GROUP_WORKFLOW_NAMESPACE_CODE, "TestWorkgroup");
46          //have member rkirkend take authority
47          doc = new WorkflowDocument(new NetworkIdDTO("rkirkend"), doc.getRouteHeaderId());
48          doc.takeGroupAuthority("", groupId);
49  
50          // verify there is only one action item and that it's to rkirkend
51          ActionListService aiService = KEWServiceLocator.getActionListService();
52          Collection actionItems = aiService.findByRouteHeaderId(doc.getRouteHeaderId());
53          assertEquals("There should be only one action item", 1, actionItems.size());
54          ActionItem ai = (ActionItem)actionItems.iterator().next();
55          assertEquals("action item should be to rkirkend", getPrincipalIdForName("rkirkend"), ai.getPrincipalId());
56          assertEquals("action item should be to group", groupId, ai.getGroupId());
57          
58          //have rkirkend release authority
59          doc = new WorkflowDocument(new NetworkIdDTO("rkirkend"), doc.getRouteHeaderId());
60  
61          doc.releaseGroupAuthority("", groupId);
62  
63          //verify that all members have the action item
64          actionItems = aiService.findByRouteHeaderId(doc.getRouteHeaderId());
65          assertTrue("There should be more than one action item", actionItems.size() > 1);
66          for (Iterator iter = actionItems.iterator(); iter.hasNext();) {
67              ActionItem actionItem = (ActionItem) iter.next();
68              assertTrue("Action Item not to workgroup member", TakeWorkgroupAuthorityTest.WORKGROUP_MEMBERS.contains(actionItem.getPerson().getPrincipalName()));
69          }
70      }
71  }