use of org.camunda.bpm.engine.runtime.VariableInstance in project camunda-bpm-platform by camunda.
the class MigrationSignalCatchEventTest method testMigrateEventSubscriptionUpdateSignalExpressionNameWithVariables.
@Test
public void testMigrateEventSubscriptionUpdateSignalExpressionNameWithVariables() {
// given
String newSignalName = "new" + SignalCatchModels.SIGNAL_NAME + "-${var}";
ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(SignalCatchModels.ONE_SIGNAL_CATCH_PROCESS);
ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.newModel().startEvent().intermediateCatchEvent("signalCatch").signal(newSignalName).userTask("userTask").endEvent().done());
MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("signalCatch", "signalCatch").updateEventTrigger().build();
HashMap<String, Object> variables = new HashMap<String, Object>();
variables.put("var", "foo");
// when
ProcessInstance processInstance = testHelper.createProcessInstanceAndMigrate(migrationPlan, variables);
// then there should be a variable
VariableInstance beforeMigration = testHelper.snapshotBeforeMigration.getSingleVariable("var");
Assert.assertEquals(1, testHelper.snapshotAfterMigration.getVariables().size());
testHelper.assertVariableMigratedToExecution(beforeMigration, beforeMigration.getExecutionId());
// and the signal event subscription's event name has changed
String resolvedSignalName = "new" + SignalCatchModels.SIGNAL_NAME + "-foo";
testHelper.assertEventSubscriptionMigrated("signalCatch", SignalCatchModels.SIGNAL_NAME, "signalCatch", resolvedSignalName);
// and it is possible to trigger the event and complete the task afterwards
rule.getRuntimeService().signalEventReceived(resolvedSignalName);
testHelper.completeTask("userTask");
testHelper.assertProcessEnded(processInstance.getId());
}
use of org.camunda.bpm.engine.runtime.VariableInstance in project camunda-bpm-platform by camunda.
the class VariableInstanceQueryForOracleTest method testQueryWhen1000InstancesActive.
@Test
public void testQueryWhen1000InstancesActive() {
// given
Assume.assumeTrue(engineRule.getProcessEngineConfiguration().getDatabaseType().equals("oracle"));
RuntimeService runtimeService = engineRule.getRuntimeService();
testRule.deploy(ProcessModels.TWO_TASKS_PROCESS);
String[] ids = new String[1000];
// when
for (int i = 0; i < 1000; i++) {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process", Variables.createVariables().putValue("foo", "bar"));
String activityInstanceId = runtimeService.getActivityInstance(processInstance.getId()).getId();
ids[i] = activityInstanceId;
}
// then
List<VariableInstance> variables = engineRule.getRuntimeService().createVariableInstanceQuery().activityInstanceIdIn(ids).list();
assertEquals(1000, variables.size());
}
use of org.camunda.bpm.engine.runtime.VariableInstance 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.VariableInstance 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.VariableInstance 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