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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations