View Javadoc
1   /**
2    * Copyright 2004-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  package org.kuali.kpme.tklm.leave.accrual;
17  
18  import org.joda.time.DateTime;
19  import org.joda.time.LocalDate;
20  import org.junit.Assert;
21  import org.junit.Test;
22  import org.kuali.kpme.core.IntegrationTest;
23  import org.kuali.kpme.core.util.HrConstants;
24  import org.kuali.kpme.core.util.TKUtils;
25  import org.kuali.kpme.tklm.TKLMIntegrationTestCase;
26  import org.kuali.kpme.tklm.api.leave.block.LeaveBlock;
27  import org.kuali.kpme.tklm.common.LMConstants;
28  import org.kuali.kpme.tklm.leave.block.LeaveBlockHistory;
29  import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
30  
31  import java.math.BigDecimal;
32  import java.util.List;
33  
34  @IntegrationTest
35  public class AccrualServiceTest extends TKLMIntegrationTestCase {
36  	 DateTime START_DATE = new DateTime(2012, 2, 20, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
37  	 DateTime END_DATE = new DateTime(2012, 5, 3, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
38  	
39  	@Test
40  	/*the employee has job A starts from 03/01/2012, ends on 04/01/2012 with standard hours of 40, so fte is 1.0
41  	 * job B starts on 04/01/2012, no end to it with standard hours of 20, fte is 0.5
42  	 * on 04/10/2012, there's a system scheduled time off of 8 hrs with a systemScheduledTimeOffDate of 04/12/2012
43  	 * on 04/11/2012, there's a system scheduled time off of 8 hrs without a systemScheduledTimeOffDate, so no usage leave block will be created for this ssto
44  	 */
45  	public void testRunAccrualForStatusChange() {
46  		 String principal_id = "testUser";
47  		 List<LeaveBlock> leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), END_DATE.toLocalDate());
48  		 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
49  		 
50  		 // first time to run accrual from 02/20/2012 to 05/03/2012
51  		 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, END_DATE, false, "admin");
52  		 verifyLeaveBlocksForStatusChange();
53  		 
54  		 List<LeaveBlockHistory> historyList = LmServiceLocator.getLeaveBlockHistoryService().getLeaveBlockHistories(principal_id, null);
55  		 Assert.assertTrue("There should be 6 leave block history for emplyee " + principal_id + ", not " + historyList.size(), historyList.size()== 6);
56  		 LeaveBlockHistory lbh = historyList.get(0);
57  		 Assert.assertTrue("Leave Block Type of leave block history should be " + LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE + ", not " + lbh.getLeaveBlockType()
58  					, lbh.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE));
59  		 
60  		 // second time to run accrual from 02/20/2012 to 05/03/2012, should get the same results as first run
61  		 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, END_DATE, false, "admin");
62  		 verifyLeaveBlocksForStatusChange();
63  		 
64  		 historyList = LmServiceLocator.getLeaveBlockHistoryService().getLeaveBlockHistories(principal_id, null);
65  		 Assert.assertTrue("There should be 16 leave block history for employee " + principal_id + ", not " + historyList.size(), historyList.size()== 16);
66  	}
67  	private void verifyLeaveBlocksForStatusChange() {
68  		String principal_id = "testUser";
69  		List<LeaveBlock> leaveBlockList;
70  		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), END_DATE.toLocalDate());
71  		Assert.assertFalse("No leave blocks created by runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
72  		Assert.assertTrue("There should be 6 leave blocks for emplyee 'testUser', not " + leaveBlockList.size(), leaveBlockList.size()== 6);
73  		 
74  		// there should be one leave block of 16 hours on 03/31/2012
75  		DateTime intervalDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
76  		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
77  		Assert.assertTrue("There should be 1 leave block for date 03/31/2012.", leaveBlockList.size()==1);
78  		LeaveBlock lb = leaveBlockList.get(0);
79  		Assert.assertTrue("Hours of the leave block for date 03/31/2012 should be 16, not " + lb.getLeaveAmount().toString(), lb.getLeaveAmount().equals(new BigDecimal(16)));
80  		Assert.assertNull("lm_sys_schd_timeoff_id should be null for regular accrual leave block", lb.getScheduleTimeOffId());
81  		Assert.assertTrue("Leave Block Type of leave block should be " + LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE + ", not " + lb.getLeaveBlockType()
82  				, lb.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE));
83  		Assert.assertTrue("Requst status of leave block should be " + HrConstants.REQUEST_STATUS.APPROVED + ", not " + lb.getRequestStatus()
84  				, lb.getRequestStatus().equals(HrConstants.REQUEST_STATUS.APPROVED));
85  		
86  		// employee changed status on 04/01, fte is changed from 1 to 0.5
87  		// there should be an empty leave block for status change on 04/01/2012
88  		intervalDate = new DateTime(2012, 4, 01, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
89  		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
90  		Assert.assertTrue("There should be 1 leave block for date 04/01/2012.", leaveBlockList.size()==1);
91  		lb = leaveBlockList.get(0);
92  		Assert.assertTrue("Hours of the leave block for date 04/01/2012 should be 0, not " + lb.getLeaveAmount().toString(), lb.getLeaveAmount().equals(BigDecimal.ZERO));
93  		Assert.assertTrue("Leave Code of the leave block for date 04/01/2012 should be " + LMConstants.STATUS_CHANGE_EARN_CODE + ", not " + lb.getEarnCode()
94  				, lb.getEarnCode().equals(LMConstants.STATUS_CHANGE_EARN_CODE));
95  		Assert.assertNull("accrual_category should be null for empty status change leave block", lb.getAccrualCategory()); 
96  		Assert.assertTrue("Leave Block Type of leave block should be " + LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE + ", not " + lb.getLeaveBlockType()
97  				, lb.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE));
98  		Assert.assertTrue("Requst status of leave block should be " + HrConstants.REQUEST_STATUS.APPROVED + ", not " + lb.getRequestStatus()
99  				, lb.getRequestStatus().equals(HrConstants.REQUEST_STATUS.APPROVED));
100 		
101 		// there should be one holiday leave blocks of 4 hours on 04/10/2012, this is the accrualed leave block for the ssto
102 		intervalDate = new DateTime(2012, 4, 10, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
103 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
104 		Assert.assertTrue("There should be 1 leave block for date 04/10/2012.", leaveBlockList.size()==1);
105 		lb = leaveBlockList.get(0);
106 		Assert.assertNotNull("lm_sys_schd_timeoff_id should NOT be null for holiday accrual leave block", lb.getScheduleTimeOffId());
107 		Assert.assertTrue("lm_sys_schd_timeoff_id should be 5000, not " + lb.getScheduleTimeOffId(), lb.getScheduleTimeOffId().equals("5000"));
108 		Assert.assertTrue("Leave Block Type of leave block should be " + LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE + ", not " + lb.getLeaveBlockType()
109 				, lb.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE));
110 		Assert.assertTrue("Requst status of leave block should be " + HrConstants.REQUEST_STATUS.APPROVED + ", not " + lb.getRequestStatus()
111 				, lb.getRequestStatus().equals(HrConstants.REQUEST_STATUS.APPROVED));
112 		Assert.assertTrue("Hours of the leave block for date 04/10/2012 should be 4, not " + lb.getLeaveAmount().toString(), lb.getLeaveAmount().equals(new BigDecimal(4)));
113 		
114 		// there should be one usage leave blocks of 4 hours on 04/12/2012
115 		intervalDate = new DateTime(2012, 4, 12, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
116 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
117 		Assert.assertTrue("There should be 1 leave block for date 04/12/2012.", leaveBlockList.size()==1);
118 		lb = leaveBlockList.get(0);
119 		Assert.assertNotNull("lm_sys_schd_timeoff_id should NOT be null for holiday accrual leave block", lb.getScheduleTimeOffId());
120 		Assert.assertTrue("lm_sys_schd_timeoff_id should be 5000, not " + lb.getScheduleTimeOffId(), lb.getScheduleTimeOffId().equals("5000"));
121 		Assert.assertTrue("Leave Block Type of leave block should be " + LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE + ", not " + lb.getLeaveBlockType()
122 				, lb.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE));
123 		Assert.assertTrue("Requst status of leave block should be " + HrConstants.REQUEST_STATUS.APPROVED + ", not " + lb.getRequestStatus()
124 				, lb.getRequestStatus().equals(HrConstants.REQUEST_STATUS.APPROVED));
125 		Assert.assertTrue("Hours of the leave block for date 04/12/2012 should be -4, not " + lb.getLeaveAmount().toString(), lb.getLeaveAmount().equals(new BigDecimal(-4)));		
126 		Assert.assertNotNull("System Scheduled Timeoff usage leave block's Job number should not be null", lb.getJobNumber());
127 		Assert.assertTrue("System Scheduled Timeoff usage leave block should have Job number 4, not " + lb.getJobNumber(), lb.getJobNumber().equals(4L));
128 		Assert.assertNotNull("System Scheduled Timeoff usage leave block's work area should not be null", lb.getWorkArea());
129 		Assert.assertTrue("System Scheduled Timeoff usage leave block should have work area 1001, not " + lb.getWorkArea(), lb.getWorkArea().equals(1001L));
130 		Assert.assertNotNull("System Scheduled Timeoff usage leave block's task should not be null", lb.getTask());
131 		Assert.assertTrue("System Scheduled Timeoff usage leave block should have task 0, not " + lb.getTask(), lb.getTask().equals(0L));
132 		
133 		// there should be one accrualed leave blocks of 4 hours on 04/11/2012
134 		intervalDate = new DateTime(2012, 4, 11, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
135 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
136 		Assert.assertTrue("There should be 1 leave block for date 04/11/2012.", leaveBlockList.size()==1);
137 		lb = leaveBlockList.get(0);
138 		Assert.assertNotNull("lm_sys_schd_timeoff_id should NOT be null for holiday accrual leave block", lb.getScheduleTimeOffId());
139 		Assert.assertTrue("lm_sys_schd_timeoff_id should be 5005, not " + lb.getScheduleTimeOffId(), lb.getScheduleTimeOffId().equals("5005"));
140 		Assert.assertTrue("Leave Block Type of leave block should be " + LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE + ", not " + lb.getLeaveBlockType()
141 				, lb.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE));
142 		Assert.assertTrue("Requst status of leave block should be " + HrConstants.REQUEST_STATUS.APPROVED + ", not " + lb.getRequestStatus()
143 				, lb.getRequestStatus().equals(HrConstants.REQUEST_STATUS.APPROVED));
144 		Assert.assertTrue("Hours of the leave block for date 04/11/2012 should be 4, not " + lb.getLeaveAmount().toString(), lb.getLeaveAmount().equals(new BigDecimal(4)));	
145 		
146 		// the disabled system scheduled time off on 04/20/2012 should not generate accruals
147 		intervalDate = new DateTime(2012, 4, 20, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
148 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
149 		Assert.assertTrue("There should be 0 leave block for date 04/20/2012.", leaveBlockList.isEmpty());
150 		
151 		// there should be 1 leave blocks on 04/30/2012, regular accrual of 8 hours
152 		intervalDate = new DateTime(2012, 4, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
153 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
154 		Assert.assertTrue("There should be 1 leave block for date 04/30/2012.", leaveBlockList.size()==1);
155 		lb = leaveBlockList.get(0);
156 		Assert.assertTrue("Hours of the regular accrual leave block for date 04/30/2012 should be 8, not " + lb.getLeaveAmount().toString(), lb.getLeaveAmount().equals(new BigDecimal(8)));
157 		Assert.assertNull("lm_sys_schd_timeoff_id should be null for regular accrual leave block", lb.getScheduleTimeOffId());
158 		Assert.assertTrue("Leave Block Type of leave block should be " + LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE + ", not " + lb.getLeaveBlockType()
159 				, lb.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE));
160 		Assert.assertTrue("Requst status of leave block should be " + HrConstants.REQUEST_STATUS.APPROVED + ", not " + lb.getRequestStatus()
161 				, lb.getRequestStatus().equals(HrConstants.REQUEST_STATUS.APPROVED));
162 	}
163 	
164 	@Test
165 	/* testUser's leavePlan "testLP" has planning month of 12
166 	 * after calculateFutureAccrualUsingPlanningMonth, try to get leaveBlock for 18 months in the future
167 	 * should still get 12 or 13 leave blocks depends on the date the test is running. 
168 	 * The accrual service also goes back 1 year for accrual runs.
169 	 */
170 	public void testCalculateFutureAccrualUsingPlanningMonth() {
171 		String principal_id = "testUser";
172 		// the planning month of this leave plan is set to 12
173 		LocalDate currentDate = LocalDate.now();		
174 		LmServiceLocator.getLeaveAccrualService().calculateFutureAccrualUsingPlanningMonth(principal_id, LocalDate.now(), "admin");		
175 		int futureSize = 12;
176 		int allSize = 17;
177 		if(currentDate.getDayOfMonth() == currentDate.dayOfMonth().getMaximumValue()) {
178 			futureSize ++;
179 			allSize ++;
180 		}
181 		
182 		LocalDate startDate = currentDate.minusMonths(5);
183 		LocalDate endDate = currentDate.plusMonths(18);
184 		
185 		// lookup future leave blocks up to 18 months in the future
186 		List<LeaveBlock> leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, currentDate, endDate);
187 		
188 		Assert.assertFalse("No leave blocks created by calculateF?utureAccrualUsingPlanningMonth for princiapl id " + principal_id, leaveBlockList.isEmpty());
189 		Assert.assertTrue("There should be " + futureSize + " leave blocks for employee 'testUser', not " + leaveBlockList.size(), leaveBlockList.size()== futureSize);
190 		
191 		// lookup leave blocks including past and future
192 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, startDate, endDate);
193 		Assert.assertTrue("There should be  " + allSize + " leave blocks for employee 'testUser', not " + leaveBlockList.size(), leaveBlockList.size()== allSize);
194 	}
195 	
196 	@Test
197 	/*
198 	  *testUser2 has two accrual category rules, rule 1 goes from 0 month to 5 with accrual rate of 16
199 	  *rule 2 goes from 5 to 900 with accrual rate of 24
200 	  *run accrual for testUser2 for 15 months
201 	 */
202 	public void testRunAccrualForRuleChanges() {
203 		 String principal_id = "testUser2";
204 		 LocalDate endDate = START_DATE.toLocalDate().plusMonths(15);
205 		 
206 		 List<LeaveBlock> leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
207 		 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
208 		
209 		 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
210 		 
211 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
212 		 Assert.assertTrue("There should be 14 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 14);
213 		 
214 		 // July of 2012 is the 5th month of this user's employment, the accrual rate should be 16
215 		 DateTime intervalDate = new DateTime(2012, 7, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
216 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
217 		 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date 07/31/2012.", leaveBlockList.size()==1);
218 		 LeaveBlock lb = leaveBlockList.get(0);
219 		 Assert.assertTrue("Hours of the leave block on date 07/31/2012 for employee " + principal_id + " should be 16, not " + lb.getLeaveAmount().toString()
220 				 , lb.getLeaveAmount().equals(new BigDecimal(16)));
221 		 
222 		 // August of 2012 is the 6th month of this user's employment, the accrual rate should be 24 from now on
223 		 intervalDate = new DateTime(2012, 8, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
224 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
225 		 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date 08/31/2012.", leaveBlockList.size()==1);
226 		 lb = leaveBlockList.get(0);
227 		 Assert.assertTrue("Hours of the leave block for date 08/31/2012 for employee " + principal_id + " should be 24, not " + lb.getLeaveAmount().toString()
228 				 , lb.getLeaveAmount().equals(new BigDecimal(24)));
229 		 
230 	}
231 	@Test
232 	/* testUser3's leavePlan has 2 accrual categories with different accrual intervals
233 	 * testAC3 has accrual interval semi-monthly
234 	 * testAC4 has accrual interval monthly
235 	 */
236 	public void testRunAccrualWithDifferentAccrualIntervals() {
237 		 String principal_id = "testUser3";
238 		 List<LeaveBlock> leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), END_DATE.toLocalDate());
239 		 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
240 		 
241 		 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, END_DATE, false, "admin");
242 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), END_DATE.toLocalDate());
243 		 Assert.assertTrue("There should be 6 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 6);
244 		 
245 		 DateTime semiMonthlyDate = new DateTime(2012, 3, 15, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
246 		 DateTime monthlyDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
247 		 this.verifyLeaveBlocksWithDifferentAccrualIntervals(semiMonthlyDate, monthlyDate);
248 
249 		 semiMonthlyDate = new DateTime(2012, 4, 15, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
250 		 monthlyDate = new DateTime(2012, 4, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
251 		 this.verifyLeaveBlocksWithDifferentAccrualIntervals(semiMonthlyDate, monthlyDate);
252 		 
253 	}
254 	public void verifyLeaveBlocksWithDifferentAccrualIntervals(DateTime semiMonthlyDate, DateTime monthlyDate) {
255 		 String principal_id = "testUser3";
256 		 List<LeaveBlock> leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, semiMonthlyDate.toLocalDate());
257 		 Assert.assertTrue("There should be 1 leave block for date " + semiMonthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
258 		 LeaveBlock lb = leaveBlockList.get(0);
259 		 Assert.assertTrue("Hours of the leave block on date " + semiMonthlyDate.toString() + " should be 8, not " + lb.getLeaveAmount().toString(), lb.getLeaveAmount().equals(new BigDecimal(8)));
260 		 Assert.assertTrue("Leave code of the leave block on date " + semiMonthlyDate.toString() + " should be EC1, not " + lb.getEarnCode(), lb.getEarnCode().equals("EC1"));
261 		 Assert.assertTrue("accrual_category of the leave block on date " + semiMonthlyDate.toString() + " should be testAC3, not " + lb.getAccrualCategory(), lb.getAccrualCategory().equals("testAC3"));
262 		
263 		
264 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
265 		 Assert.assertTrue("There should be 2 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==2);
266 		 for(LeaveBlock aLeaveBlock : leaveBlockList) {
267 			 if(aLeaveBlock.getAccrualCategory().equals("testAC3")) {
268 				 Assert.assertTrue("Leave code of the leave block with accrualCategory testAC3 on date " + monthlyDate.toString() + " should be EC1, not " + aLeaveBlock.getEarnCode()
269 						 , aLeaveBlock.getEarnCode().equals("EC1")); 
270 				 Assert.assertTrue("Hours of the leave block with accrualCategory testAC4 on date " + monthlyDate.toString() + " should be 8, not " + aLeaveBlock.getLeaveAmount().toString()
271 						 , aLeaveBlock.getLeaveAmount().equals(new BigDecimal(8)));
272 			 } else if(aLeaveBlock.getAccrualCategory().equals("testAC4")) {
273 				 Assert.assertTrue("Leave code of the leave block with accrualCategory testAC4 on date " + monthlyDate.toString() + " should be EC2, not " + aLeaveBlock.getEarnCode()
274 						 , aLeaveBlock.getEarnCode().equals("EC2")); 
275 				 Assert.assertTrue("Hours of the leave block with accrualCategory testAC4 on date " + monthlyDate.toString() + " should be 24, not " + aLeaveBlock.getLeaveAmount().toString()
276 						 , aLeaveBlock.getLeaveAmount().equals(new BigDecimal(24)));
277 			 } else {
278 				 Assert.fail("Leave block on date " + monthlyDate.toString() + " should not have accrual_category " + aLeaveBlock.getAccrualCategory());
279 			 }
280 		 }
281 	}
282 	
283 	@Test
284 	/* testUser4 has PrincipalHRAttributes that's associated with 2 accrual categories, one is testAC5, the other is testAC6
285 	 * testAC5 has minimum accrual of 0.5, proration = true
286 	 * testAC6 has minimum accrual of 0
287 	 * testUser4 has records of principalHRAttributes, the employment is from 03/18/2012 to 08/08/2012
288 	 * There should not be accrual for testAC5 in March and August of 2012 since minimum percentage is not reached
289 	 */
290 	public void testMinNotReachedProrationTrueFirstLastPeriod() {
291 		 String principal_id = "testUser4";
292 		 DateTime end = new DateTime(2012, 9, 25, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
293 		 List<LeaveBlock> leaveBlockList =  LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), end.toLocalDate());
294 		 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
295 		 
296 		 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, end, false, "admin");
297 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), end.toLocalDate());
298 		 Assert.assertTrue("There should be 10 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 10);
299 		 
300 		 DateTime monthlyDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
301 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
302 		 Assert.assertTrue("There should be 1 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
303 		 LeaveBlock lb = leaveBlockList.get(0);
304 		 Assert.assertTrue("Leave block on date " + monthlyDate.toString() + " should have accrual_category testAC6, not " + lb.getAccrualCategory()
305 				 , lb.getAccrualCategory().equals("testAC6"));
306 		 Assert.assertTrue("Leave block on date " + monthlyDate.toString() + " should have 7 hours, not " + lb.getLeaveAmount()
307 				 , lb.getLeaveAmount().equals(new BigDecimal(7)));
308 		
309 		 monthlyDate = new DateTime(2012, 4, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
310 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
311 		 Assert.assertTrue("There should be 2 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==2);
312 		 
313 // should the accrual of the last days show up on the end day or the interval day of the last pay period?????
314 		 monthlyDate = new DateTime(2012, 8, 8, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
315 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
316 		 Assert.assertTrue("There should be 1 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
317 		 lb = leaveBlockList.get(0);
318 		 Assert.assertTrue("Leave block on date " + monthlyDate.toString() + " should have accrual_category testAC6, not " + lb.getAccrualCategory()
319 				 , lb.getAccrualCategory().equals("testAC6"));
320 		 Assert.assertTrue("Leave block on date " + monthlyDate.toString() + " should have 4 hours, not " + lb.getLeaveAmount()
321 				 , lb.getLeaveAmount().equals(new BigDecimal(4)));
322 		 
323 		 monthlyDate = new DateTime(2012, 8, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
324 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
325 		 Assert.assertTrue("There should NOT be any leave blocks for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==0);
326 	}
327 	@Test
328 	/* testUser9 has PrincipalHRAttributes that's associated with accrual categories "testAC12"
329 	 * testAC12 has minimum accrual of 0.5, proration = true, fte of the ac rule is 8
330 	 * testUser9 has records of principalHRAttributes, the employment is from 03/10/2012 to 08/20/2012
331 	 * There should be partial fte accrued for testAC12 in March and August of 2012 since minimum percentage is reached
332 	 */
333 	public void testMinReachedProrationTrueFirstLastPeriod() {
334 		String principal_id = "testUser9";
335 		DateTime end = new DateTime(2012, 9, 25, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
336 		 List<LeaveBlock> leaveBlockList =  LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), end.toLocalDate());
337 		 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
338 		 
339 		 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, end, false, "admin");
340 		 leaveBlockList =  LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), end.toLocalDate());
341 		 Assert.assertTrue("There should be 6 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 6);
342 		 
343 		 DateTime monthlyDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
344 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
345 		 Assert.assertTrue("There should be 1 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
346 		 LeaveBlock lb = leaveBlockList.get(0);
347 		 Assert.assertTrue("Leave block on date " + monthlyDate.toString() + " should have 5 hours, not " + lb.getLeaveAmount()
348 				 , lb.getLeaveAmount().equals(new BigDecimal(5)));
349 		
350 		 monthlyDate = new DateTime(2012, 4, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
351 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
352 		 Assert.assertTrue("There should be 1 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
353 		 lb = leaveBlockList.get(0);
354 		 Assert.assertTrue("Leave block on date " + monthlyDate.toString() + " should have 8 hours, not " + lb.getLeaveAmount()
355 				 , lb.getLeaveAmount().equals(new BigDecimal(8)));
356 		 
357 		 monthlyDate = new DateTime(2012, 8, 20, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
358 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
359 		 Assert.assertTrue("There should be 1 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
360 		 lb = leaveBlockList.get(0);
361 		 Assert.assertTrue("Leave block on date " + monthlyDate.toString() + " should have 5 hours, not " + lb.getLeaveAmount()
362 				 , lb.getLeaveAmount().equals(new BigDecimal(5)));
363 		 
364 		 monthlyDate = new DateTime(2012, 8, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
365 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
366 		 Assert.assertTrue("There should NOT be any leave blocks for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==0);
367 	}
368 	@Test
369 	/* testUser10 has PrincipalHRAttributes that's associated with accrual categories "testAC13"
370 	 * testAC13 has minimum accrual of 0.5, proration = false
371 	 * testUser10 has records of principalHRAttributes, the employment is from 03/10/2012 to 08/20/2012
372 	 * There should be whole fte accrued for testAC13 in March and August of 2012 since minimum percentage is reached
373 	 */
374 	public void testMinReachedProrationFalseFirstLastPeriod() {
375 		String principal_id = "testUser10";
376 		DateTime end = new DateTime(2012, 9, 25, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
377 		List<LeaveBlock> leaveBlockList =  LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), end.toLocalDate());
378 		Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
379 			 
380 		LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, end, false, "admin");
381 		leaveBlockList =  LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), end.toLocalDate());
382 		Assert.assertTrue("There should be 6 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 6);
383 			 
384 		DateTime monthlyDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
385 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
386 		Assert.assertTrue("There should be 1 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
387 		LeaveBlock lb = leaveBlockList.get(0);
388 		Assert.assertTrue("Leave block on date " + monthlyDate.toString() + " should have 8 hours, not " + lb.getLeaveAmount()
389 			 , lb.getLeaveAmount().equals(new BigDecimal(8)));
390 		
391 		monthlyDate = new DateTime(2012, 4, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
392 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
393 		Assert.assertTrue("There should be 1 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
394 		lb = leaveBlockList.get(0);
395 		Assert.assertTrue("Leave block on date " + monthlyDate.toString() + " should have 8 hours, not " + lb.getLeaveAmount()
396 			 , lb.getLeaveAmount().equals(new BigDecimal(8)));
397 		
398 		monthlyDate = new DateTime(2012, 8, 20, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
399 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
400 		Assert.assertTrue("There should be 1 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
401 		lb = leaveBlockList.get(0);
402 		Assert.assertTrue("Leave block on date " + monthlyDate.toString() + " should have 8 hours, not " + lb.getLeaveAmount()
403 				, lb.getLeaveAmount().equals(new BigDecimal(8)));
404 			 
405 		monthlyDate = new DateTime(2012, 8, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
406 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
407 		Assert.assertTrue("There should NOT be any leave blocks for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==0);		
408 	}
409 	
410 	@Test
411 	/* testUser11 has PrincipalHRAttributes that's associated with accrual categories "testAC14"
412 	 * testAC14 has minimum accrual of 0.5, proration = false
413 	 * testUser11 has records of principalHRAttributes, the employment is from 03/20/2012 to 08/10/2012
414 	 * There should NOT be accrual leave blocks for testAC14 in March and August of 2012 since minimum percentage is NOT reached
415 	 */
416 	public void testMinNotReachedProrationFalseFirstLastPeriod() {
417 		String principal_id = "testUser11";
418 		DateTime end = new DateTime(2012, 9, 25, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
419 		List<LeaveBlock> leaveBlockList =  LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), end.toLocalDate());
420 		Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
421 			 
422 		LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, end, false, "admin");
423 		leaveBlockList =  LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), end.toLocalDate());
424 		Assert.assertTrue("There should be 4 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 4);
425 			 
426 		DateTime monthlyDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
427 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
428 		Assert.assertTrue("There should be 0 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.isEmpty());
429 		
430 		monthlyDate = new DateTime(2012, 4, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
431 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
432 		Assert.assertTrue("There should be 1 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
433 		LeaveBlock lb = leaveBlockList.get(0);
434 		Assert.assertTrue("Leave block on date " + monthlyDate.toString() + " should have 8 hours, not " + lb.getLeaveAmount()
435 			 , lb.getLeaveAmount().equals(new BigDecimal(8)));
436 		
437 		monthlyDate = new DateTime(2012, 8, 20, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
438 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
439 		Assert.assertTrue("There should be 0 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.isEmpty());
440 					 
441 		monthlyDate = new DateTime(2012, 8, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
442 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
443 		Assert.assertTrue("There should NOT be any leave blocks for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==0);		
444 	}
445 	@Test
446 	/* testUser5's service date is 2012-03-10
447 	 * testUser5 has two accrual category rules, rule 1 goes from 0 month to 12 with accrual rate of 16
448 	 * rule 2 goes from 12 to 900 with accrual rate of 24
449 	 * accrual category associated with the two rules has Proration=false, and minimum percentage of 0.5
450 	 * run accrual for testUser5 for 18 months
451 	 */
452 	public void testMinReachedProrationFalseAndRuleChange() {
453 		 String principal_id = "testUser5";
454 		 LocalDate endDate = START_DATE.toLocalDate().plusMonths(18);
455 		 
456 		 List<LeaveBlock> leaveBlockList =  LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
457 		 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
458 		
459 		 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
460 		 
461 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
462 		 Assert.assertTrue("There should be 17 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 17);
463 		 
464 		 // 03/31/2012 is the first accrual interval date, service starts on 2012-03-10, so minimum percentage is reached for that month
465 		 // since proration is false, the whole accrual rate is created for the first pay period
466 		 DateTime intervalDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
467 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
468 		 Assert.assertTrue("There should be 1 leave block for date " + intervalDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
469 		 LeaveBlock lb = leaveBlockList.get(0);
470 		 Assert.assertTrue("Leave block on date " + intervalDate.toString() + " should have 16 hours, not " + lb.getLeaveAmount()
471 				 , lb.getLeaveAmount().equals(new BigDecimal(16)));
472 		 
473 		 // 02/28/2013 is the 12th month of this user's employment, the accrual rate should be 16
474 		 intervalDate = new DateTime(2013, 2, 28, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
475 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
476 		 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date 02/28/2013.", leaveBlockList.size()==1);
477 		 lb = leaveBlockList.get(0);
478 		 Assert.assertTrue("Hours of the leave block on date " + intervalDate.toString() + " should be 16, not " + lb.getLeaveAmount().toString()
479 				 , lb.getLeaveAmount().equals(new BigDecimal(16)));
480 		 
481 		 // 03/31/2013 is the 13th month of this user's employment, since the minimum percentage of days is meet for
482 		 // that month (03/10 - 03/31) and proration = false, the accrual rate should be 24 from now on
483 		 intervalDate = new DateTime(2013, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
484 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
485 		 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
486 		 lb = leaveBlockList.get(0);
487 		 Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
488 				 , lb.getLeaveAmount().equals(new BigDecimal(24)));
489 	}
490 	@Test
491 	/* testUser12's service date is 2012-03-20
492 	 * testUser12 has two accrual category rules, rule 1 goes from 6 month to 12 with accrual rate of 16
493 	 * rule 2 goes from 6 to 900 with accrual rate of 24
494 	 * accrual category "testAC15" is associated with the two rules. testAC15 has Proration=false, and minimum percentage of 0.5
495 	 * run accrual for testUser12 for 12 months
496 	 * for 2012-09-30, the accrual should still be 16 since the minimum is NOT reached for the rule 2
497 	 */
498 	public void testMinNotReachedProrationFalseAndRuleChange() {
499 		String principal_id = "testUser12";
500 		LocalDate endDate = START_DATE.toLocalDate().plusMonths(18);
501 		 
502 		List<LeaveBlock> leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);		 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
503 
504         LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
505 		 
506 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
507 		 Assert.assertTrue("There should be 17 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 17);
508 		 // 08/31/2013 
509 		 DateTime intervalDate = new DateTime(2012, 8, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
510 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
511 		 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
512 		 LeaveBlock lb = leaveBlockList.get(0);
513 		 Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 16, not " + lb.getLeaveAmount().toString()
514 				 , lb.getLeaveAmount().equals(new BigDecimal(16)));		
515 		 
516 		 // 09/30/2012 is the 6th month of this user's employment, since minimum percentage is not reached, the accrual rate should be 16
517 		 intervalDate = new DateTime(2012, 9, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
518 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
519 		 Assert.assertTrue("There should be 1 leave block for date " + intervalDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
520 		 lb = leaveBlockList.get(0);
521 		 Assert.assertTrue("Leave block on date " + intervalDate.toString() + " should have 16 hours, not " + lb.getLeaveAmount()
522 				 , lb.getLeaveAmount().equals(new BigDecimal(16)));
523 		 
524 		 // 10/31/2013 
525 		 intervalDate = new DateTime(2012, 10, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
526 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
527 		 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
528 		 lb = leaveBlockList.get(0);
529 		 Assert.assertTrue("Hours of the leave block on date " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
530 				 , lb.getLeaveAmount().equals(new BigDecimal(24)));
531 	}
532 	@Test
533 	/* testUser13's service date is 2012-03-10
534 	 * testUser13 has two accrual category rules, rule 1 goes from 0 month to 6 with accrual rate of 16
535 	 * rule 2 goes from 6 to 900 with accrual rate of 24
536 	 * accrual category "testAC16" is associated with the two rules. testAC16 has Proration=true, and minimum percentage of 0.5
537 	 * run accrual for testUser13 for 12 months
538 	 * for 2012-09-30, the accrual should be based on actual work days for those two rules, ie 22 because the minimum is reached for rule 2
539 	 */
540 	public void testMinReachedProrationTrueAndRuleChange() {
541 		String principal_id = "testUser13";
542 		LocalDate endDate = START_DATE.toLocalDate().plusMonths(18);
543 		 
544 		List<LeaveBlock> leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
545 		Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
546 		
547 		LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
548 		 
549 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
550 		Assert.assertTrue("There should be 17 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 17);
551 		// 08/31/2013 
552 		DateTime intervalDate = new DateTime(2012, 8, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
553 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
554 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
555 		LeaveBlock lb = leaveBlockList.get(0);
556 		Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 16, not " + lb.getLeaveAmount().toString()
557 				 , lb.getLeaveAmount().equals(new BigDecimal(16)));		
558 		 
559 		// 09/30/2012 is the 6th month of this user's employment, since minimum percentage is reached, the accrual rate is 16 for 6 work days
560 		// and 24 hrs for 14 work days, so the final accrual hrs is 22
561 		intervalDate = new DateTime(2012, 9, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
562 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
563 		Assert.assertTrue("There should be 1 leave block for date " + intervalDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
564 		lb = leaveBlockList.get(0);
565 		Assert.assertTrue("Leave block on date " + intervalDate.toString() + " should have 22 hours, not " + lb.getLeaveAmount()
566 			 , lb.getLeaveAmount().equals(new BigDecimal(22)));
567 		 
568 		// 10/31/2013 
569 		intervalDate = new DateTime(2012, 10, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
570 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
571 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
572 		lb = leaveBlockList.get(0);
573 		Assert.assertTrue("Hours of the leave block on date " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
574 			 , lb.getLeaveAmount().equals(new BigDecimal(24)));		
575 	}
576 	@Test
577 	/* testUser14's service date is 2012-03-20
578 	 * testUser14 has two accrual category rules, rule 1 goes from 0 month to 6 with accrual rate of 16
579 	 * rule 2 goes from 6 to 900 with accrual rate of 24
580 	 * accrual category "testAC17" is associated with the two rules. testAC17 has Proration=true, and minimum percentage of 0.5
581 	 * run accrual for testUser14 for 12 months
582 	 * for 2012-09-30, the accrual should be 16 since the minimum is NOT reached for the rule 2
583 	 */
584 	public void testMinNotReachedProrationTrueAndRuleChange() {
585 		String principal_id = "testUser14";
586 		LocalDate endDate = START_DATE.toLocalDate().plusMonths(18);
587 		 
588 		List<LeaveBlock> leaveBlockList =  LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
589 		Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
590 		
591 		LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
592 		// only 16 leave blocks since the first interval 03/31/2012 does not have accruals due to minimum not reached
593 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
594 		Assert.assertTrue("There should be 16 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 16);
595 		
596 		// 03/31/2013 
597 		DateTime intervalDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
598 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
599 		Assert.assertTrue("There should be 0 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.isEmpty());
600 			
601 		// 08/31/2013 
602 		intervalDate = new DateTime(2012, 8, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
603 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
604 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
605 		LeaveBlock lb = leaveBlockList.get(0);
606 		Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 16, not " + lb.getLeaveAmount().toString()
607 				 , lb.getLeaveAmount().equals(new BigDecimal(16)));		
608 		 
609 		// 09/30/2012 is the 6th month of this user's employment, since minimum percentage is NOT reached, the accrual rate should be 16
610 		intervalDate = new DateTime(2012, 9, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
611 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
612 		Assert.assertTrue("There should be 1 leave block for date " + intervalDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
613 		lb = leaveBlockList.get(0);
614 		Assert.assertTrue("Leave block on date " + intervalDate.toString() + " should have 16 hours, not " + lb.getLeaveAmount()
615 			 , lb.getLeaveAmount().equals(new BigDecimal(16)));
616 		 
617 		// 10/31/2013 
618 		intervalDate = new DateTime(2012, 10, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
619 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
620 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
621 		lb = leaveBlockList.get(0);
622 		Assert.assertTrue("Hours of the leave block on date " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
623 			 , lb.getLeaveAmount().equals(new BigDecimal(24)));			
624 	}
625 	@Test
626 	/* testUser6's service date is 2012-03-25
627 	 * testUser6 has two accrual category rules, rule 1 goes from 0 to 6 month with accrual rate of 16
628 	 * rule 2 goes from 6 month to 900 with accrual rate of 24
629 	 * accrual category testAC8 associated with the two rules has Proration=false, and minimum percentage of 0.5 and earn interval=semi_monthly
630 	 * run accrual for testUser5 for 10 months
631 	 */
632 	public void testMinNOTReachedProrationFalseAndRuleChange() {
633 		 String principal_id = "testUser6";
634 		 LocalDate endDate = START_DATE.toLocalDate().plusMonths(10);
635 		 
636 		 List<LeaveBlock> leaveBlockList =  LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
637 		 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
638 		
639 		 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
640 		 
641 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
642 		 Assert.assertTrue("There should be 17 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 17);
643 		 
644 		 // 03/31/2012 is the first accrual interval date, since minimum percentage is not reached (03/25-03/31) and proration=false
645 		 // there should not be leave blocks
646 		 DateTime intervalDate =new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
647 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
648 		 Assert.assertTrue("There should be 0 leave block for date " + intervalDate.toString(), leaveBlockList.isEmpty());
649 		 
650 		 // 04/15/2012 should have the first leave block for testUser6 and the accrual hours should be the full 16 
651 		 intervalDate = new DateTime(2012, 4, 15, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
652 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
653 		 Assert.assertTrue("There should be 1 leave block for date " + intervalDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
654 		 LeaveBlock lb = leaveBlockList.get(0);
655 		 Assert.assertTrue("Leave block on date " + intervalDate.toString() + " should have 16 hours, not " + lb.getLeaveAmount()
656 				 , lb.getLeaveAmount().equals(new BigDecimal(16)));
657 		 
658 		 // accrual rate for 09/15/2012 should still be 16
659 		 intervalDate = new DateTime(2012, 9, 15, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
660 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
661 		 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
662 		 lb = leaveBlockList.get(0);
663 		 Assert.assertTrue("Hours of the leave block on date " + intervalDate.toString() + " should be 16, not " + lb.getLeaveAmount().toString()
664 				 , lb.getLeaveAmount().equals(new BigDecimal(16)));
665 		 
666 		 // 09/30/2013 is the first pay interval of rule 2, since the minimum percentage is not reached (09/25-09/30)
667 		 // the accrual rate should still be 16
668 		 intervalDate = new DateTime(2012, 9, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
669 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
670 		 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
671 		 lb = leaveBlockList.get(0);
672 		 Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 16, not " + lb.getLeaveAmount().toString()
673 				 , lb.getLeaveAmount().equals(new BigDecimal(16)));
674 		 
675 		 // 10/15/2013, should use new rate of 24
676 		 intervalDate = new DateTime(2012, 10, 15, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
677 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
678 		 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
679 		 lb = leaveBlockList.get(0);
680 		 Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
681 				 , lb.getLeaveAmount().equals(new BigDecimal(24)));
682 	}
683 	
684 	@Test
685 	/* testUser7's service date is 2012-03-10
686 	 * testUser7 has two leave blocks scheduled on 04/26/2012 for 2 hours and 05/08/2012 for 5 hours, they both are NOT eligible for accrual
687 	 * testUser7 has one leave block scheduled on 05/22/1012 of 8 hours, it's eligible for accrual
688 	 * testUser7 has one leave block scheduled on 06/12/1012 of 15 hours, it's NOT eligible for accrual
689 	 * testUser7 has one accrual category rule of 32 hours of accrual rate, two jobs are eligible for leave with total of 40 standard hours
690 	 * run accrual for testUser7 for 5 months
691 	 */
692 	public void testNotEligibleForAccrualAdjustment() {
693 		String principal_id = "testUser7";
694 		LocalDate endDate = START_DATE.toLocalDate().plusMonths(5);
695 		 
696 		 List<LeaveBlock> leaveBlockList =  LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
697 		 Assert.assertTrue("There should be 4 leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.size() == 5);
698 		
699 		 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
700 		 
701 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
702 		 Assert.assertTrue("There should be 10 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 11);
703 		 
704 		 // 03/31/2012, 
705 		 DateTime intervalDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
706 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
707 		 Assert.assertTrue("There should be 1 leave block for date " + intervalDate.toString(), leaveBlockList.size() == 1);
708 		 LeaveBlock lb = leaveBlockList.get(0);
709 		 Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 22, not " + lb.getLeaveAmount().toString()
710 				 , lb.getLeaveAmount().equals(new BigDecimal(22)));
711 		 
712 		 // 04/30/2012, 
713 		 intervalDate = new DateTime(2012, 4, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
714 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
715 		 Assert.assertTrue("There should be 1 leave block for date " + intervalDate.toString(), leaveBlockList.size() == 1);
716 		 lb = leaveBlockList.get(0);
717 		 Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 32, not " + lb.getLeaveAmount().toString()
718 				 , lb.getLeaveAmount().equals(new BigDecimal(32)));
719 		 
720 		 //05/31/2012
721 		 intervalDate = new DateTime(2012, 5, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
722 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
723 		 Assert.assertTrue("There should be 2 leave block for date " + intervalDate.toString(), leaveBlockList.size() == 2);
724 		 for(LeaveBlock aLeaveBlock : leaveBlockList) {
725 			 if(aLeaveBlock.getLeaveAmount().equals(new BigDecimal(-1))) {
726 				 Assert.assertTrue("Accrual category of the leave block for date  " + intervalDate.toString() + " should be 'testAC9' , not " + aLeaveBlock.getAccrualCategory()
727 						 , aLeaveBlock.getAccrualCategory().equals("testAC9")); 
728 			 } else if(aLeaveBlock.getLeaveAmount().equals(new BigDecimal(32))) {
729 				 Assert.assertTrue("Accrual category of the leave block for date  " + intervalDate.toString() + " should be 'testAC9' , not " + aLeaveBlock.getAccrualCategory()
730 						 , aLeaveBlock.getAccrualCategory().equals("testAC9")); 
731 			 } else {
732 				 Assert.fail("Hours of the leave block for date  " + intervalDate.toString() + " should be either 32 or -1, not " + aLeaveBlock.getLeaveAmount().toString());
733 			 }
734 		 }
735 		 
736 		 //06/30/2012
737 		 // we added top limit to accrual adjustment, so the 06/12/1012 of 15 hours is counted as leave of 8 hours
738 		 intervalDate = new DateTime(2012, 6, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
739 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
740 		 Assert.assertTrue("There should be 2 leave block for date " + intervalDate.toString(), leaveBlockList.size() == 2);
741 		 for(LeaveBlock aLeaveBlock : leaveBlockList) {
742 			 if(aLeaveBlock.getLeaveAmount().equals(new BigDecimal(-3))) {
743 				 Assert.assertTrue("Accrual category of the leave block for date  " + intervalDate.toString() + " should be 'testAC9' , not " + aLeaveBlock.getAccrualCategory()
744 						 , aLeaveBlock.getAccrualCategory().equals("testAC9")); 
745 			 } else if(aLeaveBlock.getLeaveAmount().equals(new BigDecimal(32))) {
746 				 Assert.assertTrue("Accrual category of the leave block for date  " + intervalDate.toString() + " should be 'testAC9' , not " + aLeaveBlock.getAccrualCategory()
747 						 , aLeaveBlock.getAccrualCategory().equals("testAC9")); 
748 			 } else {
749 				 Assert.fail("Hours of the leave block for date  " + intervalDate.toString() + " should be either 32 or -2, not " + aLeaveBlock.getLeaveAmount().toString());
750 			 }
751 		 }
752 	}
753 	
754 	@Test
755 	/* testUser8's service date is 2012-03-10
756 	 * testUser8 has one accrual category, two entries of the same accrual category. 
757 	 * The first entry has effectiveDate = 2012-03-01. The rule associated with it has 16 as the accrual rate
758 	 * the second entry has effectiveDate = 2012-5-01. The rule associated with it has 32 as the accrual rate
759 	 * run accrual for testUser8 for 6 months
760 	 */
761 	public void testAccrualCategoryChanges() {
762 		String principal_id = "testUser8";
763 		LocalDate endDate = START_DATE.toLocalDate().plusMonths(6);
764 		 
765 		 List<LeaveBlock> leaveBlockList =  LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
766 		 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
767 		
768 		 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
769 		 
770 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
771 		 Assert.assertTrue("There should be 5 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 5);		 
772 		 
773 		 // 03/31/2012, 
774 		 DateTime intervalDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
775 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
776 		 Assert.assertTrue("There should be 1 leave block for date " + intervalDate.toString(), leaveBlockList.size() == 1);
777 		 LeaveBlock lb = leaveBlockList.get(0);
778 		 Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 11, not " + lb.getLeaveAmount().toString()
779 				 , lb.getLeaveAmount().equals(new BigDecimal(11)));
780 		 
781 		 // 04/30/2012, 
782 		 intervalDate = new DateTime(2012, 4, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
783 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
784 		 Assert.assertTrue("There should be 1 leave block for date " + intervalDate.toString(), leaveBlockList.size() == 1);
785 		 lb = leaveBlockList.get(0);
786 		 Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 16, not " + lb.getLeaveAmount().toString()
787 				 , lb.getLeaveAmount().equals(new BigDecimal(16)));
788 		 
789 		 //05/31/2012
790 		 intervalDate = new DateTime(2012, 5, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
791 		 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
792 		 Assert.assertTrue("There should be 1 leave block for date " + intervalDate.toString(), leaveBlockList.size() == 1);
793 		 lb = leaveBlockList.get(0);
794 		 Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 32, not " + lb.getLeaveAmount().toString()
795 				 , lb.getLeaveAmount().equals(new BigDecimal(32)));
796 		 
797 	}
798 	
799 	@Test
800 	/*	testUser15's service Date is 2012-03-10
801 	 * 	testUser15 has one accrual category, the effectiveDate of the AC is 2012-03-01
802 	 *  The rule associated with the AC has 24 as the accrual rate
803 	 *  There's Leave Calendar document for calendar entry 2012-04-01 -- 2012-05-01
804 	 *  run accrual for testUser15 for 6 months
805 	 */
806 	public void testLeaveBlocksWithLeaveCalendarDocId() {
807 		String principal_id = "testUser15";
808 		LocalDate endDate = START_DATE.toLocalDate().plusMonths(6);
809 		 
810 		List<LeaveBlock> leaveBlockList =  LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
811 		Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
812 		
813 		LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
814 		
815 		// 04/30/2012 
816 		DateTime intervalDate = new DateTime(2012, 4, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
817 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
818 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
819 		LeaveBlock lb = leaveBlockList.get(0);
820 		Assert.assertTrue("DocumentId of the leave block for date  " + intervalDate.toString() + " should be 5000, not " + lb.getDocumentId()
821 				 , lb.getDocumentId().equals("5000"));		
822 		 
823 	}
824 	
825 	@Test
826 	/*	testUser16's service Date is 2012-03-26 which is a Monday
827 	 * 	testUser16 has one accrual category "testAC19" with effectiveDate of 2012-03-01
828 	 *  testAC19 has proration = false, minimum percentage = 0
829 	 *  testAC19 has "pay calendar" as the earn interval, so the accrual interval will be based on the pay calendar entries of testUser16
830 	 *  testUser16 has "BI-WE" as the pay calendar, it's bi-weekly with start day as Sunday
831 	 *  The rule associated with the AC has 24 as the accrual rate
832 	 *  run accrual for testUser16 for 6 months
833 	 */
834 	public void testPayCalAsEarnInterval() {
835 		String principal_id = "testUser16";
836 		LocalDate endDate = START_DATE.toLocalDate().plusMonths(6);
837 		 
838 		List<LeaveBlock> leaveBlockList =  LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
839 		Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
840 		
841 		LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
842 		
843 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
844 		Assert.assertTrue("There should be 11 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 11);	
845 		
846 		// 03/31/2012, testAC19 has proration= false, minimum percentage = 0, so whole FTE of 24 hours is given to the first interval
847 		DateTime intervalDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
848 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
849 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
850 		LeaveBlock lb = leaveBlockList.get(0);
851 		Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
852 				 , lb.getLeaveAmount().equals(new BigDecimal(24)));
853 		
854 		// 04/28/2012
855 		intervalDate = new DateTime(2012, 4, 28, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
856 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
857 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
858 		lb = leaveBlockList.get(0);		
859 		Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
860 				 , lb.getLeaveAmount().equals(new BigDecimal(24)));
861 		// 05/12/2012
862 		intervalDate = new DateTime(2012, 5, 12, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
863 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
864 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
865 		// 08/04/2012
866 		intervalDate = new DateTime(2012, 8, 4, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
867 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
868 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
869 		// 08/18/2012
870 		intervalDate = new DateTime(2012, 8, 18, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
871 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
872 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
873 	}
874 	
875 	@Test
876 	/*	testUser17's service Date is 2012-03-26 which is a Monday
877 	 * 	testUser17 has one accrual category "testAC20" with effectiveDate of 2012-03-01
878 	 *  testAC20 has proration = true, minimum percentage = 0.5
879 	 *  testAC20 has "pay calendar" as the earn interval, so the accrual interval will be based on the pay calendar entries of testUser17
880 	 *  testUser17 has "BI-WE" as the pay calendar, it's bi-weekly with start day as Sunday
881 	 *  The rule associated with the AC has 24 as the accrual rate
882 	 *  run accrual for testUser17 for 6 months
883 	 */
884 	public void testPayCalAsEarnIntervalProrationFalseMinReached() {
885 		String principal_id = "testUser17";
886 		LocalDate endDate = START_DATE.toLocalDate().plusMonths(6);
887 		 
888 		List<LeaveBlock> leaveBlockList =  LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
889 		Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
890 		
891 		LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
892 		
893 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
894 		Assert.assertTrue("There should be 11 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 11);	
895 		
896 		// 03/31/2012, testAC20 has proration= true, minimum percentage = 0.5, so only 12 hours is given to the first interval
897 		DateTime intervalDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
898 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
899 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
900 		LeaveBlock lb = leaveBlockList.get(0);
901 		Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 12, not " + lb.getLeaveAmount().toString()
902 				 , lb.getLeaveAmount().equals(new BigDecimal(12)));
903 		
904 		// 04/28/2012
905 		intervalDate = new DateTime(2012, 4, 28, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
906 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
907 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
908 		lb = leaveBlockList.get(0);		
909 		Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
910 				 , lb.getLeaveAmount().equals(new BigDecimal(24)));
911 		// 05/12/2012
912 		intervalDate = new DateTime(2012, 5, 12, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
913 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
914 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
915 		// 08/04/2012
916 		intervalDate = new DateTime(2012, 8, 4, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
917 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
918 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
919 		// 08/18/2012
920 		intervalDate = new DateTime(2012, 8, 18, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
921 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
922 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
923 	}
924 
925 	@Test
926 	/*	testUser18's service Date is 2012-03-20 which is a Tuesday
927 	 * 	testUser18 has one accrual category "testAC21" with effectiveDate of 2012-03-01
928 	 *  testAC21 has proration = false, minimum percentage = 0
929 	 *  testAC21 has "weekly" as the earn interval
930 	 *  The rule associated with the AC has 24 as the accrual rate
931 	 *  run accrual for testUser18 for 6 months
932 	 */
933 	public void testWeeklyAsEarnInterval() {
934 		String principal_id = "testUser18";
935 		LocalDate endDate = START_DATE.toLocalDate().plusMonths(6);
936 		 
937 		List<LeaveBlock> leaveBlockList =  LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
938 		Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
939 		
940 		LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
941 		
942 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
943 		Assert.assertTrue("There should be 22 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 22);	
944 		
945 		// 03/24/2012
946 		DateTime intervalDate = new DateTime(2012, 3, 24, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
947 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
948 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
949 		LeaveBlock lb = leaveBlockList.get(0);
950 		Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
951 				 , lb.getLeaveAmount().equals(new BigDecimal(24)));		
952 		// 03/31/2012
953 		intervalDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
954 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
955 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
956 		lb = leaveBlockList.get(0);		
957 		Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
958 				 , lb.getLeaveAmount().equals(new BigDecimal(24)));
959 		// 08/11/2012
960 		intervalDate = new DateTime(2012, 8, 11, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
961 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
962 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
963 		lb = leaveBlockList.get(0);		
964 		Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
965 				 , lb.getLeaveAmount().equals(new BigDecimal(24)));
966 		// 08/18/2012
967 		intervalDate = new DateTime(2012, 8, 18, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
968 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
969 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
970 		lb = leaveBlockList.get(0);		
971 		Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
972 				 , lb.getLeaveAmount().equals(new BigDecimal(24)));
973 	}
974 	@Test
975 	/*	testUser19's service Date is 2012-03-20
976 	 * 	testUser19 has one accrual category "testAC22" with effectiveDate of 2012-03-01
977 	 *  testAC22 has "yearly" as the earn interval
978 	 *  The rule associated with the AC has 100 hours as the accrual rate
979 	 *  run accrual for testUser19 for 18 months
980 	 */
981 	public void testYearlyAsEarnInterval() {
982 		String principal_id = "testUser19";
983 		LocalDate endDate = START_DATE.toLocalDate().plusMonths(18);
984 		 
985 		List<LeaveBlock> leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
986 		Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
987 		
988 		LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
989 		
990 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
991 		Assert.assertTrue("There should be 1 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 1);
992 		
993 		// 12/31/2013
994 		DateTime intervalDate = new DateTime(2012, 12, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
995 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
996 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
997 		LeaveBlock lb = leaveBlockList.get(0);
998 		Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 100, not " + lb.getLeaveAmount().toString()
999 				 , lb.getLeaveAmount().equals(new BigDecimal(100)));		
1000 	}
1001 	@Test
1002 	/*	testUser20's service Date is 2012-03-20
1003 	 * 	testUser20 has one accrual category "testAC23" with effectiveDate of 2012-03-01
1004 	 *  testAC23 has "daily" as the earn interval
1005 	 *  The rule associated with the AC has 2 as the accrual rate
1006 	 *  run accrual for testUser20 for 3 months
1007 	 */
1008 	public void testDailyAsEarnInterval() {
1009 		String principal_id = "testUser20";
1010 		LocalDate endDate = START_DATE.toLocalDate().plusMonths(3);
1011 		 
1012 		List<LeaveBlock> leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
1013 		Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
1014 		
1015 		LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
1016 		
1017 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
1018 		Assert.assertTrue("There should be 44 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 44);
1019 		
1020 		// 03/20/2012
1021 		DateTime intervalDate = new DateTime(2012, 3, 20, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
1022 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
1023 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
1024 		LeaveBlock lb = leaveBlockList.get(0);
1025 		Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 2, not " + lb.getLeaveAmount().toString()
1026 				 , lb.getLeaveAmount().equals(new BigDecimal(2)));	
1027 		
1028 		// 05/28/2012
1029 		intervalDate = new DateTime(2012, 5, 18, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
1030 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
1031 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
1032 		lb = leaveBlockList.get(0);		
1033 		Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 2, not " + lb.getLeaveAmount().toString()
1034 				 , lb.getLeaveAmount().equals(new BigDecimal(2)));
1035 	}
1036 
1037 	@Test
1038 	/*	testUser21's service Date is 2012-03-20
1039 	 * 	testUser21 has one accrual category "testAC24" with effectiveDate of 2012-03-01
1040 	 *  testAC24 has "monthly" as the earn interval
1041 	 *  There's a accrual ssto leave block on 04/10/2012 for testUser21,no usage lb, so that's a banked ssto accrual
1042 	 *  run accrual for testUser21 for 3 months, the accrual service should not delete the existing leaveblock
1043 	 *  and should not generate new ssto accrual/usage lbs on 04/10/2012
1044 	 *  There's a balance transferred leave block on 04/15/2012, sstoId is not empty, 
1045 	 *  accrual service should not generate ssto accrual leave blocks on 04/15/2012 
1046 	 */
1047 	public void testSSTOBankedOrTransferred() {
1048 		String principal_id = "testUser21";
1049 		LocalDate endDate = START_DATE.toLocalDate().plusMonths(3);
1050 		 
1051 		List<LeaveBlock> leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
1052 		Assert.assertTrue("There should be 1 leave blocks for princiapl id before runAccrual" + principal_id, leaveBlockList.size() == 2);
1053 		
1054 		LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
1055 		
1056 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
1057 		Assert.assertTrue("There should be 4 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 4);
1058 		
1059 		// 04/10/2012
1060 		DateTime intervalDate = new DateTime(2012, 4, 10, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
1061 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
1062 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
1063 		LeaveBlock lb = leaveBlockList.get(0);
1064 		Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 8, not " + lb.getLeaveAmount().toString()
1065 				 , lb.getLeaveAmount().equals(new BigDecimal(8)));	
1066 		Assert.assertTrue("LeaveBlockId of the leave block for date  " + intervalDate.toString() + " should be 5004, not " + lb.getLmLeaveBlockId()
1067 				 , lb.getLmLeaveBlockId().equals("5004"));	
1068 		
1069 		// 04/15/2012
1070 		intervalDate = new DateTime(2012, 4, 15, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
1071 		leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
1072 		Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
1073 		lb = leaveBlockList.get(0);		
1074 		Assert.assertTrue("Hours of the leave block for date  " + intervalDate.toString() + " should be 4, not " + lb.getLeaveAmount().toString()
1075 				 , lb.getLeaveAmount().equals(new BigDecimal(4)));	
1076 		Assert.assertTrue("LeaveBlockId of the leave block for date  " + intervalDate.toString() + " should be 5005, not " + lb.getLmLeaveBlockId()
1077 				 , lb.getLmLeaveBlockId().equals("5005"));
1078 	}
1079 
1080 }