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  
20  import java.util.List;
21  import java.util.Set;
22  
23  import org.junit.Test;
24  import org.kuali.rice.kew.actionrequest.ActionRequestValue;
25  import org.kuali.rice.kew.dto.MovePointDTO;
26  import org.kuali.rice.kew.dto.NetworkIdDTO;
27  import org.kuali.rice.kew.dto.RouteNodeInstanceDTO;
28  import org.kuali.rice.kew.service.KEWServiceLocator;
29  import org.kuali.rice.kew.service.WorkflowDocument;
30  import org.kuali.rice.kew.service.WorkflowInfo;
31  import org.kuali.rice.kew.test.KEWTestCase;
32  import org.kuali.rice.kew.test.TestUtilities;
33  
34  
35  public class MoveDocumentTest extends KEWTestCase {
36  
37      protected void loadTestData() throws Exception {
38          loadXmlFile("ActionsConfig.xml");
39      }
40     
41      /**
42       * Tests that we can move a sequential document forward and backward.
43       *
44       */
45      @Test public void testMoveDocumentSequential() throws Exception {
46          WorkflowDocument document = new WorkflowDocument(new NetworkIdDTO("user1"), SeqSetup.DOCUMENT_TYPE_NAME);
47          document.routeDocument("");
48          
49          document = new WorkflowDocument(new NetworkIdDTO("bmcgough"), document.getRouteHeaderId());
50          assertTrue("Bmcgough should have an approve.", document.isApprovalRequested());
51          document = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document.getRouteHeaderId());
52          assertTrue("Rkirkend should have an approve.", document.isApprovalRequested());
53          assertEquals("Should be at the WorkflowDocument Node.", SeqSetup.WORKFLOW_DOCUMENT_NODE, document.getNodeNames()[0]);
54          
55          // move the document forward one node
56          document.moveDocument(new MovePointDTO(SeqSetup.WORKFLOW_DOCUMENT_NODE, 1), "");
57          
58          List actionRequests = KEWServiceLocator.getActionRequestService().findPendingByDoc(document.getRouteHeaderId());
59          assertEquals("Should be only 1 pending approve request to pmckown.", 1, actionRequests.size());
60          assertEquals("Should be at the WorkflowDocument2 Node.", SeqSetup.WORKFLOW_DOCUMENT_2_NODE, document.getNodeNames()[0]);
61          
62          // after moving the document forward, bmcgough and rkirkend should no longer have requests, but phil should
63          document = new WorkflowDocument(new NetworkIdDTO("bmcgough"), document.getRouteHeaderId());
64          assertFalse("Bmcgough should NOT have an approve.", document.isApprovalRequested());
65          document = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document.getRouteHeaderId());
66          assertFalse("Rkirkend should NOT have an approve.", document.isApprovalRequested());
67          
68          document = new WorkflowDocument(new NetworkIdDTO("pmckown"), document.getRouteHeaderId());
69          assertTrue("Pmckown should have an approve.", document.isApprovalRequested());
70          ActionRequestValue pmckownRequest = (ActionRequestValue)actionRequests.get(0);
71          
72          // now try moving it to itself, effectively refreshing the node
73          document.moveDocument(new MovePointDTO(SeqSetup.WORKFLOW_DOCUMENT_2_NODE, 0), "");
74          assertTrue("Pmckown should still have an approve.", document.isApprovalRequested());
75          actionRequests = KEWServiceLocator.getActionRequestService().findPendingByDoc(document.getRouteHeaderId());
76          assertEquals("Should be only 1 pending approve request to pmckown.", 1, actionRequests.size());
77          assertEquals("Should be at the WorkflowDocument2 Node.", SeqSetup.WORKFLOW_DOCUMENT_2_NODE, document.getNodeNames()[0]);
78          
79          // since this should have invoked a refresh, let's ensure that the action request ids are different after the move
80          assertFalse("Action request ids should be different.", pmckownRequest.getActionRequestId().equals(((ActionRequestValue)actionRequests.get(0)).getActionRequestId()));
81          
82          // now try moving it back
83          document.moveDocument(new MovePointDTO(SeqSetup.WORKFLOW_DOCUMENT_2_NODE, -1), "");
84          
85          // document should now be back at the WorkflowDocumentNode with requests to rkirkend and brian
86          actionRequests = KEWServiceLocator.getActionRequestService().findPendingByDoc(document.getRouteHeaderId());
87          assertEquals("Should be 2 pending requests.", 2, actionRequests.size());
88          
89          assertEquals("Should be at the WorkflowDocument Node.", SeqSetup.WORKFLOW_DOCUMENT_NODE, document.getNodeNames()[0]);
90          document = new WorkflowDocument(new NetworkIdDTO("bmcgough"), document.getRouteHeaderId());
91          assertTrue("Bmcgough should have an approve.", document.isApprovalRequested());
92          document = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document.getRouteHeaderId());
93          assertTrue("Rkirkend should have an approve.", document.isApprovalRequested());
94          
95          
96          // Let's do a sanity check to make sure we're still ENROUTE and move the doc to an ack node, rendering it PROCESSED,
97          // also, we'll check that there are no permissions enforced on the move document action by moving as a random user
98          document = new WorkflowDocument(new NetworkIdDTO("xqi"), document.getRouteHeaderId());
99          assertTrue("Doc should be ENROUTE.", document.stateIsEnroute());
100         document.moveDocument(new MovePointDTO(SeqSetup.WORKFLOW_DOCUMENT_NODE, 2), "");
101         assertTrue("Doc should be PROCESSED.", document.stateIsProcessed());
102     }
103 
104     /**
105      * This tests that we can invoke the move document command inside of a sub process.
106      */
107     @Test public void testMoveDocumentInsideProcess() throws Exception {
108         WorkflowDocument document = new WorkflowDocument(new NetworkIdDTO("user1"), "MoveInProcessTest");
109         document.routeDocument("");
110         
111         // approve as bmcgough and rkirkend to move into process
112         document = new WorkflowDocument(new NetworkIdDTO("bmcgough"), document.getRouteHeaderId());
113         assertTrue("bmcgough should have approve", document.isApprovalRequested());
114         document.approve("");
115         document = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document.getRouteHeaderId());
116         assertTrue("rkirkend should have approve", document.isApprovalRequested());
117         document.approve("");
118         
119         WorkflowInfo info = new WorkflowInfo();
120         RouteNodeInstanceDTO[] activeNodeInstances = info.getActiveNodeInstances(document.getRouteHeaderId());
121         assertEquals("Should be 1 active node instance.", 1, activeNodeInstances.length);
122         RouteNodeInstanceDTO node2 = activeNodeInstances[0];
123         assertEquals("Should be at the WorkflowDocument2 node.", SeqSetup.WORKFLOW_DOCUMENT_2_NODE, node2.getName());
124         assertTrue("Node should be in a process.", node2.getProcessId() != null);
125         
126         // now try to move the document forward one which will keep us inside the subprocess
127         document.moveDocument(new MovePointDTO(SeqSetup.WORKFLOW_DOCUMENT_2_NODE, 1), "");
128         
129         activeNodeInstances = info.getActiveNodeInstances(document.getRouteHeaderId());
130         RouteNodeInstanceDTO node3 = activeNodeInstances[0];
131         assertEquals("Should be at the WorkflowDocument3 node.", SeqSetup.WORKFLOW_DOCUMENT_3_NODE, node3.getName());
132         assertTrue("Node should be in a process.", node3.getProcessId() != null);
133         assertEquals("Node 2 and 3 should be in the same process.", node2.getProcessId(), node3.getProcessId());
134         
135         document.moveDocument(new MovePointDTO(SeqSetup.WORKFLOW_DOCUMENT_3_NODE, 0), "");
136         
137         document.moveDocument(new MovePointDTO(SeqSetup.WORKFLOW_DOCUMENT_3_NODE, -1), "");
138     }
139     
140     @Test public void testMoveDocumentParallel() throws Exception {
141     	WorkflowDocument document = new WorkflowDocument(new NetworkIdDTO("ewestfal"), ParallelSetup.DOCUMENT_TYPE_NAME);
142     	document.blanketApprove("", new String[] { ParallelSetup.WORKFLOW_DOCUMENT_2_B2_NODE, ParallelSetup.WORKFLOW_DOCUMENT_3_B1_NODE, ParallelSetup.WORKFLOW_DOCUMENT_4_B3_NODE });
143     	Set nodeNames = TestUtilities.createNodeInstanceNameSet(KEWServiceLocator.getRouteNodeService().getActiveNodeInstances(document.getRouteHeaderId()));
144     	assertEquals("There should be 3 active nodes.", 3, nodeNames.size());
145     	assertTrue("Should be at WorkflowDocument3-B1", nodeNames.contains(ParallelSetup.WORKFLOW_DOCUMENT_3_B1_NODE));
146     	assertTrue("Should be at WorkflowDocument2-B2", nodeNames.contains(ParallelSetup.WORKFLOW_DOCUMENT_2_B2_NODE));
147     	assertTrue("Should be at WorkflowDocument4-B3", nodeNames.contains(ParallelSetup.WORKFLOW_DOCUMENT_4_B3_NODE));
148     	
149     	// try to move the document from WorkflowDocument3-B1 to WorkflowDocument2-B1
150     	document.moveDocument(new MovePointDTO(ParallelSetup.WORKFLOW_DOCUMENT_3_B1_NODE, -1), "");
151     	nodeNames = TestUtilities.createNodeInstanceNameSet(KEWServiceLocator.getRouteNodeService().getActiveNodeInstances(document.getRouteHeaderId()));
152     	assertEquals("There should be 3 active nodes.", 3, nodeNames.size());
153     	assertTrue("Should be at WorkflowDocument2-B1", nodeNames.contains(ParallelSetup.WORKFLOW_DOCUMENT_2_B1_NODE));
154     	assertTrue("Should be at WorkflowDocument2-B2", nodeNames.contains(ParallelSetup.WORKFLOW_DOCUMENT_2_B2_NODE));
155     	assertTrue("Should be at WorkflowDocument4-B3", nodeNames.contains(ParallelSetup.WORKFLOW_DOCUMENT_4_B3_NODE));
156     }
157     
158     private class SeqSetup {
159 
160         public static final String DOCUMENT_TYPE_NAME = "MoveSequentialTest";
161         public static final String ADHOC_NODE = "AdHoc";
162         public static final String WORKFLOW_DOCUMENT_NODE = "WorkflowDocument";
163         public static final String WORKFLOW_DOCUMENT_2_NODE = "WorkflowDocument2";
164         public static final String WORKFLOW_DOCUMENT_3_NODE = "WorkflowDocument3";
165         public static final String ACKNOWLEDGE_1_NODE = "Acknowledge1";
166         public static final String ACKNOWLEDGE_2_NODE = "Acknowledge2";
167         
168     }
169     
170     private class ParallelSetup {
171 
172         public static final String DOCUMENT_TYPE_NAME = "BlanketApproveParallelTest";
173         public static final String ADHOC_NODE = "AdHoc";
174         public static final String WORKFLOW_DOCUMENT_NODE = "WorkflowDocument";
175         public static final String WORKFLOW_DOCUMENT_2_B1_NODE = "WorkflowDocument2-B1";
176         public static final String WORKFLOW_DOCUMENT_2_B2_NODE = "WorkflowDocument2-B2";
177         public static final String WORKFLOW_DOCUMENT_3_B1_NODE = "WorkflowDocument3-B1";
178         public static final String WORKFLOW_DOCUMENT_3_B2_NODE = "WorkflowDocument3-B2";
179         public static final String WORKFLOW_DOCUMENT_4_B3_NODE = "WorkflowDocument4-B3";
180         public static final String ACKNOWLEDGE_1_NODE = "Acknowledge1";
181         public static final String ACKNOWLEDGE_2_NODE = "Acknowledge2";
182         public static final String JOIN_NODE = "Join";
183         public static final String SPLIT_NODE = "Split";
184         public static final String WORKFLOW_DOCUMENT_FINAL_NODE = "WorkflowDocumentFinal";
185         
186     }
187    
188 }