Search in sources :

Example 21 with HistoricVariableInstance

use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.

the class HistoricVariableInstanceTest method testHistoricVariableInstanceQuery.

@Deployment(resources = { "org/activiti/engine/test/history/HistoricVariableInstanceTest.testCallSimpleSubProcess.bpmn20.xml", "org/activiti/engine/test/history/simpleSubProcess.bpmn20.xml" })
public void testHistoricVariableInstanceQuery() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("callSimpleSubProcess");
        assertProcessEnded(processInstance.getId());
        assertThat(historyService.createHistoricVariableInstanceQuery().count()).isEqualTo(4);
        assertThat(historyService.createHistoricVariableInstanceQuery().list()).hasSize(4);
        assertThat(historyService.createHistoricVariableInstanceQuery().orderByProcessInstanceId().asc().count()).isEqualTo(4);
        assertThat(historyService.createHistoricVariableInstanceQuery().orderByProcessInstanceId().asc().list()).hasSize(4);
        assertThat(historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc().count()).isEqualTo(4);
        assertThat(historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc().list()).hasSize(4);
        assertThat(historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).count()).isEqualTo(2);
        assertThat(historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).list()).hasSize(2);
        assertThat(historyService.createHistoricVariableInstanceQuery().variableName("myVar").count()).isEqualTo(2);
        assertThat(historyService.createHistoricVariableInstanceQuery().variableName("myVar").list()).hasSize(2);
        assertThat(historyService.createHistoricVariableInstanceQuery().variableNameLike("myVar1").count()).isEqualTo(2);
        assertThat(historyService.createHistoricVariableInstanceQuery().variableNameLike("myVar1").list()).hasSize(2);
        List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().list();
        assertThat(variables).hasSize(4);
        assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("myVar", "test123").count()).isEqualTo(1);
        assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("myVar", "test123").list()).hasSize(1);
        assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("myVar1", "test456").count()).isEqualTo(1);
        assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("myVar1", "test456").list()).hasSize(1);
        assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("myVar", "test666").count()).isEqualTo(1);
        assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("myVar", "test666").list()).hasSize(1);
        assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("myVar1", "test666").count()).isEqualTo(1);
        assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("myVar1", "test666").list()).hasSize(1);
        assertThat(historyService.createHistoricActivityInstanceQuery().count()).isEqualTo(8);
        assertThat(historyService.createHistoricDetailQuery().count()).isEqualTo(5);
    }
}
Also used : ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) Deployment(org.activiti.engine.test.Deployment)

Example 22 with HistoricVariableInstance

use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.

the class ProcessInstanceLogQueryAndByteArrayTypeVariableTest method testIncludeVariableUpdates.

public void testIncludeVariableUpdates() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
        HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).variableName("var").singleResult();
        assertThat(LARGE_STRING_VALUE).isEqualTo(historicVariableInstance.getValue());
        ProcessInstanceHistoryLog log = historyService.createProcessInstanceHistoryLogQuery(processInstanceId).includeVariableUpdates().singleResult();
        List<HistoricData> events = log.getHistoricData();
        assertThat(events).hasSize(1);
        for (HistoricData event : events) {
            assertThat(event).isInstanceOf(HistoricVariableUpdate.class);
            assertThat(LARGE_STRING_VALUE).isEqualTo(((HistoricDetailVariableInstanceUpdateEntity) event).getValue());
        }
    }
}
Also used : HistoricData(org.activiti.engine.history.HistoricData) ProcessInstanceHistoryLog(org.activiti.engine.history.ProcessInstanceHistoryLog) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance)

Example 23 with HistoricVariableInstance

use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.

the class FullHistoryTest method testHistoricVariableUpdatesAllTypes.

@Deployment
public void testHistoricVariableUpdatesAllTypes() throws Exception {
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss SSS");
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("aVariable", "initial value");
    Date startedDate = sdf.parse("01/01/2001 01:23:45 000");
    // In the javaDelegate, the current time is manipulated
    Date updatedDate = sdf.parse("01/01/2001 01:23:46 000");
    processEngineConfiguration.getClock().setCurrentTime(startedDate);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("HistoricVariableUpdateProcess", variables);
    List<HistoricDetail> details = historyService.createHistoricDetailQuery().variableUpdates().processInstanceId(processInstance.getId()).orderByVariableName().asc().orderByTime().asc().list();
    // 8 variable updates should be present, one performed when starting process the other 7 are set in VariableSetter serviceTask
    assertThat(details).hasSize(9);
    // Since we order by varName, first entry should be aVariable update from startTask
    HistoricVariableUpdate startVarUpdate = (HistoricVariableUpdate) details.get(0);
    assertThat(startVarUpdate.getVariableName()).isEqualTo("aVariable");
    assertThat(startVarUpdate.getValue()).isEqualTo("initial value");
    assertThat(startVarUpdate.getRevision()).isEqualTo(0);
    assertThat(startVarUpdate.getProcessInstanceId()).isEqualTo(processInstance.getId());
    // Date should the the one set when starting
    assertThat(startVarUpdate.getTime()).isEqualTo(startedDate);
    HistoricVariableUpdate updatedStringVariable = (HistoricVariableUpdate) details.get(1);
    assertThat(updatedStringVariable.getVariableName()).isEqualTo("aVariable");
    assertThat(updatedStringVariable.getValue()).isEqualTo("updated value");
    assertThat(updatedStringVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    // Date should be the updated date
    assertThat(updatedStringVariable.getTime()).isEqualTo(updatedDate);
    HistoricVariableUpdate intVariable = (HistoricVariableUpdate) details.get(2);
    assertThat(intVariable.getVariableName()).isEqualTo("bVariable");
    assertThat(intVariable.getValue()).isEqualTo(123);
    assertThat(intVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    assertThat(intVariable.getTime()).isEqualTo(updatedDate);
    HistoricVariableUpdate longVariable = (HistoricVariableUpdate) details.get(3);
    assertThat(longVariable.getVariableName()).isEqualTo("cVariable");
    assertThat(longVariable.getValue()).isEqualTo(12345L);
    assertThat(longVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    assertThat(longVariable.getTime()).isEqualTo(updatedDate);
    HistoricVariableUpdate doubleVariable = (HistoricVariableUpdate) details.get(4);
    assertThat(doubleVariable.getVariableName()).isEqualTo("dVariable");
    assertThat(doubleVariable.getValue()).isEqualTo(1234.567);
    assertThat(doubleVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    assertThat(doubleVariable.getTime()).isEqualTo(updatedDate);
    HistoricVariableUpdate shortVariable = (HistoricVariableUpdate) details.get(5);
    assertThat(shortVariable.getVariableName()).isEqualTo("eVariable");
    assertThat(shortVariable.getValue()).isEqualTo((short) 12);
    assertThat(shortVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    assertThat(shortVariable.getTime()).isEqualTo(updatedDate);
    HistoricVariableUpdate dateVariable = (HistoricVariableUpdate) details.get(6);
    assertThat(dateVariable.getVariableName()).isEqualTo("fVariable");
    assertThat(dateVariable.getValue()).isEqualTo(sdf.parse("01/01/2001 01:23:45 678"));
    assertThat(dateVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    assertThat(dateVariable.getTime()).isEqualTo(updatedDate);
    HistoricVariableUpdate serializableVariable = (HistoricVariableUpdate) details.get(7);
    assertThat(serializableVariable.getVariableName()).isEqualTo("gVariable");
    assertThat(serializableVariable.getValue()).isEqualTo(new SerializableVariable("hello hello"));
    assertThat(serializableVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    assertThat(serializableVariable.getTime()).isEqualTo(updatedDate);
    HistoricVariableUpdate byteArrayVariable = (HistoricVariableUpdate) details.get(8);
    assertThat(byteArrayVariable.getVariableName()).isEqualTo("hVariable");
    assertThat(new String((byte[]) byteArrayVariable.getValue())).isEqualTo(";-)");
    assertThat(byteArrayVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    assertThat(byteArrayVariable.getTime()).isEqualTo(updatedDate);
    // end process instance
    List<Task> tasks = taskService.createTaskQuery().list();
    assertThat(tasks).hasSize(1);
    taskService.complete(tasks.get(0).getId());
    assertProcessEnded(processInstance.getId());
    // check for historic process variables set
    HistoricVariableInstanceQuery historicProcessVariableQuery = historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc();
    assertThat(historicProcessVariableQuery.count()).isEqualTo(8);
    List<HistoricVariableInstance> historicVariables = historicProcessVariableQuery.list();
    // Variable status when process is finished
    HistoricVariableInstance historicVariable = historicVariables.get(0);
    assertThat(historicVariable.getVariableName()).isEqualTo("aVariable");
    assertThat(historicVariable.getValue()).isEqualTo("updated value");
    assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    historicVariable = historicVariables.get(1);
    assertThat(historicVariable.getVariableName()).isEqualTo("bVariable");
    assertThat(historicVariable.getValue()).isEqualTo(123);
    assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    historicVariable = historicVariables.get(2);
    assertThat(historicVariable.getVariableName()).isEqualTo("cVariable");
    assertThat(historicVariable.getValue()).isEqualTo(12345L);
    assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    historicVariable = historicVariables.get(3);
    assertThat(historicVariable.getVariableName()).isEqualTo("dVariable");
    assertThat(historicVariable.getValue()).isEqualTo(1234.567);
    assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    historicVariable = historicVariables.get(4);
    assertThat(historicVariable.getVariableName()).isEqualTo("eVariable");
    assertThat(historicVariable.getValue()).isEqualTo((short) 12);
    assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    historicVariable = historicVariables.get(5);
    assertThat(historicVariable.getVariableName()).isEqualTo("fVariable");
    assertThat(historicVariable.getValue()).isEqualTo(sdf.parse("01/01/2001 01:23:45 678"));
    assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    historicVariable = historicVariables.get(6);
    assertThat(historicVariable.getVariableName()).isEqualTo("gVariable");
    assertThat(historicVariable.getValue()).isEqualTo(new SerializableVariable("hello hello"));
    assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    historicVariable = historicVariables.get(7);
    assertThat(historicVariable.getVariableName()).isEqualTo("hVariable");
    assertThat(new String((byte[]) historicVariable.getValue())).isEqualTo(";-)");
    assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
}
Also used : HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) HistoricDetail(org.activiti.engine.history.HistoricDetail) Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) Date(java.util.Date) SerializableVariable(org.activiti.engine.test.history.SerializableVariable) HistoricVariableInstanceQuery(org.activiti.engine.history.HistoricVariableInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) SimpleDateFormat(java.text.SimpleDateFormat) Deployment(org.activiti.engine.test.Deployment)

Example 24 with HistoricVariableInstance

use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.

the class HistoricVariableInstanceEscapeClauseTest method testQueryByVariableNameLike.

@Test
public void testQueryByVariableNameLike() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().variableNameLike("%\\%%").singleResult();
        assertThat(historicVariable).isNotNull();
        assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance1.getId());
        assertThat(historicVariable.getValue()).isEqualTo("One%");
        historicVariable = historyService.createHistoricVariableInstanceQuery().variableNameLike("%\\_%").singleResult();
        assertThat(historicVariable).isNotNull();
        assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance2.getId());
        assertThat(historicVariable.getValue()).isEqualTo("Two_");
    }
}
Also used : HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) Test(org.junit.Test)

Example 25 with HistoricVariableInstance

use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.

the class HistoricVariableInstanceEscapeClauseTest method testQueryLikeByQueryVariableValueIgnoreCase.

@Test
public void testQueryLikeByQueryVariableValueIgnoreCase() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().variableValueLikeIgnoreCase("var%", "%\\%%").singleResult();
        assertThat(historicVariable).isNotNull();
        assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance1.getId());
        historicVariable = historyService.createHistoricVariableInstanceQuery().variableValueLikeIgnoreCase("var_", "%\\_%").singleResult();
        assertThat(historicVariable).isNotNull();
        assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance2.getId());
    }
}
Also used : HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) Test(org.junit.Test)

Aggregations

HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)56 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)28 Deployment (org.activiti.engine.test.Deployment)25 HashMap (java.util.HashMap)20 Task (org.activiti.engine.task.Task)18 HistoricVariableInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)5 Test (org.junit.Test)5 HistoricData (org.activiti.engine.history.HistoricData)4 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)4 HistoricVariableUpdate (org.activiti.engine.history.HistoricVariableUpdate)4 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 BpmnModel (org.activiti.bpmn.model.BpmnModel)3 HistoryService (org.activiti.engine.HistoryService)3 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)3 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)3 HistoricVariableInstanceQuery (org.activiti.engine.history.HistoricVariableInstanceQuery)3 ProcessInstanceHistoryLog (org.activiti.engine.history.ProcessInstanceHistoryLog)3