1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
41
42
43
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
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
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
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
87
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
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
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
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
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
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
166
167
168
169
170 public void testCalculateFutureAccrualUsingPlanningMonth() {
171 String principal_id = "testUser";
172
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
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
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
199
200
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
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
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
233
234
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
285
286
287
288
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
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
329
330
331
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
370
371
372
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
412
413
414
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
447
448
449
450
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
465
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
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
482
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
492
493
494
495
496
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
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
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
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
534
535
536
537
538
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
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
560
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
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
578
579
580
581
582
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
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
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
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
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
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
627
628
629
630
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
645
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
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
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
667
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
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
686
687
688
689
690
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
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
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
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
737
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
756
757
758
759
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
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
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
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
801
802
803
804
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
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
827
828
829
830
831
832
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
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
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
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
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
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
877
878
879
880
881
882
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
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
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
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
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
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
927
928
929
930
931
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
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
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
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
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
976
977
978
979
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
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
1003
1004
1005
1006
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
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
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
1039
1040
1041
1042
1043
1044
1045
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
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
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 }