use of org.activiti.engine.history.HistoricActivityInstance in project Activiti by Activiti.
the class MultiInstanceTest method testEndTimeOnMiSubprocess.
@Deployment
public void testEndTimeOnMiSubprocess() {
if (!processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
return;
}
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("multiInstanceSubProcessParallelTasks");
List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
assertEquals(2, tasks.size());
assertEquals("User Task 1", tasks.get(0).getName());
assertEquals("User Task 1", tasks.get(1).getName());
// End time should not be set for the subprocess
List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityId("subprocess1").list();
assertEquals(2, historicActivityInstances.size());
for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
assertNotNull(historicActivityInstance.getStartTime());
assertNull(historicActivityInstance.getEndTime());
}
// Complete one of the user tasks. This should not trigger setting of end time of the subprocess, but due to a bug it did exactly that
taskService.complete(tasks.get(0).getId());
historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityId("subprocess1").list();
assertEquals(2, historicActivityInstances.size());
for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
assertNull(historicActivityInstance.getEndTime());
}
taskService.complete(tasks.get(1).getId());
historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityId("subprocess1").list();
assertEquals(2, historicActivityInstances.size());
for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
assertNull(historicActivityInstance.getEndTime());
}
tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskName("User Task 3").list();
assertEquals(2, tasks.size());
for (Task task : tasks) {
taskService.complete(task.getId());
historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityId("subprocess1").list();
assertEquals(2, historicActivityInstances.size());
for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
assertNull(historicActivityInstance.getEndTime());
}
}
// Finishing the tasks should also set the end time
tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
assertEquals(2, tasks.size());
for (Task task : tasks) {
taskService.complete(task.getId());
}
historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityId("subprocess1").list();
assertEquals(2, historicActivityInstances.size());
for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
assertNotNull(historicActivityInstance.getEndTime());
}
}
use of org.activiti.engine.history.HistoricActivityInstance in project Activiti by Activiti.
the class MultiInstanceTest method testSequentialUserTasksHistory.
@Deployment(resources = { "org/activiti/engine/test/bpmn/multiinstance/MultiInstanceTest.sequentialUserTasks.bpmn20.xml" })
public void testSequentialUserTasksHistory() {
runtimeService.startProcessInstanceByKey("miSequentialUserTasks", CollectionUtil.singletonMap("nrOfLoops", 4)).getId();
for (int i = 0; i < 4; i++) {
taskService.complete(taskService.createTaskQuery().singleResult().getId());
}
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
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());
}
}
}
use of org.activiti.engine.history.HistoricActivityInstance in project Activiti by Activiti.
the class MultiInstanceTest method testSequentialScriptTasksHistory.
@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());
}
}
}
use of org.activiti.engine.history.HistoricActivityInstance in project Activiti by Activiti.
the class ParallelGatewayTest method testHistoryTables.
// Test to verify ACT-1755
@Deployment
public void testHistoryTables() {
ProcessInstance pi = runtimeService.startProcessInstanceByKey("testHistoryRecords");
List<HistoricActivityInstance> history = historyService.createHistoricActivityInstanceQuery().processInstanceId(pi.getId()).list();
for (HistoricActivityInstance h : history) {
if (h.getActivityId().equals("parallelgateway2")) {
assertNotNull(h.getEndTime());
}
}
}
use of org.activiti.engine.history.HistoricActivityInstance in project Activiti by Activiti.
the class HistoricVariableInstanceTest method testVariableUpdatesLinkedToActivity.
@Deployment(resources = { "org/activiti/standalone/history/FullHistoryTest.testVariableUpdatesAreLinkedToActivity.bpmn20.xml" })
public void testVariableUpdatesLinkedToActivity() throws Exception {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
ProcessInstance pi = runtimeService.startProcessInstanceByKey("ProcessWithSubProcess");
Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("test", "1");
taskService.complete(task.getId(), variables);
// now we are in the subprocess
task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
variables.clear();
variables.put("test", "2");
taskService.complete(task.getId(), variables);
// now we are ended
assertProcessEnded(pi.getId());
// check history
List<HistoricDetail> updates = historyService.createHistoricDetailQuery().variableUpdates().list();
assertEquals(2, updates.size());
Map<String, HistoricVariableUpdate> updatesMap = new HashMap<String, HistoricVariableUpdate>();
HistoricVariableUpdate update = (HistoricVariableUpdate) updates.get(0);
updatesMap.put((String) update.getValue(), update);
update = (HistoricVariableUpdate) updates.get(1);
updatesMap.put((String) update.getValue(), update);
HistoricVariableUpdate update1 = updatesMap.get("1");
HistoricVariableUpdate update2 = updatesMap.get("2");
assertNotNull(update1.getActivityInstanceId());
assertNotNull(update1.getExecutionId());
HistoricActivityInstance historicActivityInstance1 = historyService.createHistoricActivityInstanceQuery().activityInstanceId(update1.getActivityInstanceId()).singleResult();
assertEquals(historicActivityInstance1.getExecutionId(), update1.getExecutionId());
assertEquals("usertask1", historicActivityInstance1.getActivityId());
// TODO https://activiti.atlassian.net/browse/ACT-1083
assertNotNull(update2.getActivityInstanceId());
HistoricActivityInstance historicActivityInstance2 = historyService.createHistoricActivityInstanceQuery().activityInstanceId(update2.getActivityInstanceId()).singleResult();
assertEquals("usertask2", historicActivityInstance2.getActivityId());
/*
* This is OK! The variable is set on the root execution, on a execution never run through the activity, where the process instances
* stands when calling the set Variable. But the ActivityId of this flow node is used. So the execution id's doesn't have to be equal.
*
* execution id: On which execution it was set
* activity id: in which activity was the process instance when setting the variable
*/
assertFalse(historicActivityInstance2.getExecutionId().equals(update2.getExecutionId()));
}
}
Aggregations