SuperX-Kernmodul
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

124 lines
4.5 KiB

package de.superx.rest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.time.DateUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.batch.core.ExitStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import de.superx.BaseDbTest;
import de.superx.job.ContainerNode;
import de.superx.rest.model.job.JobExecutionStatus;
import de.superx.servlet.SxSQL_Server;
import de.superx.spring.batch.job.JobUtils;
import de.superx.spring.service.UserService;
public class EtlJobApiTest extends BaseDbTest {
@Autowired
EtlJobApi api;
@Autowired
UserService userService;
@Before
public void setup() {
api.setSyncExecution();
SxSQL_Server.DEFAULT_MANDANTEN_ID = "test";
Map<String, Map<String,String>> rights = new HashMap<>();
rights.put("RIGHT_CS_BIA_STANDARDREPORTS_ADMIN", null);
user.setRights(rights, null);
}
@Test
public void testApiAvailable() {
assertNotNull("EtlJobApi available", api);
}
@Test
public void testJobsAvailable() {
List<ContainerNode> jobs = api.getAllJobs();
assertTrue("Jobs available", jobs.size() > 0);
}
@Ignore
@Test
public void testRunJobKernUpgrade() throws Exception {
Long jobExecution = api.executeUpgrade("kern");
JobExecutionStatus status = api.getStatus(jobExecution);
assertEquals("unexpected JobExecutionStatus: ", "COMPLETED", status.exitStatus.getExitCode());
}
@Test
public void testRunJobKernComplete() throws Exception {
Long jobExecution = api.complete("kern");
JobExecutionStatus status = api.getStatus(jobExecution);
assertEquals("Job execution successfull", "COMPLETED", status.exitStatus.getExitCode());
}
@Test
public void testRunJobZulComplete() throws Exception {
Long jobExecution = api.complete("zul");
JobExecutionStatus status = api.getStatus(jobExecution);
assertEquals("Job execution successfull", "COMPLETED", status.exitStatus.getExitCode());
}
@Test
public void testJobLog() throws Exception {
JdbcTemplate jt = new JdbcTemplate(dataSource);
// set create time of job_executions to older than 15 minutes
// otherwise they will not be deleted all!
Date date = DateUtils.addMinutes(new Date(), -20);
jt.update("UPDATE batch_job_execution SET create_time = ?", date);
// delete complete job history
JobUtils.deleteJobHistoryOlderThanDays(0, jt);
List<JobExecutionInfo> history = api.getJobExecutionInfos();
assertTrue("All job history entries deleted", history.size() == 0);
Long jobExecution = api.complete("zul");
JobExecutionStatus status = api.getStatus(jobExecution);
assertEquals("Job execution successfull", "COMPLETED", status.exitStatus.getExitCode());
history = api.getJobExecutionInfos();
assertTrue("All job history entries deleted", history.size() == 1);
JobExecutionInfo jobInfo = history.get(0);
assertEquals("Jobname", "ZUL Unload, Load And Transform", jobInfo.jobName);
assertEquals("Component", "Bewerbung, Zulassung", jobInfo.component);
assertNotNull("Start time", jobInfo.startTime);
assertNotNull("End time", jobInfo.endTime);
assertNull("Duration", jobInfo.duration);
assertEquals("ExistStatus", ExitStatus.COMPLETED, jobInfo.exitStatus);
Long jobInstanceId = jobInfo.jobExecutionId;
JobExecutionStatus statusHist = api.getJobExcecutionStatus(jobInstanceId);
assertEquals("JobExecutionStatus equal to history", status, statusHist);
JobLog log = api.getJobLog(jobInstanceId);
assertTrue("Download log", log.log.length() > 0);
assertEquals("Component abbreviation", "zul", log.jobAbbreviation);
}
@Ignore
@Test
public void testRunBIADComplete() throws Exception {
Long jobExecution = api.complete("biad");
JobExecutionStatus status = api.getStatus(jobExecution);
assertEquals("Job execution successfull", "COMPLETED", status.exitStatus.getExitCode());
}
@After
public void tearDown() {
api.unsetSyncExecution();
}
}