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.xml.export;
018:
019: import java.io.BufferedInputStream;
020: import java.io.ByteArrayInputStream;
021: import java.util.HashSet;
022: import java.util.Iterator;
023: import java.util.List;
024: import java.util.Set;
025:
026: import org.junit.Test;
027:
028: import edu.iu.uis.eden.KEWServiceLocator;
029: import edu.iu.uis.eden.doctype.DocumentType;
030: import edu.iu.uis.eden.doctype.DocumentTypePolicy;
031: import edu.iu.uis.eden.engine.node.BranchPrototype;
032: import edu.iu.uis.eden.engine.node.Process;
033: import edu.iu.uis.eden.engine.node.RouteNode;
034: import edu.iu.uis.eden.export.ExportDataSet;
035: import edu.iu.uis.eden.export.ExportFormat;
036:
037: public class DocumentTypeXmlExporterTest extends XmlExporterTestCase {
038:
039: @Test
040: public void testExportDynamicProcessConfig() throws Exception {
041: loadXmlFile("DocTypeExportRuleTemplateConfig.xml");
042: loadXmlFile("DocTypeExportConfig.xml");
043: assertExport();
044: }
045:
046: protected void assertExport() throws Exception {
047: List documentTypes = KEWServiceLocator.getDocumentTypeService()
048: .findAllCurrent();
049: for (Iterator iterator = documentTypes.iterator(); iterator
050: .hasNext();) {
051: DocumentType existingDocType = (DocumentType) iterator
052: .next();
053: ExportDataSet dataSet = new ExportDataSet(ExportFormat.XML);
054: dataSet.getDocumentTypes().add(existingDocType);
055: byte[] xmlBytes = KEWServiceLocator.getXmlExporterService()
056: .export(ExportFormat.XML, dataSet);
057: assertTrue("XML should be non empty.", xmlBytes != null
058: && xmlBytes.length > 0);
059: loadXmlStream(new BufferedInputStream(
060: new ByteArrayInputStream(xmlBytes)));
061: DocumentType newDocType = KEWServiceLocator
062: .getDocumentTypeService().findByName(
063: existingDocType.getName());
064: assertDocTypeExport(existingDocType, newDocType);
065: }
066: }
067:
068: // TODO delyea - check this
069: private void assertDocTypeExport(DocumentType oldDocType,
070: DocumentType newDocType) {
071: // assert fields which should be different
072: assertFalse("Document type ids should be different.",
073: oldDocType.getDocumentTypeId().equals(
074: newDocType.getDocumentTypeId()));
075: assertTrue("Version should be one greater.", newDocType
076: .getVersion().intValue() == oldDocType.getVersion()
077: .intValue() + 1);
078: assertEquals("Previous version should be old doc type.",
079: oldDocType.getDocumentTypeId(), newDocType
080: .getPreviousVersionId());
081:
082: // assert fields which should be the same
083: assertEquals("Should have same name", oldDocType.getName(),
084: newDocType.getName());
085: if (oldDocType.getParentDocType() == null) {
086: assertNull("Should have same parent.", newDocType
087: .getParentDocType());
088: } else {
089: assertEquals("Should have same parent.", oldDocType
090: .getParentDocType().getName(), newDocType
091: .getParentDocType().getName());
092: }
093: assertEquals(oldDocType.getActiveInd(), newDocType
094: .getActiveInd());
095: assertEquals(oldDocType.getDescription(), newDocType
096: .getDescription());
097: assertEquals(oldDocType.getDocHandlerUrl(), newDocType
098: .getDocHandlerUrl());
099: assertEquals(oldDocType.getLabel(), newDocType.getLabel());
100: assertEquals(oldDocType.getPostProcessorName(), newDocType
101: .getPostProcessorName());
102: assertEquals(oldDocType.getRoutingVersion(), newDocType
103: .getRoutingVersion());
104: assertEquals(oldDocType.getBlanketApproveWorkgroup()
105: .getWorkflowGroupId(), newDocType
106: .getBlanketApproveWorkgroup().getWorkflowGroupId());
107: assertEquals(oldDocType.getBlanketApprovePolicy(), newDocType
108: .getBlanketApprovePolicy());
109: assertEquals(oldDocType.getCurrentInd(), newDocType
110: .getCurrentInd());
111: assertEquals(oldDocType.getSuperUserWorkgroup()
112: .getWorkflowGroupId(), newDocType
113: .getSuperUserWorkgroup().getWorkflowGroupId());
114: assertEquals(oldDocType.getNotificationFromAddress(),
115: newDocType.getNotificationFromAddress());
116: assertRoutePath(oldDocType, newDocType);
117: assertPolicies(oldDocType, newDocType);
118: }
119:
120: private void assertRoutePath(DocumentType oldDocType,
121: DocumentType newDocType) {
122: for (Iterator iterator = oldDocType.getProcesses().iterator(); iterator
123: .hasNext();) {
124: Process oldProcess = (Process) iterator.next();
125: Process newProcess = newDocType.getNamedProcess(oldProcess
126: .getName());
127: assertRouteNodes(oldProcess.getInitialRouteNode(),
128: newProcess.getInitialRouteNode(), new HashSet());
129: }
130: }
131:
132: private void assertRouteNodes(RouteNode oldNode, RouteNode newNode,
133: Set processedNodeIds) {
134: if (processedNodeIds.contains(oldNode.getRouteNodeId())) {
135: if (!processedNodeIds.contains(newNode.getRouteNodeId())) {
136: fail("If old node is processed, new node should also be processed.");
137: }
138: return;
139: }
140: assertEquals(oldNode.getRouteNodeName(), newNode
141: .getRouteNodeName());
142: assertEquals(oldNode.getActivationType(), newNode
143: .getActivationType());
144: assertEquals(oldNode.getExceptionWorkgroupId(), newNode
145: .getExceptionWorkgroupId());
146: assertEquals(oldNode.getNodeType(), newNode.getNodeType());
147: assertEquals(oldNode.getRouteMethodCode(), newNode
148: .getRouteMethodCode());
149: assertEquals(oldNode.getRouteMethodName(), newNode
150: .getRouteMethodName());
151: assertEquals(oldNode.getDocumentType().getName(), newNode
152: .getDocumentType().getName());
153: assertEquals(oldNode.getFinalApprovalInd(), newNode
154: .getFinalApprovalInd());
155: assertEquals(oldNode.getMandatoryRouteInd(), newNode
156: .getMandatoryRouteInd());
157: assertBranches(oldNode.getBranch(), newNode.getBranch());
158: assertEquals(oldNode.getNextNodes().size(), newNode
159: .getNextNodes().size());
160: processedNodeIds.add(oldNode.getRouteNodeId());
161: processedNodeIds.add(newNode.getRouteNodeId());
162: for (Iterator iterator = oldNode.getNextNodes().iterator(); iterator
163: .hasNext();) {
164: RouteNode nextOldNode = (RouteNode) iterator.next();
165: boolean foundNode = false;
166: for (Iterator iterator2 = newNode.getNextNodes().iterator(); iterator2
167: .hasNext();) {
168: RouteNode nextNewNode = (RouteNode) iterator2.next();
169: if (nextNewNode.getRouteNodeName().equals(
170: nextOldNode.getRouteNodeName())) {
171: foundNode = true;
172: assertRouteNodes(nextOldNode, nextNewNode,
173: processedNodeIds);
174: break;
175: }
176: }
177: assertTrue("Could not locate new node by name: "
178: + nextOldNode.getRouteNodeName(), foundNode);
179: }
180: }
181:
182: private void assertBranches(BranchPrototype oldBranch,
183: BranchPrototype newBranch) {
184: if (oldBranch == null) {
185: assertNull("New Branch should also be null.", newBranch);
186: } else {
187: assertEquals(oldBranch.getName(), newBranch.getName());
188: }
189: }
190:
191: private void assertPolicies(DocumentType oldDocType,
192: DocumentType newDocType) {
193: assertEquals(oldDocType.getPolicies().size(), newDocType
194: .getPolicies().size());
195: for (Iterator iterator = oldDocType.getPolicies().iterator(); iterator
196: .hasNext();) {
197: DocumentTypePolicy oldPolicy = (DocumentTypePolicy) iterator
198: .next();
199: boolean foundPolicy = false;
200: for (Iterator iterator2 = newDocType.getPolicies()
201: .iterator(); iterator2.hasNext();) {
202: DocumentTypePolicy newPolicy = (DocumentTypePolicy) iterator2
203: .next();
204: if (oldPolicy.getPolicyName().equals(
205: newPolicy.getPolicyName())) {
206: foundPolicy = true;
207: assertEquals(oldPolicy.getInheritedFlag(),
208: newPolicy.getInheritedFlag());
209: assertEquals(oldPolicy.getPolicyValue(), newPolicy
210: .getPolicyValue());
211: break;
212: }
213: }
214: assertTrue("Could not locate policy by name "
215: + oldPolicy.getPolicyName(), foundPolicy);
216: }
217: }
218:
219: }
|