Java Code Examples for org.camunda.bpm.engine.variable.VariableMap

The following examples show how to use org.camunda.bpm.engine.variable.VariableMap. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public void testPropagateTenantIdToVariableInstanceOnStartProcessInstance() {

    deploymentForTenant(TENANT_ID, Bpmn.createExecutableProcess(PROCESS_DEFINITION_KEY)
        .startEvent()
        .userTask()
        .endEvent()
      .done());

    VariableMap variables = Variables.putValue("var", "test");

    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    runtimeService.startProcessInstanceById(processDefinition.getId(), variables);

    VariableInstance variableInstance = runtimeService.createVariableInstanceQuery().singleResult();
    assertThat(variableInstance, is(notNullValue()));
    // inherit the tenant id from process instance
    assertThat(variableInstance.getTenantId(), is(TENANT_ID));
  }
 
Example 2
private void checkVariables(VariableMap map, int expectedSize) {
  List<HistoricVariableInstance> variables = engineRule.getHistoryService()
          .createHistoricVariableInstanceQuery()
          .orderByVariableName()
          .asc()
          .list();

  assertEquals(expectedSize, variables.size());

  assertEquals(variables.size(), map.size());
  for (HistoricVariableInstance instance : variables) {
    assertTrue(map.containsKey(instance.getName()));
    Object instanceValue = instance.getTypedValue().getValue();
    Object mapValue = map.getValueTyped(instance.getName()).getValue();
    if (instanceValue == null) {
      assertNull(mapValue);
    } else if (instanceValue instanceof byte[]) {
      assertTrue(Arrays.equals((byte[]) instanceValue, (byte[]) mapValue));
    } else {
      assertEquals(instanceValue, mapValue);
    }
  }
}
 
Example 3
Source Project: camunda-bpm-platform   Source File: MultiInstanceTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment( resources = {
  "org/camunda/bpm/engine/test/bpmn/multiinstance/MultiInstanceTest.testCatchErrorThrownBySequentialDelegateExpression.bpmn20.xml"
})
public void testCatchExceptionThrownByExecuteOfSequentialDelegateExpression() {
  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());
}
 
Example 4
Source Project: camunda-bpm-platform   Source File: FeelEngineIT.java    License: Apache License 2.0 6 votes vote down vote up
protected VariableMap createSpinParsedVariableInMap(String serializationType) {
  if ("json".equalsIgnoreCase(serializationType)) {
    JsonListSerializable<String> jsonList = new JsonListSerializable<>();
    jsonList.setListProperty(TEST_LIST);
    return Variables.createVariables()
                    .putValue("inputVar", Spin.JSON(jsonList.toExpectedJsonString()));

  } else if ("xml".equalsIgnoreCase(serializationType)) {
    XmlListSerializable<String> xmlList = new XmlListSerializable<>();
    xmlList.setListProperty(TEST_LIST);
    return Variables.createVariables()
                    .putValue("inputVar", Spin.XML(xmlList.toExpectedXmlString()));

  } else {
    return Variables.createVariables();

  }
}
 
Example 5
@Test
public void testGetVariablesLocalTypedByName() {
  createTask(taskId);

  taskService.setVariablesLocal(taskId, getVariables());

  // when
  authRule
      .init(scenario)
      .withUser("userId")
      .bindResource("taskId", taskId)
      .start();

  VariableMap variables = taskService.getVariablesLocalTyped(taskId, Arrays.asList(VARIABLE_NAME), false);

  // then
  if (authRule.assertScenario(scenario)) {
    verifyGetVariables(variables);
  }
}
 
Example 6
Source Project: camunda-bpm-platform   Source File: PurgeDatabaseTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPurgeWithExistingProcessInstance() {
  //given process with variable and staying process instance in second user task
  BpmnModelInstance test = Bpmn.createExecutableProcess(PROCESS_DEF_KEY)
                               .startEvent()
                               .userTask()
                               .userTask()
                               .endEvent()
                               .done();
  engineRule.getRepositoryService().createDeployment().addModelInstance(PROCESS_MODEL_NAME, test).deploy();

  VariableMap variables = Variables.createVariables();
  variables.put("key", "value");
  engineRule.getRuntimeService().startProcessInstanceByKey(PROCESS_DEF_KEY, variables);
  Task task = engineRule.getTaskService().createTaskQuery().singleResult();
  engineRule.getTaskService().complete(task.getId());

  // when purge is executed
  ManagementServiceImpl managementService = (ManagementServiceImpl) engineRule.getManagementService();
  managementService.purge();

  // then no more data exist
  assertAndEnsureCleanDbAndCache(engineRule.getProcessEngine(), true);
}
 
Example 7
@Test
public void testGetVariablesTyped() {
  // given
  runtimeService.startProcessInstanceByKey(PROCESS_KEY, getVariables());
  String taskId = taskService.createTaskQuery().singleResult().getId();

  // when
  authRule
      .init(scenario)
      .withUser("userId")
      .bindResource("taskId", taskId)
      .start();

  VariableMap variables = taskService.getVariablesTyped(taskId);

  // then
  if (authRule.assertScenario(scenario)) {
    verifyGetVariables(variables);
  }
}
 
Example 8
Source Project: camunda-bpm-platform   Source File: JsonValueTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment(resources = ONE_TASK_PROCESS)
public void testGetTypedJsonValue() throws JSONException {
  // given
  JsonValue jsonValue = jsonValue(jsonString).create();
  VariableMap variables = Variables.createVariables().putValueTyped(variableName, jsonValue);

  String processInstanceId = runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS_KEY, variables).getId();

  // when
  JsonValue typedValue = runtimeService.getVariableTyped(processInstanceId, variableName);

  // then
  SpinJsonNode value = typedValue.getValue();
  JSONAssert.assertEquals(jsonString, value.toString(), true);

  assertTrue(typedValue.isDeserialized());
  assertEquals(JSON, typedValue.getType());
  assertEquals(JSON_FORMAT_NAME, typedValue.getSerializationDataFormat());
  JSONAssert.assertEquals(jsonString, typedValue.getValueSerialized(), true);
}
 
Example 9
Source Project: camunda-bpm-platform   Source File: HistoryServiceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = {"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"})
public void testQueryMultipleVariableValuesEquals() {
  // given
  String var1 = "var1";
  String var2 = "var2";

  String val1 = "val1";
  String val2 = "val2";
  String val3 = "val3";

  VariableMap variables = Variables.createVariables().putValue(var1, val1).putValue(var2, val1);
  String processInstance1 = runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS, variables).getId();

  variables = Variables.createVariables().putValue(var1, val2).putValue(var2, val2);
  runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS, variables).getId();

  variables = Variables.createVariables().putValue(var1, val3).putValue(var2, val3);
  runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS, variables).getId();

  // when
  List<HistoricProcessInstance> instances = historyService.createHistoricProcessInstanceQuery()
      .variableValueEquals(var1, val1)
      .variableValueEquals(var2, val1)
      .list();

  assertThat(instances).extracting("id").containsExactly(processInstance1);
}
 
Example 10
private void testVariablesWithoutDeserialization(String processDefinitionKey) throws Exception {
  //given serializable variable
  JavaSerializable javaSerializable = new JavaSerializable("foo");

  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  new ObjectOutputStream(baos).writeObject(javaSerializable);
  String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), engineRule.getProcessEngine());

  //when execute process with serialized variable and wait state
  ProcessInstanceWithVariables procInstance = engineRule.getRuntimeService()
          .createProcessInstanceByKey(processDefinitionKey)
          .setVariable("serializedVar", serializedObjectValue(serializedObject)
            .serializationDataFormat(Variables.SerializationDataFormats.JAVA)
            .objectTypeName(JavaSerializable.class.getName())
            .create())
          .executeWithVariablesInReturn(false, false);

  //then returned instance contains serialized variable
  VariableMap map = procInstance.getVariables();
  assertNotNull(map);

  ObjectValue serializedVar = (ObjectValue) map.getValueTyped("serializedVar");
  assertFalse(serializedVar.isDeserialized());
  assertObjectValueSerializedJava(serializedVar, javaSerializable);

  //access on value should fail because variable is not deserialized
  try {
    serializedVar.getValue();
    Assert.fail("Deserialization should fail!");
  } catch (IllegalStateException ise) {
    assertTrue(ise.getMessage().equals("Object is not deserialized."));
  }
}
 
Example 11
Source Project: camunda-bpm-platform   Source File: RuntimeServiceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
@Test
public void testGetVariableInstancesFromVariableScope() {

  VariableMap variables = createVariables()
    .putValue("anIntegerVariable", 1234)
    .putValue("anObjectValue", objectValue(new SimpleSerializableBean(10)).serializationDataFormat(Variables.SerializationDataFormats.JAVA))
    .putValue("anUntypedObjectValue", new SimpleSerializableBean(30));

  runtimeService.startProcessInstanceByKey("testProcess", variables);

  // assertions are part of the java delegate AssertVariableInstancesDelegate
  // only there we can access the VariableScope methods
}
 
Example 12
public void testGetVariablesLocalTypedByNameWithReadInstanceVariablePermissionOnAnyProcessDefinition() {
  // given
  setReadVariableAsDefaultReadVariablePermission();
  String processInstanceId = startProcessInstanceByKey(PROCESS_KEY, getVariables()).getId();
  createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, READ_INSTANCE_VARIABLE);

  // when
  VariableMap variables = runtimeService.getVariablesLocalTyped(processInstanceId, Arrays.asList(VARIABLE_NAME), false);

  // then
  verifyGetVariables(variables);
}
 
Example 13
public void testGetVariablesTypedByNameWithReadInstanceVariablePermissionOnAnyProcessDefinition() {
  // given
  setReadVariableAsDefaultReadVariablePermission();
  String processInstanceId = startProcessInstanceByKey(PROCESS_KEY, getVariables()).getId();
  createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, READ_INSTANCE_VARIABLE);

  // when
  VariableMap variables = runtimeService.getVariablesTyped(processInstanceId, Arrays.asList(VARIABLE_NAME), false);

  // then
  verifyGetVariables(variables);
}
 
Example 14
Source Project: camunda-engine-dmn   Source File: ExpressionLanguageTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@DecisionResource(resource = JUEL_EXPRESSIONS_WITH_PROPERTIES_DMN)
public void testJuelDoesNotShadowInnerProperty() {
  VariableMap inputs = Variables.createVariables();
  inputs.putValue("testExpr", "TestProperty");

  Map<String, Object> mapVar = new HashMap<>(1);
  mapVar.put("b", "B_FROM_MAP");
  inputs.putValue("a", mapVar);
  inputs.putValue("b", "B_FROM_CONTEXT");

  DmnDecisionResult result = dmnEngine.evaluateDecision(decision, inputs.asVariableContext());

  assertThat(result.getSingleEntry()).isEqualTo("B_FROM_MAP");
}
 
Example 15
Source Project: camunda-engine-dmn   Source File: ExpressionLanguageTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@DecisionResource(resource = JUEL_EXPRESSIONS_WITH_PROPERTIES_DMN)
public void testJuelResolvesListIndex() {
  VariableMap inputs = Variables.createVariables();
  inputs.putValue("testExpr", "TestListIndex");

  List<String> listVar = new ArrayList<>(1);
  listVar.add("0_FROM_LIST");
  inputs.putValue("a", listVar);

  DmnDecisionResult result = dmnEngine.evaluateDecision(decision, inputs.asVariableContext());

  assertThat(result.getSingleEntry()).isEqualTo("0_FROM_LIST");
}
 
Example 16
Source Project: camunda-bpm-platform   Source File: CallActivityTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test case for handing over process variables to a sub process via the typed
 * api and passing all variables
 */
@Deployment(resources = {
  "org/camunda/bpm/engine/test/bpmn/callactivity/CallActivity.testSubProcessAllDataInputOutputTypedApi.bpmn20.xml",
  "org/camunda/bpm/engine/test/bpmn/callactivity/simpleSubProcess.bpmn20.xml"})
public void testSubProcessWithAllDataInputOutputTypedApi() {

  TypedValue superVariable = Variables.stringValue(null);
  VariableMap vars = Variables.createVariables();
  vars.putValueTyped("superVariable", superVariable);

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("subProcessDataInputOutput", vars);

  // one task in the subprocess should be active after starting the process instance
  TaskQuery taskQuery = taskService.createTaskQuery();
  Task taskInSubProcess = taskQuery.singleResult();
  assertThat(taskInSubProcess.getName(), is("Task in subprocess"));
  assertThat(runtimeService.getVariableTyped(taskInSubProcess.getProcessInstanceId(), "superVariable"), is(superVariable));
  assertThat(taskService.getVariableTyped(taskInSubProcess.getId(), "superVariable"), is(superVariable));

  TypedValue subVariable = Variables.stringValue(null);
  runtimeService.setVariable(taskInSubProcess.getProcessInstanceId(), "subVariable", subVariable);

  // Completing this task ends the subprocess which leads to a task in the super process
  taskService.complete(taskInSubProcess.getId());

  Task taskAfterSubProcess = taskQuery.singleResult();
  assertThat(taskAfterSubProcess.getName(), is("Task in super process"));
  assertThat(runtimeService.getVariableTyped(processInstance.getId(), "subVariable"), is(subVariable));
  assertThat(taskService.getVariableTyped(taskAfterSubProcess.getId(), "superVariable"), is(superVariable));

  // Completing this task ends the super process which leads to a task in the super process
  taskService.complete(taskAfterSubProcess.getId());

  assertProcessEnded(processInstance.getId());
  assertEquals(0, runtimeService.createExecutionQuery().list().size());
}
 
Example 17
public void testGetVariablesTypedByNameWithReadInstancePermissionOnAnyProcessDefinition() {
  // given
  String processInstanceId = startProcessInstanceByKey(PROCESS_KEY, getVariables()).getId();
  createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, READ_INSTANCE);

  // when
  VariableMap variables = runtimeService.getVariablesTyped(processInstanceId, Arrays.asList(VARIABLE_NAME), false);

  // then
  assertNotNull(variables);
  assertFalse(variables.isEmpty());
  assertEquals(1, variables.size());

  assertEquals(VARIABLE_VALUE, variables.get(VARIABLE_NAME));
}
 
Example 18
protected CaseInstance createCaseInstanceByKey(String caseDefinitionKey, String businessKey, VariableMap variables) {
  return caseService
    .withCaseDefinitionByKey(caseDefinitionKey)
    .businessKey(businessKey)
    .setVariables(variables)
    .create();
}
 
Example 19
@Override
public void onExecutionSetVariables(final VariableMap variables) {
  doAnswer(new JavaDelegate() {

    @Override
    public void execute(final DelegateExecution execution) throws Exception {
      setVariables(execution, variables);
    }
  });
}
 
Example 20
@Override
public void onExecutionSetVariables(final VariableMap variables) {
  doAnswer(new ExecutionListener() {

    @Override
    public void notify(final DelegateExecution execution) throws Exception {
      setVariables(execution, variables);
    }
  });
}
 
Example 21
@Deployment(resources = { DECISION_SINGLE_OUTPUT_DMN })
public void testDecisionEvaluatedWithAuthenticatedUser() {
  identityService.setAuthenticatedUserId("demo");
  VariableMap variables = Variables.putValue("input1", "test");
  decisionService.evaluateDecisionTableByKey(DECISION_DEFINITION_KEY, variables);

  HistoricDecisionInstance historicDecisionInstance = historyService.createHistoricDecisionInstanceQuery().singleResult();

  assertThat(historicDecisionInstance, is(notNullValue()));
  // the user should be set since the decision was evaluated with the decision service
  assertThat(historicDecisionInstance.getUserId(), is("demo"));
}
 
Example 22
protected void performStart(CmmnActivityExecution execution) {
  VariableMap variables = getInputVariables(execution);
  String businessKey = getBusinessKey(execution);
  triggerCallableElement(execution, variables, businessKey);

  if (execution.isActive() && !isBlocking(execution)) {
    execution.complete();
  }
}
 
Example 23
public void testGetVariablesTypedByNameWithReadInstancePermissionOnProcessDefinition() {
  // given
  String processInstanceId = startProcessInstanceByKey(PROCESS_KEY, getVariables()).getId();
  createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, READ_INSTANCE);

  // when
  VariableMap variables = runtimeService.getVariablesTyped(processInstanceId, Arrays.asList(VARIABLE_NAME), false);

  // then
  assertNotNull(variables);
  assertFalse(variables.isEmpty());
  assertEquals(1, variables.size());

  assertEquals(VARIABLE_VALUE, variables.get(VARIABLE_NAME));
}
 
Example 24
@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;
    }
  }
}
 
Example 25
Source Project: camunda-bpm-platform   Source File: XmlValueTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment(resources = ONE_TASK_PROCESS)
public void testTransientXmlValue() {
  // given
  XmlValue xmlValue = xmlValue(xmlString, true).create();
  VariableMap variables = Variables.createVariables().putValueTyped(variableName, xmlValue);

  // when
  runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS_KEY, variables).getId();

  // then
  List<VariableInstance> variableInstances = runtimeService.createVariableInstanceQuery().list();
  assertEquals(0, variableInstances.size());
}
 
Example 26
public void testGetStartFormVariables() {
  // given
  String processDefinitionId = selectProcessDefinitionByKey(RENDERED_FORM_PROCESS_KEY).getId();
  createGrantAuthorization(PROCESS_DEFINITION, RENDERED_FORM_PROCESS_KEY, userId, READ);

  // when
  VariableMap variables = formService.getStartFormVariables(processDefinitionId);

  // then
  assertNotNull(variables);
  assertEquals(1, variables.size());
}
 
Example 27
@Test
public void testSubmitFormWithVariablesInReturn() {
  VariableMap variables = MockProvider.createMockSerializedVariables();
  when(formServiceMock.submitTaskFormWithVariablesInReturn(EXAMPLE_TASK_ID, null, false)).thenReturn(variables);

  Map<String, Object> queryParameters = new HashMap<>();
  queryParameters.put("withVariablesInReturn", true);

  given()
    .pathParam("id", EXAMPLE_TASK_ID)
    .contentType(POST_JSON_CONTENT_TYPE)
    .body(queryParameters)
    .header("accept", MediaType.APPLICATION_JSON)
  .expect()
    .statusCode(Status.OK.getStatusCode())
    //serialized variable
    .body(MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME + ".value",
            equalTo(MockProvider.EXAMPLE_VARIABLE_INSTANCE_SERIALIZED_VALUE))
    .body(MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME + ".type",
            equalTo("Object"))
    .body(MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME + ".valueInfo.objectTypeName",
            equalTo(ArrayList.class.getName()))
    .body(MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME + ".valueInfo.serializationDataFormat",
            equalTo(MockProvider.FORMAT_APPLICATION_JSON))
    // deserialized variable should also returned as serialized variable
    .body(MockProvider.EXAMPLE_DESERIALIZED_VARIABLE_INSTANCE_NAME + ".value",
            equalTo(MockProvider.EXAMPLE_VARIABLE_INSTANCE_SERIALIZED_VALUE))
    .body(MockProvider.EXAMPLE_DESERIALIZED_VARIABLE_INSTANCE_NAME + ".type",
            equalTo("Object"))
    .body(MockProvider.EXAMPLE_DESERIALIZED_VARIABLE_INSTANCE_NAME + ".valueInfo.objectTypeName",
            equalTo(Object.class.getName()))
    .body(MockProvider.EXAMPLE_DESERIALIZED_VARIABLE_INSTANCE_NAME + ".valueInfo.serializationDataFormat",
            equalTo(MockProvider.FORMAT_APPLICATION_JSON))
  .when().post(SUBMIT_FORM_URL);

  verify(formServiceMock).submitTaskFormWithVariablesInReturn(EXAMPLE_TASK_ID, null, false);
}
 
Example 28
Source Project: camunda-bpm-platform   Source File: BusinessProcess.java    License: Apache License 2.0 5 votes vote down vote up
public ProcessInstance startProcessByKey(String key, Map<String, Object> variables) {
  assertCommandContextNotActive();

  VariableMap cachedVariables = getAndClearCachedVariableMap();
  cachedVariables.putAll(variables);
  ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceByKey(key, cachedVariables);
  if (!instance.isEnded()) {
    setExecution(instance);
  }
  return instance;
}
 
Example 29
public void testProcessTaskGetTaskFormVariablesWithReadVariablePermissionOnTask() {
  // given
  setReadVariableAsDefaultReadVariablePermission();
  startProcessInstanceByKey(RENDERED_FORM_PROCESS_KEY);
  String taskId = selectSingleTask().getId();
  createGrantAuthorization(TASK, taskId, userId, READ_VARIABLE);

  // when
  VariableMap variables = formService.getTaskFormVariables(taskId);

  // then
  assertNotNull(variables);
  assertEquals(1, variables.size());
}
 
Example 30
@Deployment(resources = { "org/camunda/bpm/engine/test/api/externaltask/ExternalTaskVariablesTest.testExternalTaskVariablesLocal.bpmn20.xml" })
public void testFetchOnlyLocalVariables() {

  VariableMap globalVars = Variables.putValue("globalVar", "globalVal");

  runtimeService.startProcessInstanceByKey("oneExternalTaskProcess", globalVars);

  final String workerId = "workerId";
  final String topicName = "testTopic";

  List<LockedExternalTask> lockedExternalTasks = externalTaskService.fetchAndLock(10, workerId)
    .topic(topicName, 60000)
    .execute();

  assertEquals(1, lockedExternalTasks.size());

  LockedExternalTask lockedExternalTask = lockedExternalTasks.get(0);
  VariableMap variables = lockedExternalTask.getVariables();
  assertEquals(2, variables.size());
  assertEquals("globalVal", variables.getValue("globalVar", String.class));
  assertEquals("localVal", variables.getValue("localVar", String.class));

  externalTaskService.unlock(lockedExternalTask.getId());

  lockedExternalTasks = externalTaskService.fetchAndLock(10, workerId)
    .topic(topicName, 60000)
    .variables("globalVar", "localVar")
    .localVariables()
    .execute();

  assertEquals(1, lockedExternalTasks.size());

  lockedExternalTask = lockedExternalTasks.get(0);
  variables = lockedExternalTask.getVariables();
  assertEquals(1, variables.size());
  assertEquals("localVal", variables.getValue("localVar", String.class));
}