@Before
  public void deployProcessesAndCreateMigrationPlan() {
    ProcessDefinition sourceDefinition =
        testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
    ProcessDefinition targetDefinition =
        testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);

    migrationPlan =
        engineRule
            .getRuntimeService()
            .createMigrationPlan(sourceDefinition.getId(), targetDefinition.getId())
            .mapEqualActivities()
            .build();

    ProcessInstance pi =
        engineRule.getRuntimeService().startProcessInstanceById(sourceDefinition.getId());

    batch1 =
        engineRule
            .getRuntimeService()
            .newMigration(migrationPlan)
            .processInstanceIds(Arrays.asList(pi.getId()))
            .executeAsync();

    batch2 =
        engineRule
            .getRuntimeService()
            .newMigration(migrationPlan)
            .processInstanceIds(Arrays.asList(pi.getId()))
            .executeAsync();
  }
 public long countTargetProcessInstances() {
   return engineRule
       .getRuntimeService()
       .createProcessInstanceQuery()
       .processDefinitionId(targetProcessDefinition.getId())
       .count();
 }
  /** Unnamed @Deployment annotations don't work with parameterized Unit tests */
  @Ignore
  @Test
  @Deployment
  public void ruleUsageExample() {
    RuntimeService runtimeService = engineRule.getRuntimeService();
    runtimeService.startProcessInstanceByKey("ruleUsage");

    TaskService taskService = engineRule.getTaskService();
    Task task = taskService.createTaskQuery().singleResult();
    assertEquals("My Task", task.getName());

    taskService.complete(task.getId());
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
  }
  public Batch migrateProcessInstancesAsync(
      int numberOfProcessInstances,
      ProcessDefinition sourceProcessDefinition,
      ProcessDefinition targetProcessDefinition) {
    RuntimeService runtimeService = engineRule.getRuntimeService();

    List<String> processInstanceIds = new ArrayList<String>(numberOfProcessInstances);
    for (int i = 0; i < numberOfProcessInstances; i++) {
      processInstanceIds.add(
          runtimeService.startProcessInstanceById(sourceProcessDefinition.getId()).getId());
    }

    MigrationPlan migrationPlan =
        engineRule
            .getRuntimeService()
            .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId())
            .mapEqualActivities()
            .build();

    return runtimeService
        .newMigration(migrationPlan)
        .processInstanceIds(processInstanceIds)
        .executeAsync();
  }
  @Test
  @Deployment(
      resources =
          "org/camunda/bpm/engine/test/standalone/testing/ProcessEngineRuleParameterizedJunit4Test.ruleUsageExample.bpmn20.xml")
  public void ruleUsageExampleWithNamedAnnotation() {
    RuntimeService runtimeService = engineRule.getRuntimeService();
    runtimeService.startProcessInstanceByKey("ruleUsage");

    TaskService taskService = engineRule.getTaskService();
    Task task = taskService.createTaskQuery().singleResult();
    assertEquals("My Task", task.getName());

    taskService.complete(task.getId());
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
  }
  @Test
  @Deployment(resources = {"invokeRestService.bpmn"})
  public void shouldPackForWork() {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("date", "2014-01-02");

    RuntimeService runtimeService = processEngineRule.getRuntimeService();
    TaskService taskService = processEngineRule.getTaskService();

    runtimeService.startProcessInstanceByKey("holiday", variables);

    Task task = taskService.createTaskQuery().singleResult();
    Assert.assertNotNull(task);
    assertEquals("Pack for work", task.getName());

    boolean isHoliday =
        Boolean.parseBoolean(taskService.getVariable(task.getId(), "isHoliday").toString());
    Assert.assertFalse(isHoliday);
  }