use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.
the class HistoryServiceAsyncOperationsTest method prepareData.
public void prepareData() {
testRule.deploy("org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml");
startTestProcesses(2);
for (Task activeTask : taskService.createTaskQuery().list()) {
taskService.complete(activeTask.getId());
}
historicProcessInstances = new ArrayList<String>();
for (HistoricProcessInstance pi : historyService.createHistoricProcessInstanceQuery().list()) {
historicProcessInstances.add(pi.getId());
}
}
use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.
the class SetProcessDefinitionVersionCmdTest method testHistoryOfSetProcessDefinitionVersionCmd.
public void testHistoryOfSetProcessDefinitionVersionCmd() {
// given
String resource = "org/camunda/bpm/engine/test/api/runtime/migration/SetProcessDefinitionVersionCmdTest.bpmn";
// Deployments
org.camunda.bpm.engine.repository.Deployment firstDeployment = repositoryService.createDeployment().addClasspathResource(resource).deploy();
org.camunda.bpm.engine.repository.Deployment secondDeployment = repositoryService.createDeployment().addClasspathResource(resource).deploy();
// Process definitions
ProcessDefinition processDefinitionV1 = repositoryService.createProcessDefinitionQuery().deploymentId(firstDeployment.getId()).singleResult();
ProcessDefinition processDefinitionV2 = repositoryService.createProcessDefinitionQuery().deploymentId(secondDeployment.getId()).singleResult();
// start process instance
ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinitionV1.getId());
// when
setProcessDefinitionVersion(processInstance.getId(), 2);
// then
ProcessInstance processInstanceAfterMigration = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
assertEquals(processDefinitionV2.getId(), processInstanceAfterMigration.getProcessDefinitionId());
if (processEngineConfiguration.getHistoryLevel().getId() > ProcessEngineConfigurationImpl.HISTORYLEVEL_NONE) {
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
assertEquals(processDefinitionV2.getId(), historicProcessInstance.getProcessDefinitionId());
}
// Clean up the test
repositoryService.deleteDeployment(firstDeployment.getId(), true);
repositoryService.deleteDeployment(secondDeployment.getId(), true);
}
use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.
the class SetProcessDefinitionVersionCmdTest method testSetProcessDefinitionVersion.
@Deployment
public void testSetProcessDefinitionVersion() {
// start process instance
ProcessInstance pi = runtimeService.startProcessInstanceByKey("receiveTask");
// check that receive task has been reached
Execution execution = runtimeService.createExecutionQuery().processInstanceId(pi.getId()).activityId("waitState1").singleResult();
assertNotNull(execution);
// deploy new version of the process definition
org.camunda.bpm.engine.repository.Deployment deployment = repositoryService.createDeployment().addClasspathResource(TEST_PROCESS).deploy();
assertEquals(2, repositoryService.createProcessDefinitionQuery().count());
// migrate process instance to new process definition version
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
commandExecutor.execute(new SetProcessDefinitionVersionCmd(pi.getId(), 2));
// signal process instance
runtimeService.signal(execution.getId());
// check that the instance now uses the new process definition version
ProcessDefinition newProcessDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionVersion(2).singleResult();
pi = runtimeService.createProcessInstanceQuery().processInstanceId(pi.getId()).singleResult();
assertEquals(newProcessDefinition.getId(), pi.getProcessDefinitionId());
// check history
if (processEngineConfiguration.getHistoryLevel().getId() > ProcessEngineConfigurationImpl.HISTORYLEVEL_NONE) {
HistoricProcessInstance historicPI = historyService.createHistoricProcessInstanceQuery().processInstanceId(pi.getId()).singleResult();
// assertEquals(newProcessDefinition.getId(), historicPI.getProcessDefinitionId());
}
// undeploy "manually" deployed process definition
repositoryService.deleteDeployment(deployment.getId(), true);
}
use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.
the class MigrationHistoricProcessInstanceTest method testMigrateHistoryProcessInstance.
@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
public void testMigrateHistoryProcessInstance() {
// given
HistoricProcessInstanceQuery sourceHistoryProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery().processDefinitionId(sourceProcessDefinition.getId());
HistoricProcessInstanceQuery targetHistoryProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery().processDefinitionId(targetProcessDefinition.getId());
// when
assertEquals(1, sourceHistoryProcessInstanceQuery.count());
assertEquals(0, targetHistoryProcessInstanceQuery.count());
ProcessInstanceQuery sourceProcessInstanceQuery = runtimeService.createProcessInstanceQuery().processDefinitionId(sourceProcessDefinition.getId());
runtimeService.newMigration(migrationPlan).processInstanceQuery(sourceProcessInstanceQuery).execute();
// then
assertEquals(0, sourceHistoryProcessInstanceQuery.count());
assertEquals(1, targetHistoryProcessInstanceQuery.count());
HistoricProcessInstance instance = targetHistoryProcessInstanceQuery.singleResult();
assertEquals(instance.getProcessDefinitionKey(), targetProcessDefinition.getKey());
}
use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.
the class NestedCompensationScenarioTest method testHistory.
@Test
@ScenarioUnderTest("init.throwCompensate.1")
public void testHistory() {
// given
Task compensationHandler = rule.taskQuery().singleResult();
// when
rule.getTaskService().complete(compensationHandler.getId());
// then history is written for the remaining activity instances
HistoricProcessInstance historicProcessInstance = rule.historicProcessInstance();
Assert.assertNotNull(historicProcessInstance);
Assert.assertNotNull(historicProcessInstance.getEndTime());
HistoricActivityInstance subProcessInstance = rule.getHistoryService().createHistoricActivityInstanceQuery().processInstanceId(historicProcessInstance.getId()).activityId("subProcess").singleResult();
Assert.assertNotNull(subProcessInstance);
Assert.assertNotNull(subProcessInstance.getEndTime());
Assert.assertEquals(historicProcessInstance.getId(), subProcessInstance.getParentActivityInstanceId());
HistoricActivityInstance compensationThrowInstance = rule.getHistoryService().createHistoricActivityInstanceQuery().processInstanceId(historicProcessInstance.getId()).activityId("throwCompensate").singleResult();
Assert.assertNotNull(compensationThrowInstance);
Assert.assertNotNull(compensationThrowInstance.getEndTime());
Assert.assertEquals(subProcessInstance.getId(), compensationThrowInstance.getParentActivityInstanceId());
HistoricActivityInstance compensationHandlerInstance = rule.getHistoryService().createHistoricActivityInstanceQuery().processInstanceId(historicProcessInstance.getId()).activityId("undoTask").singleResult();
Assert.assertNotNull(compensationHandlerInstance);
Assert.assertNotNull(compensationHandlerInstance.getEndTime());
Assert.assertEquals(subProcessInstance.getId(), compensationHandlerInstance.getParentActivityInstanceId());
}
Aggregations