1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.engine;
18
19
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertFalse;
22 import static org.junit.Assert.assertNotNull;
23 import static org.junit.Assert.assertTrue;
24
25 import java.util.Iterator;
26 import java.util.List;
27
28 import org.junit.Test;
29 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
30 import org.kuali.rice.kew.api.WorkflowDocument;
31 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
32 import org.kuali.rice.kew.api.document.RouteNodeInstance;
33 import org.kuali.rice.kew.service.KEWServiceLocator;
34 import org.kuali.rice.kew.test.KEWTestCase;
35 import org.kuali.rice.kew.test.TestUtilities;
36 import org.kuali.rice.kew.util.KEWConstants;
37
38 public class SubProcessRoutingTest extends KEWTestCase {
39
40 private static final String DOCUMENT_TYPE_NAME = "SubProcessDocType";
41 private static final String SUB_PROCESS_NODE = "MySubProcess";
42 private static final String ACKNOWLEDGE_NODE = "Acknowledge";
43 private static final String APPROVE_NODE = "Approve";
44
45 protected void loadTestData() throws Exception {
46 loadXmlFile("EngineConfig.xml");
47 }
48
49 @Test public void testSubProcessRoute() throws Exception {
50 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), DOCUMENT_TYPE_NAME);
51 document.saveDocumentData();
52 assertTrue("Document should be initiated", document.isInitiated());
53 assertEquals("Should be no action requests.", 0, document.getRootActionRequests().size());
54 TestUtilities.assertAtNode(document, "Initial");
55 document.route("");
56 assertTrue("Document shoule be ENROUTE.", document.isEnroute());
57
58 List actionRequests = KEWServiceLocator.getActionRequestService().findPendingByDoc(document.getDocumentId());
59 assertEquals("Incorrect pending action requests.", 2, actionRequests.size());
60 boolean isAck = false;
61 boolean isApprove = false;
62 for (Iterator iterator = actionRequests.iterator(); iterator.hasNext();) {
63 ActionRequestValue request = (ActionRequestValue) iterator.next();
64 org.kuali.rice.kew.engine.node.RouteNodeInstance nodeInstance = request.getNodeInstance();
65 assertNotNull("Node instance should be non null.", nodeInstance);
66 if (request.getPrincipalId().equals(getPrincipalIdForName("bmcgough"))) {
67 isAck = true;
68 assertEquals("Wrong request type.", KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, request.getActionRequested());
69 assertEquals("Wrong node.", ACKNOWLEDGE_NODE, nodeInstance.getRouteNode().getRouteNodeName());
70 assertNotNull("Should be in a sub process.", nodeInstance.getProcess());
71 assertEquals("Wrong sub process.", SUB_PROCESS_NODE, nodeInstance.getProcess().getRouteNode().getRouteNodeName());
72 assertFalse("Sub process should be non-initial.", nodeInstance.getProcess().isInitial());
73 assertFalse("Sub process should be non-active.", nodeInstance.getProcess().isActive());
74 assertFalse("Sub process should be non-complete.", nodeInstance.getProcess().isComplete());
75 } else if (request.getPrincipalId().equals(getPrincipalIdForName("temay"))) {
76 isApprove = true;
77 assertEquals("Wrong request type.", KEWConstants.ACTION_REQUEST_APPROVE_REQ, request.getActionRequested());
78 assertEquals("Wrong node.", APPROVE_NODE, request.getNodeInstance().getRouteNode().getRouteNodeName());
79 assertNotNull("Should be in a sub process.", request.getNodeInstance().getProcess());
80 assertEquals("Wrong sub process.", SUB_PROCESS_NODE, request.getNodeInstance().getProcess().getRouteNode().getRouteNodeName());
81 assertFalse("Sub process should be non-initial.", nodeInstance.getProcess().isInitial());
82 assertFalse("Sub process should be non-active.", nodeInstance.getProcess().isActive());
83 assertFalse("Sub process should be non-complete.", nodeInstance.getProcess().isComplete());
84 }
85 }
86 assertTrue(isAck);
87 assertTrue(isApprove);
88 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
89 assertTrue("Should have acknowledge.", document.isAcknowledgeRequested());
90 document.acknowledge("");
91
92 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("temay"), document.getDocumentId());
93 document.approve("");
94
95
96 boolean foundSubProcess = false;
97 List<RouteNodeInstance> nodeInstances = document.getRouteNodeInstances();
98 for (int index = 0; index < nodeInstances.size(); index++) {
99 RouteNodeInstance instanceVO = nodeInstances.get(index);
100 if (instanceVO.getName().equals(SUB_PROCESS_NODE)) {
101 foundSubProcess = true;
102 assertFalse("Sub process should be non-initial.", instanceVO.isInitial());
103 assertFalse("Sub process should be non-active.", instanceVO.isActive());
104 assertTrue("Sub process should be complete.", instanceVO.isComplete());
105 }
106 }
107 assertTrue("Could not locate sub process node.", foundSubProcess);
108
109 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
110 document.approve("");
111
112 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
113 assertTrue("Document should be final.", document.isFinal());
114 }
115
116 }