View Javadoc

1   /**
2    * Copyright 2004-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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          //cleanup
47          KRADServiceLocator.getBusinessObjectService().delete(gpr);
48  	}
49  
50  	@Test
51      @Ignore
52  	public void testGracePeriodFetchValidation() throws Exception{
53  		//TODO: Sai - confirm maintenance page renders
54  		//TODO: Sai - confirm if hour factor is less than or equal 0 and greater than 1 it throws
55  		//appropriate error
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          //cleanup
81          KRADServiceLocator.getBusinessObjectService().delete(gpr);
82  	}
83  }