View Javadoc
1   /**
2    * Copyright 2005-2014 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.actions;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertTrue;
20  import static org.junit.Assert.fail;
21  
22  import java.util.Collection;
23  import java.util.List;
24  
25  import org.junit.Test;
26  import org.kuali.rice.kew.actionitem.ActionItem;
27  import org.kuali.rice.kew.actions.BlanketApproveTest.NotifySetup;
28  import org.kuali.rice.kew.api.WorkflowDocument;
29  import org.kuali.rice.kew.api.WorkflowDocumentFactory;
30  import org.kuali.rice.kew.service.KEWServiceLocator;
31  import org.kuali.rice.kew.test.KEWTestCase;
32  
33  
34  public class CancelActionTest extends KEWTestCase {
35  
36      protected void loadTestData() throws Exception {
37          loadXmlFile("ActionsConfig.xml");
38      }
39  
40      @Test public void testCancel() throws Exception {
41          WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME);
42          document.route("");
43          
44          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId());
45          document.approve("");
46          
47          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
48          document.approve("");//ewestfal had force action rule
49          
50          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
51          document.approve("");
52          
53          //this be the role delegate of jitrue
54          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("natjohns"), document.getDocumentId());
55          document.approve("");
56          
57          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
58          document.cancel("");
59          
60          assertTrue("Document should be disapproved", document.isCanceled());
61  
62          //verify that the document is truly dead - no more action requests or action items.
63          
64          List requests = KEWServiceLocator.getActionRequestService().findPendingByDoc(document.getDocumentId());
65          assertEquals("Should not have any active requests", 0, requests.size());
66          
67          Collection<ActionItem> actionItems = KEWServiceLocator.getActionListService().findByDocumentId(document.getDocumentId());
68          assertEquals("Should not have any action items", 0, actionItems.size());
69          
70          
71      }
72  
73      @Test public void testInitiatorOnlyCancel() throws Exception {
74          WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME);
75          
76          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("user1"), document.getDocumentId());
77          try {
78              document.cancel("");
79              fail("Document should not be allowed to be cancelled due to initiator check.");
80          } catch (Exception e) {
81              
82          }
83      }
84  }