View Javadoc
1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.actionrequest;
17  
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.assertFalse;
21  import static org.junit.Assert.assertTrue;
22  
23  import java.util.HashSet;
24  import java.util.List;
25  import java.util.Set;
26  
27  import org.junit.Test;
28  import org.kuali.rice.kew.api.KewApiServiceLocator;
29  import org.kuali.rice.kew.api.document.DocumentRefreshQueue;
30  import org.kuali.rice.kew.api.WorkflowDocument;
31  import org.kuali.rice.kew.api.WorkflowDocumentFactory;
32  import org.kuali.rice.kew.api.action.ActionRequest;
33  import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
34  import org.kuali.rice.kew.service.KEWServiceLocator;
35  import org.kuali.rice.kew.test.KEWTestCase;
36  
37  /**
38   * Tests the reference implementation of the {@link DocumentRefreshQueue}.
39   *
40   * @author Kuali Rice Team (rice.collab@kuali.org)
41   */
42  public class DocumentRefreshQueueTest extends KEWTestCase {
43  
44      protected void loadTestData() throws Exception {
45          loadXmlFile("ActionRequestsConfig.xml");
46      }
47  
48      @Test public void testDocumentRequeueSingleNode() throws Exception {
49         WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), SeqSetup.DOCUMENT_TYPE_NAME);
50         document.route("");
51         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
52         assertTrue(document.isEnroute());
53         List<ActionRequest> requests = document.getRootActionRequests();
54         assertEquals("Should be 2 requests.", 2, requests.size());
55         // save off request ids
56  
57         Set<String> requestIds = new HashSet<String>();
58         for (ActionRequest request : requests) {
59      	   requestIds.add(request.getId());
60         }
61  
62         DocumentRouteHeaderValue documentH = KEWServiceLocator.getRouteHeaderService().getRouteHeader(document.getDocumentId());
63         DocumentRefreshQueue documentRequeuer = KewApiServiceLocator.getDocumentRequeuerService(documentH.getDocumentType().getApplicationId(), documentH.getDocumentId(), 0);
64         documentRequeuer.refreshDocument(document.getDocumentId());
65  
66         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
67         assertTrue(document.isEnroute());
68         requests = document.getRootActionRequests();
69         assertEquals("Should be 2 requests.", 2, requests.size());
70         for (ActionRequest requestVO : requests) {
71             assertTrue("Request ids should be different.", !requestIds.contains(requestVO.getId()));
72         }
73         assertTrue(document.isApprovalRequested());
74         document.approve("");
75  
76         // now there should just be a pending request to ryan, let's requeue again, because of force action = false we should still
77         // have only one pending request to ryan
78         documentRequeuer.refreshDocument(document.getDocumentId());
79         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
80         assertTrue(document.isEnroute());
81         requests = document.getRootActionRequests();
82         assertEquals("Should be 2 requests.", 2, requests.size());
83         // there should only be one pending request to rkirkend
84         boolean pendingToRkirkend = false;
85          for (ActionRequest requestVO : requests)
86          {
87              if (requestVO.getPrincipalId().equals(getPrincipalIdForName("rkirkend")) && requestVO.isActivated())
88              {
89                  assertFalse("rkirkend has too many requests!", pendingToRkirkend);
90                  pendingToRkirkend = true;
91              } else
92              {
93                  assertTrue("previous request to all others should be done.", requestVO.isDone());
94              }
95          }
96         assertTrue(document.isApprovalRequested());
97     }
98  
99     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 }