1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.routemodule;
18
19 import org.junit.Test;
20 import org.kuali.rice.kew.api.KewApiServiceLocator;
21 import org.kuali.rice.kew.api.WorkflowDocument;
22 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
23 import org.kuali.rice.kew.api.action.ActionRequest;
24 import org.kuali.rice.kew.api.action.ActionRequestStatus;
25 import org.kuali.rice.kew.api.action.RoutingReportCriteria;
26 import org.kuali.rice.kew.api.document.DocumentDetail;
27 import org.kuali.rice.kew.engine.node.RouteNodeInstance;
28 import org.kuali.rice.kew.service.KEWServiceLocator;
29 import org.kuali.rice.kew.test.KEWTestCase;
30 import org.kuali.rice.kew.util.KEWConstants;
31
32 import java.util.Collection;
33 import java.util.List;
34
35 import static org.junit.Assert.*;
36
37 public class RoutingReportServiceTest extends KEWTestCase {
38
39
40 protected void loadTestData() throws Exception {
41 loadXmlFile("RouteModuleConfig.xml");
42 }
43
44
45
46
47 @Test public void testReportSequential() throws Exception {
48
49
50
51 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), SeqSetup.DOCUMENT_TYPE_NAME);
52 document.route("");
53
54
55 Collection activeNodeInstances = KEWServiceLocator.getRouteNodeService().getActiveNodeInstances(document.getDocumentId());
56 List requests = KEWServiceLocator.getActionRequestService().findAllActionRequestsByDocumentId(document.getDocumentId());
57 assertEquals("Should be one active node.", 1, activeNodeInstances.size());
58 String activeNodeId = ((RouteNodeInstance)activeNodeInstances.iterator().next()).getRouteNodeInstanceId();
59 assertEquals("Should be 2 pending requests.", 2, requests.size());
60
61
62 RoutingReportCriteria criteria = RoutingReportCriteria.Builder.createByDocumentId(document.getDocumentId()).build();
63
64 long start = System.currentTimeMillis();
65 DocumentDetail documentDetail = KewApiServiceLocator.getWorkflowDocumentActionsService().executeSimulation(
66 criteria);
67 long end = System.currentTimeMillis();
68 System.out.println("Time to run routing report: " + (end-start)+" milliseconds.");
69
70
71 assertEquals("There should be 5 requests.", 5, documentDetail.getActionRequests().size());
72 boolean approveToBmcgough = false;
73 boolean approveToRkirkend = false;
74 boolean approveToPmckown = false;
75 boolean ackToTemay = false;
76 boolean ackToJhopf = false;
77 for (ActionRequest requestVO : documentDetail.getActionRequests()) {
78 String netId = getPrincipalNameForId(requestVO.getPrincipalId());
79 if (netId.equals("bmcgough")) {
80 assertEquals("Should be approve.", KEWConstants.ACTION_REQUEST_APPROVE_REQ, requestVO.getActionRequested());
81 assertEquals("Should be activated.", ActionRequestStatus.ACTIVATED.getCode(), requestVO.getStatus());
82 assertEquals("Wrong node name", SeqSetup.WORKFLOW_DOCUMENT_NODE, requestVO.getNodeName());
83 approveToBmcgough = true;
84 } else if (netId.equals("rkirkend")) {
85 assertEquals("Should be approve.", KEWConstants.ACTION_REQUEST_APPROVE_REQ, requestVO.getActionRequested());
86 assertEquals("Should be activated.", ActionRequestStatus.ACTIVATED.getCode(), requestVO.getStatus());
87 assertEquals("Wrong node name", SeqSetup.WORKFLOW_DOCUMENT_NODE, requestVO.getNodeName());
88 approveToRkirkend = true;
89 } else if (netId.equals("pmckown")) {
90 assertEquals("Should be approve.", KEWConstants.ACTION_REQUEST_APPROVE_REQ, requestVO.getActionRequested());
91 assertEquals("Should be initialized.", ActionRequestStatus.INITIALIZED.getCode(), requestVO.getStatus());
92 assertEquals("Wrong node name", SeqSetup.WORKFLOW_DOCUMENT_2_NODE, requestVO.getNodeName());
93 approveToPmckown = true;
94 } else if (netId.equals("temay")) {
95 assertEquals("Should be acknowledge.", KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, requestVO.getActionRequested());
96 assertEquals("Should be initialized.", ActionRequestStatus.INITIALIZED.getCode(), requestVO.getStatus());
97 assertEquals("Wrong node name", SeqSetup.ACKNOWLEDGE_1_NODE, requestVO.getNodeName());
98 ackToTemay = true;
99 } else if (netId.equals("jhopf")) {
100 assertEquals("Should be acknowledge.", KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, requestVO.getActionRequested());
101 assertEquals("Should be initialized.", ActionRequestStatus.INITIALIZED.getCode(), requestVO.getStatus());
102 assertEquals("Wrong node name", SeqSetup.ACKNOWLEDGE_2_NODE, requestVO.getNodeName());
103 ackToJhopf = true;
104 }
105 assertNotNull(requestVO.getId());
106 }
107 assertTrue("There should be an approve to bmcgough", approveToBmcgough);
108 assertTrue("There should be an approve to rkirkend", approveToRkirkend);
109 assertTrue("There should be an approve to pmckown", approveToPmckown);
110 assertTrue("There should be an ack to temay", ackToTemay);
111 assertTrue("There should be an ack to jhopf", ackToJhopf);
112
113
114 activeNodeInstances = KEWServiceLocator.getRouteNodeService().getActiveNodeInstances(document.getDocumentId());
115 requests = KEWServiceLocator.getActionRequestService().findAllActionRequestsByDocumentId(document.getDocumentId());
116 assertEquals("Should be one active node.", 1, activeNodeInstances.size());
117 assertEquals("Should be at the same node.", activeNodeId, ((RouteNodeInstance)activeNodeInstances.iterator().next()).getRouteNodeInstanceId());
118 assertEquals("Should be 2 pending requests.", 2, requests.size());
119
120
121 criteria = RoutingReportCriteria.Builder.createByDocumentIdAndTargetNodeName(document.getDocumentId(), SeqSetup.ACKNOWLEDGE_1_NODE).build();
122 documentDetail = KewApiServiceLocator.getWorkflowDocumentActionsService().executeSimulation(criteria);
123
124
125 assertEquals("There should be 4 requets.", 4, documentDetail.getActionRequests().size());
126
127 for (ActionRequest requestVO : documentDetail.getActionRequests()) {
128 if (requestVO.getPrincipalId().equals(getPrincipalIdForName("jhopf"))) {
129 fail("There should be no request to jhopf");
130 }
131 }
132 }
133
134 private static class SeqSetup {
135 public static final String DOCUMENT_TYPE_NAME = "SeqDocType";
136 public static final String ADHOC_NODE = "AdHoc";
137 public static final String WORKFLOW_DOCUMENT_NODE = "WorkflowDocument";
138 public static final String WORKFLOW_DOCUMENT_2_NODE = "WorkflowDocument2";
139 public static final String ACKNOWLEDGE_1_NODE = "Acknowledge1";
140 public static final String ACKNOWLEDGE_2_NODE = "Acknowledge2";
141 }
142
143 private static class DynSetup {
144 public static final String DOCUMENT_TYPE_NAME = "DynChartOrgDocType";
145 public static final String INITIAL_NODE = "Initial";
146 public static final String CHART_ORG_NODE = "ChartOrg";
147 public static final String SPLIT_NODE_NAME = "Organization Split";
148 public static final String JOIN_NODE_NAME = "Organization Join";
149 public static final String REQUEST_NODE_NAME = "Organization Request";
150 }
151 }