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.List;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.joda.time.DateTime;
23 import org.junit.Assert;
24 import org.junit.Test;
25 import org.kuali.hr.KPMEWebTestCase;
26 import org.kuali.kpme.core.FunctionalTest;
27 import org.kuali.kpme.core.util.HrConstants;
28 import org.kuali.kpme.core.util.TKUtils;
29 import org.kuali.kpme.tklm.time.rules.lunch.department.DeptLunchRule;
30 import org.kuali.kpme.tklm.time.service.TkServiceLocator;
31 import org.kuali.kpme.tklm.time.timeblock.TimeBlock;
32 import org.kuali.kpme.tklm.time.timehourdetail.TimeHourDetail;
33 import org.kuali.kpme.tklm.time.timesheet.TimesheetDocument;
34 import org.kuali.kpme.tklm.utils.TkTestUtils;
35 import org.kuali.rice.krad.service.KRADServiceLocator;
36
37 @FunctionalTest
38 public class DepartmentLunchRuleTest extends KPMEWebTestCase {
39 private DateTime JAN_AS_OF_DATE = new DateTime(2010, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
40
41 @Test
42 public void testDepartmentLunchRuleFetch() throws Exception{
43 DeptLunchRule deptLunchRule = new DeptLunchRule();
44 deptLunchRule.setActive(true);
45 deptLunchRule.setDept("TEST");
46 deptLunchRule.setWorkArea(1234L);
47 deptLunchRule.setEffectiveLocalDate(JAN_AS_OF_DATE.toLocalDate());
48 deptLunchRule.setJobNumber(0L);
49 deptLunchRule.setPrincipalId("admin");
50 deptLunchRule.setDeductionMins(new BigDecimal(30));
51 deptLunchRule.setShiftHours(new BigDecimal(6));
52 deptLunchRule.setTkDeptLunchRuleId("1001");
53
54 KRADServiceLocator.getBusinessObjectService().save(deptLunchRule);
55
56 deptLunchRule = TkServiceLocator.getDepartmentLunchRuleService().getDepartmentLunchRule("TEST",
57 1234L, "admin", 0L, JAN_AS_OF_DATE.toLocalDate());
58 Assert.assertTrue("dept lunch rule fetched ", deptLunchRule!=null);
59
60 }
61
62
63
64
65
66 @Test
67 public void testDepartmentLunchRule() throws Exception {
68
69 DeptLunchRule deptLunchRule = new DeptLunchRule();
70 deptLunchRule.setActive(true);
71 deptLunchRule.setDept("TEST-DEPT");
72 deptLunchRule.setWorkArea(1234L);
73 deptLunchRule.setEffectiveLocalDate(JAN_AS_OF_DATE.toLocalDate());
74 deptLunchRule.setJobNumber(1L);
75 deptLunchRule.setPrincipalId("edna");
76 deptLunchRule.setDeductionMins(new BigDecimal(30));
77 deptLunchRule.setShiftHours(new BigDecimal(6));
78 deptLunchRule.setTkDeptLunchRuleId("1001");
79
80 KRADServiceLocator.getBusinessObjectService().save(deptLunchRule);
81
82 deptLunchRule = TkServiceLocator.getDepartmentLunchRuleService().getDepartmentLunchRule("TEST-DEPT",
83 1234L, "edna", 1L, JAN_AS_OF_DATE.toLocalDate());
84 Assert.assertTrue("dept lunch rule fetched ", deptLunchRule!=null);
85
86 TimesheetDocument doc = TkTestUtils.populateTimesheetDocument(JAN_AS_OF_DATE, "edna");
87
88 for(TimeBlock tb : doc.getTimeBlocks()){
89 tb.setClockLogCreated(true);
90 }
91
92
93
94 for(TimeBlock tb : doc.getTimeBlocks()) {
95 if(tb.getHours().compareTo(deptLunchRule.getShiftHours()) == 1) {
96 for(TimeHourDetail thd : tb.getTimeHourDetails()){
97
98 if(!StringUtils.equals(thd.getEarnCode(), HrConstants.LUNCH_EARN_CODE)){
99 Assert.assertEquals(new BigDecimal(9.50).setScale(2), tb.getHours());
100 }
101 }
102 }
103 }
104
105 }
106
107 @Test
108 public void testSearchDepartmentLunchRules() throws Exception {
109 List<DeptLunchRule> allResults = TkServiceLocator.getDepartmentLunchRuleService().getDepartmentLunchRules("admin", null, null, null, null, null, null, "Y", "N");
110 Assert.assertEquals("Search returned the wrong number of results.", 2, allResults.size());
111
112 List<DeptLunchRule> restrictedResults = TkServiceLocator.getDepartmentLunchRuleService().getDepartmentLunchRules("fran", null, null, null, null, null, null, "Y", "N");
113 Assert.assertEquals("Search returned the wrong number of results.", 0, restrictedResults.size());
114 }
115
116 }