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.Collection;
020: import java.util.Iterator;
021: import java.util.List;
022:
023: import org.junit.Test;
024: import org.kuali.workflow.test.WorkflowTestCase;
025:
026: import edu.iu.uis.eden.KEWServiceLocator;
027: import edu.iu.uis.eden.actionrequests.ActionRequestValue;
028: import edu.iu.uis.eden.actions.BlanketApproveTest.NotifySetup;
029: import edu.iu.uis.eden.clientapp.WorkflowDocument;
030: import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
031:
032: public class RoleTest extends WorkflowTestCase {
033:
034: protected void loadTestData() throws Exception {
035: loadXmlFile("ActionsConfig.xml");
036: }
037:
038: @Test
039: public void testRoleRequestGeneration() throws Exception {
040: WorkflowDocument document = new WorkflowDocument(
041: new NetworkIdVO("ewestfal"),
042: NotifySetup.DOCUMENT_TYPE_NAME);
043: document.routeDocument("");
044:
045: document = new WorkflowDocument(new NetworkIdVO("jhopf"),
046: document.getRouteHeaderId());
047: assertTrue("This user should have an approve request", document
048: .isApprovalRequested());
049: document.approve("");
050:
051: document = new WorkflowDocument(new NetworkIdVO("ewestfal"),
052: document.getRouteHeaderId());
053: assertTrue("This user should have an approve request", document
054: .isApprovalRequested());
055: document.approve("");//ewestfal had ignore previous rule
056:
057: document = new WorkflowDocument(new NetworkIdVO("rkirkend"),
058: document.getRouteHeaderId());
059: assertTrue("This user should have an approve request", document
060: .isApprovalRequested());
061: document.approve("");
062:
063: //this be the role delegate of jitrue
064: document = new WorkflowDocument(new NetworkIdVO("natjohns"),
065: document.getRouteHeaderId());
066: assertTrue("This user should have an approve request", document
067: .isApprovalRequested());
068: document.approve("");
069:
070: document = new WorkflowDocument(new NetworkIdVO("bmcgough"),
071: document.getRouteHeaderId());
072: document.approve("");
073:
074: document = new WorkflowDocument(new NetworkIdVO("xqi"),
075: document.getRouteHeaderId());
076: document.acknowledge("");
077:
078: assertTrue("Document should be final", document.stateIsFinal());
079:
080: List requests = KEWServiceLocator.getActionRequestService()
081: .findAllActionRequestsByRouteHeaderId(
082: document.getRouteHeaderId());
083: List rootRequests = KEWServiceLocator.getActionRequestService()
084: .getRootRequests(requests);
085:
086: //verify our requests have been made correctly
087: for (Iterator iter = rootRequests.iterator(); iter.hasNext();) {
088: ActionRequestValue request = (ActionRequestValue) iter
089: .next();
090: if (request.isRoleRequest()) {
091: //direct children should not be role requests
092: iterateChildrenRequests(request.getChildrenRequests(),
093: new String[] { "U", "W" }, request);
094: }
095: }
096: }
097:
098: private void iterateChildrenRequests(Collection childrenRequests,
099: String[] requestTypes, ActionRequestValue parentRequest) {
100: for (Iterator iter = childrenRequests.iterator(); iter
101: .hasNext();) {
102: ActionRequestValue request = (ActionRequestValue) iter
103: .next();
104: boolean matched = false;
105: for (int i = 0; i < requestTypes.length; i++) {
106: if (request.getRecipientTypeCd()
107: .equals(requestTypes[i])) {
108: matched = true;
109: }
110: }
111: if (!matched) {
112: fail("Didn't find request of types expected Recipient Type: "
113: + parentRequest.getRecipientTypeCd()
114: + " RoleName: "
115: + parentRequest.getRoleName()
116: + " Qualified Role Name:"
117: + parentRequest.getQualifiedRoleName()
118: + " RuleId: "
119: + parentRequest.getRuleBaseValuesId());
120: }
121: //if this is a role then it can't have a child role
122: if (request.isRoleRequest()) {
123: //direct children should not be role requests
124: iterateChildrenRequests(request.getChildrenRequests(),
125: new String[] { "U", "W" }, request);
126: }
127: }
128: }
129: }
|