001 /** 002 * Copyright 2005-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.kew.actions; 017 018 import org.junit.Test; 019 import org.kuali.rice.kew.actionitem.ActionItem; 020 import org.kuali.rice.kew.actionlist.service.ActionListService; 021 import org.kuali.rice.kew.api.KewApiServiceLocator; 022 import org.kuali.rice.kew.api.WorkflowDocument; 023 import org.kuali.rice.kew.api.WorkflowDocumentFactory; 024 import org.kuali.rice.kew.api.action.ActionTaken; 025 import org.kuali.rice.kew.service.KEWServiceLocator; 026 import org.kuali.rice.kew.test.KEWTestCase; 027 import org.kuali.rice.kew.api.KewApiConstants; 028 import org.kuali.rice.kim.api.KimConstants; 029 030 import java.util.ArrayList; 031 import java.util.Collection; 032 import java.util.Iterator; 033 import java.util.List; 034 035 import static org.junit.Assert.assertEquals; 036 import static org.junit.Assert.assertTrue; 037 038 /** 039 * @author Kuali Rice Team (rice.collab@kuali.org) 040 * 041 */ 042 public class TakeWorkgroupAuthorityTest extends KEWTestCase { 043 044 public static final String DOC_TYPE = "TakeWorkgroupAuthorityDoc"; 045 public static List<String> WORKGROUP_MEMBERS = new ArrayList<String>(); 046 047 static { 048 WORKGROUP_MEMBERS.add("ewestfal"); 049 WORKGROUP_MEMBERS.add("rkirkend"); 050 WORKGROUP_MEMBERS.add("jhopf"); 051 WORKGROUP_MEMBERS.add("bmcgough"); 052 WORKGROUP_MEMBERS.add("temay"); 053 WORKGROUP_MEMBERS.add("xqi"); 054 WORKGROUP_MEMBERS.add("natjohns"); 055 WORKGROUP_MEMBERS.add("pmckown"); 056 WORKGROUP_MEMBERS.add("jthomas"); 057 WORKGROUP_MEMBERS.add("jitrue"); 058 } 059 060 protected void loadTestData() throws Exception { 061 loadXmlFile("ActionsConfig.xml"); 062 } 063 064 @Test public void testTakeWorkgroupAuthorityAction() throws Exception { 065 066 WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), DOC_TYPE); 067 doc.route(""); 068 069 String groupId = getGroupIdForName(KimConstants.KIM_GROUP_WORKFLOW_NAMESPACE_CODE, "TestWorkgroup"); 070 071 //verify that all members have the action item 072 ActionListService aiService = KEWServiceLocator.getActionListService(); 073 Collection<ActionItem> actionItems = aiService.findByDocumentId(doc.getDocumentId()); 074 assertTrue("There should be more than one action item", actionItems.size() > 1); 075 for (Iterator<ActionItem> iter = actionItems.iterator(); iter.hasNext();) { 076 ActionItem actionItem = iter.next(); 077 assertTrue("Action Item not to workgroup member", WORKGROUP_MEMBERS.contains(getPrincipalNameForId(actionItem.getPrincipalId()))); 078 } 079 080 //have member rkirkend take authority 081 doc = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), doc.getDocumentId()); 082 doc.takeGroupAuthority("", groupId); 083 084 //verify that only rkirkend has an action item now. 085 actionItems = aiService.findByDocumentId(doc.getDocumentId()); 086 assertEquals("There should only be a single action item to rkirkend", 1, actionItems.size()); 087 for (Iterator<ActionItem> iter = actionItems.iterator(); iter.hasNext();) { 088 ActionItem actionItem = iter.next(); 089 assertEquals("Action item should be to rkirkend", "rkirkend", getPrincipalNameForId(actionItem.getPrincipalId())); 090 } 091 092 //verify the action was recorded and by rkirkend 093 List<ActionTaken> actionsTaken = KewApiServiceLocator.getWorkflowDocumentService().getActionsTaken( 094 doc.getDocumentId()); 095 boolean rkirkendATFound = false; 096 for (ActionTaken at : actionsTaken) { 097 if (at.getPrincipalId().equals(getPrincipalIdForName("rkirkend"))) { 098 assertEquals("Incorrect action code recorded", KewApiConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY_CD, at.getActionTaken().getCode()); 099 rkirkendATFound = true; 100 } 101 } 102 103 assertTrue("should have found action taken for rkirkend", rkirkendATFound); 104 } 105 }