001 /**
002 * Copyright 2005-2014 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.actions;
017
018 import static org.junit.Assert.assertEquals;
019 import static org.junit.Assert.assertTrue;
020 import static org.junit.Assert.fail;
021
022 import java.util.Collection;
023 import java.util.List;
024
025 import org.junit.Test;
026 import org.kuali.rice.kew.actionitem.ActionItem;
027 import org.kuali.rice.kew.actions.BlanketApproveTest.NotifySetup;
028 import org.kuali.rice.kew.api.WorkflowDocument;
029 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
030 import org.kuali.rice.kew.service.KEWServiceLocator;
031 import org.kuali.rice.kew.test.KEWTestCase;
032
033
034 public class CancelActionTest extends KEWTestCase {
035
036 protected void loadTestData() throws Exception {
037 loadXmlFile("ActionsConfig.xml");
038 }
039
040 @Test public void testCancel() throws Exception {
041 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME);
042 document.route("");
043
044 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId());
045 document.approve("");
046
047 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
048 document.approve("");//ewestfal had force action rule
049
050 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
051 document.approve("");
052
053 //this be the role delegate of jitrue
054 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("natjohns"), document.getDocumentId());
055 document.approve("");
056
057 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
058 document.cancel("");
059
060 assertTrue("Document should be disapproved", document.isCanceled());
061
062 //verify that the document is truly dead - no more action requests or action items.
063
064 List requests = KEWServiceLocator.getActionRequestService().findPendingByDoc(document.getDocumentId());
065 assertEquals("Should not have any active requests", 0, requests.size());
066
067 Collection<ActionItem> actionItems = KEWServiceLocator.getActionListService().findByDocumentId(document.getDocumentId());
068 assertEquals("Should not have any action items", 0, actionItems.size());
069
070
071 }
072
073 @Test public void testInitiatorOnlyCancel() throws Exception {
074 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME);
075
076 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("user1"), document.getDocumentId());
077 try {
078 document.cancel("");
079 fail("Document should not be allowed to be cancelled due to initiator check.");
080 } catch (Exception e) {
081
082 }
083 }
084 }