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.workschedule.service;
17  
18  import java.sql.Date;
19  import java.util.List;
20  
21  import org.joda.time.DateTime;
22  import org.joda.time.DateTimeZone;
23  import org.junit.Assert;
24  import org.junit.Ignore;
25  import org.junit.Test;
26  import org.kuali.hr.test.KPMETestCase;
27  import org.kuali.hr.time.service.base.TkServiceLocator;
28  import org.kuali.hr.time.util.TKUtils;
29  import org.kuali.hr.time.util.TkConstants;
30  import org.kuali.hr.time.workschedule.WorkSchedule;
31  import org.kuali.hr.time.workschedule.WorkScheduleEntry;
32  
33  public class WorkScheduleServiceTest extends KPMETestCase {
34  
35  	@Test
36  	@Ignore
37  	public void testGetWorkSchedules() throws Exception {
38  		WorkScheduleService wss = TkServiceLocator.getWorkScheduleService();
39  		String dept = null;
40  		String principalId = null;
41  		Long workScheduleId = null;
42  		Long workArea = null;
43  		Date asOfDate = new Date((new DateTime(2010, 1, 1, 12, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
44  		List<WorkSchedule> schedules = null;
45  
46  		// principal, department, workarea
47  		workScheduleId = 1L;
48  		dept = "TEST-DEPT";
49  		principalId = "admin";
50  		workArea = 1234L;
51  		//schedules = wss.getWorkSchedules(principalId, dept, workArea, asOfDate);
52  		Assert.assertNotNull("Null return list", schedules);
53  		Assert.assertEquals("Wrong number of elements returned.", 1, schedules.size());
54  		Assert.assertEquals("Wrong ID returned", workScheduleId, (schedules.get(0)).getHrWorkScheduleId());
55  		// principal, department, -1
56  		workScheduleId = 2L;
57  		dept = "TEST-DEPT";
58  		principalId = "admin";
59  		workArea = -999L;
60  		//schedules = wss.getWorkSchedules(principalId, dept, workArea, asOfDate);
61  		Assert.assertNotNull("Null return list", schedules);
62  		Assert.assertEquals("Wrong number of elements returned.", 1, schedules.size());
63  		Assert.assertEquals("Wrong ID returned", workScheduleId, (schedules.get(0)).getHrWorkScheduleId());
64  
65  		// principal, *, workarea
66  		workScheduleId = 3L;
67  		dept = "NOTFOUND";
68  		principalId = "admin";
69  		workArea = 1234L;
70  		//schedules = wss.getWorkSchedules(principalId, dept, workArea, asOfDate);
71  		Assert.assertNotNull("Null return list", schedules);
72  		Assert.assertEquals("Wrong number of elements returned.", 1, schedules.size());
73  		Assert.assertEquals("Wrong ID returned", workScheduleId, (schedules.get(0)).getHrWorkScheduleId());
74  	}
75  
76  	@Test
77  	public void testWorkScheduleFlattening() throws Exception{
78  		WorkSchedule workSchedule = new WorkSchedule();
79  		Date asOfDate = new Date((new DateTime(2010, 1, 1, 12, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
80  		workSchedule.setEffectiveDate(asOfDate);
81  		WorkScheduleEntry wse = new WorkScheduleEntry();
82  		for(int i = 0 ;i<TkConstants.LENGTH_OF_WORK_SCHEDULE;i++){
83  			workSchedule.getWorkScheduleEntries().add(wse);
84  		}
85  		Date beginPeriodDate = new Date((new DateTime(2010, 1, 3, 1, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
86  		Date endPeriodDate = new Date((new DateTime(2010, 1, 15, 1, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
87  
88  		List<WorkScheduleEntry> lstWorkSchedEntries = TkServiceLocator.getWorkScheduleService().getWorkSchedEntries(
89  															workSchedule, beginPeriodDate, endPeriodDate);
90  
91  		Assert.assertTrue("verify work sched entries is correct", lstWorkSchedEntries!= null);
92  	}
93  }