/** * Deletes a currently running job and preserves the job state in history. <p>Requires EXECUTE permission on namespace</p> * * @param id The job id * @param jobDeleteRequest The delete request * * @return The job that has been deleted * @throws Exception when any exception occurs */ @RequestMapping(value = "/jobs/ids/{id}", method = RequestMethod.DELETE) @Secured(SecurityFunctions.FN_JOBS_DELETE) public Job deleteJob(@PathVariable("id") String id, @RequestBody JobDeleteRequest jobDeleteRequest) throws Exception { return jobService.deleteJob(id, jobDeleteRequest); } }
/** * Deletes a currently running job and preserves the job state in history. <p>Requires EXECUTE permission on namespace</p> * * @param id The job id * @param jobDeleteRequest The delete request * * @return The job that has been deleted * @throws Exception when any exception occurs */ @RequestMapping(value = "/jobs/ids/{id}", method = RequestMethod.DELETE) @Secured(SecurityFunctions.FN_JOBS_DELETE) public Job deleteJob(@PathVariable("id") String id, @RequestBody JobDeleteRequest jobDeleteRequest) throws Exception { return jobService.deleteJob(id, jobDeleteRequest); } }
@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); }
/** * Asserts that the deleteJob call will throw an error when specified job does not exist. * * @throws Exception */ @Test public void testDeleteJobAssertErrorJobDoesNotExist() throws Exception { // Create a job delete request JobDeleteRequest jobDeleteRequest = new JobDeleteRequest(); jobDeleteRequest.setDeleteReason("test delete reason"); try { jobService.deleteJob("DOES_NOT_EXIST", jobDeleteRequest); } catch (Exception e) { assertEquals(ObjectNotFoundException.class, e.getClass()); assertEquals("Job with ID \"DOES_NOT_EXIST\" does not exist or is already completed.", e.getMessage()); } }
@Test public void testDeleteJobAssertAccessDeniedWhenUserHasNoPermissions() 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)); String username = "username"; ApplicationUser applicationUser = new ApplicationUser(getClass()); applicationUser.setUserId(username); applicationUser.setNamespaceAuthorizations(new HashSet<>()); SecurityContextHolder.getContext().setAuthentication( new TestingAuthenticationToken(new SecurityUserWrapper(username, "password", false, false, false, false, Collections.emptyList(), applicationUser), null)); try { jobService.deleteJob(job.getId(), new JobDeleteRequest("test delete reason")); fail(); } catch (Exception e) { assertEquals(AccessDeniedException.class, e.getClass()); assertEquals(String.format("User \"%s\" does not have \"[EXECUTE]\" permission(s) to the namespace \"%s\"", username, TEST_ACTIVITI_NAMESPACE_CD), e.getMessage()); } }
@Test public void testDeleteJobAssertNoErrorWhenUserHasPermissions() 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)); 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.EXECUTE))); SecurityContextHolder.getContext().setAuthentication( new TestingAuthenticationToken(new SecurityUserWrapper(username, "password", false, false, false, false, Collections.emptyList(), applicationUser), null)); try { jobService.deleteJob(job.getId(), new JobDeleteRequest("test delete reason")); } catch (AccessDeniedException e) { fail(); } }
/** * 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()); } }
Job deleteJobResponse = jobService.deleteJob(processInstanceId, new JobDeleteRequest(ACTIVITI_JOB_DELETE_REASON)); assertEquals(JobStatusEnum.COMPLETED, deleteJobResponse.getStatus()); assertEquals(ACTIVITI_JOB_DELETE_REASON, deleteJobResponse.getDeleteReason());
Job deleteJobResponse = jobService.deleteJob(processInstanceId, new JobDeleteRequest(ACTIVITI_JOB_DELETE_REASON)); assertEquals(JobStatusEnum.COMPLETED, deleteJobResponse.getStatus()); assertEquals(ACTIVITI_JOB_DELETE_REASON, deleteJobResponse.getDeleteReason());
/** * 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()); }