Search in sources :

Example 1 with JobDeleteRequest

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);
}
Also used : JobDeleteRequest(org.finra.herd.model.api.xml.JobDeleteRequest) Job(org.finra.herd.model.api.xml.Job) Test(org.junit.Test)

Example 2 with JobDeleteRequest

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();
    }
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) JobUpdateRequest(org.finra.herd.model.api.xml.JobUpdateRequest) HashMap(java.util.HashMap) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) JobDeleteRequest(org.finra.herd.model.api.xml.JobDeleteRequest) Job(org.finra.herd.model.api.xml.Job) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with JobDeleteRequest

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());
}
Also used : HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) JobDeleteRequest(org.finra.herd.model.api.xml.JobDeleteRequest) Job(org.finra.herd.model.api.xml.Job) Test(org.junit.Test)

Example 4 with JobDeleteRequest

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();
    }
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) HashMap(java.util.HashMap) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) JobDeleteRequest(org.finra.herd.model.api.xml.JobDeleteRequest) Job(org.finra.herd.model.api.xml.Job) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with JobDeleteRequest

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());
    }
}
Also used : JobDeleteRequest(org.finra.herd.model.api.xml.JobDeleteRequest) Job(org.finra.herd.model.api.xml.Job) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Test(org.junit.Test)

Aggregations

JobDeleteRequest (org.finra.herd.model.api.xml.JobDeleteRequest)8 Test (org.junit.Test)8 Job (org.finra.herd.model.api.xml.Job)7 AccessDeniedException (org.springframework.security.access.AccessDeniedException)4 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)3 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)3 HashMap (java.util.HashMap)2 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)2 ApplicationUser (org.finra.herd.model.dto.ApplicationUser)2 SecurityUserWrapper (org.finra.herd.model.dto.SecurityUserWrapper)2 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)2 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)2 Transactional (org.springframework.transaction.annotation.Transactional)2 JobUpdateRequest (org.finra.herd.model.api.xml.JobUpdateRequest)1 NamespaceAuthorization (org.finra.herd.model.api.xml.NamespaceAuthorization)1