Search in sources :

Example 31 with VariableInstanceQuery

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

the class VariableInstanceQueryTest method testQueryByNameAndVariableValueEquals_Short.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testQueryByNameAndVariableValueEquals_Short() {
    // given
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("shortValue", (short) 123);
    runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);
    // when
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().variableValueEquals("shortValue", (short) 123);
    // then
    List<VariableInstance> result = query.list();
    assertFalse(result.isEmpty());
    assertEquals(1, result.size());
    assertEquals(1, query.count());
    VariableInstance var = result.get(0);
    assertEquals("shortValue", var.getName());
    assertEquals((short) 123, var.getValue());
    assertEquals("short", 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 32 with VariableInstanceQuery

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

the class VariableInstanceQueryTest method testParallelGatewayVariables.

@Test
@Deployment
public void testParallelGatewayVariables() {
    // given
    Map<String, Object> processVariables = new HashMap<String, Object>();
    processVariables.put("processVariable", "aProcessVariable");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("parallelGatewayProcess", processVariables);
    Execution execution = runtimeService.createExecutionQuery().activityId("task1").singleResult();
    runtimeService.setVariableLocal(execution.getId(), "aLocalVariable", "aLocalValue");
    ActivityInstance tree = runtimeService.getActivityInstance(processInstance.getId());
    assertEquals(2, tree.getChildActivityInstances().length);
    ActivityInstance task1Instance = tree.getActivityInstances("task1")[0];
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().variableName("aLocalVariable").activityInstanceIdIn(task1Instance.getId());
    VariableInstance localVariable = query.singleResult();
    assertNotNull(localVariable);
    assertEquals("aLocalVariable", localVariable.getName());
    assertEquals("aLocalValue", localVariable.getValue());
    Task task = taskService.createTaskQuery().executionId(execution.getId()).singleResult();
    taskService.complete(task.getId());
    tree = runtimeService.getActivityInstance(processInstance.getId());
    assertEquals(2, tree.getChildActivityInstances().length);
    ActivityInstance task3Instance = tree.getActivityInstances("task3")[0];
    query = runtimeService.createVariableInstanceQuery().variableName("aLocalVariable").activityInstanceIdIn(task3Instance.getId());
    localVariable = query.singleResult();
    assertNotNull(localVariable);
    assertEquals("aLocalVariable", localVariable.getName());
    assertEquals("aLocalValue", localVariable.getValue());
}
Also used : Task(org.camunda.bpm.engine.task.Task) Execution(org.camunda.bpm.engine.runtime.Execution) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) 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 33 with VariableInstanceQuery

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

the class VariableInstanceQueryTest method testQueryOrderByActivityInstanceId_Asc.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testQueryOrderByActivityInstanceId_Asc() {
    // given
    Map<String, Object> variables1 = new HashMap<String, Object>();
    variables1.put("intVar", 123);
    ProcessInstance procInst1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables1);
    String activityId1 = runtimeService.getActivityInstance(procInst1.getId()).getChildActivityInstances()[0].getId();
    Map<String, Object> variables2 = new HashMap<String, Object>();
    variables2.put("stringVar", "test");
    ProcessInstance procInst2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables2);
    String activityId2 = runtimeService.getActivityInstance(procInst2.getId()).getChildActivityInstances()[0].getId();
    int comparisonResult = activityId1.compareTo(activityId2);
    // when
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().orderByActivityInstanceId().asc();
    // then
    List<VariableInstance> result = query.list();
    assertFalse(result.isEmpty());
    assertEquals(2, result.size());
    VariableInstance first = result.get(0);
    VariableInstance second = result.get(1);
    if (comparisonResult < 0) {
        assertEquals("intVar", first.getName());
        assertEquals("integer", first.getTypeName());
        assertEquals("stringVar", second.getName());
        assertEquals("string", second.getTypeName());
    } else if (comparisonResult > 0) {
        assertEquals("stringVar", first.getName());
        assertEquals("string", first.getTypeName());
        assertEquals("intVar", second.getName());
        assertEquals("integer", second.getTypeName());
    } else {
        fail("Something went wrong: both activity instances have the same id " + activityId1 + " and " + activityId2);
    }
}
Also used : 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 34 with VariableInstanceQuery

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

the class VariableInstanceQueryTest method testQueryByNameAndVariableValueEquals_String.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testQueryByNameAndVariableValueEquals_String() {
    // given
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("stringVar", "test");
    runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);
    // when
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().variableValueEquals("stringVar", "test");
    // 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 35 with VariableInstanceQuery

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

the class VariableInstanceQueryTest method testQueryByNameAndVariableValueEquals_Bytes.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testQueryByNameAndVariableValueEquals_Bytes() {
    // given
    byte[] bytes = "somebytes".getBytes();
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("bytesVar", bytes);
    runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);
    // when
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().variableValueEquals("bytesVar", bytes);
    // then
    try {
        query.list();
        fail("A ProcessEngineException was expected: Variables of type ByteArray cannot be used to query.");
    } catch (ProcessEngineException e) {
    // expected exception
    }
}
Also used : HashMap(java.util.HashMap) VariableInstanceQuery(org.camunda.bpm.engine.runtime.VariableInstanceQuery) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

VariableInstanceQuery (org.camunda.bpm.engine.runtime.VariableInstanceQuery)347 Deployment (org.camunda.bpm.engine.test.Deployment)206 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)90 Test (org.junit.Test)79 HashMap (java.util.HashMap)72 Matchers.containsString (org.hamcrest.Matchers.containsString)28 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)20 Task (org.camunda.bpm.engine.task.Task)18 TaskServiceImpl (org.camunda.bpm.engine.impl.TaskServiceImpl)12 CaseInstance (org.camunda.bpm.engine.runtime.CaseInstance)10 RuntimeServiceImpl (org.camunda.bpm.engine.impl.RuntimeServiceImpl)8 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)7 RequiredHistoryLevel (org.camunda.bpm.engine.test.RequiredHistoryLevel)6 MySpecialTaskListener (org.camunda.bpm.engine.test.cmmn.tasklistener.util.MySpecialTaskListener)6 MyTaskListener (org.camunda.bpm.engine.test.cmmn.tasklistener.util.MyTaskListener)6 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)4 ArrayList (java.util.ArrayList)3 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)3