View Javadoc
1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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          // check for super user action "c", "a"
53          // check for blanket approve "B"
54          // check for no route "O"
55          // check for no save "S"
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          // check for no super user action "c", "a"
62          // check for blanket approve "B"
63          // check for no route "O"
64          // check for no save "S"
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          // check for no blanket approve "B"
71          // check for no super user actions "c", "a"
72          // check for routable "O"
73          // check for savable "S"
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          // check for super user action "c", "a"
81          // check for blanket approve "B"
82          // check for no route "O"
83          // check for no save "S"
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          // check for no super user action "c", "a"
90          // check for blanket approve "B"
91          // check for no route "O"
92          // check for no save "S"
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          // check for no blanket approve "B"
99          // check for no super user actions "c", "a"
100         // check for routable "O"
101         // check for savable "S"
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         // check for no blanket approve "B"
110         // check for no super user actions "c", "a"
111         // check for no routable "O"
112         // check for no savable "S"
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         // check for super user action "c", "a"
119         // check for blanket approve "B"
120         // check for approve "A"
121         // check for no route "O"
122         // check for no save "S"
123 
124         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
125         document.approve("");
126 
127         // an action has been taken, initiator can no longer recall!
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         // an action has been taken, initiator can no longer recall
134         this.checkActions("user1", documentId, new String[]{}, new String[]{ActionType.RECALL.getCode()});
135 
136         // SHOULD NOW BE ONLY ACKNOWLEDGED
137 
138         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId());
139         // test for Processed Status on document
140         document.acknowledge("");
141 
142         // an action has been taken, initiator can no longer recall
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         // an action has been taken, initiator can no longer recall
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 }