Search in sources :

Example 91 with ProcessInstanceQuery

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());
}
Also used : ProcessInstanceQuery(org.camunda.bpm.engine.runtime.ProcessInstanceQuery) HashMap(java.util.HashMap) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test)

Example 92 with ProcessInstanceQuery

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);
}
Also used : ProcessInstanceQuery(org.camunda.bpm.engine.runtime.ProcessInstanceQuery) RuntimeService(org.camunda.bpm.engine.RuntimeService) Batch(org.camunda.bpm.engine.batch.Batch) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ArrayList(java.util.ArrayList) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 93 with ProcessInstanceQuery

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());
}
Also used : HistoricActivityInstanceQuery(org.camunda.bpm.engine.history.HistoricActivityInstanceQuery) ProcessInstanceQuery(org.camunda.bpm.engine.runtime.ProcessInstanceQuery) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricActivityInstance(org.camunda.bpm.engine.history.HistoricActivityInstance) Test(org.junit.Test) RequiredHistoryLevel(org.camunda.bpm.engine.test.RequiredHistoryLevel)

Example 94 with ProcessInstanceQuery

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());
}
Also used : HistoricProcessInstanceQuery(org.camunda.bpm.engine.history.HistoricProcessInstanceQuery) ProcessInstanceQuery(org.camunda.bpm.engine.runtime.ProcessInstanceQuery) HistoricProcessInstanceQuery(org.camunda.bpm.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) Test(org.junit.Test) RequiredHistoryLevel(org.camunda.bpm.engine.test.RequiredHistoryLevel)

Example 95 with ProcessInstanceQuery

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());
}
Also used : ProcessInstanceQuery(org.camunda.bpm.engine.runtime.ProcessInstanceQuery) TaskQuery(org.camunda.bpm.engine.task.TaskQuery) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) JobQuery(org.camunda.bpm.engine.runtime.JobQuery) ExecutionQuery(org.camunda.bpm.engine.runtime.ExecutionQuery) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

ProcessInstanceQuery (org.camunda.bpm.engine.runtime.ProcessInstanceQuery)201 Test (org.junit.Test)127 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)59 Deployment (org.camunda.bpm.engine.test.Deployment)42 HistoricProcessInstanceQuery (org.camunda.bpm.engine.history.HistoricProcessInstanceQuery)34 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)27 HashMap (java.util.HashMap)24 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)19 Batch (org.camunda.bpm.engine.batch.Batch)18 JobQuery (org.camunda.bpm.engine.runtime.JobQuery)17 ArrayList (java.util.ArrayList)16 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)15 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)15 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)14 ExecutionQuery (org.camunda.bpm.engine.runtime.ExecutionQuery)12 HistoricProcessInstanceQueryDto (org.camunda.bpm.engine.rest.dto.history.HistoricProcessInstanceQueryDto)9 Job (org.camunda.bpm.engine.runtime.Job)9 BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)8 AbstractAsyncOperationsTest (org.camunda.bpm.engine.test.api.AbstractAsyncOperationsTest)8 Response (com.jayway.restassured.response.Response)7