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.actionitem;
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.apache.commons.beanutils.BeanUtils;
025: import org.junit.Test;
026: import org.kuali.workflow.test.WorkflowTestCase;
027:
028: import edu.iu.uis.eden.EdenConstants;
029: import edu.iu.uis.eden.KEWServiceLocator;
030: import edu.iu.uis.eden.actionlist.ActionListService;
031: import edu.iu.uis.eden.clientapp.WorkflowDocument;
032: import edu.iu.uis.eden.clientapp.vo.ActionRequestVO;
033: import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
034: import edu.iu.uis.eden.clientapp.vo.WorkgroupNameIdVO;
035: import edu.iu.uis.eden.user.AuthenticationUserId;
036: import edu.iu.uis.eden.user.Recipient;
037: import edu.iu.uis.eden.user.WorkflowUser;
038: import edu.iu.uis.eden.workgroup.BaseWorkgroup;
039: import edu.iu.uis.eden.workgroup.BaseWorkgroupMember;
040: import edu.iu.uis.eden.workgroup.GroupNameId;
041: import edu.iu.uis.eden.workgroup.WorkflowGroupId;
042: import edu.iu.uis.eden.workgroup.Workgroup;
043: import edu.iu.uis.eden.workgroup.WorkgroupService;
044:
045: public class ActionItemServiceTest extends WorkflowTestCase {
046:
047: private ActionListService actionListService;
048:
049: protected void loadTestData() throws Exception {
050: loadXmlFile("ActionItemConfig.xml");
051: }
052:
053: protected void setUpTransaction() throws Exception {
054: super .setUpTransaction();
055: actionListService = KEWServiceLocator.getActionListService();
056: }
057:
058: /**
059: * When workgroup membership changes all action items to that workgroup need to reflect
060: * the new membership
061: *
062: * @throws Exception
063: */
064: @Test
065: public void testUpdateActionItemsForWorkgroupChange()
066: throws Exception {
067:
068: WorkflowDocument document = new WorkflowDocument(
069: new NetworkIdVO("user1"), "ActionItemDocumentType");
070: document.setTitle("");
071: document.routeDocument("");
072:
073: WorkgroupService workgroupService = KEWServiceLocator
074: .getWorkgroupService();
075: BaseWorkgroup oldWorkgroup = (BaseWorkgroup) workgroupService
076: .getWorkgroup(new GroupNameId("WorkflowAdmin"));
077: WorkflowUser user1 = KEWServiceLocator.getUserService()
078: .getWorkflowUser(new AuthenticationUserId("user1"));
079: WorkflowUser user2 = KEWServiceLocator.getUserService()
080: .getWorkflowUser(new AuthenticationUserId("user2"));
081:
082: BaseWorkgroup newWorkgroup = (BaseWorkgroup) KEWServiceLocator
083: .getWorkgroupService().getBlankWorkgroup();
084: newWorkgroup.setGroupNameId(oldWorkgroup.getGroupNameId());
085: newWorkgroup.setActiveInd(Boolean.TRUE);
086: newWorkgroup.setCurrentInd(Boolean.TRUE);
087: newWorkgroup.setVersionNumber(new Integer(oldWorkgroup
088: .getVersionNumber().intValue() + 1));
089: newWorkgroup.setLockVerNbr(new Integer(oldWorkgroup
090: .getLockVerNbr().intValue()));
091: newWorkgroup.setWorkflowGroupId(oldWorkgroup
092: .getWorkflowGroupId());
093: newWorkgroup.setWorkgroupId(oldWorkgroup.getWorkflowGroupId()
094: .getGroupId());
095: newWorkgroup.setGroupNameId(new GroupNameId(oldWorkgroup
096: .getGroupNameId().getNameId()));
097: newWorkgroup.setMembers(new ArrayList<Recipient>(oldWorkgroup
098: .getMembers()));
099:
100: List<WorkflowUser> usersToRemove = new ArrayList<WorkflowUser>();
101: //remove 'rkirkend' and 'shenl' from the workgroup
102: for (Recipient recipient : oldWorkgroup.getMembers()) {
103: if (recipient instanceof WorkflowUser) {
104: WorkflowUser user = (WorkflowUser) recipient;
105: if (user.getAuthenticationUserId()
106: .getAuthenticationId().equals("rkirkend")
107: || user.getAuthenticationUserId()
108: .getAuthenticationId().equals("shenl")) {
109: usersToRemove.add(user);
110: }
111: }
112: }
113:
114: newWorkgroup.getMembers().removeAll(usersToRemove);
115:
116: List<WorkflowUser> newMembers = new ArrayList<WorkflowUser>();
117: newMembers.add(user1);
118: newMembers.add(user2);
119: newWorkgroup.getMembers().addAll(newMembers);
120:
121: // copy the WorkflowUser members into WorkgroupMember members for persistence through OJB
122: newWorkgroup.getWorkgroupMembers().clear();
123: for (Recipient recipient : newWorkgroup.getMembers()) {
124: if (recipient instanceof WorkflowUser) {
125: WorkflowUser user = (WorkflowUser) recipient;
126: BaseWorkgroupMember member = new BaseWorkgroupMember();
127: member.setWorkflowId(user.getWorkflowId());
128: member
129: .setMemberType(EdenConstants.ACTION_REQUEST_USER_RECIPIENT_CD);
130: member.setWorkgroup(newWorkgroup);
131: member.setWorkgroupVersionNumber(newWorkgroup
132: .getVersionNumber());
133: member.setWorkgroupId(newWorkgroup.getWorkgroupId());
134: newWorkgroup.getWorkgroupMembers().add(member);
135: }
136: }
137: workgroupService.save(newWorkgroup);
138: // make the old workgroup non-current
139: oldWorkgroup.setCurrentInd(Boolean.FALSE);
140: workgroupService.save(oldWorkgroup);
141:
142: // verify that the new workgroup is sane...
143: Workgroup loadedNewWorkgroup = workgroupService
144: .getWorkgroup(new WorkflowGroupId(newWorkgroup
145: .getWorkgroupId()));
146: boolean foundUser1 = false;
147: boolean foundUser2 = false;
148: assertEquals("Workgroup should have 6 members.", 6,
149: loadedNewWorkgroup.getUsers().size());
150: for (Iterator iterator = loadedNewWorkgroup.getUsers()
151: .iterator(); iterator.hasNext();) {
152: WorkflowUser user = (WorkflowUser) iterator.next();
153: if (user.getAuthenticationUserId().equals(
154: user1.getAuthenticationUserId())) {
155: foundUser1 = true;
156: } else if (user.getAuthenticationUserId().equals(
157: user2.getAuthenticationUserId())) {
158: foundUser2 = true;
159: }
160: }
161: assertTrue("Did not find user 1 on workgroup.", foundUser1);
162: assertTrue("Did not find user 2 on workgroup.", foundUser2);
163:
164: KEWServiceLocator.getActionListService()
165: .updateActionItemsForWorkgroupChange(oldWorkgroup,
166: newWorkgroup);
167:
168: Collection actionItems = KEWServiceLocator
169: .getActionListService().findByRouteHeaderId(
170: document.getRouteHeaderId());
171: boolean foundrkirkend = false;
172: boolean foundlshen = false;
173: boolean founduser1 = false;
174: boolean founduser2 = false;
175:
176: for (Iterator iter = actionItems.iterator(); iter.hasNext();) {
177: ActionItem actionItem = (ActionItem) iter.next();
178: String authId = actionItem.getUser()
179: .getAuthenticationUserId().getAuthenticationId();
180: if (authId.equals("rkirkend")) {
181: foundrkirkend = true;
182: } else if (authId.equals("user1")) {
183: founduser1 = true;
184: } else if (authId.equals("lshen")) {
185: foundlshen = true;
186: } else if (authId.equals("user2")) {
187: founduser2 = true;
188: }
189: }
190:
191: assertTrue(
192: "rkirkend should still have an AI because he is in 2 workgroups that are routed to.",
193: foundrkirkend);
194: assertTrue(
195: "user1 should have an AI because they were added to 'WorkflowAdmin'",
196: founduser1);
197: assertTrue(
198: "user2 should have an AI because they were added to 'WorkflowAdmin'",
199: founduser2);
200: assertFalse(
201: "lshen should not have an AI because they were removed from 'WorkflowAdmin'",
202: foundlshen);
203:
204: }
205:
206: /**
207: * When workgroup membership changes all action items to that workgroup need to reflect
208: * the new membership even in the case of nested workgroups.
209: *
210: * @throws Exception
211: */
212: @Test
213: public void testUpdateActionItemsForNestedWorkgroupChange()
214: throws Exception {
215:
216: WorkflowDocument document = new WorkflowDocument(
217: new NetworkIdVO("user1"), "ActionItemDocumentType");
218: document.setTitle("");
219: document.appSpecificRouteDocumentToWorkgroup(
220: EdenConstants.ACTION_REQUEST_APPROVE_REQ, "",
221: new WorkgroupNameIdVO("AIWGNested2"), "", true);
222: document.routeDocument("");
223:
224: // remove a user from the AGWG1 workgroup
225: WorkflowUser ewestfal = KEWServiceLocator.getUserService()
226: .getWorkflowUser(new AuthenticationUserId("ewestfal"));
227: BaseWorkgroup workgroup1 = (BaseWorkgroup) KEWServiceLocator
228: .getWorkgroupService().getWorkgroup(
229: new GroupNameId("AIWG1"));
230: assertNotNull(workgroup1);
231: BaseWorkgroup oldWorkgroup1 = copy(workgroup1);
232:
233: assertEquals("Workgroup should have 2 members.", 2, workgroup1
234: .getWorkgroupMembers().size());
235: for (Iterator iterator = workgroup1.getWorkgroupMembers()
236: .iterator(); iterator.hasNext();) {
237: BaseWorkgroupMember member = (BaseWorkgroupMember) iterator
238: .next();
239: // remove ewestfal
240: if (member.getWorkflowId().equals(ewestfal.getWorkflowId())) {
241: iterator.remove();
242: }
243: }
244: workgroup1.getMembers().clear();
245: workgroup1.materializeMembers();
246: assertEquals("Workgroup should have 1 members.", 1, workgroup1
247: .getWorkgroupMembers().size());
248: KEWServiceLocator.getWorkgroupService().save(workgroup1);
249:
250: Workgroup workgroupNested2 = KEWServiceLocator
251: .getWorkgroupService().getWorkgroup(
252: new GroupNameId("AIWGNested2"));
253: Collection actionItems = KEWServiceLocator
254: .getActionListService().findByRouteHeaderId(
255: document.getRouteHeaderId());
256: assertEquals("Should be 6 action items.", 6, actionItems.size());
257: boolean foundEwestfal = false;
258: for (Iterator iterator = actionItems.iterator(); iterator
259: .hasNext();) {
260: ActionItem actionItem = (ActionItem) iterator.next();
261: if (actionItem.getWorkflowId().equals(
262: ewestfal.getWorkflowId())) {
263: assertEquals(
264: "Action Item should be for the AIWGNested2 workgroup",
265: actionItem.getWorkgroupId(), workgroupNested2
266: .getWorkflowGroupId().getGroupId());
267: foundEwestfal = true;
268: }
269: }
270: assertTrue("Should have found an action item to ewestfal.",
271: foundEwestfal);
272:
273: // now, let's update the action items for our workgroup change
274: KEWServiceLocator.getActionListService()
275: .updateActionItemsForWorkgroupChange(oldWorkgroup1,
276: workgroup1);
277:
278: // there should no longer be a request to ewestfal
279: actionItems = KEWServiceLocator.getActionListService()
280: .findByRouteHeaderId(document.getRouteHeaderId());
281: assertEquals("Should be 5 action items.", 5, actionItems.size());
282: foundEwestfal = false;
283: for (Iterator iterator = actionItems.iterator(); iterator
284: .hasNext();) {
285: ActionItem actionItem = (ActionItem) iterator.next();
286: if (actionItem.getWorkflowId().equals(
287: ewestfal.getWorkflowId())) {
288: foundEwestfal = true;
289: }
290: }
291: assertFalse(
292: "Should not have found an action item to ewestfal.",
293: foundEwestfal);
294:
295: // add user user1 to AIWGNested1
296: WorkflowUser user1 = KEWServiceLocator.getUserService()
297: .getWorkflowUser(new AuthenticationUserId("user1"));
298: BaseWorkgroup workgroup2 = (BaseWorkgroup) KEWServiceLocator
299: .getWorkgroupService().getWorkgroup(
300: new GroupNameId("AIWGNested1"));
301: assertNotNull(workgroup2);
302: BaseWorkgroup oldWorkgroup2 = copy(workgroup2);
303: assertEquals("Workgroup should have 2 members.", 2, workgroup2
304: .getWorkgroupMembers().size());
305: assertEquals("Workgroup should have 2 members.", 2, workgroup2
306: .getMembers().size());
307: assertEquals("Workgroup should have 2 users.", 2, workgroup2
308: .getUsers().size());
309: // add user1
310: BaseWorkgroupMember member = new BaseWorkgroupMember();
311: member.setWorkflowId(user1.getWorkflowId());
312: member
313: .setMemberType(EdenConstants.ACTION_REQUEST_USER_RECIPIENT_CD);
314: member.setWorkgroup(workgroup2);
315: member.setWorkgroupVersionNumber(workgroup2.getVersionNumber());
316: member.setWorkgroupId(workgroup2.getWorkgroupId());
317: workgroup2.getWorkgroupMembers().add(member);
318: workgroup2.getMembers().clear();
319: workgroup2.materializeMembers();
320: KEWServiceLocator.getWorkgroupService().save(workgroup2);
321:
322: // update action items
323: KEWServiceLocator.getActionListService()
324: .updateActionItemsForWorkgroupChange(oldWorkgroup2,
325: workgroup2);
326: // there should now be an action item to user1
327: actionItems = KEWServiceLocator.getActionListService()
328: .findByRouteHeaderId(document.getRouteHeaderId());
329: assertEquals("Should be 6 action items.", 6, actionItems.size());
330: boolean foundUser1 = false;
331: for (Iterator iterator = actionItems.iterator(); iterator
332: .hasNext();) {
333: ActionItem actionItem = (ActionItem) iterator.next();
334: if (actionItem.getWorkflowId()
335: .equals(user1.getWorkflowId())) {
336: foundUser1 = true;
337: }
338: }
339: assertTrue("Should have found an action item to user1.",
340: foundUser1);
341:
342: // remove a user from the AIWGNested1 workgroup from AIWGNested2
343: Workgroup aiwgNested1Workgroup = KEWServiceLocator
344: .getWorkgroupService().getWorkgroup(
345: new GroupNameId("AIWGNested1"));
346: BaseWorkgroup workgroup3 = (BaseWorkgroup) KEWServiceLocator
347: .getWorkgroupService().getWorkgroup(
348: new GroupNameId("AIWGNested2"));
349: assertNotNull(workgroup3);
350: BaseWorkgroup oldWorkgroup3 = copy(workgroup3);
351:
352: assertEquals("Workgroup should have 3 members.", 3, workgroup3
353: .getWorkgroupMembers().size());
354: assertEquals("Workgroup should have 6 users.", 6, workgroup3
355: .getUsers().size());
356: for (Iterator iterator = workgroup3.getWorkgroupMembers()
357: .iterator(); iterator.hasNext();) {
358: member = (BaseWorkgroupMember) iterator.next();
359: // remove ewestfal
360: if (member
361: .getMemberType()
362: .equals(
363: EdenConstants.ACTION_REQUEST_WORKGROUP_RECIPIENT_CD)
364: && member.getWorkflowId().equals(
365: aiwgNested1Workgroup.getWorkflowGroupId()
366: .getGroupId().toString())) {
367: iterator.remove();
368: }
369: }
370: workgroup3.getMembers().clear();
371: workgroup3.materializeMembers();
372: assertEquals("Workgroup should have 2 members.", 2, workgroup3
373: .getWorkgroupMembers().size());
374: assertEquals("Workgroup should have 3 users.", 3, workgroup3
375: .getUsers().size());
376: KEWServiceLocator.getWorkgroupService().save(workgroup3);
377:
378: actionItems = KEWServiceLocator.getActionListService()
379: .findByRouteHeaderId(document.getRouteHeaderId());
380: assertEquals("Should be 6 action items.", 6, actionItems.size());
381:
382: // now, let's update the action items for our workgroup change
383: KEWServiceLocator.getActionListService()
384: .updateActionItemsForWorkgroupChange(oldWorkgroup3,
385: workgroup3);
386:
387: // there should only be 3 action items now
388: actionItems = KEWServiceLocator.getActionListService()
389: .findByRouteHeaderId(document.getRouteHeaderId());
390: assertEquals("Should be 3 action items.", 3, actionItems.size());
391: WorkflowUser pmckown = KEWServiceLocator.getUserService()
392: .getWorkflowUser(new AuthenticationUserId("pmckown"));
393: WorkflowUser jhopf = KEWServiceLocator.getUserService()
394: .getWorkflowUser(new AuthenticationUserId("jhopf"));
395: WorkflowUser bmcgough = KEWServiceLocator.getUserService()
396: .getWorkflowUser(new AuthenticationUserId("bmcgough"));
397: boolean foundPmckown = false;
398: boolean foundJhopf = false;
399: boolean foundBmcgough = false;
400: for (Iterator iterator = actionItems.iterator(); iterator
401: .hasNext();) {
402: ActionItem actionItem = (ActionItem) iterator.next();
403: if (actionItem.getWorkflowId().equals(
404: pmckown.getWorkflowId())) {
405: foundPmckown = true;
406: }
407: if (actionItem.getWorkflowId()
408: .equals(jhopf.getWorkflowId())) {
409: foundJhopf = true;
410: }
411: if (actionItem.getWorkflowId().equals(
412: bmcgough.getWorkflowId())) {
413: foundBmcgough = true;
414: }
415: }
416: assertTrue("Should have found an action item to pmckown.",
417: foundPmckown);
418: assertTrue("Should have found an action item to jhopf.",
419: foundJhopf);
420: assertTrue("Should have found an action item to bmcgough.",
421: foundBmcgough);
422:
423: // WorkgroupService workgroupService = KEWServiceLocator.getWorkgroupService();
424: // BaseWorkgroup oldWorkgroup = (BaseWorkgroup)workgroupService.getWorkgroup(new GroupNameId("WorkflowAdmin"));
425: // WorkflowUser user1 = KEWServiceLocator.getUserService().getWorkflowUser(new AuthenticationUserId("user1"));
426: // WorkflowUser user2 = KEWServiceLocator.getUserService().getWorkflowUser(new AuthenticationUserId("user2"));
427: //
428: // BaseWorkgroup newWorkgroup = (BaseWorkgroup)KEWServiceLocator.getWorkgroupService().getBlankWorkgroup();
429: // newWorkgroup.setGroupNameId(oldWorkgroup.getGroupNameId());
430: // newWorkgroup.setActiveInd(Boolean.TRUE);
431: // newWorkgroup.setCurrentInd(Boolean.TRUE);
432: // newWorkgroup.setVersionNumber(new Integer(oldWorkgroup.getVersionNumber().intValue()+1));
433: // newWorkgroup.setLockVerNbr(new Integer(oldWorkgroup.getLockVerNbr().intValue()));
434: // newWorkgroup.setWorkflowGroupId(oldWorkgroup.getWorkflowGroupId());
435: // newWorkgroup.setWorkgroupId(oldWorkgroup.getWorkflowGroupId().getGroupId());
436: // newWorkgroup.setGroupNameId(new GroupNameId(oldWorkgroup.getGroupNameId().getNameId()));
437: // newWorkgroup.setMembers(new ArrayList<Recipient>(oldWorkgroup.getMembers()));
438: //
439: // List<WorkflowUser> usersToRemove = new ArrayList<WorkflowUser>();
440: // //remove 'rkirkend' and 'shenl' from the workgroup
441: // for (Recipient recipient : oldWorkgroup.getMembers()) {
442: // if (recipient instanceof WorkflowUser) {
443: // WorkflowUser user = (WorkflowUser)recipient;
444: // if (user.getAuthenticationUserId().getAuthenticationId().equals("rkirkend") || user.getAuthenticationUserId().getAuthenticationId().equals("shenl")) {
445: // usersToRemove.add(user);
446: // }
447: // }
448: // }
449: //
450: // newWorkgroup.getMembers().removeAll(usersToRemove);
451: //
452: // List<WorkflowUser> newMembers = new ArrayList<WorkflowUser>();
453: // newMembers.add(user1);
454: // newMembers.add(user2);
455: // newWorkgroup.getMembers().addAll(newMembers);
456: //
457: // // copy the WorkflowUser members into WorkgroupMember members for persistence through OJB
458: // newWorkgroup.getWorkgroupMembers().clear();
459: // for (Recipient recipient : newWorkgroup.getMembers()) {
460: // if (recipient instanceof WorkflowUser) {
461: // WorkflowUser user = (WorkflowUser) recipient;
462: // BaseWorkgroupMember member = new BaseWorkgroupMember();
463: // member.setWorkflowId(user.getWorkflowId());
464: // member.setMemberType(EdenConstants.ACTION_REQUEST_USER_RECIPIENT_CD);
465: // member.setWorkgroup(newWorkgroup);
466: // member.setWorkgroupVersionNumber(newWorkgroup.getVersionNumber());
467: // member.setWorkgroupId(newWorkgroup.getWorkgroupId());
468: // newWorkgroup.getWorkgroupMembers().add(member);
469: // }
470: // }
471: // workgroupService.save(newWorkgroup);
472: // // make the old workgroup non-current
473: // oldWorkgroup.setCurrentInd(Boolean.FALSE);
474: // workgroupService.save(oldWorkgroup);
475: //
476: // // verify that the new workgroup is sane...
477: // Workgroup loadedNewWorkgroup = workgroupService.getWorkgroup(new WorkflowGroupId(newWorkgroup.getWorkgroupId()));
478: // boolean foundUser1 = false;
479: // boolean foundUser2 = false;
480: // assertEquals("Workgroup should have 6 members.", 6, loadedNewWorkgroup.getUsers().size());
481: // for (Iterator iterator = loadedNewWorkgroup.getUsers().iterator(); iterator.hasNext();) {
482: // WorkflowUser user = (WorkflowUser) iterator.next();
483: // if (user.getAuthenticationUserId().equals(user1.getAuthenticationUserId())) {
484: // foundUser1 = true;
485: // } else if (user.getAuthenticationUserId().equals(user2.getAuthenticationUserId())) {
486: // foundUser2 = true;
487: // }
488: // }
489: // assertTrue("Did not find user 1 on workgroup.", foundUser1);
490: // assertTrue("Did not find user 2 on workgroup.", foundUser2);
491: //
492: // KEWServiceLocator.getActionListService().updateActionItemsForWorkgroupChange(oldWorkgroup, newWorkgroup);
493: //
494: // Collection actionItems = KEWServiceLocator.getActionListService().findByRouteHeaderId(document.getRouteHeaderId());
495: // boolean foundrkirkend = false;
496: // boolean foundlshen = false;
497: // boolean founduser1 = false;
498: // boolean founduser2 = false;
499: //
500: // for (Iterator iter = actionItems.iterator(); iter.hasNext();) {
501: // ActionItem actionItem = (ActionItem) iter.next();
502: // String authId = actionItem.getUser().getAuthenticationUserId().getAuthenticationId();
503: // if (authId.equals("rkirkend")) {
504: // foundrkirkend = true;
505: // } else if (authId.equals("user1")) {
506: // founduser1 = true;
507: // } else if (authId.equals("lshen")) {
508: // foundlshen = true;
509: // } else if (authId.equals("user2")) {
510: // founduser2 = true;
511: // }
512: // }
513: //
514: // assertTrue("rkirkend should still have an AI because he is in 2 workgroups that are routed to.", foundrkirkend);
515: // assertTrue("user1 should have an AI because they were added to 'WorkflowAdmin'", founduser1);
516: // assertTrue("user2 should have an AI because they were added to 'WorkflowAdmin'", founduser2);
517: // assertFalse("lshen should not have an AI because they were removed from 'WorkflowAdmin'", foundlshen);
518:
519: }
520:
521: /**
522: * addresses the following bug http://fms.dfa.cornell.edu:8080/browse/KULWF-428
523: *
524: * @throws Exception
525: */
526: @Test
527: public void testWorkgroupActionItemGenerationWhenMultipleWorkgroupRequests()
528: throws Exception {
529: WorkflowDocument document = new WorkflowDocument(
530: new NetworkIdVO("user1"), "ActionItemDocumentType");
531: document.setTitle("");
532: document.routeDocument("");
533:
534: document = new WorkflowDocument(new NetworkIdVO("jitrue"),
535: document.getRouteHeaderId());
536:
537: ActionRequestVO[] ars = document.getActionRequests();
538: boolean routedWorkflowAdmin = false;
539: boolean routedTestWorkgroup = false;
540: for (int i = 0; i < ars.length; i++) {
541: ActionRequestVO request = ars[i];
542: if (request.isWorkgroupRequest()
543: && request.getWorkgroupVO().getWorkgroupName()
544: .equals("TestWorkgroup")) {
545: routedTestWorkgroup = true;
546: } else if (request.isWorkgroupRequest()
547: && request.getWorkgroupVO().getWorkgroupName()
548: .equals("WorkflowAdmin")) {
549: routedWorkflowAdmin = true;
550: }
551: }
552:
553: //verify that our test is sane
554: assertTrue("Should have routed to 'TestWorkgroup'",
555: routedTestWorkgroup);
556: assertTrue("Should have routed to 'WorkflowAdmin'",
557: routedWorkflowAdmin);
558: assertTrue(
559: "Approve should be requested to member of 'TestWorkgroup'",
560: document.isApprovalRequested());
561:
562: document.approve("");
563:
564: Collection actionItems = KEWServiceLocator
565: .getActionListService().findByRouteHeaderId(
566: document.getRouteHeaderId());
567:
568: assertEquals(
569: "There should be 6 action items to the WorkflowAdmin.",
570: 6, actionItems.size());
571:
572: for (Iterator iter = actionItems.iterator(); iter.hasNext();) {
573: ActionItem actionItem = (ActionItem) iter.next();
574: //don't worry about which workgroup - they can get activated in any order
575: assertNotNull("this should be a workgroup request",
576: actionItem.getWorkgroup());
577: }
578: }
579:
580: /**
581: * This test verifies that if someone gets more than one request routed to them then they will get
582: * multiple Action Items but only one of them will show up in their Action List.
583: */
584: @Test
585: public void testMultipleActionItemGeneration() throws Exception {
586: WorkflowDocument document = new WorkflowDocument(
587: new NetworkIdVO("user1"), "ActionItemDocumentType");
588: document.setTitle("");
589: document.routeDocument("");
590:
591: // now the document should be at both the WorkflowAdmin workgroup and the TestWorkgroup
592: // ewestfal is a member of both Workgroups so verify that he has two action items
593: WorkflowUser user = KEWServiceLocator.getUserService()
594: .getWorkflowUser(new AuthenticationUserId("ewestfal"));
595: Collection actionItems = KEWServiceLocator
596: .getActionListService()
597: .findByWorkflowUserRouteHeaderId(user.getWorkflowId(),
598: document.getRouteHeaderId());
599: assertEquals("Ewestfal should have two action items.", 2,
600: actionItems.size());
601:
602: // now check the action list, there should be only one entry
603: actionItems = KEWServiceLocator.getActionListService()
604: .getActionList(user, null);
605: assertEquals(
606: "Ewestfal should have one action item in his action list.",
607: 1, actionItems.size());
608: document = new WorkflowDocument(new NetworkIdVO("ewestfal"),
609: document.getRouteHeaderId());
610: assertTrue("Ewestfal should have an approval requested.",
611: document.isApprovalRequested());
612:
613: // approve as a member from the first workgroup
614: document = new WorkflowDocument(new NetworkIdVO("jitrue"),
615: document.getRouteHeaderId());
616: assertTrue("Jitrue should have an approval requested.",
617: document.isApprovalRequested());
618: document.approve("");
619:
620: // now ewestfal should have only one action item in both his action items and his action list
621: actionItems = KEWServiceLocator.getActionListService()
622: .findByWorkflowUserRouteHeaderId(user.getWorkflowId(),
623: document.getRouteHeaderId());
624: assertEquals("Ewestfal should have one action item.", 1,
625: actionItems.size());
626: Long actionItemId = ((ActionItem) actionItems.iterator().next())
627: .getActionItemId();
628: actionItems = KEWServiceLocator.getActionListService()
629: .getActionList(user, null);
630: assertEquals(
631: "Ewestfal should have one action item in his action list.",
632: 1, actionItems.size());
633: assertEquals("The two action items should be the same.",
634: actionItemId, ((ActionItem) actionItems.iterator()
635: .next()).getActionItemId());
636: }
637:
638: /**
639: * This tests verifies that bug KULWF-507 has been fixed:
640: *
641: * https://test.kuali.org/jira/browse/KULWF-507
642: *
643: * To fix this, we implemented the system so that multiple action items are generated rather then just
644: * one which gets reassigned across multiple requests as needed.
645: *
646: * This test verifies that after the blanket approval, there should no longer be an orphaned Acknowledge
647: * request. The workgroup used here is the TestWorkgroup and "user1" is ewestfal with "user2" as rkirkend.
648: *
649: * The routing is configured in the BAOrphanedRequestDocumentType.
650: */
651: @Test
652: public void testOrphanedAcknowledgeFromBlanketApprovalFix()
653: throws Exception {
654: WorkflowDocument document = new WorkflowDocument(
655: new NetworkIdVO("ewestfal"),
656: "BAOrphanedRequestDocumentType");
657: document.blanketApprove("");
658: assertTrue("Document should be processed.", document
659: .stateIsProcessed());
660:
661: // after the document has blanket approved there should be 2 action items since the blanket approver
662: // is in the final workgroup. These action items should be the acknowledges generated to both
663: // rkirkend and user1
664: int numActionItems = actionListService.findByRouteHeaderId(
665: document.getRouteHeaderId()).size();
666: assertEquals("Incorrect number of action items.", 2,
667: numActionItems);
668:
669: WorkflowUser user1 = KEWServiceLocator.getUserService()
670: .getWorkflowUser(new NetworkIdVO("user1"));
671: WorkflowUser rkirkend = KEWServiceLocator.getUserService()
672: .getWorkflowUser(new NetworkIdVO("rkirkend"));
673:
674: // check that user1 has 1 action item
675: Collection actionItems = actionListService
676: .findByWorkflowUserRouteHeaderId(user1.getWorkflowId(),
677: document.getRouteHeaderId());
678: assertEquals("user1 should have one action item.", 1,
679: actionItems.size());
680:
681: // check that rkirkend still has 1, the is where the bug would have manifested itself before, rkirkend would have had
682: // no action item (hence the orphaned request)
683: actionItems = actionListService
684: .findByWorkflowUserRouteHeaderId(rkirkend
685: .getWorkflowId(), document.getRouteHeaderId());
686: assertEquals("rkirkend should have one action item.", 1,
687: actionItems.size());
688:
689: // lets go ahead and take it to final for funsies
690: document = new WorkflowDocument(new NetworkIdVO("rkirkend"),
691: document.getRouteHeaderId());
692: assertTrue("Should have ack request.", document
693: .isAcknowledgeRequested());
694: document.acknowledge("");
695: assertTrue("Should still be PROCESSED.", document
696: .stateIsProcessed());
697:
698: document = new WorkflowDocument(new NetworkIdVO("user1"),
699: document.getRouteHeaderId());
700: assertTrue("Should have ack request.", document
701: .isAcknowledgeRequested());
702: document.acknowledge("");
703: assertTrue("Should now be FINAL.", document.stateIsFinal());
704: }
705:
706: /**
707: * Executes a deep copy of the BaseWorkgroup
708: */
709: private BaseWorkgroup copy(BaseWorkgroup workgroup)
710: throws Exception {
711: BaseWorkgroup workgroupCopy = (BaseWorkgroup) KEWServiceLocator
712: .getWorkgroupService().copy(workgroup);
713: // copy above does a shallow copy so we need to deep copy members
714: List<BaseWorkgroupMember> members = workgroupCopy
715: .getWorkgroupMembers();
716: List<BaseWorkgroupMember> membersCopy = new ArrayList<BaseWorkgroupMember>();
717: for (BaseWorkgroupMember member : members) {
718: membersCopy.add(copy(member));
719: }
720: workgroupCopy.setWorkgroupMembers(membersCopy);
721: workgroupCopy.setMembers(new ArrayList<Recipient>());
722: workgroupCopy.materializeMembers();
723: return workgroupCopy;
724: }
725:
726: private BaseWorkgroupMember copy(BaseWorkgroupMember member)
727: throws Exception {
728: return (BaseWorkgroupMember) BeanUtils.cloneBean(member);
729: }
730:
731: }
|