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.accrual.service;
017
018 import java.sql.Date;
019 import java.text.SimpleDateFormat;
020
021 import org.joda.time.DateTime;
022 import org.junit.Assert;
023 import org.junit.Test;
024 import org.kuali.hr.lm.accrual.PrincipalAccrualRan;
025 import org.kuali.hr.test.KPMETestCase;
026 import org.kuali.hr.time.service.base.TkServiceLocator;
027 import org.kuali.hr.time.util.TKUtils;
028 import org.kuali.hr.time.util.TkConstants;
029
030 public class PrincipalAccrualRanServiceTest extends KPMETestCase {
031
032 @Test
033 public void testUpdateInfo() {
034 // the database has an entry for principalId testUser dated 2012-05-01
035 // run accrual service for testUser
036 // the principalAccrualRan entry in database should be changed to today's timestamp
037 PrincipalAccrualRan par = TkServiceLocator.getPrincipalAccrualRanService().getLastPrincipalAccrualRan("testUser");
038 Assert.assertNotNull("There should be one entry in PrincipalAccrualRan table for 'testUser'", par);
039 Date aDate = new Date(par.getLastRanTs().getTime());
040 SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
041 Assert.assertTrue("Date of the original entry in PrincipalAccrualRan for 'testUser' should be 05/01/2012"
042 , formatter.format(aDate).equals("05/01/2012"));
043
044 Date startDate = new Date((new DateTime(2012, 2, 20, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
045 Date endDate = new Date((new DateTime(2012, 5, 3, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
046
047 boolean rerunFlag = TkServiceLocator.getLeaveAccrualService().statusChangedSinceLastRun("testUser");
048 Assert.assertTrue("Status should be changed for 'testUser'", rerunFlag);
049
050 TkServiceLocator.getLeaveAccrualService().runAccrual("testUser", startDate, endDate, true);
051 par = TkServiceLocator.getPrincipalAccrualRanService().getLastPrincipalAccrualRan("testUser");
052 aDate = new Date(par.getLastRanTs().getTime());
053 Assert.assertTrue("Date of the original entry in PrincipalAccrualRan for 'testUser' should be current date"
054 , formatter.format(aDate).equals(formatter.format(TKUtils.getCurrentDate())));
055
056 }
057
058 }