Java Code Examples for org.camunda.bpm.engine.variable.Variables#createVariables()

The following examples show how to use org.camunda.bpm.engine.variable.Variables#createVariables() . 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
Source File: EventSubProcessStartConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources ={ "org/camunda/bpm/engine/test/bpmn/event/conditional/EventSubProcessStartConditionalEventTest.testVariableCondition.bpmn20.xml"})
public void testVariableConditionAndStartingWithVar() {
  //given process with event sub process conditional start event
  Map<String, Object> vars = Variables.createVariables();
  vars.put(VARIABLE_NAME, 1);

  //when starting process with variable
  ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY, vars);

  //then event sub process is triggered via default evaluation behavior
  TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(TASK_AFTER_CONDITION, tasksAfterVariableIsSet.get(0).getName());
  assertEquals(0, conditionEventSubscriptionQuery.list().size());
}
 
Example 2
Source File: EventSubProcessStartConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 3
Source File: ExpressionLanguageTest.java    From camunda-engine-dmn with 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 4
Source File: PrimitiveVariableIT.java    From camunda-external-task-client-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shoudSetVariableUntyped_String() {
  // given
  engineRule.startProcessInstance(processDefinition.getId());

  client.subscribe(EXTERNAL_TASK_TOPIC_FOO)
    .handler(invocationHandler)
    .open();

  clientRule.waitForFetchAndLockUntil(() -> !invocationHandler.getInvocations().isEmpty());

  RecordedInvocation invocation = invocationHandler.getInvocations().get(0);
  ExternalTask fooTask = invocation.getExternalTask();
  ExternalTaskService fooService = invocation.getExternalTaskService();

  client.subscribe(EXTERNAL_TASK_TOPIC_BAR)
    .handler(handler)
    .open();

  // when
  Map<String, Object> variables = Variables.createVariables();
  variables.put(VARIABLE_NAME, Variables.untypedValue(VARIABLE_VALUE_STRING));
  fooService.complete(fooTask, variables);

  // then
  clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

  ExternalTask task = handler.getHandledTasks().get(0);

  String variableValue = task.getVariable(VARIABLE_NAME);
  assertThat(variableValue).isEqualTo(VARIABLE_VALUE_STRING);

  TypedValue typedValue = task.getVariableTyped(VARIABLE_NAME);
  assertThat(typedValue.getValue()).isEqualTo(VARIABLE_VALUE_STRING);
  assertThat(typedValue.getType()).isEqualTo(STRING);
}
 
Example 5
Source File: PrimitiveVariableIT.java    From camunda-external-task-client-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shoudSetVariable_Boolean() {
  // given
  engineRule.startProcessInstance(processDefinition.getId());

  client.subscribe(EXTERNAL_TASK_TOPIC_FOO)
    .handler(invocationHandler)
    .open();

  clientRule.waitForFetchAndLockUntil(() -> !invocationHandler.getInvocations().isEmpty());

  RecordedInvocation invocation = invocationHandler.getInvocations().get(0);
  ExternalTask fooTask = invocation.getExternalTask();
  ExternalTaskService fooService = invocation.getExternalTaskService();

  client.subscribe(EXTERNAL_TASK_TOPIC_BAR)
    .handler(handler)
    .open();

  // when
  Map<String, Object> variables = Variables.createVariables();
  variables.put(VARIABLE_NAME, VARIABLE_VALUE_BOOLEAN);
  fooService.complete(fooTask, variables);

  // then
  clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

  ExternalTask task = handler.getHandledTasks().get(0);

  boolean variableValue = task.getVariable(VARIABLE_NAME);
  assertThat(variableValue).isEqualTo(VARIABLE_VALUE_BOOLEAN);

  TypedValue typedValue = task.getVariableTyped(VARIABLE_NAME);
  assertThat(typedValue.getValue()).isEqualTo(VARIABLE_VALUE_BOOLEAN);
  assertThat(typedValue.getType()).isEqualTo(BOOLEAN);
}
 
Example 6
Source File: FeelEngineCustomFunctionTest.java    From camunda-engine-dmn with Apache License 2.0 5 votes vote down vote up
@Before
public void initEngine() {
  variables = Variables.createVariables();

  List<FeelToJuelFunctionTransformer> customFunctionTransformers = new ArrayList<FeelToJuelFunctionTransformer>();
  customFunctionTransformers.add(new StartsWithFunctionTransformer());

  FeelEngineFactoryImpl feelEngineFactory = new FeelEngineFactoryImpl(customFunctionTransformers);

  feelEngine = feelEngineFactory.createInstance();
}
 
Example 7
Source File: PrimitiveVariableIT.java    From camunda-external-task-client-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shoudSetVariableTyped_String() {
  // given
  engineRule.startProcessInstance(processDefinition.getId());

  client.subscribe(EXTERNAL_TASK_TOPIC_FOO)
    .handler(invocationHandler)
    .open();

  clientRule.waitForFetchAndLockUntil(() -> !invocationHandler.getInvocations().isEmpty());

  RecordedInvocation invocation = invocationHandler.getInvocations().get(0);
  ExternalTask fooTask = invocation.getExternalTask();
  ExternalTaskService fooService = invocation.getExternalTaskService();

  client.subscribe(EXTERNAL_TASK_TOPIC_BAR)
    .handler(handler)
    .open();

  // when
  Map<String, Object> variables = Variables.createVariables();
  variables.put(VARIABLE_NAME, Variables.stringValue(VARIABLE_VALUE_STRING));
  fooService.complete(fooTask, variables);

  // then
  clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

  ExternalTask task = handler.getHandledTasks().get(0);

  String variableValue = task.getVariable(VARIABLE_NAME);
  assertThat(variableValue).isEqualTo(VARIABLE_VALUE_STRING);

  TypedValue typedValue = task.getVariableTyped(VARIABLE_NAME);
  assertThat(typedValue.getValue()).isEqualTo(VARIABLE_VALUE_STRING);
  assertThat(typedValue.getType()).isEqualTo(STRING);
}
 
Example 8
Source File: GetHistoricDecisionInstancesForOptimizeTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = {DECISION_PROCESS, DECISION_SINGLE_OUTPUT_DMN})
public void decisionOutputInstanceProperties() {
  // given start process and evaluate decision
  VariableMap variables = Variables.createVariables();
  variables.put("input1", null);
  runtimeService.startProcessInstanceByKey("testProcess", variables);

  // when
  List<HistoricDecisionInstance> decisionInstances =
    optimizeService.getHistoricDecisionInstances(pastDate(), null, 10);

  // then
  assertThat(decisionInstances.size(), is(1));
  HistoricDecisionInstance decisionInstance = decisionInstances.get(0);
  List<HistoricDecisionOutputInstance> outputs = decisionInstance.getOutputs();
  assertThat(outputs, is(notNullValue()));
  assertThat(outputs.size(), is(1));

  HistoricDecisionOutputInstance output = outputs.get(0);
  assertThat(output.getDecisionInstanceId(), is(decisionInstance.getId()));
  assertThat(output.getClauseId(), is("out"));
  assertThat(output.getClauseName(), is("output"));

  assertThat(output.getRuleId(), is("rule"));
  assertThat(output.getRuleOrder(), is(1));

  assertThat(output.getVariableName(), is("result"));
}
 
Example 9
Source File: DecisionDefinitionResourceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected Map<String, VariableValueDto> createResultEntriesDto(DmnDecisionResultEntries entries) {
  VariableMap variableMap = Variables.createVariables();

  for(String key : entries.keySet()) {
    TypedValue typedValue = entries.getEntryTyped(key);
    variableMap.putValueTyped(key, typedValue);
  }

  return VariableValueDto.fromMap(variableMap);
}
 
Example 10
Source File: ExpressionLanguageTest.java    From camunda-engine-dmn with 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 11
Source File: CallActivityTest.java    From camunda-bpm-platform with 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 only certain variables
 */
@Deployment(resources = {
  "org/camunda/bpm/engine/test/bpmn/callactivity/CallActivity.testSubProcessLimitedDataInputOutputTypedApi.bpmn20.xml",
  "org/camunda/bpm/engine/test/bpmn/callactivity/simpleSubProcess.bpmn20.xml"})
public void testSubProcessWithLimitedDataInputOutputTypedApi() {

  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(), "subVariable"), is(superVariable));
  assertThat(taskService.getVariableTyped(taskInSubProcess.getId(), "subVariable"), is(superVariable));

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

  // super variable is unchanged
  assertThat(runtimeService.getVariableTyped(processInstance.getId(), "superVariable"), is(superVariable));

  // 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(), "superVariable"), is(subVariable));
  assertThat(taskService.getVariableTyped(taskAfterSubProcess.getId(), "superVariable"), is(subVariable));

  // 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 12
Source File: PrimitiveVariableIT.java    From camunda-external-task-client-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shoudSetVariableUntyped_Integer() {
  // given
  engineRule.startProcessInstance(processDefinition.getId());

  client.subscribe(EXTERNAL_TASK_TOPIC_FOO)
    .handler(invocationHandler)
    .open();

  clientRule.waitForFetchAndLockUntil(() -> !invocationHandler.getInvocations().isEmpty());

  RecordedInvocation invocation = invocationHandler.getInvocations().get(0);
  ExternalTask fooTask = invocation.getExternalTask();
  ExternalTaskService fooService = invocation.getExternalTaskService();

  client.subscribe(EXTERNAL_TASK_TOPIC_BAR)
    .handler(handler)
    .open();

  // when
  Map<String, Object> variables = Variables.createVariables();
  variables.put(VARIABLE_NAME, Variables.untypedValue(VARIABLE_VALUE_INT));
  fooService.complete(fooTask, variables);

  // then
  clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

  ExternalTask task = handler.getHandledTasks().get(0);

  int variableValue = task.getVariable(VARIABLE_NAME);
  assertThat(variableValue).isEqualTo(VARIABLE_VALUE_INT);

  TypedValue typedValue = task.getVariableTyped(VARIABLE_NAME);
  assertThat(typedValue.getValue()).isEqualTo(VARIABLE_VALUE_INT);
  assertThat(typedValue.getType()).isEqualTo(INTEGER);
}
 
Example 13
Source File: PrimitiveVariableIT.java    From camunda-external-task-client-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shoudSetVariableTyped_Integer() {
  // given
  engineRule.startProcessInstance(processDefinition.getId());

  client.subscribe(EXTERNAL_TASK_TOPIC_FOO)
    .handler(invocationHandler)
    .open();

  clientRule.waitForFetchAndLockUntil(() -> !invocationHandler.getInvocations().isEmpty());

  RecordedInvocation invocation = invocationHandler.getInvocations().get(0);
  ExternalTask fooTask = invocation.getExternalTask();
  ExternalTaskService fooService = invocation.getExternalTaskService();

  client.subscribe(EXTERNAL_TASK_TOPIC_BAR)
    .handler(handler)
    .open();

  // when
  Map<String, Object> variables = Variables.createVariables();
  variables.put(VARIABLE_NAME, Variables.integerValue(VARIABLE_VALUE_INT));
  fooService.complete(fooTask, variables);

  // then
  clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

  ExternalTask task = handler.getHandledTasks().get(0);

  int variableValue = task.getVariable(VARIABLE_NAME);
  assertThat(variableValue).isEqualTo(VARIABLE_VALUE_INT);

  TypedValue typedValue = task.getVariableTyped(VARIABLE_NAME);
  assertThat(typedValue.getValue()).isEqualTo(VARIABLE_VALUE_INT);
  assertThat(typedValue.getType()).isEqualTo(INTEGER);
}
 
Example 14
Source File: DefaultDmnDecisionContext.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected VariableMap buildVariableMapFromVariableContext(VariableContext variableContext) {

    VariableMap variableMap = Variables.createVariables();

    Set<String> variables = variableContext.keySet();
    for(String variable: variables) {
      variableMap.put(variable, variableContext.resolve(variable));
    }

    return variableMap;
  }
 
Example 15
Source File: PrimitiveVariableIT.java    From camunda-external-task-client-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shoudSetVariable_Null() {
  // given
  engineRule.startProcessInstance(processDefinition.getId());

  client.subscribe(EXTERNAL_TASK_TOPIC_FOO)
    .handler(invocationHandler)
    .open();

  clientRule.waitForFetchAndLockUntil(() -> !invocationHandler.getInvocations().isEmpty());

  RecordedInvocation invocation = invocationHandler.getInvocations().get(0);
  ExternalTask fooTask = invocation.getExternalTask();
  ExternalTaskService fooService = invocation.getExternalTaskService();

  client.subscribe(EXTERNAL_TASK_TOPIC_BAR)
    .handler(handler)
    .open();

  // when
  Map<String, Object> variables = Variables.createVariables();
  variables.put(VARIABLE_NAME, null);
  fooService.complete(fooTask, variables);

  // then
  clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

  ExternalTask task = handler.getHandledTasks().get(0);

  Object variableValue = task.getVariable(VARIABLE_NAME);
  assertThat(variableValue).isNull();

  TypedValue typedValue = task.getVariableTyped(VARIABLE_NAME);
  assertThat(typedValue.getValue()).isNull();
  assertThat(typedValue.getType()).isEqualTo(NULL);
}
 
Example 16
Source File: DmnExpressionLanguageTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = 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);

  DmnDecisionTableResult result = decisionService.evaluateDecisionTableByKey("decision_1", inputs);

  assertThat((String)result.getSingleEntry()).isEqualTo("0_FROM_LIST");
}
 
Example 17
Source File: JsonSerializationIT.java    From camunda-external-task-client-java with Apache License 2.0 4 votes vote down vote up
@Test
public void shoudSetJsonListVariableTyped() throws JSONException {
  // given
  engineRule.startProcessInstance(processDefinition.getId());

  client.subscribe(EXTERNAL_TASK_TOPIC_FOO)
    .handler(invocationHandler)
    .open();

  clientRule.waitForFetchAndLockUntil(() -> !invocationHandler.getInvocations().isEmpty());

  RecordedInvocation invocation = invocationHandler.getInvocations().get(0);
  ExternalTask fooTask = invocation.getExternalTask();
  ExternalTaskService fooService = invocation.getExternalTaskService();

  client.subscribe(EXTERNAL_TASK_TOPIC_BAR)
    .handler(handler)
    .open();

  // when
  List<JsonSerializable> variable = new ArrayList<>();
  variable.add(VARIABLE_VALUE_JSON_DESERIALIZED);
  variable.add(VARIABLE_VALUE_JSON_DESERIALIZED);

  Map<String, Object> variables = Variables.createVariables();
  variables.put(VARIABLE_NAME_JSON, Variables.objectValue(variable).create());
  fooService.complete(fooTask, variables);

  // then
  clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

  ExternalTask task = handler.getHandledTasks().get(0);

  ObjectValue serializedValue = task.getVariableTyped(VARIABLE_NAME_JSON, false);
  assertThat(serializedValue.isDeserialized()).isFalse();
  JSONAssert.assertEquals(VARIABLE_VALUE_JSON_LIST_SERIALIZED, new String(serializedValue.getValueSerialized()), true);
  assertThat(serializedValue.getType()).isEqualTo(OBJECT);
  assertThat(serializedValue.getObjectTypeName()).isEqualTo("java.util.ArrayList<org.camunda.bpm.client.variable.JsonSerializable>");

  ObjectValue deserializedValue = task.getVariableTyped(VARIABLE_NAME_JSON);
  assertThat(deserializedValue.isDeserialized()).isTrue();
  assertThat(deserializedValue.getValue()).isEqualTo(variable);
  assertThat(deserializedValue.getType()).isEqualTo(OBJECT);
  assertThat(deserializedValue.getObjectTypeName()).isEqualTo("java.util.ArrayList<org.camunda.bpm.client.variable.JsonSerializable>");

  List<JsonSerializable> variableValue = task.getVariable(VARIABLE_NAME_JSON);
  assertThat(variableValue).isEqualTo(variable);
}
 
Example 18
Source File: IntermediateConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
@Deployment
public void testParallelVariableValue() {
  //given process with intermediate conditional event and variable with wrong value
  Map<String, Object> variables = Variables.createVariables();
  variables.put(VARIABLE_NAME, 0);
  ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY, variables);
  Execution execution1 = runtimeService.createExecutionQuery()
           .processInstanceId(procInst.getId())
           .activityId(CONDITIONAL_EVENT + 1)
           .singleResult();

  Execution execution2 = runtimeService.createExecutionQuery()
           .processInstanceId(procInst.getId())
           .activityId(CONDITIONAL_EVENT + 2)
           .singleResult();
  assertEquals(2, conditionEventSubscriptionQuery.list().size());

  //when variable is set to correct value
  runtimeService.setVariable(execution1.getId(), VARIABLE_NAME, 1);

  //then execution of first conditional event is completed
  execution1 = runtimeService.createExecutionQuery()
           .processInstanceId(procInst.getId())
           .activityId(CONDITIONAL_EVENT + 1)
           .singleResult();
  assertNull(execution1);
  assertEquals(1, conditionEventSubscriptionQuery.list().size());

  //when second variable is set to correct value
  runtimeService.setVariable(execution2.getId(), VARIABLE_NAME, 2);

  //then execution and process instance is ended, since both conditions was true
  execution2 = runtimeService.createExecutionQuery()
           .processInstanceId(procInst.getId())
           .activityId(CONDITIONAL_EVENT + 2)
           .singleResult();
  assertNull(execution2);
  procInst = runtimeService.createProcessInstanceQuery()
                           .processDefinitionKey(CONDITIONAL_EVENT_PROCESS_KEY)
                           .singleResult();
  assertNull(procInst);
  assertEquals(0, conditionEventSubscriptionQuery.list().size());
}
 
Example 19
Source File: FeelExceptionTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Before
public void initVariables() {
  variables = Variables.createVariables();
  variables.putValue(INPUT_VARIABLE, 13);
}
 
Example 20
Source File: JsonSerializationIT.java    From camunda-external-task-client-java with Apache License 2.0 4 votes vote down vote up
@Test
public void shoudSetVariable() throws JSONException {
  // given
  engineRule.startProcessInstance(processDefinition.getId());

  client.subscribe(EXTERNAL_TASK_TOPIC_FOO)
    .handler(invocationHandler)
    .open();

  clientRule.waitForFetchAndLockUntil(() -> !invocationHandler.getInvocations().isEmpty());

  RecordedInvocation invocation = invocationHandler.getInvocations().get(0);
  ExternalTask fooTask = invocation.getExternalTask();
  ExternalTaskService fooService = invocation.getExternalTaskService();

  client.subscribe(EXTERNAL_TASK_TOPIC_BAR)
    .handler(handler)
    .open();

  // when
  Map<String, Object> variables = Variables.createVariables();
  variables.put(VARIABLE_NAME_JSON, VARIABLE_VALUE_JSON_DESERIALIZED);
  fooService.complete(fooTask, variables);

  // then
  clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

  ExternalTask task = handler.getHandledTasks().get(0);

  ObjectValue serializedValue = task.getVariableTyped(VARIABLE_NAME_JSON, false);
  assertThat(serializedValue.isDeserialized()).isFalse();
  JSONAssert.assertEquals(VARIABLE_VALUE_JSON_SERIALIZED, new String(serializedValue.getValueSerialized()), true);
  assertThat(serializedValue.getType()).isEqualTo(OBJECT);
  assertThat(serializedValue.getObjectTypeName()).isEqualTo(JsonSerializable.class.getName());

  ObjectValue deserializedValue = task.getVariableTyped(VARIABLE_NAME_JSON);
  assertThat(deserializedValue.isDeserialized()).isTrue();
  assertThat(deserializedValue.getValue()).isEqualTo(VARIABLE_VALUE_JSON_DESERIALIZED);
  assertThat(deserializedValue.getType()).isEqualTo(OBJECT);
  assertThat(deserializedValue.getObjectTypeName()).isEqualTo(JsonSerializable.class.getName());

  JsonSerializable variableValue = task.getVariable(VARIABLE_NAME_JSON);
  assertThat(variableValue).isEqualTo(VARIABLE_VALUE_JSON_DESERIALIZED);
}