use of org.activiti.engine.history.HistoricActivityInstance in project Activiti by Activiti.
the class CallActivityAdvancedTest method testCallSimpleSubProcess.
@Deployment(resources = { "org/activiti/engine/test/bpmn/callactivity/CallActivity.testCallSimpleSubProcess.bpmn20.xml", "org/activiti/engine/test/bpmn/callactivity/simpleSubProcess.bpmn20.xml" })
public void testCallSimpleSubProcess() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("callSimpleSubProcess");
// one task in the subprocess should be active after starting the process instance
TaskQuery taskQuery = taskService.createTaskQuery();
Task taskBeforeSubProcess = taskQuery.singleResult();
assertEquals("Task before subprocess", taskBeforeSubProcess.getName());
// Completing the task continues the process which leads to calling the subprocess
taskService.complete(taskBeforeSubProcess.getId());
Task taskInSubProcess = taskQuery.singleResult();
assertEquals("Task in subprocess", taskInSubProcess.getName());
// Completing the task in the subprocess, finishes the subprocess
taskService.complete(taskInSubProcess.getId());
Task taskAfterSubProcess = taskQuery.singleResult();
assertEquals("Task after subprocess", taskAfterSubProcess.getName());
// Completing this task end the process instance
taskService.complete(taskAfterSubProcess.getId());
assertProcessEnded(processInstance.getId());
// Validate subprocess history
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
// Subprocess should have initial activity set
HistoricProcessInstance historicProcess = historyService.createHistoricProcessInstanceQuery().processInstanceId(taskInSubProcess.getProcessInstanceId()).singleResult();
assertNotNull(historicProcess);
assertEquals("theStart", historicProcess.getStartActivityId());
List<HistoricActivityInstance> historicInstances = historyService.createHistoricActivityInstanceQuery().processInstanceId(taskInSubProcess.getProcessInstanceId()).list();
// Should contain a start-event, the task and an end-event
assertEquals(3L, historicInstances.size());
Set<String> expectedActivities = new HashSet<String>(Arrays.asList(new String[] { "theStart", "task", "theEnd" }));
for (HistoricActivityInstance act : historicInstances) {
expectedActivities.remove(act.getActivityId());
}
assertTrue("Not all expected activities were found in the history", expectedActivities.isEmpty());
}
}
use of org.activiti.engine.history.HistoricActivityInstance in project Activiti by Activiti.
the class BoundaryErrorEventTest method assertThatErrorHasBeenCaught.
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());
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());
}
}
}
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()));
}
}
use of org.activiti.engine.history.HistoricActivityInstance in project Activiti by Activiti.
the class HistoricActivityInstanceTest method testHistoricActivityInstanceReceive.
@Deployment
public void testHistoricActivityInstanceReceive() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("receiveProcess");
HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("receive").singleResult();
assertEquals("receive", historicActivityInstance.getActivityId());
assertEquals("receiveTask", historicActivityInstance.getActivityType());
assertNull(historicActivityInstance.getEndTime());
assertNull(historicActivityInstance.getDurationInMillis());
assertNotNull(historicActivityInstance.getProcessDefinitionId());
assertEquals(processInstance.getId(), historicActivityInstance.getProcessInstanceId());
assertEquals(processInstance.getId(), historicActivityInstance.getExecutionId());
assertNotNull(historicActivityInstance.getStartTime());
runtimeService.signal(processInstance.getId());
historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("receive").singleResult();
assertEquals("receive", historicActivityInstance.getActivityId());
assertEquals("receiveTask", historicActivityInstance.getActivityType());
assertNotNull(historicActivityInstance.getEndTime());
assertTrue(historicActivityInstance.getDurationInMillis() >= 0);
assertNotNull(historicActivityInstance.getProcessDefinitionId());
assertEquals(processInstance.getId(), historicActivityInstance.getProcessInstanceId());
assertEquals(processInstance.getId(), historicActivityInstance.getExecutionId());
assertNotNull(historicActivityInstance.getStartTime());
}
use of org.activiti.engine.history.HistoricActivityInstance in project Activiti by Activiti.
the class HistoricActivityInstanceTest method testParallelJoinEndTime.
/**
* 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<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());
}
Aggregations