View Javadoc

1   /**
2    * Copyright 2004-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.hr.lm.leaveSummary.service;
17  
18  import java.math.BigDecimal;
19  import java.util.Date;
20  import java.util.List;
21  
22  import org.junit.Assert;
23  import org.junit.Test;
24  import org.kuali.hr.lm.leaveSummary.LeaveSummary;
25  import org.kuali.hr.lm.leaveSummary.LeaveSummaryRow;
26  import org.kuali.hr.test.KPMETestCase;
27  import org.kuali.hr.time.calendar.CalendarEntries;
28  import org.kuali.hr.time.service.base.TkServiceLocator;
29  
30  public class LeaveSummaryServiceImplTest extends KPMETestCase {
31  	
32  	@Test
33  	public void testGetLeaveSummary() throws Exception {
34  		// selected calendar entry is 03/15/2012 - 04/01/2012
35  		CalendarEntries ce = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("10001");
36  		
37  		LeaveSummary ls = TkServiceLocator.getLeaveSummaryService().getLeaveSummary("testUser", ce);
38  		Assert.assertTrue("There ytd dates String should be 'March 1 - March 14 2012', not " + ls.getYtdDatesString(), ls.getYtdDatesString().equals("March 1 - March 14 2012"));
39  		Assert.assertTrue("There pending dates String should be 'March 15 - March 31 2012', not " + ls.getPendingDatesString(), ls.getPendingDatesString().equals("March 15 - March 31 2012"));
40  		
41  		List<LeaveSummaryRow> rows = ls.getLeaveSummaryRows();
42  		Assert.assertTrue("There should be 1 leave summary rows for emplyee 'testUser', not " + rows.size(), rows.size()== 1);
43  		LeaveSummaryRow aRow = rows.get(0);
44  		Assert.assertTrue("Accrual cateogry for Row should be 'testAC', not " + aRow.getAccrualCategory(), aRow.getAccrualCategory().equals("testAC"));
45  		Assert.assertTrue("Carry over for Row should be '0', not " + aRow.getCarryOver(), aRow.getCarryOver().compareTo(BigDecimal.ZERO) == 0);
46  		Assert.assertTrue("YTD accrualed balance for Row should be '5', not " + aRow.getYtdAccruedBalance(), aRow.getYtdAccruedBalance().compareTo(new BigDecimal(5)) == 0);
47  		Assert.assertTrue("YTD approved usage for Row should be '2', not " + aRow.getYtdApprovedUsage(), aRow.getYtdApprovedUsage().compareTo(new BigDecimal(2)) == 0);
48  		Assert.assertTrue("Leave Balance for Row should be '3', not " + aRow.getLeaveBalance(), aRow.getLeaveBalance().compareTo(new BigDecimal(3)) == 0);
49  		Assert.assertTrue("Pending Leave Accrual for Row should be '10', not " + aRow.getPendingLeaveAccrual(), aRow.getPendingLeaveAccrual().compareTo(new BigDecimal(10)) == 0);
50  		Assert.assertTrue("Pending Leave requests for Row should be '0', not " + aRow.getPendingLeaveRequests(), aRow.getPendingLeaveRequests().compareTo(new BigDecimal(0)) == 0);
51  		//Assert.assertTrue("Pending Leave Balance for Row should be '3', not " + aRow.getPendingLeaveBalance(), aRow.getPendingLeaveBalance().equals(new BigDecimal(3)));
52  		//Assert.assertTrue("Pending Available usage for Row should be '198', not " + aRow.getPendingAvailableUsage(), aRow.getPendingAvailableUsage().equals(new BigDecimal(198)));
53  		Assert.assertTrue("Usage Limit for Row should be '200', not " + aRow.getUsageLimit(), aRow.getUsageLimit().compareTo(new BigDecimal(200)) == 0);
54  		Assert.assertTrue("FMLA usage for Row should be '2', not " + aRow.getFmlaUsage(), aRow.getFmlaUsage().compareTo(new BigDecimal(2)) == 0);
55  		
56  		// selected calendar entry is 04/01/2012 - 04/30/2012
57  		ce = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("10002");
58  		ls = TkServiceLocator.getLeaveSummaryService().getLeaveSummary("testUser", ce);
59  		Assert.assertTrue("There ytd dates String should be 'March 1 - March 14 2012', not " + ls.getYtdDatesString(), ls.getYtdDatesString().equals("March 1 - March 14 2012"));
60  		Assert.assertTrue("There pending dates String should be 'April 1 - April 30 2012', not " + ls.getPendingDatesString(), ls.getPendingDatesString().equals("April 1 - April 30 2012"));
61  		
62  		rows = ls.getLeaveSummaryRows();
63  		Assert.assertTrue("There should be 1 leave summary rows for emplyee 'testUser', not " + rows.size(), rows.size()== 1);
64  		aRow = rows.get(0);
65  		Assert.assertTrue("Accrual cateogry for Row should be 'testAC', not " + aRow.getAccrualCategory(), aRow.getAccrualCategory().equals("testAC"));
66  		Assert.assertTrue("Carry over for Row should be '0', not " + aRow.getCarryOver(), aRow.getCarryOver().compareTo(BigDecimal.ZERO)==0);
67  		Assert.assertTrue("YTD accrualed balance for Row should be '5', not " + aRow.getYtdAccruedBalance(), aRow.getYtdAccruedBalance().compareTo(new BigDecimal(5))==0);
68  		Assert.assertTrue("YTD approved usage for Row should be '2', not " + aRow.getYtdApprovedUsage(), aRow.getYtdApprovedUsage().compareTo(new BigDecimal(2))==0);
69  		Assert.assertTrue("Leave Balance for Row should be '3', not " + aRow.getLeaveBalance(), aRow.getLeaveBalance().compareTo(new BigDecimal(3))==0);
70  		Assert.assertTrue("Pending Leave Accrual for Row should be '0', not " + aRow.getPendingLeaveAccrual(), aRow.getPendingLeaveAccrual().compareTo(BigDecimal.ZERO)==0);
71  		Assert.assertTrue("Pending Leave requests for Row should be '0', not " + aRow.getPendingLeaveRequests(), aRow.getPendingLeaveRequests().compareTo(new BigDecimal(0))==0);
72  		//Assert.assertTrue("Pending Leave Balance for Row should be '13', not " + aRow.getPendingLeaveBalance(), aRow.getPendingLeaveBalance().equals(new BigDecimal(13)));
73  		//Assert.assertTrue("Pending Available usage for Row should be '198', not " + aRow.getPendingAvailableUsage(), aRow.getPendingAvailableUsage().equals(new BigDecimal(198)));
74  		Assert.assertTrue("Usage Limit for Row should be '200', not " + aRow.getUsageLimit(), aRow.getUsageLimit().compareTo(new BigDecimal(200)) == 0);
75  		Assert.assertTrue("FMLA usage for Row should be '2', not " + aRow.getFmlaUsage(), aRow.getFmlaUsage().compareTo(new BigDecimal(2)) == 0);
76  		
77  		// selected calendar entry is 05/01/2012 - 05/31/2012
78  		ce = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("10003");
79  		ls = TkServiceLocator.getLeaveSummaryService().getLeaveSummary("testUser", ce);
80  		Assert.assertTrue("There ytd dates String should be 'March 1 - March 14 2012', not " + ls.getYtdDatesString(), ls.getYtdDatesString().equals("March 1 - March 14 2012"));
81  		Assert.assertTrue("There pending dates String should be 'May 1 - May 31 2012', not " + ls.getPendingDatesString(), ls.getPendingDatesString().equals("May 1 - May 31 2012"));
82  		
83  		rows = ls.getLeaveSummaryRows();
84  		Assert.assertTrue("There should be 2 leave summary rows for emplyee 'testUser', not " + rows.size(), rows.size()== 2);
85  		for(LeaveSummaryRow lsRow : rows ) {
86  			if(lsRow.getAccrualCategory().equals("testAC")) {
87  				Assert.assertTrue("Carry over for Row should be '0', not " + lsRow.getCarryOver(), lsRow.getCarryOver().compareTo(BigDecimal.ZERO) == 0);
88  				Assert.assertTrue("YTD accrualed balance for Row should be '15', not " + lsRow.getYtdAccruedBalance(), lsRow.getYtdAccruedBalance().compareTo(new BigDecimal(15)) == 0);
89  				Assert.assertTrue("YTD approved usage for Row should be '2', not " + lsRow.getYtdApprovedUsage(), lsRow.getYtdApprovedUsage().compareTo(new BigDecimal(2)) == 0);
90  				Assert.assertTrue("Leave Balance for Row should be '13', not " + lsRow.getLeaveBalance(), lsRow.getLeaveBalance().compareTo(new BigDecimal(13)) == 0);
91  				Assert.assertTrue("Pending Leave Accrual for Row should be '0', not " + lsRow.getPendingLeaveAccrual(), lsRow.getPendingLeaveAccrual().compareTo(BigDecimal.ZERO) == 0);
92  				Assert.assertTrue("Pending Leave requests for Row should be '0', not " + lsRow.getPendingLeaveRequests(), lsRow.getPendingLeaveRequests().compareTo(new BigDecimal(0)) == 0);
93  				//Assert.assertTrue("Pending Leave Balance for Row should be '13', not " + lsRow.getPendingLeaveBalance(), lsRow.getPendingLeaveBalance().equals(new BigDecimal(13)));
94  				//Assert.assertTrue("Pending Available usage for Row should be '198', not " + lsRow.getPendingAvailableUsage(), lsRow.getPendingAvailableUsage().equals(new BigDecimal(198)));
95  				Assert.assertTrue("Usage Limit for Row should be '200', not " + lsRow.getUsageLimit(), lsRow.getUsageLimit().compareTo(new BigDecimal(200)) == 0);
96  				Assert.assertTrue("FMLA usage for Row should be '2', not " + lsRow.getFmlaUsage(), lsRow.getFmlaUsage().compareTo(new BigDecimal(2)) == 0);
97  			} else if(lsRow.getAccrualCategory().equals("testAC1")) {
98  				Assert.assertTrue("Carry over for Row should be '0', not " + lsRow.getCarryOver(), lsRow.getCarryOver().compareTo(BigDecimal.ZERO) == 0);
99  				Assert.assertTrue("YTD accrualed balance for Row should be '0', not " + lsRow.getYtdAccruedBalance(), lsRow.getYtdAccruedBalance().compareTo(new BigDecimal(0)) == 0);
100 				Assert.assertTrue("YTD approved usage for Row should be '0', not " + lsRow.getYtdApprovedUsage(), lsRow.getYtdApprovedUsage().compareTo(new BigDecimal(0)) == 0);
101 				Assert.assertTrue("Leave Balance for Row should be '0', not " + lsRow.getLeaveBalance(), lsRow.getLeaveBalance().compareTo(new BigDecimal(0)) == 0);
102 				Assert.assertTrue("Pending Leave Accrual for Row should be '0', not " + lsRow.getPendingLeaveAccrual(), lsRow.getPendingLeaveAccrual().compareTo(BigDecimal.ZERO) == 0);
103 				Assert.assertTrue("Pending Leave requests for Row should be '0', not " + lsRow.getPendingLeaveRequests(), lsRow.getPendingLeaveRequests().compareTo(new BigDecimal(0)) == 0);
104 				//Assert.assertTrue("Pending Leave Balance for Row should be '8', not " + lsRow.getPendingLeaveBalance(), lsRow.getPendingLeaveBalance().equals(new BigDecimal(8)));
105 				//Assert.assertTrue("Pending Available usage for Row should be '300', not " + lsRow.getPendingAvailableUsage(), lsRow.getPendingAvailableUsage().equals(new BigDecimal(300)));
106 				Assert.assertTrue("Usage Limit for Row should be '300', not " + lsRow.getUsageLimit(), lsRow.getUsageLimit().compareTo(new BigDecimal(300)) == 0);
107 				Assert.assertTrue("FMLA usage for Row should be '0', not " + lsRow.getFmlaUsage(), lsRow.getFmlaUsage().compareTo(new BigDecimal(0)) == 0);
108 			} else {
109 				Assert.fail("Accrual category for Row should either be 'testAC' or 'testAC1', not " + lsRow.getAccrualCategory());
110 			}
111 		}
112 		// selected calendar entry is 02/01/2012 - 03/01/2012
113 		// principal HR attribute does not exist on 02/01/2012, it becomes active on 02/05/2012
114 		// this is testing null principalHrAttributes with beginning date of Calendar entry
115 		ce = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("10004");
116 		ls = TkServiceLocator.getLeaveSummaryService().getLeaveSummary("testUser", ce);
117 		rows = ls.getLeaveSummaryRows();
118 		Assert.assertTrue("There should be 1 leave summary rows for emplyee 'testUser', not " + rows.size(), rows.size()== 1);
119 	}
120 	
121 	@Test
122 	public void testGetHeaderForSummary() throws Exception {
123 		CalendarEntries ce = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("10001");
124 		List<Date> leaveSummaryDates = TkServiceLocator.getLeaveSummaryService().getLeaveSummaryDates(ce);
125 		
126 		Assert.assertTrue("The number of leave summary dates should be 17, not " + leaveSummaryDates.size(), leaveSummaryDates.size()== 17);
127 		
128 	}
129 }