org.flowable.engine.TaskService Java Examples

The following examples show how to use org.flowable.engine.TaskService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void taskOwnerEvent(TaskService taskService, HistoryService historyService, ManagementService managementService,
        ProcessEngineConfiguration processEngineConfiguration) {
    task = taskService.createTaskBuilder().
            assignee("initialAssignee").
            create();

    taskService.setOwner(task.getId(), "newOwner");

    if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
        List<HistoricTaskLogEntry> taskLogEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
        assertThat(taskLogEntries).hasSize(2);

        taskLogEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_OWNER_CHANGED").list();
        assertThat(taskLogEntries).hasSize(1);
        assertThat(taskLogEntries.get(0).getData()).
                contains("\"previousOwnerId\":null", "\"newOwnerId\":\"newOwner\"");
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getTimeStamp).isNotNull();
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getTaskId).isEqualTo(task.getId());
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getUserId).isNull();
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getType).isEqualTo("USER_TASK_OWNER_CHANGED");
    }
}
 
Example #2
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void createCustomTaskEventLog_withoutTimeStamp_addsDefault(TaskService taskService, HistoryService historyService,
        ProcessEngineConfiguration processEngineConfiguration) {
    task = taskService.createTaskBuilder().create();

    HistoricTaskLogEntryBuilder historicTaskLogEntryBuilder = historyService.createHistoricTaskLogEntryBuilder(task);
    historicTaskLogEntryBuilder.userId("testUser");
    historicTaskLogEntryBuilder.type("customType");
    historicTaskLogEntryBuilder.data("testData");
    historicTaskLogEntryBuilder.create();

    if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
        List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();

        assertThat(logEntries).hasSize(2);
        HistoricTaskLogEntry historicTaskLogEntry = logEntries.get(1);
        assertThat(historicTaskLogEntry.getLogNumber()).isNotNull();
        assertThat(historicTaskLogEntry.getTimeStamp()).isNotNull();
    }
}
 
Example #3
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void queryForTaskLogEntriesByTasKId(TaskService taskService, HistoryService historyService,
        ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) {

    task = taskService.createTaskBuilder().
            assignee("testAssignee").
            create();
    Task anotherTask = taskService.createTaskBuilder().create();

    try {
        if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
            List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
            assertThat(logEntries).hasSize(1);
            assertThat(logEntries.get(0)).extracting(HistoricTaskLogEntry::getTaskId).isEqualTo(task.getId());

            assertThat(historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).count()).isEqualTo(1l);
        }

    } finally {
        deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, anotherTask.getId());
    }
}
 
Example #4
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void createCustomTaskEventLog_taskIdIsEnoughToCreateTaskLogEntry(TaskService taskService, HistoryService historyService,
        ProcessEngineConfiguration processEngineConfiguration) {
    task = taskService.createTaskBuilder().create();

    HistoricTaskLogEntryBuilder historicTaskLogEntryBuilder = historyService.createHistoricTaskLogEntryBuilder(task);
    historicTaskLogEntryBuilder.create();

    if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
        List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();

        assertThat(logEntries).hasSize(2);
        HistoricTaskLogEntry historicTaskLogEntry = logEntries.get(1);
        assertThat(historicTaskLogEntry.getLogNumber()).isNotNull();
        assertThat(historicTaskLogEntry.getUserId()).isNull();
        assertThat(historicTaskLogEntry.getTaskId()).isEqualTo(task.getId());
        assertThat(historicTaskLogEntry.getType()).isNull();
        assertThat(historicTaskLogEntry.getTimeStamp()).isNotNull();
        assertThat(historicTaskLogEntry.getData()).isNull();
    }
}
 
Example #5
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void saveTask(TaskService taskService, HistoryService historyService, ProcessEngineConfiguration configuration) {
    task = taskService.createTaskBuilder().
            create();

    task.setName("newTaskName");
    task.setAssignee("newAssignee");
    task.setOwner("newOwner");
    task.setPriority(Integer.MAX_VALUE);
    task.setDueDate(new Date());
    taskService.saveTask(task);

    if (HistoryTestHelper.isHistoricTaskLoggingEnabled(configuration)) {
        List<HistoricTaskLogEntry> taskLogEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
        assertThat(taskLogEntries).as("The only event is user task created").hasSize(1);
    }
}
 
Example #6
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void changeDueDate(TaskService taskService, HistoryService historyService, ManagementService managementService,
        ProcessEngineConfiguration processEngineConfiguration) {
    task = taskService.createTaskBuilder().create();

    taskService.setDueDate(task.getId(), new Date());

    if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
        List<HistoricTaskLogEntry> taskLogEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
        assertThat(taskLogEntries).hasSize(2);

        taskLogEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_DUEDATE_CHANGED").list();
        assertThat(taskLogEntries).hasSize(1);
        assertThat(taskLogEntries.get(0).getData()).contains("\"newDueDate\"", "\"previousDueDate\":null}");
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getTimeStamp).isNotNull();
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getTaskId).isEqualTo(task.getId());
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getUserId).isNull();
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getType).isEqualTo("USER_TASK_DUEDATE_CHANGED");
    }
}
 
Example #7
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void deleteTaskWithLogEntries(TaskService taskService, ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration,
        String taskId) {
    taskService.deleteTask(taskId, true);
    managementService.executeCommand(new Command<Void>() {

        @Override
        public Void execute(CommandContext commandContext) {
            HistoricTaskLogEntryEntityManager historicTaskLogEntryEntityManager = CommandContextUtil.getTaskServiceConfiguration(commandContext)
                    .getHistoricTaskLogEntryEntityManager();
            List<HistoricTaskLogEntry> taskLogEntries = historicTaskLogEntryEntityManager
                    .findHistoricTaskLogEntriesByQueryCriteria(new HistoricTaskLogEntryQueryImpl(processEngineConfiguration.getCommandExecutor()));
            for (HistoricTaskLogEntry historicTaskLogEntry : taskLogEntries) {
                historicTaskLogEntryEntityManager.deleteHistoricTaskLogEntry(historicTaskLogEntry.getLogNumber());
            }

            HistoryJobService historyJobService = CommandContextUtil.getHistoryJobService(commandContext);
            List<HistoryJob> jobs = historyJobService.findHistoryJobsByQueryCriteria(new HistoryJobQueryImpl(commandContext));
            for (HistoryJob historyJob : jobs) {
                historyJobService.deleteHistoryJob((HistoryJobEntity) historyJob);
            }

            return null;
        }
    });
}
 
Example #8
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void assertThatAuthenticatedUserIsSet(TaskService taskService, HistoryService historyService,
        Consumer<String> functionToAssert, ProcessEngineConfiguration processEngineConfiguration) {

    String previousUserId = Authentication.getAuthenticatedUserId();
    task = taskService.createTaskBuilder().
            assignee("testAssignee").
            create();
    Authentication.setAuthenticatedUserId("testUser");

    try {
        functionToAssert.accept(task.getId());

        if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
            List<HistoricTaskLogEntry> taskLogsByTaskInstanceId = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
            assertThat(taskLogsByTaskInstanceId).hasSize(2);

            taskLogsByTaskInstanceId = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).userId("testUser").list();
            assertThat(taskLogsByTaskInstanceId).hasSize(1);
        }

    } finally {
        Authentication.setAuthenticatedUserId(previousUserId);
    }
}
 
Example #9
Source File: ProcessWithFormTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void completeTaskWithoutValidationOnModelLevel(RuntimeService runtimeService,
    TaskService taskService, RepositoryService repositoryService) {

    Deployment deployment = repositoryService.createDeployment().
        addString("oneTaskWithFormKeySideEffectProcess.bpmn20.xml",
            ONE_TASK_PROCESS.
                replace("START_EVENT_VALIDATION", "false").
                replace("USER_TASK_VALIDATION", "false")
        ).
        deploy();
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
    ProcessInstance processInstance = runtimeService.startProcessInstanceWithForm(processDefinition.getId(),"__COMPLETE", Collections.emptyMap(),
        "oneTaskWithFormSideEffectProcess");
    assertThat(SideEffectExecutionListener.getSideEffect()).isEqualTo(1);
    SideEffectExecutionListener.reset();

    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

    FormRepositoryService formRepositoryService = FormEngines.getDefaultFormEngine().getFormRepositoryService();
    FormDefinition formDefinition = formRepositoryService.createFormDefinitionQuery().formDefinitionKey("form1").singleResult();

    taskService.completeTaskWithForm(task.getId(), formDefinition.getId(), "__COMPLETE", Collections.singletonMap("initiator", "someInitiator"));

    assertThat(SideEffectExecutionListener.getSideEffect()).isEqualTo(1);
}
 
Example #10
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void changePriority(TaskService taskService, HistoryService historyService, ProcessEngineConfiguration processEngineConfiguration) {
    task = taskService.createTaskBuilder().create();
    taskService.setPriority(task.getId(), Integer.MAX_VALUE);

    if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
        List<HistoricTaskLogEntry> taskLogEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
        assertThat(taskLogEntries).hasSize(2);

        taskLogEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_PRIORITY_CHANGED").list();
        assertThat(taskLogEntries).hasSize(1);
        assertThat(taskLogEntries.get(0).getData()).
                contains("\"newPriority\":2147483647", "\"previousPriority\":50}");
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getTimeStamp).isNotNull();
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getTaskId).isEqualTo(task.getId());
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getUserId).isNull();
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getType).isEqualTo("USER_TASK_PRIORITY_CHANGED");
    }
}
 
Example #11
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void unclaimTaskEvent(TaskService taskService, HistoryService historyService, ProcessEngineConfiguration processEngineConfiguration) {
    task = taskService.createTaskBuilder().
            assignee("initialAssignee").
            create();

    taskService.unclaim(task.getId());

    if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
        List<HistoricTaskLogEntry> taskLogEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
        assertThat(taskLogEntries).hasSize(2);

        taskLogEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_ASSIGNEE_CHANGED").list();
        assertThat(taskLogEntries).hasSize(1);
        assertThat(taskLogEntries.get(0).getData()).
                contains("\"newAssigneeId\":null", "\"previousAssigneeId\":\"initialAssignee\"");
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getTimeStamp).isNotNull();
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getTaskId).isEqualTo(task.getId());
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getUserId).isNull();
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getType).isEqualTo("USER_TASK_ASSIGNEE_CHANGED");
    }
}
 
Example #12
Source File: SimpleSimulationRunTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
private void recordEvents() {
    Clock clock = new DefaultClockImpl();
    clock.setCurrentTime(new Date(0));
    ProcessEngineConfigurationImpl config = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault();
    config.setClock(clock);

    ProcessEngine processEngine = (new RecordableProcessEngineFactory(config, listener))
            .getObject();

    processEngine.getRepositoryService().createDeployment().addClasspathResource(USERTASK_PROCESS).deploy();
    EventRecorderTestUtils.increaseTime(clock);

    TaskService taskService = processEngine.getTaskService();

    Map<String, Object> variables = new HashMap<>();
    variables.put(TEST_VARIABLE, TEST_VALUE);
    processEngine.getRuntimeService().startProcessInstanceByKey("oneTaskProcess", "oneTaskProcessBusinessKey", variables);
    EventRecorderTestUtils.increaseTime(clock);
    Task task = taskService.createTaskQuery().taskDefinitionKey("userTask").singleResult();
    taskService.complete(task.getId());
    checkStatus(processEngine.getHistoryService());
    EventRecorderTestUtils.closeProcessEngine(processEngine, listener);
    ProcessEngines.destroy();
}
 
Example #13
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void deleteTaskEventLogEntry(TaskService taskService, HistoryService historyService, ManagementService managementService,
        ProcessEngineConfiguration processEngineConfiguration) {
    task = taskService.createTaskBuilder().
            assignee("testAssignee").
            create();

    if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
        List<HistoricTaskLogEntry> taskLogsByTaskInstanceId = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
        assertThat(taskLogsByTaskInstanceId).hasSize(1);

        historyService.deleteHistoricTaskLogEntry(taskLogsByTaskInstanceId.get(0).getLogNumber());

        HistoryTestHelper.waitForJobExecutorToProcessAllHistoryJobs(processEngineConfiguration, managementService, 5000, 200);
        taskLogsByTaskInstanceId = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
        assertThat(taskLogsByTaskInstanceId).isEmpty();
    }
}
 
Example #14
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void createTaskEventAsAuthenticatedUser(TaskService taskService, HistoryService historyService, ManagementService managementService,
        ProcessEngineConfiguration processEngineConfiguration) {
    String previousUserId = Authentication.getAuthenticatedUserId();
    Authentication.setAuthenticatedUserId("testUser");
    try {
        task = taskService.createTaskBuilder().
                assignee("testAssignee").
                create();

        if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
            List<HistoricTaskLogEntry> taskLogsByTaskInstanceId = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
            assertThat(taskLogsByTaskInstanceId).hasSize(1);

            assertThat(taskLogsByTaskInstanceId.get(0)).
                    extracting(HistoricTaskLogEntry::getUserId)
                    .isEqualTo("testUser");
        }

    } finally {
        Authentication.setAuthenticatedUserId(previousUserId);
    }
}
 
Example #15
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void claimTaskEvent(TaskService taskService, HistoryService historyService, ManagementService managementService,
        ProcessEngineConfiguration processEngineConfiguration) {
    task = taskService.createTaskBuilder().create();

    taskService.claim(task.getId(), "testUser");

    if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
        List<HistoricTaskLogEntry> taskLogEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
        assertThat(taskLogEntries).hasSize(2);

        taskLogEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_ASSIGNEE_CHANGED").list();
        assertThat(taskLogEntries).hasSize(1);
        assertThat(taskLogEntries.get(0).getData()).contains("\"newAssigneeId\":\"testUser\"", "\"previousAssigneeId\":null");
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getTimeStamp).isNotNull();
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getTaskId).isEqualTo(task.getId());
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getUserId).isNull();
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getType).isEqualTo("USER_TASK_ASSIGNEE_CHANGED");
    }
}
 
Example #16
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void taskAssigneeEvent(TaskService taskService, HistoryService historyService, ProcessEngineConfiguration processEngineConfiguration) {
    task = taskService.createTaskBuilder().
            assignee("initialAssignee").
            create();

    taskService.setAssignee(task.getId(), "newAssignee");

    if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
        List<HistoricTaskLogEntry> taskLogEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
        assertThat(taskLogEntries).hasSize(2);

        taskLogEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_ASSIGNEE_CHANGED").list();
        assertThat(taskLogEntries).hasSize(1);
        assertThat(taskLogEntries.get(0).getData()).contains("\"newAssigneeId\":\"newAssignee\"", "\"previousAssigneeId\":\"initialAssignee\"");
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getTimeStamp).isNotNull();
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getTaskId).isEqualTo(task.getId());
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getUserId).isNull();
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getType).isEqualTo("USER_TASK_ASSIGNEE_CHANGED");
    }
}
 
Example #17
Source File: ProcessWithFormTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void completeTaskWithValidationOnMissingModelLevel(ProcessEngineConfiguration processEngineConfiguration, RuntimeService runtimeService,
    TaskService taskService, RepositoryService repositoryService) {

    repositoryService.createDeployment().
        addString("oneTaskWithFormKeySideEffectProcess.bpmn20.xml",
            ONE_TASK_PROCESS.
                replace("flowable:formFieldValidation=\"START_EVENT_VALIDATION\"", "").
                replace("flowable:formFieldValidation=\"USER_TASK_VALIDATION\"", "")
        ).
        deploy();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(
        "oneTaskWithFormSideEffectProcess",
        Collections.emptyMap()
    );
    SideEffectExecutionListener.reset();

    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

    FormRepositoryService formRepositoryService = FormEngines.getDefaultFormEngine().getFormRepositoryService();
    FormDefinition formDefinition = formRepositoryService.createFormDefinitionQuery().formDefinitionKey("form1").singleResult();

    assertThatThrownBy(() -> taskService.completeTaskWithForm(task.getId(), formDefinition.getId(), "__COMPLETE", Collections.singletonMap("initiator", "someInitiator")))
            .isInstanceOf(RuntimeException.class)
            .hasMessage("validation failed");

    assertThat(SideEffectExecutionListener.getSideEffect()).isZero();
}
 
Example #18
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void queryForTaskLogEntriesByProcessInstanceId(TaskService taskService, HistoryService historyService,
        ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) {

    assertThatTaskLogIsFetched(taskService, historyService.createHistoricTaskLogEntryBuilder().processInstanceId("testProcess"),
            historyService.createHistoricTaskLogEntryQuery().processInstanceId("testProcess"), managementService, processEngineConfiguration);
}
 
Example #19
Source File: FlowableJupiterTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
void extensionUsageExample(ProcessEngine processEngine) {
    RuntimeService runtimeService = processEngine.getRuntimeService();
    runtimeService.startProcessInstanceByKey("extensionUsage");

    TaskService taskService = processEngine.getTaskService();
    org.flowable.task.api.Task task = taskService.createTaskQuery().singleResult();
    assertThat(task.getName()).isEqualTo("My Task");

    taskService.complete(task.getId());
    assertThat(runtimeService.createProcessInstanceQuery().count()).isZero();
    assertThat(processEngine.getName()).as("process engine  name").isEqualTo(ProcessEngines.NAME_DEFAULT);
}
 
Example #20
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void queryForTaskLogOrderBy(TaskService taskService, HistoryService historyService, ManagementService managementService,
        ProcessEngineConfiguration processEngineConfiguration) {
    HistoricTaskLogEntryBuilder historicTaskLogEntryBuilder = historyService.createHistoricTaskLogEntryBuilder();
    historicTaskLogEntryBuilder.taskId("1").timeStamp(getInsertDate()).create();
    historicTaskLogEntryBuilder.taskId("2").timeStamp(getCompareAfterDate()).create();
    historicTaskLogEntryBuilder.taskId("3").timeStamp(getCompareBeforeDate()).create();

    try {

        if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
            List<HistoricTaskLogEntry> taskLogEntries = historyService.createHistoricTaskLogEntryQuery().list();
            assertThat(taskLogEntries).extracting(taskLogEntry -> taskLogEntry.getTaskId()).containsExactly("1", "2", "3");

            taskLogEntries = historyService.createHistoricTaskLogEntryQuery().orderByLogNumber().desc().list();
            assertThat(taskLogEntries).extracting(taskLogEntry -> taskLogEntry.getTaskId()).containsExactly("3", "2", "1");

            taskLogEntries = historyService.createHistoricTaskLogEntryQuery().orderByTimeStamp().desc().list();
            assertThat(taskLogEntries).extracting(taskLogEntry -> taskLogEntry.getTaskId()).containsExactly("2", "1", "3");
        }

    } finally {
        deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, "1");
        deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, "2");
        deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, "3");
    }
}
 
Example #21
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void queryForTaskLogEntriesByTenantId(TaskService taskService, HistoryService historyService,
        ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) {

    assertThatTaskLogIsFetched(taskService, historyService.createHistoricTaskLogEntryBuilder().timeStamp(getInsertDate()),
            historyService.createHistoricTaskLogEntryQuery().from(getCompareBeforeDate()).to(getCompareAfterDate()), managementService,
            processEngineConfiguration);
}
 
Example #22
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void queryForTaskLogEntriesByToTimeStamp(TaskService taskService, HistoryService historyService, ManagementService managementService,
        ProcessEngineConfiguration processEngineConfiguration) {
    
    HistoricTaskLogEntryBuilder historicTaskLogEntryBuilder = historyService.createHistoricTaskLogEntryBuilder().timeStamp(getInsertDate());
    HistoricTaskLogEntryQuery historicTaskLogEntryQuery = historyService.createHistoricTaskLogEntryQuery().to(getCompareAfterDate());

    task = taskService.createTaskBuilder().
            assignee("testAssignee").
            create();
    Task anotherTask = taskService.createTaskBuilder().create();
    historicTaskLogEntryBuilder.taskId(task.getId()).create();
    historicTaskLogEntryBuilder.taskId(task.getId()).create();
    historicTaskLogEntryBuilder.taskId(task.getId()).create();

    try {
        if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
            List<HistoricTaskLogEntry> logEntries = historicTaskLogEntryQuery.list();
            assertThat(logEntries).hasSize(3);
            assertThat(logEntries).extracting(HistoricTaskLogEntry::getTaskId)
                    .containsExactly(task.getId(), task.getId(), task.getId());

            assertThat(historicTaskLogEntryQuery.count()).isEqualTo(3);

            List<HistoricTaskLogEntry> pagedLogEntries = historicTaskLogEntryQuery.listPage(1, 1);
            assertThat(pagedLogEntries).hasSize(1);
            assertThat(pagedLogEntries.get(0)).isEqualToComparingFieldByField(logEntries.get(1));
        }

    } finally {
        deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, anotherTask.getId());
        taskService.deleteTask(anotherTask.getId(), true);
    }
}
 
Example #23
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void queryForTaskLogEntriesByFromTimeStamp(TaskService taskService, HistoryService historyService,
        ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) {

    assertThatAllTaskLogIsFetched(taskService, historyService.createHistoricTaskLogEntryBuilder().timeStamp(getInsertDate()),
            historyService.createHistoricTaskLogEntryQuery().from(getCompareBeforeDate()), managementService, processEngineConfiguration);
}
 
Example #24
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void queryForTaskLogEntriesByScopeId(TaskService taskService, HistoryService historyService,
        ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) {

    assertThatTaskLogIsFetched(taskService, historyService.createHistoricTaskLogEntryBuilder().scopeId("testScopeId"),
            historyService.createHistoricTaskLogEntryQuery().scopeId("testScopeId"), managementService, processEngineConfiguration);
}
 
Example #25
Source File: ProcessWithFormTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void completeTaskWithValidationOnModelLevelStringExpression(ProcessEngineConfiguration processEngineConfiguration, RuntimeService runtimeService,
    TaskService taskService, RepositoryService repositoryService) {

    repositoryService.createDeployment().
        addString("oneTaskWithFormKeySideEffectProcess.bpmn20.xml",
            ONE_TASK_PROCESS.
                replace("START_EVENT_VALIDATION", "true").
                replace("USER_TASK_VALIDATION", "${true}")
        ).
        deploy();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(
        "oneTaskWithFormSideEffectProcess",
        Collections.emptyMap()
    );
    SideEffectExecutionListener.reset();

    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

    FormRepositoryService formRepositoryService = FormEngines.getDefaultFormEngine().getFormRepositoryService();
    FormDefinition formDefinition = formRepositoryService.createFormDefinitionQuery().formDefinitionKey("form1").singleResult();

    assertThatThrownBy(() -> taskService.completeTaskWithForm(task.getId(), formDefinition.getId(), "__COMPLETE", Collections.singletonMap("initiator", "someInitiator")))
            .isInstanceOf(RuntimeException.class)
            .hasMessage("validation failed");

    assertThat(SideEffectExecutionListener.getSideEffect()).isZero();
}
 
Example #26
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void logAddParticipantUser(RuntimeService runtimeService, TaskService taskService, HistoryService historyService,
        ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) {

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    try {
        assertThat(processInstance).isNotNull();
        assertThat(task).isNotNull();

        taskService.addUserIdentityLink(task.getId(), "newCandidateUser", IdentityLinkType.PARTICIPANT);

        if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
            List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
            assertThat(logEntries).hasSize(2);

            logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId())
                    .type("USER_TASK_IDENTITY_LINK_ADDED")
                    .list();
            assertThat(logEntries).hasSize(1);
            assertThat(logEntries.get(0).getData()).contains(
                    "\"type\":\"participant\"",
                    "\"userId\":\"newCandidateUser\""
            );
        }

    } finally {
        taskService.complete(task.getId());
        deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, task.getId());
    }
}
 
Example #27
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void logAddCandidateUser(RuntimeService runtimeService, TaskService taskService, HistoryService historyService,
        ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) {

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    try {
        assertThat(processInstance).isNotNull();
        assertThat(task).isNotNull();

        taskService.addCandidateUser(task.getId(), "newCandidateUser");

        if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
            List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
            assertThat(logEntries).hasSize(2);

            logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId())
                    .type("USER_TASK_IDENTITY_LINK_ADDED")
                    .list();
            assertThat(logEntries).hasSize(1);
            assertThat(logEntries.get(0).getData()).contains(
                    "\"type\":\"candidate\"",
                    "\"userId\":\"newCandidateUser\""
            );
        }

    } finally {
        taskService.complete(task.getId());
        deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, task.getId());
    }
}
 
Example #28
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void logProcessTaskEvents(RuntimeService runtimeService, TaskService taskService, HistoryService historyService,
        ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) {

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    assertThat(processInstance).isNotNull();

    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(task).isNotNull();
    try {
        taskService.setAssignee(task.getId(), "newAssignee");
        taskService.setOwner(task.getId(), "newOwner");
        taskService.complete(task.getId());

        if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
            List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
            assertThat(logEntries).hasSize(4);

            HistoricTaskLogEntry logEntry = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_CREATED").singleResult();
            assertThat(logEntry).isNotNull();
            assertThat(logEntry.getProcessDefinitionId()).isEqualTo(processInstance.getProcessDefinitionId());
            assertThat(logEntry.getExecutionId()).isEqualTo(task.getExecutionId());
            assertThat(logEntry.getProcessInstanceId()).isEqualTo(processInstance.getId());

            assertThat(historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_ASSIGNEE_CHANGED").count()).isEqualTo(1);
            assertThat(historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_OWNER_CHANGED").count()).isEqualTo(1);
            assertThat(historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_COMPLETED").count()).isEqualTo(1);
        }

    } finally {
        deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, task.getId());
    }
}
 
Example #29
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void logAddGroup(RuntimeService runtimeService, TaskService taskService, HistoryService historyService,
        ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) {

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    assertThat(processInstance).isNotNull();
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(task).isNotNull();
    try {

        taskService.addGroupIdentityLink(task.getId(), "newCandidateGroup", IdentityLinkType.PARTICIPANT);

        if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
            List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
            assertThat(logEntries).hasSize(2);

            logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId())
                    .type("USER_TASK_IDENTITY_LINK_ADDED")
                    .list();
            assertThat(logEntries).hasSize(1);
            assertThat(logEntries.get(0).getData()).contains(
                    "\"type\":\"participant\"",
                    "\"groupId\":\"newCandidateGroup\""
            );
        }

    } finally {
        taskService.complete(task.getId());
        deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, task.getId());
    }
}
 
Example #30
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void createCustomTaskEventLog(TaskService taskService, HistoryService historyService, ManagementService managementService,
        ProcessEngineConfiguration processEngineConfiguration) {
    task = taskService.createTaskBuilder().create();

    Date todayDate = new Date();
    HistoricTaskLogEntryBuilder historicTaskLogEntryBuilder = historyService.createHistoricTaskLogEntryBuilder(task);
    historicTaskLogEntryBuilder.timeStamp(todayDate);
    historicTaskLogEntryBuilder.userId("testUser");
    historicTaskLogEntryBuilder.type("customType");
    historicTaskLogEntryBuilder.data("testData");
    historicTaskLogEntryBuilder.create();

    if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
        List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
        assertThat(logEntries).hasSize(2);

        logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("customType").list();
        assertThat(logEntries).hasSize(1);
        HistoricTaskLogEntry historicTaskLogEntry = logEntries.get(0);
        assertThat(historicTaskLogEntry.getLogNumber()).isNotNull();
        assertThat(historicTaskLogEntry.getUserId()).isEqualTo("testUser");
        assertThat(historicTaskLogEntry.getTaskId()).isEqualTo(task.getId());
        assertThat(historicTaskLogEntry.getType()).isEqualTo("customType");
        assertThat(simpleDateFormat.format(historicTaskLogEntry.getTimeStamp())).isEqualTo(simpleDateFormat.format(todayDate));
        assertThat(historicTaskLogEntry.getData()).isEqualTo("testData");
        historyService.deleteHistoricTaskLogEntry(historicTaskLogEntry.getLogNumber());
    }
}