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.clientapp;
018:
019: import org.junit.Ignore;
020: import org.junit.Test;
021: import org.kuali.workflow.test.WorkflowTestCase;
022:
023: import edu.iu.uis.eden.clientapp.vo.EmplIdVO;
024: import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
025: import edu.iu.uis.eden.clientapp.vo.RouteNodeInstanceVO;
026: import edu.iu.uis.eden.clientapp.vo.UserIdVO;
027: import edu.iu.uis.eden.clientapp.vo.UuIdVO;
028: import edu.iu.uis.eden.clientapp.vo.WorkflowIdVO;
029:
030: /**
031: * Place to test WorkflowDocument.
032: *
033: */
034: public class WorkflowDocumentTest extends WorkflowTestCase {
035:
036: protected void loadTestData() throws Exception {
037: loadXmlFile("ClientAppConfig.xml");
038: }
039:
040: @Test
041: public void testLoadNonExistentDocument() throws Exception {
042: WorkflowDocument document = new WorkflowDocument(
043: new NetworkIdVO("ewestfal"), new Long(123456789));
044: assertNull("RouteHeaderVO should be null.", document
045: .getRouteHeader());
046: }
047:
048: @Test
049: public void testWorkflowDocument() throws Exception {
050: WorkflowDocument document = new WorkflowDocument(
051: new NetworkIdVO("rkirkend"), "UnitTestDocument");
052: document.routeDocument("");
053:
054: document = new WorkflowDocument(new NetworkIdVO("ewestfal"),
055: document.getRouteHeaderId());
056: document.approve("");
057:
058: document = new WorkflowDocument(new NetworkIdVO("jhopf"),
059: document.getRouteHeaderId());
060: document.approve("");
061:
062: RouteNodeInstanceVO[] nodeInstances = document
063: .getRouteNodeInstances();
064: boolean containsInitiated = false;
065: boolean containsTemplate1 = false;
066: boolean containsTemplate2 = false;
067: for (int j = 0; j < nodeInstances.length; j++) {
068: RouteNodeInstanceVO routeNodeInstance = nodeInstances[j];
069: if (routeNodeInstance.getName().equals("Initiated")) {
070: containsInitiated = true;
071: } else if (routeNodeInstance.getName().equals("Template1")) {
072: containsTemplate1 = true;
073: } else if (routeNodeInstance.getName().equals("Template2")) {
074: containsTemplate2 = true;
075: }
076: }
077:
078: assertTrue("Should have gone through initiated node",
079: containsInitiated);
080: assertTrue("Should have gone through template1 node",
081: containsTemplate1);
082: assertTrue("Should have gone through template2 node",
083: containsTemplate2);
084: }
085:
086: /**
087: * Test that the document is being updated appropriately after a return to previous call
088: *
089: * @throws Exception
090: */
091: @Test
092: public void testReturnToPreviousCorrectlyUpdatingDocumentStatus()
093: throws Exception {
094:
095: WorkflowDocument document = new WorkflowDocument(
096: new NetworkIdVO("rkirkend"), "UnitTestDocument");
097: document.routeDocument("");
098:
099: document = new WorkflowDocument(new NetworkIdVO("ewestfal"),
100: document.getRouteHeaderId());
101: document.returnToPreviousNode("", "Initiated");
102:
103: assertFalse("ewestfal should no longer have approval status",
104: document.isApprovalRequested());
105: assertFalse(
106: "ewestfal should no long have blanket approve status",
107: document.isBlanketApproveCapable());
108:
109: //just for good measure
110: document = new WorkflowDocument(new NetworkIdVO("rkirkend"),
111: document.getRouteHeaderId());
112: assertTrue("rkirkend should now have an approve request",
113: document.isApprovalRequested());
114: }
115:
116: @Test
117: public void testGetPreviousRouteNodeNames() throws Exception {
118:
119: WorkflowDocument document = new WorkflowDocument(
120: new NetworkIdVO("rkirkend"), "UnitTestDocument");
121: document.routeDocument("");
122:
123: document = new WorkflowDocument(new NetworkIdVO("ewestfal"),
124: document.getRouteHeaderId());
125: document.approve("");
126:
127: document = new WorkflowDocument(new NetworkIdVO("jhopf"),
128: document.getRouteHeaderId());
129: String[] previousNodeNames = document.getPreviousNodeNames();
130: assertEquals("Should have 2 previous Node Names", 2,
131: previousNodeNames.length);
132: assertEquals("First node name should be last node visited",
133: "Template1", previousNodeNames[0]);
134: assertEquals("Last node name should be the first visisted",
135: "Initiated", previousNodeNames[1]);
136: String[] currentNodes = document.getNodeNames();
137: assertEquals("Should have 1 current node name", 1,
138: currentNodes.length);
139: assertEquals("Current node name incorrect", "Template2",
140: currentNodes[0]);
141: document.returnToPreviousNode("", "Template1");
142: previousNodeNames = document.getPreviousNodeNames();
143: assertEquals("Should have 1 previous Node Name", 1,
144: previousNodeNames.length);
145: assertEquals("Previous Node name incorrect", "Initiated",
146: previousNodeNames[0]);
147:
148: }
149:
150: @Test
151: public void testIsRouteCapable() throws Exception {
152:
153: WorkflowDocument doc = new WorkflowDocument(new NetworkIdVO(
154: "rkirkend"), "UnitTestDocument");
155:
156: verifyIsRouteCapable(false, new NetworkIdVO("ewestfal"), doc
157: .getRouteHeaderId());
158: verifyIsRouteCapable(false, new WorkflowIdVO("1"), doc
159: .getRouteHeaderId());
160: verifyIsRouteCapable(false, new UuIdVO("1"), doc
161: .getRouteHeaderId());
162: verifyIsRouteCapable(false, new EmplIdVO("1"), doc
163: .getRouteHeaderId());
164:
165: verifyIsRouteCapable(true, new NetworkIdVO("rkirkend"), doc
166: .getRouteHeaderId());
167: verifyIsRouteCapable(true, new WorkflowIdVO("2"), doc
168: .getRouteHeaderId());
169: verifyIsRouteCapable(true, new UuIdVO("2"), doc
170: .getRouteHeaderId());
171: verifyIsRouteCapable(true, new EmplIdVO("2"), doc
172: .getRouteHeaderId());
173: }
174:
175: private void verifyIsRouteCapable(boolean routeCapable,
176: UserIdVO userId, Long docId) throws Exception {
177: WorkflowDocument doc = new WorkflowDocument(userId, docId);
178: assertEquals(routeCapable, doc.isRouteCapable());
179: }
180:
181: }
|