1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.graceperiod.service;
17
18 import java.math.BigDecimal;
19 import java.sql.Date;
20 import java.sql.Timestamp;
21
22 import org.joda.time.DateTime;
23 import org.joda.time.DateTimeZone;
24 import org.junit.Assert;
25 import org.junit.Ignore;
26 import org.junit.Test;
27 import org.kuali.hr.test.KPMETestCase;
28 import org.kuali.hr.time.graceperiod.rule.GracePeriodRule;
29 import org.kuali.hr.time.service.base.TkServiceLocator;
30 import org.kuali.hr.time.util.TKUtils;
31 import org.kuali.rice.krad.service.KRADServiceLocator;
32
33 public class GracePeriodRuleServiceTest extends KPMETestCase{
34
35 @Test
36 public void testGracePeriodRuleFetch() throws Exception{
37 GracePeriodRule gpr = new GracePeriodRule();
38 gpr.setActive(true);
39 gpr.setEffectiveDate(new Date(System.currentTimeMillis()));
40 gpr.setHourFactor(new BigDecimal(0.1));
41
42 KRADServiceLocator.getBusinessObjectService().save(gpr);
43 gpr = TkServiceLocator.getGracePeriodService().getGracePeriodRule(new Date(System.currentTimeMillis()));
44 Assert.assertTrue("fetched one rule", gpr != null);
45
46
47 KRADServiceLocator.getBusinessObjectService().delete(gpr);
48 }
49
50 @Test
51 @Ignore
52 public void testGracePeriodFetchValidation() throws Exception{
53
54
55
56
57 }
58
59 @Test
60 public void testGracePeriodRuleTest() throws Exception{
61 GracePeriodRule gpr = new GracePeriodRule();
62 gpr.setActive(true);
63 gpr.setEffectiveDate(new Date(System.currentTimeMillis()));
64 gpr.setHourFactor(new BigDecimal(3));
65
66 KRADServiceLocator.getBusinessObjectService().save(gpr);
67 gpr = TkServiceLocator.getGracePeriodService().getGracePeriodRule(new Date(System.currentTimeMillis()));
68 Assert.assertTrue("fetched one rule", gpr != null);
69
70 Timestamp beginDateTime = new Timestamp((new DateTime(2012, 10, 16, 12, 3, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
71 Timestamp derivedTimestamp = TkServiceLocator.getGracePeriodService().processGracePeriodRule(beginDateTime, new Date(System.currentTimeMillis()));
72
73 Assert.assertTrue("rounded to 1:03", derivedTimestamp.getMinutes()==3);
74
75 beginDateTime = new Timestamp((new DateTime(2012, 10, 16, 12, 56, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
76 derivedTimestamp = TkServiceLocator.getGracePeriodService().processGracePeriodRule(beginDateTime, new Date(System.currentTimeMillis()));
77
78 Assert.assertTrue("rounded to 1:56", derivedTimestamp.getMinutes()==57);
79
80
81 KRADServiceLocator.getBusinessObjectService().delete(gpr);
82 }
83 }