use of org.camunda.bpm.engine.runtime.ProcessInstanceQuery in project camunda-bpm-platform by camunda.
the class MultiTenancyStartProcessInstanceByConditionCmdTenantCheckTest method testWithAuthenticatedTenant2.
@Test
public void testWithAuthenticatedTenant2() throws Exception {
// given
testRule.deployForTenant(TENANT_ONE, PROCESS);
testRule.deployForTenant(TENANT_TWO, PROCESS);
ensureEventSubscriptions(2);
engineRule.getIdentityService().setAuthentication("user", null, Arrays.asList(TENANT_ONE));
Map<String, Object> variableMap = new HashMap<String, Object>();
variableMap.put("foo", "bar");
// when
List<ProcessInstance> processInstances = engineRule.getRuntimeService().createConditionEvaluation().setVariables(variableMap).evaluateStartConditions();
// then
assertNotNull(processInstances);
assertEquals(1, processInstances.size());
engineRule.getIdentityService().clearAuthentication();
ProcessInstanceQuery processInstanceQuery = engineRule.getRuntimeService().createProcessInstanceQuery();
assertEquals(1, processInstanceQuery.tenantIdIn(TENANT_ONE).count());
assertEquals(0, processInstanceQuery.tenantIdIn(TENANT_TWO).count());
}
use of org.camunda.bpm.engine.runtime.ProcessInstanceQuery in project camunda-bpm-platform by camunda.
the class BatchMigrationTest method testBatchCreationWithOverlappingProcessInstanceIdsAndQuery.
@Test
public void testBatchCreationWithOverlappingProcessInstanceIdsAndQuery() {
RuntimeService runtimeService = engineRule.getRuntimeService();
int processInstanceCount = 15;
ProcessDefinition sourceProcessDefinition = migrationRule.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
ProcessDefinition targetProcessDefinition = migrationRule.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
List<String> processInstanceIds = new ArrayList<String>();
for (int i = 0; i < processInstanceCount; i++) {
processInstanceIds.add(runtimeService.startProcessInstanceById(sourceProcessDefinition.getId()).getId());
}
MigrationPlan migrationPlan = engineRule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapEqualActivities().build();
ProcessInstanceQuery sourceProcessInstanceQuery = runtimeService.createProcessInstanceQuery().processDefinitionId(sourceProcessDefinition.getId());
assertEquals(processInstanceCount, sourceProcessInstanceQuery.count());
// when
Batch batch = runtimeService.newMigration(migrationPlan).processInstanceIds(processInstanceIds).processInstanceQuery(sourceProcessInstanceQuery).executeAsync();
// then a batch is created
assertBatchCreated(batch, processInstanceCount);
}
use of org.camunda.bpm.engine.runtime.ProcessInstanceQuery in project camunda-bpm-platform by camunda.
the class MigrationHistoricActivityInstanceTest method testMigrateHistoryActivityInstance.
@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
public void testMigrateHistoryActivityInstance() {
// given
ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(modify(ProcessModels.ONE_TASK_PROCESS).changeElementId("Process", "Process2").changeElementId("userTask", "userTask2").changeElementName("userTask", "new activity name"));
MigrationPlan migrationPlan = runtimeService.createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("userTask", "userTask2").build();
ProcessInstance processInstance = runtimeService.startProcessInstanceById(sourceProcessDefinition.getId());
HistoricActivityInstanceQuery sourceHistoryActivityInstanceQuery = historyService.createHistoricActivityInstanceQuery().processDefinitionId(sourceProcessDefinition.getId());
HistoricActivityInstanceQuery targetHistoryActivityInstanceQuery = historyService.createHistoricActivityInstanceQuery().processDefinitionId(targetProcessDefinition.getId());
// when
assertEquals(2, sourceHistoryActivityInstanceQuery.count());
assertEquals(0, targetHistoryActivityInstanceQuery.count());
ProcessInstanceQuery sourceProcessInstanceQuery = runtimeService.createProcessInstanceQuery().processDefinitionId(sourceProcessDefinition.getId());
runtimeService.newMigration(migrationPlan).processInstanceQuery(sourceProcessInstanceQuery).execute();
// then one instance of the start event still belongs to the source process
// and one active user task instances is now migrated to the target process
assertEquals(1, sourceHistoryActivityInstanceQuery.count());
assertEquals(1, targetHistoryActivityInstanceQuery.count());
HistoricActivityInstance instance = targetHistoryActivityInstanceQuery.singleResult();
assertMigratedTo(instance, targetProcessDefinition, "userTask2");
assertEquals("new activity name", instance.getActivityName());
assertEquals(processInstance.getId(), instance.getParentActivityInstanceId());
assertEquals("userTask", instance.getActivityType());
}
use of org.camunda.bpm.engine.runtime.ProcessInstanceQuery 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.runtime.ProcessInstanceQuery in project camunda-bpm-platform by camunda.
the class StartTimerEventTest method testStartTimerEventSubProcessInParallelMultiInstanceSubProcessWithNonInterruptingBoundaryTimerEvent.
/**
* test scenario: - start process instance with multiInstance parallel -
* execute interrupting timer job of event subprocess - execute non
* interrupting timer boundary event of subprocess
*/
@Deployment
public void testStartTimerEventSubProcessInParallelMultiInstanceSubProcessWithNonInterruptingBoundaryTimerEvent() {
DummyServiceTask.wasExecuted = false;
// start process instance
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");
// execute multiInstance loop number 1
// check if execution exists
ExecutionQuery executionQuery = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId());
assertEquals(6, executionQuery.count());
// check if user task exists
TaskQuery taskQuery = taskService.createTaskQuery();
assertEquals(2, taskQuery.count());
JobQuery jobQuery = managementService.createJobQuery();
assertEquals(3, jobQuery.count());
// execute interrupting timer job
managementService.executeJob(jobQuery.orderByJobDuedate().asc().list().get(1).getId());
assertEquals(true, DummyServiceTask.wasExecuted);
// after interrupting timer job execution
assertEquals(2, jobQuery.count());
assertEquals(1, taskQuery.count());
assertEquals(5, executionQuery.count());
// execute non interrupting boundary timer job
managementService.executeJob(jobQuery.orderByJobDuedate().asc().list().get(0).getId());
// after non interrupting boundary timer job execution
assertEquals(1, jobQuery.count());
assertEquals(1, taskQuery.count());
assertEquals(5, executionQuery.count());
ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId());
assertEquals(1, processInstanceQuery.count());
}
Aggregations