001/** 002 * Copyright 2005-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.kew.util; 017 018import org.junit.Test; 019import org.kuali.rice.kew.actionrequest.ActionRequestValue; 020 021import java.util.ArrayList; 022import java.util.Collections; 023import java.util.List; 024 025import static org.junit.Assert.assertEquals; 026 027/** 028 * Tests the various static methods in the {@link Utilities} class. 029 * 030 * @author Kuali Rice Team (rice.collab@kuali.org) 031 */ 032public class UtilitiesTest { 033 034 /** 035 * AR1 is active and AR2 is initialized and hence the expected result is AR1 comes first. 036 */ 037 @Test 038 public void RouteLogActionRequestSorterTest_AR1_Active() { 039 ActionRequestValue ar1 = new ActionRequestValue(); 040 ActionRequestValue ar2 = new ActionRequestValue(); 041 042 ar1.setActionRequestId("Test1"); 043 ar1.setRouteLevel(1); 044 ar1.setStatus("A"); 045 046 ar2.setActionRequestId("Test2"); 047 ar2.setRouteLevel(1); 048 ar2.setStatus("I"); 049 050 List<ActionRequestValue> actionRequestValues = new ArrayList<ActionRequestValue>(); 051 actionRequestValues.add(ar1); 052 actionRequestValues.add(ar2); 053 054 Collections.sort(actionRequestValues, new Utilities.RouteLogActionRequestSorter()); 055 056 assertEquals("Test1", actionRequestValues.get(0).getActionRequestId()); 057 } 058 059 /** 060 * AR1 is Initialized and AR2 is Active and hence the expected result is AR2 comes first. 061 */ 062 @Test 063 public void RouteLogActionRequestSorterTest_AR2_Active() { 064 ActionRequestValue ar1 = new ActionRequestValue(); 065 ActionRequestValue ar2 = new ActionRequestValue(); 066 067 ar1.setActionRequestId("Test1"); 068 ar1.setRouteLevel(1); 069 ar1.setStatus("I"); 070 071 ar2.setActionRequestId("Test2"); 072 ar2.setRouteLevel(1); 073 ar2.setStatus("A"); 074 075 List<ActionRequestValue> actionRequestValues = new ArrayList<ActionRequestValue>(); 076 actionRequestValues.add(ar1); 077 actionRequestValues.add(ar2); 078 079 Collections.sort(actionRequestValues, new Utilities.RouteLogActionRequestSorter()); 080 081 assertEquals("Test2", actionRequestValues.get(0).getActionRequestId()); 082 } 083 084 /** 085 * AR1 and AR2 both are active and hence the call should go to {@code PrioritySorter} and result should be based on 086 * the priority Level. 087 */ 088 @Test 089 public void RouteLogActionRequestSorterTest_Both_Active() { 090 ActionRequestValue ar1 = new ActionRequestValue(); 091 ActionRequestValue ar2 = new ActionRequestValue(); 092 ActionRequestValue ar3 = new ActionRequestValue(); 093 094 ar1.setActionRequestId("Test1"); 095 ar1.setRouteLevel(1); 096 ar1.setStatus("A"); 097 ar1.setPriority(1); 098 099 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}