View Javadoc
1   /*
2    * Copyright 2006-2014 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  
17  package org.kuali.rice.kew.impl.peopleflow;
18  
19  import org.kuali.rice.kew.api.action.ActionType;
20  import org.kuali.rice.kew.engine.RouteContext;
21  import org.kuali.rice.kew.framework.support.krms.RulesEngineExecutor;
22  import org.kuali.rice.krms.api.engine.Engine;
23  import org.kuali.rice.krms.api.engine.EngineResults;
24  import org.kuali.rice.krms.framework.engine.EngineResultsImpl;
25  import org.kuali.rice.krms.impl.peopleflow.PeopleFlowActionTypeService;
26  
27  import java.lang.reflect.Field;
28  
29  /**
30   * A test RulesEngineExecutor that doesn't actually call KRMS, it just dummies up some EngineResults and passes them
31   * back.
32   */
33  public class RulesEngineExecutorMock implements RulesEngineExecutor {
34  
35      private static String peopleFlowId = null;
36  
37      public static void setPeopleFlowId(String ppfId) {
38          peopleFlowId = ppfId;
39      }
40  
41      @Override
42      public EngineResults execute(RouteContext routeContext, Engine engine) {
43          EngineResultsImpl engineResults = new EngineResultsImpl();
44  
45          String ppfAttributeName = "";
46  
47          try {
48              Field field = PeopleFlowActionTypeService.class.getDeclaredField("PEOPLE_FLOWS_SELECTED_ATTRIBUTE");
49              field.setAccessible(true);
50              ppfAttributeName = (String)field.get(new PeopleFlowActionTypeService(PeopleFlowActionTypeService.Type.APPROVAL));
51          } catch (NoSuchFieldException e) {
52              e.printStackTrace();
53          } catch (IllegalAccessException e) {
54              e.printStackTrace();
55          }
56  
57          engineResults.setAttribute(ppfAttributeName, ActionType.APPROVE.getCode() + ":" + peopleFlowId);
58  
59          return engineResults;
60      }
61  
62  }