View Javadoc

1   /**
2    * Copyright 2004-2012 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.util.List;
19  
20  import org.junit.Assert;
21  import org.junit.Before;
22  import org.junit.Test;
23  import org.kuali.hr.test.KPMETestCase;
24  import org.kuali.hr.time.batch.service.BatchJobEntryService;
25  import org.kuali.hr.time.calendar.Calendar;
26  import org.kuali.hr.time.service.base.TkServiceLocator;
27  import org.kuali.hr.time.util.TkConstants;
28  
29  public class BatchJobEntryTest extends KPMETestCase {
30  	private static final String BATCH_JOB_NAME = "testJob";
31  	private Long bjeId;
32  
33  	private BatchJobEntryService bjeService;
34  
35  	@Before
36      public void setUp() throws Exception {
37      	super.setUp();
38      	bjeService = TkServiceLocator.getBatchJobEntryService();
39      }
40  	private void creatAndSaveBatchJobEntry(){
41  		BatchJobEntry bje = new BatchJobEntry();
42  		bje.setBatchJobName(BATCH_JOB_NAME);
43  		bje.setBatchJobEntryStatus(TkConstants.BATCH_JOB_ENTRY_STATUS.SCHEDULED);
44  		bje.setBatchJobException("test error");
45  		bje.setIpAddress("1.2.3.4");
46  		bje.setPrincipalId("admin");
47  		bje.setDocumentId("testDoc");
48  
49  		Calendar pc = TkServiceLocator.getCalendarService().getCalendarByGroup("BW-CAL");
50  		bje.setHrPyCalendarEntryId(pc.getHrCalendarId());
51  		List<BatchJob> batchJobs = TkServiceLocator.getBatchJobService().getBatchJobs(pc.getHrCalendarId());
52  		Long batchJobId = new Long(0);
53  		if(!batchJobs.isEmpty()){
54  			batchJobId = batchJobs.get(0).getTkBatchJobId();
55  		}
56  		bje.setTkBatchJobId(batchJobId);
57  
58  		bjeService.saveBatchJobEntry(bje);
59  
60  		bjeId = bje.getTkBatchJobEntryId();
61  	}
62  
63  	@Test
64  	public void testSavingAndRetrievingBatchJobEntry() throws Exception {
65  		creatAndSaveBatchJobEntry();
66  		BatchJobEntry bje = (BatchJobEntry) bjeService.getBatchJobEntry(bjeId);
67  		Assert.assertTrue("Batch Job Name not right", bje.getBatchJobName().equals(BATCH_JOB_NAME));
68  
69  		List<BatchJobEntry> entries = bjeService.getBatchJobEntries(bje.getTkBatchJobId());
70  		Assert.assertTrue("Batch Job Entry not empty", (!entries.isEmpty()));
71  	}
72  }