use of org.activiti.api.process.runtime.conf.ProcessRuntimeConfiguration in project Activiti by Activiti.
the class ProcessExtensionsJsonVarsTest method processInstanceHasValidInitialVariables.
@Test
public void processInstanceHasValidInitialVariables() throws ParseException, IOException {
securityUtil.logInAs("user");
ProcessRuntimeConfiguration configuration = processRuntime.configuration();
assertThat(configuration).isNotNull();
CustomType customType = new CustomType();
customType.setCustomTypeField1("a");
// because this annotated with type info it should automatically be deserialized to object
CustomTypeAnnotated bigObject = new CustomTypeAnnotated();
bigObject.setCustomTypeField1(StringUtils.repeat("a", 4000));
// start a process with vars then check default and specified vars exist
ProcessInstance initialVarsProcess = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(JSON_VARS_PROCESS).withVariable("var2", new ObjectMapper().readValue("{ \"testvar2element\":\"testvar2element\"}", JsonNode.class)).withVariable("var4", customType).withVariable("var5", new ObjectMapper().readValue("{ \"verylongjson\":\"" + StringUtils.repeat("a", 4000) + "\"}", JsonNode.class)).withVariable("var6", bigObject).withBusinessKey("my business key").build());
assertThat(initialVarsProcess).isNotNull();
assertThat(initialVarsProcess.getStatus()).isEqualTo(ProcessInstance.ProcessInstanceStatus.RUNNING);
List<VariableInstance> variableInstances = processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstance(initialVarsProcess).build());
assertThat(variableInstances).isNotNull();
assertThat(variableInstances).hasSize(6);
assertThat(variableInstances).extracting("name", "type").contains(tuple("var1", "json"), tuple("var2", "json"), tuple("var3", "json"), tuple("var4", "json"), tuple("var5", "longJson"), tuple("var6", "longJson"));
assertThat(variableInstances).filteredOn("name", "var2").extracting("value").hasSize(1).hasOnlyElementsOfType(ObjectNode.class).first().toString().equalsIgnoreCase("{ \"testvar2element\":\"testvar2element\"}");
assertThat(variableInstances).filteredOn("name", "var3").extracting("value").hasSize(1).hasOnlyElementsOfType(ObjectNode.class).first().toString().contains("testvalueelement1");
assertThat(variableInstances).filteredOn("name", "var4").extracting("value").hasSize(1).hasOnlyElementsOfTypes(ObjectNode.class, CustomType.class).toString().contains(customType.getCustomTypeField1());
assertThat(variableInstances).filteredOn("name", "var6").extracting("value").hasSize(1).hasOnlyElementsOfType(CustomTypeAnnotated.class).extracting("customTypeField1").containsOnly(StringUtils.repeat("a", 4000));
// cleanup
processRuntime.delete(ProcessPayloadBuilder.delete(initialVarsProcess));
}
use of org.activiti.api.process.runtime.conf.ProcessRuntimeConfiguration in project Activiti by Activiti.
the class ProcessExtensionsIT method processInstanceHasValidInitialVariables.
@Test
public void processInstanceHasValidInitialVariables() throws ParseException {
ProcessRuntimeConfiguration configuration = processRuntime.configuration();
assertThat(configuration).isNotNull();
// start a process with vars then check default and specified vars exist
ProcessInstance initialVarsProcess = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(INITIAL_VARS_PROCESS).withVariable("extraVar", true).withVariable("age", 10).withVariable("name", "bob").withVariable("subscribe", true).withVariable("birth", new SimpleDateFormat("yyyy-MM-dd").parse("2009-11-30")).withBusinessKey("my business key").build());
assertThat(initialVarsProcess).isNotNull();
assertThat(initialVarsProcess.getStatus()).isEqualTo(ProcessInstance.ProcessInstanceStatus.RUNNING);
List<VariableInstance> variableInstances = processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstance(initialVarsProcess).build());
assertThat(variableInstances).isNotNull();
assertThat(variableInstances).hasSize(5);
assertThat(variableInstances).extracting("name").contains("extraVar", "name", "age", "birth", "subscribe");
// cleanup
processRuntime.delete(ProcessPayloadBuilder.delete(initialVarsProcess));
}
Aggregations