001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.actions;
018:
019: import java.util.ArrayList;
020: import java.util.Collection;
021: import java.util.Iterator;
022: import java.util.List;
023:
024: import org.junit.Test;
025: import org.kuali.workflow.test.WorkflowTestCase;
026:
027: import edu.iu.uis.eden.EdenConstants;
028: import edu.iu.uis.eden.KEWServiceLocator;
029: import edu.iu.uis.eden.actionitem.ActionItem;
030: import edu.iu.uis.eden.actionlist.ActionListService;
031: import edu.iu.uis.eden.clientapp.WorkflowDocument;
032: import edu.iu.uis.eden.clientapp.WorkflowInfo;
033: import edu.iu.uis.eden.clientapp.vo.ActionTakenVO;
034: import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
035: import edu.iu.uis.eden.clientapp.vo.WorkflowGroupIdVO;
036: import edu.iu.uis.eden.workgroup.GroupNameId;
037: import edu.iu.uis.eden.workgroup.Workgroup;
038:
039: /**
040: * @author rkirkend
041: *
042: *<authenticationId>ewestfal</authenticationId>
043: <authenticationId>rkirkend</authenticationId>
044: <authenticationId>jhopf</authenticationId>
045: <authenticationId>bmcgough</authenticationId>
046: <authenticationId>temay</authenticationId>
047: <authenticationId>xqi</authenticationId>
048: <authenticationId>natjohns</authenticationId>
049: <authenticationId>pmckown</authenticationId>
050: <authenticationId>jthomas</authenticationId>
051: <authenticationId>jitrue</authenticationId>
052: *
053: */
054: public class TakeWorkgroupAuthorityTest extends WorkflowTestCase {
055:
056: public static final String DOC_TYPE = "TakeWorkgroupAuthorityDoc";
057: public static List<String> WORKGROUP_MEMBERS = new ArrayList<String>();
058:
059: static {
060: WORKGROUP_MEMBERS.add("ewestfal");
061: WORKGROUP_MEMBERS.add("rkirkend");
062: WORKGROUP_MEMBERS.add("jhopf");
063: WORKGROUP_MEMBERS.add("bmcgough");
064: WORKGROUP_MEMBERS.add("temay");
065: WORKGROUP_MEMBERS.add("xqi");
066: WORKGROUP_MEMBERS.add("natjohns");
067: WORKGROUP_MEMBERS.add("pmckown");
068: WORKGROUP_MEMBERS.add("jthomas");
069: WORKGROUP_MEMBERS.add("jitrue");
070: }
071:
072: protected void loadTestData() throws Exception {
073: loadXmlFile("ActionsConfig.xml");
074: }
075:
076: @Test
077: public void testTakeWorkgroupAuthorityAction() throws Exception {
078:
079: WorkflowDocument doc = new WorkflowDocument(new NetworkIdVO(
080: "user1"), DOC_TYPE);
081: doc.routeDocument("");
082:
083: Workgroup workgroup = KEWServiceLocator.getWorkgroupService()
084: .getWorkgroup(new GroupNameId("TestWorkgroup"));
085:
086: //verify that all members have the action item
087: ActionListService aiService = KEWServiceLocator
088: .getActionListService();
089: Collection actionItems = aiService.findByRouteHeaderId(doc
090: .getRouteHeaderId());
091: assertTrue("There should be more than one action item",
092: actionItems.size() > 1);
093: for (Iterator iter = actionItems.iterator(); iter.hasNext();) {
094: ActionItem actionItem = (ActionItem) iter.next();
095: assertTrue("Action Item not to workgroup member",
096: WORKGROUP_MEMBERS.contains(actionItem.getUser()
097: .getAuthenticationUserId()
098: .getAuthenticationId()));
099: }
100:
101: //have member rkirkend take authority
102: doc = new WorkflowDocument(new NetworkIdVO("rkirkend"), doc
103: .getRouteHeaderId());
104: doc.takeWorkgroupAuthority("", new WorkflowGroupIdVO(workgroup
105: .getWorkflowGroupId().getGroupId()));
106:
107: //verify that only rkirkend has an action item now.
108: actionItems = aiService.findByRouteHeaderId(doc
109: .getRouteHeaderId());
110: assertEquals(
111: "There should only be a single action item to rkirkend",
112: 1, actionItems.size());
113: for (Iterator iter = actionItems.iterator(); iter.hasNext();) {
114: ActionItem actionItem = (ActionItem) iter.next();
115: assertEquals("Action item should be to rkirkend",
116: "rkirkend", actionItem.getUser()
117: .getAuthenticationUserId()
118: .getAuthenticationId());
119: }
120:
121: //verify the action was recorded and by rkirkend
122: WorkflowInfo wUtil = new WorkflowInfo();
123: ActionTakenVO[] actionsTaken = wUtil.getActionsTaken(doc
124: .getRouteHeaderId());
125: boolean rkirkendATFound = false;
126: for (int i = 0; i < actionsTaken.length; i++) {
127: ActionTakenVO at = actionsTaken[i];
128: if (at.getUserVO().getNetworkId().equals("rkirkend")) {
129: assertEquals(
130: "Incorrect action code recorded",
131: EdenConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY_CD,
132: at.getActionTaken());
133: rkirkendATFound = true;
134: }
135: }
136:
137: assertTrue("should have found action taken for rkirkend",
138: rkirkendATFound);
139: }
140: }
|