001 /** 002 * Copyright 2004-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.hr.time.graceperiod.service; 017 018 import java.math.BigDecimal; 019 import java.sql.Date; 020 import java.sql.Timestamp; 021 022 import org.joda.time.DateTime; 023 import org.joda.time.DateTimeZone; 024 import org.junit.Assert; 025 import org.junit.Ignore; 026 import org.junit.Test; 027 import org.kuali.hr.test.KPMETestCase; 028 import org.kuali.hr.time.graceperiod.rule.GracePeriodRule; 029 import org.kuali.hr.time.service.base.TkServiceLocator; 030 import org.kuali.hr.time.util.TKUtils; 031 import org.kuali.rice.krad.service.KRADServiceLocator; 032 033 public class GracePeriodRuleServiceTest extends KPMETestCase{ 034 035 @Test 036 public void testGracePeriodRuleFetch() throws Exception{ 037 GracePeriodRule gpr = new GracePeriodRule(); 038 gpr.setActive(true); 039 gpr.setEffectiveDate(new Date(System.currentTimeMillis())); 040 gpr.setHourFactor(new BigDecimal(0.1)); 041 042 KRADServiceLocator.getBusinessObjectService().save(gpr); 043 gpr = TkServiceLocator.getGracePeriodService().getGracePeriodRule(new Date(System.currentTimeMillis())); 044 Assert.assertTrue("fetched one rule", gpr != null); 045 046 //cleanup 047 KRADServiceLocator.getBusinessObjectService().delete(gpr); 048 } 049 050 @Test 051 @Ignore 052 public void testGracePeriodFetchValidation() throws Exception{ 053 //TODO: Sai - confirm maintenance page renders 054 //TODO: Sai - confirm if hour factor is less than or equal 0 and greater than 1 it throws 055 //appropriate error 056 057 } 058 059 @Test 060 public void testGracePeriodRuleTest() throws Exception{ 061 GracePeriodRule gpr = new GracePeriodRule(); 062 gpr.setActive(true); 063 gpr.setEffectiveDate(new Date(System.currentTimeMillis())); 064 gpr.setHourFactor(new BigDecimal(3)); 065 066 KRADServiceLocator.getBusinessObjectService().save(gpr); 067 gpr = TkServiceLocator.getGracePeriodService().getGracePeriodRule(new Date(System.currentTimeMillis())); 068 Assert.assertTrue("fetched one rule", gpr != null); 069 070 Timestamp beginDateTime = new Timestamp((new DateTime(2012, 10, 16, 12, 3, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis()); 071 Timestamp derivedTimestamp = TkServiceLocator.getGracePeriodService().processGracePeriodRule(beginDateTime, new Date(System.currentTimeMillis())); 072 073 Assert.assertTrue("rounded to 1:03", derivedTimestamp.getMinutes()==3); 074 075 beginDateTime = new Timestamp((new DateTime(2012, 10, 16, 12, 56, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis()); 076 derivedTimestamp = TkServiceLocator.getGracePeriodService().processGracePeriodRule(beginDateTime, new Date(System.currentTimeMillis())); 077 078 Assert.assertTrue("rounded to 1:56", derivedTimestamp.getMinutes()==57); 079 080 //cleanup 081 KRADServiceLocator.getBusinessObjectService().delete(gpr); 082 } 083 }