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.util.List;
019
020 import org.junit.Assert;
021 import org.junit.Before;
022 import org.junit.Test;
023 import org.kuali.hr.test.KPMETestCase;
024 import org.kuali.hr.time.batch.service.BatchJobEntryService;
025 import org.kuali.hr.time.calendar.Calendar;
026 import org.kuali.hr.time.service.base.TkServiceLocator;
027 import org.kuali.hr.time.util.TkConstants;
028
029 public class BatchJobEntryTest extends KPMETestCase {
030 private static final String BATCH_JOB_NAME = "testJob";
031 private Long bjeId;
032
033 private BatchJobEntryService bjeService;
034
035 @Before
036 public void setUp() throws Exception {
037 super.setUp();
038 bjeService = TkServiceLocator.getBatchJobEntryService();
039 }
040 private void creatAndSaveBatchJobEntry(){
041 BatchJobEntry bje = new BatchJobEntry();
042 bje.setBatchJobName(BATCH_JOB_NAME);
043 bje.setBatchJobEntryStatus(TkConstants.BATCH_JOB_ENTRY_STATUS.SCHEDULED);
044 bje.setBatchJobException("test error");
045 bje.setIpAddress("1.2.3.4");
046 bje.setPrincipalId("admin");
047 bje.setDocumentId("testDoc");
048
049 Calendar pc = TkServiceLocator.getCalendarService().getCalendarByGroup("BW-CAL");
050 bje.setHrPyCalendarEntryId(pc.getHrCalendarId());
051 List<BatchJob> batchJobs = TkServiceLocator.getBatchJobService().getBatchJobs(pc.getHrCalendarId());
052 Long batchJobId = new Long(0);
053 if(!batchJobs.isEmpty()){
054 batchJobId = batchJobs.get(0).getTkBatchJobId();
055 }
056 bje.setTkBatchJobId(batchJobId);
057
058 bjeService.saveBatchJobEntry(bje);
059
060 bjeId = bje.getTkBatchJobEntryId();
061 }
062
063 @Test
064 public void testSavingAndRetrievingBatchJobEntry() throws Exception {
065 creatAndSaveBatchJobEntry();
066 BatchJobEntry bje = (BatchJobEntry) bjeService.getBatchJobEntry(bjeId);
067 Assert.assertTrue("Batch Job Name not right", bje.getBatchJobName().equals(BATCH_JOB_NAME));
068
069 List<BatchJobEntry> entries = bjeService.getBatchJobEntries(bje.getTkBatchJobId());
070 Assert.assertTrue("Batch Job Entry not empty", (!entries.isEmpty()));
071 }
072 }