Search in sources :

Example 1 with SaveTaskPayloadBuilder

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);
}
Also used : Task(org.activiti.api.task.model.Task) SaveTaskPayloadBuilder(org.activiti.api.task.model.builders.SaveTaskPayloadBuilder) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with SaveTaskPayloadBuilder

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);
}
Also used : Task(org.activiti.api.task.model.Task) HashMap(java.util.HashMap) SaveTaskPayloadBuilder(org.activiti.api.task.model.builders.SaveTaskPayloadBuilder) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) 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 3 with SaveTaskPayloadBuilder

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"));
}
Also used : Task(org.activiti.api.task.model.Task) SaveTaskPayloadBuilder(org.activiti.api.task.model.builders.SaveTaskPayloadBuilder) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Task (org.activiti.api.task.model.Task)3 SaveTaskPayloadBuilder (org.activiti.api.task.model.builders.SaveTaskPayloadBuilder)3 Test (org.junit.jupiter.api.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 VariableInstance (org.activiti.api.model.shared.model.VariableInstance)2 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)2 HashMap (java.util.HashMap)1 ProcessInstance (org.activiti.api.process.model.ProcessInstance)1