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.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.KEWServiceLocator;
026: import edu.iu.uis.eden.clientapp.WorkflowDocument;
027: import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
028: import edu.iu.uis.eden.engine.node.DynamicNode;
029: import edu.iu.uis.eden.engine.node.DynamicResult;
030: import edu.iu.uis.eden.engine.node.NodeState;
031: import edu.iu.uis.eden.engine.node.RouteNode;
032: import edu.iu.uis.eden.engine.node.RouteNodeInstance;
033: import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
034:
035: public class DynamicRoutingTest extends WorkflowTestCase {
036:
037: private static final String SEQ_DOC_TYPE_NAME = "DynSeqDocType";
038: private static final String INIT = "Initial";
039: private static final String FIRST = "First";
040: private static final String DYNAMIC_SEQ = "DynSeq";
041: private static final String SUB_REQUESTS = "SubRequests";
042: private static final String LAST = "Last";
043:
044: protected void loadTestData() throws Exception {
045: loadXmlFile("EngineConfig.xml");
046: }
047:
048: @Test
049: public void testDynamicParallelRoute() throws Exception {
050: WorkflowDocument document = new WorkflowDocument(
051: new NetworkIdVO("ewestfal"), SEQ_DOC_TYPE_NAME);
052: document.saveRoutingData();
053: assertTrue("Document should be initiated", document
054: .stateIsInitiated());
055: assertEquals("Should be no action requests.", 0, document
056: .getActionRequests().length);
057: assertEquals("Invalid route level.", new Integer(0), document
058: .getRouteHeader().getDocRouteLevel());
059: Collection nodeInstances = KEWServiceLocator
060: .getRouteNodeService().getActiveNodeInstances(
061: document.getRouteHeaderId());
062: assertEquals("Wrong number of active nodes.", 1, nodeInstances
063: .size());
064: assertEquals("Wrong active node.", INIT,
065: ((RouteNodeInstance) nodeInstances.iterator().next())
066: .getRouteNode().getRouteNodeName());
067: document.routeDocument("");
068:
069: document = new WorkflowDocument(new NetworkIdVO("bmcgough"),
070: document.getRouteHeaderId());
071: assertTrue("Approve should be requested.", document
072: .isApprovalRequested());
073: document.approve("");
074:
075: nodeInstances = KEWServiceLocator.getRouteNodeService()
076: .getActiveNodeInstances(document.getRouteHeaderId());
077: assertEquals("Wrong number of active nodes.", 1, nodeInstances
078: .size());
079: document = new WorkflowDocument(new NetworkIdVO("pmckown"),
080: document.getRouteHeaderId());
081: assertTrue("Approve should be requested.", document
082: .isApprovalRequested());
083: document.approve("");
084:
085: document = new WorkflowDocument(new NetworkIdVO("temay"),
086: document.getRouteHeaderId());
087: assertTrue("Approve should be requested.", document
088: .isApprovalRequested());
089: document.approve("");
090:
091: document = new WorkflowDocument(new NetworkIdVO("jhopf"),
092: document.getRouteHeaderId());
093: assertTrue("Approve should be requested.", document
094: .isApprovalRequested());
095: document.approve("");
096:
097: document = new WorkflowDocument(new NetworkIdVO("rkirkend"),
098: document.getRouteHeaderId());
099: assertTrue("Approve should be requested.", document
100: .isApprovalRequested());
101: document.approve("");
102:
103: // document = new WorkflowDocument(new NetworkIdVO("ewestfal"), document.getRouteHeaderId());
104: // assertTrue("Document should be final.", document.stateIsFinal());
105:
106: verifyRoutingPath(document.getRouteHeaderId());
107: }
108:
109: private void verifyRoutingPath(Long documentId) {
110: DocumentRouteHeaderValue document = KEWServiceLocator
111: .getRouteHeaderService().getRouteHeader(documentId);
112: List initial = document.getInitialRouteNodeInstances();
113: assertEquals(1, initial.size());
114: RouteNodeInstance init = (RouteNodeInstance) initial.get(0);
115: assertEquals(INIT, init.getRouteNode().getRouteNodeName());
116: assertEquals(0, init.getPreviousNodeInstances().size());
117:
118: List next = init.getNextNodeInstances();
119: assertEquals(1, next.size());
120: RouteNodeInstance first = (RouteNodeInstance) next.get(0);
121: assertEquals(FIRST, first.getRouteNode().getRouteNodeName());
122: assertEquals(1, first.getPreviousNodeInstances().size());
123:
124: next = first.getNextNodeInstances();
125: assertEquals(1, next.size());
126: RouteNodeInstance pmckownNode = (RouteNodeInstance) next.get(0);
127: assertEquals(SUB_REQUESTS, pmckownNode.getRouteNode()
128: .getRouteNodeName());
129: assertEquals(1, pmckownNode.getPreviousNodeInstances().size());
130: assertInSubProcess(pmckownNode);
131:
132: next = pmckownNode.getNextNodeInstances();
133: assertEquals(1, next.size());
134: RouteNodeInstance temayNode = (RouteNodeInstance) next.get(0);
135: assertEquals(SUB_REQUESTS, temayNode.getRouteNode()
136: .getRouteNodeName());
137: assertEquals(1, temayNode.getPreviousNodeInstances().size());
138: assertInSubProcess(temayNode);
139:
140: next = temayNode.getNextNodeInstances();
141: assertEquals(1, next.size());
142: RouteNodeInstance jhopfNode = (RouteNodeInstance) next.get(0);
143: assertEquals(SUB_REQUESTS, jhopfNode.getRouteNode()
144: .getRouteNodeName());
145: assertEquals(1, jhopfNode.getPreviousNodeInstances().size());
146: assertInSubProcess(jhopfNode);
147:
148: next = jhopfNode.getNextNodeInstances();
149: assertEquals(1, next.size());
150: RouteNodeInstance last = (RouteNodeInstance) next.get(0);
151: assertNull(last.getProcess());
152: assertEquals(LAST, last.getRouteNode().getRouteNodeName());
153: assertEquals(1, last.getPreviousNodeInstances().size());
154: assertEquals(0, last.getNextNodeInstances().size());
155: }
156:
157: private void assertInSubProcess(RouteNodeInstance nodeInstance) {
158: RouteNodeInstance subProcess = nodeInstance.getProcess();
159: assertNotNull(subProcess);
160: assertEquals(DYNAMIC_SEQ, subProcess.getRouteNode()
161: .getRouteNodeName());
162: }
163:
164: public static class MockSequentialDynamicNode implements
165: DynamicNode {
166:
167: public DynamicResult transitioningInto(RouteContext context,
168: RouteNodeInstance process, RouteHelper helper)
169: throws Exception {
170: RouteNodeInstance routeNodeInstance = context
171: .getNodeInstance();
172: RouteNode dynamicRequestNode = helper.getNodeFactory()
173: .getRouteNode(context, SUB_REQUESTS);
174: RouteNodeInstance dynamicRequestNodeInstance1 = helper
175: .getNodeFactory().createRouteNodeInstance(
176: context.getDocument().getRouteHeaderId(),
177: dynamicRequestNode);
178: dynamicRequestNodeInstance1.addNodeState(new NodeState(
179: "role", "pmckown"));
180: RouteNodeInstance dynamicRequestNodeInstance2 = helper
181: .getNodeFactory().createRouteNodeInstance(
182: context.getDocument().getRouteHeaderId(),
183: dynamicRequestNode);
184: dynamicRequestNodeInstance2.addNodeState(new NodeState(
185: "role", "temay"));
186: RouteNodeInstance dynamicRequestNodeInstance3 = helper
187: .getNodeFactory().createRouteNodeInstance(
188: context.getDocument().getRouteHeaderId(),
189: dynamicRequestNode);
190: dynamicRequestNodeInstance3.addNodeState(new NodeState(
191: "role", "jhopf"));
192: dynamicRequestNodeInstance1
193: .addNextNodeInstance(dynamicRequestNodeInstance2);
194: dynamicRequestNodeInstance2
195: .addNextNodeInstance(dynamicRequestNodeInstance3);
196: routeNodeInstance.addNodeState(new NodeState("beenHere",
197: "val"));
198: return new DynamicResult(true, dynamicRequestNodeInstance1);
199: }
200:
201: public DynamicResult transitioningOutOf(RouteContext context,
202: RouteHelper helper) throws Exception {
203: return new DynamicResult(true, null);
204: }
205: }
206: }
|