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.engine;
18  
19  
20  import java.util.Iterator;
21  import java.util.List;
22  
23  import org.junit.Test;
24  import org.kuali.rice.kew.actionrequest.ActionRequestValue;
25  import org.kuali.rice.kew.dto.NetworkIdDTO;
26  import org.kuali.rice.kew.dto.RouteNodeInstanceDTO;
27  import org.kuali.rice.kew.engine.node.RouteNodeInstance;
28  import org.kuali.rice.kew.service.KEWServiceLocator;
29  import org.kuali.rice.kew.service.WorkflowDocument;
30  import org.kuali.rice.kew.test.KEWTestCase;
31  import org.kuali.rice.kew.util.KEWConstants;
32  
33  
34  public class SubProcessRoutingTest extends KEWTestCase {
35      
36      private static final String DOCUMENT_TYPE_NAME = "SubProcessDocType";
37  	private static final String SUB_PROCESS_NODE = "MySubProcess";
38      private static final String ACKNOWLEDGE_NODE = "Acknowledge";
39      private static final String APPROVE_NODE = "Approve";
40  	
41      protected void loadTestData() throws Exception {
42          loadXmlFile("EngineConfig.xml");
43      }
44  
45      @Test public void testSubProcessRoute() throws Exception {
46      	WorkflowDocument document = new WorkflowDocument(new NetworkIdDTO("ewestfal"), DOCUMENT_TYPE_NAME);
47      	document.saveRoutingData();
48          assertTrue("Document should be initiated", document.stateIsInitiated());
49          assertEquals("Should be no action requests.", 0, document.getActionRequests().length);
50          assertEquals("Invalid route level.", new Integer(0), document.getRouteHeader().getDocRouteLevel());
51          document.routeDocument("");
52          assertTrue("Document shoule be ENROUTE.", document.stateIsEnroute());
53          
54          List actionRequests = KEWServiceLocator.getActionRequestService().findPendingByDoc(document.getRouteHeaderId());
55          assertEquals("Incorrect pending action requests.", 2, actionRequests.size());
56          boolean isAck = false;
57          boolean isApprove = false;
58          for (Iterator iterator = actionRequests.iterator(); iterator.hasNext();) {
59              ActionRequestValue request = (ActionRequestValue) iterator.next();
60              RouteNodeInstance nodeInstance = request.getNodeInstance();
61              assertNotNull("Node instance should be non null.", nodeInstance);
62              if (request.getPrincipalId().equals(getPrincipalIdForName("bmcgough"))) {
63                  isAck = true;
64                  assertEquals("Wrong request type.", KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, request.getActionRequested());
65                  assertEquals("Wrong node.", ACKNOWLEDGE_NODE, nodeInstance.getRouteNode().getRouteNodeName());
66                  assertNotNull("Should be in a sub process.", nodeInstance.getProcess());
67                  assertEquals("Wrong sub process.", SUB_PROCESS_NODE, nodeInstance.getProcess().getRouteNode().getRouteNodeName());
68                  assertFalse("Sub process should be non-initial.", nodeInstance.getProcess().isInitial());
69                  assertFalse("Sub process should be non-active.", nodeInstance.getProcess().isActive());
70                  assertFalse("Sub process should be non-complete.", nodeInstance.getProcess().isComplete());
71              } else if (request.getPrincipalId().equals(getPrincipalIdForName("temay"))) {
72                  isApprove = true;
73                  assertEquals("Wrong request type.", KEWConstants.ACTION_REQUEST_APPROVE_REQ, request.getActionRequested());
74                  assertEquals("Wrong node.", APPROVE_NODE, request.getNodeInstance().getRouteNode().getRouteNodeName());
75                  assertNotNull("Should be in a sub process.", request.getNodeInstance().getProcess());
76                  assertEquals("Wrong sub process.", SUB_PROCESS_NODE, request.getNodeInstance().getProcess().getRouteNode().getRouteNodeName());
77                  assertFalse("Sub process should be non-initial.", nodeInstance.getProcess().isInitial());
78                  assertFalse("Sub process should be non-active.", nodeInstance.getProcess().isActive());
79                  assertFalse("Sub process should be non-complete.", nodeInstance.getProcess().isComplete());
80              }
81          }
82          assertTrue(isAck);
83          assertTrue(isApprove);
84          document = new WorkflowDocument(new NetworkIdDTO("bmcgough"), document.getRouteHeaderId());
85          assertTrue("Should have acknowledge.", document.isAcknowledgeRequested());
86          document.acknowledge("");
87          
88          document = new WorkflowDocument(new NetworkIdDTO("temay"), document.getRouteHeaderId());
89          document.approve("");
90          
91          // find the subprocess and assert it is complete, not active, and not initial
92          boolean foundSubProcess = false;
93          RouteNodeInstanceDTO[] nodeInstances = document.getRouteNodeInstances();
94          for (int index = 0; index < nodeInstances.length; index++) {
95              RouteNodeInstanceDTO instanceVO = nodeInstances[index];
96              if (instanceVO.getName().equals(SUB_PROCESS_NODE)) {
97                  foundSubProcess = true;
98                  assertFalse("Sub process should be non-initial.", instanceVO.isInitial());
99                  assertFalse("Sub process should be non-active.", instanceVO.isActive());
100                 assertTrue("Sub process should be complete.", instanceVO.isComplete());
101             }
102         }
103         assertTrue("Could not locate sub process node.", foundSubProcess);
104         
105         document = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document.getRouteHeaderId());
106         document.approve("");
107         
108         document = new WorkflowDocument(new NetworkIdDTO("ewestfal"), document.getRouteHeaderId());
109         assertTrue("Document should be final.", document.stateIsFinal());
110     }
111     
112 }