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 if (notify) {
61 assertTrue(WorkflowDocumentFactory.loadDocument(document.getInitiatorPrincipalId(), document.getDocumentId()).isAcknowledgeRequested());
62 assertTrue(WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId()).isAcknowledgeRequested());
63 assertTrue(WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId()).isAcknowledgeRequested());
64
65 assertFalse(WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId()).isAcknowledgeRequested());
66 }
67 }
68
69 @Test public void testSuperUserInitiatorDisapprove() throws Exception {
70 superUserInitiatorDisapprove(false);
71 }
72
73 @Test public void testSuperUserInitiatorDisapproveWithNotification() throws Exception {
74 superUserInitiatorDisapprove(true);
75 }
76
77 protected void superUserInitiatorDisapprove(boolean notify) throws Exception {
78 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), notify ? DOC_TYPE_WITH_NOTIFY: DOC_TYPE);
79 document.route("");
80
81 WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId()).approve("");
82 WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId()).approve("");
83 WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId()).approve("");
84
85 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
86 assertTrue("WorkflowDocument should indicate ewestfal as SuperUser", document.isValidAction(ActionType.SU_DISAPPROVE));
87 document.superUserDisapprove("");
88 assertTrue("Document should be final after Super User Disapprove", document.isDisapproved());
89 if (notify) {
90 assertTrue(WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId()).isAcknowledgeRequested());
91 assertTrue(WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId()).isAcknowledgeRequested());
92
93 assertFalse(WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId()).isAcknowledgeRequested());
94 }
95 }
96
97 @Test public void testSuperUserInitiatorImmediateDisapprove() throws Exception {
98 superUserInitiatorImmediateDisapprove(false);
99 }
100
101 @Test public void testSuperUserInitiatorImmediateDisapproveWithNotification() throws Exception {
102 superUserInitiatorImmediateDisapprove(true);
103 }
104
105 protected void superUserInitiatorImmediateDisapprove(boolean notify) throws Exception {
106 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), notify ? DOC_TYPE_WITH_NOTIFY: DOC_TYPE);
107 assertTrue("WorkflowDocument should indicate ewestfal as SuperUser", document.isValidAction(ActionType.SU_DISAPPROVE));
108 document.superUserDisapprove("");
109 assertTrue("Document should be final after Super User Disapprove", document.isDisapproved());
110
111 assertFalse(WorkflowDocumentFactory.loadDocument(document.getInitiatorPrincipalId(), document.getDocumentId()).isAcknowledgeRequested());
112 assertFalse(WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId()).isAcknowledgeRequested());
113 }
114
115 @Test public void testSuperUserDisapproveInvalidUser() throws Exception {
116 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME);
117 document.route("");
118
119 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("quickstart"), document.getDocumentId());
120 try {
121 assertFalse("WorkflowDocument should not indicate quickstart as SuperUser", document.isValidAction(ActionType.SU_DISAPPROVE));
122 document.superUserDisapprove("");
123 fail("invalid user attempted to SuperUserApprove");
124 } catch (Exception e) {
125 }
126
127 }
128
129 }