Search in sources :

Example 61 with VariableMap

use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.

the class CaseCallActivityTest method testOutputVariablesShouldNotExistAnymore.

@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/callactivity/CaseCallActivityTest.testOutputAll.bpmn20.xml", "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testOutputVariablesShouldNotExistAnymore() {
    // given
    String superProcessInstanceId = startProcessInstanceByKey(PROCESS_DEFINITION_KEY).getId();
    String callActivityId = queryExecutionByActivityId(CALL_ACTIVITY_ID).getId();
    VariableMap parameters = Variables.createVariables().putValue("aVariable", "xyz").putValue("anotherVariable", 123);
    runtimeService.setVariablesLocal(callActivityId, parameters);
    String subCaseInstanceId = queryOneTaskCaseInstance().getId();
    caseService.withCaseExecution(subCaseInstanceId).setVariable("aVariable", "abc").setVariable("anotherVariable", 999).execute();
    String humanTaskId = queryCaseExecutionByActivityId(HUMAN_TASK_ID).getId();
    // when
    complete(humanTaskId);
    // then
    // the variables has been deleted
    List<VariableInstance> variables = runtimeService.createVariableInstanceQuery().processInstanceIdIn(superProcessInstanceId).list();
    assertTrue(variables.isEmpty());
    // complete ////////////////////////////////////////////////////////
    close(subCaseInstanceId);
    assertCaseEnded(subCaseInstanceId);
    String taskId = queryTaskByActivityId(USER_TASK_ID).getId();
    taskService.complete(taskId);
    assertProcessEnded(superProcessInstanceId);
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 62 with VariableMap

use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.

the class ModifyVariableInSameTransactionTest method testInsertDeleteInsertTheSameVariable.

@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_AUDIT)
public void testInsertDeleteInsertTheSameVariable() {
    BpmnModelInstance bpmnModel = Bpmn.createExecutableProcess("serviceTaskProcess").startEvent().userTask("userTask").serviceTask("service").camundaClass(InsertDeleteInsertVariableDelegate.class).userTask("userTask1").endEvent().done();
    ProcessDefinition processDefinition = testHelper.deployAndGetDefinition(bpmnModel);
    VariableMap variables = Variables.createVariables().putValue("listVar", Arrays.asList(new int[] { 1, 2, 3 }));
    ProcessInstance instance = engineRule.getRuntimeService().startProcessInstanceById(processDefinition.getId(), variables);
    Task task = engineRule.getTaskService().createTaskQuery().singleResult();
    engineRule.getTaskService().complete(task.getId());
    VariableInstance variable = engineRule.getRuntimeService().createVariableInstanceQuery().processInstanceIdIn(instance.getId()).variableName("foo").singleResult();
    assertNotNull(variable);
    assertEquals("bar", variable.getValue());
    List<HistoricVariableInstance> historyVariables = engineRule.getHistoryService().createHistoricVariableInstanceQuery().list();
    for (HistoricVariableInstance historicVariable : historyVariables) {
        if (variable.getName().equals(historicVariable.getName())) {
            assertEquals(HistoricVariableInstance.STATE_CREATED, historicVariable.getState());
            break;
        }
    }
}
Also used : Task(org.camunda.bpm.engine.task.Task) VariableMap(org.camunda.bpm.engine.variable.VariableMap) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test) RequiredHistoryLevel(org.camunda.bpm.engine.test.RequiredHistoryLevel)

Example 63 with VariableMap

use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.

the class TargetVariableScopeTest method testExecutionWithoutProperTargetScope.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/variables/scope/TargetVariableScopeTest.testExecutionWithoutProperTargetScope.bpmn", "org/camunda/bpm/engine/test/api/variables/scope/doer.bpmn" })
public void testExecutionWithoutProperTargetScope() {
    VariableMap variables = Variables.createVariables().putValue("orderIds", Arrays.asList(new int[] { 1, 2, 3 }));
    // fails due to inappropriate variable scope target
    thrown.expect(ScriptEvaluationException.class);
    ProcessDefinition processDefinition = engineRule.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey("Process_MultiInstanceCallAcitivity").singleResult();
    thrown.expectMessage(startsWith("Unable to evaluate script while executing activity 'CallActivity_1' in the process definition with id '" + processDefinition.getId() + "': org.camunda.bpm.engine.ProcessEngineException: ENGINE-20011 Scope with specified activity Id NOT_EXISTING and execution"));
    engineRule.getRuntimeService().startProcessInstanceByKey("Process_MultiInstanceCallAcitivity", variables);
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 64 with VariableMap

use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.

the class TargetVariableScopeTest method testWithDelegateVariableMappingAndChildScope.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/variables/scope/doer.bpmn" })
public void testWithDelegateVariableMappingAndChildScope() {
    BpmnModelInstance instance = Bpmn.createExecutableProcess("process1").startEvent().parallelGateway().subProcess("SubProcess_1").embeddedSubProcess().startEvent().callActivity().calledElement("Process_StuffDoer").camundaVariableMappingClass("org.camunda.bpm.engine.test.api.variables.scope.SetVariableToChildMappingDelegate").serviceTask().camundaClass("org.camunda.bpm.engine.test.api.variables.scope.AssertVariableScopeDelegate").endEvent().subProcessDone().moveToLastGateway().subProcess("SubProcess_2").embeddedSubProcess().startEvent().userTask("ut").endEvent().subProcessDone().endEvent().done();
    instance = modify(instance).activityBuilder("SubProcess_1").multiInstance().parallel().camundaCollection("orderIds").camundaElementVariable("orderId").done();
    ProcessDefinition processDefinition = testHelper.deployAndGetDefinition(instance);
    thrown.expect(ProcessEngineException.class);
    thrown.expectMessage(startsWith("org.camunda.bpm.engine.ProcessEngineException: ENGINE-20011 Scope with specified activity Id SubProcess_2 and execution"));
    VariableMap variables = Variables.createVariables().putValue("orderIds", Arrays.asList(new int[] { 1, 2, 3 }));
    engineRule.getRuntimeService().startProcessInstanceById(processDefinition.getId(), variables);
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 65 with VariableMap

use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.

the class BoundaryErrorEventTest method testCatchExceptionThrownByExecuteOfDelegateExpression.

@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/event/error/BoundaryErrorEventTest.testCatchErrorThrownByDelegateExpression.bpmn20.xml" })
public void testCatchExceptionThrownByExecuteOfDelegateExpression() {
    VariableMap variables = Variables.createVariables().putValue("myDelegate", new ThrowErrorDelegate());
    variables.putAll(throwException());
    String pi = runtimeService.startProcessInstanceByKey("testProcess", variables).getId();
    assertTrue((Boolean) runtimeService.getVariable(pi, "executed"));
    assertNull(runtimeService.getVariable(pi, "signaled"));
    Task userTask = taskService.createTaskQuery().processInstanceId(pi).singleResult();
    assertNotNull(userTask);
    assertEquals("userTaskException", userTask.getTaskDefinitionKey());
    taskService.complete(userTask.getId());
}
Also used : Task(org.camunda.bpm.engine.task.Task) VariableMap(org.camunda.bpm.engine.variable.VariableMap) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

VariableMap (org.camunda.bpm.engine.variable.VariableMap)228 Deployment (org.camunda.bpm.engine.test.Deployment)107 Test (org.junit.Test)57 Task (org.camunda.bpm.engine.task.Task)38 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)32 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)30 VariableMapImpl (org.camunda.bpm.engine.variable.impl.VariableMapImpl)15 CaseExecutionEntity (org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity)13 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)13 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)12 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)12 HashMap (java.util.HashMap)11 ProcessInstanceWithVariables (org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables)9 LockedExternalTask (org.camunda.bpm.engine.externaltask.LockedExternalTask)8 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)8 RestException (org.camunda.bpm.engine.rest.exception.RestException)8 CaseExecutionQuery (org.camunda.bpm.engine.runtime.CaseExecutionQuery)8 Execution (org.camunda.bpm.engine.runtime.Execution)8 CaseExecution (org.camunda.bpm.engine.runtime.CaseExecution)7 ThrowErrorDelegate (org.camunda.bpm.engine.test.bpmn.event.error.ThrowErrorDelegate)7