public List<Job> getJobsForDefinition(JobDefinition jobDefinition) {
   return engineRule
       .getManagementService()
       .createJobQuery()
       .jobDefinitionId(jobDefinition.getId())
       .list();
 }
 public JobDefinition getMigrationJobDefinition(Batch batch) {
   return engineRule
       .getManagementService()
       .createJobDefinitionQuery()
       .jobDefinitionId(batch.getBatchJobDefinitionId())
       .jobType(Batch.TYPE_PROCESS_INSTANCE_MIGRATION)
       .singleResult();
 }
 public JobDefinition getMonitorJobDefinition(Batch batch) {
   return engineRule
       .getManagementService()
       .createJobDefinitionQuery()
       .jobDefinitionId(batch.getMonitorJobDefinitionId())
       .jobType(BatchMonitorJobHandler.TYPE)
       .singleResult();
 }
 public void executeJob(Job job) {
   assertNotNull("Job to execute does not exist", job);
   try {
     engineRule.getManagementService().executeJob(job.getId());
   } catch (Exception e) {
     // ignore
   }
 }
  public void setRetries(Batch batch, int count, int retries) {
    List<Job> migrationJobs = getMigrationJobs(batch);
    assertTrue(migrationJobs.size() >= count);

    ManagementService managementService = engineRule.getManagementService();
    for (int i = 0; i < count; i++) {
      managementService.setJobRetries(migrationJobs.get(i).getId(), retries);
    }
  }
 public Job getJobForDefinition(JobDefinition jobDefinition) {
   if (jobDefinition != null) {
     return engineRule
         .getManagementService()
         .createJobQuery()
         .jobDefinitionId(jobDefinition.getId())
         .singleResult();
   } else {
     return null;
   }
 }
  /** Remove all batches and historic batches. Usually called in {@link org.junit.After} method. */
  public void removeAllRunningAndHistoricBatches() {
    HistoryService historyService = engineRule.getHistoryService();
    ManagementService managementService = engineRule.getManagementService();

    for (Batch batch : managementService.createBatchQuery().list()) {
      managementService.deleteBatch(batch.getId(), true);
    }

    // remove history of completed batches
    for (HistoricBatch historicBatch : historyService.createHistoricBatchQuery().list()) {
      historyService.deleteHistoricBatch(historicBatch.getId());
    }
  }
 @After
 public void deleteBatches() {
   engineRule.getManagementService().deleteBatch(batch1.getId(), true);
   engineRule.getManagementService().deleteBatch(batch2.getId(), true);
 }