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.assertEquals;
19 import static org.junit.Assert.assertFalse;
20 import static org.junit.Assert.assertTrue;
21
22 import java.util.List;
23
24 import org.junit.Test;
25 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
26 import org.kuali.rice.kew.actions.BlanketApproveTest.NotifySetup;
27 import org.kuali.rice.kew.api.WorkflowDocument;
28 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
29 import org.kuali.rice.kew.api.action.ActionRequestType;
30 import org.kuali.rice.kew.api.action.ActionType;
31 import org.kuali.rice.kew.api.document.DocumentStatus;
32 import org.kuali.rice.kew.service.KEWServiceLocator;
33 import org.kuali.rice.kew.test.KEWTestCase;
34 import org.kuali.rice.kew.api.KewApiConstants;
35
36
37
38
39 public class SuperUserActionRequestApproveEventTest extends KEWTestCase {
40
41 protected void loadTestData() throws Exception {
42 loadXmlFile("ActionsConfig.xml");
43 }
44
45 @Test public void testSuperUserActionsOnEnroute() throws Exception {
46 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME);
47 document.adHocToPrincipal(ActionRequestType.FYI, "", getPrincipalIdForName("rkirkend"), "", true);
48 document.adHocToPrincipal(ActionRequestType.APPROVE, "", getPrincipalIdForName("jhopf"), "", true);
49 document.route("");
50
51 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
52 assertTrue("rkirkend should have an FYI request.", document.isFYIRequested());
53
54 String rkirkendPrincipalId = getPrincipalIdForName("rkirkend");
55 List<ActionRequestValue> actionRequests = KEWServiceLocator.getActionRequestService().findAllValidRequests(rkirkendPrincipalId, document.getDocumentId(), KewApiConstants.ACTION_REQUEST_FYI_REQ);
56 assertEquals("There should only be 1 fyi request to rkirkend.", 1, actionRequests.size());
57 document = WorkflowDocumentFactory.loadDocument(rkirkendPrincipalId, document.getDocumentId());
58 document.superUserTakeRequestedAction(actionRequests.get(0).getActionRequestId().toString(), "");
59
60
61 document = WorkflowDocumentFactory.loadDocument(rkirkendPrincipalId, document.getDocumentId());
62 assertFalse("rkirkend should no longer have an FYI request.", document.isFYIRequested());
63
64
65 assertTrue("Document should still be ENROUTE", document.isEnroute());
66
67 }
68
69 @Test public void testSuperUserActionsOnFinal() throws Exception {
70 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "SuperUserApproveActionRequestFyiTest");
71 document.adHocToPrincipal(ActionRequestType.FYI, "", getPrincipalIdForName("rkirkend"), "", true);
72 document.route("");
73
74
75 assertEquals("Document should be FINAL", DocumentStatus.FINAL, document.getStatus());
76
77 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
78 assertTrue("rkirkend should have an FYI request.", document.isFYIRequested());
79
80 String rkirkendPrincipalId = getPrincipalIdForName("rkirkend");
81 List<ActionRequestValue> actionRequests = KEWServiceLocator.getActionRequestService().findAllValidRequests(rkirkendPrincipalId, document.getDocumentId(), KewApiConstants.ACTION_REQUEST_FYI_REQ);
82 assertEquals("There should only be 1 fyi request to rkirkend.", 1, actionRequests.size());
83 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
84 document.superUserTakeRequestedAction(actionRequests.get(0).getActionRequestId().toString(), "");
85
86
87 document = WorkflowDocumentFactory.loadDocument(rkirkendPrincipalId, document.getDocumentId());
88 assertFalse("rkirkend should no longer have an FYI request.", document.isFYIRequested());
89 }
90
91 @Test public void testSuperUserActionsOnProcessed() throws Exception {
92 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "SuperUserApproveActionRequestFyiTest");
93 document.adHocToPrincipal(ActionRequestType.ACKNOWLEDGE, "", getPrincipalIdForName("jhopf"), "", true);
94 document.adHocToPrincipal(ActionRequestType.FYI, "", getPrincipalIdForName("rkirkend"), "", true);
95 document.route("");
96
97
98 assertEquals("Document should be PROCESSED", DocumentStatus.PROCESSED, document.getStatus());
99
100 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
101 assertTrue("rkirkend should have an FYI request.", document.isFYIRequested());
102
103 String rkirkendPrincipalId = getPrincipalIdForName("rkirkend");
104 List<ActionRequestValue> fyiActionRequests = KEWServiceLocator.getActionRequestService().findAllValidRequests(rkirkendPrincipalId, document.getDocumentId(), KewApiConstants.ACTION_REQUEST_FYI_REQ);
105 assertEquals("There should only be 1 fyi request to rkirkend.", 1, fyiActionRequests.size());
106 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
107 document.superUserTakeRequestedAction(fyiActionRequests.get(0).getActionRequestId().toString(), "");
108
109
110 document = WorkflowDocumentFactory.loadDocument(rkirkendPrincipalId, document.getDocumentId());
111 assertFalse("rkirkend should no longer have an FYI request.", document.isFYIRequested());
112
113
114 assertEquals("Document should be PROCESSED", DocumentStatus.PROCESSED, document.getStatus());
115
116 String jhopfPrincipalId = getPrincipalIdForName("jhopf");
117 List<ActionRequestValue> ackActionRequests = KEWServiceLocator.getActionRequestService().findAllValidRequests(jhopfPrincipalId, document.getDocumentId(), KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ);
118 assertEquals("There should only be 1 ACK request to jhopf.", 1, ackActionRequests.size());
119 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
120 document.superUserTakeRequestedAction(ackActionRequests.get(0).getActionRequestId().toString(), "");
121
122
123 document = WorkflowDocumentFactory.loadDocument(jhopfPrincipalId, document.getDocumentId());
124 assertFalse("jhopf should no longer have an ACK request.", document.isAcknowledgeRequested());
125
126
127 assertEquals("Document should be FINAL", DocumentStatus.FINAL, document.getStatus());
128 }
129
130
131 @Test public void testSuperUserActionRoutesDocumentToEnroute() throws Exception {
132 String documentId = testSuperUserActionRoutesDocument("SuperUserApproveActionRequestApproveTest");
133 WorkflowDocument document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), documentId);
134
135 assertEquals("Document should be ENROUTE", DocumentStatus.ENROUTE, document.getStatus());
136 }
137
138 @Test public void testSuperUserActionRoutesDocumentToFinal() throws Exception {
139 String documentId = testSuperUserActionRoutesDocument("SuperUserApproveActionRequestFyiTest");
140 WorkflowDocument document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), documentId);
141
142 assertEquals("Document should be FINAL", DocumentStatus.FINAL, document.getStatus());
143 }
144
145 private String testSuperUserActionRoutesDocument(String documentType) throws Exception {
146 String ewestfalPrincipalId = getPrincipalIdForName("ewestfal");
147 WorkflowDocument document = WorkflowDocumentFactory.createDocument(ewestfalPrincipalId, documentType);
148 document.saveDocument("");
149
150 assertEquals("Document should be SAVED", DocumentStatus.SAVED, document.getStatus());
151
152 document = WorkflowDocumentFactory.loadDocument(ewestfalPrincipalId, document.getDocumentId());
153 assertTrue("ewestfal should have Complete request", document.isCompletionRequested());
154
155 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
156 assertFalse("rkirkend should not have Complete request", document.isCompletionRequested());
157 assertFalse("rkirkend should not have Approve request", document.isApprovalRequested());
158 assertTrue("rkirkend should be a super user of the document", document.isValidAction(ActionType.SU_APPROVE));
159
160 List<ActionRequestValue> actionRequests = KEWServiceLocator.getActionRequestService().findAllValidRequests(ewestfalPrincipalId, document.getDocumentId(), KewApiConstants.ACTION_REQUEST_COMPLETE_REQ);
161 assertEquals("There should only be 1 complete request to ewestfal as result of the save.", 1, actionRequests.size());
162 document.superUserTakeRequestedAction(actionRequests.get(0).getActionRequestId().toString(), "");
163
164
165 document = WorkflowDocumentFactory.loadDocument(ewestfalPrincipalId, document.getDocumentId());
166 assertFalse("ewestfal should not have Complete request", document.isCompletionRequested());
167
168 return document.getDocumentId();
169 }
170
171 @Test public void testSavedDocumentSuperUserAdhocActionsApprove() throws Exception {
172 String initiatorNetworkId = "ewestfal";
173 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName(initiatorNetworkId), "SuperUserApproveActionRequestFyiTest");
174 String adhocActionUserNetworkId = "jhopf";
175 document.adHocToPrincipal(ActionRequestType.APPROVE, "", getPrincipalIdForName(adhocActionUserNetworkId), "", true);
176 document.saveDocument("");
177
178 assertEquals("Document should be SAVED", DocumentStatus.SAVED, document.getStatus());
179
180 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
181 assertTrue("ewestfal should have Complete request", document.isCompletionRequested());
182
183 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
184 assertFalse("rkirkend should not have Complete request", document.isCompletionRequested());
185 assertFalse("rkirkend should not have Approve request", document.isApprovalRequested());
186 assertTrue("rkirkend should be a super user of the document", document.isValidAction(ActionType.SU_APPROVE));
187 String adhocPrincipalId = getPrincipalIdForName(adhocActionUserNetworkId);
188 List<ActionRequestValue> actionRequests = KEWServiceLocator.getActionRequestService().findAllValidRequests(adhocPrincipalId, document.getDocumentId(), ActionRequestType.APPROVE.getCode());
189 assertEquals("There should only be 1 approve request to " + adhocActionUserNetworkId + ".", 1, actionRequests.size());
190 document.superUserTakeRequestedAction(actionRequests.get(0).getActionRequestId().toString(), "");
191
192
193 document = WorkflowDocumentFactory.loadDocument(adhocPrincipalId, document.getDocumentId());
194 assertFalse(adhocPrincipalId + " should not have approve request", document.isApprovalRequested());
195
196
197 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName(initiatorNetworkId), document.getDocumentId());
198 assertTrue(initiatorNetworkId + " should not have complete request", document.isCompletionRequested());
199
200
201 assertEquals("Document should be SAVED", DocumentStatus.SAVED, document.getStatus());
202 }
203
204 }