View Javadoc
1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.engine;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertNotNull;
20  import static org.junit.Assert.assertTrue;
21  
22  import org.junit.Test;
23  import org.kuali.rice.kew.api.WorkflowDocument;
24  import org.kuali.rice.kew.api.WorkflowDocumentFactory;
25  import org.kuali.rice.kew.test.KEWTestCase;
26  import org.kuali.rice.kew.api.KewApiConstants;
27  
28  /**
29   * Tests a new document being spawned from the post processing of an existing document
30   * 
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   *
33   */
34  public class PostProcessorSpawnedDocumentTest extends KEWTestCase {
35  	
36  	private static final String DOCUMENT_TYPE_THAT_SPAWNS = "SpawnNewDocumentType";
37  
38      protected void loadTestData() throws Exception {
39          loadXmlFile("PostProcessorSpawnedDocConfig.xml");
40      }
41  
42      @Test public void testSpawnDocument() throws Exception {
43      	WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("jitrue"), DOCUMENT_TYPE_THAT_SPAWNS);
44      	document.saveDocumentData();
45      	assertNotNull(document.getDocumentId());
46      	assertTrue("Document should be initiatied", document.isInitiated());
47      	document.route("Route");
48  
49          // should have generated a request to "bmcgough"
50      	document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
51          assertTrue("Document should be enroute", document.isEnroute());
52          assertEquals("Document should be enroute.", KewApiConstants.ROUTE_HEADER_ENROUTE_CD, document.getStatus().getCode());
53          assertTrue(document.isApprovalRequested());
54          document.approve("Test approve by bmcgough");
55          
56          String originalDocumentId = document.getDocumentId();
57      	Long originalDocumentIdLong = Long.parseLong(originalDocumentId.trim());
58          Long spawnedDocumentIdLong = (originalDocumentIdLong + 1);
59          String spawnedDocumentId = spawnedDocumentIdLong.toString();
60          
61      	// get spawned document (should be next document id)
62      	document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), spawnedDocumentId);
63          assertEquals("Document should be final.", KewApiConstants.ROUTE_HEADER_FINAL_CD, document.getStatus().getCode());
64  
65      	// get original document
66          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), originalDocumentId);
67          assertEquals("Document should be final.", KewApiConstants.ROUTE_HEADER_FINAL_CD, document.getStatus().getCode());
68      }
69  }