1
2
3
4
5
6
7
8
9
10
11
12
13
14
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("");
49
50 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
51 document.approve("");
52
53
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
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 }