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