View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    * http://www.opensource.org/licenses/ecl2.php
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.kuali.rice.kew.actions;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.fail;
21  
22  import java.util.Set;
23  
24  import org.junit.Test;
25  import org.kuali.rice.kew.api.WorkflowDocument;
26  import org.kuali.rice.kew.api.WorkflowDocumentFactory;
27  import org.kuali.rice.kew.api.action.ActionType;
28  import org.kuali.rice.kew.api.document.DocumentStatus;
29  import org.kuali.rice.kew.test.KEWTestCase;
30  import org.kuali.rice.kew.util.KEWConstants;
31  
32  
33  public class ValidActionsTest extends KEWTestCase {
34  
35  	private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ValidActionsTest.class);
36  
37      public static final String DOCUMENT_TYPE_NAME = "BlanketApproveSequentialTest";
38  
39      protected void loadTestData() throws Exception {
40          loadXmlFile("ActionsConfig.xml");
41      }
42  
43      @Test public void testValidActions() throws Exception {
44          WorkflowDocument document = null;
45          String networkId = null;
46          document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), DOCUMENT_TYPE_NAME);
47          String documentId = document.getDocumentId();
48  
49          networkId = "rkirkend";
50          document = this.checkActions(networkId, documentId, 
51                  new String[]{KEWConstants.ACTION_TAKEN_SU_CANCELED_CD,KEWConstants.ACTION_TAKEN_SU_APPROVED_CD}, 
52                  new String[]{KEWConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,KEWConstants.ACTION_TAKEN_ROUTED_CD,KEWConstants.ACTION_TAKEN_SAVED_CD,KEWConstants.ACTION_TAKEN_CANCELED_CD});
53          // check for super user action "c", "a"
54          // check for blanket approve "B"
55          // check for no route "O"
56          // check for no save "S"
57  
58          networkId = "pmckown";
59          document = this.checkActions(networkId, documentId, 
60                  new String[]{}, 
61                  new String[]{KEWConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,KEWConstants.ACTION_TAKEN_SU_CANCELED_CD,KEWConstants.ACTION_TAKEN_SU_APPROVED_CD,KEWConstants.ACTION_TAKEN_ROUTED_CD,KEWConstants.ACTION_TAKEN_SAVED_CD,KEWConstants.ACTION_TAKEN_CANCELED_CD});
62          // check for no super user action "c", "a"
63          // check for blanket approve "B"
64          // check for no route "O"
65          // check for no save "S"
66  
67          networkId = "user1";
68          document = this.checkActions(networkId, documentId, 
69                  new String[]{KEWConstants.ACTION_TAKEN_ROUTED_CD,KEWConstants.ACTION_TAKEN_SAVED_CD,KEWConstants.ACTION_TAKEN_CANCELED_CD}, 
70                  new String[]{KEWConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,KEWConstants.ACTION_TAKEN_SU_CANCELED_CD,KEWConstants.ACTION_TAKEN_SU_APPROVED_CD});
71          // check for no blanket approve "B"
72          // check for no super user actions "c", "a"
73          // check for routable "O"
74          // check for savable "S"
75          document.saveDocument("");
76  
77          networkId = "rkirkend";
78          document = this.checkActions(networkId, documentId, 
79                  new String[]{KEWConstants.ACTION_TAKEN_SU_CANCELED_CD,KEWConstants.ACTION_TAKEN_SU_APPROVED_CD}, 
80                  new String[]{KEWConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,KEWConstants.ACTION_TAKEN_ROUTED_CD,KEWConstants.ACTION_TAKEN_SAVED_CD,KEWConstants.ACTION_TAKEN_CANCELED_CD});
81          // check for super user action "c", "a"
82          // check for blanket approve "B"
83          // check for no route "O"
84          // check for no save "S"
85  
86          networkId = "pmckown";
87          document = this.checkActions(networkId, documentId, 
88                  new String[]{}, 
89                  new String[]{KEWConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,KEWConstants.ACTION_TAKEN_SU_CANCELED_CD,KEWConstants.ACTION_TAKEN_SU_APPROVED_CD,KEWConstants.ACTION_TAKEN_ROUTED_CD,KEWConstants.ACTION_TAKEN_SAVED_CD,KEWConstants.ACTION_TAKEN_CANCELED_CD});
90          // check for no super user action "c", "a"
91          // check for blanket approve "B"
92          // check for no route "O"
93          // check for no save "S"
94  
95          networkId = "user1";
96          document = this.checkActions(networkId, documentId, 
97                  new String[]{KEWConstants.ACTION_TAKEN_ROUTED_CD,KEWConstants.ACTION_TAKEN_SAVED_CD,KEWConstants.ACTION_TAKEN_CANCELED_CD}, 
98                  new String[]{KEWConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,KEWConstants.ACTION_TAKEN_SU_CANCELED_CD,KEWConstants.ACTION_TAKEN_SU_APPROVED_CD});
99          // check for no blanket approve "B"
100         // check for no super user actions "c", "a"
101         // check for routable "O"
102         // check for savable "S"
103         document.route("");
104         assertEquals("Document should be ENROUTE", DocumentStatus.ENROUTE, document.getStatus());
105 
106         networkId = "user1";
107         document = this.checkActions(networkId, documentId, 
108                 new String[]{}, 
109                 new String[]{KEWConstants.ACTION_TAKEN_SAVED_CD,KEWConstants.ACTION_TAKEN_ROUTED_CD,KEWConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,KEWConstants.ACTION_TAKEN_SU_CANCELED_CD,KEWConstants.ACTION_TAKEN_SU_APPROVED_CD,KEWConstants.ACTION_TAKEN_CANCELED_CD});
110         // check for no blanket approve "B"
111         // check for no super user actions "c", "a"
112         // check for no routable "O"
113         // check for no savable "S"
114 
115         networkId = "rkirkend";
116         document = this.checkActions(networkId, documentId, 
117                 new String[]{KEWConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,KEWConstants.ACTION_TAKEN_SU_CANCELED_CD,KEWConstants.ACTION_TAKEN_SU_APPROVED_CD,KEWConstants.ACTION_TAKEN_APPROVED_CD}, 
118                 new String[]{KEWConstants.ACTION_TAKEN_SAVED_CD,KEWConstants.ACTION_TAKEN_ROUTED_CD});
119         // check for super user action "c", "a"
120         // check for blanket approve "B"
121         // check for approve "A"
122         // check for no route "O"
123         // check for no save "S"
124 
125         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
126         document.approve("");
127 
128         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("pmckown"), document.getDocumentId());
129         document.approve("");
130 
131         // SHOULD NOW BE ONLY ACKNOWLEDGED
132 
133         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId());
134         // test for Processed Status on document
135         document.acknowledge("");
136         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("temay"), document.getDocumentId());
137         document.acknowledge("");
138     }
139 
140     private WorkflowDocument checkActions(String networkId,String documentId,String[] validActionsAllowed,String[] invalidActionsNotAllowed) throws Exception {
141         WorkflowDocument document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName(networkId), documentId);
142         org.kuali.rice.kew.api.action.ValidActions validActions = document.getValidActions();
143         Set<ActionType> validActionsSet = validActions.getValidActions();
144 
145         for (int i = 0; i < validActionsAllowed.length; i++) {
146             String actionAllowed = validActionsAllowed[i];
147             if (!validActionsSet.contains(ActionType.fromCode(actionAllowed))) {
148                 fail("Action '" + KEWConstants.ACTION_TAKEN_CD.get(actionAllowed) + "' should be allowed for user " + networkId);
149             }
150         }
151 
152         for (int j = 0; j < invalidActionsNotAllowed.length; j++) {
153             String actionDisallowed = invalidActionsNotAllowed[j];
154             if (validActionsSet.contains(actionDisallowed)) {
155                 fail("Action '" + KEWConstants.ACTION_TAKEN_CD.get(actionDisallowed) + "' should not be allowed for user " + networkId);
156             }
157         }
158 
159         return document;
160     }
161 }