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