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.fail;
20
21 import java.util.Set;
22
23 import org.junit.Test;
24 import org.kuali.rice.kew.api.WorkflowDocument;
25 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
26 import org.kuali.rice.kew.api.action.ActionType;
27 import org.kuali.rice.kew.api.document.DocumentStatus;
28 import org.kuali.rice.kew.test.KEWTestCase;
29 import org.kuali.rice.kew.api.KewApiConstants;
30
31
32 public class ValidActionsTest extends KEWTestCase {
33
34 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ValidActionsTest.class);
35
36 public static final String DOCUMENT_TYPE_NAME = "BlanketApproveSequentialTest";
37
38 protected void loadTestData() throws Exception {
39 loadXmlFile("ActionsConfig.xml");
40 }
41
42 @Test public void testValidActions() throws Exception {
43 WorkflowDocument document = null;
44 String networkId = null;
45 document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), DOCUMENT_TYPE_NAME);
46 String documentId = document.getDocumentId();
47
48 networkId = "rkirkend";
49 document = this.checkActions(networkId, documentId,
50 new String[]{KewApiConstants.ACTION_TAKEN_SU_CANCELED_CD,KewApiConstants.ACTION_TAKEN_SU_APPROVED_CD},
51 new String[]{KewApiConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,KewApiConstants.ACTION_TAKEN_ROUTED_CD,KewApiConstants.ACTION_TAKEN_SAVED_CD,KewApiConstants.ACTION_TAKEN_CANCELED_CD,ActionType.RECALL.getCode()});
52
53
54
55
56
57 networkId = "pmckown";
58 document = this.checkActions(networkId, documentId,
59 new String[]{},
60 new String[]{KewApiConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,KewApiConstants.ACTION_TAKEN_SU_CANCELED_CD,KewApiConstants.ACTION_TAKEN_SU_APPROVED_CD,KewApiConstants.ACTION_TAKEN_ROUTED_CD,KewApiConstants.ACTION_TAKEN_SAVED_CD,KewApiConstants.ACTION_TAKEN_CANCELED_CD,ActionType.RECALL.getCode()});
61
62
63
64
65
66 networkId = "user1";
67 document = this.checkActions(networkId, documentId,
68 new String[]{KewApiConstants.ACTION_TAKEN_ROUTED_CD,KewApiConstants.ACTION_TAKEN_SAVED_CD,KewApiConstants.ACTION_TAKEN_CANCELED_CD},
69 new String[]{KewApiConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,KewApiConstants.ACTION_TAKEN_SU_CANCELED_CD,KewApiConstants.ACTION_TAKEN_SU_APPROVED_CD,ActionType.RECALL.getCode()});
70
71
72
73
74 document.saveDocument("");
75
76 networkId = "rkirkend";
77 document = this.checkActions(networkId, documentId,
78 new String[]{KewApiConstants.ACTION_TAKEN_SU_CANCELED_CD,KewApiConstants.ACTION_TAKEN_SU_APPROVED_CD},
79 new String[]{KewApiConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,KewApiConstants.ACTION_TAKEN_ROUTED_CD,KewApiConstants.ACTION_TAKEN_SAVED_CD,KewApiConstants.ACTION_TAKEN_CANCELED_CD,ActionType.RECALL.getCode()});
80
81
82
83
84
85 networkId = "pmckown";
86 document = this.checkActions(networkId, documentId,
87 new String[]{},
88 new String[]{KewApiConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,KewApiConstants.ACTION_TAKEN_SU_CANCELED_CD,KewApiConstants.ACTION_TAKEN_SU_APPROVED_CD,KewApiConstants.ACTION_TAKEN_ROUTED_CD,KewApiConstants.ACTION_TAKEN_SAVED_CD,KewApiConstants.ACTION_TAKEN_CANCELED_CD,ActionType.RECALL.getCode()});
89
90
91
92
93
94 networkId = "user1";
95 document = this.checkActions(networkId, documentId,
96 new String[]{KewApiConstants.ACTION_TAKEN_ROUTED_CD,KewApiConstants.ACTION_TAKEN_SAVED_CD,KewApiConstants.ACTION_TAKEN_CANCELED_CD},
97 new String[]{KewApiConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,KewApiConstants.ACTION_TAKEN_SU_CANCELED_CD,KewApiConstants.ACTION_TAKEN_SU_APPROVED_CD,ActionType.RECALL.getCode()});
98
99
100
101
102 document.route("");
103 assertEquals("Document should be ENROUTE", DocumentStatus.ENROUTE, document.getStatus());
104
105 networkId = "user1";
106 document = this.checkActions(networkId, documentId,
107 new String[]{ActionType.RECALL.getCode()},
108 new String[]{KewApiConstants.ACTION_TAKEN_SAVED_CD,KewApiConstants.ACTION_TAKEN_ROUTED_CD,KewApiConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,KewApiConstants.ACTION_TAKEN_SU_CANCELED_CD,KewApiConstants.ACTION_TAKEN_SU_APPROVED_CD,KewApiConstants.ACTION_TAKEN_CANCELED_CD});
109
110
111
112
113
114 networkId = "rkirkend";
115 document = this.checkActions(networkId, documentId,
116 new String[]{KewApiConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,KewApiConstants.ACTION_TAKEN_SU_CANCELED_CD,KewApiConstants.ACTION_TAKEN_SU_APPROVED_CD,KewApiConstants.ACTION_TAKEN_APPROVED_CD},
117 new String[]{KewApiConstants.ACTION_TAKEN_SAVED_CD,KewApiConstants.ACTION_TAKEN_ROUTED_CD,ActionType.RECALL.getCode()});
118
119
120
121
122
123
124 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
125 document.approve("");
126
127
128 this.checkActions("user1", documentId, new String[]{}, new String[]{ActionType.RECALL.getCode()});
129
130 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("pmckown"), document.getDocumentId());
131 document.approve("");
132
133
134 this.checkActions("user1", documentId, new String[]{}, new String[]{ActionType.RECALL.getCode()});
135
136
137
138 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId());
139
140 document.acknowledge("");
141
142
143 this.checkActions("user1", documentId, new String[]{}, new String[]{ActionType.RECALL.getCode()});
144
145 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("temay"), document.getDocumentId());
146 document.acknowledge("");
147
148
149 this.checkActions("user1", documentId, new String[]{}, new String[]{ActionType.RECALL.getCode()});
150
151 }
152
153 private WorkflowDocument checkActions(String networkId,String documentId,String[] validActionsAllowed,String[] invalidActionsNotAllowed) throws Exception {
154 WorkflowDocument document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName(networkId), documentId);
155 org.kuali.rice.kew.api.action.ValidActions validActions = document.getValidActions();
156 Set<ActionType> validActionsSet = validActions.getValidActions();
157
158 for (int i = 0; i < validActionsAllowed.length; i++) {
159 String actionAllowed = validActionsAllowed[i];
160 if (!validActionsSet.contains(ActionType.fromCode(actionAllowed))) {
161 fail("Action '" + KewApiConstants.ACTION_TAKEN_CD.get(actionAllowed) + "' should be allowed for user " + networkId);
162 }
163 }
164
165 for (int j = 0; j < invalidActionsNotAllowed.length; j++) {
166 String actionDisallowed = invalidActionsNotAllowed[j];
167 if (validActionsSet.contains(actionDisallowed)) {
168 fail("Action '" + KewApiConstants.ACTION_TAKEN_CD.get(actionDisallowed) + "' should not be allowed for user " + networkId);
169 }
170 }
171
172 return document;
173 }
174 }