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: // Created on Aug 24, 2006
018: package edu.iu.uis.eden.actions;
019:
020: import org.junit.Test;
021: import org.kuali.workflow.test.WorkflowTestCase;
022:
023: import edu.iu.uis.eden.clientapp.WorkflowDocument;
024: import edu.iu.uis.eden.clientapp.vo.ActionRequestVO;
025: import edu.iu.uis.eden.clientapp.vo.ActionTakenVO;
026: import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
027: import edu.iu.uis.eden.engine.node.Branch;
028: import edu.iu.uis.eden.engine.node.BranchState;
029: import edu.iu.uis.eden.exception.WorkflowException;
030:
031: /**
032: * Test case that tests setting and getting variables, both programmatically
033: * and via the "SetVar" node; stolen directly from ApproveActionTest.testPreapprovals
034: * @author Aaron Hamid (arh14 at cornell dot edu)
035: */
036: public class VariablesTestCase extends WorkflowTestCase {
037:
038: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
039: .getLogger(VariablesTestCase.class);
040:
041: protected void loadTestData() throws Exception {
042: loadXmlFile("ActionsConfig.xml");
043: }
044:
045: private void dumpInfoAboutDoc(WorkflowDocument doc)
046: throws WorkflowException {
047: LOG.info("\tDoc: class=" + doc.getDocumentType() + " title="
048: + doc.getTitle() + " status="
049: + doc.getStatusDisplayValue());
050: LOG.info("\tActionRequests:");
051: for (ActionRequestVO ar : doc.getActionRequests()) {
052: LOG.info("\t\tId: "
053: + ar.getActionRequestId()
054: + " UserId: "
055: + ar.getUserIdVO()
056: + " User: "
057: + (ar.getUserVO() != null ? ar.getUserVO()
058: .getDisplayName() : null)
059: + " ActionRequested: "
060: + ar.getActionRequested()
061: + " ActionTaken: "
062: + (ar.getActionTaken() != null ? ar
063: .getActionTaken().getActionTaken() : null)
064: + " NodeName: " + ar.getNodeName() + " Status:"
065: + ar.getStatus());
066: }
067: LOG.info("\tActionTakens:");
068: for (ActionTakenVO at : doc.getActionsTaken()) {
069: LOG.info("\t\tId: "
070: + at.getActionTakenId()
071: + " User: "
072: + (at.getUserVO() != null ? at.getUserVO()
073: .getDisplayName() : null)
074: + " ActionTaken: " + at.getActionTaken());
075: }
076: LOG.info("\tNodeNames:");
077: for (String name : doc.getNodeNames()) {
078: LOG.info("\t\t" + name);
079: }
080: }
081:
082: public void dumpBranch(Branch b) {
083: LOG.info("Branch: " + b.getBranchId() + " " + b.getName());
084: for (BranchState bs : b.getBranchState()) {
085: LOG.info(bs.getBranchStateId() + " " + bs.getKey() + " "
086: + bs.getValue());
087: }
088: }
089:
090: @Test
091: public void testVariables() throws Exception {
092: WorkflowDocument doc = new WorkflowDocument(new NetworkIdVO(
093: "rkirkend"), "VariablesTest");
094: doc.routeDocument("");
095:
096: //rock some preapprovals and other actions...
097: doc = new WorkflowDocument(new NetworkIdVO("ewestfal"), doc
098: .getRouteHeaderId());
099: dumpInfoAboutDoc(doc);
100: doc.setVariable("myexcellentvariable", "righton");
101: doc.approve("");
102: assertEquals("startedVariableValue", doc.getVariable("started"));
103: assertEquals("startedVariableValue", doc
104: .getVariable("copiedVar"));
105:
106: doc = new WorkflowDocument(new NetworkIdVO("user2"), doc
107: .getRouteHeaderId());
108: assertEquals("righton", doc.getVariable("myexcellentvariable"));
109: doc.setVariable("vartwo", "two");
110: doc.setVariable("myexcellentvariable", "ichangedit");
111: doc.acknowledge("");
112:
113: doc = new WorkflowDocument(new NetworkIdVO("user3"), doc
114: .getRouteHeaderId());
115: assertEquals("ichangedit", doc
116: .getVariable("myexcellentvariable"));
117: assertEquals("two", doc.getVariable("vartwo"));
118: doc.setVariable("another", "another");
119: doc.setVariable("vartwo", null);
120: doc.complete("");
121:
122: //approve as the person the doc is routed to so we can move the documen on and hopefully to final
123: doc = new WorkflowDocument(new NetworkIdVO("user1"), doc
124: .getRouteHeaderId());
125: assertEquals("ichangedit", doc
126: .getVariable("myexcellentvariable"));
127: assertEquals(null, doc.getVariable("vartwo"));
128: assertEquals("another", doc.getVariable("another"));
129: doc.approve("");
130:
131: assertEquals("endedVariableValue", doc.getVariable("ended"));
132: assertNotNull(doc.getVariable("google"));
133: LOG.info(doc.getVariable("google"));
134: assertEquals("documentContentendedVariableValue", doc
135: .getVariable("xpath"));
136: LOG.info(doc.getVariable("xpath"));
137:
138: assertEquals("aNewStartedVariableValue", doc
139: .getVariable("started"));
140:
141: assertTrue("the document should be final", doc.stateIsFinal());
142: }
143: }
|