1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.actions;
17
18 import static org.junit.Assert.assertTrue;
19 import static org.junit.Assert.fail;
20
21 import java.util.Collection;
22 import java.util.Iterator;
23 import java.util.List;
24
25 import org.junit.Test;
26 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
27 import org.kuali.rice.kew.actions.BlanketApproveTest.NotifySetup;
28 import org.kuali.rice.kew.api.WorkflowDocument;
29 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
30 import org.kuali.rice.kew.service.KEWServiceLocator;
31 import org.kuali.rice.kew.test.KEWTestCase;
32
33 public class RoleTest extends KEWTestCase {
34
35 protected void loadTestData() throws Exception {
36 loadXmlFile("ActionsConfig.xml");
37 }
38
39 @Test public void testRoleRequestGeneration() throws Exception {
40 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME);
41 document.route("");
42
43 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId());
44 assertTrue("This user should have an approve request", document.isApprovalRequested());
45 document.approve("");
46
47 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
48 assertTrue("This user should have an approve request", document.isApprovalRequested());
49 document.approve("");
50
51 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
52 assertTrue("This user should have an approve request", document.isApprovalRequested());
53 document.approve("");
54
55
56 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("natjohns"), document.getDocumentId());
57 assertTrue("This user should have an approve request", document.isApprovalRequested());
58 document.approve("");
59
60 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
61 document.approve("");
62
63 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("xqi"), document.getDocumentId());
64 document.acknowledge("");
65
66 assertTrue("Document should be final", document.isFinal());
67
68 List requests = KEWServiceLocator.getActionRequestService().findAllActionRequestsByDocumentId(document.getDocumentId());
69 List rootRequests = KEWServiceLocator.getActionRequestService().getRootRequests(requests);
70
71
72 for (Iterator iter = rootRequests.iterator(); iter.hasNext();) {
73 ActionRequestValue request = (ActionRequestValue) iter.next();
74 if (request.isRoleRequest()) {
75
76 iterateChildrenRequests(request.getChildrenRequests(), new String[] {"U", "W"}, request);
77 }
78 }
79 }
80
81 private void iterateChildrenRequests(Collection childrenRequests, String[] requestTypes, ActionRequestValue parentRequest) {
82 for (Iterator iter = childrenRequests.iterator(); iter.hasNext();) {
83 ActionRequestValue request = (ActionRequestValue) iter.next();
84 boolean matched = false;
85 for (int i = 0; i < requestTypes.length; i++) {
86 if (request.getRecipientTypeCd().equals(requestTypes[i])) {
87 matched = true;
88 }
89 }
90 if (!matched) {
91 fail("Didn't find request of types expected Recipient Type: " + parentRequest.getRecipientTypeCd() + " RoleName: " + parentRequest.getRoleName() + " Qualified Role Name:" + parentRequest.getQualifiedRoleName() + " RuleId: " + parentRequest.getRuleBaseValuesId());
92 }
93
94 if (request.isRoleRequest()) {
95
96 iterateChildrenRequests(request.getChildrenRequests(), new String[] {"U", "W"}, request);
97 }
98 }
99 }
100 }