use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.
the class ProcessInstantiationWithVariablesInReturnTest method testReturnVariablesFromStartAndExecution.
@Test
@Deployment(resources = SET_VARIABLE_IN_DELEGATE_PROCESS)
public void testReturnVariablesFromStartAndExecution() {
// given executed process which sets variables in java delegate
ProcessInstanceWithVariables procInstance = engineRule.getRuntimeService().createProcessInstanceByKey("variableProcess").setVariable("aVariable1", "aValue1").setVariableLocal("aVariable2", "aValue2").setVariables(Variables.createVariables().putValue("aVariable3", "aValue3")).setVariablesLocal(Variables.createVariables().putValue("aVariable4", new byte[] { 127, 34, 64 })).executeWithVariablesInReturn();
// when returned instance contains variables
VariableMap map = procInstance.getVariables();
assertNotNull(map);
// then variables equal to variables which are accessible via query
checkVariables(map, 12);
}
use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.
the class EventSubProcessStartConditionalEventTest method testNonInterruptingSetMultipleVariables.
@Test
public void testNonInterruptingSetMultipleVariables() {
BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY).startEvent().userTask(TASK_WITH_CONDITION_ID).name(TASK_WITH_CONDITION).endEvent().done();
deployConditionalEventSubProcess(modelInstance, CONDITIONAL_EVENT_PROCESS_KEY, false);
// given
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);
TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(processInstance.getId());
Task task = taskQuery.singleResult();
// when multiple variable are set on task execution
VariableMap variables = Variables.createVariables();
variables.put("variable", 1);
variables.put("variable1", 1);
runtimeService.setVariables(task.getExecutionId(), variables);
// then event sub process should be triggered more than once
tasksAfterVariableIsSet = taskQuery.list();
assertEquals(3, tasksAfterVariableIsSet.size());
}
use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.
the class CallActivityTest method testCallCaseByVersionAsDelegateExpression.
@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/callactivity/CallActivityAdvancedTest.testCallProcessByVersionAsDelegateExpression.bpmn20.xml", "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testCallCaseByVersionAsDelegateExpression() {
processEngineConfiguration.getBeans().put("myDelegate", new MyVersionDelegate());
// given
String bpmnResourceName = "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml";
String secondDeploymentId = repositoryService.createDeployment().addClasspathResource(bpmnResourceName).deploy().getId();
String thirdDeploymentId = repositoryService.createDeployment().addClasspathResource(bpmnResourceName).deploy().getId();
String processDefinitionIdInSecondDeployment = repositoryService.createProcessDefinitionQuery().processDefinitionKey("oneTaskProcess").deploymentId(secondDeploymentId).singleResult().getId();
VariableMap variables = Variables.createVariables().putValue("myVersion", 2);
// when
runtimeService.startProcessInstanceByKey("process", variables).getId();
// then
ProcessInstance subInstance = runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").singleResult();
assertNotNull(subInstance);
assertEquals(processDefinitionIdInSecondDeployment, subInstance.getProcessDefinitionId());
repositoryService.deleteDeployment(secondDeploymentId, true);
repositoryService.deleteDeployment(thirdDeploymentId, true);
}
use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.
the class CallActivityTest method testSubProcessWithNullDataOutputAsExpression.
@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/callactivity/CallActivity.testSubProcessDataInputOutputAsExpression.bpmn20.xml", "org/camunda/bpm/engine/test/bpmn/callactivity/dataSubProcess.bpmn20.xml" })
public void testSubProcessWithNullDataOutputAsExpression() {
Map<String, Object> params = new HashMap<String, Object>();
params.put("superVariable", null);
String processInstanceId = runtimeService.startProcessInstanceByKey("subProcessDataInputOutput", params).getId();
// the variable named "subVariable" is not set on process instance
VariableInstance variable = runtimeService.createVariableInstanceQuery().processInstanceIdIn(processInstanceId).variableName("subVariable").singleResult();
assertNull(variable);
variable = runtimeService.createVariableInstanceQuery().processInstanceIdIn(processInstanceId).variableName("superVariable").singleResult();
assertNotNull(variable);
assertNull(variable.getValue());
// the sub process instance is in the task
Task task = taskService.createTaskQuery().singleResult();
assertNotNull(task);
assertEquals("Task in subprocess", task.getName());
VariableMap variables = Variables.createVariables().putValue("myLocalVariable", null);
taskService.complete(task.getId(), variables);
variable = runtimeService.createVariableInstanceQuery().processInstanceIdIn(processInstanceId).variableName("subVariable").singleResult();
assertNull(variable);
variable = runtimeService.createVariableInstanceQuery().processInstanceIdIn(processInstanceId).variableName("superVariable").singleResult();
assertNotNull(variable);
assertNull(variable.getValue());
variable = runtimeService.createVariableInstanceQuery().processInstanceIdIn(processInstanceId).variableName("hisLocalVariable").singleResult();
assertNotNull(variable);
assertNull(variable.getValue());
}
use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.
the class CaseCallActivityTest method testVariablesRoundtrip.
@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/callactivity/CaseCallActivityTest.testVariablesRoundtrip.bpmn20.xml", "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testVariablesRoundtrip() {
// given
VariableMap parameters = Variables.createVariables().putValue("aVariable", "xyz").putValue("anotherVariable", 999);
String superProcessInstanceId = startProcessInstanceByKey(PROCESS_DEFINITION_KEY, parameters).getId();
String subCaseInstanceId = queryOneTaskCaseInstance().getId();
caseService.withCaseExecution(subCaseInstanceId).setVariable("aVariable", "abc").setVariable("anotherVariable", 1000).execute();
String humanTaskId = queryCaseExecutionByActivityId(HUMAN_TASK_ID).getId();
// when
complete(humanTaskId);
// then
List<VariableInstance> variables = runtimeService.createVariableInstanceQuery().processInstanceIdIn(superProcessInstanceId).list();
assertFalse(variables.isEmpty());
assertEquals(2, variables.size());
for (VariableInstance variable : variables) {
String name = variable.getName();
if ("aVariable".equals(name)) {
assertEquals("aVariable", name);
assertEquals("abc", variable.getValue());
} else if ("anotherVariable".equals(name)) {
assertEquals("anotherVariable", name);
assertEquals(1000, variable.getValue());
} else {
fail("Found an unexpected variable: '" + name + "'");
}
}
// complete ////////////////////////////////////////////////////////
close(subCaseInstanceId);
assertCaseEnded(subCaseInstanceId);
String taskId = queryTaskByActivityId(USER_TASK_ID).getId();
taskService.complete(taskId);
assertProcessEnded(superProcessInstanceId);
}
Aggregations