View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.routemodule;
17  
18  import org.junit.Test;
19  import org.kuali.rice.kew.api.KewApiServiceLocator;
20  import org.kuali.rice.kew.api.WorkflowDocument;
21  import org.kuali.rice.kew.api.WorkflowDocumentFactory;
22  import org.kuali.rice.kew.api.action.ActionRequest;
23  import org.kuali.rice.kew.api.action.ActionRequestStatus;
24  import org.kuali.rice.kew.api.action.RoutingReportCriteria;
25  import org.kuali.rice.kew.api.document.DocumentDetail;
26  import org.kuali.rice.kew.engine.node.RouteNodeInstance;
27  import org.kuali.rice.kew.service.KEWServiceLocator;
28  import org.kuali.rice.kew.test.KEWTestCase;
29  import org.kuali.rice.kew.api.KewApiConstants;
30  
31  import java.util.Collection;
32  import java.util.List;
33  
34  import static org.junit.Assert.*;
35  
36  public class RoutingReportServiceTest extends KEWTestCase {
37      
38  
39      protected void loadTestData() throws Exception {
40          loadXmlFile("RouteModuleConfig.xml");
41      }
42  
43      /**
44       * Tests the report() method against a sequential document type.
45       */
46      @Test public void testReportSequential() throws Exception {
47          
48          
49          // route a document to the first node
50          WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), SeqSetup.DOCUMENT_TYPE_NAME);
51          document.route("");
52          
53          // there should now be 1 active node and 2 pending requests on the document
54          Collection activeNodeInstances = KEWServiceLocator.getRouteNodeService().getActiveNodeInstances(document.getDocumentId());
55          List requests = KEWServiceLocator.getActionRequestService().findAllActionRequestsByDocumentId(document.getDocumentId());
56          assertEquals("Should be one active node.", 1, activeNodeInstances.size());
57          String activeNodeId = ((RouteNodeInstance)activeNodeInstances.iterator().next()).getRouteNodeInstanceId();
58          assertEquals("Should be 2 pending requests.", 2, requests.size());
59          
60          // now, lets "get our report on", the WorkflowInfo.executeSimulation method will call the service's report method.
61          RoutingReportCriteria criteria = RoutingReportCriteria.Builder.createByDocumentId(document.getDocumentId()).build();
62          
63          long start = System.currentTimeMillis();
64          DocumentDetail documentDetail = KewApiServiceLocator.getWorkflowDocumentActionsService().executeSimulation(
65                  criteria);
66          long end = System.currentTimeMillis();
67          System.out.println("Time to run routing report: " + (end-start)+" milliseconds.");
68          
69          // document detail should have all of our requests on it, 2 activated approves, 1 initialized approve, 2 initialized acknowledges
70          assertEquals("There should be 5 requests.", 5, documentDetail.getActionRequests().size());
71          boolean approveToBmcgough = false;
72          boolean approveToRkirkend = false;
73          boolean approveToPmckown = false;
74          boolean ackToTemay = false;
75          boolean ackToJhopf = false;
76          for (ActionRequest requestVO : documentDetail.getActionRequests()) {
77              String netId = getPrincipalNameForId(requestVO.getPrincipalId()); 
78              if (netId.equals("bmcgough")) {
79                  assertEquals("Should be approve.", KewApiConstants.ACTION_REQUEST_APPROVE_REQ, requestVO.getActionRequested().getCode());
80                  assertEquals("Should be activated.", ActionRequestStatus.ACTIVATED, requestVO.getStatus());
81                  assertEquals("Wrong node name", SeqSetup.WORKFLOW_DOCUMENT_NODE, requestVO.getNodeName());
82                  approveToBmcgough = true;
83              } else if (netId.equals("rkirkend")) {
84                  assertEquals("Should be approve.", KewApiConstants.ACTION_REQUEST_APPROVE_REQ, requestVO.getActionRequested().getCode());
85                  assertEquals("Should be activated.", ActionRequestStatus.ACTIVATED, requestVO.getStatus());
86                  assertEquals("Wrong node name", SeqSetup.WORKFLOW_DOCUMENT_NODE, requestVO.getNodeName());
87                  approveToRkirkend = true;
88              } else if (netId.equals("pmckown")) {
89                  assertEquals("Should be approve.", KewApiConstants.ACTION_REQUEST_APPROVE_REQ, requestVO.getActionRequested().getCode());
90                  assertEquals("Should be initialized.", ActionRequestStatus.INITIALIZED, requestVO.getStatus());
91                  assertEquals("Wrong node name", SeqSetup.WORKFLOW_DOCUMENT_2_NODE, requestVO.getNodeName());
92                  approveToPmckown = true;
93              } else if (netId.equals("temay")) {
94                  assertEquals("Should be acknowledge.", KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, requestVO.getActionRequested().getCode());
95                  assertEquals("Should be initialized.", ActionRequestStatus.INITIALIZED, requestVO.getStatus());
96                  assertEquals("Wrong node name", SeqSetup.ACKNOWLEDGE_1_NODE, requestVO.getNodeName());
97                  ackToTemay = true;
98              } else if (netId.equals("jhopf")) {
99                  assertEquals("Should be acknowledge.", KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, requestVO.getActionRequested().getCode());
100                 assertEquals("Should be initialized.", ActionRequestStatus.INITIALIZED, requestVO.getStatus());
101                 assertEquals("Wrong node name", SeqSetup.ACKNOWLEDGE_2_NODE, requestVO.getNodeName());
102                 ackToJhopf = true;
103             } 
104             assertNotNull(requestVO.getId());
105         }
106         assertTrue("There should be an approve to bmcgough", approveToBmcgough);
107         assertTrue("There should be an approve to rkirkend", approveToRkirkend);
108         assertTrue("There should be an approve to pmckown", approveToPmckown);
109         assertTrue("There should be an ack to temay", ackToTemay);
110         assertTrue("There should be an ack to jhopf", ackToJhopf);
111         
112         // assert that the report call didn't save any of the nodes or requests
113         activeNodeInstances = KEWServiceLocator.getRouteNodeService().getActiveNodeInstances(document.getDocumentId());
114         requests = KEWServiceLocator.getActionRequestService().findAllActionRequestsByDocumentId(document.getDocumentId());
115         assertEquals("Should be one active node.", 1, activeNodeInstances.size());
116         assertEquals("Should be at the same node.", activeNodeId, ((RouteNodeInstance)activeNodeInstances.iterator().next()).getRouteNodeInstanceId());
117         assertEquals("Should be 2 pending requests.", 2, requests.size());
118         
119         // test reporting to a specified target node
120         criteria = RoutingReportCriteria.Builder.createByDocumentIdAndTargetNodeName(document.getDocumentId(), SeqSetup.ACKNOWLEDGE_1_NODE).build();
121         documentDetail = KewApiServiceLocator.getWorkflowDocumentActionsService().executeSimulation(criteria);
122         
123         // document detail should have all of our requests except for the final acknowledge
124         assertEquals("There should be 4 requets.", 4, documentDetail.getActionRequests().size());
125         // assert that we don't have an acknowledge to jhopf
126         for (ActionRequest requestVO : documentDetail.getActionRequests()) {
127             if (requestVO.getPrincipalId().equals(getPrincipalIdForName("jhopf"))) {
128                 fail("There should be no request to jhopf");
129             }
130         }
131     }
132 
133     private static class SeqSetup {
134         public static final String DOCUMENT_TYPE_NAME = "SeqDocType";
135         public static final String ADHOC_NODE = "AdHoc";
136         public static final String WORKFLOW_DOCUMENT_NODE = "WorkflowDocument";
137         public static final String WORKFLOW_DOCUMENT_2_NODE = "WorkflowDocument2";
138         public static final String ACKNOWLEDGE_1_NODE = "Acknowledge1";
139         public static final String ACKNOWLEDGE_2_NODE = "Acknowledge2";
140     }
141     
142     private static class DynSetup {
143         public static final String DOCUMENT_TYPE_NAME = "DynChartOrgDocType";
144         public static final String INITIAL_NODE = "Initial";
145         public static final String CHART_ORG_NODE = "ChartOrg";
146         public static final String SPLIT_NODE_NAME = "Organization Split";
147         public static final String JOIN_NODE_NAME = "Organization Join";
148         public static final String REQUEST_NODE_NAME = "Organization Request";
149     }
150 }