1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }