Search in sources :

Example 6 with HistoricDetail

use of org.camunda.bpm.engine.history.HistoricDetail in project camunda-bpm-platform by camunda.

the class BulkHistoryDeleteTest method testCleanupHistoryCaseInstanceDetails.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testCleanupHistoryCaseInstanceDetails() {
    // given
    // create case instances
    String variableNameCase1 = "varName1";
    CaseInstance caseInstance1 = caseService.createCaseInstanceByKey("oneTaskCase", Variables.createVariables().putValue(variableNameCase1, "value1"));
    CaseInstance caseInstance2 = caseService.createCaseInstanceByKey("oneTaskCase", Variables.createVariables().putValue("varName2", "value2"));
    caseService.setVariable(caseInstance1.getId(), variableNameCase1, "theValue");
    // assume
    List<HistoricDetail> detailsList = historyService.createHistoricDetailQuery().list();
    assertEquals(3, detailsList.size());
    caseService.terminateCaseExecution(caseInstance1.getId(), caseService.getVariables(caseInstance1.getId()));
    caseService.terminateCaseExecution(caseInstance2.getId(), caseService.getVariables(caseInstance2.getId()));
    caseService.closeCaseInstance(caseInstance1.getId());
    caseService.closeCaseInstance(caseInstance2.getId());
    // when
    historyService.deleteHistoricCaseInstancesBulk(Arrays.asList(caseInstance1.getId(), caseInstance2.getId()));
    // then
    detailsList = historyService.createHistoricDetailQuery().list();
    assertEquals(0, detailsList.size());
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) HistoricCaseInstance(org.camunda.bpm.engine.history.HistoricCaseInstance) HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 7 with HistoricDetail

use of org.camunda.bpm.engine.history.HistoricDetail in project camunda-bpm-platform by camunda.

the class ProcessInstanceModificationHistoryTest method testStartTransitionWithVariablesInHistory.

@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS)
public void testStartTransitionWithVariablesInHistory() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("exclusiveGateway");
    runtimeService.createProcessInstanceModification(processInstance.getId()).startTransition("flow2").setVariable("procInstVar", "procInstValue").setVariableLocal("localVar", "localValue").execute();
    ActivityInstance updatedTree = runtimeService.getActivityInstance(processInstance.getId());
    HistoricVariableInstance procInstVariable = historyService.createHistoricVariableInstanceQuery().variableName("procInstVar").singleResult();
    assertNotNull(procInstVariable);
    assertEquals(updatedTree.getId(), procInstVariable.getActivityInstanceId());
    assertEquals("procInstVar", procInstVariable.getName());
    assertEquals("procInstValue", procInstVariable.getValue());
    HistoricDetail procInstanceVarDetail = historyService.createHistoricDetailQuery().variableInstanceId(procInstVariable.getId()).singleResult();
    assertNotNull(procInstanceVarDetail);
    assertEquals(updatedTree.getId(), procInstVariable.getActivityInstanceId());
    HistoricVariableInstance localVariable = historyService.createHistoricVariableInstanceQuery().variableName("localVar").singleResult();
    assertNotNull(localVariable);
    assertEquals(updatedTree.getId(), procInstVariable.getActivityInstanceId());
    assertEquals("localVar", localVariable.getName());
    assertEquals("localValue", localVariable.getValue());
    HistoricDetail localInstanceVarDetail = historyService.createHistoricDetailQuery().variableInstanceId(localVariable.getId()).singleResult();
    assertNotNull(localInstanceVarDetail);
    // when starting before/after an activity instance, the activity instance id of the
    // execution is null and so is the activity instance id of the historic detail
    assertNull(localInstanceVarDetail.getActivityInstanceId());
    completeTasksInOrder("task1", "task1");
    assertProcessEnded(processInstance.getId());
}
Also used : HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) HistoricActivityInstance(org.camunda.bpm.engine.history.HistoricActivityInstance) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 8 with HistoricDetail

use of org.camunda.bpm.engine.history.HistoricDetail in project camunda-bpm-platform by camunda.

the class TaskServiceTest method checkHistoricVariableUpdateEntity.

private void checkHistoricVariableUpdateEntity(String variableName, String processInstanceId) {
    if (processEngineConfiguration.getHistoryLevel().getId() == ProcessEngineConfigurationImpl.HISTORYLEVEL_FULL) {
        boolean deletedVariableUpdateFound = false;
        List<HistoricDetail> resultSet = historyService.createHistoricDetailQuery().processInstanceId(processInstanceId).list();
        for (HistoricDetail currentHistoricDetail : resultSet) {
            assertTrue(currentHistoricDetail instanceof HistoricDetailVariableInstanceUpdateEntity);
            HistoricDetailVariableInstanceUpdateEntity historicVariableUpdate = (HistoricDetailVariableInstanceUpdateEntity) currentHistoricDetail;
            if (historicVariableUpdate.getName().equals(variableName)) {
                if (historicVariableUpdate.getValue() == null) {
                    if (deletedVariableUpdateFound) {
                        fail("Mismatch: A HistoricVariableUpdateEntity with a null value already found");
                    } else {
                        deletedVariableUpdateFound = true;
                    }
                }
            }
        }
        assertTrue(deletedVariableUpdateFound);
    }
}
Also used : HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) HistoricDetailVariableInstanceUpdateEntity(org.camunda.bpm.engine.impl.persistence.entity.HistoricDetailVariableInstanceUpdateEntity)

Example 9 with HistoricDetail

use of org.camunda.bpm.engine.history.HistoricDetail in project camunda-bpm-platform by camunda.

the class VariableListenerTest method FAILING_testListenerDoesNotInterfereWithHistory.

/**
 * TODO: add when history for case execution variables is implemented
 */
@Deployment
public void FAILING_testListenerDoesNotInterfereWithHistory() {
    CaseInstance caseInstance = caseService.withCaseDefinitionByKey("case").create();
    // when i set a variable that causes the listener to be notified
    // and that listener sets the same variable to another value (here "value2")
    caseService.withCaseExecution(caseInstance.getId()).setVariableLocal("variable", "value1").execute();
    // then there should be two historic variable updates for both values
    if (processEngineConfiguration.getHistoryLevel().getId() >= HistoryLevel.HISTORY_LEVEL_FULL.getId()) {
        List<HistoricDetail> variableUpdates = historyService.createHistoricDetailQuery().variableUpdates().list();
        assertEquals(2, variableUpdates.size());
        for (HistoricDetail detail : variableUpdates) {
            HistoricVariableUpdate update = (HistoricVariableUpdate) detail;
            boolean update1Processed = false;
            boolean update2Processed = false;
            if (!update1Processed && update.getValue().equals("value1")) {
                update1Processed = true;
            } else if (!update2Processed && update.getValue().equals("value2")) {
                update2Processed = true;
            } else {
                fail("unexpected variable update");
            }
        }
    }
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 10 with HistoricDetail

use of org.camunda.bpm.engine.history.HistoricDetail in project camunda-bpm-platform by camunda.

the class HistoricVariableInstanceScopeTest method testCmmnActivityInstanceIdOnTask.

@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());
    }
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) Task(org.camunda.bpm.engine.task.Task) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

HistoricDetail (org.camunda.bpm.engine.history.HistoricDetail)40 Deployment (org.camunda.bpm.engine.test.Deployment)23 Test (org.junit.Test)20 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)14 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)14 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)14 Task (org.camunda.bpm.engine.task.Task)13 HistoricActivityInstance (org.camunda.bpm.engine.history.HistoricActivityInstance)12 HistoricVariableUpdate (org.camunda.bpm.engine.history.HistoricVariableUpdate)10 HashMap (java.util.HashMap)7 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)7 CaseInstance (org.camunda.bpm.engine.runtime.CaseInstance)6 ArrayList (java.util.ArrayList)3 HistoricCaseInstance (org.camunda.bpm.engine.history.HistoricCaseInstance)3 HistoricDetailVariableInstanceUpdateEntity (org.camunda.bpm.engine.impl.persistence.entity.HistoricDetailVariableInstanceUpdateEntity)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 HistoricDetailQuery (org.camunda.bpm.engine.history.HistoricDetailQuery)2 HistoricFormProperty (org.camunda.bpm.engine.history.HistoricFormProperty)2 HistoricVariableInstanceQuery (org.camunda.bpm.engine.history.HistoricVariableInstanceQuery)2