View Javadoc

1   /**
2    * Copyright 2005-2013 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.ksb.messaging.threadpool;
17  
18  import org.junit.Test;
19  import org.kuali.rice.ksb.messaging.MessageServiceInvoker;
20  import org.kuali.rice.ksb.messaging.PersistedMessageBO;
21  
22  import java.sql.Timestamp;
23  
24  import static org.junit.Assert.assertEquals;
25  
26  
27  /**
28   * Tests that the {@link PriorityBlockingQueuePersistedMessageComparator} is sorting by 
29   * priority and date. 
30   * 
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   *
33   */
34  public class PriorityBlockingQueuePersistedMessageComparatorTest {
35  
36      @Test public void testSortingByPriorityAndDate() throws Exception {
37  	PersistedMessageBO message1 = new PersistedMessageBO();
38  	message1.setQueuePriority(1);
39  	message1.setQueueDate(new Timestamp(System.currentTimeMillis()));
40  	
41  	PersistedMessageBO message2 = new PersistedMessageBO();
42  	message2.setQueuePriority(5);
43  	message2.setQueueDate(new Timestamp(System.currentTimeMillis()));
44  	
45  	PersistedMessageBO message3 = new PersistedMessageBO();
46  	message3.setQueuePriority(5);
47  	message3.setQueueDate(new Timestamp(System.currentTimeMillis() + 5));
48  	
49  	assertEquals(PriorityBlockingQueuePersistedMessageComparator.class.getName() + " is sorting incorrectly", -1, new PriorityBlockingQueuePersistedMessageComparator().compare(new MessageServiceInvoker(message1), new MessageServiceInvoker(message2)));
50  	assertEquals(PriorityBlockingQueuePersistedMessageComparator.class.getName() + " is sorting incorrectly", 1, new PriorityBlockingQueuePersistedMessageComparator().compare(new MessageServiceInvoker(message2), new MessageServiceInvoker(message1)));
51  	assertEquals(PriorityBlockingQueuePersistedMessageComparator.class.getName() + " is sorting incorrectly", -1, new PriorityBlockingQueuePersistedMessageComparator().compare(new MessageServiceInvoker(message2), new MessageServiceInvoker(message3)));
52      }   
53  }