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