1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.actions;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.assertTrue;
22 import static org.junit.Assert.fail;
23
24 import java.util.Collection;
25
26 import org.junit.Test;
27 import org.kuali.rice.kew.actiontaken.ActionTakenValue;
28 import org.kuali.rice.kew.api.WorkflowDocument;
29 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
30 import org.kuali.rice.kew.api.action.InvalidActionTakenException;
31 import org.kuali.rice.kew.api.document.DocumentStatus;
32 import org.kuali.rice.kew.service.KEWServiceLocator;
33 import org.kuali.rice.kew.test.KEWTestCase;
34
35 public class RouteDocumentTest extends KEWTestCase {
36
37 public static final String DOCUMENT_TYPE_NAME = "BlanketApproveSequentialTest";
38 public static final String DOCUMENT_TYPE_POLICY_TEST_NAME = "BlanketApprovePolicyTest";
39
40 protected void loadTestData() throws Exception {
41 loadXmlFile("ActionsConfig.xml");
42 }
43
44
45
46
47 @Test public void testRouteAlreadyRoutedDocument() throws Exception {
48 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), DOCUMENT_TYPE_NAME);
49 document.route("");
50
51 assertTrue("Document should be ENROUTE.", document.isEnroute());
52 assertFalse("There should not be a request to ewestfal.", document.isApprovalRequested());
53
54
55 Collection<ActionTakenValue> actionTakens = KEWServiceLocator.getActionTakenService().findByDocumentId(document.getDocumentId());
56 assertEquals("There should be only 1 action taken.", 1, actionTakens.size());
57
58
59 try {
60 document.route("");
61 fail("A WorkflowException should have been thrown.");
62 } catch (InvalidActionTakenException e) {
63 e.printStackTrace();
64 }
65
66
67 actionTakens = KEWServiceLocator.getActionTakenService().findByDocumentId(document.getDocumentId());
68 assertEquals("There should still be only 1 action taken.", 1, actionTakens.size());
69 }
70
71
72
73
74 @Test public void testRouteDocumentAsNonInitiatorUser() throws Exception {
75 WorkflowDocument firstDocument = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), DOCUMENT_TYPE_POLICY_TEST_NAME);
76 WorkflowDocument document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("user2"), firstDocument.getDocumentId());
77 try {
78 document.route("");
79 } catch (Exception e) {
80 e.printStackTrace();
81 fail("Exception thrown but should not have have been... Exception was of type " + e.getClass().getName() + " and message was " + e.getMessage());
82 }
83 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("user1"), firstDocument.getDocumentId());
84 assertEquals("Document should be in Enroute status.", DocumentStatus.ENROUTE, document.getStatus());
85
86
87 Collection<ActionTakenValue> actionTakens = KEWServiceLocator.getActionTakenService().findByDocumentId(document.getDocumentId());
88 assertEquals("There should be 1 action taken.", 1, actionTakens.size());
89 }
90
91
92
93
94 @Test public void testRouteDefaultDocumentAsNonInitiatorUser() throws Exception {
95 WorkflowDocument firstDocument = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), DOCUMENT_TYPE_NAME);
96 WorkflowDocument document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("user2"), firstDocument.getDocumentId());
97 try {
98 document.route("");
99 fail("Exception should have been thrown.");
100 } catch (Exception e) {
101 e.printStackTrace();
102 }
103 assertFalse("Document should not be ENROUTE.", document.isEnroute());
104
105
106
107
108
109 }
110
111 }