@Deployment(resources = {"org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn"})
  public void testCmmnActivityInstanceIdOnTask() {

    // given
    CaseInstance caseInstance = caseService.createCaseInstanceByKey("oneTaskCase");

    String taskExecutionId =
        caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult().getId();

    Task task = taskService.createTaskQuery().singleResult();

    // when
    taskService.setVariable(task.getId(), "foo", "bar");

    // then
    HistoricVariableInstance variable =
        historyService.createHistoricVariableInstanceQuery().variableName("foo").singleResult();

    assertNotNull(variable);
    assertEquals(caseInstance.getId(), variable.getActivityInstanceId());

    if (processEngineConfiguration.getHistoryLevel().getId()
        > ProcessEngineConfigurationImpl.HISTORYLEVEL_AUDIT) {
      HistoricDetail variableDetail =
          historyService
              .createHistoricDetailQuery()
              .variableUpdates()
              .variableInstanceId(variable.getId())
              .singleResult();
      assertEquals(taskExecutionId, variableDetail.getActivityInstanceId());
    }
  }
  @Deployment
  public void testInputMappings() {
    // given
    String processInstanceId = runtimeService.startProcessInstanceByKey("process").getId();

    HistoricActivityInstanceQuery activityInstanceQuery =
        historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId);

    String theService1Id = activityInstanceQuery.activityId("theService1").singleResult().getId();
    String theService2Id = activityInstanceQuery.activityId("theService2").singleResult().getId();
    String theTaskId = activityInstanceQuery.activityId("theTask").singleResult().getId();

    // when (1)
    HistoricVariableInstance firstVariable =
        historyService
            .createHistoricVariableInstanceQuery()
            .variableName("firstInputVariable")
            .singleResult();

    // then (1)
    assertEquals(theService1Id, firstVariable.getActivityInstanceId());

    if (processEngineConfiguration.getHistoryLevel().getId()
        > ProcessEngineConfigurationImpl.HISTORYLEVEL_AUDIT) {
      HistoricDetail firstVariableDetail =
          historyService
              .createHistoricDetailQuery()
              .variableUpdates()
              .variableInstanceId(firstVariable.getId())
              .singleResult();
      assertEquals(theService1Id, firstVariableDetail.getActivityInstanceId());
    }

    // when (2)
    HistoricVariableInstance secondVariable =
        historyService
            .createHistoricVariableInstanceQuery()
            .variableName("secondInputVariable")
            .singleResult();

    // then (2)
    assertEquals(theService2Id, secondVariable.getActivityInstanceId());

    if (processEngineConfiguration.getHistoryLevel().getId()
        > ProcessEngineConfigurationImpl.HISTORYLEVEL_AUDIT) {
      HistoricDetail secondVariableDetail =
          historyService
              .createHistoricDetailQuery()
              .variableUpdates()
              .variableInstanceId(secondVariable.getId())
              .singleResult();
      assertEquals(theService2Id, secondVariableDetail.getActivityInstanceId());
    }

    // when (3)
    HistoricVariableInstance thirdVariable =
        historyService
            .createHistoricVariableInstanceQuery()
            .variableName("thirdInputVariable")
            .singleResult();

    // then (3)
    assertEquals(theTaskId, thirdVariable.getActivityInstanceId());

    if (processEngineConfiguration.getHistoryLevel().getId()
        > ProcessEngineConfigurationImpl.HISTORYLEVEL_AUDIT) {
      HistoricDetail thirdVariableDetail =
          historyService
              .createHistoricDetailQuery()
              .variableUpdates()
              .variableInstanceId(thirdVariable.getId())
              .singleResult();
      assertEquals(theTaskId, thirdVariableDetail.getActivityInstanceId());
    }
  }