processVars.put("serializable", Arrays.asList("a", "b", "c"));
runtimeService.startProcessInstanceByKey("testProcess", processVars);
Task task = taskService.createTaskQuery().singleResult();
VariableMap variables = formService.getTaskFormVariables(task.getId());
assertEquals(7, variables.size());
assertEquals("someString", variables.get("stringField"));
assertEquals("someString", variables.getValueTyped("stringField").getValue());
assertEquals(ValueType.STRING, variables.getValueTyped("stringField").getType());
assertEquals(5l, variables.get("longField"));
assertEquals(5l, variables.getValueTyped("longField").getValue());
assertEquals(ValueType.LONG, variables.getValueTyped("longField").getType());
assertNull(variables.get("customField"));
assertNull(variables.getValueTyped("customField").getValue());
assertEquals(ValueType.STRING, variables.getValueTyped("customField").getType());
assertEquals("initialValue", variables.get("someString"));
assertEquals("initialValue", variables.getValueTyped("someString").getValue());
assertEquals(ValueType.STRING, variables.getValueTyped("someString").getType());
assertEquals(true, variables.get("initialBooleanVariable"));
assertEquals(true, variables.getValueTyped("initialBooleanVariable").getValue());
assertEquals(ValueType.BOOLEAN, variables.getValueTyped("initialBooleanVariable").getType());
assertEquals(1l, variables.get("initialLongVariable"));
assertEquals(1l, variables.getValueTyped("initialLongVariable").getValue());
assertEquals(ValueType.LONG, variables.getValueTyped("initialLongVariable").getType());
assertNotNull(variables.get("serializable"));
// override the long variable
taskService.setVariableLocal(task.getId(), "initialLongVariable", 2l);
variables = formService.getTaskFormVariables(task.getId());
assertEquals(7, variables.size());
assertEquals(2l, variables.get("initialLongVariable"));
assertEquals(2l, variables.getValueTyped("initialLongVariable").getValue());
assertEquals(ValueType.LONG, variables.getValueTyped("initialLongVariable").getType());
// get restricted set of variables (form field):
variables = formService.getTaskFormVariables(task.getId(), Arrays.asList("someString"), true);
assertEquals(1, variables.size());
assertEquals("initialValue", variables.get("someString"));
assertEquals("initialValue", variables.getValueTyped("someString").getValue());
assertEquals(ValueType.STRING, variables.getValueTyped("someString").getType());
// get restricted set of variables (process variable):
variables = formService.getTaskFormVariables(task.getId(), Arrays.asList("initialBooleanVariable"), true);
assertEquals(1, variables.size());
assertEquals(true, variables.get("initialBooleanVariable"));
assertEquals(true, variables.getValueTyped("initialBooleanVariable").getValue());
assertEquals(ValueType.BOOLEAN, variables.getValueTyped("initialBooleanVariable").getType());
// request non-existing variable
variables = formService.getTaskFormVariables(task.getId(), Arrays.asList("non-existing!"), true);
assertEquals(0, variables.size());
// null => all
variables = formService.getTaskFormVariables(task.getId(), null, true);
assertEquals(7, variables.size());
}