View Javadoc

1   /**
2    * Copyright 2004-2013 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.accrual.service;
17  
18  import java.sql.Date;
19  import java.text.SimpleDateFormat;
20  
21  import org.joda.time.DateTime;
22  import org.junit.Assert;
23  import org.junit.Test;
24  import org.kuali.hr.lm.accrual.PrincipalAccrualRan;
25  import org.kuali.hr.test.KPMETestCase;
26  import org.kuali.hr.time.service.base.TkServiceLocator;
27  import org.kuali.hr.time.util.TKUtils;
28  import org.kuali.hr.time.util.TkConstants;
29  
30  public class PrincipalAccrualRanServiceTest extends KPMETestCase {
31  	
32  	@Test
33  	public void testUpdateInfo() {
34  		// the database has an entry for principalId testUser dated 2012-05-01
35  		// run accrual service for testUser
36  		// the principalAccrualRan entry in database should be changed to today's timestamp
37  		PrincipalAccrualRan par = TkServiceLocator.getPrincipalAccrualRanService().getLastPrincipalAccrualRan("testUser");
38  		Assert.assertNotNull("There should be one entry in PrincipalAccrualRan table for 'testUser'", par);
39  		Date aDate = new Date(par.getLastRanTs().getTime());
40  		SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
41  		Assert.assertTrue("Date of the original entry in PrincipalAccrualRan for 'testUser' should be 05/01/2012"
42  				, formatter.format(aDate).equals("05/01/2012"));
43  		
44  		Date startDate = new Date((new DateTime(2012, 2, 20, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
45  		Date endDate = new Date((new DateTime(2012, 5, 3, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
46  		
47  		boolean rerunFlag = TkServiceLocator.getLeaveAccrualService().statusChangedSinceLastRun("testUser");
48  		Assert.assertTrue("Status should be changed for 'testUser'", rerunFlag);
49  		
50  		TkServiceLocator.getLeaveAccrualService().runAccrual("testUser", startDate, endDate, true);
51  		par = TkServiceLocator.getPrincipalAccrualRanService().getLastPrincipalAccrualRan("testUser");
52  		aDate = new Date(par.getLastRanTs().getTime());
53  		Assert.assertTrue("Date of the original entry in PrincipalAccrualRan for 'testUser' should be current date"
54  				, formatter.format(aDate).equals(formatter.format(TKUtils.getCurrentDate())));
55  		
56  	}
57  
58  }