use of org.camunda.bpm.engine.history.HistoricActivityInstance in project camunda-bpm-platform by camunda.
the class MigrationHistoricActivityInstanceTest method testMigrateHistoricSubProcessRename.
@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
public void testMigrateHistoricSubProcessRename() {
// given
ProcessDefinition sourceDefinition = testHelper.deployAndGetDefinition(ProcessModels.SUBPROCESS_PROCESS);
ProcessDefinition targetDefinition = testHelper.deployAndGetDefinition(modify(ProcessModels.SUBPROCESS_PROCESS).changeElementId("subProcess", "newSubProcess"));
MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceDefinition.getId(), targetDefinition.getId()).mapActivities("subProcess", "newSubProcess").mapActivities("userTask", "userTask").build();
ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceDefinition.getId());
// when
rule.getRuntimeService().newMigration(migrationPlan).processInstanceIds(Arrays.asList(processInstance.getId())).execute();
// then
List<HistoricActivityInstance> historicInstances = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).unfinished().orderByActivityId().asc().list();
Assert.assertEquals(2, historicInstances.size());
assertMigratedTo(historicInstances.get(0), targetDefinition, "newSubProcess");
assertMigratedTo(historicInstances.get(1), targetDefinition, "userTask");
assertEquals(processInstance.getId(), historicInstances.get(0).getParentActivityInstanceId());
assertEquals(historicInstances.get(0).getId(), historicInstances.get(1).getParentActivityInstanceId());
}
use of org.camunda.bpm.engine.history.HistoricActivityInstance in project camunda-bpm-platform by camunda.
the class MigrationHistoricActivityInstanceTest method testMigrateHistoricActivityInstanceAddScope.
@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
public void testMigrateHistoricActivityInstanceAddScope() {
// given
ProcessDefinition sourceDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
ProcessDefinition targetDefinition = testHelper.deployAndGetDefinition(ProcessModels.SUBPROCESS_PROCESS);
MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceDefinition.getId(), targetDefinition.getId()).mapActivities("userTask", "userTask").build();
ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceDefinition.getId());
// when
rule.getRuntimeService().newMigration(migrationPlan).processInstanceIds(Arrays.asList(processInstance.getId())).execute();
// then
List<HistoricActivityInstance> historicInstances = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).unfinished().orderByActivityId().asc().list();
Assert.assertEquals(2, historicInstances.size());
assertMigratedTo(historicInstances.get(0), targetDefinition, "subProcess");
assertMigratedTo(historicInstances.get(1), targetDefinition, "userTask");
assertEquals(processInstance.getId(), historicInstances.get(0).getParentActivityInstanceId());
assertEquals(historicInstances.get(0).getId(), historicInstances.get(1).getParentActivityInstanceId());
}
use of org.camunda.bpm.engine.history.HistoricActivityInstance in project camunda-bpm-platform by camunda.
the class FullHistoryTest method testHistoricFormProperties.
@Test
@Deployment
public void testHistoricFormProperties() throws Exception {
Date startedDate = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss SSS").parse("01/01/2001 01:23:46 000");
ClockUtil.setCurrentTime(startedDate);
Map<String, String> formProperties = new HashMap<String, String>();
formProperties.put("formProp1", "Activiti rocks");
formProperties.put("formProp2", "12345");
ProcessDefinition procDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("historicFormPropertiesProcess").singleResult();
ProcessInstance processInstance = formService.submitStartFormData(procDef.getId(), formProperties);
// Submit form-properties on the created task
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
// Out execution only has a single activity waiting, the task
List<String> activityIds = runtimeService.getActiveActivityIds(task.getExecutionId());
assertNotNull(activityIds);
assertEquals(1, activityIds.size());
String taskActivityId = activityIds.get(0);
// Submit form properties
formProperties = new HashMap<String, String>();
formProperties.put("formProp3", "Activiti still rocks!!!");
formProperties.put("formProp4", "54321");
formService.submitTaskFormData(task.getId(), formProperties);
// 4 historic form properties should be created. 2 when process started, 2 when task completed
List<HistoricDetail> props = historyService.createHistoricDetailQuery().formProperties().processInstanceId(processInstance.getId()).orderByFormPropertyId().asc().list();
HistoricFormProperty historicProperty1 = (HistoricFormProperty) props.get(0);
assertEquals("formProp1", historicProperty1.getPropertyId());
assertEquals("Activiti rocks", historicProperty1.getPropertyValue());
assertEquals(startedDate, historicProperty1.getTime());
assertEquals(processInstance.getId(), historicProperty1.getProcessInstanceId());
assertNull(historicProperty1.getTaskId());
assertNotNull(historicProperty1.getActivityInstanceId());
HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityInstanceId(historicProperty1.getActivityInstanceId()).singleResult();
assertNotNull(historicActivityInstance);
assertEquals("start", historicActivityInstance.getActivityId());
HistoricFormProperty historicProperty2 = (HistoricFormProperty) props.get(1);
assertEquals("formProp2", historicProperty2.getPropertyId());
assertEquals("12345", historicProperty2.getPropertyValue());
assertEquals(startedDate, historicProperty2.getTime());
assertEquals(processInstance.getId(), historicProperty2.getProcessInstanceId());
assertNull(historicProperty2.getTaskId());
assertNotNull(historicProperty2.getActivityInstanceId());
historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityInstanceId(historicProperty2.getActivityInstanceId()).singleResult();
assertNotNull(historicActivityInstance);
assertEquals("start", historicActivityInstance.getActivityId());
HistoricFormProperty historicProperty3 = (HistoricFormProperty) props.get(2);
assertEquals("formProp3", historicProperty3.getPropertyId());
assertEquals("Activiti still rocks!!!", historicProperty3.getPropertyValue());
assertEquals(startedDate, historicProperty3.getTime());
assertEquals(processInstance.getId(), historicProperty3.getProcessInstanceId());
String activityInstanceId = historicProperty3.getActivityInstanceId();
historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityInstanceId(activityInstanceId).singleResult();
assertNotNull(historicActivityInstance);
assertEquals(taskActivityId, historicActivityInstance.getActivityId());
assertNotNull(historicProperty3.getTaskId());
HistoricFormProperty historicProperty4 = (HistoricFormProperty) props.get(3);
assertEquals("formProp4", historicProperty4.getPropertyId());
assertEquals("54321", historicProperty4.getPropertyValue());
assertEquals(startedDate, historicProperty4.getTime());
assertEquals(processInstance.getId(), historicProperty4.getProcessInstanceId());
activityInstanceId = historicProperty4.getActivityInstanceId();
historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityInstanceId(activityInstanceId).singleResult();
assertNotNull(historicActivityInstance);
assertEquals(taskActivityId, historicActivityInstance.getActivityId());
assertNotNull(historicProperty4.getTaskId());
assertEquals(4, props.size());
}
use of org.camunda.bpm.engine.history.HistoricActivityInstance in project camunda-bpm-platform by camunda.
the class FullHistoryTest method testVariableUpdates.
@Test
@Deployment
public void testVariableUpdates() {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("number", "one");
variables.put("character", "a");
variables.put("bytes", ":-(".getBytes());
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("receiveTask", variables);
runtimeService.setVariable(processInstance.getId(), "number", "two");
runtimeService.setVariable(processInstance.getId(), "bytes", ":-)".getBytes());
// Start-task should be added to history
HistoricActivityInstance historicStartEvent = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).activityId("theStart").singleResult();
assertNotNull(historicStartEvent);
HistoricActivityInstance waitStateActivity = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).activityId("waitState").singleResult();
assertNotNull(waitStateActivity);
HistoricActivityInstance serviceTaskActivity = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).activityId("serviceTask").singleResult();
assertNotNull(serviceTaskActivity);
List<HistoricDetail> historicDetails = historyService.createHistoricDetailQuery().orderByVariableName().asc().orderByVariableRevision().asc().list();
assertEquals(10, historicDetails.size());
HistoricVariableUpdate historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(0);
assertEquals("bytes", historicVariableUpdate.getVariableName());
assertEquals(":-(", new String((byte[]) historicVariableUpdate.getValue()));
assertEquals(0, historicVariableUpdate.getRevision());
assertEquals(historicStartEvent.getId(), historicVariableUpdate.getActivityInstanceId());
// Variable is updated when process was in waitstate
historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(1);
assertEquals("bytes", historicVariableUpdate.getVariableName());
assertEquals(":-)", new String((byte[]) historicVariableUpdate.getValue()));
assertEquals(1, historicVariableUpdate.getRevision());
assertEquals(waitStateActivity.getId(), historicVariableUpdate.getActivityInstanceId());
historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(2);
assertEquals("character", historicVariableUpdate.getVariableName());
assertEquals("a", historicVariableUpdate.getValue());
assertEquals(0, historicVariableUpdate.getRevision());
assertEquals(historicStartEvent.getId(), historicVariableUpdate.getActivityInstanceId());
historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(3);
assertEquals("number", historicVariableUpdate.getVariableName());
assertEquals("one", historicVariableUpdate.getValue());
assertEquals(0, historicVariableUpdate.getRevision());
assertEquals(historicStartEvent.getId(), historicVariableUpdate.getActivityInstanceId());
// Variable is updated when process was in waitstate
historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(4);
assertEquals("number", historicVariableUpdate.getVariableName());
assertEquals("two", historicVariableUpdate.getValue());
assertEquals(1, historicVariableUpdate.getRevision());
assertEquals(waitStateActivity.getId(), historicVariableUpdate.getActivityInstanceId());
// Variable set from process-start execution listener
historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(5);
assertEquals("zVar1", historicVariableUpdate.getVariableName());
assertEquals("Event: start", historicVariableUpdate.getValue());
assertEquals(0, historicVariableUpdate.getRevision());
assertEquals(historicStartEvent.getId(), historicVariableUpdate.getActivityInstanceId());
// Variable set from transition take execution listener
historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(6);
assertEquals("zVar2", historicVariableUpdate.getVariableName());
assertEquals("Event: take", historicVariableUpdate.getValue());
assertEquals(0, historicVariableUpdate.getRevision());
assertNull(historicVariableUpdate.getActivityInstanceId());
// Variable set from activity start execution listener on the servicetask
historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(7);
assertEquals("zVar3", historicVariableUpdate.getVariableName());
assertEquals("Event: start", historicVariableUpdate.getValue());
assertEquals(0, historicVariableUpdate.getRevision());
assertEquals(serviceTaskActivity.getId(), historicVariableUpdate.getActivityInstanceId());
// Variable set from activity end execution listener on the servicetask
historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(8);
assertEquals("zVar4", historicVariableUpdate.getVariableName());
assertEquals("Event: end", historicVariableUpdate.getValue());
assertEquals(0, historicVariableUpdate.getRevision());
assertEquals(serviceTaskActivity.getId(), historicVariableUpdate.getActivityInstanceId());
// Variable set from service-task
historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(9);
assertEquals("zzz", historicVariableUpdate.getVariableName());
assertEquals(123456789L, historicVariableUpdate.getValue());
assertEquals(0, historicVariableUpdate.getRevision());
assertEquals(serviceTaskActivity.getId(), historicVariableUpdate.getActivityInstanceId());
// trigger receive task
runtimeService.signal(processInstance.getId());
testHelper.assertProcessEnded(processInstance.getId());
// check for historic process variables set
HistoricVariableInstanceQuery historicProcessVariableQuery = historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc();
assertEquals(8, historicProcessVariableQuery.count());
List<HistoricVariableInstance> historicVariables = historicProcessVariableQuery.list();
// Variable status when process is finished
HistoricVariableInstance historicVariable = historicVariables.get(0);
assertEquals("bytes", historicVariable.getVariableName());
assertEquals(":-)", new String((byte[]) historicVariable.getValue()));
historicVariable = historicVariables.get(1);
assertEquals("character", historicVariable.getVariableName());
assertEquals("a", historicVariable.getValue());
historicVariable = historicVariables.get(2);
assertEquals("number", historicVariable.getVariableName());
assertEquals("two", historicVariable.getValue());
historicVariable = historicVariables.get(3);
assertEquals("zVar1", historicVariable.getVariableName());
assertEquals("Event: start", historicVariable.getValue());
historicVariable = historicVariables.get(4);
assertEquals("zVar2", historicVariable.getVariableName());
assertEquals("Event: take", historicVariable.getValue());
historicVariable = historicVariables.get(5);
assertEquals("zVar3", historicVariable.getVariableName());
assertEquals("Event: start", historicVariable.getValue());
historicVariable = historicVariables.get(6);
assertEquals("zVar4", historicVariable.getVariableName());
assertEquals("Event: end", historicVariable.getValue());
historicVariable = historicVariables.get(7);
assertEquals("zzz", historicVariable.getVariableName());
assertEquals(123456789L, historicVariable.getValue());
}
use of org.camunda.bpm.engine.history.HistoricActivityInstance in project camunda-bpm-platform by camunda.
the class ActivityPerfTestWatcher method logActivityResults.
protected void logActivityResults(PerfTestPass pass, PerfTestRun run, HistoryService historyService) {
String processInstanceId = run.getVariable(PerfTestConstants.PROCESS_INSTANCE_ID);
List<ActivityPerfTestResult> activityResults = new ArrayList<ActivityPerfTestResult>();
HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
Date startTime = processInstance.getStartTime();
List<HistoricActivityInstance> activityInstances = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).orderByHistoricActivityInstanceStartTime().asc().list();
for (HistoricActivityInstance activityInstance : activityInstances) {
if (watchAllActivities || activityIds.contains(activityInstance.getActivityId())) {
ActivityPerfTestResult result = new ActivityPerfTestResult(activityInstance);
if (activityInstance.getActivityType().equals("startEvent")) {
result.setStartTime(startTime);
}
activityResults.add(result);
}
}
pass.logActivityResult(processInstanceId, activityResults);
}
Aggregations