View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    * http://www.opensource.org/licenses/ecl2.php
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.kuali.rice.kew.routemodule;
18  
19  
20  import java.util.Collection;
21  import java.util.List;
22  
23  import org.junit.Test;
24  import org.kuali.rice.kew.dto.ActionRequestDTO;
25  import org.kuali.rice.kew.dto.DocumentDetailDTO;
26  import org.kuali.rice.kew.dto.NetworkIdDTO;
27  import org.kuali.rice.kew.dto.ReportCriteriaDTO;
28  import org.kuali.rice.kew.engine.node.RouteNodeInstance;
29  import org.kuali.rice.kew.service.KEWServiceLocator;
30  import org.kuali.rice.kew.service.WorkflowDocument;
31  import org.kuali.rice.kew.service.WorkflowInfo;
32  import org.kuali.rice.kew.test.KEWTestCase;
33  import org.kuali.rice.kew.util.KEWConstants;
34  
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 = new WorkflowDocument(new NetworkIdDTO("ewestfal"), SeqSetup.DOCUMENT_TYPE_NAME);
51          document.routeDocument("");
52          
53          // there should now be 1 active node and 2 pending requests on the document
54          Collection activeNodeInstances = KEWServiceLocator.getRouteNodeService().getActiveNodeInstances(document.getRouteHeaderId());
55          List requests = KEWServiceLocator.getActionRequestService().findAllActionRequestsByRouteHeaderId(document.getRouteHeaderId());
56          assertEquals("Should be one active node.", 1, activeNodeInstances.size());
57          Long 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.routingReport method will call the service's report method.
61          WorkflowInfo info = new WorkflowInfo();
62          ReportCriteriaDTO criteria = new ReportCriteriaDTO(document.getRouteHeaderId());
63          
64          long start = System.currentTimeMillis();
65          DocumentDetailDTO documentDetail = info.routingReport(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().length);
71          boolean approveToBmcgough = false;
72          boolean approveToRkirkend = false;
73          boolean approveToPmckown = false;
74          boolean ackToTemay = false;
75          boolean ackToJhopf = false;
76          for (int index = 0; index < documentDetail.getActionRequests().length; index++) {
77              ActionRequestDTO requestVO = documentDetail.getActionRequests()[index];
78              String netId = getPrincipalNameForId(requestVO.getPrincipalId()); 
79              if (netId.equals("bmcgough")) {
80                  assertEquals("Should be approve.", KEWConstants.ACTION_REQUEST_APPROVE_REQ, requestVO.getActionRequested());
81                  assertEquals("Should be activated.", KEWConstants.ACTION_REQUEST_ACTIVATED, requestVO.getStatus());
82                  assertEquals("Wrong node name", SeqSetup.WORKFLOW_DOCUMENT_NODE, requestVO.getNodeName());
83                  approveToBmcgough = true;
84              } else if (netId.equals("rkirkend")) {
85                  assertEquals("Should be approve.", KEWConstants.ACTION_REQUEST_APPROVE_REQ, requestVO.getActionRequested());
86                  assertEquals("Should be activated.", KEWConstants.ACTION_REQUEST_ACTIVATED, requestVO.getStatus());
87                  assertEquals("Wrong node name", SeqSetup.WORKFLOW_DOCUMENT_NODE, requestVO.getNodeName());
88                  approveToRkirkend = true;
89              } else if (netId.equals("pmckown")) {
90                  assertEquals("Should be approve.", KEWConstants.ACTION_REQUEST_APPROVE_REQ, requestVO.getActionRequested());
91                  assertEquals("Should be initialized.", KEWConstants.ACTION_REQUEST_INITIALIZED, requestVO.getStatus());
92                  assertEquals("Wrong node name", SeqSetup.WORKFLOW_DOCUMENT_2_NODE, requestVO.getNodeName());
93                  approveToPmckown = true;
94              } else if (netId.equals("temay")) {
95                  assertEquals("Should be acknowledge.", KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, requestVO.getActionRequested());
96                  assertEquals("Should be initialized.", KEWConstants.ACTION_REQUEST_INITIALIZED, requestVO.getStatus());
97                  assertEquals("Wrong node name", SeqSetup.ACKNOWLEDGE_1_NODE, requestVO.getNodeName());
98                  ackToTemay = true;
99              } else if (netId.equals("jhopf")) {
100                 assertEquals("Should be acknowledge.", KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, requestVO.getActionRequested());
101                 assertEquals("Should be initialized.", KEWConstants.ACTION_REQUEST_INITIALIZED, requestVO.getStatus());
102                 assertEquals("Wrong node name", SeqSetup.ACKNOWLEDGE_2_NODE, requestVO.getNodeName());
103                 ackToJhopf = true;
104             } 
105             assertNotNull(requestVO.getNodeInstanceId());            
106         }
107         assertTrue("There should be an approve to bmcgough", approveToBmcgough);
108         assertTrue("There should be an approve to rkirkend", approveToRkirkend);
109         assertTrue("There should be an approve to pmckown", approveToPmckown);
110         assertTrue("There should be an ack to temay", ackToTemay);
111         assertTrue("There should be an ack to jhopf", ackToJhopf);
112         
113         // assert that the report call didn't save any of the nodes or requests
114         activeNodeInstances = KEWServiceLocator.getRouteNodeService().getActiveNodeInstances(document.getRouteHeaderId());
115         requests = KEWServiceLocator.getActionRequestService().findAllActionRequestsByRouteHeaderId(document.getRouteHeaderId());
116         assertEquals("Should be one active node.", 1, activeNodeInstances.size());
117         assertEquals("Should be at the same node.", activeNodeId, ((RouteNodeInstance)activeNodeInstances.iterator().next()).getRouteNodeInstanceId());
118         assertEquals("Should be 2 pending requests.", 2, requests.size());
119         
120         // test reporting to a specified target node
121         criteria = new ReportCriteriaDTO(document.getRouteHeaderId(), SeqSetup.ACKNOWLEDGE_1_NODE);
122         documentDetail = info.routingReport(criteria);
123         
124         // document detail should have all of our requests except for the final acknowledge
125         assertEquals("There should be 4 requets.", 4, documentDetail.getActionRequests().length);
126         // assert that we don't have an acknowledge to jhopf
127         for (int index = 0; index < documentDetail.getActionRequests().length; index++) {
128             ActionRequestDTO requestVO = documentDetail.getActionRequests()[index];
129             if (requestVO.getPrincipalId().equals(getPrincipalIdForName("jhopf"))) {
130                 fail("There should be no request to jhopf");
131             }
132         }
133     }
134 
135     private static class SeqSetup {
136         public static final String DOCUMENT_TYPE_NAME = "SeqDocType";
137         public static final String ADHOC_NODE = "AdHoc";
138         public static final String WORKFLOW_DOCUMENT_NODE = "WorkflowDocument";
139         public static final String WORKFLOW_DOCUMENT_2_NODE = "WorkflowDocument2";
140         public static final String ACKNOWLEDGE_1_NODE = "Acknowledge1";
141         public static final String ACKNOWLEDGE_2_NODE = "Acknowledge2";
142     }
143     
144     private static class DynSetup {
145         public static final String DOCUMENT_TYPE_NAME = "DynChartOrgDocType";
146         public static final String INITIAL_NODE = "Initial";
147         public static final String CHART_ORG_NODE = "ChartOrg";
148         public static final String SPLIT_NODE_NAME = "Organization Split";
149         public static final String JOIN_NODE_NAME = "Organization Join";
150         public static final String REQUEST_NODE_NAME = "Organization Request";
151     }
152 }