protected void ensureHistoricProcessInstanceNotActive(HistoricProcessInstance instance) { if (instance.getEndTime() == null) { throw LOG.historicProcessInstanceActive(instance); } }
protected void ensureHistoricProcessInstanceNotActive(HistoricProcessInstance instance) { if (instance.getEndTime() == null) { throw LOG.historicProcessInstanceActive(instance); } }
private void assertThatInstanceHasAllImportantInformation(HistoricProcessInstance historicProcessInstance) { assertThat(historicProcessInstance, notNullValue()); assertThat(historicProcessInstance.getId(), notNullValue()); assertThat(historicProcessInstance.getProcessDefinitionKey(), is("process")); assertThat(historicProcessInstance.getProcessDefinitionVersion(), notNullValue()); assertThat(historicProcessInstance.getProcessDefinitionId(), notNullValue()); assertThat(historicProcessInstance.getDurationInMillis(), notNullValue()); assertThat(historicProcessInstance.getStartTime(), notNullValue()); assertThat(historicProcessInstance.getEndTime(), notNullValue()); }
private void assertThatInstanceHasAllImportantInformation(HistoricProcessInstance historicProcessInstance) { assertThat(historicProcessInstance, notNullValue()); assertThat(historicProcessInstance.getId(), notNullValue()); assertThat(historicProcessInstance.getProcessDefinitionKey(), is("process")); assertThat(historicProcessInstance.getProcessDefinitionVersion(), notNullValue()); assertThat(historicProcessInstance.getProcessDefinitionId(), notNullValue()); assertThat(historicProcessInstance.getStartTime(), notNullValue()); assertThat(historicProcessInstance.getEndTime(), nullValue()); }
public static HistoricProcessInstance createMockHistoricProcessInstanceUnfinished() { HistoricProcessInstance mock = mock(HistoricProcessInstance.class); when(mock.getId()).thenReturn(EXAMPLE_PROCESS_INSTANCE_ID); when(mock.getBusinessKey()).thenReturn(EXAMPLE_PROCESS_INSTANCE_BUSINESS_KEY); when(mock.getProcessDefinitionId()).thenReturn(EXAMPLE_PROCESS_DEFINITION_ID); when(mock.getDeleteReason()).thenReturn(EXAMPLE_HISTORIC_PROCESS_INSTANCE_DELETE_REASON); when(mock.getEndTime()).thenReturn(null); when(mock.getStartTime()).thenReturn(DateTimeUtil.parseDate(EXAMPLE_HISTORIC_PROCESS_INSTANCE_START_TIME)); when(mock.getDurationInMillis()).thenReturn(EXAMPLE_HISTORIC_PROCESS_INSTANCE_DURATION_MILLIS); return mock; }
public static HistoricProcessInstance createMockHistoricProcessInstance(String tenantId) { HistoricProcessInstance mock = mock(HistoricProcessInstance.class); when(mock.getId()).thenReturn(EXAMPLE_PROCESS_INSTANCE_ID); when(mock.getBusinessKey()).thenReturn(EXAMPLE_PROCESS_INSTANCE_BUSINESS_KEY); when(mock.getProcessDefinitionKey()).thenReturn(EXAMPLE_PROCESS_DEFINITION_KEY); when(mock.getProcessDefinitionName()).thenReturn(EXAMPLE_PROCESS_DEFINITION_NAME); when(mock.getProcessDefinitionVersion()).thenReturn(EXAMPLE_PROCESS_DEFINITION_VERSION); when(mock.getProcessDefinitionId()).thenReturn(EXAMPLE_PROCESS_DEFINITION_ID); when(mock.getDeleteReason()).thenReturn(EXAMPLE_HISTORIC_PROCESS_INSTANCE_DELETE_REASON); when(mock.getRemovalTime()).thenReturn(DateTimeUtil.parseDate(EXAMPLE_HISTORIC_PROCESS_INSTANCE_REMOVAL_TIME)); when(mock.getEndTime()).thenReturn(DateTimeUtil.parseDate(EXAMPLE_HISTORIC_PROCESS_INSTANCE_END_TIME)); when(mock.getStartTime()).thenReturn(DateTimeUtil.parseDate(EXAMPLE_HISTORIC_PROCESS_INSTANCE_START_TIME)); when(mock.getDurationInMillis()).thenReturn(EXAMPLE_HISTORIC_PROCESS_INSTANCE_DURATION_MILLIS); when(mock.getStartUserId()).thenReturn(EXAMPLE_HISTORIC_PROCESS_INSTANCE_START_USER_ID); when(mock.getStartActivityId()).thenReturn(EXAMPLE_HISTORIC_PROCESS_INSTANCE_START_ACTIVITY_ID); when(mock.getRootProcessInstanceId()).thenReturn(EXAMPLE_HISTORIC_PROCESS_INSTANCE_ROOT_PROCESS_INSTANCE_ID); when(mock.getSuperProcessInstanceId()).thenReturn(EXAMPLE_HISTORIC_PROCESS_INSTANCE_SUPER_PROCESS_INSTANCE_ID); when(mock.getSuperCaseInstanceId()).thenReturn(EXAMPLE_HISTORIC_PROCESS_INSTANCE_SUPER_CASE_INSTANCE_ID); when(mock.getCaseInstanceId()).thenReturn(EXAMPLE_HISTORIC_PROCESS_INSTANCE_CASE_INSTANCE_ID); when(mock.getTenantId()).thenReturn(tenantId); when(mock.getState()).thenReturn(EXAMPLE_HISTORIC_PROCESS_INSTANCE_STATE); return mock; }
@Override public Object execute(CommandContext commandContext) { //when List<String> historicProcessInstanceIdsForCleanup = commandContext.getHistoricProcessInstanceManager().findHistoricProcessInstanceIdsForCleanup( batchSize, 0, 60); //then assertEquals(resultCount, historicProcessInstanceIdsForCleanup.size()); if (resultCount > 0) { List<HistoricProcessInstance> historicProcessInstances = historyService.createHistoricProcessInstanceQuery() .processInstanceIds(new HashSet<String>(historicProcessInstanceIdsForCleanup)).list(); for (HistoricProcessInstance historicProcessInstance : historicProcessInstances) { assertNotNull(historicProcessInstance.getEndTime()); List<ProcessDefinition> processDefinitions = engineRule.getRepositoryService().createProcessDefinitionQuery() .processDefinitionId(historicProcessInstance.getProcessDefinitionId()).list(); assertEquals(1, processDefinitions.size()); ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) processDefinitions.get(0); assertTrue(historicProcessInstance.getEndTime().before(DateUtils.addDays(ClockUtil.getCurrentTime(), processDefinition.getHistoryTimeToLive()))); } } return null; } });
@Deployment public void testProcessInstanceShouldBeActive() { // given // when String processInstanceId = runtimeService.startProcessInstanceByKey("process").getId(); // then HistoricProcessInstance historicProcessInstance = historyService .createHistoricProcessInstanceQuery() .processInstanceId(processInstanceId) .singleResult(); assertNull(historicProcessInstance.getEndTime()); assertNull(historicProcessInstance.getDurationInMillis()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/history/oneTaskProcess.bpmn20.xml"}) public void testDeleteProcessInstanceHistoryCreated() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); assertNotNull(processInstance); // delete process instance should not delete the history runtimeService.deleteProcessInstance(processInstance.getId(), "cancel"); HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult(); assertNotNull(historicProcessInstance.getEndTime()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/history/oneTaskProcess.bpmn20.xml"}) public void testHistoricProcessInstanceDelete() { ProcessInstance pi = runtimeService.startProcessInstanceByKey("oneTaskProcess"); runtimeService.deleteProcessInstance(pi.getId(), "cancel"); HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().singleResult(); assertNotNull(historicProcessInstance.getDeleteReason()); assertEquals("cancel", historicProcessInstance.getDeleteReason()); assertNotNull(historicProcessInstance.getEndTime()); }
/** See: https://app.camunda.com/jira/browse/CAM-1324 */ @Deployment public void testHistoricProcessInstanceDeleteAsync() { ProcessInstance pi = runtimeService.startProcessInstanceByKey("failing"); runtimeService.deleteProcessInstance(pi.getId(), "cancel"); HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().singleResult(); assertNotNull(historicProcessInstance.getDeleteReason()); assertEquals("cancel", historicProcessInstance.getDeleteReason()); assertNotNull(historicProcessInstance.getEndTime()); }
public static HistoricProcessInstanceDto fromHistoricProcessInstance(HistoricProcessInstance historicProcessInstance) { HistoricProcessInstanceDto dto = new HistoricProcessInstanceDto(); dto.id = historicProcessInstance.getId(); dto.businessKey = historicProcessInstance.getBusinessKey(); dto.processDefinitionId = historicProcessInstance.getProcessDefinitionId(); dto.processDefinitionKey = historicProcessInstance.getProcessDefinitionKey(); dto.processDefinitionName = historicProcessInstance.getProcessDefinitionName(); dto.processDefinitionVersion = historicProcessInstance.getProcessDefinitionVersion(); dto.startTime = historicProcessInstance.getStartTime(); dto.endTime = historicProcessInstance.getEndTime(); dto.removalTime = historicProcessInstance.getRemovalTime(); dto.durationInMillis = historicProcessInstance.getDurationInMillis(); dto.startUserId = historicProcessInstance.getStartUserId(); dto.startActivityId = historicProcessInstance.getStartActivityId(); dto.deleteReason = historicProcessInstance.getDeleteReason(); dto.rootProcessInstanceId = historicProcessInstance.getRootProcessInstanceId(); dto.superProcessInstanceId = historicProcessInstance.getSuperProcessInstanceId(); dto.superCaseInstanceId = historicProcessInstance.getSuperCaseInstanceId(); dto.caseInstanceId = historicProcessInstance.getCaseInstanceId(); dto.tenantId = historicProcessInstance.getTenantId(); dto.state = historicProcessInstance.getState(); return dto; }
public static HistoricProcessInstanceDto fromHistoricProcessInstance(HistoricProcessInstance historicProcessInstance) { HistoricProcessInstanceDto dto = new HistoricProcessInstanceDto(); dto.id = historicProcessInstance.getId(); dto.businessKey = historicProcessInstance.getBusinessKey(); dto.processDefinitionId = historicProcessInstance.getProcessDefinitionId(); dto.processDefinitionKey = historicProcessInstance.getProcessDefinitionKey(); dto.processDefinitionName = historicProcessInstance.getProcessDefinitionName(); dto.processDefinitionVersion = historicProcessInstance.getProcessDefinitionVersion(); dto.startTime = historicProcessInstance.getStartTime(); dto.endTime = historicProcessInstance.getEndTime(); dto.removalTime = historicProcessInstance.getRemovalTime(); dto.durationInMillis = historicProcessInstance.getDurationInMillis(); dto.startUserId = historicProcessInstance.getStartUserId(); dto.startActivityId = historicProcessInstance.getStartActivityId(); dto.deleteReason = historicProcessInstance.getDeleteReason(); dto.rootProcessInstanceId = historicProcessInstance.getRootProcessInstanceId(); dto.superProcessInstanceId = historicProcessInstance.getSuperProcessInstanceId(); dto.superCaseInstanceId = historicProcessInstance.getSuperCaseInstanceId(); dto.caseInstanceId = historicProcessInstance.getCaseInstanceId(); dto.tenantId = historicProcessInstance.getTenantId(); dto.state = historicProcessInstance.getState(); return dto; }
@Deployment(resources = ONE_TASK_PROCESS) public void testCancelTaskShouldCancelProcessInstance() { // given String processInstanceId = runtimeService.startProcessInstanceByKey("oneTaskProcess").getId(); // when runtimeService .createProcessInstanceModification(processInstanceId) .cancelAllForActivity("theTask") .execute(true, false); // then HistoricProcessInstance instance = historyService.createHistoricProcessInstanceQuery().singleResult(); assertNotNull(instance); assertEquals(processInstanceId, instance.getId()); assertNotNull(instance.getEndTime()); }
/** * https://app.camunda.com/jira/browse/CAM-1537 */ @Deployment public void testHistoricActivityInstanceGatewayEndTimes() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("gatewayEndTimes"); TaskQuery query = taskService.createTaskQuery().orderByTaskName().asc(); List<Task> tasks = query.list(); taskService.complete(tasks.get(0).getId()); taskService.complete(tasks.get(1).getId()); // process instance should have finished assertNotNull(historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult().getEndTime()); // gateways should have end timestamps assertNotNull(historyService.createHistoricActivityInstanceQuery().activityId("Gateway_0").singleResult().getEndTime()); // there exists two historic activity instances for "Gateway_1" (parallel join) HistoricActivityInstanceQuery historicActivityInstanceQuery = historyService.createHistoricActivityInstanceQuery().activityId("Gateway_1"); assertEquals(2, historicActivityInstanceQuery.count()); // they should have an end timestamp assertNotNull(historicActivityInstanceQuery.list().get(0).getEndTime()); assertNotNull(historicActivityInstanceQuery.list().get(1).getEndTime()); }
@Test @Deployment(resources = "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml") public void testDeleteProcessInstanceSkipCustomListener() { // given String processInstanceId = runtimeService.startProcessInstanceByKey("oneTaskProcess").getId(); // when runtimeService.deleteProcessInstance(processInstanceId, null, true); // then HistoricProcessInstance instance = historyService .createHistoricProcessInstanceQuery() .processInstanceId(processInstanceId) .singleResult(); assertNotNull(instance); assertEquals(processInstanceId, instance.getId()); assertNotNull(instance.getEndTime()); }
/** * CAM-4067 */ @Deployment(resources = "org/camunda/bpm/engine/test/bpmn/event/end/TerminateEndEventTest.testTerminateInSubProcessConcurrent.bpmn") public void testTerminateInSubProcessConcurrentShouldNotEndProcessInstanceInHistory() throws Exception { // when process instance is started and terminate end event in subprocess executed ProcessInstance pi = runtimeService.startProcessInstanceByKey("terminateEndEventExample"); // then the historic process instance should not appear ended assertProcessNotEnded(pi.getId()); if (processEngineConfiguration.getHistoryLevel().getId() > ProcessEngineConfigurationImpl.HISTORYLEVEL_NONE) { HistoricProcessInstance hpi = historyService.createHistoricProcessInstanceQuery().singleResult(); assertNotNull(hpi); assertNull(hpi.getEndTime()); assertNull(hpi.getDurationInMillis()); assertNull(hpi.getDeleteReason()); } }
@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS) public void testHistoricProcessInstanceForSynchronousCompletion() { // when the process instance ends immediately ProcessInstance instance = runtimeService .createProcessInstanceByKey("exclusiveGateway") .startAfterActivity("task1") .execute(); // then HistoricProcessInstance historicInstance = historyService.createHistoricProcessInstanceQuery().singleResult(); assertNotNull(historicInstance); assertEquals(instance.getId(), historicInstance.getId()); assertNotNull(historicInstance.getStartTime()); assertNotNull(historicInstance.getEndTime()); assertEquals("join", historicInstance.getStartActivityId()); }
/** * CAM-4067 */ @Deployment(resources = "org/camunda/bpm/engine/test/bpmn/event/end/TerminateEndEventTest.testTerminateInSubProcess.bpmn") public void testTerminateInSubProcessShouldNotEndProcessInstanceInHistory() throws Exception { // when process instance is started and terminate end event in subprocess executed ProcessInstance pi = runtimeService.startProcessInstanceByKey("terminateEndEventExample"); // then the historic process instance should not appear ended assertProcessNotEnded(pi.getId()); if (processEngineConfiguration.getHistoryLevel().getId() > ProcessEngineConfigurationImpl.HISTORYLEVEL_NONE) { HistoricProcessInstance hpi = historyService.createHistoricProcessInstanceQuery().singleResult(); assertNotNull(hpi); assertNull(hpi.getEndTime()); assertNull(hpi.getDurationInMillis()); assertNull(hpi.getDeleteReason()); } }
@Deployment(resources={ "org/camunda/bpm/engine/test/api/cmmn/oneProcessTaskCaseWithManualActivation.cmmn", "org/camunda/bpm/engine/test/history/HistoricCaseActivityInstanceTest.oneTaskProcess.bpmn20.xml" }) public void testHistoricCalledProcessInstanceId() { String taskId = "PI_ProcessTask_1"; createCaseInstanceByKey("oneProcessTaskCase").getId(); // as long as the process task is not activated there should be no process instance assertCount(0, historyService.createHistoricProcessInstanceQuery()); HistoricCaseActivityInstance historicInstance = queryHistoricActivityCaseInstance(taskId); assertNull(historicInstance.getCalledProcessInstanceId()); // start process task manually to create case instance CaseExecution processTask = queryCaseExecutionByActivityId(taskId); manualStart(processTask.getId()); // there should exist a new process instance HistoricProcessInstance calledProcessInstance = historyService.createHistoricProcessInstanceQuery().singleResult(); assertNotNull(calledProcessInstance); assertNotNull(calledProcessInstance.getEndTime()); // check that the called process instance id was correctly set historicInstance = queryHistoricActivityCaseInstance(taskId); assertEquals(calledProcessInstance.getId(), historicInstance.getCalledProcessInstanceId()); }