Search in sources :

Example 11 with VariableInstanceQuery

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

the class RuntimeServiceTest method testChangeTypeFromSerializableUsingApi.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/RuntimeServiceTest.testBasicVariableOperations.bpmn20.xml" })
@Test
public void testChangeTypeFromSerializableUsingApi() {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("aVariable", new SerializableVariable("foo"));
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("taskAssigneeProcess", variables);
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().variableName("aVariable");
    VariableInstance variable = query.singleResult();
    assertEquals(ValueType.OBJECT.getName(), variable.getTypeName());
    runtimeService.setVariable(pi.getId(), "aVariable", null);
    variable = query.singleResult();
    assertEquals(ValueType.NULL.getName(), variable.getTypeName());
}
Also used : SerializableVariable(org.camunda.bpm.engine.test.history.SerializableVariable) HashMap(java.util.HashMap) VariableInstanceQuery(org.camunda.bpm.engine.runtime.VariableInstanceQuery) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 12 with VariableInstanceQuery

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

the class RuntimeServiceTest method testChangeToSerializableUsingApi.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/RuntimeServiceTest.testBasicVariableOperations.bpmn20.xml" })
@Test
public void testChangeToSerializableUsingApi() {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("aVariable", "test");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("taskAssigneeProcess", variables);
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().variableName("aVariable");
    VariableInstance variable = query.singleResult();
    assertEquals(ValueType.STRING.getName(), variable.getTypeName());
    runtimeService.setVariable(processInstance.getId(), "aVariable", new SerializableVariable("foo"));
    variable = query.singleResult();
    assertEquals(ValueType.OBJECT.getName(), variable.getTypeName());
}
Also used : SerializableVariable(org.camunda.bpm.engine.test.history.SerializableVariable) HashMap(java.util.HashMap) VariableInstanceQuery(org.camunda.bpm.engine.runtime.VariableInstanceQuery) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 13 with VariableInstanceQuery

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

the class VariableInstanceQueryTest method testQueryOrderByType_Desc.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testQueryOrderByType_Desc() {
    // given
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("intVar", 123);
    variables.put("myVar", "test123");
    runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);
    // when
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().orderByVariableType().desc();
    // then
    List<VariableInstance> result = query.list();
    assertFalse(result.isEmpty());
    assertEquals(2, result.size());
    VariableInstance first = result.get(0);
    VariableInstance second = result.get(1);
    // string
    assertEquals("myVar", first.getName());
    assertEquals("string", first.getTypeName());
    // integer
    assertEquals("intVar", second.getName());
    assertEquals("integer", second.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 14 with VariableInstanceQuery

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

the class VariableInstanceQueryTest method testSimpleSubProcessVariables.

@Deployment
public void testSimpleSubProcessVariables() {
    // given
    Map<String, Object> processVariables = new HashMap<String, Object>();
    processVariables.put("processVariable", "aProcessVariable");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processWithSubProcess", processVariables);
    Task task = taskService.createTaskQuery().taskDefinitionKey("UserTask_1").singleResult();
    runtimeService.setVariableLocal(task.getExecutionId(), "aLocalVariable", "aLocalValue");
    ActivityInstance tree = runtimeService.getActivityInstance(processInstance.getId());
    assertEquals(1, tree.getChildActivityInstances().length);
    ActivityInstance subProcessInstance = tree.getActivityInstances("SubProcess_1")[0];
    // then the local variable has activity instance Id of the subprocess
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().activityInstanceIdIn(subProcessInstance.getId());
    VariableInstance localVariable = query.singleResult();
    assertNotNull(localVariable);
    assertEquals("aLocalVariable", localVariable.getName());
    assertEquals("aLocalValue", localVariable.getValue());
    // and the global variable has the activity instance Id of the process instance:
    query = runtimeService.createVariableInstanceQuery().activityInstanceIdIn(processInstance.getId());
    VariableInstance globalVariable = query.singleResult();
    assertNotNull(localVariable);
    assertEquals("processVariable", globalVariable.getName());
    assertEquals("aProcessVariable", globalVariable.getValue());
    taskService.complete(task.getId());
}
Also used : Task(org.camunda.bpm.engine.task.Task) 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) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 15 with VariableInstanceQuery

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

the class VariableInstanceQueryTest method testQueryByActivityInstanceId.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testQueryByActivityInstanceId() {
    // given
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("stringVar", "test");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);
    String activityId = runtimeService.getActivityInstance(processInstance.getId()).getChildActivityInstances()[0].getId();
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.setVariableLocal(task.getId(), "taskVariable", "aCustomValue");
    // when
    VariableInstanceQuery taskVariablesQuery = runtimeService.createVariableInstanceQuery().activityInstanceIdIn(activityId);
    VariableInstanceQuery processVariablesQuery = runtimeService.createVariableInstanceQuery().activityInstanceIdIn(processInstance.getId());
    // then
    VariableInstance taskVar = taskVariablesQuery.singleResult();
    assertNotNull(taskVar);
    assertEquals(1, taskVariablesQuery.count());
    assertEquals("string", taskVar.getTypeName());
    assertEquals("taskVariable", taskVar.getName());
    assertEquals("aCustomValue", taskVar.getValue());
    VariableInstance processVar = processVariablesQuery.singleResult();
    assertEquals(1, processVariablesQuery.count());
    assertEquals("string", processVar.getTypeName());
    assertEquals("stringVar", processVar.getName());
    assertEquals("test", processVar.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)

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