use of org.finra.herd.model.api.xml.JobDeleteRequest in project herd by FINRAOS.
the class JobRestControllerTest method testDeleteJob.
@Test
public void testDeleteJob() throws Exception {
// Create a job delete request.
JobDeleteRequest jobDeleteRequest = new JobDeleteRequest(ACTIVITI_JOB_DELETE_REASON);
// Create a job.
Job job = new Job();
job.setId(JOB_ID);
// Mock the external calls.
when(jobService.deleteJob(JOB_ID, jobDeleteRequest)).thenReturn(job);
// Call the method under test.
Job result = jobRestController.deleteJob(JOB_ID, jobDeleteRequest);
// Verify the external calls.
verify(jobService).deleteJob(JOB_ID, jobDeleteRequest);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(job, result);
}
use of org.finra.herd.model.api.xml.JobDeleteRequest in project herd by FINRAOS.
the class JobServiceTest method testDeleteJobSuspendedJobWithMultipleSubProcesses.
@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void testDeleteJobSuspendedJobWithMultipleSubProcesses() throws Exception {
// Create and persist a test job definition.
executeJdbcTestHelper.prepareHerdDatabaseForExecuteJdbcWithReceiveTaskTest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, ACTIVITI_XML_TEST_MULTIPLE_SUB_PROCESSES);
try {
// Get the job definition entity and ensure it exists.
JobDefinitionEntity jobDefinitionEntity = jobDefinitionDao.getJobDefinitionByAltKey(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME);
assertNotNull(jobDefinitionEntity);
// Get the process definition id.
String processDefinitionId = jobDefinitionEntity.getActivitiId();
// Build the parameters map.
Map<String, Object> parameters = new HashMap<>();
parameters.put("counter", 0);
// Start the job.
ProcessInstance processInstance = activitiService.startProcessInstanceByProcessDefinitionId(processDefinitionId, parameters);
assertNotNull(processInstance);
// Get the process instance id for this job.
String processInstanceId = processInstance.getProcessInstanceId();
// Wait for all processes to become active - we expect to have the main process along with 800 sub-processes.
waitUntilActiveProcessesThreshold(processDefinitionId, 801);
// Get the job and validate that it is RUNNING.
Job getJobResponse = jobService.getJob(processInstanceId, true);
assertNotNull(getJobResponse);
assertEquals(JobStatusEnum.RUNNING, getJobResponse.getStatus());
// Suspend the job.
jobService.updateJob(processInstanceId, new JobUpdateRequest(JobActionEnum.SUSPEND));
// Get the job again and validate that it is now SUSPENDED.
getJobResponse = jobService.getJob(processInstanceId, true);
assertNotNull(getJobResponse);
assertEquals(JobStatusEnum.SUSPENDED, getJobResponse.getStatus());
// Delete the job in suspended state and validate the response.
Job deleteJobResponse = jobService.deleteJob(processInstanceId, new JobDeleteRequest(ACTIVITI_JOB_DELETE_REASON));
assertEquals(JobStatusEnum.COMPLETED, deleteJobResponse.getStatus());
assertEquals(ACTIVITI_JOB_DELETE_REASON, deleteJobResponse.getDeleteReason());
// Validate the historic process instance.
HistoricProcessInstance historicProcessInstance = activitiHistoryService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
assertNotNull(historicProcessInstance);
assertEquals(ACTIVITI_JOB_DELETE_REASON, historicProcessInstance.getDeleteReason());
} finally {
// Clean up the Herd database.
executeJdbcTestHelper.cleanUpHerdDatabaseAfterExecuteJdbcWithReceiveTaskTest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME);
// Clean up the Activiti.
deleteActivitiDeployments();
}
}
use of org.finra.herd.model.api.xml.JobDeleteRequest in project herd by FINRAOS.
the class JobServiceTest method testDeleteJob.
/**
* Asserts that the deleteJob call will move the job to completion, and add a record in the history instance with the specified delete reason.
*
* @throws Exception
*/
@Test
public void testDeleteJob() throws Exception {
// Start a job that will wait in a receive task
jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_RECEIVE_TASK_WITH_CLASSPATH);
Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME));
// Create a job delete request
JobDeleteRequest jobDeleteRequest = new JobDeleteRequest();
jobDeleteRequest.setDeleteReason("test delete reason");
Job deleteJobResponse = jobService.deleteJob(job.getId(), jobDeleteRequest);
// Assert delete job response
assertEquals(job.getId(), deleteJobResponse.getId());
assertNull(deleteJobResponse.getNamespace());
assertNull(deleteJobResponse.getJobName());
assertEquals(JobStatusEnum.COMPLETED, deleteJobResponse.getStatus());
assertEquals(jobDeleteRequest.getDeleteReason(), deleteJobResponse.getDeleteReason());
// Assert historic process instance
HistoricProcessInstance historicProcessInstance = activitiHistoryService.createHistoricProcessInstanceQuery().processInstanceId(job.getId()).singleResult();
assertNotNull(historicProcessInstance);
assertEquals(jobDeleteRequest.getDeleteReason(), historicProcessInstance.getDeleteReason());
}
use of org.finra.herd.model.api.xml.JobDeleteRequest in project herd by FINRAOS.
the class JobServiceTest method testDeleteJobActiveJobWithMultipleSubProcesses.
@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void testDeleteJobActiveJobWithMultipleSubProcesses() throws Exception {
// Create and persist a test job definition.
executeJdbcTestHelper.prepareHerdDatabaseForExecuteJdbcWithReceiveTaskTest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, ACTIVITI_XML_TEST_MULTIPLE_SUB_PROCESSES);
try {
// Get the job definition entity and ensure it exists.
JobDefinitionEntity jobDefinitionEntity = jobDefinitionDao.getJobDefinitionByAltKey(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME);
assertNotNull(jobDefinitionEntity);
// Get the process definition id.
String processDefinitionId = jobDefinitionEntity.getActivitiId();
// Build the parameters map.
Map<String, Object> parameters = new HashMap<>();
parameters.put("counter", 0);
// Start the job.
ProcessInstance processInstance = activitiService.startProcessInstanceByProcessDefinitionId(processDefinitionId, parameters);
assertNotNull(processInstance);
// Get the process instance id for this job.
String processInstanceId = processInstance.getProcessInstanceId();
// Wait for all processes to become active - we expect to have the main process along with 800 sub-processes.
waitUntilActiveProcessesThreshold(processDefinitionId, 801);
// Get the job and validate that it is RUNNING.
Job getJobResponse = jobService.getJob(processInstanceId, true);
assertNotNull(getJobResponse);
assertEquals(JobStatusEnum.RUNNING, getJobResponse.getStatus());
// Delete the job and validate the response.
Job deleteJobResponse = jobService.deleteJob(processInstanceId, new JobDeleteRequest(ACTIVITI_JOB_DELETE_REASON));
assertEquals(JobStatusEnum.COMPLETED, deleteJobResponse.getStatus());
assertEquals(ACTIVITI_JOB_DELETE_REASON, deleteJobResponse.getDeleteReason());
// Validate the historic process instance.
HistoricProcessInstance historicProcessInstance = activitiHistoryService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
assertNotNull(historicProcessInstance);
assertEquals(ACTIVITI_JOB_DELETE_REASON, historicProcessInstance.getDeleteReason());
} finally {
// Clean up the Herd database.
executeJdbcTestHelper.cleanUpHerdDatabaseAfterExecuteJdbcWithReceiveTaskTest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME);
// Clean up the Activiti.
deleteActivitiDeployments();
}
}
use of org.finra.herd.model.api.xml.JobDeleteRequest in project herd by FINRAOS.
the class JobServiceTest method testDeleteJobAssertErrorDeleteReasonBlank.
/**
* Asserts that the deleteJob call will throw an error when delete reason is blank.
*
* @throws Exception
*/
@Test
public void testDeleteJobAssertErrorDeleteReasonBlank() throws Exception {
// Start a job that will wait in a receive task
jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_RECEIVE_TASK_WITH_CLASSPATH);
Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME));
// Create a job delete request
JobDeleteRequest jobDeleteRequest = new JobDeleteRequest();
jobDeleteRequest.setDeleteReason(BLANK_TEXT);
try {
jobService.deleteJob(job.getId(), jobDeleteRequest);
} catch (Exception e) {
assertEquals(IllegalArgumentException.class, e.getClass());
assertEquals("deleteReason must be specified", e.getMessage());
}
}
Aggregations