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.assertNotNull;
22 import static org.junit.Assert.assertTrue;
23
24 import java.util.List;
25 import java.util.Set;
26
27 import org.junit.Test;
28 import org.kuali.rice.kew.api.WorkflowDocument;
29 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
30 import org.kuali.rice.kew.api.action.ActionRequest;
31 import org.kuali.rice.kew.api.action.ActionRequestStatus;
32 import org.kuali.rice.kew.engine.node.RouteNodeInstance;
33 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
34 import org.kuali.rice.kew.service.KEWServiceLocator;
35 import org.kuali.rice.kew.test.KEWTestCase;
36 import org.kuali.rice.kew.test.TestUtilities;
37 import org.kuali.rice.kew.util.KEWConstants;
38
39 public class SequentialRoutingTest extends KEWTestCase {
40
41
42 private static final String DOCUMENT_TYPE_NAME = "SeqDocType";
43 private static final String ADHOC_NODE = "AdHoc";
44 private static final String WORKFLOW_DOCUMENT_NODE = "WorkflowDocument";
45 private static final String ACKNOWLEDGE_1_NODE = "Acknowledge1";
46 private static final String ACKNOWLEDGE_2_NODE = "Acknowledge2";
47
48 protected void loadTestData() throws Exception {
49 loadXmlFile("EngineConfig.xml");
50 }
51
52 @Test public void testSequentialRoute() throws Exception {
53 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), DOCUMENT_TYPE_NAME);
54 document.saveDocumentData();
55 assertNotNull(document.getDocumentId());
56 assertTrue("Document should be initiatied", document.isInitiated());
57 Set<String> nodeNames = document.getNodeNames();
58 assertEquals("Wrong number of node names.", 1, nodeNames.size());
59 assertEquals("Wrong node name.", ADHOC_NODE, nodeNames.iterator().next());
60 document.route("Routing sequentially.");
61
62
63 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
64 assertTrue("Document should be enroute", document.isEnroute());
65 nodeNames = document.getNodeNames();
66 assertEquals("Wrong number of node names.", 1, nodeNames.size());
67 assertEquals("Wrong node name.", WORKFLOW_DOCUMENT_NODE, nodeNames.iterator().next());
68 List<ActionRequest> requests = document.getRootActionRequests();
69 assertEquals(1, requests.size());
70 ActionRequest request = requests.get(0);
71 assertEquals(getPrincipalIdForName("bmcgough"), request.getPrincipalId());
72 assertEquals(KEWConstants.ACTION_REQUEST_APPROVE_REQ, request.getActionRequested());
73 TestUtilities.assertAtNode(document, WORKFLOW_DOCUMENT_NODE);
74 assertTrue(document.isApprovalRequested());
75 document.approve("Test approve by bmcgough");
76
77 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("temay"), document.getDocumentId());
78 assertTrue("Document should be processed.", document.isProcessed());
79 requests = document.getRootActionRequests();
80 assertEquals(3, requests.size());
81 boolean toTemay = false;
82 boolean toJhopf = false;
83 for (int i = 0; i < requests.size(); i++) {
84 ActionRequest requestVO = requests.get(i);
85 if (requestVO.getPrincipalId().equals(getPrincipalIdForName("temay"))) {
86 toTemay = true;
87 assertEquals(KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, requestVO.getActionRequested());
88 TestUtilities.assertAtNode(document, ACKNOWLEDGE_1_NODE);
89 assertEquals(ActionRequestStatus.ACTIVATED.getCode(), requestVO.getStatus());
90 } else if (requestVO.getPrincipalId().equals(getPrincipalIdForName("jhopf"))) {
91 toJhopf = true;
92 assertEquals(KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, requestVO.getActionRequested());
93 TestUtilities.assertAtNode(document, ACKNOWLEDGE_2_NODE);
94 assertEquals(ActionRequestStatus.ACTIVATED.getCode(), requestVO.getStatus());
95 }
96 }
97 assertTrue("Should be an acknowledge to temay", toTemay);
98 assertTrue("Should be an acknowledge to jhopf", toJhopf);
99
100
101 document.acknowledge("Temay taking acknowledge");
102
103 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId());
104 assertTrue("Document should be processed.", document.isProcessed());
105 requests = document.getRootActionRequests();
106 toTemay = false;
107 toJhopf = false;
108 for (int i = 0; i < requests.size(); i++) {
109 ActionRequest requestVO = requests.get(i);
110 if (requestVO.getPrincipalId().equals(getPrincipalIdForName("temay"))) {
111 toTemay = true;
112 assertEquals(KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, requestVO.getActionRequested());
113 assertEquals(ActionRequestStatus.DONE.getCode(), requestVO.getStatus());
114 } else if (requestVO.getPrincipalId().equals(getPrincipalIdForName("jhopf"))) {
115 toJhopf = true;
116 assertEquals(KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, requestVO.getActionRequested());
117 TestUtilities.assertAtNode(document, ACKNOWLEDGE_2_NODE);
118 assertEquals(ActionRequestStatus.ACTIVATED.getCode(), requestVO.getStatus());
119 }
120 }
121 assertTrue("Should be a DONE acknowledge to temay", toTemay);
122 assertTrue("Should be an acknowledge to jhopf", toJhopf);
123
124 document.acknowledge("Jhopf taking acknowledge");
125
126
127 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
128 assertTrue("Document should be final.", document.isFinal());
129
130 verifyRoutingPath(document.getDocumentId());
131 }
132
133 private void verifyRoutingPath(String documentId) {
134 DocumentRouteHeaderValue document = KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId);
135 List initial = document.getInitialRouteNodeInstances();
136 assertEquals(1, initial.size());
137 RouteNodeInstance adhoc = (RouteNodeInstance)initial.get(0);
138 assertEquals(ADHOC_NODE, adhoc.getRouteNode().getRouteNodeName());
139 assertEquals(0, adhoc.getPreviousNodeInstances().size());
140
141 List next = adhoc.getNextNodeInstances();
142 assertEquals(1, next.size());
143 RouteNodeInstance wd = (RouteNodeInstance)next.get(0);
144 assertEquals(WORKFLOW_DOCUMENT_NODE, wd.getRouteNode().getRouteNodeName());
145 assertEquals(1, wd.getPreviousNodeInstances().size());
146
147 next = wd.getNextNodeInstances();
148 assertEquals(1, next.size());
149 RouteNodeInstance ack1 = (RouteNodeInstance)next.get(0);
150 assertEquals(ACKNOWLEDGE_1_NODE, ack1.getRouteNode().getRouteNodeName());
151 assertEquals(1, ack1.getPreviousNodeInstances().size());
152
153 next = ack1.getNextNodeInstances();
154 assertEquals(1, next.size());
155 RouteNodeInstance ack2 = (RouteNodeInstance)next.get(0);
156 assertEquals(ACKNOWLEDGE_2_NODE, ack2.getRouteNode().getRouteNodeName());
157 assertEquals(1, ack2.getPreviousNodeInstances().size());
158
159 next = ack2.getNextNodeInstances();
160 assertEquals(0, next.size());
161 }
162
163 }