1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.actionrequest;
17
18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.assertTrue;
22
23 import java.util.HashSet;
24 import java.util.List;
25 import java.util.Set;
26
27 import org.junit.Test;
28 import org.kuali.rice.kew.api.document.DocumentRefreshQueue;
29 import org.kuali.rice.kew.api.WorkflowDocument;
30 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
31 import org.kuali.rice.kew.api.action.ActionRequest;
32 import org.kuali.rice.kew.messaging.MessageServiceNames;
33 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
34 import org.kuali.rice.kew.service.KEWServiceLocator;
35 import org.kuali.rice.kew.test.KEWTestCase;
36
37
38
39
40
41
42 public class DocumentRefreshQueueTest extends KEWTestCase {
43
44 protected void loadTestData() throws Exception {
45 loadXmlFile("ActionRequestsConfig.xml");
46 }
47
48 @Test public void testDocumentRequeueSingleNode() throws Exception {
49 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), SeqSetup.DOCUMENT_TYPE_NAME);
50 document.route("");
51 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
52 assertTrue(document.isEnroute());
53 List<ActionRequest> requests = document.getRootActionRequests();
54 assertEquals("Should be 2 requests.", 2, requests.size());
55
56
57 Set<String> requestIds = new HashSet<String>();
58 for (ActionRequest request : requests) {
59 requestIds.add(request.getId());
60 }
61
62 DocumentRouteHeaderValue documentH = KEWServiceLocator.getRouteHeaderService().getRouteHeader(document.getDocumentId());
63 DocumentRefreshQueue documentRequeuer = MessageServiceNames.getDocumentRequeuerService(documentH.getDocumentType().getApplicationId(), documentH.getDocumentId(), 0);
64 documentRequeuer.refreshDocument(document.getDocumentId());
65
66 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
67 assertTrue(document.isEnroute());
68 requests = document.getRootActionRequests();
69 assertEquals("Should be 2 requests.", 2, requests.size());
70 for (ActionRequest requestVO : requests) {
71 assertTrue("Request ids should be different.", !requestIds.contains(requestVO.getId()));
72 }
73 assertTrue(document.isApprovalRequested());
74 document.approve("");
75
76
77
78 documentRequeuer.refreshDocument(document.getDocumentId());
79 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
80 assertTrue(document.isEnroute());
81 requests = document.getRootActionRequests();
82 assertEquals("Should be 2 requests.", 2, requests.size());
83
84 boolean pendingToRkirkend = false;
85 for (ActionRequest requestVO : requests)
86 {
87 if (requestVO.getPrincipalId().equals(getPrincipalIdForName("rkirkend")) && requestVO.isActivated())
88 {
89 assertFalse("rkirkend has too many requests!", pendingToRkirkend);
90 pendingToRkirkend = true;
91 } else
92 {
93 assertTrue("previous request to all others should be done.", requestVO.isDone());
94 }
95 }
96 assertTrue(document.isApprovalRequested());
97 }
98
99 private class SeqSetup {
100 public static final String DOCUMENT_TYPE_NAME = "DRSeqDocType";
101 public static final String ADHOC_NODE = "AdHoc";
102 public static final String WORKFLOW_DOCUMENT_NODE = "WorkflowDocument";
103 public static final String WORKFLOW_DOCUMENT_2_NODE = "WorkflowDocument2";
104 }
105
106 }