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 org.junit.Test;
19 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
20 import org.kuali.rice.kew.api.KewApiServiceLocator;
21 import org.kuali.rice.kew.api.WorkflowDocument;
22 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
23 import org.kuali.rice.kew.api.action.MovePoint;
24 import org.kuali.rice.kew.api.document.node.RouteNodeInstance;
25 import org.kuali.rice.kew.api.document.WorkflowDocumentService;
26 import org.kuali.rice.kew.service.KEWServiceLocator;
27 import org.kuali.rice.kew.test.KEWTestCase;
28 import org.kuali.rice.kew.test.TestUtilities;
29
30 import java.util.List;
31 import java.util.Set;
32
33 import static org.junit.Assert.*;
34
35 public class MoveDocumentTest extends KEWTestCase {
36
37 protected void loadTestData() throws Exception {
38 loadXmlFile("ActionsConfig.xml");
39 }
40
41
42
43
44
45 @Test public void testMoveDocumentSequential() throws Exception {
46 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), SeqSetup.DOCUMENT_TYPE_NAME);
47 document.route("");
48
49 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
50 assertTrue("Bmcgough should have an approve.", document.isApprovalRequested());
51 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
52 assertTrue("Rkirkend should have an approve.", document.isApprovalRequested());
53 assertEquals("Should be at the WorkflowDocument Node.", SeqSetup.WORKFLOW_DOCUMENT_NODE, document.getNodeNames().iterator().next());
54
55
56 document.move(MovePoint.create(SeqSetup.WORKFLOW_DOCUMENT_NODE, 1), "");
57
58 List actionRequests = KEWServiceLocator.getActionRequestService().findPendingByDoc(document.getDocumentId());
59 assertEquals("Should be only 1 pending approve request to pmckown.", 1, actionRequests.size());
60 assertEquals("Should be at the WorkflowDocument2 Node.", SeqSetup.WORKFLOW_DOCUMENT_2_NODE, document.getNodeNames().iterator().next());
61
62
63 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
64 assertFalse("Bmcgough should NOT have an approve.", document.isApprovalRequested());
65 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
66 assertFalse("Rkirkend should NOT have an approve.", document.isApprovalRequested());
67
68 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("pmckown"), document.getDocumentId());
69 assertTrue("Pmckown should have an approve.", document.isApprovalRequested());
70 ActionRequestValue pmckownRequest = (ActionRequestValue)actionRequests.get(0);
71
72
73 document.move(MovePoint.create(SeqSetup.WORKFLOW_DOCUMENT_2_NODE, 0), "");
74 assertTrue("Pmckown should still have an approve.", document.isApprovalRequested());
75 actionRequests = KEWServiceLocator.getActionRequestService().findPendingByDoc(document.getDocumentId());
76 assertEquals("Should be only 1 pending approve request to pmckown.", 1, actionRequests.size());
77 assertEquals("Should be at the WorkflowDocument2 Node.", SeqSetup.WORKFLOW_DOCUMENT_2_NODE, document.getNodeNames().iterator().next());
78
79
80 assertFalse("Action request ids should be different.", pmckownRequest.getActionRequestId().equals(((ActionRequestValue)actionRequests.get(0)).getActionRequestId()));
81
82
83 document.move(MovePoint.create(SeqSetup.WORKFLOW_DOCUMENT_2_NODE, -1), "");
84
85
86 actionRequests = KEWServiceLocator.getActionRequestService().findPendingByDoc(document.getDocumentId());
87 assertEquals("Should be 2 pending requests.", 2, actionRequests.size());
88
89 assertEquals("Should be at the WorkflowDocument Node.", SeqSetup.WORKFLOW_DOCUMENT_NODE, document.getNodeNames().iterator().next());
90 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
91 assertTrue("Bmcgough should have an approve.", document.isApprovalRequested());
92 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
93 assertTrue("Rkirkend should have an approve.", document.isApprovalRequested());
94
95
96
97
98 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("xqi"), document.getDocumentId());
99 assertTrue("Doc should be ENROUTE.", document.isEnroute());
100 document.move(MovePoint.create(SeqSetup.WORKFLOW_DOCUMENT_NODE, 2), "");
101 assertTrue("Doc should be PROCESSED.", document.isProcessed());
102 }
103
104
105
106
107 @Test public void testMoveDocumentInsideProcess() throws Exception {
108 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), "MoveInProcessTest");
109 document.route("");
110
111
112 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
113 assertTrue("bmcgough should have approve", document.isApprovalRequested());
114 document.approve("");
115 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
116 assertTrue("rkirkend should have approve", document.isApprovalRequested());
117 document.approve("");
118
119 WorkflowDocumentService workflowDocumentService = KewApiServiceLocator.getWorkflowDocumentService();
120 List<RouteNodeInstance> activeNodeInstances = workflowDocumentService.getActiveRouteNodeInstances(document.getDocumentId());
121 assertEquals("Should be 1 active node instance.", 1, activeNodeInstances.size());
122 RouteNodeInstance node2 = activeNodeInstances.get(0);
123 assertEquals("Should be at the WorkflowDocument2 node.", SeqSetup.WORKFLOW_DOCUMENT_2_NODE, node2.getName());
124 assertTrue("Node should be in a process.", node2.getProcessId() != null);
125
126
127 document.move(MovePoint.create(SeqSetup.WORKFLOW_DOCUMENT_2_NODE, 1), "");
128
129 activeNodeInstances = workflowDocumentService.getActiveRouteNodeInstances(document.getDocumentId());
130 RouteNodeInstance node3 = activeNodeInstances.get(0);
131 assertEquals("Should be at the WorkflowDocument3 node.", SeqSetup.WORKFLOW_DOCUMENT_3_NODE, node3.getName());
132 assertTrue("Node should be in a process.", node3.getProcessId() != null);
133 assertEquals("Node 2 and 3 should be in the same process.", node2.getProcessId(), node3.getProcessId());
134
135 document.move(MovePoint.create(SeqSetup.WORKFLOW_DOCUMENT_3_NODE, 0), "");
136
137 document.move(MovePoint.create(SeqSetup.WORKFLOW_DOCUMENT_3_NODE, -1), "");
138 }
139
140 @Test public void testMoveDocumentParallel() throws Exception {
141 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), ParallelSetup.DOCUMENT_TYPE_NAME);
142 document.blanketApprove("", new String[] { ParallelSetup.WORKFLOW_DOCUMENT_2_B2_NODE, ParallelSetup.WORKFLOW_DOCUMENT_3_B1_NODE, ParallelSetup.WORKFLOW_DOCUMENT_4_B3_NODE });
143 Set nodeNames = TestUtilities.createNodeInstanceNameSet(KEWServiceLocator.getRouteNodeService().getActiveNodeInstances(document.getDocumentId()));
144 assertEquals("There should be 3 active nodes.", 3, nodeNames.size());
145 assertTrue("Should be at WorkflowDocument3-B1", nodeNames.contains(ParallelSetup.WORKFLOW_DOCUMENT_3_B1_NODE));
146 assertTrue("Should be at WorkflowDocument2-B2", nodeNames.contains(ParallelSetup.WORKFLOW_DOCUMENT_2_B2_NODE));
147 assertTrue("Should be at WorkflowDocument4-B3", nodeNames.contains(ParallelSetup.WORKFLOW_DOCUMENT_4_B3_NODE));
148
149
150 document.move(MovePoint.create(ParallelSetup.WORKFLOW_DOCUMENT_3_B1_NODE, -1), "");
151 nodeNames = TestUtilities.createNodeInstanceNameSet(KEWServiceLocator.getRouteNodeService().getActiveNodeInstances(document.getDocumentId()));
152 assertEquals("There should be 3 active nodes.", 3, nodeNames.size());
153 assertTrue("Should be at WorkflowDocument2-B1", nodeNames.contains(ParallelSetup.WORKFLOW_DOCUMENT_2_B1_NODE));
154 assertTrue("Should be at WorkflowDocument2-B2", nodeNames.contains(ParallelSetup.WORKFLOW_DOCUMENT_2_B2_NODE));
155 assertTrue("Should be at WorkflowDocument4-B3", nodeNames.contains(ParallelSetup.WORKFLOW_DOCUMENT_4_B3_NODE));
156 }
157
158 private class SeqSetup {
159
160 public static final String DOCUMENT_TYPE_NAME = "MoveSequentialTest";
161 public static final String ADHOC_NODE = "AdHoc";
162 public static final String WORKFLOW_DOCUMENT_NODE = "WorkflowDocument";
163 public static final String WORKFLOW_DOCUMENT_2_NODE = "WorkflowDocument2";
164 public static final String WORKFLOW_DOCUMENT_3_NODE = "WorkflowDocument3";
165 public static final String ACKNOWLEDGE_1_NODE = "Acknowledge1";
166 public static final String ACKNOWLEDGE_2_NODE = "Acknowledge2";
167
168 }
169
170 private class ParallelSetup {
171
172 public static final String DOCUMENT_TYPE_NAME = "BlanketApproveParallelTest";
173 public static final String ADHOC_NODE = "AdHoc";
174 public static final String WORKFLOW_DOCUMENT_NODE = "WorkflowDocument";
175 public static final String WORKFLOW_DOCUMENT_2_B1_NODE = "WorkflowDocument2-B1";
176 public static final String WORKFLOW_DOCUMENT_2_B2_NODE = "WorkflowDocument2-B2";
177 public static final String WORKFLOW_DOCUMENT_3_B1_NODE = "WorkflowDocument3-B1";
178 public static final String WORKFLOW_DOCUMENT_3_B2_NODE = "WorkflowDocument3-B2";
179 public static final String WORKFLOW_DOCUMENT_4_B3_NODE = "WorkflowDocument4-B3";
180 public static final String ACKNOWLEDGE_1_NODE = "Acknowledge1";
181 public static final String ACKNOWLEDGE_2_NODE = "Acknowledge2";
182 public static final String JOIN_NODE = "Join";
183 public static final String SPLIT_NODE = "Split";
184 public static final String WORKFLOW_DOCUMENT_FINAL_NODE = "WorkflowDocumentFinal";
185
186 }
187
188 }