Search in sources :

Example 81 with VariableInstance

use of org.camunda.bpm.engine.runtime.VariableInstance in project camunda-bpm-platform by camunda.

the class VariableInstanceQueryTest method testQueryByTaskIds.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testQueryByTaskIds() {
    // given
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("stringVar", "test");
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    Task task1 = taskService.createTaskQuery().processInstanceId(processInstance1.getId()).singleResult();
    Task task2 = taskService.createTaskQuery().processInstanceId(processInstance2.getId()).singleResult();
    Task task3 = taskService.createTaskQuery().processInstanceId(processInstance3.getId()).singleResult();
    taskService.setVariableLocal(task1.getId(), "taskVariable", "aCustomValue");
    taskService.setVariableLocal(task2.getId(), "anotherTaskVariable", "aCustomValue");
    // when
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().taskIdIn(task1.getId(), task2.getId(), task3.getId());
    // then
    List<VariableInstance> result = query.list();
    assertFalse(result.isEmpty());
    assertEquals(2, result.size());
    assertEquals(2, query.count());
    for (VariableInstance var : result) {
        assertEquals("string", var.getTypeName());
        if (var.getName().equals("taskVariable")) {
            assertEquals("taskVariable", var.getName());
            assertEquals("aCustomValue", var.getValue());
        } else if (var.getName().equals("anotherTaskVariable")) {
            assertEquals("anotherTaskVariable", var.getName());
            assertEquals("aCustomValue", var.getValue());
        } else {
            fail("An unexpected variable '" + var.getName() + "' was found with value " + var.getValue());
        }
    }
}
Also used : Task(org.camunda.bpm.engine.task.Task) HashMap(java.util.HashMap) VariableInstanceQuery(org.camunda.bpm.engine.runtime.VariableInstanceQuery) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 82 with VariableInstance

use of org.camunda.bpm.engine.runtime.VariableInstance in project camunda-bpm-platform by camunda.

the class VariableInstanceQueryTest method checkVariables.

private void checkVariables(List<VariableInstance> variableInstances) {
    assertFalse(variableInstances.isEmpty());
    for (VariableInstance instance : variableInstances) {
        if (instance.getName().equals("nrOfInstances")) {
            assertEquals("nrOfInstances", instance.getName());
            assertEquals("integer", instance.getTypeName());
        } else if (instance.getName().equals("nrOfCompletedInstances")) {
            assertEquals("nrOfCompletedInstances", instance.getName());
            assertEquals("integer", instance.getTypeName());
        } else if (instance.getName().equals("nrOfActiveInstances")) {
            assertEquals("nrOfActiveInstances", instance.getName());
            assertEquals("integer", instance.getTypeName());
        } else if (instance.getName().equals("loopCounter")) {
            assertEquals("loopCounter", instance.getName());
            assertEquals("integer", instance.getTypeName());
        } else if (instance.getName().equals("nullVar")) {
            assertEquals("nullVar", instance.getName());
            assertEquals("null", instance.getTypeName());
        } else if (instance.getName().equals("integerVar")) {
            assertEquals("integerVar", instance.getName());
            assertEquals("integer", instance.getTypeName());
        } else if (instance.getName().equals("dateVar")) {
            assertEquals("dateVar", instance.getName());
            assertEquals("date", instance.getTypeName());
        } else if (instance.getName().equals("stringVar")) {
            assertEquals("stringVar", instance.getName());
            assertEquals("string", instance.getTypeName());
        } else if (instance.getName().equals("shortVar")) {
            assertEquals("shortVar", instance.getName());
            assertEquals("short", instance.getTypeName());
        } else if (instance.getName().equals("longVar")) {
            assertEquals("longVar", instance.getName());
            assertEquals("long", instance.getTypeName());
        } else if (instance.getName().equals("byteVar")) {
            assertEquals("bytes", instance.getTypeName());
        } else if (instance.getName().equals("serializableVar")) {
            assertEquals("serializableVar", instance.getName());
            try {
                instance.getValue();
            } catch (NullPointerException e) {
            // the serialized value has not been initially loaded
            }
        } else {
            fail("An unexpected variable '" + instance.getName() + "' was found with value " + instance.getValue());
        }
    }
}
Also used : VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance)

Example 83 with VariableInstance

use of org.camunda.bpm.engine.runtime.VariableInstance in project camunda-bpm-platform by camunda.

the class VariableInstanceQueryTest method testQueryByNameAndVariableValueNotEquals_String.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testQueryByNameAndVariableValueNotEquals_String() {
    // given
    Map<String, Object> variables1 = new HashMap<String, Object>();
    variables1.put("stringVar", "test");
    runtimeService.startProcessInstanceByKey("oneTaskProcess", variables1);
    Map<String, Object> variables2 = new HashMap<String, Object>();
    variables2.put("stringVar", "test123");
    runtimeService.startProcessInstanceByKey("oneTaskProcess", variables2);
    // when
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().variableValueNotEquals("stringVar", "test123");
    // then
    List<VariableInstance> result = query.list();
    assertFalse(result.isEmpty());
    assertEquals(1, result.size());
    assertEquals(1, query.count());
    VariableInstance var = result.get(0);
    assertEquals("stringVar", var.getName());
    assertEquals("test", var.getValue());
    assertEquals("string", var.getTypeName());
}
Also used : HashMap(java.util.HashMap) VariableInstanceQuery(org.camunda.bpm.engine.runtime.VariableInstanceQuery) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 84 with VariableInstance

use of org.camunda.bpm.engine.runtime.VariableInstance in project camunda-bpm-platform by camunda.

the class VariableInstanceQueryTest method testQueryByNameAndVariableValueLessThanOrEqual_String.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testQueryByNameAndVariableValueLessThanOrEqual_String() {
    // given
    Map<String, Object> variables1 = new HashMap<String, Object>();
    variables1.put("stringVar", "a");
    runtimeService.startProcessInstanceByKey("oneTaskProcess", variables1);
    Map<String, Object> variables2 = new HashMap<String, Object>();
    variables2.put("stringVar", "b");
    runtimeService.startProcessInstanceByKey("oneTaskProcess", variables2);
    Map<String, Object> variables3 = new HashMap<String, Object>();
    variables3.put("stringVar", "c");
    runtimeService.startProcessInstanceByKey("oneTaskProcess", variables3);
    // when
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().variableValueLessThanOrEqual("stringVar", "c");
    // then
    List<VariableInstance> result = query.list();
    assertFalse(result.isEmpty());
    assertEquals(3, result.size());
    assertEquals(3, query.count());
    for (VariableInstance var : result) {
        assertEquals("stringVar", var.getName());
        assertEquals("string", var.getTypeName());
        if (var.getValue().equals("a")) {
            assertEquals("a", var.getValue());
        } else if (var.getValue().equals("b")) {
            assertEquals("b", var.getValue());
        } else if (var.getValue().equals("c")) {
            assertEquals("c", var.getValue());
        } else {
            fail("A non expected value occured: " + var.getValue());
        }
    }
}
Also used : HashMap(java.util.HashMap) VariableInstanceQuery(org.camunda.bpm.engine.runtime.VariableInstanceQuery) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 85 with VariableInstance

use of org.camunda.bpm.engine.runtime.VariableInstance in project camunda-bpm-platform by camunda.

the class VariableInstanceQueryTest method testQueryByCaseExecutionIds.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testQueryByCaseExecutionIds() {
    CaseInstance instance1 = caseService.withCaseDefinitionByKey("oneTaskCase").setVariable("aVariableName", "abc").create();
    CaseInstance instance2 = caseService.withCaseDefinitionByKey("oneTaskCase").setVariable("anotherVariableName", "xyz").create();
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery();
    query.caseExecutionIdIn(instance1.getId(), instance2.getId()).orderByVariableName().asc();
    List<VariableInstance> result = query.list();
    assertEquals(2, result.size());
    for (VariableInstance variableInstance : result) {
        if (variableInstance.getName().equals("aVariableName")) {
            assertEquals("aVariableName", variableInstance.getName());
            assertEquals("abc", variableInstance.getValue());
        } else if (variableInstance.getName().equals("anotherVariableName")) {
            assertEquals("anotherVariableName", variableInstance.getName());
            assertEquals("xyz", variableInstance.getValue());
        } else {
            fail("Unexpected variable: " + variableInstance.getName());
        }
    }
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) VariableInstanceQuery(org.camunda.bpm.engine.runtime.VariableInstanceQuery) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)374 Deployment (org.camunda.bpm.engine.test.Deployment)265 Test (org.junit.Test)167 HashMap (java.util.HashMap)136 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)122 VariableInstanceQuery (org.camunda.bpm.engine.runtime.VariableInstanceQuery)93 Task (org.camunda.bpm.engine.task.Task)67 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)42 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)39 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)33 Execution (org.camunda.bpm.engine.runtime.Execution)33 VariableMap (org.camunda.bpm.engine.variable.VariableMap)30 CaseExecution (org.camunda.bpm.engine.runtime.CaseExecution)27 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)26 CaseInstance (org.camunda.bpm.engine.runtime.CaseInstance)23 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)21 ExecutionTree (org.camunda.bpm.engine.test.util.ExecutionTree)17 CaseExecutionQuery (org.camunda.bpm.engine.runtime.CaseExecutionQuery)13 CaseExecutionEntity (org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity)11 List (java.util.List)10