Search in sources :

Example 16 with ProcessRuntimeConfiguration

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));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ProcessInstance(org.activiti.api.process.model.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) ProcessRuntimeConfiguration(org.activiti.api.process.runtime.conf.ProcessRuntimeConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with ProcessRuntimeConfiguration

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));
}
Also used : ProcessInstance(org.activiti.api.process.model.ProcessInstance) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) SimpleDateFormat(java.text.SimpleDateFormat) ProcessRuntimeConfiguration(org.activiti.api.process.runtime.conf.ProcessRuntimeConfiguration) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ProcessRuntimeConfiguration (org.activiti.api.process.runtime.conf.ProcessRuntimeConfiguration)17 Test (org.junit.jupiter.api.Test)17 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)17 ProcessRuntimeEventListener (org.activiti.api.process.runtime.events.listener.ProcessRuntimeEventListener)6 VariableEventListener (org.activiti.api.runtime.shared.events.VariableEventListener)6 ProcessInstance (org.activiti.api.process.model.ProcessInstance)4 VariableInstance (org.activiti.api.model.shared.model.VariableInstance)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ProcessDefinition (org.activiti.api.process.model.ProcessDefinition)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 SimpleDateFormat (java.text.SimpleDateFormat)1 UpdateProcessPayload (org.activiti.api.process.model.payloads.UpdateProcessPayload)1