View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.engine;
17  
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.assertFalse;
21  import static org.junit.Assert.assertNotNull;
22  import static org.junit.Assert.assertTrue;
23  
24  import java.util.Iterator;
25  import java.util.List;
26  
27  import org.junit.Test;
28  import org.kuali.rice.kew.actionrequest.ActionRequestValue;
29  import org.kuali.rice.kew.api.WorkflowDocument;
30  import org.kuali.rice.kew.api.WorkflowDocumentFactory;
31  import org.kuali.rice.kew.api.document.node.RouteNodeInstance;
32  import org.kuali.rice.kew.service.KEWServiceLocator;
33  import org.kuali.rice.kew.test.KEWTestCase;
34  import org.kuali.rice.kew.test.TestUtilities;
35  import org.kuali.rice.kew.api.KewApiConstants;
36  
37  public class SubProcessRoutingTest extends KEWTestCase {
38      
39      private static final String DOCUMENT_TYPE_NAME = "SubProcessDocType";
40  	private static final String SUB_PROCESS_NODE = "MySubProcess";
41      private static final String ACKNOWLEDGE_NODE = "Acknowledge";
42      private static final String APPROVE_NODE = "Approve";
43  	
44      protected void loadTestData() throws Exception {
45          loadXmlFile("EngineConfig.xml");
46      }
47  
48      @Test public void testSubProcessRoute() throws Exception {
49      	WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), DOCUMENT_TYPE_NAME);
50      	document.saveDocumentData();
51          assertTrue("Document should be initiated", document.isInitiated());
52          assertEquals("Should be no action requests.", 0, document.getRootActionRequests().size());
53          TestUtilities.assertAtNode(document, "Initial");
54          document.route("");
55          assertTrue("Document shoule be ENROUTE.", document.isEnroute());
56          
57          List actionRequests = KEWServiceLocator.getActionRequestService().findPendingByDoc(document.getDocumentId());
58          assertEquals("Incorrect pending action requests.", 2, actionRequests.size());
59          boolean isAck = false;
60          boolean isApprove = false;
61          for (Iterator iterator = actionRequests.iterator(); iterator.hasNext();) {
62              ActionRequestValue request = (ActionRequestValue) iterator.next();
63              org.kuali.rice.kew.engine.node.RouteNodeInstance nodeInstance = request.getNodeInstance();
64              assertNotNull("Node instance should be non null.", nodeInstance);
65              if (request.getPrincipalId().equals(getPrincipalIdForName("bmcgough"))) {
66                  isAck = true;
67                  assertEquals("Wrong request type.", KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, request.getActionRequested());
68                  assertEquals("Wrong node.", ACKNOWLEDGE_NODE, nodeInstance.getRouteNode().getRouteNodeName());
69                  assertNotNull("Should be in a sub process.", nodeInstance.getProcess());
70                  assertEquals("Wrong sub process.", SUB_PROCESS_NODE, nodeInstance.getProcess().getRouteNode().getRouteNodeName());
71                  assertFalse("Sub process should be non-initial.", nodeInstance.getProcess().isInitial());
72                  assertFalse("Sub process should be non-active.", nodeInstance.getProcess().isActive());
73                  assertFalse("Sub process should be non-complete.", nodeInstance.getProcess().isComplete());
74              } else if (request.getPrincipalId().equals(getPrincipalIdForName("temay"))) {
75                  isApprove = true;
76                  assertEquals("Wrong request type.", KewApiConstants.ACTION_REQUEST_APPROVE_REQ, request.getActionRequested());
77                  assertEquals("Wrong node.", APPROVE_NODE, request.getNodeInstance().getRouteNode().getRouteNodeName());
78                  assertNotNull("Should be in a sub process.", request.getNodeInstance().getProcess());
79                  assertEquals("Wrong sub process.", SUB_PROCESS_NODE, request.getNodeInstance().getProcess().getRouteNode().getRouteNodeName());
80                  assertFalse("Sub process should be non-initial.", nodeInstance.getProcess().isInitial());
81                  assertFalse("Sub process should be non-active.", nodeInstance.getProcess().isActive());
82                  assertFalse("Sub process should be non-complete.", nodeInstance.getProcess().isComplete());
83              }
84          }
85          assertTrue(isAck);
86          assertTrue(isApprove);
87          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
88          assertTrue("Should have acknowledge.", document.isAcknowledgeRequested());
89          document.acknowledge("");
90          
91          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("temay"), document.getDocumentId());
92          document.approve("");
93          
94          // find the subprocess and assert it is complete, not active, and not initial
95          boolean foundSubProcess = false;
96          List<RouteNodeInstance> nodeInstances = document.getRouteNodeInstances();
97          for (int index = 0; index < nodeInstances.size(); index++) {
98              RouteNodeInstance instanceVO = nodeInstances.get(index);
99              if (instanceVO.getName().equals(SUB_PROCESS_NODE)) {
100                 foundSubProcess = true;
101                 assertFalse("Sub process should be non-initial.", instanceVO.isInitial());
102                 assertFalse("Sub process should be non-active.", instanceVO.isActive());
103                 assertTrue("Sub process should be complete.", instanceVO.isComplete());
104             }
105         }
106         assertTrue("Could not locate sub process node.", foundSubProcess);
107         
108         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
109         document.approve("");
110         
111         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
112         assertTrue("Document should be final.", document.isFinal());
113     }
114     
115 }