use of org.activiti.api.model.shared.model.VariableInstance in project Activiti by Activiti.
the class TaskRuntimeVariableMappingIT method taskShouldHaveNoVariablesWhenMappingIsEmpty.
@Test
public void taskShouldHaveNoVariablesWhenMappingIsEmpty() {
ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey(TASK_EMPTY_VAR_MAPPING);
List<Task> tasks = taskBaseRuntime.getTasksByProcessInstanceId(processInstance.getId());
assertThat(tasks).isNotEmpty();
assertThat(tasks).hasSize(1);
Task task = tasks.get(0);
assertThat(task.getName()).isEqualTo("testSimpleTask");
List<VariableInstance> procVariables = processBaseRuntime.getProcessVariablesByProcessId(processInstance.getId());
assertThat(procVariables).isNotNull().extracting(VariableInstance::getName, VariableInstance::getValue).containsOnly(tuple("process_variable_unmapped_1", "unmapped1Value"), tuple("process_variable_inputmap_1", "inputmap1Value"), tuple("process_variable_outputmap_1", "outputmap1Value"));
List<VariableInstance> taskVariables = taskBaseRuntime.getTasksVariablesByTaskId(task.getId());
assertThat(taskVariables).isEmpty();
Map<String, Object> variables = new HashMap<>();
variables.put("task_input_variable_name_1", "outputValue");
variables.put("task_output_variable_name_1", "outputTaskValue");
taskBaseRuntime.completeTask(task.getId(), variables);
assertThat(procVariables).isNotNull().extracting(VariableInstance::getName, VariableInstance::getValue).containsOnly(tuple("process_variable_unmapped_1", "unmapped1Value"), tuple("process_variable_inputmap_1", "inputmap1Value"), tuple("process_variable_outputmap_1", "outputmap1Value"));
processBaseRuntime.delete(processInstance.getId());
}
use of org.activiti.api.model.shared.model.VariableInstance in project Activiti by Activiti.
the class TaskRuntimeCompleteTaskTest method completeProcessTaskAndCheckReturnedTaskAndVariables.
@Test
public void completeProcessTaskAndCheckReturnedTaskAndVariables() {
securityUtil.logInAs("user");
Map<String, Object> startVariables = new HashMap<>();
startVariables.put("start1", "start1");
startVariables.put("start2", "start2");
// when
ProcessInstance twoTaskInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(TWOTASK_PROCESS).withVariables(startVariables).build());
// both tasks should have same variables
List<Task> tasks = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent();
List<VariableInstance> variables;
for (Task task : tasks) {
variables = taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task.getId()).build());
assertThat(variables).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("start1", "start1"), tuple("start2", "start2"));
}
Task task = tasks.get(0);
// claim task
Task claimTask = taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build());
assertThat(claimTask).extracting(Task::getStatus, Task::getOwner, Task::getAssignee, Task::getName, Task::getDescription, Task::getCreatedDate, Task::getDueDate, Task::getPriority, Task::getProcessDefinitionId, Task::getProcessInstanceId, Task::getParentTaskId, Task::getFormKey, Task::getProcessDefinitionVersion).containsExactly(TaskStatus.ASSIGNED, task.getOwner(), "user", task.getName(), task.getDescription(), task.getCreatedDate(), task.getDueDate(), task.getPriority(), task.getProcessDefinitionId(), task.getProcessInstanceId(), task.getParentTaskId(), task.getFormKey(), task.getProcessDefinitionVersion());
// complete one task and change var
Task completeTask = taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).withVariable("start1", "modagainstart1").build());
assertThat(completeTask).isNotNull().extracting(Task::getStatus, Task::getOwner, Task::getAssignee, Task::getName, Task::getDescription, Task::getCreatedDate, Task::getDueDate, Task::getClaimedDate, Task::getPriority, Task::getProcessDefinitionId, Task::getProcessInstanceId, Task::getParentTaskId, Task::getFormKey, Task::getProcessDefinitionVersion).containsExactly(TaskStatus.COMPLETED, task.getOwner(), claimTask.getAssignee(), task.getName(), task.getDescription(), task.getCreatedDate(), task.getDueDate(), claimTask.getClaimedDate(), task.getPriority(), task.getProcessDefinitionId(), task.getProcessInstanceId(), task.getParentTaskId(), task.getFormKey(), task.getProcessDefinitionVersion());
// after completion of the process variable start1 should updated
assertThat(processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstance(twoTaskInstance).build())).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("start1", "modagainstart1"), tuple("start2", "start2"));
}
use of org.activiti.api.model.shared.model.VariableInstance in project Activiti by Activiti.
the class TaskRuntimeSaveTaskTest method createStandaloneTaskAndSave.
@Test
public void createStandaloneTaskAndSave() {
// given
securityUtil.logInAs("garth");
Task standAloneTask = taskRuntime.create(TaskPayloadBuilder.create().withName("simple task").withAssignee("garth").build());
// when
taskRuntime.save(new SaveTaskPayloadBuilder().withTaskId(standAloneTask.getId()).withVariable("name", "value").build());
// then
List<VariableInstance> variables = taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(standAloneTask.getId()).build());
assertThat(variables).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("name", "value"));
}
use of org.activiti.api.model.shared.model.VariableInstance 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.model.shared.model.VariableInstance in project Activiti by Activiti.
the class ProcessRuntimeBPMNMessageIT method shouldReceiveCatchMessageWithCorrelationKeyAndMappedPayload.
@Test
public void shouldReceiveCatchMessageWithCorrelationKeyAndMappedPayload() {
ProcessInstance process = processRuntime.start(ProcessPayloadBuilder.start().withBusinessKey("businessKey").withVariable("correlationKey", "foo").withVariable("process_variable_name", "").withProcessDefinitionKey(CATCH_MESSAGE_PAYLOAD).build());
// when
processRuntime.receive(MessagePayloadBuilder.receive(TEST_MESSAGE).withVariable("message_variable_name", "value").withCorrelationKey("foo").build());
// then
assertThat(MessageTestConfiguration.messageEvents).isNotEmpty().extracting(BPMNMessageEvent::getEventType, BPMNMessageEvent::getProcessDefinitionId, BPMNMessageEvent::getProcessInstanceId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getMessagePayload().getName(), event -> event.getEntity().getMessagePayload().getCorrelationKey(), event -> event.getEntity().getMessagePayload().getBusinessKey(), event -> event.getEntity().getMessagePayload().getVariables()).contains(Tuple.tuple(BPMNMessageEvent.MessageEvents.MESSAGE_WAITING, process.getProcessDefinitionId(), process.getId(), process.getProcessDefinitionId(), process.getId(), "testMessage", "foo", process.getBusinessKey(), null), Tuple.tuple(BPMNMessageEvent.MessageEvents.MESSAGE_RECEIVED, process.getProcessDefinitionId(), process.getId(), process.getProcessDefinitionId(), process.getId(), "testMessage", "foo", process.getBusinessKey(), singletonMap("message_variable_name", "value")));
// and
List<VariableInstance> variables = processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstanceId(process.getId()).build());
assertThat(variables).extracting(VariableInstance::getName, VariableInstance::getValue).contains(tuple("process_variable_name", "value"));
}
Aggregations