001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.routemodule;
018:
019: import java.util.Collection;
020: import java.util.List;
021:
022: import org.junit.Test;
023: import org.kuali.workflow.test.WorkflowTestCase;
024:
025: import edu.iu.uis.eden.EdenConstants;
026: import edu.iu.uis.eden.KEWServiceLocator;
027: import edu.iu.uis.eden.clientapp.WorkflowDocument;
028: import edu.iu.uis.eden.clientapp.WorkflowInfo;
029: import edu.iu.uis.eden.clientapp.vo.ActionRequestVO;
030: import edu.iu.uis.eden.clientapp.vo.DocumentDetailVO;
031: import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
032: import edu.iu.uis.eden.clientapp.vo.ReportCriteriaVO;
033: import edu.iu.uis.eden.engine.node.RouteNodeInstance;
034:
035: public class RoutingReportServiceTest extends WorkflowTestCase {
036:
037: protected void loadTestData() throws Exception {
038: loadXmlFile("RouteModuleConfig.xml");
039: }
040:
041: /**
042: * Tests the report() method against a sequential document type.
043: */
044: @Test
045: public void testReportSequential() throws Exception {
046:
047: // route a document to the first node
048: WorkflowDocument document = new WorkflowDocument(
049: new NetworkIdVO("ewestfal"),
050: SeqSetup.DOCUMENT_TYPE_NAME);
051: document.routeDocument("");
052:
053: // there should now be 1 active node and 2 pending requests on the document
054: Collection activeNodeInstances = KEWServiceLocator
055: .getRouteNodeService().getActiveNodeInstances(
056: document.getRouteHeaderId());
057: List requests = KEWServiceLocator.getActionRequestService()
058: .findAllActionRequestsByRouteHeaderId(
059: document.getRouteHeaderId());
060: assertEquals("Should be one active node.", 1,
061: activeNodeInstances.size());
062: Long activeNodeId = ((RouteNodeInstance) activeNodeInstances
063: .iterator().next()).getRouteNodeInstanceId();
064: assertEquals("Should be 2 pending requests.", 2, requests
065: .size());
066:
067: // now, lets "get our report on", the WorkflowInfo.routingReport method will call the service's report method.
068: WorkflowInfo info = new WorkflowInfo();
069: ReportCriteriaVO criteria = new ReportCriteriaVO(document
070: .getRouteHeaderId());
071:
072: long start = System.currentTimeMillis();
073: DocumentDetailVO documentDetail = info.routingReport(criteria);
074: long end = System.currentTimeMillis();
075: System.out.println("Time to run routing report: "
076: + (end - start) + " milliseconds.");
077:
078: // document detail should have all of our requests on it, 2 activated approves, 1 initialized approve, 2 initialized acknowledges
079: assertEquals("There should be 5 requests.", 5, documentDetail
080: .getActionRequests().length);
081: boolean approveToBmcgough = false;
082: boolean approveToRkirkend = false;
083: boolean approveToPmckown = false;
084: boolean ackToTemay = false;
085: boolean ackToJhopf = false;
086: for (int index = 0; index < documentDetail.getActionRequests().length; index++) {
087: ActionRequestVO requestVO = documentDetail
088: .getActionRequests()[index];
089: String netId = requestVO.getUserVO().getNetworkId();
090: if (netId.equals("bmcgough")) {
091: assertEquals("Should be approve.",
092: EdenConstants.ACTION_REQUEST_APPROVE_REQ,
093: requestVO.getActionRequested());
094: assertEquals("Should be activated.",
095: EdenConstants.ACTION_REQUEST_ACTIVATED,
096: requestVO.getStatus());
097: assertEquals("Wrong node name",
098: SeqSetup.WORKFLOW_DOCUMENT_NODE, requestVO
099: .getNodeName());
100: approveToBmcgough = true;
101: } else if (netId.equals("rkirkend")) {
102: assertEquals("Should be approve.",
103: EdenConstants.ACTION_REQUEST_APPROVE_REQ,
104: requestVO.getActionRequested());
105: assertEquals("Should be activated.",
106: EdenConstants.ACTION_REQUEST_ACTIVATED,
107: requestVO.getStatus());
108: assertEquals("Wrong node name",
109: SeqSetup.WORKFLOW_DOCUMENT_NODE, requestVO
110: .getNodeName());
111: approveToRkirkend = true;
112: } else if (netId.equals("pmckown")) {
113: assertEquals("Should be approve.",
114: EdenConstants.ACTION_REQUEST_APPROVE_REQ,
115: requestVO.getActionRequested());
116: assertEquals("Should be initialized.",
117: EdenConstants.ACTION_REQUEST_INITIALIZED,
118: requestVO.getStatus());
119: assertEquals("Wrong node name",
120: SeqSetup.WORKFLOW_DOCUMENT_2_NODE, requestVO
121: .getNodeName());
122: approveToPmckown = true;
123: } else if (netId.equals("temay")) {
124: assertEquals("Should be acknowledge.",
125: EdenConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ,
126: requestVO.getActionRequested());
127: assertEquals("Should be initialized.",
128: EdenConstants.ACTION_REQUEST_INITIALIZED,
129: requestVO.getStatus());
130: assertEquals("Wrong node name",
131: SeqSetup.ACKNOWLEDGE_1_NODE, requestVO
132: .getNodeName());
133: ackToTemay = true;
134: } else if (netId.equals("jhopf")) {
135: assertEquals("Should be acknowledge.",
136: EdenConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ,
137: requestVO.getActionRequested());
138: assertEquals("Should be initialized.",
139: EdenConstants.ACTION_REQUEST_INITIALIZED,
140: requestVO.getStatus());
141: assertEquals("Wrong node name",
142: SeqSetup.ACKNOWLEDGE_2_NODE, requestVO
143: .getNodeName());
144: ackToJhopf = true;
145: }
146: assertNotNull(requestVO.getNodeInstanceId());
147: }
148: assertTrue("There should be an approve to bmcgough",
149: approveToBmcgough);
150: assertTrue("There should be an approve to rkirkend",
151: approveToRkirkend);
152: assertTrue("There should be an approve to pmckown",
153: approveToPmckown);
154: assertTrue("There should be an ack to temay", ackToTemay);
155: assertTrue("There should be an ack to jhopf", ackToJhopf);
156:
157: // assert that the report call didn't save any of the nodes or requests
158: activeNodeInstances = KEWServiceLocator.getRouteNodeService()
159: .getActiveNodeInstances(document.getRouteHeaderId());
160: requests = KEWServiceLocator.getActionRequestService()
161: .findAllActionRequestsByRouteHeaderId(
162: document.getRouteHeaderId());
163: assertEquals("Should be one active node.", 1,
164: activeNodeInstances.size());
165: assertEquals("Should be at the same node.", activeNodeId,
166: ((RouteNodeInstance) activeNodeInstances.iterator()
167: .next()).getRouteNodeInstanceId());
168: assertEquals("Should be 2 pending requests.", 2, requests
169: .size());
170:
171: // test reporting to a specified target node
172: criteria = new ReportCriteriaVO(document.getRouteHeaderId(),
173: SeqSetup.ACKNOWLEDGE_1_NODE);
174: documentDetail = info.routingReport(criteria);
175:
176: // document detail should have all of our requests except for the final acknowledge
177: assertEquals("There should be 4 requets.", 4, documentDetail
178: .getActionRequests().length);
179: // assert that we don't have an acknowledge to jhopf
180: for (int index = 0; index < documentDetail.getActionRequests().length; index++) {
181: ActionRequestVO requestVO = documentDetail
182: .getActionRequests()[index];
183: if (requestVO.getUserVO().getNetworkId().equals("jhopf")) {
184: fail("There should be no request to jhopf");
185: }
186: }
187: }
188:
189: private static class SeqSetup {
190: public static final String DOCUMENT_TYPE_NAME = "SeqDocType";
191: public static final String ADHOC_NODE = "AdHoc";
192: public static final String WORKFLOW_DOCUMENT_NODE = "WorkflowDocument";
193: public static final String WORKFLOW_DOCUMENT_2_NODE = "WorkflowDocument2";
194: public static final String ACKNOWLEDGE_1_NODE = "Acknowledge1";
195: public static final String ACKNOWLEDGE_2_NODE = "Acknowledge2";
196: }
197:
198: private static class DynSetup {
199: public static final String DOCUMENT_TYPE_NAME = "DynChartOrgDocType";
200: public static final String INITIAL_NODE = "Initial";
201: public static final String CHART_ORG_NODE = "ChartOrg";
202: public static final String SPLIT_NODE_NAME = "Organization Split";
203: public static final String JOIN_NODE_NAME = "Organization Join";
204: public static final String REQUEST_NODE_NAME = "Organization Request";
205: }
206: }
|