Search in sources :

Example 36 with VariableInstanceQuery

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

the class VariableInstanceQueryTest method testQueryByNameAndVariableLessThanAndEqual_Short.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testQueryByNameAndVariableLessThanAndEqual_Short() {
    // given
    Map<String, Object> variables1 = new HashMap<String, Object>();
    variables1.put("shortValue", (short) 123);
    runtimeService.startProcessInstanceByKey("oneTaskProcess", variables1);
    Map<String, Object> variables2 = new HashMap<String, Object>();
    variables2.put("shortValue", (short) 999);
    runtimeService.startProcessInstanceByKey("oneTaskProcess", variables2);
    Map<String, Object> variables3 = new HashMap<String, Object>();
    variables3.put("shortValue", (short) 555);
    runtimeService.startProcessInstanceByKey("oneTaskProcess", variables3);
    // when
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().variableValueLessThanOrEqual("shortValue", (short) 999);
    // then
    List<VariableInstance> result = query.list();
    assertFalse(result.isEmpty());
    assertEquals(3, result.size());
    assertEquals(3, query.count());
    for (VariableInstance var : result) {
        assertEquals("shortValue", var.getName());
        assertEquals("short", var.getTypeName());
        if (var.getValue().equals((short) 123)) {
            assertEquals((short) 123, var.getValue());
        } else if (var.getValue().equals((short) 555)) {
            assertEquals((short) 555, var.getValue());
        } else if (var.getValue().equals((short) 999)) {
            assertEquals((short) 999, 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 37 with VariableInstanceQuery

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

the class VariableInstanceQueryTest method testQueryByNameAndVariableGreaterThanAndEqual_Double.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testQueryByNameAndVariableGreaterThanAndEqual_Double() {
    // given
    Map<String, Object> variables1 = new HashMap<String, Object>();
    variables1.put("doubleValue", 123.456);
    runtimeService.startProcessInstanceByKey("oneTaskProcess", variables1);
    Map<String, Object> variables2 = new HashMap<String, Object>();
    variables2.put("doubleValue", 654.321);
    runtimeService.startProcessInstanceByKey("oneTaskProcess", variables2);
    Map<String, Object> variables3 = new HashMap<String, Object>();
    variables3.put("doubleValue", 999.999);
    runtimeService.startProcessInstanceByKey("oneTaskProcess", variables3);
    // when
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().variableValueGreaterThanOrEqual("doubleValue", 123.456);
    // then
    List<VariableInstance> result = query.list();
    assertFalse(result.isEmpty());
    assertEquals(3, result.size());
    assertEquals(3, query.count());
    for (VariableInstance var : result) {
        assertEquals("doubleValue", var.getName());
        assertEquals("double", var.getTypeName());
        if (var.getValue().equals(123.456)) {
            assertEquals(123.456, var.getValue());
        } else if (var.getValue().equals(654.321)) {
            assertEquals(654.321, var.getValue());
        } else if (var.getValue().equals(999.999)) {
            assertEquals(999.999, 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 38 with VariableInstanceQuery

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

the class VariableInstanceQueryTest method testQueryByTaskId.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testQueryByTaskId() {
    // given
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("stringVar", "test");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.setVariableLocal(task.getId(), "taskVariable", "aCustomValue");
    // when
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().taskIdIn(task.getId());
    // then
    List<VariableInstance> result = query.list();
    assertFalse(result.isEmpty());
    assertEquals(1, result.size());
    assertEquals(1, query.count());
    VariableInstance var = result.get(0);
    assertEquals("taskVariable", var.getName());
    assertEquals("aCustomValue", var.getValue());
    assertEquals("string", var.getTypeName());
}
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 39 with VariableInstanceQuery

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

the class VariableInstanceQueryTest method testQueryByExecutionIds.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testQueryByExecutionIds() {
    // given
    Map<String, Object> variables1 = new HashMap<String, Object>();
    variables1.put("stringVar", "test");
    variables1.put("myVar", "test123");
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables1);
    Map<String, Object> variables2 = new HashMap<String, Object>();
    variables2.put("myVar", "test123");
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables2);
    // when
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().executionIdIn(processInstance1.getId(), processInstance2.getId());
    // then
    List<VariableInstance> result = query.list();
    assertFalse(result.isEmpty());
    assertEquals(3, result.size());
    assertEquals(3, query.count());
    for (VariableInstance var : result) {
        assertEquals("string", var.getTypeName());
        if (var.getName().equals("myVar")) {
            assertEquals("myVar", var.getName());
            assertEquals("test123", var.getValue());
        } else if (var.getName().equals("stringVar")) {
            assertEquals("stringVar", var.getName());
            assertEquals("test", var.getValue());
        } else {
            fail("An unexpected variable '" + var.getName() + "' was found with value " + var.getValue());
        }
    }
}
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 40 with VariableInstanceQuery

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

the class VariableInstanceQueryTest method testQueryByVariableId.

@Test
public void testQueryByVariableId() {
    // given
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("var1", "test");
    variables.put("var2", "test");
    Task task = taskService.newTask();
    taskService.saveTask(task);
    taskService.setVariablesLocal(task.getId(), variables);
    VariableInstance result = runtimeService.createVariableInstanceQuery().variableName("var1").singleResult();
    assertNotNull(result);
    // when
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().variableId(result.getId());
    // then
    assertNotNull(query);
    VariableInstance resultById = query.singleResult();
    assertEquals(result.getId(), resultById.getId());
    // delete task
    taskService.deleteTask(task.getId(), true);
}
Also used : Task(org.camunda.bpm.engine.task.Task) HashMap(java.util.HashMap) VariableInstanceQuery(org.camunda.bpm.engine.runtime.VariableInstanceQuery) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test)

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