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.actionrequests;
018:
019: import java.util.HashSet;
020: import java.util.Set;
021:
022: import org.junit.Ignore;
023: import org.junit.Test;
024: import org.kuali.workflow.test.WorkflowTestCase;
025:
026: import edu.iu.uis.eden.KEWServiceLocator;
027: import edu.iu.uis.eden.clientapp.WorkflowDocument;
028: import edu.iu.uis.eden.clientapp.vo.ActionRequestVO;
029: import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
030: import edu.iu.uis.eden.messaging.MessageServiceNames;
031: import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
032:
033: /**
034: * Tests the DocumentRequeuer route queue processor.
035: *
036: * @author ewestfal
037: */
038: public class DocumentRequeuerTest extends WorkflowTestCase {
039:
040: protected void loadTestData() throws Exception {
041: loadXmlFile("ActionRequestsConfig.xml");
042: }
043:
044: @Test
045: public void testDocumentRequeueSingleNode() throws Exception {
046: WorkflowDocument document = new WorkflowDocument(
047: new NetworkIdVO("ewestfal"),
048: SeqSetup.DOCUMENT_TYPE_NAME);
049: document.routeDocument("");
050: document = new WorkflowDocument(new NetworkIdVO("ewestfal"),
051: document.getRouteHeaderId());
052: assertTrue(document.stateIsEnroute());
053: ActionRequestVO[] requests = document.getActionRequests();
054: assertEquals("Should be 2 requests.", 2, requests.length);
055: // save off request ids
056: Set<Long> requestIds = new HashSet<Long>();
057: for (int index = 0; index < requests.length; index++) {
058: ActionRequestVO requestVO = requests[index];
059: requestIds.add(requestVO.getActionRequestId());
060: }
061:
062: DocumentRouteHeaderValue documentH = KEWServiceLocator
063: .getRouteHeaderService().getRouteHeader(
064: document.getRouteHeaderId());
065: DocumentRequeuerService documentRequeuer = MessageServiceNames
066: .getDocumentRequeuerService(documentH.getDocumentType()
067: .getMessageEntity(), documentH
068: .getRouteHeaderId(), 0);
069: documentRequeuer.requeueDocument(document.getRouteHeaderId());
070:
071: // initiate a requeue of the document
072: // SpringServiceLocator.getRouteQueueService().requeueDocument(document.getRouteHeaderId(), DocumentRequeuerImpl.class.getName());
073:
074: document = new WorkflowDocument(new NetworkIdVO("bmcgough"),
075: document.getRouteHeaderId());
076: assertTrue(document.stateIsEnroute());
077: requests = document.getActionRequests();
078: assertEquals("Should be 2 requests.", 2, requests.length);
079: for (int index = 0; index < requests.length; index++) {
080: ActionRequestVO requestVO = requests[index];
081: assertTrue("Request ids should be different.", !requestIds
082: .contains(requestVO.getActionRequestId()));
083: }
084: assertTrue(document.isApprovalRequested());
085: document.approve("");
086:
087: // now there should just be a pending request to ryan, let's requeue again, because of ignore previous = false we should still
088: // have only one pending request to ryan
089: // SpringServiceLocator.getRouteQueueService().requeueDocument(document.getRouteHeaderId(), DocumentRequeuerImpl.class.getName());
090: documentRequeuer.requeueDocument(document.getRouteHeaderId());
091: document = new WorkflowDocument(new NetworkIdVO("rkirkend"),
092: document.getRouteHeaderId());
093: assertTrue(document.stateIsEnroute());
094: requests = document.getActionRequests();
095: assertEquals("Should be 2 requests.", 2, requests.length);
096: // there should only be one pending request to rkirkend
097: boolean pendingToRkirkend = false;
098: for (int index = 0; index < requests.length; index++) {
099: ActionRequestVO requestVO = requests[index];
100: if (requestVO.getUserVO().getNetworkId().equals("rkirkend")
101: && requestVO.isActivated()) {
102: assertFalse("rkirkend has too many requests!",
103: pendingToRkirkend);
104: pendingToRkirkend = true;
105: } else {
106: assertTrue(
107: "previous request to all others should be done.",
108: requestVO.isDone());
109: }
110: }
111: assertTrue(document.isApprovalRequested());
112: // WorkflowReports reports = new WorkflowReports();
113: // assertTrue(reports.isLastApproverAtNode(document.getRouteHeaderId(), new NetworkIdVO("rkirkend"), SeqSetup.WORKFLOW_DOCUMENT_NODE));
114: }
115:
116: @Ignore("This test needs to be implemented!")
117: @Test
118: public void testDocumentRequeueMultipleNodes() throws Exception {
119: // TODO time permitting we should write a test here which attempts to requeue a document which is sitting at multiple nodes
120: }
121:
122: private class SeqSetup {
123: public static final String DOCUMENT_TYPE_NAME = "DRSeqDocType";
124: public static final String ADHOC_NODE = "AdHoc";
125: public static final String WORKFLOW_DOCUMENT_NODE = "WorkflowDocument";
126: public static final String WORKFLOW_DOCUMENT_2_NODE = "WorkflowDocument2";
127: }
128:
129: }
|