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.node;
018:
019: import java.util.ArrayList;
020: import java.util.Iterator;
021: import java.util.List;
022: import java.util.Set;
023:
024: import org.junit.Test;
025: import org.kuali.workflow.test.WorkflowTestCase;
026:
027: import edu.iu.uis.eden.KEWServiceLocator;
028: import edu.iu.uis.eden.clientapp.WorkflowDocument;
029: import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
030: import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
031: import edu.iu.uis.eden.test.TestUtilities;
032:
033: public class RouteNodeServiceTest extends WorkflowTestCase {
034:
035: private RouteNodeService service;
036:
037: protected void setUpTransaction() throws Exception {
038: service = KEWServiceLocator.getRouteNodeService();
039: }
040:
041: protected void loadTestData() throws Exception {
042: loadXmlFile("NodeConfig.xml");
043: }
044:
045: @Test
046: public void testGetFlattenedNodeInstances() throws Exception {
047: WorkflowDocument document = new WorkflowDocument(
048: new NetworkIdVO("ewestfal"), "SeqDocType");
049: document.saveDocument("");
050:
051: DocumentRouteHeaderValue serverDocument = KEWServiceLocator
052: .getRouteHeaderService().getRouteHeader(
053: document.getRouteHeaderId());
054: List routeNodeInstances = service.getFlattenedNodeInstances(
055: serverDocument, true);
056: assertEquals(1, routeNodeInstances.size());
057: assertEquals("AdHoc", ((RouteNodeInstance) routeNodeInstances
058: .get(0)).getName());
059:
060: document.blanketApprove("");
061: assertTrue(document.stateIsProcessed());
062:
063: serverDocument = KEWServiceLocator.getRouteHeaderService()
064: .getRouteHeader(document.getRouteHeaderId());
065: routeNodeInstances = service.getFlattenedNodeInstances(
066: serverDocument, true);
067: assertEquals(4, routeNodeInstances.size());
068: assertEquals("AdHoc", ((RouteNodeInstance) routeNodeInstances
069: .get(0)).getName());
070: assertEquals("WorkflowDocument",
071: ((RouteNodeInstance) routeNodeInstances.get(1))
072: .getName());
073: assertEquals("Acknowledge1",
074: ((RouteNodeInstance) routeNodeInstances.get(2))
075: .getName());
076: assertEquals("Acknowledge2",
077: ((RouteNodeInstance) routeNodeInstances.get(3))
078: .getName());
079: }
080:
081: @Test
082: public void testSearchNodeGraphSequentailBackward()
083: throws Exception {
084: WorkflowDocument document = new WorkflowDocument(
085: new NetworkIdVO("ewestfal"), "SeqDocType");
086: document.blanketApprove("", "WorkflowDocument");
087: List activeNodeInstances = service
088: .getActiveNodeInstances(document.getRouteHeaderId());
089: NodeGraphSearchCriteria criteria = new NodeGraphSearchCriteria(
090: NodeGraphSearchCriteria.SEARCH_DIRECTION_BACKWARD,
091: activeNodeInstances, "AdHoc");
092: NodeGraphSearchResult result = service
093: .searchNodeGraph(criteria);
094: assertEquals("Path should have two nodes.", 2, result.getPath()
095: .size());
096: RouteNodeInstance resultNodeInstance = result
097: .getResultNodeInstance();
098: assertNotNull("Should have a resulting node instance.",
099: resultNodeInstance);
100: assertEquals("Result node should be the adhoc node.", "AdHoc",
101: resultNodeInstance.getName());
102:
103: // take it to the end
104: document.blanketApprove("");
105: assertTrue("Document should be processed.", document
106: .stateIsProcessed());
107: List terminalNodeInstances = service
108: .getTerminalNodeInstances(document.getRouteHeaderId());
109: criteria = new NodeGraphSearchCriteria(
110: NodeGraphSearchCriteria.SEARCH_DIRECTION_BACKWARD,
111: terminalNodeInstances, "AdHoc");
112: result = service.searchNodeGraph(criteria);
113: assertEquals("Path should have 4 nodes.", 4, result.getPath()
114: .size());
115: resultNodeInstance = result.getResultNodeInstance();
116: assertNotNull("Should have a resulting node instance.",
117: resultNodeInstance);
118: assertEquals("Result node should be the adhoc node.", "AdHoc",
119: resultNodeInstance.getName());
120:
121: // now try searching from the Ack1 node for the WorkflowDocument node
122: RouteNodeInstance ack1NodeInstance = null;
123: for (Iterator iterator = result.getPath().iterator(); iterator
124: .hasNext();) {
125: RouteNodeInstance nodeInstance = (RouteNodeInstance) iterator
126: .next();
127: if (nodeInstance.getName().equals("Acknowledge1")) {
128: ack1NodeInstance = nodeInstance;
129: break;
130: }
131: }
132: assertNotNull(
133: "Could not locate the Acknowledge1 node in the path.",
134: ack1NodeInstance);
135: List startNodes = new ArrayList();
136: startNodes.add(ack1NodeInstance);
137: criteria = new NodeGraphSearchCriteria(
138: NodeGraphSearchCriteria.SEARCH_DIRECTION_BACKWARD,
139: startNodes, "WorkflowDocument");
140: result = service.searchNodeGraph(criteria);
141: // since we started at 'Acknowledge1' there should just be 'Acknowledge1' and 'WorkflowDocument' in the path
142: assertEquals("Path should have 2 nodes.", 2, result.getPath()
143: .size());
144: resultNodeInstance = result.getResultNodeInstance();
145: assertNotNull("Should have a resulting node instance.",
146: resultNodeInstance);
147: assertEquals(
148: "Result node should be the workflow document node.",
149: "WorkflowDocument", resultNodeInstance.getName());
150: }
151:
152: @Test
153: public void testSearchNodeGraphParallelBackward() throws Exception {
154: WorkflowDocument document = new WorkflowDocument(
155: new NetworkIdVO("ewestfal"), "ParallelDocType");
156: document.blanketApprove("", new String[] { "WorkflowDocument2",
157: "WorkflowDocument3" });
158: List activeNodeInstances = service
159: .getActiveNodeInstances(document.getRouteHeaderId());
160: assertEquals("Should be 2 active nodes.", 2,
161: activeNodeInstances.size());
162: Set nodeNames = TestUtilities
163: .createNodeInstanceNameSet(activeNodeInstances);
164: assertTrue("Should be at WorkflowDocument2 node.", nodeNames
165: .contains("WorkflowDocument2"));
166: assertTrue("Should be at the WorkflowDocument3 node.",
167: nodeNames.contains("WorkflowDocument3"));
168:
169: // search backward to the adhoc node
170: NodeGraphSearchCriteria criteria = new NodeGraphSearchCriteria(
171: NodeGraphSearchCriteria.SEARCH_DIRECTION_BACKWARD,
172: activeNodeInstances, "AdHoc");
173: NodeGraphSearchResult result = service
174: .searchNodeGraph(criteria);
175: assertEquals("Path should have eight nodes.", 8, result
176: .getPath().size());
177: RouteNodeInstance resultNodeInstance = result
178: .getResultNodeInstance();
179: assertNotNull("Should have a resulting node instance.",
180: resultNodeInstance);
181: assertEquals("Result node should be the adhoc node.", "AdHoc",
182: resultNodeInstance.getName());
183: nodeNames = TestUtilities.createNodeInstanceNameSet(result
184: .getPath());
185: // the following nodes should be in the list of 8
186: assertTrue(nodeNames.contains("WorkflowDocument3"));
187: assertTrue(nodeNames.contains("WorkflowDocument5"));
188: assertTrue(nodeNames.contains("WorkflowDocument2"));
189: assertTrue(nodeNames.contains("Acknowledge1"));
190: assertTrue(nodeNames.contains("WorkflowDocument4"));
191: assertTrue(nodeNames.contains("Split"));
192: assertTrue(nodeNames.contains("WorkflowDocument"));
193: assertTrue(nodeNames.contains("AdHoc"));
194:
195: // extract our active node instances
196: RouteNodeInstance workflowDocument2Node = null;
197: RouteNodeInstance workflowDocument3Node = null;
198: for (Iterator iterator = activeNodeInstances.iterator(); iterator
199: .hasNext();) {
200: RouteNodeInstance nodeInstance = (RouteNodeInstance) iterator
201: .next();
202: if (nodeInstance.getName().equals("WorkflowDocument2")) {
203: workflowDocument2Node = nodeInstance;
204: } else if (nodeInstance.getName().equals(
205: "WorkflowDocument3")) {
206: workflowDocument3Node = nodeInstance;
207: }
208: }
209: assertNotNull("Could not locate WorkflowDocument2 node.",
210: workflowDocument2Node);
211: assertNotNull("Could not locate WorkflowDocument3 node.",
212: workflowDocument3Node);
213:
214: // now try searching backward for WorkflowDocument4 from WorkflowDocument2, this should keep us on the branch
215: List startNodeInstances = new ArrayList();
216: startNodeInstances.add(workflowDocument2Node);
217: criteria = new NodeGraphSearchCriteria(
218: NodeGraphSearchCriteria.SEARCH_DIRECTION_BACKWARD,
219: activeNodeInstances, "WorkflowDocument4");
220: result = service.searchNodeGraph(criteria);
221: assertEquals("Path should have three nodes.", 3, result
222: .getPath().size());
223: resultNodeInstance = result.getResultNodeInstance();
224: assertEquals(
225: "Result node should be the WorkflowDocument4 node.",
226: "WorkflowDocument4", resultNodeInstance.getName());
227: nodeNames = TestUtilities.createNodeInstanceNameSet(result
228: .getPath());
229: // the following nodes should be in the list of 3
230: assertTrue(nodeNames.contains("WorkflowDocument2"));
231: assertTrue(nodeNames.contains("Acknowledge1"));
232: assertTrue(nodeNames.contains("WorkflowDocument4"));
233:
234: // try searching backward for WorkflowDocument5
235: startNodeInstances = new ArrayList();
236: startNodeInstances.add(workflowDocument3Node);
237: criteria = new NodeGraphSearchCriteria(
238: NodeGraphSearchCriteria.SEARCH_DIRECTION_BACKWARD,
239: activeNodeInstances, "WorkflowDocument5");
240: result = service.searchNodeGraph(criteria);
241: assertEquals("Path should have two nodes.", 2, result.getPath()
242: .size());
243: resultNodeInstance = result.getResultNodeInstance();
244: assertEquals(
245: "Result node should be the WorkflowDocument5 node.",
246: "WorkflowDocument5", resultNodeInstance.getName());
247: nodeNames = TestUtilities.createNodeInstanceNameSet(result
248: .getPath());
249: // the following nodes should be in the list of 2
250: assertTrue(nodeNames.contains("WorkflowDocument3"));
251: assertTrue(nodeNames.contains("WorkflowDocument5"));
252: }
253:
254: /**
255: * currently searching forward does not work and needs to be implemented, we'll stub in a test
256: * that shows it throws an UnsupportedOperationException and then this test can be modified when the
257: * functionality is implemented.
258: */
259: @Test
260: public void testSearchNodeGraphForward() throws Exception {
261: WorkflowDocument document = new WorkflowDocument(
262: new NetworkIdVO("ewestfal"), "SeqDocType");
263: document.routeDocument("");
264: List initialNodeInstances = KEWServiceLocator
265: .getRouteNodeService().getInitialNodeInstances(
266: document.getRouteHeaderId());
267: NodeGraphSearchCriteria criteria = new NodeGraphSearchCriteria(
268: NodeGraphSearchCriteria.SEARCH_DIRECTION_FORWARD,
269: initialNodeInstances, "WorkflowDocument");
270: try {
271: service.searchNodeGraph(criteria);
272: fail("Should have thrown UnsupportedOperationException");
273: } catch (UnsupportedOperationException e) {
274: }
275: }
276:
277: }
|