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.batch;
17  
18  import java.text.DateFormat;
19  import java.text.SimpleDateFormat;
20  import java.util.Date;
21  
22  import org.junit.Assert;
23  import org.junit.Before;
24  import org.junit.Test;
25  import org.kuali.hr.test.KPMETestCase;
26  import org.kuali.hr.time.batch.service.BatchJobService;
27  import org.kuali.hr.time.calendar.CalendarEntries;
28  import org.kuali.hr.time.service.base.TkServiceLocator;
29  import org.kuali.hr.time.util.TkConstants;
30  
31  public class BatchJobTest extends KPMETestCase {
32  
33  	private static final DateFormat DATE_FORMAT = new SimpleDateFormat("MM/dd/yy");
34  	private static final String BATCH_JOB_NAME = "testJob";
35  	private Long ibjId;
36  	private BatchJobService bjService;
37  
38  	@Before
39      public void setUp() throws Exception {
40      	super.setUp();
41      	bjService = TkServiceLocator.getBatchJobService();
42      }
43  	
44  	private void creatAndSaveBatchJob() throws Exception{
45  		Date beginPeriodDate = DATE_FORMAT.parse("04/01/2011");
46  		Date endPeriodDate = DATE_FORMAT.parse("04/15/2011");
47  		CalendarEntries calendarEntry = TkServiceLocator.getCalendarEntriesService().getCalendarEntriesByBeginAndEndDate(beginPeriodDate, endPeriodDate);
48  		InitiateBatchJob ibj = new InitiateBatchJob(calendarEntry);
49  		ibj.setBatchJobName(BATCH_JOB_NAME);
50  		ibj.setBatchJobStatus(TkConstants.BATCH_JOB_ENTRY_STATUS.SCHEDULED);
51  		ibj.setTimeElapsed(new Long(123));
52  
53  		bjService.saveBatchJob(ibj);
54  
55  		ibjId = ibj.getTkBatchJobId();
56  	}
57  
58  	@Test
59  	public void testSavingAndRetrievingBatchJob() throws Exception {
60  		creatAndSaveBatchJob();
61  		BatchJob bj = (BatchJob) bjService.getBatchJob(ibjId);
62  		Assert.assertTrue("Batch Job Name not right", bj.getBatchJobName().equals(BATCH_JOB_NAME));
63  	}
64  }