Search in sources :

Example 11 with HistoricVariableUpdate

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

the class FullHistoryTest method testVariableInstance.

@Test
public void testVariableInstance() {
    Task newTask = taskService.newTask();
    taskService.saveTask(newTask);
    String variableName = "someName";
    String variableValue = "someValue";
    taskService.setVariable(newTask.getId(), variableName, variableValue);
    VariableInstance variable = runtimeService.createVariableInstanceQuery().singleResult();
    assertNotNull(variable);
    HistoricVariableUpdate result = (HistoricVariableUpdate) historyService.createHistoricDetailQuery().variableUpdates().singleResult();
    assertNotNull(result);
    assertEquals(variable.getId(), result.getVariableInstanceId());
    taskService.deleteTask(newTask.getId(), true);
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) Task(org.camunda.bpm.engine.task.Task) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test)

Example 12 with HistoricVariableUpdate

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

the class FullHistoryTest method testDisableBinaryFetchingForFileValues.

@Test
@Deployment(resources = "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml")
public void testDisableBinaryFetchingForFileValues() {
    // given
    String fileName = "text.txt";
    String encoding = "crazy-encoding";
    String mimeType = "martini/dry";
    FileValue fileValue = Variables.fileValue(fileName).file("ABC".getBytes()).encoding(encoding).mimeType(mimeType).create();
    runtimeService.startProcessInstanceByKey("oneTaskProcess", Variables.createVariables().putValueTyped("fileVar", fileValue));
    // when enabling binary fetching
    HistoricVariableUpdate fileVariableInstance = (HistoricVariableUpdate) historyService.createHistoricDetailQuery().singleResult();
    // then the binary value is accessible
    assertNotNull(fileVariableInstance.getValue());
    // when disabling binary fetching
    fileVariableInstance = (HistoricVariableUpdate) historyService.createHistoricDetailQuery().disableBinaryFetching().singleResult();
    // then the byte value is not fetched
    assertNotNull(fileVariableInstance);
    assertEquals("fileVar", fileVariableInstance.getVariableName());
    assertNull(fileVariableInstance.getValue());
    FileValue typedValue = (FileValue) fileVariableInstance.getTypedValue();
    assertNull(typedValue.getValue());
    // but typed value metadata is accessible
    assertEquals(ValueType.FILE, typedValue.getType());
    assertEquals(fileName, typedValue.getFilename());
    assertEquals(encoding, typedValue.getEncoding());
    assertEquals(mimeType, typedValue.getMimeType());
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 13 with HistoricVariableUpdate

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

the class FullHistoryTest method testDisableCustomObjectDeserialization.

@Test
public void testDisableCustomObjectDeserialization() {
    Task newTask = taskService.newTask();
    taskService.saveTask(newTask);
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("customSerializable", new CustomSerializable());
    variables.put("failingSerializable", new FailingSerializable());
    taskService.setVariables(newTask.getId(), variables);
    List<HistoricDetail> results = historyService.createHistoricDetailQuery().disableBinaryFetching().disableCustomObjectDeserialization().variableUpdates().list();
    // both variables are not deserialized, but their serialized values are available
    assertEquals(2, results.size());
    for (HistoricDetail update : results) {
        HistoricVariableUpdate variableUpdate = (HistoricVariableUpdate) update;
        assertNull(variableUpdate.getErrorMessage());
        ObjectValue typedValue = (ObjectValue) variableUpdate.getTypedValue();
        assertNotNull(typedValue);
        assertFalse(typedValue.isDeserialized());
        // cannot access the deserialized value
        try {
            typedValue.getValue();
        } catch (IllegalStateException e) {
            Assert.assertThat(e.getMessage(), CoreMatchers.containsString("Object is not deserialized"));
        }
        assertNotNull(typedValue.getValueSerialized());
    }
    taskService.deleteTask(newTask.getId(), true);
}
Also used : FailingSerializable(org.camunda.bpm.engine.test.api.runtime.util.FailingSerializable) HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) Task(org.camunda.bpm.engine.task.Task) ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) HashMap(java.util.HashMap) CustomSerializable(org.camunda.bpm.engine.test.api.runtime.util.CustomSerializable) Test(org.junit.Test)

Example 14 with HistoricVariableUpdate

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

the class FullHistoryTest method testVariableUpdatesLinkedToActivity.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/standalone/history/FullHistoryTest.testVariableUpdatesAreLinkedToActivity.bpmn20.xml" })
public void testVariableUpdatesLinkedToActivity() throws Exception {
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("ProcessWithSubProcess");
    Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("test", "1");
    taskService.complete(task.getId(), variables);
    // now we are in the subprocess
    task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    variables.clear();
    variables.put("test", "2");
    taskService.complete(task.getId(), variables);
    // now we are ended
    testHelper.assertProcessEnded(pi.getId());
    // check history
    List<HistoricDetail> updates = historyService.createHistoricDetailQuery().variableUpdates().list();
    assertEquals(2, updates.size());
    Map<String, HistoricVariableUpdate> updatesMap = new HashMap<String, HistoricVariableUpdate>();
    HistoricVariableUpdate update = (HistoricVariableUpdate) updates.get(0);
    updatesMap.put((String) update.getValue(), update);
    update = (HistoricVariableUpdate) updates.get(1);
    updatesMap.put((String) update.getValue(), update);
    HistoricVariableUpdate update1 = updatesMap.get("1");
    HistoricVariableUpdate update2 = updatesMap.get("2");
    assertNotNull(update1.getActivityInstanceId());
    assertNotNull(update1.getExecutionId());
    HistoricActivityInstance historicActivityInstance1 = historyService.createHistoricActivityInstanceQuery().activityInstanceId(update1.getActivityInstanceId()).singleResult();
    assertEquals(historicActivityInstance1.getExecutionId(), update1.getExecutionId());
    assertEquals("usertask1", historicActivityInstance1.getActivityId());
    assertNotNull(update2.getActivityInstanceId());
    HistoricActivityInstance historicActivityInstance2 = historyService.createHistoricActivityInstanceQuery().activityInstanceId(update2.getActivityInstanceId()).singleResult();
    assertEquals("usertask2", historicActivityInstance2.getActivityId());
    /*
     * This is OK! The variable is set on the root execution, on a execution never run through the activity, where the process instances
     * stands when calling the set Variable. But the ActivityId of this flow node is used. So the execution id's doesn't have to be equal.
     *
     * execution id: On which execution it was set
     * activity id: in which activity was the process instance when setting the variable
     */
    assertFalse(historicActivityInstance2.getExecutionId().equals(update2.getExecutionId()));
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) Task(org.camunda.bpm.engine.task.Task) HashMap(java.util.HashMap) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricActivityInstance(org.camunda.bpm.engine.history.HistoricActivityInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 15 with HistoricVariableUpdate

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

the class FullHistoryTest method testHistoricVariableUpdateCaseDefinitionProperty.

@Test
@Deployment(resources = "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn")
public void testHistoricVariableUpdateCaseDefinitionProperty() {
    // given
    String key = "oneTaskCase";
    CaseInstance caseInstance = caseService.createCaseInstanceByKey(key);
    String caseInstanceId = caseInstance.getId();
    String humanTask = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult().getId();
    String taskId = taskService.createTaskQuery().singleResult().getId();
    caseService.setVariable(caseInstanceId, "aVariable", "aValue");
    taskService.setVariableLocal(taskId, "aLocalVariable", "anotherValue");
    String firstVariable = runtimeService.createVariableInstanceQuery().variableName("aVariable").singleResult().getId();
    String secondVariable = runtimeService.createVariableInstanceQuery().variableName("aLocalVariable").singleResult().getId();
    // when (1)
    HistoricVariableUpdate instance = (HistoricVariableUpdate) historyService.createHistoricDetailQuery().variableUpdates().variableInstanceId(firstVariable).singleResult();
    // then (1)
    assertNotNull(instance.getCaseDefinitionKey());
    assertEquals(key, instance.getCaseDefinitionKey());
    assertNotNull(instance.getCaseDefinitionId());
    assertEquals(caseInstance.getCaseDefinitionId(), instance.getCaseDefinitionId());
    assertNull(instance.getProcessDefinitionKey());
    assertNull(instance.getProcessDefinitionId());
    // when (2)
    instance = (HistoricVariableUpdate) historyService.createHistoricDetailQuery().variableUpdates().variableInstanceId(secondVariable).singleResult();
    // then (2)
    assertNotNull(instance.getCaseDefinitionKey());
    assertEquals(key, instance.getCaseDefinitionKey());
    assertNotNull(instance.getCaseDefinitionId());
    assertEquals(caseInstance.getCaseDefinitionId(), instance.getCaseDefinitionId());
    assertNull(instance.getProcessDefinitionKey());
    assertNull(instance.getProcessDefinitionId());
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

HistoricVariableUpdate (org.camunda.bpm.engine.history.HistoricVariableUpdate)29 Test (org.junit.Test)19 Deployment (org.camunda.bpm.engine.test.Deployment)13 HistoricDetail (org.camunda.bpm.engine.history.HistoricDetail)10 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)10 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)8 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)8 AbstractRestServiceTest (org.camunda.bpm.engine.rest.AbstractRestServiceTest)8 MockHistoricVariableUpdateBuilder (org.camunda.bpm.engine.rest.helper.MockHistoricVariableUpdateBuilder)7 HistoricActivityInstance (org.camunda.bpm.engine.history.HistoricActivityInstance)6 HashMap (java.util.HashMap)5 Task (org.camunda.bpm.engine.task.Task)5 ObjectValue (org.camunda.bpm.engine.variable.value.ObjectValue)5 FileValue (org.camunda.bpm.engine.variable.value.FileValue)4 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Response (com.jayway.restassured.response.Response)2 HistoryService (org.camunda.bpm.engine.HistoryService)2 HistoricVariableInstanceQuery (org.camunda.bpm.engine.history.HistoricVariableInstanceQuery)2 MockObjectValue (org.camunda.bpm.engine.rest.helper.MockObjectValue)2