org.flowable.engine.history.HistoricActivityInstance Java Examples

The following examples show how to use org.flowable.engine.history.HistoricActivityInstance. 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: AsyncHistoryTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testTaskAssigneeChangeToNull() {
    Task task = startOneTaskprocess();

    waitForHistoryJobExecutorToProcessAllJobs(7000L, 100L);
    HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery()
            .activityId("theTask").singleResult();
    assertThat(historicActivityInstance.getAssignee()).isEqualTo("kermit");

    task = taskService.createTaskQuery().singleResult();
    taskService.setAssignee(task.getId(), null);
    waitForHistoryJobExecutorToProcessAllJobs(7000L, 100L);
    historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("theTask").singleResult();
    assertThat(historicActivityInstance.getAssignee()).isNull();

    finishOneTaskProcess(task);
}
 
Example #2
Source File: RestResponseFactory.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public HistoricActivityInstanceResponse createHistoricActivityInstanceResponse(HistoricActivityInstance activityInstance, RestUrlBuilder urlBuilder) {
    HistoricActivityInstanceResponse result = new HistoricActivityInstanceResponse();
    result.setActivityId(activityInstance.getActivityId());
    result.setActivityName(activityInstance.getActivityName());
    result.setActivityType(activityInstance.getActivityType());
    result.setAssignee(activityInstance.getAssignee());
    result.setCalledProcessInstanceId(activityInstance.getCalledProcessInstanceId());
    result.setDurationInMillis(activityInstance.getDurationInMillis());
    result.setEndTime(activityInstance.getEndTime());
    result.setExecutionId(activityInstance.getExecutionId());
    result.setId(activityInstance.getId());
    result.setProcessDefinitionId(activityInstance.getProcessDefinitionId());
    result.setProcessDefinitionUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_DEFINITION, activityInstance.getProcessDefinitionId()));
    result.setProcessInstanceId(activityInstance.getProcessInstanceId());
    result.setProcessInstanceUrl(urlBuilder.buildUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE, activityInstance.getId()));
    result.setStartTime(activityInstance.getStartTime());
    result.setTaskId(activityInstance.getTaskId());
    result.setTenantId(activityInstance.getTenantId());
    return result;
}
 
Example #3
Source File: MultiInstanceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/bpmn/multiinstance/MultiInstanceTest.testParallelSubProcess.bpmn20.xml" })
public void testParallelSubProcessHistory() {
    runtimeService.startProcessInstanceByKey("miParallelSubprocess");
    for (org.flowable.task.api.Task task : taskService.createTaskQuery().list()) {
        taskService.complete(task.getId());
    }

    // Validate history
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityId("miSubProcess").list();
        assertEquals(2, historicActivityInstances.size());
        for (HistoricActivityInstance hai : historicActivityInstances) {
            assertNotNull(hai.getStartTime());
            assertNotNull(hai.getEndTime());
        }
    }
}
 
Example #4
Source File: HistoricActivityInstanceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
public void testHistoricActivityInstanceNoop() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("noopProcess");
    
    waitForHistoryJobExecutorToProcessAllJobs(7000, 100);

    HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("noop").singleResult();

    assertThat(historicActivityInstance.getActivityId()).isEqualTo("noop");
    assertThat(historicActivityInstance.getActivityType()).isEqualTo("serviceTask");
    assertThat(historicActivityInstance.getProcessDefinitionId()).isNotNull();
    assertThat(historicActivityInstance.getProcessInstanceId()).isEqualTo(processInstance.getId());
    assertThat(historicActivityInstance.getStartTime()).isNotNull();
    assertThat(historicActivityInstance.getEndTime()).isNotNull();
    assertThat(historicActivityInstance.getDurationInMillis()).isGreaterThanOrEqualTo(0);
}
 
Example #5
Source File: MultiInstanceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/bpmn/multiinstance/MultiInstanceTest.testParallelScriptTasks.bpmn20.xml" })
public void testParallelScriptTasksHistory() {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("sum", 0);
    vars.put("nrOfLoops", 4);
    runtimeService.startProcessInstanceByKey("miParallelScriptTask", vars);

    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityType("scriptTask").list();
        assertEquals(4, historicActivityInstances.size());
        for (HistoricActivityInstance hai : historicActivityInstances) {
            assertNotNull(hai.getStartTime());
            assertNotNull(hai.getStartTime());
        }
    }
}
 
Example #6
Source File: MultiInstanceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/bpmn/multiinstance/MultiInstanceTest.testSequentialScriptTasks.bpmn20.xml" })
public void testSequentialScriptTasksHistory() {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("sum", 0);
    vars.put("nrOfLoops", 7);
    runtimeService.startProcessInstanceByKey("miSequentialScriptTask", vars);

    // Validate history
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        List<HistoricActivityInstance> historicInstances = historyService.createHistoricActivityInstanceQuery().activityType("scriptTask").orderByActivityId().asc().list();
        assertEquals(7, historicInstances.size());
        for (int i = 0; i < 7; i++) {
            HistoricActivityInstance hai = historicInstances.get(i);
            assertEquals("scriptTask", hai.getActivityType());
            assertNotNull(hai.getStartTime());
            assertNotNull(hai.getEndTime());
        }
    }
}
 
Example #7
Source File: HistoricActivityInstanceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Test to validate fix for ACT-1549: endTime of joining parallel gateway is not set
 */
@Deployment
public void testParallelJoinEndTime() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("forkJoin");

    List<org.flowable.task.api.Task> tasksToComplete = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
    assertEquals(2, tasksToComplete.size());

    // Complete both tasks, second task-complete should end the fork-gateway and set time
    taskService.complete(tasksToComplete.get(0).getId());
    taskService.complete(tasksToComplete.get(1).getId());

    List<HistoricActivityInstance> historicActivityInstance = historyService
            .createHistoricActivityInstanceQuery()
            .activityId("join")
            .processInstanceId(processInstance.getId())
            .list();

    assertNotNull(historicActivityInstance);

    // History contains 2 entries for parallel join (one for each path arriving in the join), should contain end-time
    assertEquals(2, historicActivityInstance.size());
    assertNotNull(historicActivityInstance.get(0).getEndTime());
    assertNotNull(historicActivityInstance.get(1).getEndTime());
}
 
Example #8
Source File: MultiInstanceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/bpmn/multiinstance/MultiInstanceTest.testParallelSubProcess.bpmn20.xml" })
public void testParallelSubProcessHistory() {
    runtimeService.startProcessInstanceByKey("miParallelSubprocess");
    for (org.flowable.task.api.Task task : taskService.createTaskQuery().list()) {
        taskService.complete(task.getId());
    }

    // Validate history
    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processEngineConfiguration)) {
        List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityId("miSubProcess").list();
        assertEquals(2, historicActivityInstances.size());
        for (HistoricActivityInstance hai : historicActivityInstances) {
            assertNotNull(hai.getStartTime());
            assertNotNull(hai.getEndTime());
        }
    }
}
 
Example #9
Source File: MultiInstanceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/bpmn/multiinstance/MultiInstanceTest.testParallelScriptTasks.bpmn20.xml" })
public void testParallelScriptTasksHistory() {
    Map<String, Object> vars = new HashMap<>();
    vars.put("sum", 0);
    vars.put("nrOfLoops", 4);
    runtimeService.startProcessInstanceByKey("miParallelScriptTask", vars);

    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processEngineConfiguration)) {
        List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityType("scriptTask").list();
        assertEquals(4, historicActivityInstances.size());
        for (HistoricActivityInstance hai : historicActivityInstances) {
            assertActivityInstancesAreSame(hai, runtimeService.createActivityInstanceQuery().activityInstanceId(hai.getId()).singleResult());
            assertNotNull(hai.getStartTime());
            assertNotNull(hai.getEndTime());
        }
    }
}
 
Example #10
Source File: BoundaryErrorEventTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
private void assertThatErrorHasBeenCaught(String procId) {
    // The service task will throw an error event,
    // which is caught on the service task boundary
    assertEquals("No tasks found in task list.", 1, taskService.createTaskQuery().count());
    org.flowable.task.api.Task task = taskService.createTaskQuery().singleResult();
    assertEquals("Escalated Task", task.getName());

    // Completing the task will end the process instance
    taskService.complete(task.getId());
    assertProcessEnded(procId);

    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
        List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().processInstanceId(procId).list();
        for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
            assertNotNull("Historic activity " + historicActivityInstance.getActivityName() + " has a null end time, while the process instance is finished",
                    historicActivityInstance.getEndTime());
        }
    }
}
 
Example #11
Source File: CompensateEventTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/bpmn/event/compensate/CompensateEventTest.testCompensationStepEndRecorded.bpmn20.xml" })
public void testCompensationStepEndTimeRecorded() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("compensationStepEndRecordedProcess");
    assertProcessEnded(processInstance.getId());
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());

    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processEngineConfiguration)) {
        final HistoricActivityInstanceQuery query = historyService.createHistoricActivityInstanceQuery().activityId("compensationScriptTask");
        assertEquals(1, query.count());
        final HistoricActivityInstance compensationScriptTask = query.singleResult();
        assertNotNull(compensationScriptTask);
        assertNotNull(compensationScriptTask.getEndTime());
        assertNotNull(compensationScriptTask.getDurationInMillis());
    }
}
 
Example #12
Source File: CompensateEventTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/bpmn/event/compensate/CompensateEventTest.testCompensationStepEndRecorded.bpmn20.xml" })
public void testCompensationStepEndTimeRecorded() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("compensationStepEndRecordedProcess");
    assertProcessEnded(processInstance.getId());
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());

    if (!processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        return;
    }
    final HistoricActivityInstanceQuery query = historyService.createHistoricActivityInstanceQuery().activityId("compensationScriptTask");
    assertEquals(1, query.count());
    final HistoricActivityInstance compensationScriptTask = query.singleResult();
    assertNotNull(compensationScriptTask);
    assertNotNull(compensationScriptTask.getEndTime());
    assertNotNull(compensationScriptTask.getDurationInMillis());
}
 
Example #13
Source File: AbstractFlowableTestCase.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void assertHistoricActivitiesDeleteReason(ProcessInstance processInstance, String expectedDeleteReason, String... activityIds) {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
        for (String activityId : activityIds) {
            List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery()
                    .activityId(activityId).processInstanceId(processInstance.getId()).list();
            assertTrue("Could not find historic activities", historicActivityInstances.size() > 0);
            for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
                assertNotNull(historicActivityInstance.getEndTime());
                if (expectedDeleteReason == null) {
                    assertNull(historicActivityInstance.getDeleteReason());
                } else {
                    assertTrue(historicActivityInstance.getDeleteReason().startsWith(expectedDeleteReason));
                }
            }
        }
    }
}
 
Example #14
Source File: HistoricActivityInstanceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Test to validate fix for ACT-1399: Boundary-event and event-based auditing
 */
@Deployment
public void testEventBasedGateway() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("catchSignal");
    Execution waitingExecution = runtimeService.createExecutionQuery()
            .signalEventSubscriptionName("alert")
            .singleResult();
    assertNotNull(waitingExecution);
    runtimeService.signalEventReceived("alert", waitingExecution.getId());

    assertEquals(0L, runtimeService.createProcessInstanceQuery()
            .processInstanceId(processInstance.getId()).count());

    HistoricActivityInstance historicActivityInstance = historyService
            .createHistoricActivityInstanceQuery()
            .activityId("eventBasedgateway")
            .processInstanceId(processInstance.getId())
            .singleResult();

    assertNotNull(historicActivityInstance);
}
 
Example #15
Source File: MultiInstanceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/bpmn/multiinstance/MultiInstanceTest.testSequentialScriptTasks.bpmn20.xml" })
public void testSequentialScriptTasksHistory() {
    Map<String, Object> vars = new HashMap<>();
    vars.put("sum", 0);
    vars.put("nrOfLoops", 7);
    runtimeService.startProcessInstanceByKey("miSequentialScriptTask", vars);

    // Validate history
    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processEngineConfiguration)) {
        List<HistoricActivityInstance> historicInstances = historyService.createHistoricActivityInstanceQuery().activityType("scriptTask").orderByActivityId().asc().list();
        assertEquals(7, historicInstances.size());
        for (int i = 0; i < 7; i++) {
            HistoricActivityInstance hai = historicInstances.get(i);
            assertActivityInstancesAreSame(hai, runtimeService.createActivityInstanceQuery().activityInstanceId(hai.getId()).singleResult());
            assertEquals("scriptTask", hai.getActivityType());
            assertNotNull(hai.getStartTime());
            assertNotNull(hai.getEndTime());
        }
    }
}
 
Example #16
Source File: FlowableUserRequestHandler.java    From syncope with Apache License 2.0 6 votes vote down vote up
protected UserRequestForm getForm(final HistoricTaskInstance task) {
    List<HistoricFormPropertyEntity> props = engine.getHistoryService().
            createHistoricDetailQuery().taskId(task.getId()).list().stream().
            filter(HistoricFormPropertyEntity.class::isInstance).
            map(HistoricFormPropertyEntity.class::cast).
            collect(Collectors.toList());

    UserRequestForm formTO = getHistoricFormTO(
            task.getProcessInstanceId(), task.getId(), task.getFormKey(), props);
    formTO.setCreateTime(task.getCreateTime());
    formTO.setDueDate(task.getDueDate());
    formTO.setExecutionId(task.getExecutionId());
    formTO.setFormKey(task.getFormKey());
    formTO.setAssignee(task.getAssignee());

    HistoricActivityInstance historicActivityInstance = engine.getHistoryService().
            createHistoricActivityInstanceQuery().
            executionId(task.getExecutionId()).activityType("userTask").activityName(task.getName()).singleResult();

    if (historicActivityInstance != null) {
        formTO.setCreateTime(historicActivityInstance.getStartTime());
        formTO.setDueDate(historicActivityInstance.getEndTime());
    }

    return formTO;
}
 
Example #17
Source File: HistoricActivityInstanceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(
    resources = {
        "org/flowable/engine/test/api/runtime/callActivity.bpmn20.xml",
        "org/flowable/engine/test/api/runtime/calledActivity.bpmn20.xml"
    }
)
public void callSubProcess() {
    ProcessInstance pi = this.runtimeService.startProcessInstanceByKey("callActivity");

    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processEngineConfiguration)) {
        HistoricActivityInstance callSubProcessActivityInstance = historyService.createHistoricActivityInstanceQuery().processInstanceId(pi.getId())
            .activityId("callSubProcess").singleResult();
        assertThat(callSubProcessActivityInstance.getCalledProcessInstanceId()).isEqualTo(
            runtimeService.createProcessInstanceQuery().superProcessInstanceId(pi.getId()).singleResult().getId());
    }
}
 
Example #18
Source File: HistoricActivityInstanceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testHistoricActivityInstanceNoop() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("noopProcess");

    HistoricActivityInstance historicActivityInstance = historyService
            .createHistoricActivityInstanceQuery()
            .activityId("noop")
            .singleResult();

    assertEquals("noop", historicActivityInstance.getActivityId());
    assertEquals("serviceTask", historicActivityInstance.getActivityType());
    assertNotNull(historicActivityInstance.getProcessDefinitionId());
    assertEquals(processInstance.getId(), historicActivityInstance.getProcessInstanceId());
    assertEquals(processInstance.getId(), historicActivityInstance.getExecutionId());
    assertNotNull(historicActivityInstance.getStartTime());
    assertNotNull(historicActivityInstance.getEndTime());
    assertTrue(historicActivityInstance.getDurationInMillis() >= 0);
}
 
Example #19
Source File: HistoricActivityInstanceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Test to validate fix for ACT-1399: Boundary-event and event-based auditing
 */
@Test
@Deployment
public void testEventBasedGateway() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("catchSignal");
    Execution waitingExecution = runtimeService.createExecutionQuery().signalEventSubscriptionName("alert").singleResult();
    assertThat(waitingExecution).isNotNull();
    runtimeService.signalEventReceived("alert", waitingExecution.getId());

    assertThat(runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).count()).isEqualTo(0L);
    
    waitForHistoryJobExecutorToProcessAllJobs(7000, 100);

    HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("eventBasedgateway").processInstanceId(processInstance.getId()).singleResult();

    assertThat(historicActivityInstance).isNotNull();
}
 
Example #20
Source File: HistoricDetailVariableUpdateHistoryJsonTransformer.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isApplicable(ObjectNode historicalData, CommandContext commandContext) {
    String activityId = getStringFromJson(historicalData, HistoryJsonConstants.ACTIVITY_ID);
    
    // Variables for a mi root execution (like nrOfInstances, nrOfCompletedInstance, etc.) are stored without a reference to the historical activity.
    Boolean isMiRootExecution = getBooleanFromJson(historicalData, HistoryJsonConstants.IS_MULTI_INSTANCE_ROOT_EXECUTION, false);
    
    if (!isMiRootExecution && StringUtils.isNotEmpty(activityId)) {
        HistoricActivityInstance activityInstance = findHistoricActivityInstance(commandContext, 
                getStringFromJson(historicalData, HistoryJsonConstants.SOURCE_EXECUTION_ID), activityId);
        if (activityInstance == null) {
            return false;
        }
    }
    return true;
}
 
Example #21
Source File: HistoricActivityInstanceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {
        "org/activiti/engine/test/history/calledProcess.bpmn20.xml",
        "org/activiti/engine/test/history/HistoricActivityInstanceTest.testCallSimpleSubProcess.bpmn20.xml"
})
public void testHistoricActivityInstanceCalledProcessId() {
    runtimeService.startProcessInstanceByKey("callSimpleSubProcess");

    HistoricActivityInstance historicActivityInstance = historyService
            .createHistoricActivityInstanceQuery()
            .activityId("callSubProcess")
            .singleResult();

    HistoricProcessInstance oldInstance = historyService.createHistoricProcessInstanceQuery().processDefinitionKey("calledProcess").singleResult();

    assertEquals(oldInstance.getId(), historicActivityInstance.getCalledProcessInstanceId());
}
 
Example #22
Source File: AsyncExclusiveJobsTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Test for https://activiti.atlassian.net/browse/ACT-4035.
 */
@Deployment
public void testExclusiveJobs() {

    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {

        // The process has two script tasks in parallel, both exclusive.
        // They should be executed with at least 6 seconds in between (as they both sleep for 6 seconds)
        runtimeService.startProcessInstanceByKey("testExclusiveJobs");
        waitForJobExecutorToProcessAllJobs(20000L, 500L);

        HistoricActivityInstance scriptTaskAInstance = historyService.createHistoricActivityInstanceQuery().activityId("scriptTaskA").singleResult();
        HistoricActivityInstance scriptTaskBInstance = historyService.createHistoricActivityInstanceQuery().activityId("scriptTaskB").singleResult();

        long endTimeA = scriptTaskAInstance.getEndTime().getTime();
        long endTimeB = scriptTaskBInstance.getEndTime().getTime();
        long endTimeDifference = 0;
        if (endTimeB > endTimeA) {
            endTimeDifference = endTimeB - endTimeA;
        } else {
            endTimeDifference = endTimeA - endTimeB;
        }
        assertTrue(endTimeDifference > 6000); // > 6000 -> jobs were executed in parallel
    }

}
 
Example #23
Source File: ParallelGatewayTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
public void testHistoricActivityInstanceEndTimes() {
    runtimeService.startProcessInstanceByKey("nestedForkJoin");
    
    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.AUDIT, processEngineConfiguration)) {
        List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().list();
        assertThat(historicActivityInstances).hasSize(41);
        for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
            assertThat(historicActivityInstance.getStartTime()).isNotNull();
            assertThat(historicActivityInstance.getEndTime()).isNotNull();
            if (historicActivityInstance.getActivityId().startsWith("flow")) {
                assertThat(historicActivityInstance.getEndTime()).isEqualTo(historicActivityInstance.getStartTime());
            }
        }
    }
}
 
Example #24
Source File: HistoricActivityInstanceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testHistoricActivityInstanceForEventsQuery() {
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("eventProcess");
    assertEquals(1, taskService.createTaskQuery().count());
    runtimeService.signalEventReceived("signal");
    assertProcessEnded(pi.getId());

    assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("noop").list().size());
    assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("userTask").list().size());
    assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("intermediate-event").list().size());
    assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("start").list().size());
    assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("end").list().size());

    // TODO: Discuss if boundary events will occur in the log!
    // assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("boundaryEvent").list().size());

    HistoricActivityInstance intermediateEvent = historyService.createHistoricActivityInstanceQuery().activityId("intermediate-event").singleResult();
    assertNotNull(intermediateEvent.getStartTime());
    assertNotNull(intermediateEvent.getEndTime());

    HistoricActivityInstance startEvent = historyService.createHistoricActivityInstanceQuery().activityId("start").singleResult();
    assertNotNull(startEvent.getStartTime());
    assertNotNull(startEvent.getEndTime());

    HistoricActivityInstance endEvent = historyService.createHistoricActivityInstanceQuery().activityId("end").singleResult();
    assertNotNull(endEvent.getStartTime());
    assertNotNull(endEvent.getEndTime());
}
 
Example #25
Source File: MultiInstanceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/bpmn/multiinstance/MultiInstanceTest.sequentialUserTasks.bpmn20.xml" })
public void testSequentialUserTasksHistory() {
    String procId = runtimeService.startProcessInstanceByKey("miSequentialUserTasks", CollectionUtil.singletonMap("nrOfLoops", 4)).getId();
    for (int i = 0; i < 4; i++) {
        taskService.complete(taskService.createTaskQuery().singleResult().getId());
    }
    assertProcessEnded(procId);

    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processEngineConfiguration)) {

        List<HistoricTaskInstance> historicTaskInstances = historyService.createHistoricTaskInstanceQuery().list();
        assertEquals(4, historicTaskInstances.size());
        for (HistoricTaskInstance ht : historicTaskInstances) {
            assertNotNull(ht.getAssignee());
            assertNotNull(ht.getStartTime());
            assertNotNull(ht.getEndTime());
        }

        List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityType("userTask").list();
        assertEquals(4, historicActivityInstances.size());
        for (HistoricActivityInstance hai : historicActivityInstances) {
            assertNotNull(hai.getActivityId());
            assertNotNull(hai.getActivityName());
            assertNotNull(hai.getStartTime());
            assertNotNull(hai.getEndTime());
            assertNotNull(hai.getAssignee());
        }

    }
}
 
Example #26
Source File: ExpressionServiceTaskTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void testSetServiceResultToProcessVariablesWithSkipExpression() {
    Map<String, Object> variables = new HashMap<>();
    variables.put("bean", new ValueBean("ok"));
    variables.put("_ACTIVITI_SKIP_EXPRESSION_ENABLED", true);
    variables.put("skip", false);
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("setServiceResultToProcessVariablesWithSkipExpression", variables);
    assertThat(runtimeService.getVariable(pi.getId(), "result")).isEqualTo("ok");

    Map<String, Object> variables2 = new HashMap<>();
    variables2.put("bean", new ValueBean("ok"));
    variables2.put("_ACTIVITI_SKIP_EXPRESSION_ENABLED", true);
    variables2.put("skip", true);
    ProcessInstance pi2 = runtimeService.startProcessInstanceByKey("setServiceResultToProcessVariablesWithSkipExpression", variables2);
    assertThat(runtimeService.getVariable(pi2.getId(), "result")).isNull();

    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.AUDIT, processEngineConfiguration)) {
        HistoricActivityInstance skipActivityInstance = historyService.createHistoricActivityInstanceQuery().processInstanceId(pi2.getId())
                .activityId("valueExpressionServiceWithResultVariableNameSet")
                .singleResult();
        assertActivityInstancesAreSame(skipActivityInstance,
                runtimeService.createActivityInstanceQuery().activityInstanceId(skipActivityInstance.getId()).singleResult());

        assertThat(skipActivityInstance).isNotNull();
    }

    Map<String, Object> variables3 = new HashMap<>();
    variables3.put("bean", new ValueBean("okBean"));
    variables3.put("_ACTIVITI_SKIP_EXPRESSION_ENABLED", false);
    ProcessInstance pi3 = runtimeService.startProcessInstanceByKey("setServiceResultToProcessVariablesWithSkipExpression", variables3);
    assertThat(runtimeService.getVariable(pi3.getId(), "result")).isEqualTo("okBean");
}
 
Example #27
Source File: FormPropertiesSubmittedHistoryJsonTransformer.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isApplicable(ObjectNode historicalData, CommandContext commandContext) {
    String activityId = getStringFromJson(historicalData, HistoryJsonConstants.ACTIVITY_ID);
    if (StringUtils.isNotEmpty(activityId)) {
        HistoricActivityInstance historicActivityInstance = findHistoricActivityInstance(commandContext,
                getStringFromJson(historicalData, HistoryJsonConstants.EXECUTION_ID), activityId);

        if (historicActivityInstance == null) {
            return false;
        }
    }
    return true;
}
 
Example #28
Source File: SubProcessInstanceStartHistoryJsonTransformer.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isApplicable(ObjectNode historicalData, CommandContext commandContext) {
    String activityId = getStringFromJson(historicalData, HistoryJsonConstants.ACTIVITY_ID);
    HistoricActivityInstance activityInstance = findHistoricActivityInstance(commandContext, 
            getStringFromJson(historicalData, HistoryJsonConstants.EXECUTION_ID), activityId);
        
    if (activityInstance == null) {
        return false;
    }
    
    return true;
}
 
Example #29
Source File: HistoricActivityInstanceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void testHistoricActivityInstanceReceive() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("receiveProcess");
    
    waitForHistoryJobExecutorToProcessAllJobs(7000, 100);

    HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("receive").singleResult();
    assertActivityInstancesAreSame(historicActivityInstance, runtimeService.createActivityInstanceQuery().activityInstanceId(historicActivityInstance.getId()).singleResult());

    assertThat(historicActivityInstance.getActivityId()).isEqualTo("receive");
    assertThat(historicActivityInstance.getActivityType()).isEqualTo("receiveTask");
    assertThat(historicActivityInstance.getEndTime()).isNull();
    assertThat(historicActivityInstance.getDurationInMillis()).isNull();
    assertThat(historicActivityInstance.getProcessDefinitionId()).isNotNull();
    assertThat(historicActivityInstance.getProcessInstanceId()).isEqualTo(processInstance.getId());
    assertThat(historicActivityInstance.getStartTime()).isNotNull();

    Execution execution = runtimeService.createExecutionQuery().onlyChildExecutions().processInstanceId(processInstance.getId()).singleResult();
    runtimeService.trigger(execution.getId());
    
    waitForHistoryJobExecutorToProcessAllJobs(7000, 100);

    historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("receive").singleResult();

    assertThat(historicActivityInstance.getActivityId()).isEqualTo("receive");
    assertThat(historicActivityInstance.getActivityType()).isEqualTo("receiveTask");
    assertThat(historicActivityInstance.getEndTime()).isNotNull();
    assertThat(historicActivityInstance.getDurationInMillis()).isGreaterThanOrEqualTo(0);
    assertThat(historicActivityInstance.getProcessDefinitionId()).isNotNull();
    assertThat(historicActivityInstance.getProcessInstanceId()).isEqualTo(processInstance.getId());
    assertThat(historicActivityInstance.getStartTime()).isNotNull();
}
 
Example #30
Source File: VerifyDatabaseOperationsTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@AfterEach
protected void tearDown() throws Exception {

    processEngineConfiguration.setBulkInsertEnabled(oldIsBulkInsertableValue);
    processEngineConfiguration.getPerformanceSettings().setEnableEagerExecutionTreeFetching(oldExecutionTreeFetchValue);
    processEngineConfiguration.getPerformanceSettings().setEnableExecutionRelationshipCounts(oldExecutionRelationshipCountValue);
    processEngineConfiguration.getPerformanceSettings().setEnableTaskRelationshipCounts(oldTaskRelationshipCountValue);

    TaskServiceConfiguration TaskServiceConfiguration = (TaskServiceConfiguration) processEngineConfiguration.getServiceConfigurations().get(EngineConfigurationConstants.KEY_TASK_SERVICE_CONFIG);
    TaskServiceConfiguration.setEnableTaskRelationshipCounts(oldTaskRelationshipCountValue);

    processEngineConfiguration.setEnableProcessDefinitionInfoCache(oldenableProcessDefinitionInfoCacheValue);
    ((AbstractHistoryManager) processEngineConfiguration.getHistoryManager()).setHistoryLevel(oldHistoryLevel);

    ((CommandExecutorImpl) processEngineConfiguration.getCommandExecutor()).setFirst(oldFirstCommandInterceptor);

    processEngineConfiguration.addSessionFactory(oldDbSqlSessionFactory);

    // Validate (cause this tended to be screwed up)
    List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().list();
    for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
        assertThat(historicActivityInstance.getStartTime()).isNotNull();
        assertThat(historicActivityInstance.getEndTime()).isNotNull();
    }

    FlowableProfiler.getInstance().reset();

    for (Deployment deployment : repositoryService.createDeploymentQuery().list()) {
        repositoryService.deleteDeployment(deployment.getId(), true);
    }

    assertThat(runtimeService.createActivityInstanceQuery().count()).isZero();
}