1 package org.kuali.rice.kew.engine;
2
3 import org.junit.Test;
4 import org.kuali.rice.kew.api.KewApiServiceLocator;
5 import org.kuali.rice.kew.api.WorkflowDocument;
6 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
7 import org.kuali.rice.kew.api.doctype.ProcessDefinition;
8 import org.kuali.rice.kew.api.doctype.RoutePath;
9 import org.kuali.rice.kew.api.document.DocumentStatus;
10 import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
11 import org.kuali.rice.kew.framework.postprocessor.ProcessDocReport;
12 import org.kuali.rice.kew.postprocessor.DefaultPostProcessor;
13 import org.kuali.rice.kew.test.KEWTestCase;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import static org.junit.Assert.*;
19
20
21
22
23 public class EmptyProcessTest extends KEWTestCase {
24
25 private static final String DOCUMENT_TYPE_NAME = "EmptyProcessDocType";
26
27 protected void loadTestData() throws Exception {
28 loadXmlFile("EngineConfig.xml");
29 }
30
31
32
33
34
35 @Test public void testEmptyProcess() throws Exception {
36 PostProcessor.clear();
37
38 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), DOCUMENT_TYPE_NAME);
39 document.route("test");
40 assertNotNull(document.getDocumentId());
41 assertTrue(document.isFinal());
42
43
44
45 assertEquals(3, PostProcessor.statusChanges.size());
46 DocumentRouteStatusChange iToR = PostProcessor.statusChanges.get(0);
47 DocumentRouteStatusChange rToP = PostProcessor.statusChanges.get(1);
48 DocumentRouteStatusChange pToF = PostProcessor.statusChanges.get(2);
49 assertEquals(DocumentStatus.INITIATED.getCode(), iToR.getOldRouteStatus());
50 assertEquals(DocumentStatus.ENROUTE.getCode(), iToR.getNewRouteStatus());
51 assertEquals(DocumentStatus.ENROUTE.getCode(), rToP.getOldRouteStatus());
52 assertEquals(DocumentStatus.PROCESSED.getCode(), rToP.getNewRouteStatus());
53 assertEquals(DocumentStatus.PROCESSED.getCode(), pToF.getOldRouteStatus());
54 assertEquals(DocumentStatus.FINAL.getCode(), pToF.getNewRouteStatus());
55 }
56
57
58
59
60
61
62 @Test public void testGetRoutePathForDocumentTypeName() throws Exception {
63 RoutePath routePath =
64 KewApiServiceLocator.getDocumentTypeService().getRoutePathForDocumentTypeName(DOCUMENT_TYPE_NAME);
65 assertNotNull(routePath);
66 ProcessDefinition processDefinition = routePath.getPrimaryProcess();
67 assertNotNull(processDefinition);
68 assertNull("The initial route node *should* be null since this is an empty process", processDefinition.getInitialRouteNode());
69 }
70
71 public static class PostProcessor extends DefaultPostProcessor {
72
73 private static List<DocumentRouteStatusChange> statusChanges = new ArrayList<DocumentRouteStatusChange>();
74
75 public static void clear() {
76 statusChanges.clear();
77 }
78
79 @Override
80 public ProcessDocReport doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) throws Exception {
81 statusChanges.add(statusChangeEvent);
82 return super.doRouteStatusChange(statusChangeEvent);
83 }
84 }
85
86 }