001 /**
002 * Copyright 2005-2011 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kew.engine;
017
018 import static org.junit.Assert.assertEquals;
019 import static org.junit.Assert.assertNotNull;
020 import static org.junit.Assert.assertTrue;
021
022 import org.junit.Test;
023 import org.kuali.rice.kew.api.WorkflowDocument;
024 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
025 import org.kuali.rice.kew.test.KEWTestCase;
026 import org.kuali.rice.kew.api.KewApiConstants;
027
028 /**
029 * Tests a new document being spawned from the post processing of an existing document
030 *
031 * @author Kuali Rice Team (rice.collab@kuali.org)
032 *
033 */
034 public class PostProcessorSpawnedDocumentTest extends KEWTestCase {
035
036 private static final String DOCUMENT_TYPE_THAT_SPAWNS = "SpawnNewDocumentType";
037
038 protected void loadTestData() throws Exception {
039 loadXmlFile("PostProcessorSpawnedDocConfig.xml");
040 }
041
042 @Test public void testSpawnDocument() throws Exception {
043 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("jitrue"), DOCUMENT_TYPE_THAT_SPAWNS);
044 document.saveDocumentData();
045 assertNotNull(document.getDocumentId());
046 assertTrue("Document should be initiatied", document.isInitiated());
047 document.route("Route");
048
049 // should have generated a request to "bmcgough"
050 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
051 assertTrue("Document should be enroute", document.isEnroute());
052 assertEquals("Document should be enroute.", KewApiConstants.ROUTE_HEADER_ENROUTE_CD, document.getStatus().getCode());
053 assertTrue(document.isApprovalRequested());
054 document.approve("Test approve by bmcgough");
055
056 String originalDocumentId = document.getDocumentId();
057 Long originalDocumentIdLong = Long.parseLong(originalDocumentId.trim());
058 Long spawnedDocumentIdLong = (originalDocumentIdLong + 1);
059 String spawnedDocumentId = spawnedDocumentIdLong.toString();
060
061 // get spawned document (should be next document id)
062 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), spawnedDocumentId);
063 assertEquals("Document should be final.", KewApiConstants.ROUTE_HEADER_FINAL_CD, document.getStatus().getCode());
064
065 // get original document
066 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), originalDocumentId);
067 assertEquals("Document should be final.", KewApiConstants.ROUTE_HEADER_FINAL_CD, document.getStatus().getCode());
068 }
069 }