001 /**
002 * Copyright 2005-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kew.actions;
017
018 import static org.junit.Assert.assertEquals;
019 import static org.junit.Assert.fail;
020
021 import java.util.Set;
022
023 import org.junit.Test;
024 import org.kuali.rice.kew.api.WorkflowDocument;
025 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
026 import org.kuali.rice.kew.api.action.ActionType;
027 import org.kuali.rice.kew.api.document.DocumentStatus;
028 import org.kuali.rice.kew.test.KEWTestCase;
029 import org.kuali.rice.kew.api.KewApiConstants;
030
031
032 public class ValidActionsTest extends KEWTestCase {
033
034 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ValidActionsTest.class);
035
036 public static final String DOCUMENT_TYPE_NAME = "BlanketApproveSequentialTest";
037
038 protected void loadTestData() throws Exception {
039 loadXmlFile("ActionsConfig.xml");
040 }
041
042 @Test public void testValidActions() throws Exception {
043 WorkflowDocument document = null;
044 String networkId = null;
045 document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), DOCUMENT_TYPE_NAME);
046 String documentId = document.getDocumentId();
047
048 networkId = "rkirkend";
049 document = this.checkActions(networkId, documentId,
050 new String[]{KewApiConstants.ACTION_TAKEN_SU_CANCELED_CD,KewApiConstants.ACTION_TAKEN_SU_APPROVED_CD},
051 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()});
052 // check for super user action "c", "a"
053 // check for blanket approve "B"
054 // check for no route "O"
055 // check for no save "S"
056
057 networkId = "pmckown";
058 document = this.checkActions(networkId, documentId,
059 new String[]{},
060 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()});
061 // check for no super user action "c", "a"
062 // check for blanket approve "B"
063 // check for no route "O"
064 // check for no save "S"
065
066 networkId = "user1";
067 document = this.checkActions(networkId, documentId,
068 new String[]{KewApiConstants.ACTION_TAKEN_ROUTED_CD,KewApiConstants.ACTION_TAKEN_SAVED_CD,KewApiConstants.ACTION_TAKEN_CANCELED_CD},
069 new String[]{KewApiConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,KewApiConstants.ACTION_TAKEN_SU_CANCELED_CD,KewApiConstants.ACTION_TAKEN_SU_APPROVED_CD,ActionType.RECALL.getCode()});
070 // check for no blanket approve "B"
071 // check for no super user actions "c", "a"
072 // check for routable "O"
073 // check for savable "S"
074 document.saveDocument("");
075
076 networkId = "rkirkend";
077 document = this.checkActions(networkId, documentId,
078 new String[]{KewApiConstants.ACTION_TAKEN_SU_CANCELED_CD,KewApiConstants.ACTION_TAKEN_SU_APPROVED_CD},
079 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()});
080 // check for super user action "c", "a"
081 // check for blanket approve "B"
082 // check for no route "O"
083 // check for no save "S"
084
085 networkId = "pmckown";
086 document = this.checkActions(networkId, documentId,
087 new String[]{},
088 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()});
089 // check for no super user action "c", "a"
090 // check for blanket approve "B"
091 // check for no route "O"
092 // check for no save "S"
093
094 networkId = "user1";
095 document = this.checkActions(networkId, documentId,
096 new String[]{KewApiConstants.ACTION_TAKEN_ROUTED_CD,KewApiConstants.ACTION_TAKEN_SAVED_CD,KewApiConstants.ACTION_TAKEN_CANCELED_CD},
097 new String[]{KewApiConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,KewApiConstants.ACTION_TAKEN_SU_CANCELED_CD,KewApiConstants.ACTION_TAKEN_SU_APPROVED_CD,ActionType.RECALL.getCode()});
098 // check for no blanket approve "B"
099 // 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 }