View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    *
4    *
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.opensource.org/licenses/ecl2.php
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.kuali.rice.kew.actions;
18  
19  import java.util.List;
20  
21  import org.junit.Test;
22  import org.kuali.rice.kew.actionrequest.ActionRequestValue;
23  import org.kuali.rice.kew.actions.BlanketApproveTest.NotifySetup;
24  import org.kuali.rice.kew.dto.NetworkIdDTO;
25  import org.kuali.rice.kew.service.KEWServiceLocator;
26  import org.kuali.rice.kew.service.WorkflowDocument;
27  import org.kuali.rice.kew.test.KEWTestCase;
28  import org.kuali.rice.kew.util.KEWConstants;
29  
30  
31  /**
32   * Tests the super user actions available on the API.
33   */
34  public class SuperUserActionRequestApproveEventTest extends KEWTestCase {
35  
36      protected void loadTestData() throws Exception {
37          loadXmlFile("ActionsConfig.xml");
38      }
39  
40      @Test public void testSuperUserActionsOnEnroute() throws Exception {
41          WorkflowDocument document = new WorkflowDocument(new NetworkIdDTO("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME);
42          document.adHocRouteDocumentToPrincipal(KEWConstants.ACTION_REQUEST_FYI_REQ, "", getPrincipalIdForName("rkirkend"), "", true);
43          document.adHocRouteDocumentToPrincipal(KEWConstants.ACTION_REQUEST_APPROVE_REQ, "", getPrincipalIdForName("jhopf"), "", true);
44          document.routeDocument("");
45  
46          document = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document.getRouteHeaderId());
47          assertTrue("rkirkend should have an FYI request.", document.isFYIRequested());
48  
49          String rkirkendPrincipalId = getPrincipalIdForName("rkirkend");
50          List<ActionRequestValue> actionRequests = KEWServiceLocator.getActionRequestService().findAllValidRequests(rkirkendPrincipalId, document.getRouteHeaderId(), KEWConstants.ACTION_REQUEST_FYI_REQ);
51          assertEquals("There should only be 1 fyi request to rkirkend.", 1, actionRequests.size());
52          document = new WorkflowDocument(rkirkendPrincipalId, document.getRouteHeaderId());
53          document.superUserActionRequestApprove(actionRequests.get(0).getActionRequestId(), "");
54  
55          // FYI should no longer be requested
56          document = new WorkflowDocument(rkirkendPrincipalId, document.getRouteHeaderId());
57          assertFalse("rkirkend should no longer have an FYI request.", document.isFYIRequested());
58  
59          // doc should still be enroute
60          assertTrue("Document should still be ENROUTE", document.stateIsEnroute());
61  
62      }
63  
64      @Test public void testSuperUserActionsOnFinal() throws Exception {
65          WorkflowDocument document = new WorkflowDocument(new NetworkIdDTO("ewestfal"), "SuperUserApproveActionRequestFyiTest");
66          document.adHocRouteDocumentToPrincipal(KEWConstants.ACTION_REQUEST_FYI_REQ, "", getPrincipalIdForName("rkirkend"), "", true);
67          document.routeDocument("");
68  
69          // doc should still be final
70          assertEquals("Document should be FINAL", KEWConstants.ROUTE_HEADER_FINAL_CD, document.getRouteHeader().getDocRouteStatus());
71  
72          document = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document.getRouteHeaderId());
73          assertTrue("rkirkend should have an FYI request.", document.isFYIRequested());
74  
75          String rkirkendPrincipalId = getPrincipalIdForName("rkirkend");
76          List<ActionRequestValue> actionRequests = KEWServiceLocator.getActionRequestService().findAllValidRequests(rkirkendPrincipalId, document.getRouteHeaderId(), KEWConstants.ACTION_REQUEST_FYI_REQ);
77          assertEquals("There should only be 1 fyi request to rkirkend.", 1, actionRequests.size());
78          document = new WorkflowDocument(new NetworkIdDTO("ewestfal"), document.getRouteHeaderId());
79          document.superUserActionRequestApprove(actionRequests.get(0).getActionRequestId(), "");
80  
81          // FYI should no longer be requested
82          document = new WorkflowDocument(rkirkendPrincipalId, document.getRouteHeaderId());
83          assertFalse("rkirkend should no longer have an FYI request.", document.isFYIRequested());
84      }
85      
86      @Test public void testSuperUserActionsOnProcessed() throws Exception {
87          WorkflowDocument document = new WorkflowDocument(new NetworkIdDTO("ewestfal"), "SuperUserApproveActionRequestFyiTest");
88          document.adHocRouteDocumentToPrincipal(KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, "", getPrincipalIdForName("jhopf"), "", true);
89          document.adHocRouteDocumentToPrincipal(KEWConstants.ACTION_REQUEST_FYI_REQ, "", getPrincipalIdForName("rkirkend"), "", true);
90          document.routeDocument("");
91  
92          // doc should still be processed
93          assertEquals("Document should be PROCESSED", KEWConstants.ROUTE_HEADER_PROCESSED_CD, document.getRouteHeader().getDocRouteStatus());
94  
95          document = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document.getRouteHeaderId());
96          assertTrue("rkirkend should have an FYI request.", document.isFYIRequested());
97  
98          String rkirkendPrincipalId = getPrincipalIdForName("rkirkend");
99          List<ActionRequestValue> fyiActionRequests = KEWServiceLocator.getActionRequestService().findAllValidRequests(rkirkendPrincipalId, document.getRouteHeaderId(), KEWConstants.ACTION_REQUEST_FYI_REQ);
100         assertEquals("There should only be 1 fyi request to rkirkend.", 1, fyiActionRequests.size());
101         document = new WorkflowDocument(new NetworkIdDTO("ewestfal"), document.getRouteHeaderId());
102         document.superUserActionRequestApprove(fyiActionRequests.get(0).getActionRequestId(), "");
103 
104         // FYI should no longer be requested
105         document = new WorkflowDocument(rkirkendPrincipalId, document.getRouteHeaderId());
106         assertFalse("rkirkend should no longer have an FYI request.", document.isFYIRequested());
107 
108         // doc should still be processed
109         assertEquals("Document should be PROCESSED", KEWConstants.ROUTE_HEADER_PROCESSED_CD, document.getRouteHeader().getDocRouteStatus());
110 
111         String jhopfPrincipalId = getPrincipalIdForName("jhopf");
112         List<ActionRequestValue> ackActionRequests = KEWServiceLocator.getActionRequestService().findAllValidRequests(jhopfPrincipalId, document.getRouteHeaderId(), KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ);
113         assertEquals("There should only be 1 ACK request to jhopf.", 1, ackActionRequests.size());
114         document = new WorkflowDocument(new NetworkIdDTO("ewestfal"), document.getRouteHeaderId());
115         document.superUserActionRequestApprove(ackActionRequests.get(0).getActionRequestId(), "");
116 
117         // ACK should no longer be requested
118         document = new WorkflowDocument(jhopfPrincipalId, document.getRouteHeaderId());
119         assertFalse("jhopf should no longer have an ACK request.", document.isAcknowledgeRequested());
120 
121         // doc should be final
122         assertEquals("Document should be FINAL", KEWConstants.ROUTE_HEADER_FINAL_CD, document.getRouteHeader().getDocRouteStatus());
123     }
124     
125 
126     @Test public void testSuperUserActionRoutesDocumentToEnroute() throws Exception {
127 	Long routeHeaderId = testSuperUserActionRoutesDocument("SuperUserApproveActionRequestApproveTest");
128 	WorkflowDocument document = new WorkflowDocument(new NetworkIdDTO("ewestfal"), routeHeaderId);
129         // doc should now be enroute
130         assertEquals("Document should be ENROUTE", KEWConstants.ROUTE_HEADER_ENROUTE_CD, document.getRouteHeader().getDocRouteStatus());
131     }
132 
133     @Test public void testSuperUserActionRoutesDocumentToFinal() throws Exception {
134 	Long routeHeaderId = testSuperUserActionRoutesDocument("SuperUserApproveActionRequestFyiTest");
135 	WorkflowDocument document = new WorkflowDocument(new NetworkIdDTO("ewestfal"), routeHeaderId);
136         // doc should now be enroute
137         assertEquals("Document should be FINAL", KEWConstants.ROUTE_HEADER_FINAL_CD, document.getRouteHeader().getDocRouteStatus());
138     }
139 
140     private Long testSuperUserActionRoutesDocument(String documentType) throws Exception {
141     	String ewestfalPrincipalId = getPrincipalIdForName("ewestfal");
142         WorkflowDocument document = new WorkflowDocument(ewestfalPrincipalId, documentType);
143         document.saveDocument("");
144         // doc should saved
145         assertEquals("Document should be SAVED", KEWConstants.ROUTE_HEADER_SAVED_CD, document.getRouteHeader().getDocRouteStatus());
146 
147         document = new WorkflowDocument(ewestfalPrincipalId, document.getRouteHeaderId());
148         assertTrue("ewestfal should have Complete request", document.isCompletionRequested());
149 
150         document = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document.getRouteHeaderId());
151         assertFalse("rkirkend should not have Complete request", document.isCompletionRequested());
152         assertFalse("rkirkend should not have Approve request", document.isApprovalRequested());
153         assertTrue("rkirkend should be a super user of the document", document.isSuperUser());
154         
155         List<ActionRequestValue> actionRequests = KEWServiceLocator.getActionRequestService().findAllValidRequests(ewestfalPrincipalId, document.getRouteHeaderId(), KEWConstants.ACTION_REQUEST_COMPLETE_REQ);
156         assertEquals("There should only be 1 complete request to ewestfal as result of the save.", 1, actionRequests.size());
157         document.superUserActionRequestApprove(actionRequests.get(0).getActionRequestId(), "");
158 
159         // Complete should no longer be requested
160         document = new WorkflowDocument(ewestfalPrincipalId, document.getRouteHeaderId());
161         assertFalse("ewestfal should not have Complete request", document.isCompletionRequested());
162 
163         return document.getRouteHeaderId();
164     }
165 
166     @Test public void testSavedDocumentSuperUserAdhocActionsApprove() throws Exception {
167 	String initiatorNetworkId = "ewestfal";
168         WorkflowDocument document = new WorkflowDocument(new NetworkIdDTO(initiatorNetworkId), "SuperUserApproveActionRequestFyiTest");
169         String adhocActionRequestCode = KEWConstants.ACTION_REQUEST_APPROVE_REQ;
170         String adhocActionUserNetworkId = "jhopf";
171         document.adHocRouteDocumentToPrincipal(adhocActionRequestCode, "", getPrincipalIdForName(adhocActionUserNetworkId), "", true);
172         document.saveDocument("");
173         // doc should be saved
174         assertEquals("Document should be SAVED", KEWConstants.ROUTE_HEADER_SAVED_CD, document.getRouteHeader().getDocRouteStatus());
175 
176         document = new WorkflowDocument(new NetworkIdDTO("ewestfal"), document.getRouteHeaderId());
177         assertTrue("ewestfal should have Complete request", document.isCompletionRequested());
178 
179         document = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document.getRouteHeaderId());
180         assertFalse("rkirkend should not have Complete request", document.isCompletionRequested());
181         assertFalse("rkirkend should not have Approve request", document.isApprovalRequested());
182         assertTrue("rkirkend should be a super user of the document", document.isSuperUser());
183         String adhocPrincipalId = getPrincipalIdForName(adhocActionUserNetworkId);
184         List<ActionRequestValue> actionRequests = KEWServiceLocator.getActionRequestService().findAllValidRequests(adhocPrincipalId, document.getRouteHeaderId(), adhocActionRequestCode);
185         assertEquals("There should only be 1 approve request to " + adhocActionUserNetworkId + ".", 1, actionRequests.size());
186         document.superUserActionRequestApprove(actionRequests.get(0).getActionRequestId(), "");
187 
188         // approve should no longer be requested
189         document = new WorkflowDocument(adhocPrincipalId, document.getRouteHeaderId());
190         assertFalse(adhocPrincipalId + " should not have approve request", document.isApprovalRequested());
191 
192         // complete should no longer be requested
193         document = new WorkflowDocument(new NetworkIdDTO(initiatorNetworkId), document.getRouteHeaderId());
194         assertTrue(initiatorNetworkId + " should not have complete request", document.isCompletionRequested());
195 
196         // doc should still be saved
197         assertEquals("Document should be SAVED", KEWConstants.ROUTE_HEADER_SAVED_CD, document.getRouteHeader().getDocRouteStatus());
198     }
199 
200 }