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