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.engine;
018:
019: import java.util.List;
020:
021: import org.junit.Test;
022: import org.kuali.workflow.test.WorkflowTestCase;
023:
024: import edu.iu.uis.eden.EdenConstants;
025: import edu.iu.uis.eden.KEWServiceLocator;
026: import edu.iu.uis.eden.clientapp.WorkflowDocument;
027: import edu.iu.uis.eden.clientapp.vo.ActionRequestVO;
028: import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
029: import edu.iu.uis.eden.engine.node.RouteNodeInstance;
030: import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
031:
032: public class SequentialRoutingTest extends WorkflowTestCase {
033:
034: private static final String DOCUMENT_TYPE_NAME = "SeqDocType";
035: private static final String ADHOC_NODE = "AdHoc";
036: private static final String WORKFLOW_DOCUMENT_NODE = "WorkflowDocument";
037: private static final String ACKNOWLEDGE_1_NODE = "Acknowledge1";
038: private static final String ACKNOWLEDGE_2_NODE = "Acknowledge2";
039:
040: protected void loadTestData() throws Exception {
041: loadXmlFile("EngineConfig.xml");
042: }
043:
044: @Test
045: public void testSequentialRoute() throws Exception {
046: WorkflowDocument document = new WorkflowDocument(
047: new NetworkIdVO("ewestfal"), DOCUMENT_TYPE_NAME);
048: document.saveRoutingData();
049: assertNotNull(document.getRouteHeaderId());
050: assertTrue("Document should be initiatied", document
051: .stateIsInitiated());
052: assertEquals("Invalid route level.", new Integer(0), document
053: .getRouteHeader().getDocRouteLevel());
054: String[] nodeNames = document.getNodeNames();
055: assertEquals("Wrong number of node names.", 1, nodeNames.length);
056: assertEquals("Wrong node name.", ADHOC_NODE, nodeNames[0]);
057: document.routeDocument("Routing sequentially.");
058:
059: // should have generated a request to "bmcgough"
060: document = new WorkflowDocument(new NetworkIdVO("bmcgough"),
061: document.getRouteHeaderId());
062: assertTrue("Document should be enroute", document
063: .stateIsEnroute());
064: assertEquals("Invalid route level.", new Integer(1), document
065: .getRouteHeader().getDocRouteLevel());
066: nodeNames = document.getNodeNames();
067: assertEquals("Wrong number of node names.", 1, nodeNames.length);
068: assertEquals("Wrong node name.", WORKFLOW_DOCUMENT_NODE,
069: nodeNames[0]);
070: ActionRequestVO[] requests = document.getActionRequests();
071: assertEquals(1, requests.length);
072: ActionRequestVO request = requests[0];
073: assertEquals("bmcgough", request.getUserVO().getNetworkId());
074: assertEquals(EdenConstants.ACTION_REQUEST_APPROVE_REQ, request
075: .getActionRequested());
076: assertEquals(new Integer(1), request.getRouteLevel());
077: assertTrue(document.isApprovalRequested());
078: document.approve("Test approve by bmcgough");
079:
080: document = new WorkflowDocument(new NetworkIdVO("temay"),
081: document.getRouteHeaderId());
082: assertTrue("Document should be processed.", document
083: .stateIsProcessed());
084: requests = document.getActionRequests();
085: assertEquals(3, requests.length);
086: boolean toTemay = false;
087: boolean toJhopf = false;
088: for (int i = 0; i < requests.length; i++) {
089: ActionRequestVO requestVO = requests[i];
090: if (requestVO.getUserVO().getNetworkId().equals("temay")) {
091: toTemay = true;
092: assertEquals(
093: EdenConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ,
094: requestVO.getActionRequested());
095: assertEquals(new Integer(2), requestVO.getRouteLevel());
096: assertEquals(EdenConstants.ACTION_REQUEST_ACTIVATED,
097: requestVO.getStatus());
098: } else if (requestVO.getUserVO().getNetworkId().equals(
099: "jhopf")) {
100: toJhopf = true;
101: assertEquals(
102: EdenConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ,
103: requestVO.getActionRequested());
104: assertEquals(new Integer(3), requestVO.getRouteLevel());
105: assertEquals(EdenConstants.ACTION_REQUEST_ACTIVATED,
106: requestVO.getStatus());
107: }
108: }
109: assertTrue("Should be an acknowledge to temay", toTemay);
110: assertTrue("Should be an acknowledge to jhopf", toJhopf);
111: // assertEquals(ACKNOWLEDGE_2_NODE, document.getRouteHeader().getNodeNames()[0]);
112: // have temay take her acknowledge
113: document.acknowledge("Temay taking acknowledge");
114:
115: document = new WorkflowDocument(new NetworkIdVO("jhopf"),
116: document.getRouteHeaderId());
117: assertTrue("Document should be processed.", document
118: .stateIsProcessed());
119: requests = document.getActionRequests();
120: toTemay = false;
121: toJhopf = false;
122: for (int i = 0; i < requests.length; i++) {
123: ActionRequestVO requestVO = requests[i];
124: if (requestVO.getUserVO().getNetworkId().equals("temay")) {
125: toTemay = true;
126: assertEquals(
127: EdenConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ,
128: requestVO.getActionRequested());
129: assertEquals(EdenConstants.ACTION_REQUEST_DONE_STATE,
130: requestVO.getStatus());
131: } else if (requestVO.getUserVO().getNetworkId().equals(
132: "jhopf")) {
133: toJhopf = true;
134: assertEquals(
135: EdenConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ,
136: requestVO.getActionRequested());
137: assertEquals(new Integer(3), requestVO.getRouteLevel());
138: assertEquals(EdenConstants.ACTION_REQUEST_ACTIVATED,
139: requestVO.getStatus());
140: }
141: }
142: assertTrue("Should be a DONE acknowledge to temay", toTemay);
143: assertTrue("Should be an acknowledge to jhopf", toJhopf);
144: // have jhopf take his acknowledge, this should cause the document to go final
145: document.acknowledge("Jhopf taking acknowledge");
146:
147: // TODO when we are able to, we should also verify the RouteNodeInstances are correct
148: document = new WorkflowDocument(new NetworkIdVO("ewestfal"),
149: document.getRouteHeaderId());
150: assertTrue("Document should be final.", document.stateIsFinal());
151:
152: verifyRoutingPath(document.getRouteHeaderId());
153: }
154:
155: private void verifyRoutingPath(Long documentId) {
156: DocumentRouteHeaderValue document = KEWServiceLocator
157: .getRouteHeaderService().getRouteHeader(documentId);
158: List initial = document.getInitialRouteNodeInstances();
159: assertEquals(1, initial.size());
160: RouteNodeInstance adhoc = (RouteNodeInstance) initial.get(0);
161: assertEquals(ADHOC_NODE, adhoc.getRouteNode()
162: .getRouteNodeName());
163: assertEquals(0, adhoc.getPreviousNodeInstances().size());
164:
165: List next = adhoc.getNextNodeInstances();
166: assertEquals(1, next.size());
167: RouteNodeInstance wd = (RouteNodeInstance) next.get(0);
168: assertEquals(WORKFLOW_DOCUMENT_NODE, wd.getRouteNode()
169: .getRouteNodeName());
170: assertEquals(1, wd.getPreviousNodeInstances().size());
171:
172: next = wd.getNextNodeInstances();
173: assertEquals(1, next.size());
174: RouteNodeInstance ack1 = (RouteNodeInstance) next.get(0);
175: assertEquals(ACKNOWLEDGE_1_NODE, ack1.getRouteNode()
176: .getRouteNodeName());
177: assertEquals(1, ack1.getPreviousNodeInstances().size());
178:
179: next = ack1.getNextNodeInstances();
180: assertEquals(1, next.size());
181: RouteNodeInstance ack2 = (RouteNodeInstance) next.get(0);
182: assertEquals(ACKNOWLEDGE_2_NODE, ack2.getRouteNode()
183: .getRouteNodeName());
184: assertEquals(1, ack2.getPreviousNodeInstances().size());
185:
186: next = ack2.getNextNodeInstances();
187: assertEquals(0, next.size());
188: }
189:
190: }
|