Search in sources :

Example 31 with HistoricTaskInstance

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

the class HistoricTaskInstanceTest method testQueryByCaseDefinitionId.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testQueryByCaseDefinitionId() {
    // given
    String caseDefinitionId = repositoryService.createCaseDefinitionQuery().singleResult().getId();
    String caseInstanceId = caseService.withCaseDefinition(caseDefinitionId).create().getId();
    String humanTaskId = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult().getId();
    // then
    HistoricTaskInstanceQuery query = historyService.createHistoricTaskInstanceQuery();
    query.caseDefinitionId(caseDefinitionId);
    assertEquals(1, query.count());
    assertEquals(1, query.list().size());
    assertNotNull(query.singleResult());
    HistoricTaskInstance task = query.singleResult();
    assertNotNull(task);
    assertEquals(caseDefinitionId, task.getCaseDefinitionId());
    assertEquals(caseInstanceId, task.getCaseInstanceId());
    assertEquals(humanTaskId, task.getCaseExecutionId());
}
Also used : HistoricTaskInstance(org.camunda.bpm.engine.history.HistoricTaskInstance) HistoricTaskInstanceQuery(org.camunda.bpm.engine.history.HistoricTaskInstanceQuery) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 32 with HistoricTaskInstance

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

the class HistoricTaskInstanceTest method testQueryByCaseExecutionId.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testQueryByCaseExecutionId() {
    // given
    String key = "oneTaskCase";
    String caseDefinitionId = repositoryService.createCaseDefinitionQuery().caseDefinitionKey(key).singleResult().getId();
    String caseInstanceId = caseService.withCaseDefinitionByKey(key).create().getId();
    String humanTaskId = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult().getId();
    // then
    HistoricTaskInstanceQuery query = historyService.createHistoricTaskInstanceQuery();
    query.caseExecutionId(humanTaskId);
    assertEquals(1, query.count());
    assertEquals(1, query.list().size());
    assertNotNull(query.singleResult());
    HistoricTaskInstance task = query.singleResult();
    assertNotNull(task);
    assertEquals(caseDefinitionId, task.getCaseDefinitionId());
    assertEquals(caseInstanceId, task.getCaseInstanceId());
    assertEquals(humanTaskId, task.getCaseExecutionId());
}
Also used : HistoricTaskInstance(org.camunda.bpm.engine.history.HistoricTaskInstance) HistoricTaskInstanceQuery(org.camunda.bpm.engine.history.HistoricTaskInstanceQuery) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 33 with HistoricTaskInstance

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

the class HistoricTaskInstanceTest method testCaseDefinitionKeyProperty.

@Deployment(resources = "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn")
public void testCaseDefinitionKeyProperty() {
    // given
    String key = "oneTaskCase";
    String caseInstanceId = caseService.createCaseInstanceByKey(key).getId();
    // when
    HistoricTaskInstance task = historyService.createHistoricTaskInstanceQuery().caseInstanceId(caseInstanceId).taskDefinitionKey("PI_HumanTask_1").singleResult();
    // then
    assertNotNull(task.getCaseDefinitionKey());
    assertEquals(key, task.getCaseDefinitionKey());
    assertNull(task.getProcessDefinitionKey());
}
Also used : HistoricTaskInstance(org.camunda.bpm.engine.history.HistoricTaskInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 34 with HistoricTaskInstance

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

the class HistoricTaskInstanceTest method testProcessDefinitionKeyProperty.

@Deployment(resources = "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml")
public void testProcessDefinitionKeyProperty() {
    // given
    String key = "oneTaskProcess";
    String processInstanceId = runtimeService.startProcessInstanceByKey(key).getId();
    // when
    HistoricTaskInstance task = historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstanceId).taskDefinitionKey("theTask").singleResult();
    // then
    assertNotNull(task.getProcessDefinitionKey());
    assertEquals(key, task.getProcessDefinitionKey());
    assertNull(task.getCaseDefinitionKey());
}
Also used : HistoricTaskInstance(org.camunda.bpm.engine.history.HistoricTaskInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 35 with HistoricTaskInstance

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

the class HistoricTaskInstanceTest method testHistoricTaskInstance.

@Deployment
public void testHistoricTaskInstance() throws Exception {
    String processInstanceId = runtimeService.startProcessInstanceByKey("HistoricTaskInstanceTest").getId();
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
    // Set priority to non-default value
    Task runtimeTask = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
    runtimeTask.setPriority(1234);
    // Set due-date
    Date dueDate = sdf.parse("01/02/2003 04:05:06");
    runtimeTask.setDueDate(dueDate);
    taskService.saveTask(runtimeTask);
    String taskId = runtimeTask.getId();
    String taskDefinitionKey = runtimeTask.getTaskDefinitionKey();
    HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
    assertEquals(taskId, historicTaskInstance.getId());
    assertEquals(1234, historicTaskInstance.getPriority());
    assertEquals("Clean up", historicTaskInstance.getName());
    assertEquals("Schedule an engineering meeting for next week with the new hire.", historicTaskInstance.getDescription());
    assertEquals(dueDate, historicTaskInstance.getDueDate());
    assertEquals("kermit", historicTaskInstance.getAssignee());
    assertEquals(taskDefinitionKey, historicTaskInstance.getTaskDefinitionKey());
    assertNull(historicTaskInstance.getEndTime());
    assertNull(historicTaskInstance.getDurationInMillis());
    assertNull(historicTaskInstance.getCaseDefinitionId());
    assertNull(historicTaskInstance.getCaseInstanceId());
    assertNull(historicTaskInstance.getCaseExecutionId());
    // the activity instance id is set
    assertEquals(((TaskEntity) runtimeTask).getExecution().getActivityInstanceId(), historicTaskInstance.getActivityInstanceId());
    runtimeService.setVariable(processInstanceId, "deadline", "yesterday");
    // move clock by 1 second
    Date now = ClockUtil.getCurrentTime();
    ClockUtil.setCurrentTime(new Date(now.getTime() + 1000));
    taskService.complete(taskId);
    assertEquals(1, historyService.createHistoricTaskInstanceQuery().count());
    historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
    assertEquals(taskId, historicTaskInstance.getId());
    assertEquals(1234, historicTaskInstance.getPriority());
    assertEquals("Clean up", historicTaskInstance.getName());
    assertEquals("Schedule an engineering meeting for next week with the new hire.", historicTaskInstance.getDescription());
    assertEquals(dueDate, historicTaskInstance.getDueDate());
    assertEquals("kermit", historicTaskInstance.getAssignee());
    assertEquals(TaskEntity.DELETE_REASON_COMPLETED, historicTaskInstance.getDeleteReason());
    assertEquals(taskDefinitionKey, historicTaskInstance.getTaskDefinitionKey());
    assertNotNull(historicTaskInstance.getEndTime());
    assertNotNull(historicTaskInstance.getDurationInMillis());
    assertTrue(historicTaskInstance.getDurationInMillis() >= 1000);
    assertTrue(((HistoricTaskInstanceEntity) historicTaskInstance).getDurationRaw() >= 1000);
    assertNull(historicTaskInstance.getCaseDefinitionId());
    assertNull(historicTaskInstance.getCaseInstanceId());
    assertNull(historicTaskInstance.getCaseExecutionId());
    historyService.deleteHistoricTaskInstance(taskId);
    assertEquals(0, historyService.createHistoricTaskInstanceQuery().count());
}
Also used : Task(org.camunda.bpm.engine.task.Task) HistoricTaskInstance(org.camunda.bpm.engine.history.HistoricTaskInstance) TaskEntity(org.camunda.bpm.engine.impl.persistence.entity.TaskEntity) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) HistoricTaskInstanceEntity(org.camunda.bpm.engine.impl.persistence.entity.HistoricTaskInstanceEntity) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

HistoricTaskInstance (org.camunda.bpm.engine.history.HistoricTaskInstance)36 Deployment (org.camunda.bpm.engine.test.Deployment)20 Task (org.camunda.bpm.engine.task.Task)18 HistoricTaskInstanceQuery (org.camunda.bpm.engine.history.HistoricTaskInstanceQuery)10 RequiredHistoryLevel (org.camunda.bpm.engine.test.RequiredHistoryLevel)6 Test (org.junit.Test)6 HistoricActivityInstance (org.camunda.bpm.engine.history.HistoricActivityInstance)4 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)4 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)3 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)2 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1 ProcessApplicationService (org.camunda.bpm.ProcessApplicationService)1