Search in sources :

Example 86 with HistoricProcessInstance

use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.

the class HistoricCaseActivityInstanceTest method testHistoricCalledProcessInstanceId.

@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());
}
Also used : CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) HistoricCaseActivityInstance(org.camunda.bpm.engine.history.HistoricCaseActivityInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 87 with HistoricProcessInstance

use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.

the class HistoricProcessInstanceTest method testQueryByCaseInstanceIdHierarchy.

@Deployment(resources = { "org/camunda/bpm/engine/test/history/HistoricProcessInstanceTest.testQueryByCaseInstanceId.cmmn", "org/camunda/bpm/engine/test/history/HistoricProcessInstanceTest.testQueryByCaseInstanceIdHierarchy-super.bpmn20.xml", "org/camunda/bpm/engine/test/history/HistoricProcessInstanceTest.testQueryByCaseInstanceIdHierarchy-sub.bpmn20.xml" })
public void testQueryByCaseInstanceIdHierarchy() {
    // given
    String caseInstanceId = caseService.withCaseDefinitionByKey("case").create().getId();
    // then
    HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery();
    query.caseInstanceId(caseInstanceId);
    assertEquals(2, query.count());
    assertEquals(2, query.list().size());
    for (HistoricProcessInstance hpi : query.list()) {
        assertEquals(caseInstanceId, hpi.getCaseInstanceId());
    }
    // complete existing user task -> completes the process instance(s)
    String taskId = taskService.createTaskQuery().caseInstanceId(caseInstanceId).singleResult().getId();
    taskService.complete(taskId);
    // the completed historic process instance is still associated with the
    // case instance id
    assertEquals(2, query.count());
    assertEquals(2, query.list().size());
    for (HistoricProcessInstance hpi : query.list()) {
        assertEquals(caseInstanceId, hpi.getCaseInstanceId());
    }
}
Also used : HistoricProcessInstanceQuery(org.camunda.bpm.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 88 with HistoricProcessInstance

use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.

the class HistoricProcessInstanceTest method testProcessInstanceShouldBeActive.

@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());
}
Also used : HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 89 with HistoricProcessInstance

use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.

the class HistoricProcessInstanceTest method testStartActivityId.

@Deployment(resources = { "org/camunda/bpm/engine/test/history/HistoricProcessInstanceTest.testStartActivityId-super.bpmn20.xml", "org/camunda/bpm/engine/test/history/HistoricProcessInstanceTest.testStartActivityId-sub.bpmn20.xml" })
public void testStartActivityId() {
    // given
    // when
    runtimeService.startProcessInstanceByKey("super");
    // then
    HistoricProcessInstance hpi = historyService.createHistoricProcessInstanceQuery().processDefinitionKey("sub").singleResult();
    assertEquals("theSubStart", hpi.getStartActivityId());
}
Also used : HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 90 with HistoricProcessInstance

use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.

the class HistoricProcessInstanceTest method testHistoricProcInstExecutedActivityAfter.

@Test
public void testHistoricProcInstExecutedActivityAfter() {
    // given
    Calendar now = Calendar.getInstance();
    ClockUtil.setCurrentTime(now.getTime());
    BpmnModelInstance model = Bpmn.createExecutableProcess("proc").startEvent().endEvent().done();
    deployment(model);
    Calendar hourFromNow = (Calendar) now.clone();
    hourFromNow.add(Calendar.HOUR_OF_DAY, 1);
    runtimeService.startProcessInstanceByKey("proc");
    // when query historic process instance which has executed an activity after the start time
    HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().executedActivityAfter(now.getTime()).singleResult();
    // then query returns result
    assertNotNull(historicProcessInstance);
    // when query historic proc inst with execute activity after a hour of the starting time
    historicProcessInstance = historyService.createHistoricProcessInstanceQuery().executedActivityAfter(hourFromNow.getTime()).singleResult();
    // then query returns no result
    assertNull(historicProcessInstance);
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) Test(org.junit.Test)

Aggregations

HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)113 Deployment (org.camunda.bpm.engine.test.Deployment)46 Test (org.junit.Test)37 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)36 HistoricProcessInstanceQuery (org.camunda.bpm.engine.history.HistoricProcessInstanceQuery)25 Task (org.camunda.bpm.engine.task.Task)19 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)18 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)17 ArrayList (java.util.ArrayList)15 Calendar (java.util.Calendar)12 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)12 GregorianCalendar (java.util.GregorianCalendar)11 HistoricActivityInstance (org.camunda.bpm.engine.history.HistoricActivityInstance)9 RequiredHistoryLevel (org.camunda.bpm.engine.test.RequiredHistoryLevel)9 HistoricProcessInstanceQueryDto (org.camunda.bpm.engine.rest.dto.history.HistoricProcessInstanceQueryDto)7 List (java.util.List)5 ProcessInstanceQuery (org.camunda.bpm.engine.runtime.ProcessInstanceQuery)5 Response (com.jayway.restassured.response.Response)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4