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.Iterator;
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.actionrequests.ActionRequestValue;
028: import edu.iu.uis.eden.clientapp.WorkflowDocument;
029: import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
030: import edu.iu.uis.eden.clientapp.vo.RouteNodeInstanceVO;
031: import edu.iu.uis.eden.engine.node.RouteNodeInstance;
032:
033: public class SubProcessRoutingTest extends WorkflowTestCase {
034:
035: private static final String DOCUMENT_TYPE_NAME = "SubProcessDocType";
036: private static final String SUB_PROCESS_NODE = "MySubProcess";
037: private static final String ACKNOWLEDGE_NODE = "Acknowledge";
038: private static final String APPROVE_NODE = "Approve";
039:
040: protected void loadTestData() throws Exception {
041: loadXmlFile("EngineConfig.xml");
042: }
043:
044: @Test
045: public void testSubProcessRoute() throws Exception {
046: WorkflowDocument document = new WorkflowDocument(
047: new NetworkIdVO("ewestfal"), DOCUMENT_TYPE_NAME);
048: document.saveRoutingData();
049: assertTrue("Document should be initiated", document
050: .stateIsInitiated());
051: assertEquals("Should be no action requests.", 0, document
052: .getActionRequests().length);
053: assertEquals("Invalid route level.", new Integer(0), document
054: .getRouteHeader().getDocRouteLevel());
055: document.routeDocument("");
056: assertTrue("Document shoule be ENROUTE.", document
057: .stateIsEnroute());
058:
059: List actionRequests = KEWServiceLocator
060: .getActionRequestService().findPendingByDoc(
061: document.getRouteHeaderId());
062: assertEquals("Incorrect pending action requests.", 2,
063: actionRequests.size());
064: boolean isAck = false;
065: boolean isApprove = false;
066: for (Iterator iterator = actionRequests.iterator(); iterator
067: .hasNext();) {
068: ActionRequestValue request = (ActionRequestValue) iterator
069: .next();
070: RouteNodeInstance nodeInstance = request.getNodeInstance();
071: assertNotNull("Node instance should be non null.",
072: nodeInstance);
073: if (request.getWorkflowUser().getAuthenticationUserId()
074: .getId().equals("bmcgough")) {
075: isAck = true;
076: assertEquals("Wrong request type.",
077: EdenConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ,
078: request.getActionRequested());
079: assertEquals("Wrong node.", ACKNOWLEDGE_NODE,
080: nodeInstance.getRouteNode().getRouteNodeName());
081: assertNotNull("Should be in a sub process.",
082: nodeInstance.getProcess());
083: assertEquals("Wrong sub process.", SUB_PROCESS_NODE,
084: nodeInstance.getProcess().getRouteNode()
085: .getRouteNodeName());
086: assertFalse("Sub process should be non-initial.",
087: nodeInstance.getProcess().isInitial());
088: assertFalse("Sub process should be non-active.",
089: nodeInstance.getProcess().isActive());
090: assertFalse("Sub process should be non-complete.",
091: nodeInstance.getProcess().isComplete());
092: } else if (request.getWorkflowUser()
093: .getAuthenticationUserId().getId().equals("temay")) {
094: isApprove = true;
095: assertEquals("Wrong request type.",
096: EdenConstants.ACTION_REQUEST_APPROVE_REQ,
097: request.getActionRequested());
098: assertEquals("Wrong node.", APPROVE_NODE, request
099: .getNodeInstance().getRouteNode()
100: .getRouteNodeName());
101: assertNotNull("Should be in a sub process.", request
102: .getNodeInstance().getProcess());
103: assertEquals("Wrong sub process.", SUB_PROCESS_NODE,
104: request.getNodeInstance().getProcess()
105: .getRouteNode().getRouteNodeName());
106: assertFalse("Sub process should be non-initial.",
107: nodeInstance.getProcess().isInitial());
108: assertFalse("Sub process should be non-active.",
109: nodeInstance.getProcess().isActive());
110: assertFalse("Sub process should be non-complete.",
111: nodeInstance.getProcess().isComplete());
112: }
113: }
114: assertTrue(isAck);
115: assertTrue(isApprove);
116: document = new WorkflowDocument(new NetworkIdVO("bmcgough"),
117: document.getRouteHeaderId());
118: assertTrue("Should have acknowledge.", document
119: .isAcknowledgeRequested());
120: document.acknowledge("");
121:
122: document = new WorkflowDocument(new NetworkIdVO("temay"),
123: document.getRouteHeaderId());
124: document.approve("");
125:
126: // find the subprocess and assert it is complete, not active, and not initial
127: boolean foundSubProcess = false;
128: RouteNodeInstanceVO[] nodeInstances = document
129: .getRouteNodeInstances();
130: for (int index = 0; index < nodeInstances.length; index++) {
131: RouteNodeInstanceVO instanceVO = nodeInstances[index];
132: if (instanceVO.getName().equals(SUB_PROCESS_NODE)) {
133: foundSubProcess = true;
134: assertFalse("Sub process should be non-initial.",
135: instanceVO.isInitial());
136: assertFalse("Sub process should be non-active.",
137: instanceVO.isActive());
138: assertTrue("Sub process should be complete.",
139: instanceVO.isComplete());
140: }
141: }
142: assertTrue("Could not locate sub process node.",
143: foundSubProcess);
144:
145: document = new WorkflowDocument(new NetworkIdVO("rkirkend"),
146: document.getRouteHeaderId());
147: document.approve("");
148:
149: document = new WorkflowDocument(new NetworkIdVO("ewestfal"),
150: document.getRouteHeaderId());
151: assertTrue("Document should be final.", document.stateIsFinal());
152: }
153:
154: }
|