View Javadoc
1   /**
2    * Copyright 2005-2016 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.util;
17  
18  import org.junit.Test;
19  import org.kuali.rice.kew.actionrequest.ActionRequestValue;
20  
21  import java.util.ArrayList;
22  import java.util.Collections;
23  import java.util.List;
24  
25  import static org.junit.Assert.assertEquals;
26  
27  /**
28   * Tests the various static methods in the {@link Utilities} class.
29   *
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  public class UtilitiesTest {
33  
34      /**
35       * AR1 is active and AR2 is initialized and hence the expected result is AR1 comes first.
36       */
37      @Test
38      public void RouteLogActionRequestSorterTest_AR1_Active() {
39          ActionRequestValue ar1 = new ActionRequestValue();
40          ActionRequestValue ar2 = new ActionRequestValue();
41  
42          ar1.setActionRequestId("Test1");
43          ar1.setRouteLevel(1);
44          ar1.setStatus("A");
45  
46          ar2.setActionRequestId("Test2");
47          ar2.setRouteLevel(1);
48          ar2.setStatus("I");
49  
50          List<ActionRequestValue> actionRequestValues = new ArrayList<ActionRequestValue>();
51          actionRequestValues.add(ar1);
52          actionRequestValues.add(ar2);
53  
54          Collections.sort(actionRequestValues, new Utilities.RouteLogActionRequestSorter());
55  
56          assertEquals("Test1", actionRequestValues.get(0).getActionRequestId());
57      }
58  
59      /**
60       * AR1 is Initialized and AR2 is Active and hence the expected result is AR2 comes first.
61       */
62      @Test
63      public void RouteLogActionRequestSorterTest_AR2_Active() {
64          ActionRequestValue ar1 = new ActionRequestValue();
65          ActionRequestValue ar2 = new ActionRequestValue();
66  
67          ar1.setActionRequestId("Test1");
68          ar1.setRouteLevel(1);
69          ar1.setStatus("I");
70  
71          ar2.setActionRequestId("Test2");
72          ar2.setRouteLevel(1);
73          ar2.setStatus("A");
74  
75          List<ActionRequestValue> actionRequestValues = new ArrayList<ActionRequestValue>();
76          actionRequestValues.add(ar1);
77          actionRequestValues.add(ar2);
78  
79          Collections.sort(actionRequestValues, new Utilities.RouteLogActionRequestSorter());
80  
81          assertEquals("Test2", actionRequestValues.get(0).getActionRequestId());
82      }
83  
84      /**
85       * AR1 and AR2 both are active and hence the call should go to {@code PrioritySorter} and result should be based on
86       * the priority Level.
87       */
88      @Test
89      public void RouteLogActionRequestSorterTest_Both_Active() {
90          ActionRequestValue ar1 = new ActionRequestValue();
91          ActionRequestValue ar2 = new ActionRequestValue();
92          ActionRequestValue ar3 = new ActionRequestValue();
93  
94          ar1.setActionRequestId("Test1");
95          ar1.setRouteLevel(1);
96          ar1.setStatus("A");
97          ar1.setPriority(1);
98  
99          ar2.setActionRequestId("Test2");
100         ar2.setRouteLevel(1);
101         ar2.setStatus("A");
102         ar2.setPriority(2);
103 
104         ar3.setActionRequestId("Test3");
105         ar3.setRouteLevel(1);
106         ar3.setStatus("I");
107 
108         List<ActionRequestValue> actionRequestValues = new ArrayList<ActionRequestValue>();
109         actionRequestValues.add(ar1);
110         actionRequestValues.add(ar2);
111         actionRequestValues.add(ar3);
112 
113         Collections.sort(actionRequestValues, new Utilities.RouteLogActionRequestSorter());
114 
115         assertEquals("Test1", actionRequestValues.get(0).getActionRequestId());
116         assertEquals("Test2", actionRequestValues.get(1).getActionRequestId());
117         assertEquals("Test3", actionRequestValues.get(2).getActionRequestId());
118     }
119 }