001    /**
002     * Copyright 2005-2011 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.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/ecl2.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.rice.kew.actionrequest;
017    
018    
019    import static org.junit.Assert.assertEquals;
020    import static org.junit.Assert.assertFalse;
021    import static org.junit.Assert.assertTrue;
022    
023    import java.util.HashSet;
024    import java.util.List;
025    import java.util.Set;
026    
027    import org.junit.Test;
028    import org.kuali.rice.kew.api.document.DocumentRefreshQueue;
029    import org.kuali.rice.kew.api.WorkflowDocument;
030    import org.kuali.rice.kew.api.WorkflowDocumentFactory;
031    import org.kuali.rice.kew.api.action.ActionRequest;
032    import org.kuali.rice.kew.messaging.MessageServiceNames;
033    import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
034    import org.kuali.rice.kew.service.KEWServiceLocator;
035    import org.kuali.rice.kew.test.KEWTestCase;
036    
037    /**
038     * Tests the reference implementation of the {@link DocumentRefreshQueue}.
039     *
040     * @author Kuali Rice Team (rice.collab@kuali.org)
041     */
042    public class DocumentRefreshQueueTest extends KEWTestCase {
043    
044        protected void loadTestData() throws Exception {
045            loadXmlFile("ActionRequestsConfig.xml");
046        }
047    
048        @Test public void testDocumentRequeueSingleNode() throws Exception {
049           WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), SeqSetup.DOCUMENT_TYPE_NAME);
050           document.route("");
051           document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
052           assertTrue(document.isEnroute());
053           List<ActionRequest> requests = document.getRootActionRequests();
054           assertEquals("Should be 2 requests.", 2, requests.size());
055           // save off request ids
056    
057           Set<String> requestIds = new HashSet<String>();
058           for (ActionRequest request : requests) {
059               requestIds.add(request.getId());
060           }
061    
062           DocumentRouteHeaderValue documentH = KEWServiceLocator.getRouteHeaderService().getRouteHeader(document.getDocumentId());
063           DocumentRefreshQueue documentRequeuer = MessageServiceNames.getDocumentRequeuerService(documentH.getDocumentType().getApplicationId(), documentH.getDocumentId(), 0);
064           documentRequeuer.refreshDocument(document.getDocumentId());
065    
066           document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
067           assertTrue(document.isEnroute());
068           requests = document.getRootActionRequests();
069           assertEquals("Should be 2 requests.", 2, requests.size());
070           for (ActionRequest requestVO : requests) {
071               assertTrue("Request ids should be different.", !requestIds.contains(requestVO.getId()));
072           }
073           assertTrue(document.isApprovalRequested());
074           document.approve("");
075    
076           // now there should just be a pending request to ryan, let's requeue again, because of force action = false we should still
077           // have only one pending request to ryan
078           documentRequeuer.refreshDocument(document.getDocumentId());
079           document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
080           assertTrue(document.isEnroute());
081           requests = document.getRootActionRequests();
082           assertEquals("Should be 2 requests.", 2, requests.size());
083           // there should only be one pending request to rkirkend
084           boolean pendingToRkirkend = false;
085            for (ActionRequest requestVO : requests)
086            {
087                if (requestVO.getPrincipalId().equals(getPrincipalIdForName("rkirkend")) && requestVO.isActivated())
088                {
089                    assertFalse("rkirkend has too many requests!", pendingToRkirkend);
090                    pendingToRkirkend = true;
091                } else
092                {
093                    assertTrue("previous request to all others should be done.", requestVO.isDone());
094                }
095            }
096           assertTrue(document.isApprovalRequested());
097       }
098    
099       private class SeqSetup {
100           public static final String DOCUMENT_TYPE_NAME = "DRSeqDocType";
101           public static final String ADHOC_NODE = "AdHoc";
102           public static final String WORKFLOW_DOCUMENT_NODE = "WorkflowDocument";
103           public static final String WORKFLOW_DOCUMENT_2_NODE = "WorkflowDocument2";
104       }
105    
106    }