Search in sources :

Example 46 with Task

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

the class TaskRuntimeStandaloneTaskTest method should_throwExceptionOnCreateVariable_when_charactersNotAllowedInVariableName.

@Test
public void should_throwExceptionOnCreateVariable_when_charactersNotAllowedInVariableName() {
    securityUtil.logInAs("user");
    Task task = taskRuntime.create(TaskPayloadBuilder.create().withName("name").withAssignee("user").build());
    Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getContent()).hasSize(1);
    Throwable throwable = catchThrowable(() -> taskRuntime.createVariable(TaskPayloadBuilder.createVariable().withTaskId(task.getId()).withVariable("!wrong_name", "value").build()));
    assertThat(throwable).isInstanceOf(IllegalStateException.class);
}
Also used : Task(org.activiti.api.task.model.Task) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 47 with Task

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

the class TaskRuntimeStandaloneTaskTest method shouldEmmitEventForStandAloneTaskDeletion.

@Test
public void shouldEmmitEventForStandAloneTaskDeletion() {
    // given
    securityUtil.logInAs("user");
    Task firstTask = taskRuntime.create(TaskPayloadBuilder.create().withName("First task").withAssignee("user").build());
    Task secondTask = taskRuntime.create(TaskPayloadBuilder.create().withName("Second task").withAssignee("user").build());
    // when
    taskRuntime.delete(TaskPayloadBuilder.delete().withTaskId(secondTask.getId()).build());
    // then
    assertThat(taskRuntimeEventListeners.getCancelledTasks()).extracting(Task::getId, Task::getName).contains(tuple(secondTask.getId(), secondTask.getName())).doesNotContain(tuple(firstTask.getId(), firstTask.getName()));
}
Also used : Task(org.activiti.api.task.model.Task) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 48 with Task

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

the class TaskRuntimeStandaloneTaskTest method should_throwExceptionOnTaskComplete_when_charactersNotAllowedInVariableName.

@Test
public void should_throwExceptionOnTaskComplete_when_charactersNotAllowedInVariableName() {
    securityUtil.logInAs("user");
    Task task = taskRuntime.create(TaskPayloadBuilder.create().withName("name").withAssignee("user").build());
    Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getContent()).hasSize(1);
    Map<String, Object> variables = new HashMap<>();
    variables.put("var_name1", "good_value");
    variables.put("!wrong_name", "!any_value>");
    Throwable throwable = catchThrowable(() -> taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).withVariables(variables).build()));
    assertThat(throwable).isInstanceOf(IllegalStateException.class);
}
Also used : Task(org.activiti.api.task.model.Task) HashMap(java.util.HashMap) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 49 with Task

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

the class TaskRuntimeUnAuthorizedTest method createStandaloneTaskForGroup.

@Test
public void createStandaloneTaskForGroup() {
    securityUtil.logInAs("garth");
    Task standAloneTask = taskRuntime.create(TaskPayloadBuilder.create().withName("group task").withCandidateGroup("doctor").build());
    // the owner should be able to see the created task
    Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getContent()).hasSize(1);
    Task task = tasks.getContent().get(0);
    assertThat(task.getAssignee()).isNull();
    assertThat(task.getStatus()).isEqualTo(Task.TaskStatus.CREATED);
    // Claim should throw a NotFoundException due you are not a candidate
    securityUtil.logInAs("user");
    // when
    Throwable throwable = catchThrowable(() -> taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build()));
    // then
    assertThat(throwable).isInstanceOf(NotFoundException.class);
}
Also used : Task(org.activiti.api.task.model.Task) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 50 with Task

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

the class ProcessRuntimeBPMNTimerIT method shouldGetTimerCanceledEventOnBoundaryEvent.

@Test
public void shouldGetTimerCanceledEventOnBoundaryEvent() {
    // given
    ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey(PROCESS_TIMER_CANCELLED_EVENT);
    List<BPMNTimerScheduledEvent> eventsScheduled = listenerScheduled.getEvents();
    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"));
    clear();
    Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().withProcessInstanceId(processInstance.getId()).build());
    assertThat(tasks.getContent()).hasSize(1);
    Task task = tasks.getContent().get(0);
    taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build());
    taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).build());
    List<BPMNTimerCancelledEvent> eventsCanceled = listenerCancelled.getEvents();
    assertThat(eventsCanceled).extracting(BPMNTimerEvent::getEventType, BPMNTimerEvent::getProcessDefinitionId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getElementId()).contains(Tuple.tuple(BPMNTimerEvent.TimerEvents.TIMER_CANCELLED, processInstance.getProcessDefinitionId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "timer"));
}
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) BPMNTimerCancelledEvent(org.activiti.api.process.model.events.BPMNTimerCancelledEvent) 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