001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.actions;
018:
019: import java.util.Arrays;
020: import java.util.HashSet;
021: import java.util.Set;
022:
023: import org.junit.Ignore;
024: import org.junit.Test;
025: import org.kuali.workflow.test.WorkflowTestCase;
026:
027: import edu.iu.uis.eden.EdenConstants;
028: import edu.iu.uis.eden.clientapp.WorkflowDocument;
029: import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
030: import edu.iu.uis.eden.clientapp.vo.ValidActionsVO;
031:
032: public class ValidActionsTest extends WorkflowTestCase {
033:
034: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
035: .getLogger(ValidActionsTest.class);
036:
037: public static final String DOCUMENT_TYPE_NAME = "BlanketApproveSequentialTest";
038:
039: protected void loadTestData() throws Exception {
040: loadXmlFile("ActionsConfig.xml");
041: }
042:
043: @Ignore
044: @Test
045: public void testValidActions() throws Exception {
046: WorkflowDocument document = null;
047: String networkId = null;
048: document = new WorkflowDocument(new NetworkIdVO("user1"),
049: DOCUMENT_TYPE_NAME);
050: Long routeHeaderId = document.getRouteHeaderId();
051:
052: networkId = "rkirkend";
053: document = this .checkActions(networkId, routeHeaderId,
054: new String[] {
055: EdenConstants.ACTION_TAKEN_SU_CANCELED_CD,
056: EdenConstants.ACTION_TAKEN_SU_APPROVED_CD },
057: new String[] {
058: EdenConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,
059: EdenConstants.ACTION_TAKEN_ROUTED_CD,
060: EdenConstants.ACTION_TAKEN_SAVED_CD,
061: EdenConstants.ACTION_TAKEN_CANCELED_CD });
062: // check for super user action "c", "a"
063: // check for blanket approve "B"
064: // check for no route "O"
065: // check for no save "S"
066:
067: networkId = "pmckown";
068: document = this .checkActions(networkId, routeHeaderId,
069: new String[] {}, new String[] {
070: EdenConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,
071: EdenConstants.ACTION_TAKEN_SU_CANCELED_CD,
072: EdenConstants.ACTION_TAKEN_SU_APPROVED_CD,
073: EdenConstants.ACTION_TAKEN_ROUTED_CD,
074: EdenConstants.ACTION_TAKEN_SAVED_CD,
075: EdenConstants.ACTION_TAKEN_CANCELED_CD });
076: // check for no super user action "c", "a"
077: // check for blanket approve "B"
078: // check for no route "O"
079: // check for no save "S"
080:
081: networkId = "user1";
082: document = this .checkActions(networkId, routeHeaderId,
083: new String[] { EdenConstants.ACTION_TAKEN_ROUTED_CD,
084: EdenConstants.ACTION_TAKEN_SAVED_CD,
085: EdenConstants.ACTION_TAKEN_CANCELED_CD },
086: new String[] {
087: EdenConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,
088: EdenConstants.ACTION_TAKEN_SU_CANCELED_CD,
089: EdenConstants.ACTION_TAKEN_SU_APPROVED_CD });
090: // check for no blanket approve "B"
091: // check for no super user actions "c", "a"
092: // check for routable "O"
093: // check for savable "S"
094: document.saveDocument("");
095:
096: networkId = "rkirkend";
097: document = this .checkActions(networkId, routeHeaderId,
098: new String[] {
099: EdenConstants.ACTION_TAKEN_SU_CANCELED_CD,
100: EdenConstants.ACTION_TAKEN_SU_APPROVED_CD },
101: new String[] {
102: EdenConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,
103: EdenConstants.ACTION_TAKEN_ROUTED_CD,
104: EdenConstants.ACTION_TAKEN_SAVED_CD,
105: EdenConstants.ACTION_TAKEN_CANCELED_CD });
106: // check for super user action "c", "a"
107: // check for blanket approve "B"
108: // check for no route "O"
109: // check for no save "S"
110:
111: networkId = "pmckown";
112: document = this .checkActions(networkId, routeHeaderId,
113: new String[] {}, new String[] {
114: EdenConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,
115: EdenConstants.ACTION_TAKEN_SU_CANCELED_CD,
116: EdenConstants.ACTION_TAKEN_SU_APPROVED_CD,
117: EdenConstants.ACTION_TAKEN_ROUTED_CD,
118: EdenConstants.ACTION_TAKEN_SAVED_CD,
119: EdenConstants.ACTION_TAKEN_CANCELED_CD });
120: // check for no super user action "c", "a"
121: // check for blanket approve "B"
122: // check for no route "O"
123: // check for no save "S"
124:
125: networkId = "user1";
126: document = this .checkActions(networkId, routeHeaderId,
127: new String[] { EdenConstants.ACTION_TAKEN_ROUTED_CD,
128: EdenConstants.ACTION_TAKEN_SAVED_CD,
129: EdenConstants.ACTION_TAKEN_CANCELED_CD },
130: new String[] {
131: EdenConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,
132: EdenConstants.ACTION_TAKEN_SU_CANCELED_CD,
133: EdenConstants.ACTION_TAKEN_SU_APPROVED_CD });
134: // check for no blanket approve "B"
135: // check for no super user actions "c", "a"
136: // check for routable "O"
137: // check for savable "S"
138: document.routeDocument("");
139:
140: networkId = "user1";
141: document = this .checkActions(networkId, routeHeaderId,
142: new String[] { EdenConstants.ACTION_TAKEN_SAVED_CD },
143: new String[] { EdenConstants.ACTION_TAKEN_ROUTED_CD,
144: EdenConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,
145: EdenConstants.ACTION_TAKEN_SU_CANCELED_CD,
146: EdenConstants.ACTION_TAKEN_SU_APPROVED_CD,
147: EdenConstants.ACTION_TAKEN_CANCELED_CD });
148: // check for no blanket approve "B"
149: // check for no super user actions "c", "a"
150: // check for no routable "O"
151: // check for no savable "S"
152:
153: networkId = "rkirkend";
154: document = this .checkActions(networkId, routeHeaderId,
155: new String[] { EdenConstants.ACTION_TAKEN_SAVED_CD,
156: EdenConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,
157: EdenConstants.ACTION_TAKEN_SU_CANCELED_CD,
158: EdenConstants.ACTION_TAKEN_SU_APPROVED_CD,
159: EdenConstants.ACTION_TAKEN_APPROVED_CD },
160: new String[] { EdenConstants.ACTION_TAKEN_ROUTED_CD });
161: // check for super user action "c", "a"
162: // check for blanket approve "B"
163: // check for approve "A"
164: // check for no route "O"
165: // check for no save "S"
166:
167: document = new WorkflowDocument(new NetworkIdVO("bmcgough"),
168: document.getRouteHeaderId());
169: document.approve("");
170:
171: document = new WorkflowDocument(new NetworkIdVO("pmckown"),
172: document.getRouteHeaderId());
173: document.approve("");
174:
175: // SHOULD NOW BE ONLY ACKNOWLEDGED
176:
177: document = new WorkflowDocument(new NetworkIdVO("jhopf"),
178: document.getRouteHeaderId());
179: // test for Processed Status on document
180: document.acknowledge("");
181: document = new WorkflowDocument(new NetworkIdVO("temay"),
182: document.getRouteHeaderId());
183: document.acknowledge("");
184: }
185:
186: private WorkflowDocument checkActions(String networkId,
187: Long routeHeaderId, String[] validActionsAllowed,
188: String[] invalidActionsNotAllowed) throws Exception {
189: WorkflowDocument document = new WorkflowDocument(
190: new NetworkIdVO(networkId), routeHeaderId);
191: ValidActionsVO validActions = document.getRouteHeader()
192: .getValidActions();
193: Set validActionsSet = (validActions
194: .getValidActionCodesAllowed() != null) ? new HashSet(
195: Arrays
196: .asList(validActions
197: .getValidActionCodesAllowed()))
198: : new HashSet();
199:
200: for (int i = 0; i < validActionsAllowed.length; i++) {
201: String actionAllowed = validActionsAllowed[i];
202: if (!validActionsSet.contains(actionAllowed)) {
203: fail("Action '"
204: + EdenConstants.ACTION_TAKEN_CD
205: .get(actionAllowed)
206: + "' should be allowed for user " + networkId);
207: }
208: }
209:
210: for (int j = 0; j < invalidActionsNotAllowed.length; j++) {
211: String actionDisallowed = invalidActionsNotAllowed[j];
212: if (validActionsSet.contains(actionDisallowed)) {
213: fail("Action '"
214: + EdenConstants.ACTION_TAKEN_CD
215: .get(actionDisallowed)
216: + "' should not be allowed for user "
217: + networkId);
218: }
219: }
220:
221: return document;
222: }
223: }
|