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.batch;
017
018 import java.text.DateFormat;
019 import java.text.SimpleDateFormat;
020 import java.util.Date;
021
022 import org.junit.Assert;
023 import org.junit.Before;
024 import org.junit.Test;
025 import org.kuali.hr.test.KPMETestCase;
026 import org.kuali.hr.time.batch.service.BatchJobService;
027 import org.kuali.hr.time.calendar.CalendarEntries;
028 import org.kuali.hr.time.service.base.TkServiceLocator;
029 import org.kuali.hr.time.util.TkConstants;
030
031 public class BatchJobTest extends KPMETestCase {
032
033 private static final DateFormat DATE_FORMAT = new SimpleDateFormat("MM/dd/yy");
034 private static final String BATCH_JOB_NAME = "testJob";
035 private Long ibjId;
036 private BatchJobService bjService;
037
038 @Before
039 public void setUp() throws Exception {
040 super.setUp();
041 bjService = TkServiceLocator.getBatchJobService();
042 }
043
044 private void creatAndSaveBatchJob() throws Exception{
045 Date beginPeriodDate = DATE_FORMAT.parse("04/01/2011");
046 Date endPeriodDate = DATE_FORMAT.parse("04/15/2011");
047 CalendarEntries calendarEntry = TkServiceLocator.getCalendarEntriesService().getCalendarEntriesByBeginAndEndDate(beginPeriodDate, endPeriodDate);
048 InitiateBatchJob ibj = new InitiateBatchJob(calendarEntry);
049 ibj.setBatchJobName(BATCH_JOB_NAME);
050 ibj.setBatchJobStatus(TkConstants.BATCH_JOB_ENTRY_STATUS.SCHEDULED);
051 ibj.setTimeElapsed(new Long(123));
052
053 bjService.saveBatchJob(ibj);
054
055 ibjId = ibj.getTkBatchJobId();
056 }
057
058 @Test
059 public void testSavingAndRetrievingBatchJob() throws Exception {
060 creatAndSaveBatchJob();
061 BatchJob bj = (BatchJob) bjService.getBatchJob(ibjId);
062 Assert.assertTrue("Batch Job Name not right", bj.getBatchJobName().equals(BATCH_JOB_NAME));
063 }
064 }