Search in sources :

Example 31 with VariableInstance

use of org.activiti.api.model.shared.model.VariableInstance in project Activiti by Activiti.

the class ProcessRuntimeCallActivityMappingIT method haveToPassAllVariablesCallActivityEmptyMappingNoTaskTest.

@Test
public void haveToPassAllVariablesCallActivityEmptyMappingNoTaskTest() {
    securityUtil.logInAs("user");
    // After the process has started, the subProcess task should be active
    ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(PARENT_PROCESS_CALL_ACTIVITY_EMPTY_MAPPING_NO_TASK).build());
    assertThat(processInstance).isNotNull();
    ProcessInstance subProcessInstance = getSubProcess(processInstance);
    assertThat(subProcessInstance.getProcessDefinitionKey()).isEqualTo(SUB_PROCESS_CALL_ACTIVITY);
    Task task = getTask(subProcessInstance);
    taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build());
    List<VariableInstance> subProcVariables = processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstanceId(subProcessInstance.getId()).build());
    assertThat(subProcVariables).extracting(VariableInstance::getName, VariableInstance::getValue).containsOnly(tuple("output_unmapped_variable_with_non_matching_connector_output_name", "default"), tuple("input_unmapped_variable_with_non_matching_connector_input_name", "inTest"), tuple("name", "inName"), tuple("age", 20), tuple("subprocess_input_var2", 2), tuple("subprocess_input_var3", 3), tuple("subprocess_out_var2", 222), tuple("subprocess_out_var1", "outValue"), tuple("subprocess_input_var1", "value1"), tuple("subprocess_static_value", "static some value"));
    assertThat("my-task-call-activity").isEqualTo(task.getName());
    Map<String, Object> variablesForTask = new HashMap<>();
    variablesForTask.put("input_variable_name_1", "fromSubprocessName");
    completeTask(task.getId(), variablesForTask);
    List<VariableInstance> parentVariablesAfterComnplete = processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstanceId(processInstance.getId()).build());
    assertThat(parentVariablesAfterComnplete).extracting(VariableInstance::getName, VariableInstance::getValue).containsOnly(tuple("output_unmapped_variable_with_non_matching_connector_output_name", "default"), tuple("input_unmapped_variable_with_non_matching_connector_input_name", "inTest"), tuple("name", "inName"), tuple("age", 20), tuple("subprocess_input_var2", 2), tuple("subprocess_input_var3", 3), tuple("subprocess_out_var2", 222), tuple("subprocess_out_var1", "outValue"), tuple("subprocess_input_var1", "value1"), tuple("subprocess_static_value", "static some value"), tuple("input_variable_name_1", "fromSubprocessName"));
}
Also used : Task(org.activiti.api.task.model.Task) HashMap(java.util.HashMap) ProcessInstance(org.activiti.api.process.model.ProcessInstance) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 32 with VariableInstance

use of org.activiti.api.model.shared.model.VariableInstance in project Activiti by Activiti.

the class ProcessRuntimeCallActivityMappingIT method haveToPassNoVariablesCallActivityEmptyMappingWithTaskTest.

@Test
public void haveToPassNoVariablesCallActivityEmptyMappingWithTaskTest() {
    securityUtil.logInAs("user");
    ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(PARENT_PROCESS_CALL_ACTIVITY_EMPTY_MAPPING_WITH_TASK).build());
    assertThat(processInstance).isNotNull();
    ProcessInstance subProcessInstance = getSubProcess(processInstance);
    assertThat(subProcessInstance.getProcessDefinitionKey()).isEqualTo(SUB_PROCESS_CALL_ACTIVITY);
    Task task = getTask(subProcessInstance);
    taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build());
    List<VariableInstance> subProcVariables = processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstanceId(subProcessInstance.getId()).build());
    assertThat(subProcVariables).extracting(VariableInstance::getName, VariableInstance::getValue).size().isEqualTo(6);
    assertThat(subProcVariables).extracting(VariableInstance::getName, VariableInstance::getValue).containsOnly(tuple("subprocess_input_var2", 2), tuple("subprocess_input_var3", 3), tuple("subprocess_out_var2", 222), tuple("subprocess_out_var1", "outValue"), tuple("subprocess_input_var1", "value1"), tuple("subprocess_static_value", "static some value"));
    assertThat("my-task-call-activity").isEqualTo(task.getName());
    Map<String, Object> variablesForTask = new HashMap<>();
    variablesForTask.put("input_variable_name_1", "fromSubprocessName");
    completeTask(task.getId(), variablesForTask);
    List<VariableInstance> parentVariablesAfterComnplete = processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstanceId(processInstance.getId()).build());
    assertThat(parentVariablesAfterComnplete).extracting(VariableInstance::getName, VariableInstance::getValue).containsOnly(tuple("output_unmapped_variable_with_non_matching_connector_output_name", "default"), tuple("input_unmapped_variable_with_non_matching_connector_input_name", "inTest"), tuple("name", "inName"), tuple("age", 20));
}
Also used : Task(org.activiti.api.task.model.Task) HashMap(java.util.HashMap) ProcessInstance(org.activiti.api.process.model.ProcessInstance) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 33 with VariableInstance

use of org.activiti.api.model.shared.model.VariableInstance in project Activiti by Activiti.

the class ProcessRuntimeVariableMappingTest method shouldMapVariables.

@Test
public void shouldMapVariables() {
    ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey(VARIABLE_MAPPING_PROCESS);
    List<VariableInstance> variables = processBaseRuntime.getProcessVariablesByProcessId(processInstance.getId());
    assertThat(variables).extracting(VariableInstance::getName, VariableInstance::getValue).containsOnly(tuple("name", "outName"), tuple("age", 35), tuple("input_unmapped_variable_with_matching_name", "inTest"), tuple("input_unmapped_variable_with_non_matching_connector_input_name", "inTest"), tuple("nickName", "testName"), tuple("out_unmapped_variable_matching_name", "default"), tuple("output_unmapped_variable_with_non_matching_connector_output_name", "default"));
}
Also used : ProcessInstance(org.activiti.api.process.model.ProcessInstance) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 34 with VariableInstance

use of org.activiti.api.model.shared.model.VariableInstance in project Activiti by Activiti.

the class ProcessRuntimeVariableMappingTest method should_resolveExpression_when_expressionIsInInputMappingValueOrInMappedProperty.

@Test
public void should_resolveExpression_when_expressionIsInInputMappingValueOrInMappedProperty() {
    ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey(VARIABLE_MAPPING_EXPRESSION_PROCESS);
    List<VariableInstance> variables = processBaseRuntime.getProcessVariablesByProcessId(processInstance.getId());
    String[] array = { "first", "${name}", "${surname}", "last" };
    List<String> list = asList(array);
    Map<String, Object> dataMap = new HashMap<>();
    dataMap.put("age-in-months", "${age * 12}");
    dataMap.put("full-name", "${name} ${surname}");
    dataMap.put("demoString", "expressionResolved");
    dataMap.put("list", list);
    JsonNode data = mapper.convertValue(dataMap, JsonNode.class);
    assertThat(variables).extracting(VariableInstance::getName, VariableInstance::getValue).containsOnly(tuple("age", 30), tuple("name", "outName"), tuple("surname", "Doe"), tuple("data", data), tuple("user-msg", "Hello ${name.concat(' ').concat(surname)}, today is your ${age}th birthday! It means ${age * 365.25} days of life"), tuple("input-unmapped-variable-with-matching-name", "${surname}"), tuple("input-unmapped-variable-with-non-matching-connector-input-name", "inTestExpression"), tuple("variableToResolve", "${name}"), tuple("out-unmapped-variable-matching-name", "defaultExpression"), tuple("output-unmapped-variable-with-non-matching-connector-output-name", "defaultExpression"), tuple("resident", true));
}
Also used : HashMap(java.util.HashMap) ProcessInstance(org.activiti.api.process.model.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

VariableInstance (org.activiti.api.model.shared.model.VariableInstance)34 Test (org.junit.jupiter.api.Test)33 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)33 ProcessInstance (org.activiti.api.process.model.ProcessInstance)26 Task (org.activiti.api.task.model.Task)15 HashMap (java.util.HashMap)9 ArrayList (java.util.ArrayList)3 Collections.singletonMap (java.util.Collections.singletonMap)3 List (java.util.List)3 RuntimeEvent (org.activiti.api.model.shared.event.RuntimeEvent)3 StartMessageDeploymentDefinition (org.activiti.api.process.model.StartMessageDeploymentDefinition)3 StartMessageSubscription (org.activiti.api.process.model.StartMessageSubscription)3 MessagePayloadBuilder (org.activiti.api.process.model.builders.MessagePayloadBuilder)3 ProcessPayloadBuilder (org.activiti.api.process.model.builders.ProcessPayloadBuilder)3 BPMNMessageEvent (org.activiti.api.process.model.events.BPMNMessageEvent)3 MessageSubscriptionCancelledEvent (org.activiti.api.process.model.events.MessageSubscriptionCancelledEvent)3 MessageSubscriptionEvent (org.activiti.api.process.model.events.MessageSubscriptionEvent)3 ProcessRuntimeEvent (org.activiti.api.process.model.events.ProcessRuntimeEvent)3 StartMessageDeployedEvent (org.activiti.api.process.model.events.StartMessageDeployedEvent)3 ProcessRuntime (org.activiti.api.process.runtime.ProcessRuntime)3