001package org.kuali.rice.kew.engine; 002 003import org.junit.Test; 004import org.kuali.rice.kew.api.KewApiServiceLocator; 005import org.kuali.rice.kew.api.WorkflowDocument; 006import org.kuali.rice.kew.api.WorkflowDocumentFactory; 007import org.kuali.rice.kew.api.doctype.ProcessDefinition; 008import org.kuali.rice.kew.api.doctype.RoutePath; 009import org.kuali.rice.kew.api.document.DocumentStatus; 010import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange; 011import org.kuali.rice.kew.framework.postprocessor.ProcessDocReport; 012import org.kuali.rice.kew.postprocessor.DefaultPostProcessor; 013import org.kuali.rice.kew.test.KEWTestCase; 014 015import java.util.ArrayList; 016import java.util.List; 017 018import static org.junit.Assert.*; 019 020/** 021 * Integration test cases for documents with empty processes 022 */ 023public class EmptyProcessTest extends KEWTestCase { 024 025 private static final String DOCUMENT_TYPE_NAME = "EmptyProcessDocType"; 026 027 protected void loadTestData() throws Exception { 028 loadXmlFile("EngineConfig.xml"); 029 } 030 031 /** 032 * creates a new doc of the given type and routes it, asserting that it goes final 033 * @throws Exception 034 */ 035 @Test public void testEmptyProcess() throws Exception { 036 PostProcessor.clear(); 037 038 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), DOCUMENT_TYPE_NAME); 039 document.route("test"); 040 assertNotNull(document.getDocumentId()); 041 assertTrue(document.isFinal()); 042 043 // verify that the PostProcessor invoked the proper status transitions 044 // Initiated -> Enroute -> Processed -> Final 045 assertEquals(3, PostProcessor.statusChanges.size()); 046 DocumentRouteStatusChange iToR = PostProcessor.statusChanges.get(0); 047 DocumentRouteStatusChange rToP = PostProcessor.statusChanges.get(1); 048 DocumentRouteStatusChange pToF = PostProcessor.statusChanges.get(2); 049 assertEquals(DocumentStatus.INITIATED.getCode(), iToR.getOldRouteStatus()); 050 assertEquals(DocumentStatus.ENROUTE.getCode(), iToR.getNewRouteStatus()); 051 assertEquals(DocumentStatus.ENROUTE.getCode(), rToP.getOldRouteStatus()); 052 assertEquals(DocumentStatus.PROCESSED.getCode(), rToP.getNewRouteStatus()); 053 assertEquals(DocumentStatus.PROCESSED.getCode(), pToF.getOldRouteStatus()); 054 assertEquals(DocumentStatus.FINAL.getCode(), pToF.getNewRouteStatus()); 055 } 056 057 /** 058 * Tests scenario for KULRICE-7235: Document Type use of Null routePaths causes IllegalArgumentException: 059 * contract was null 060 * @throws Exception 061 */ 062 @Test public void testGetRoutePathForDocumentTypeName() throws Exception { 063 RoutePath routePath = 064 KewApiServiceLocator.getDocumentTypeService().getRoutePathForDocumentTypeName(DOCUMENT_TYPE_NAME); 065 assertNotNull(routePath); 066 ProcessDefinition processDefinition = routePath.getPrimaryProcess(); 067 assertNotNull(processDefinition); 068 assertNull("The initial route node *should* be null since this is an empty process", processDefinition.getInitialRouteNode()); 069 } 070 071 public static class PostProcessor extends DefaultPostProcessor { 072 073 private static List<DocumentRouteStatusChange> statusChanges = new ArrayList<DocumentRouteStatusChange>(); 074 075 public static void clear() { 076 statusChanges.clear(); 077 } 078 079 @Override 080 public ProcessDocReport doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) throws Exception { 081 statusChanges.add(statusChangeEvent); 082 return super.doRouteStatusChange(statusChangeEvent); 083 } 084 } 085 086}