use of org.activiti.api.task.model.builders.SaveTaskPayloadBuilder in project Activiti by Activiti.
the class TaskRuntimeSaveTaskTest method createStandaloneTaskAndSaveWithUnAuthorizedUser.
@Test()
public void createStandaloneTaskAndSaveWithUnAuthorizedUser() {
// given
securityUtil.logInAs("garth");
Task standAloneTask = taskRuntime.create(TaskPayloadBuilder.create().withName("simple task").withAssignee("garth").build());
// Complete should fail with a different user
securityUtil.logInAs("user");
// when
Throwable throwable = catchThrowable(() -> taskRuntime.save(new SaveTaskPayloadBuilder().withTaskId(standAloneTask.getId()).withVariable("name", "value").build()));
// then
assertThat(throwable).isInstanceOf(NotFoundException.class);
}
use of org.activiti.api.task.model.builders.SaveTaskPayloadBuilder in project Activiti by Activiti.
the class TaskRuntimeSaveTaskTest method testSaveCompleteReviewOutcomeTasksProcessWithVariables.
@Test()
public void testSaveCompleteReviewOutcomeTasksProcessWithVariables() {
// given
securityUtil.logInAs("user");
Map<String, Object> startVariables = new HashMap<>();
startVariables.put("name", "");
// when
ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(COMPLETE_REVIEW_TASK_PROCESS).withVariables(startVariables).build());
// complete task
securityUtil.logInAs("garth");
Task task1 = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
List<VariableInstance> variables = taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task1.getId()).build());
assertThat(variables).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("name", ""));
taskRuntime.save(new SaveTaskPayloadBuilder().withTaskId(task1.getId()).withVariable("name", "wrong").build());
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task1.getId()).build());
// reject task
securityUtil.logInAs("user");
Task task2 = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
List<VariableInstance> variables1 = taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task2.getId()).build());
assertThat(variables1).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("name", "wrong"));
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task2.getId()).withVariable("approved", false).build());
// fix task
securityUtil.logInAs("garth");
Task task3 = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
taskRuntime.save(new SaveTaskPayloadBuilder().withTaskId(task3.getId()).withVariable("name", "correct").build());
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task3.getId()).build());
// approve task
securityUtil.logInAs("user");
Task task4 = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
List<VariableInstance> variables2 = taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task4.getId()).build());
assertThat(variables2).extracting(VariableInstance::getName, VariableInstance::getValue).contains(tuple("name", "correct"));
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task4.getId()).withVariable("approved", true).build());
// then process completes
Throwable throwable = catchThrowable(() -> assertThat(processRuntime.processInstance(processInstance.getId())).isNull());
assertThat(throwable).isInstanceOf(NotFoundException.class);
}
use of org.activiti.api.task.model.builders.SaveTaskPayloadBuilder 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"));
}
Aggregations