use of org.finra.herd.model.api.xml.Job in project herd by FINRAOS.
the class JobServiceTest method testUpdateJobInvalidParameters.
@Test
public void testUpdateJobInvalidParameters() throws Exception {
// Create a test job definition.
jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_USER_TASK_WITH_CLASSPATH);
// Create and start the job.
Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME));
// Job should be waiting at User task.
// Get the running job with non verbose.
Job jobGet = jobService.getJob(job.getId(), false);
assertEquals(JobStatusEnum.RUNNING, jobGet.getStatus());
assertNull(jobGet.getActivitiJobXml());
assertTrue(CollectionUtils.isEmpty(jobGet.getCompletedWorkflowSteps()));
assertEquals("usertask1", jobGet.getCurrentWorkflowStep().getId());
// Try to update a job using invalid job id.
try {
jobService.updateJob("I_DO_NOT_EXIST", new JobUpdateRequest(JobActionEnum.SUSPEND));
fail();
} catch (ObjectNotFoundException e) {
assertEquals("Job with ID \"I_DO_NOT_EXIST\" does not exist or is already completed.", e.getMessage());
}
// Try to resume an already running job.
try {
jobService.updateJob(job.getId(), new JobUpdateRequest(JobActionEnum.RESUME));
fail();
} catch (IllegalArgumentException e) {
assertEquals(String.format("Job with ID \"%s\" is already in an active state.", job.getId()), e.getMessage());
}
// Suspend the job.
jobService.updateJob(job.getId(), new JobUpdateRequest(JobActionEnum.SUSPEND));
// Validate that the job is suspended.
jobGet = jobService.getJob(job.getId(), false);
assertEquals(JobStatusEnum.SUSPENDED, jobGet.getStatus());
assertNull(jobGet.getActivitiJobXml());
assertTrue(CollectionUtils.isEmpty(jobGet.getCompletedWorkflowSteps()));
assertEquals("usertask1", jobGet.getCurrentWorkflowStep().getId());
// Try to suspend an already suspended job.
try {
jobService.updateJob(job.getId(), new JobUpdateRequest(JobActionEnum.SUSPEND));
fail();
} catch (IllegalArgumentException e) {
assertEquals(String.format("Job with ID \"%s\" is already in a suspended state.", job.getId()), e.getMessage());
}
// Resume the job.
jobService.updateJob(job.getId(), new JobUpdateRequest(JobActionEnum.RESUME));
// Validate that the job is running.
jobGet = jobService.getJob(job.getId(), false);
assertEquals(JobStatusEnum.RUNNING, jobGet.getStatus());
assertNull(jobGet.getActivitiJobXml());
assertTrue(CollectionUtils.isEmpty(jobGet.getCompletedWorkflowSteps()));
assertEquals("usertask1", jobGet.getCurrentWorkflowStep().getId());
// Query the pending task and complete it
List<Task> tasks = activitiTaskService.createTaskQuery().processInstanceId(job.getId()).list();
activitiTaskService.complete(tasks.get(0).getId());
// Job should have been completed.
// Get the completed job with non verbose.
jobGet = jobService.getJob(job.getId(), false);
assertEquals(JobStatusEnum.COMPLETED, jobGet.getStatus());
assertNotNull(jobGet.getStartTime());
assertNotNull(jobGet.getEndTime());
assertNull(jobGet.getActivitiJobXml());
assertTrue(CollectionUtils.isEmpty(jobGet.getCompletedWorkflowSteps()));
assertNull(jobGet.getCurrentWorkflowStep());
// Try to update a completed job.
try {
jobService.updateJob(job.getId(), new JobUpdateRequest(JobActionEnum.SUSPEND));
fail();
} catch (ObjectNotFoundException e) {
assertEquals(String.format("Job with ID \"%s\" does not exist or is already completed.", job.getId()), e.getMessage());
}
}
use of org.finra.herd.model.api.xml.Job 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.Job in project herd by FINRAOS.
the class JobServiceTest method testGetJobAssertNoErrorGivenJobCompletedAndUserDoesHasPermissions.
@Test
public void testGetJobAssertNoErrorGivenJobCompletedAndUserDoesHasPermissions() throws Exception {
jobDefinitionServiceTestHelper.createJobDefinition(null);
Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME));
String username = "username";
ApplicationUser applicationUser = new ApplicationUser(getClass());
applicationUser.setUserId(username);
applicationUser.setNamespaceAuthorizations(new HashSet<>());
applicationUser.getNamespaceAuthorizations().add(new NamespaceAuthorization(TEST_ACTIVITI_NAMESPACE_CD, Arrays.asList(NamespacePermissionEnum.READ)));
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(new SecurityUserWrapper(username, "password", false, false, false, false, Collections.emptyList(), applicationUser), null));
try {
jobService.getJob(job.getId(), false);
} catch (AccessDeniedException e) {
fail();
}
}
use of org.finra.herd.model.api.xml.Job 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.Job in project herd by FINRAOS.
the class JobServiceTest method testGetJob.
@Test
public void testGetJob() throws Exception {
jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_USER_TASK_WITH_CLASSPATH);
Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME));
String activitiXml = IOUtils.toString(resourceLoader.getResource(ACTIVITI_XML_TEST_USER_TASK_WITH_CLASSPATH).getInputStream());
// Job should be waiting at User task.
// Running job with verbose
Job jobGet = jobService.getJob(job.getId(), true);
assertEquals(JobStatusEnum.RUNNING, jobGet.getStatus());
assertNotNull(jobGet.getActivitiJobXml());
assertEquals(activitiXml, jobGet.getActivitiJobXml());
assertTrue(jobGet.getCompletedWorkflowSteps().size() > 0);
assertEquals("usertask1", jobGet.getCurrentWorkflowStep().getId());
// Running job with non verbose
jobGet = jobService.getJob(job.getId(), false);
assertEquals(JobStatusEnum.RUNNING, jobGet.getStatus());
assertNull(jobGet.getActivitiJobXml());
assertTrue(CollectionUtils.isEmpty(jobGet.getCompletedWorkflowSteps()));
assertEquals("usertask1", jobGet.getCurrentWorkflowStep().getId());
// Query the pending task and complete it
List<Task> tasks = activitiTaskService.createTaskQuery().processInstanceId(job.getId()).list();
activitiTaskService.complete(tasks.get(0).getId());
// Job should have been completed.
// Completed job with verbose
jobGet = jobService.getJob(job.getId(), true);
assertEquals(JobStatusEnum.COMPLETED, jobGet.getStatus());
assertNotNull(jobGet.getStartTime());
assertNotNull(jobGet.getEndTime());
assertNotNull(jobGet.getActivitiJobXml());
assertEquals(activitiXml, jobGet.getActivitiJobXml());
assertTrue(jobGet.getCompletedWorkflowSteps().size() > 0);
assertNull(jobGet.getCurrentWorkflowStep());
// Completed job with non verbose
jobGet = jobService.getJob(job.getId(), false);
assertEquals(JobStatusEnum.COMPLETED, jobGet.getStatus());
assertNotNull(jobGet.getStartTime());
assertNotNull(jobGet.getEndTime());
assertNull(jobGet.getActivitiJobXml());
assertTrue(CollectionUtils.isEmpty(jobGet.getCompletedWorkflowSteps()));
assertNull(jobGet.getCurrentWorkflowStep());
}
Aggregations