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 org.junit.Test;
19 import org.kuali.rice.kew.actions.BlanketApproveTest.NotifySetup;
20 import org.kuali.rice.kew.api.WorkflowDocument;
21 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
22 import org.kuali.rice.kew.api.action.ActionType;
23 import org.kuali.rice.kew.test.KEWTestCase;
24
25 import static org.junit.Assert.*;
26
27
28
29
30
31
32 public class SuperUserDisapproveTest extends KEWTestCase {
33 private static final String DOC_TYPE = NotifySetup.DOCUMENT_TYPE_NAME;
34 private static final String DOC_TYPE_WITH_NOTIFY = "SUDisapproveWithNotificationTest";
35
36 protected void loadTestData() throws Exception {
37 loadXmlFile("ActionsConfig.xml");
38 }
39
40 @Test public void testSuperUserDisapprove() throws Exception {
41 superUserDisapprove(false);
42 }
43
44 @Test public void testSuperUserDisapproveWithNotification() throws Exception {
45 superUserDisapprove(true);
46 }
47
48 protected void superUserDisapprove(boolean notify) throws Exception {
49 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), notify ? DOC_TYPE_WITH_NOTIFY: DOC_TYPE);
50 document.route("");
51
52 WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId()).approve("");
53 WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId()).approve("");
54 WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId()).approve("");
55
56 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId());
57 assertTrue("WorkflowDocument should indicate jhopf as SuperUser", document.isValidAction(ActionType.SU_DISAPPROVE));
58 document.superUserDisapprove("");
59 assertTrue("Document should be final after Super User Disapprove", document.isDisapproved());
60 assertEquals(notify, WorkflowDocumentFactory.loadDocument(document.getInitiatorPrincipalId(), document.getDocumentId()).isAcknowledgeRequested());
61 assertEquals(notify, WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId()).isAcknowledgeRequested());
62 assertEquals(notify, WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId()).isAcknowledgeRequested());
63 assertEquals(notify, WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId()).isAcknowledgeRequested());
64 }
65
66 @Test public void testSuperUserInitiatorDisapprove() throws Exception {
67 superUserInitiatorDisapprove(false);
68 }
69
70 @Test public void testSuperUserInitiatorDisapproveWithNotification() throws Exception {
71 superUserInitiatorDisapprove(true);
72 }
73
74 protected void superUserInitiatorDisapprove(boolean notify) throws Exception {
75 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), notify ? DOC_TYPE_WITH_NOTIFY: DOC_TYPE);
76 document.route("");
77
78 WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId()).approve("");
79 WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId()).approve("");
80 WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId()).approve("");
81
82 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
83 assertTrue("WorkflowDocument should indicate ewestfal as SuperUser", document.isValidAction(ActionType.SU_DISAPPROVE));
84 document.superUserDisapprove("");
85 assertTrue("Document should be final after Super User Disapprove", document.isDisapproved());
86
87 assertEquals(notify, WorkflowDocumentFactory.loadDocument(document.getInitiatorPrincipalId(), document.getDocumentId()).isAcknowledgeRequested());
88 assertEquals(notify, WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId()).isAcknowledgeRequested());
89 assertEquals(notify, WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId()).isAcknowledgeRequested());
90 assertEquals(notify, WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId()).isAcknowledgeRequested());
91 }
92
93 @Test public void testSuperUserInitiatorImmediateDisapprove() throws Exception {
94 superUserInitiatorImmediateDisapprove(false);
95 }
96
97 @Test public void testSuperUserInitiatorImmediateDisapproveWithNotification() throws Exception {
98 superUserInitiatorImmediateDisapprove(true);
99 }
100
101 protected void superUserInitiatorImmediateDisapprove(boolean notify) throws Exception {
102 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), notify ? DOC_TYPE_WITH_NOTIFY: DOC_TYPE);
103 assertTrue("WorkflowDocument should indicate ewestfal as SuperUser", document.isValidAction(ActionType.SU_DISAPPROVE));
104 document.superUserDisapprove("");
105 assertTrue("Document should be final after Super User Disapprove", document.isDisapproved());
106
107 assertFalse(WorkflowDocumentFactory.loadDocument(document.getInitiatorPrincipalId(), document.getDocumentId()).isAcknowledgeRequested());
108 assertFalse(WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId()).isAcknowledgeRequested());
109 }
110
111 @Test public void testSuperUserDisapproveInvalidUser() throws Exception {
112 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME);
113 document.route("");
114
115 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("quickstart"), document.getDocumentId());
116 try {
117 assertFalse("WorkflowDocument should not indicate quickstart as SuperUser", document.isValidAction(ActionType.SU_DISAPPROVE));
118 document.superUserDisapprove("");
119 fail("invalid user attempted to SuperUserApprove");
120 } catch (Exception e) {
121 }
122
123 }
124
125 }