public void setJobDefinition(JobDefinition jobDefinition) { this.jobDefinition = jobDefinition; if (jobDefinition != null) { jobDefinitionId = jobDefinition.getId(); } else { jobDefinitionId = null; } }
public Job getJobForDefinition(JobDefinition jobDefinition) { if (jobDefinition != null) { return getManagementService() .createJobQuery().jobDefinitionId(jobDefinition.getId()).singleResult(); } else { return null; } }
@Test public void testSetOverridingJobPriorityWithNoAuthenticatedTenant() { JobDefinition jobDefinition = managementService .createJobDefinitionQuery() .list().get(0); identityService.setAuthentication("aUserId", null); // then thrown.expect(ProcessEngineException.class); thrown.expectMessage("Cannot update the process definition '" + jobDefinition.getProcessDefinitionId() +"' because it belongs to no authenticated tenant."); managementService.setOverridingJobPriorityForJobDefinition(jobDefinition.getId(), 1701); }
@Test public void testSetOverridingJobPriorityWithCascadeAndNoAuthenticatedTenant() { JobDefinition jobDefinition = managementService .createJobDefinitionQuery() .list().get(0); identityService.setAuthentication("aUserId", null); // then thrown.expect(ProcessEngineException.class); thrown.expectMessage("Cannot update the process definition '" + jobDefinition.getProcessDefinitionId() +"' because it belongs to no authenticated tenant."); managementService.setOverridingJobPriorityForJobDefinition(jobDefinition.getId(), 1701, true); }
@Test public void executionJobShouldGetPriorityFromOverridingJobDefinitionPriorityWithCascade() { // given Batch batch = helper.migrateProcessInstancesAsync(1); JobDefinition executionJobDefinition = helper.getExecutionJobDefinition(batch); helper.executeSeedJob(batch); // when managementService.setOverridingJobPriorityForJobDefinition(executionJobDefinition.getId(), CUSTOM_PRIORITY, true); // then Job executionJob = helper.getExecutionJobs(batch).get(0); assertEquals(CUSTOM_PRIORITY, executionJob.getPriority()); }
@Test public void executionJobShouldGetPriorityFromOverridingJobDefinitionPriority() { // given Batch batch = helper.migrateProcessInstancesAsync(1); JobDefinition executionJobDefinition = helper.getExecutionJobDefinition(batch); managementService.setOverridingJobPriorityForJobDefinition(executionJobDefinition.getId(), CUSTOM_PRIORITY, true); // when helper.executeSeedJob(batch); // then Job executionJob = helper.getExecutionJobs(batch).get(0); assertEquals(CUSTOM_PRIORITY, executionJob.getPriority()); }
@Deployment(resources = "org/camunda/bpm/engine/test/api/runtime/oneFailingServiceProcess.bpmn20.xml") public void testActivateJobDefinition() { // given runtimeService.startProcessInstanceByKey("oneFailingServiceTaskProcess"); String id = managementService.createJobDefinitionQuery().singleResult().getId(); // when managementService.activateJobByJobDefinitionId(id); // then verifyNoUserOperationLogged(); }
@Deployment(resources = "org/camunda/bpm/engine/test/api/runtime/oneFailingServiceProcess.bpmn20.xml") public void testSuspendJobDefinition() { // given runtimeService.startProcessInstanceByKey("oneFailingServiceTaskProcess"); String id = managementService.createJobDefinitionQuery().singleResult().getId(); // when managementService.suspendJobByJobDefinitionId(id); // then verifyNoUserOperationLogged(); }
@Test public void testByJobDefinitionId() { JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult(); JobQuery query = managementService.createJobQuery().jobDefinitionId(jobDefinition.getId()); verifyQueryResults(query, 3); }
public void assertJobMigrated(String activityIdBefore, String activityIdAfter, String handlerType) { JobDefinition jobDefinitionBefore = snapshotBeforeMigration.getJobDefinitionForActivityIdAndType(activityIdBefore, handlerType); assertNotNull("Expected that a job definition for activity '" + activityIdBefore + "' exists before migration", jobDefinitionBefore); Job jobBefore = snapshotBeforeMigration.getJobForDefinitionId(jobDefinitionBefore.getId()); assertNotNull("Expected that a timer job for activity '" + activityIdBefore + "' exists before migration", jobBefore); assertJobMigrated(jobBefore, activityIdAfter, jobBefore.getDuedate()); }
@Deployment(resources = "org/camunda/bpm/engine/test/api/mgmt/asyncTaskProcess.bpmn20.xml") public void testSetJobDefinitionPriorityToExtremeValues() { JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult(); // it is possible to set the max long value managementService.setOverridingJobPriorityForJobDefinition(jobDefinition.getId(), Long.MAX_VALUE); jobDefinition = managementService.createJobDefinitionQuery().singleResult(); assertEquals(Long.MAX_VALUE, (long) jobDefinition.getOverridingJobPriority()); // it is possible to set the min long value managementService.setOverridingJobPriorityForJobDefinition(jobDefinition.getId(), Long.MIN_VALUE + 1); // +1 for informix jobDefinition = managementService.createJobDefinitionQuery().singleResult(); assertEquals(Long.MIN_VALUE + 1, (long) jobDefinition.getOverridingJobPriority()); }
public void testSuspendByIdWithUpdatePermissionOnAnyProcessDefinition() { // given createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, UPDATE); String jobDefinitionId = selectJobDefinitionByProcessDefinitionKey(TIMER_BOUNDARY_PROCESS_KEY).getId(); // when managementService.suspendJobDefinitionById(jobDefinitionId); // then JobDefinition jobDefinition = selectJobDefinitionByProcessDefinitionKey(TIMER_BOUNDARY_PROCESS_KEY); assertNotNull(jobDefinition); assertTrue(jobDefinition.isSuspended()); }
public void assertJobRemoved(String activityId, String handlerType) { JobDefinition jobDefinitionBefore = snapshotBeforeMigration.getJobDefinitionForActivityIdAndType(activityId, handlerType); assertNotNull("Expected that a job definition for activity '" + activityId + "' exists before migration", jobDefinitionBefore); Job jobBefore = snapshotBeforeMigration.getJobForDefinitionId(jobDefinitionBefore.getId()); assertNotNull("Expected that a job for activity '" + activityId + "' exists before migration", jobBefore); assertTimerJob(jobBefore); for (Job job : snapshotAfterMigration.getJobs()) { if (jobBefore.getId().equals(job.getId())) { fail("Expected job '" + jobBefore.getId() + "' to be removed after migration"); } } }
@Test public void seedJobShouldGetPriorityFromOverridingJobDefinitionPriorityWithCascade() { // given Batch batch = helper.migrateProcessInstancesAsync(1); JobDefinition seedJobDefinition = helper.getSeedJobDefinition(batch); // when managementService.setOverridingJobPriorityForJobDefinition(seedJobDefinition.getId(), CUSTOM_PRIORITY, true); // then Job seedJob = helper.getSeedJob(batch); assertEquals(CUSTOM_PRIORITY, seedJob.getPriority()); }
public void testActivateByIdWithUpdatePermissionOnProcessDefinition() { // given createGrantAuthorization(PROCESS_DEFINITION, TIMER_BOUNDARY_PROCESS_KEY, userId, UPDATE); String jobDefinitionId = selectJobDefinitionByProcessDefinitionKey(TIMER_BOUNDARY_PROCESS_KEY).getId(); suspendJobDefinitionById(jobDefinitionId); // when managementService.activateJobDefinitionById(jobDefinitionId); // then JobDefinition jobDefinition = selectJobDefinitionByProcessDefinitionKey(TIMER_BOUNDARY_PROCESS_KEY); assertNotNull(jobDefinition); assertFalse(jobDefinition.isSuspended()); }
@Test public void seedJobShouldGetPriorityFromOverridingJobDefinitionPriority() { // given Batch batch = helper.migrateProcessInstancesAsync(2); JobDefinition seedJobDefinition = helper.getSeedJobDefinition(batch); managementService.setOverridingJobPriorityForJobDefinition(seedJobDefinition.getId(), CUSTOM_PRIORITY); // when helper.executeSeedJob(batch); // then Job seedJob = helper.getSeedJob(batch); assertEquals(CUSTOM_PRIORITY, seedJob.getPriority()); }
@Test public void monitorJobShouldGetPriorityOverridingJobDefinitionPriorityWithCascade() { // given Batch batch = helper.migrateProcessInstancesAsync(1); JobDefinition monitorJobDefinition = helper.getMonitorJobDefinition(batch); helper.executeSeedJob(batch); // when managementService.setOverridingJobPriorityForJobDefinition(monitorJobDefinition.getId(), CUSTOM_PRIORITY, true); // then Job monitorJob = helper.getMonitorJob(batch); assertEquals(CUSTOM_PRIORITY, monitorJob.getPriority()); }
public void testSuspendJobByJobDefinitionIdWihtUpdatePermissionOnProcessDefinition() { // given String processInstanceId = startProcessInstanceByKey(TIMER_BOUNDARY_PROCESS_KEY).getId(); String jobDefinitionId = selectJobDefinitionByProcessDefinitionKey(TIMER_BOUNDARY_PROCESS_KEY).getId(); createGrantAuthorization(PROCESS_DEFINITION, TIMER_BOUNDARY_PROCESS_KEY, userId, UPDATE_INSTANCE); // when managementService.suspendJobByJobDefinitionId(jobDefinitionId); // then Job job = selectJobByProcessInstanceId(processInstanceId); assertNotNull(job); assertTrue(job.isSuspended()); }
public void testSuspendJobByJobDefinitionIdWihtUpdatePermissionOnAnyProcessDefinition() { // given String processInstanceId = startProcessInstanceByKey(TIMER_BOUNDARY_PROCESS_KEY).getId(); String jobDefinitionId = selectJobDefinitionByProcessDefinitionKey(TIMER_BOUNDARY_PROCESS_KEY).getId(); createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, UPDATE_INSTANCE); // when managementService.suspendJobByJobDefinitionId(jobDefinitionId); // then Job job = selectJobByProcessInstanceId(processInstanceId); assertNotNull(job); assertTrue(job.isSuspended()); }
public void testSuspendJobByJobDefinitionIdWihtUpdatePermissionOnAnyProcessInstance() { // given String processInstanceId = startProcessInstanceByKey(TIMER_BOUNDARY_PROCESS_KEY).getId(); String jobDefinitionId = selectJobDefinitionByProcessDefinitionKey(TIMER_BOUNDARY_PROCESS_KEY).getId(); createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, UPDATE); // when managementService.suspendJobByJobDefinitionId(jobDefinitionId); // then Job job = selectJobByProcessInstanceId(processInstanceId); assertNotNull(job); assertTrue(job.isSuspended()); }