Search in sources :

Example 51 with Task

use of org.activiti.api.task.model.Task in project Activiti by Activiti.

the class ProcessRuntimeBPMNTimerIT method shouldGetTimerFiredScheduledEventsForProcessWithTimer.

@Test
public void shouldGetTimerFiredScheduledEventsForProcessWithTimer() throws Exception {
    // given
    ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey(PROCESS_INTERMEDIATE_TIMER_EVENT);
    // when
    List<BPMNTimerScheduledEvent> eventsScheduled = listenerScheduled.getEvents();
    // then
    assertThat(eventsScheduled).extracting(BPMNTimerEvent::getEventType, BPMNTimerEvent::getProcessDefinitionId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getElementId()).contains(Tuple.tuple(BPMNTimerEvent.TimerEvents.TIMER_SCHEDULED, processInstance.getProcessDefinitionId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "timer"));
    assertThat(listenerFired.getEvents()).isEmpty();
    // when
    long waitTime = 10 * 60 * 1000;
    Date startTime = new Date();
    Date dueDate = new Date(startTime.getTime() + waitTime);
    // After setting the clock to time '5minutes and 5 seconds', the second timer should fire
    processEngineConfiguration.getClock().setCurrentTime(new Date(dueDate.getTime() + 5000));
    // then
    await().untilAsserted(() -> {
        assertThat(listenerFired.getEvents()).extracting(BPMNTimerEvent::getEventType, BPMNTimerEvent::getProcessDefinitionId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getElementId()).contains(Tuple.tuple(BPMNTimerEvent.TimerEvents.TIMER_FIRED, processInstance.getProcessDefinitionId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "timer"));
        assertThat(listenerExecuted.getEvents()).extracting(BPMNTimerEvent::getEventType, BPMNTimerEvent::getProcessDefinitionId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getElementId()).contains(Tuple.tuple(BPMNTimerEvent.TimerEvents.TIMER_EXECUTED, processInstance.getProcessDefinitionId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "timer"));
    });
    // then the execution reaches the task
    Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().withProcessInstanceId(processInstance.getId()).build());
    assertThat(tasks.getContent()).hasSize(1);
    assertThat(tasks.getContent().get(0).getName()).isEqualTo("User Task");
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Pageable(org.activiti.api.runtime.shared.query.Pageable) DummyBPMNTimerCancelledListener(org.activiti.spring.boot.process.listener.DummyBPMNTimerCancelledListener) Task(org.activiti.api.task.model.Task) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SecurityUtil(org.activiti.spring.boot.security.util.SecurityUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) DummyBPMNTimerScheduledListener(org.activiti.spring.boot.process.listener.DummyBPMNTimerScheduledListener) ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) BPMNTimerEvent(org.activiti.api.process.model.events.BPMNTimerEvent) DummyBPMNTimerExecutedListener(org.activiti.spring.boot.process.listener.DummyBPMNTimerExecutedListener) TaskRuntime(org.activiti.api.task.runtime.TaskRuntime) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Awaitility.await(org.awaitility.Awaitility.await) Tuple(org.assertj.core.groups.Tuple) BPMNTimerCancelledEvent(org.activiti.api.process.model.events.BPMNTimerCancelledEvent) Assertions.tuple(org.assertj.core.api.Assertions.tuple) TaskPayloadBuilder(org.activiti.api.task.model.builders.TaskPayloadBuilder) Import(org.springframework.context.annotation.Import) Page(org.activiti.api.runtime.shared.query.Page) BPMNTimerScheduledEvent(org.activiti.api.process.model.events.BPMNTimerScheduledEvent) DummyBPMNTimerFiredListener(org.activiti.spring.boot.process.listener.DummyBPMNTimerFiredListener) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ProcessCleanUpUtil(org.activiti.spring.boot.test.util.ProcessCleanUpUtil) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) Task(org.activiti.api.task.model.Task) BPMNTimerScheduledEvent(org.activiti.api.process.model.events.BPMNTimerScheduledEvent) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Date(java.util.Date) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 52 with Task

use of org.activiti.api.task.model.Task in project Activiti by Activiti.

the class ProcessRuntimeCallActivityMappingIT method getTask.

private Task getTask(ProcessInstance subProcessInstance) {
    List<Task> taskList = taskRuntime.tasks(Pageable.of(0, 50), TaskPayloadBuilder.tasks().withProcessInstanceId(subProcessInstance.getId()).build()).getContent();
    assertThat(taskList).isNotEmpty();
    Task task = taskList.get(0);
    assertThat(task.getAssignee()).isNull();
    assertThat(task.getStatus()).isEqualTo(Task.TaskStatus.CREATED);
    return task;
}
Also used : Task(org.activiti.api.task.model.Task)

Example 53 with Task

use of org.activiti.api.task.model.Task in project Activiti by Activiti.

the class ProcessRuntimeCallActivityMappingIT method completeTask.

public void completeTask(String taskId, Map<String, Object> variables) {
    Task completeTask = taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(taskId).withVariables(variables).build());
    assertThat(completeTask).isNotNull();
    assertThat(completeTask.getStatus()).isEqualTo(Task.TaskStatus.COMPLETED);
}
Also used : Task(org.activiti.api.task.model.Task)

Example 54 with Task

use of org.activiti.api.task.model.Task in project Activiti by Activiti.

the class ProcessRuntimeCallActivityMappingIT method basicCallActivityMappingTest.

@Test
public void basicCallActivityMappingTest() {
    securityUtil.logInAs("user");
    ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(PARENT_PROCESS_CALL_ACTIVITY).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("subprocess_input_var1", "inName"), tuple("subprocess_input_var2", 20), tuple("subprocess_input_var3", 5), tuple("input_static_value", "a static value"), tuple("subprocess_out_var1", "outValue"), tuple("subprocess_out_var2", 222), tuple("subprocess_static_value", "static some value"), tuple("var_not_exist_in_subprocess_extension_file", 20));
    assertThat("my-task-call-activity").isEqualTo(task.getName());
    Map<String, Object> variablesForTask = new HashMap<>();
    variablesForTask.put("input_variable_name_1", "fromSubprocessName");
    variablesForTask.put("input_variable_name_2", 39);
    variablesForTask.put("out_variable_name_1", 176);
    completeTask(task.getId(), variablesForTask);
    List<VariableInstance> parentVariables = processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstanceId(processInstance.getId()).build());
    assertThat(parentVariables).extracting(VariableInstance::getName, VariableInstance::getValue).containsOnly(tuple("name", "outValue"), tuple("age", 222), tuple("output_unmapped_variable_with_non_matching_connector_output_name", "default"), tuple("input_unmapped_variable_with_non_matching_connector_input_name", "inTest"));
    cleanUp();
}
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 55 with Task

use of org.activiti.api.task.model.Task in project Activiti by Activiti.

the class ProcessRuntimeIT method should_startAnAlreadyCreatedProcess_when_startCreatedProcessIsCalled.

@Test
public void should_startAnAlreadyCreatedProcess_when_startCreatedProcessIsCalled() {
    securityUtil.logInAs("garth");
    ProcessInstance singleTaskProcessCreated = processRuntime.create(ProcessPayloadBuilder.create().withProcessDefinitionKey(SINGLE_TASK_PROCESS).build());
    assertThat(singleTaskProcessCreated.getStatus()).isEqualTo(ProcessInstance.ProcessInstanceStatus.CREATED);
    Page<Task> tasks = taskRuntime.tasks(PAGEABLE, TaskPayloadBuilder.tasks().withProcessInstanceId(singleTaskProcessCreated.getId()).build());
    assertThat(tasks.getTotalItems()).isEqualTo(0);
    ProcessInstance singleTaskProcessStarted = processRuntime.startCreatedProcess(singleTaskProcessCreated.getId(), ProcessPayloadBuilder.start().build());
    tasks = taskRuntime.tasks(PAGEABLE, TaskPayloadBuilder.tasks().withProcessInstanceId(singleTaskProcessCreated.getId()).build());
    assertThat(tasks.getTotalItems()).isEqualTo(1);
    assertThat(tasks.getContent().get(0).getName()).isEqualTo("my-task");
    assertThat(RuntimeTestConfiguration.createdTasks).contains(tasks.getContent().get(0).getId());
    assertThat(singleTaskProcessStarted).isNotNull();
    assertThat(singleTaskProcessStarted.getStatus()).isEqualTo(ProcessInstance.ProcessInstanceStatus.RUNNING);
}
Also used : Task(org.activiti.api.task.model.Task) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Task (org.activiti.api.task.model.Task)115 Test (org.junit.jupiter.api.Test)99 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)95 ProcessInstance (org.activiti.api.process.model.ProcessInstance)59 VariableInstance (org.activiti.api.model.shared.model.VariableInstance)29 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)25 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)23 AfterEach (org.junit.jupiter.api.AfterEach)23 Autowired (org.springframework.beans.factory.annotation.Autowired)23 SecurityUtil (org.activiti.spring.boot.security.util.SecurityUtil)22 Page (org.activiti.api.runtime.shared.query.Page)21 ProcessCleanUpUtil (org.activiti.spring.boot.test.util.ProcessCleanUpUtil)20 BeforeEach (org.junit.jupiter.api.BeforeEach)20 Import (org.springframework.context.annotation.Import)20 Date (java.util.Date)19 List (java.util.List)19 Collections.singletonMap (java.util.Collections.singletonMap)15 RuntimeEvent (org.activiti.api.model.shared.event.RuntimeEvent)15 ProcessRuntimeEvent (org.activiti.api.process.model.events.ProcessRuntimeEvent)15 TaskRuntimeEvent (org.activiti.api.task.model.events.TaskRuntimeEvent)15