001 /** 002 * Copyright 2005-2011 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}); 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}); 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}); 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}); 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}); 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}); 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[]{}, 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}); 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 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("pmckown"), document.getDocumentId()); 128 document.approve(""); 129 130 // SHOULD NOW BE ONLY ACKNOWLEDGED 131 132 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId()); 133 // test for Processed Status on document 134 document.acknowledge(""); 135 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("temay"), document.getDocumentId()); 136 document.acknowledge(""); 137 } 138 139 private WorkflowDocument checkActions(String networkId,String documentId,String[] validActionsAllowed,String[] invalidActionsNotAllowed) throws Exception { 140 WorkflowDocument document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName(networkId), documentId); 141 org.kuali.rice.kew.api.action.ValidActions validActions = document.getValidActions(); 142 Set<ActionType> validActionsSet = validActions.getValidActions(); 143 144 for (int i = 0; i < validActionsAllowed.length; i++) { 145 String actionAllowed = validActionsAllowed[i]; 146 if (!validActionsSet.contains(ActionType.fromCode(actionAllowed))) { 147 fail("Action '" + KewApiConstants.ACTION_TAKEN_CD.get(actionAllowed) + "' should be allowed for user " + networkId); 148 } 149 } 150 151 for (int j = 0; j < invalidActionsNotAllowed.length; j++) { 152 String actionDisallowed = invalidActionsNotAllowed[j]; 153 if (validActionsSet.contains(actionDisallowed)) { 154 fail("Action '" + KewApiConstants.ACTION_TAKEN_CD.get(actionDisallowed) + "' should not be allowed for user " + networkId); 155 } 156 } 157 158 return document; 159 } 160 }