001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.workflow;
017:
018: import junit.framework.Assert;
019:
020: import org.apache.commons.logging.Log;
021: import org.apache.commons.logging.LogFactory;
022: import org.kuali.core.bo.user.UniversalUser;
023: import org.kuali.core.document.Document;
024: import org.kuali.core.service.DocumentService;
025: import org.kuali.core.workflow.service.KualiWorkflowDocument;
026: import org.kuali.kfs.context.SpringContext;
027: import org.kuali.test.monitor.ChangeMonitor;
028: import org.kuali.test.monitor.DocumentWorkflowNodeMonitor;
029: import org.kuali.test.monitor.DocumentWorkflowRequestMonitor;
030: import org.kuali.test.monitor.DocumentWorkflowStatusMonitor;
031:
032: import edu.iu.uis.eden.EdenConstants;
033: import edu.iu.uis.eden.exception.WorkflowException;
034:
035: public class WorkflowTestUtils {
036: private static final Log LOG = LogFactory
037: .getLog(WorkflowTestUtils.class);
038:
039: public static boolean isAtNode(Document document, String nodeName)
040: throws WorkflowException {
041: String[] nodeNames = document.getDocumentHeader()
042: .getWorkflowDocument().getNodeNames();
043: for (int index = 0; index < nodeNames.length; index++) {
044: if (nodeName.equals(nodeNames[index])) {
045: return true;
046: }
047: }
048: return false;
049: }
050:
051: public static void waitForNodeChange(
052: KualiWorkflowDocument document, String desiredNodeName)
053: throws Exception {
054: LOG.info("Entering: waitForNodeChange("
055: + document.getRouteHeaderId() + "," + desiredNodeName
056: + ")");
057: DocumentWorkflowNodeMonitor monitor = new DocumentWorkflowNodeMonitor(
058: document, desiredNodeName);
059: Assert.assertTrue("waitForNodeChange("
060: + document.getRouteHeaderId() + "," + desiredNodeName
061: + ") timed out", ChangeMonitor.waitUntilChange(monitor,
062: 240, 5));
063: }
064:
065: public static void waitForStatusChange(
066: KualiWorkflowDocument document, String desiredStatus)
067: throws Exception {
068: waitForStatusChange(240, document, desiredStatus);
069: }
070:
071: public static void waitForStatusChange(int numSeconds,
072: KualiWorkflowDocument document, String desiredStatus)
073: throws Exception {
074: LOG.info("Entering: waitForStatusChange(" + numSeconds + ","
075: + document.getRouteHeaderId() + "," + desiredStatus
076: + ")");
077: DocumentWorkflowStatusMonitor monitor = new DocumentWorkflowStatusMonitor(
078: SpringContext.getBean(DocumentService.class), ""
079: + document.getRouteHeaderId(), desiredStatus);
080: Assert.assertTrue("waitForStatusChange(" + numSeconds + ","
081: + document.getRouteHeaderId() + "," + desiredStatus
082: + ") timed out", ChangeMonitor.waitUntilChange(monitor,
083: numSeconds, 5));
084: }
085:
086: public static void waitForStatusChange(int numSeconds,
087: KualiWorkflowDocument document, String[] desiredStatuses)
088: throws Exception {
089: LOG.info("Entering: waitForStatusChange(" + numSeconds + ","
090: + document.getRouteHeaderId() + "," + desiredStatuses
091: + ")");
092: DocumentWorkflowStatusMonitor monitor = new DocumentWorkflowStatusMonitor(
093: SpringContext.getBean(DocumentService.class), ""
094: + document.getRouteHeaderId(), desiredStatuses);
095: Assert.assertTrue("waitForStatusChange(" + numSeconds + ","
096: + document.getRouteHeaderId() + "," + desiredStatuses
097: + ") timed out", ChangeMonitor.waitUntilChange(monitor,
098: numSeconds, 5));
099: }
100:
101: public static void waitForApproveRequest(Long docHeaderId,
102: UniversalUser user) throws Exception {
103: LOG.info("Entering: waitForApproveRequest(" + docHeaderId + ","
104: + user.getPersonUserIdentifier() + ")");
105: DocumentWorkflowRequestMonitor monitor = new DocumentWorkflowRequestMonitor(
106: docHeaderId, user,
107: EdenConstants.ACTION_REQUEST_APPROVE_REQ);
108: Assert.assertTrue("waitForApproveRequest(" + docHeaderId + ","
109: + user.getPersonUserIdentifier() + ") timed out",
110: ChangeMonitor.waitUntilChange(monitor, 240, 5));
111: }
112:
113: }
|