1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.department.lunch.rule;
17
18 import java.math.BigDecimal;
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.joda.time.DateTime;
24 import org.junit.Assert;
25 import org.junit.Test;
26 import org.kuali.hr.KPMEWebTestCase;
27 import org.kuali.kpme.core.FunctionalTest;
28 import org.kuali.kpme.core.util.HrConstants;
29 import org.kuali.kpme.core.util.TKUtils;
30 import org.kuali.kpme.tklm.api.time.timeblock.TimeBlock;
31 import org.kuali.kpme.tklm.api.time.timehourdetail.TimeHourDetail;
32 import org.kuali.kpme.tklm.time.rules.lunch.department.DeptLunchRule;
33 import org.kuali.kpme.tklm.time.service.TkServiceLocator;
34 import org.kuali.kpme.tklm.time.timesheet.TimesheetDocument;
35 import org.kuali.kpme.tklm.utils.TkTestUtils;
36 import org.kuali.rice.krad.service.KRADServiceLocator;
37 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
38
39 @FunctionalTest
40 public class DepartmentLunchRuleTest extends KPMEWebTestCase {
41 private DateTime JAN_AS_OF_DATE = new DateTime(2010, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
42
43 @Test
44 public void testDepartmentLunchRuleFetch() throws Exception{
45 DeptLunchRule deptLunchRule = new DeptLunchRule();
46 deptLunchRule.setActive(true);
47 deptLunchRule.setDept("TEST");
48 deptLunchRule.setWorkArea(1234L);
49 deptLunchRule.setEffectiveLocalDate(JAN_AS_OF_DATE.toLocalDate());
50 deptLunchRule.setJobNumber(0L);
51 deptLunchRule.setPrincipalId("admin");
52 deptLunchRule.setDeductionMins(new BigDecimal(30));
53 deptLunchRule.setShiftHours(new BigDecimal(6));
54 deptLunchRule.setTkDeptLunchRuleId("1001");
55 deptLunchRule.setUserPrincipalId("admin");
56 deptLunchRule.setGroupKeyCode("IU-BL");
57
58 KRADServiceLocatorWeb.getLegacyDataAdapter().save(deptLunchRule);
59
60 deptLunchRule = TkServiceLocator.getDepartmentLunchRuleService().getDepartmentLunchRule("TEST",
61 1234L, "admin", 0L, "IU-BL", JAN_AS_OF_DATE.toLocalDate());
62 Assert.assertTrue("dept lunch rule fetched ", deptLunchRule!=null);
63
64 }
65
66
67
68
69
70 @Test
71 public void testDepartmentLunchRule() throws Exception {
72
73 DeptLunchRule deptLunchRule = new DeptLunchRule();
74 deptLunchRule.setActive(true);
75 deptLunchRule.setDept("TEST-DEPT");
76 deptLunchRule.setWorkArea(1234L);
77 deptLunchRule.setEffectiveLocalDate(JAN_AS_OF_DATE.toLocalDate());
78 deptLunchRule.setJobNumber(1L);
79 deptLunchRule.setPrincipalId("edna");
80 deptLunchRule.setDeductionMins(new BigDecimal(30));
81 deptLunchRule.setShiftHours(new BigDecimal(6));
82 deptLunchRule.setTkDeptLunchRuleId("1001");
83 deptLunchRule.setUserPrincipalId("admin");
84 deptLunchRule.setGroupKeyCode("IU-BL");
85
86 KRADServiceLocatorWeb.getLegacyDataAdapter().save(deptLunchRule);
87
88 deptLunchRule = TkServiceLocator.getDepartmentLunchRuleService().getDepartmentLunchRule("TEST-DEPT",
89 1234L, "edna", 1L, "IU-BL", JAN_AS_OF_DATE.toLocalDate());
90 Assert.assertTrue("dept lunch rule fetched ", deptLunchRule!=null);
91
92 TimesheetDocument doc = TkTestUtils.populateTimesheetDocument(JAN_AS_OF_DATE, "edna");
93
94 List<TimeBlock> timeBlocks = new ArrayList<TimeBlock>(doc.getTimeBlocks());
95 for(TimeBlock tb : doc.getTimeBlocks()){
96 TimeBlock.Builder b = TimeBlock.Builder.create(tb);
97 b.setClockLogCreated(true);
98 timeBlocks.add(b.build());
99 }
100 for(TimeBlock tb : timeBlocks) {
101 if(tb.getHours().compareTo(deptLunchRule.getShiftHours()) == 1) {
102 for(TimeHourDetail thd : tb.getTimeHourDetails()){
103
104 if(!StringUtils.equals(thd.getEarnCode(), HrConstants.LUNCH_EARN_CODE)){
105 Assert.assertEquals(new BigDecimal(9.50).setScale(2), tb.getHours());
106 }
107 }
108 }
109 }
110
111 }
112
113 @Test
114 public void testSearchDepartmentLunchRules() throws Exception {
115
116
117
118
119
120 }
121
122 }