org.camunda.bpm.engine.runtime.ProcessInstanceQuery Java Examples

The following examples show how to use org.camunda.bpm.engine.runtime.ProcessInstanceQuery. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MessageCorrelationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/api/runtime/MessageCorrelationTest.testMessageStartEventCorrelation.bpmn20.xml")
@Test
public void testStartMessageOnlyFlagAllWithVariablesInResult() {

  List<MessageCorrelationResultWithVariables> results = runtimeService.createMessageCorrelation("newInvoiceMessage")
    .setVariable("aKey", "aValue")
    .startMessageOnly()
    .correlateAllWithResultAndVariables(false);

  ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery().processDefinitionKey("messageStartEvent")
      .variableValueEquals("aKey", "aValue");
  assertThat(processInstanceQuery.count()).isEqualTo(1);
  MessageCorrelationResultWithVariables result = results.get(0);
  assertThat(result.getVariables().size()).isEqualTo(1);
  assertThat(result.getVariables().getValueTyped("aKey").getValue()).isEqualTo("aValue");
}
 
Example #2
Source File: MultiTenancySignalReceiveCmdTenantCheckTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void sendSignalToStartEventNoAuthenticatedTenants() {
  testRule.deploy(SIGNAL_START_PROCESS);
  testRule.deployForTenant(TENANT_ONE, SIGNAL_START_PROCESS);

  engineRule.getIdentityService().setAuthentication("user", null, null);

  engineRule.getRuntimeService().createSignalEvent("signal").send();

  engineRule.getIdentityService().clearAuthentication();

  ProcessInstanceQuery query = engineRule.getRuntimeService().createProcessInstanceQuery();
  assertThat(query.count(), is(1L));
  assertThat(query.withoutTenantId().count(), is(1L));
  assertThat(query.tenantIdIn(TENANT_ONE).count(), is(0L));
}
 
Example #3
Source File: WorkflowEngineService.java    From wecube-platform with Apache License 2.0 6 votes vote down vote up
public ProcessInstance retrieveProcessInstance(String processInstanceId) {
	if (StringUtils.isBlank(processInstanceId)) {
		throw new IllegalArgumentException("Process instance ID is blank.");
	}

	ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId);

	ProcessInstance procInst = query.singleResult();

	if (procInst == null) {
		throw new WecubeCoreException(
				String.format("Such process instance with id [%s] does not exist.", processInstanceId));
	}

	return procInst;
}
 
Example #4
Source File: MultiTenancyProcessTaskTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testStartProcessInstanceWithLatestBindingDifferentVersion() {

    deploymentForTenant(TENANT_ONE, CMMN_LATEST_WITH_MANUAL_ACTIVATION, PROCESS);

    deploymentForTenant(TENANT_TWO, CMMN_LATEST_WITH_MANUAL_ACTIVATION, PROCESS);
    deploymentForTenant(TENANT_TWO, PROCESS);

    createCaseInstance("testCase", TENANT_ONE);
    createCaseInstance("testCase", TENANT_TWO);

    ProcessDefinition latestProcessTenantTwo = repositoryService.createProcessDefinitionQuery()
        .tenantIdIn(TENANT_TWO).processDefinitionKey("testProcess").latestVersion().singleResult();

    ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().processDefinitionKey("testProcess");
    assertThat(query.tenantIdIn(TENANT_ONE).count(), is(1L));
    assertThat(query.tenantIdIn(TENANT_TWO).processDefinitionId(latestProcessTenantTwo.getId()).count(), is(1L));
  }
 
Example #5
Source File: ManagementServiceAsyncOperationsTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetJobsRetryAsyncWithProcessQueryAndList() throws Exception {
  //given
  List<String> extraPi = startTestProcesses(1);
  ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().processInstanceId(extraPi.get(0));

  //when
  Batch batch = managementService.setJobRetriesAsync(processInstanceIds, query, RETRIES);
  completeSeedJobs(batch);
  List<Exception> exceptions = executeBatchJobs(batch);

  // then
  assertThat(exceptions.size(), is(0));
  assertRetries(getAllJobIds(), RETRIES);
  assertHistoricBatchExists(testRule);
}
 
Example #6
Source File: ProcessInstanceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testQueryNoSpecificsDeploymentIdMappings() {
  // given
  String deploymentId = repositoryService.createDeploymentQuery().singleResult().getId();
  ImmutablePair<String, String>[] expectedMappings = processInstanceIds.stream()
      .map(id -> new ImmutablePair<>(deploymentId, id))
      .collect(Collectors.toList())
      .toArray(new ImmutablePair[0]);
  // when
  List<ImmutablePair<String, String>> mappings = engineRule.getProcessEngineConfiguration().getCommandExecutorTxRequired().execute((c) -> {
    ProcessInstanceQuery query = c.getProcessEngineConfiguration().getRuntimeService().createProcessInstanceQuery();
    return ((ProcessInstanceQueryImpl) query).listDeploymentIdMappings();
  });
  // then
  assertEquals(5, mappings.size());
  assertThat(mappings).containsExactlyInAnyOrder(expectedMappings);
}
 
Example #7
Source File: MultiTenancyMessageCorrelationCmdTenantCheckTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void correlateMessageToStartEventWithAuthenticatedTenant() {
  testRule.deployForTenant(TENANT_ONE, MESSAGE_START_PROCESS);
  testRule.deployForTenant(TENANT_TWO, MESSAGE_START_PROCESS);

  engineRule.getIdentityService().setAuthentication("user", null, Arrays.asList(TENANT_ONE));

  engineRule.getRuntimeService().createMessageCorrelation("message")
    .correlateStartMessage();

  engineRule.getIdentityService().clearAuthentication();

  ProcessInstanceQuery query = engineRule.getRuntimeService().createProcessInstanceQuery();
  assertThat(query.tenantIdIn(TENANT_ONE).count(), is(1L));
  assertThat(query.tenantIdIn(TENANT_TWO).count(), is(0L));
}
 
Example #8
Source File: ProcessInstanceRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public List<ProcessInstanceDto> queryProcessInstances(
    ProcessInstanceQueryDto queryDto, Integer firstResult, Integer maxResults) {
  ProcessEngine engine = getProcessEngine();
  queryDto.setObjectMapper(getObjectMapper());
  ProcessInstanceQuery query = queryDto.toQuery(engine);

  List<ProcessInstance> matchingInstances;
  if (firstResult != null || maxResults != null) {
    matchingInstances = executePaginatedQuery(query, firstResult, maxResults);
  } else {
    matchingInstances = query.list();
  }

  List<ProcessInstanceDto> instanceResults = new ArrayList<ProcessInstanceDto>();
  for (ProcessInstance instance : matchingInstances) {
    ProcessInstanceDto resultInstance = ProcessInstanceDto.fromProcessInstance(instance);
    instanceResults.add(resultInstance);
  }
  return instanceResults;
}
 
Example #9
Source File: BatchMigrationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testEmptyProcessInstanceQuery() {
  ProcessDefinition testProcessDefinition = migrationRule.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
  MigrationPlan migrationPlan = runtimeService.createMigrationPlan(testProcessDefinition.getId(), testProcessDefinition.getId())
    .mapEqualActivities()
    .build();

  ProcessInstanceQuery emptyProcessInstanceQuery = runtimeService.createProcessInstanceQuery();
  assertEquals(0, emptyProcessInstanceQuery.count());

  try {
    runtimeService.newMigration(migrationPlan).processInstanceQuery(emptyProcessInstanceQuery).executeAsync();
    fail("Should not succeed");
  } catch (ProcessEngineException e) {
    assertThat(e.getMessage(), containsString("process instance ids is empty"));
  }
}
 
Example #10
Source File: ProcessInstanceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryByProcessDefinitionKeyNotIn() {
  // given (deploy another process)
  ProcessDefinition oneTaskProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);

  String oneTaskProcessDefinitionId = oneTaskProcessDefinition.getId();
  runtimeService.startProcessInstanceById(oneTaskProcessDefinitionId);
  runtimeService.startProcessInstanceById(oneTaskProcessDefinitionId);

  // assume
  assertThat(runtimeService.createProcessInstanceQuery().count(), is(7l));

  // when
  ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery()
    .processDefinitionKeyNotIn(PROCESS_DEFINITION_KEY, PROCESS_DEFINITION_KEY_2);

  // then
  assertThat(query.count(), is(2l));
  assertThat(query.list().size(), is(2));
}
 
Example #11
Source File: SetExternalTasksRetriesTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldUpdateRetriesByProcessInstanceQuery() {
  // given
  ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery();

  // when
  Batch batch = externalTaskService.updateRetries().processInstanceQuery(processInstanceQuery).setAsync(RETRIES);
  executeSeedAndBatchJobs(batch);

  // then
  List<ExternalTask> tasks = externalTaskService.createExternalTaskQuery().list();
  assertEquals(6, tasks.size());

  for (ExternalTask task : tasks) {
    assertEquals(RETRIES, (int) task.getRetries());
  }
}
 
Example #12
Source File: RuntimeServiceAsyncOperationsTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {
    "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"})
@Test
public void testDeleteProcessInstancesAsyncWithQuery() throws Exception {
  // given
  List<String> processIds = startTestProcesses(2);
  ProcessInstanceQuery processInstanceQuery = runtimeService
      .createProcessInstanceQuery().processInstanceIds(new HashSet<>(processIds));

  // when
  Batch batch = runtimeService.deleteProcessInstancesAsync(null, processInstanceQuery, TESTING_INSTANCE_DELETE);

  completeSeedJobs(batch);
  executeBatchJobs(batch);

  // then
  assertHistoricTaskDeletionPresent(processIds, TESTING_INSTANCE_DELETE, testRule);
  assertHistoricBatchExists(testRule);
  assertProcessInstancesAreDeleted();
}
 
Example #13
Source File: MultiTenancyProcessInstanceSuspensionStateTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void suspendProcessInstanceForNonTenant() {
  // given activated process instances
  ProcessInstanceQuery query = engineRule.getRuntimeService().createProcessInstanceQuery();
  assertThat(query.active().count(), is(3L));
  assertThat(query.suspended().count(), is(0L));

  engineRule.getRuntimeService()
    .updateProcessInstanceSuspensionState()
    .byProcessDefinitionKey(PROCESS_DEFINITION_KEY)
    .processDefinitionWithoutTenantId()
    .suspend();

  assertThat(query.active().count(), is(2L));
  assertThat(query.suspended().count(), is(1L));
  assertThat(query.suspended().withoutTenantId().count(), is(1L));
}
 
Example #14
Source File: ProcessInstanceRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetSingleInstance() {
  ProcessInstance mockInstance = MockProvider.createMockInstance();
  ProcessInstanceQuery sampleInstanceQuery = mock(ProcessInstanceQuery.class);
  when(runtimeServiceMock.createProcessInstanceQuery()).thenReturn(sampleInstanceQuery);
  when(sampleInstanceQuery.processInstanceId(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID)).thenReturn(sampleInstanceQuery);
  when(sampleInstanceQuery.singleResult()).thenReturn(mockInstance);

  given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID)
    .then().expect().statusCode(Status.OK.getStatusCode())
    .body("id", equalTo(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID))
    .body("ended", equalTo(MockProvider.EXAMPLE_PROCESS_INSTANCE_IS_ENDED))
    .body("definitionId", equalTo(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID))
    .body("businessKey", equalTo(MockProvider.EXAMPLE_PROCESS_INSTANCE_BUSINESS_KEY))
    .body("suspended", equalTo(MockProvider.EXAMPLE_PROCESS_INSTANCE_IS_SUSPENDED))
    .body("tenantId", equalTo(MockProvider.EXAMPLE_TENANT_ID))
    .when().get(SINGLE_PROCESS_INSTANCE_URL);
}
 
Example #15
Source File: ProcessInstanceRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetRetriesByProcessAsyncHistoricQueryBasedWithNegativeRetries() {
  doThrow(new BadUserRequestException("retries are negative"))
    .when(mockManagementService).setJobRetriesAsync(
      anyListOf(String.class),
      eq((ProcessInstanceQuery) null),
      any(HistoricProcessInstanceQuery.class),
      eq(MockProvider.EXAMPLE_NEGATIVE_JOB_RETRIES));

  HistoricProcessInstanceQuery mockedHistoricProcessInstanceQuery = mock(HistoricProcessInstanceQuery.class);
  when(historyServiceMock.createHistoricProcessInstanceQuery()).thenReturn(mockedHistoricProcessInstanceQuery);
  List<HistoricProcessInstance> historicProcessInstances = MockProvider.createMockRunningHistoricProcessInstances();
  when(mockedHistoricProcessInstanceQuery.list()).thenReturn(historicProcessInstances);

  SetJobRetriesByProcessDto body = new SetJobRetriesByProcessDto();
  body.setRetries(MockProvider.EXAMPLE_NEGATIVE_JOB_RETRIES);
  body.setHistoricProcessInstanceQuery(new HistoricProcessInstanceQueryDto());

  given()
    .contentType(ContentType.JSON).body(body)
  .then().expect()
    .statusCode(Status.BAD_REQUEST.getStatusCode())
  .when().post(SET_JOB_RETRIES_ASYNC_HIST_QUERY_URL);
}
 
Example #16
Source File: ModificationExecutionAsyncTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testBatchCreationWithOverlappingProcessInstanceIdsAndQuery() {
  int processInstanceCount = 15;
  DeploymentWithDefinitions deployment = testRule.deploy(instance);
  ProcessDefinition processDefinition = deployment.getDeployedProcessDefinitions().get(0);
  List<String> processInstanceIds = helper.startInstances("process1", 15);

  ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition.getId());
  assertEquals(processInstanceCount, processInstanceQuery.count());

  // when
  Batch batch = runtimeService
    .createModification(processDefinition.getId())
    .startTransition("seq")
    .processInstanceIds(processInstanceIds)
    .processInstanceQuery(processInstanceQuery)
    .executeAsync();

  // then a batch is created
  assertBatchCreated(batch, processInstanceCount);
}
 
Example #17
Source File: ProcessInstanceRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetRetriesByProcessWithNegativeRetries() {
  doThrow(new BadUserRequestException("retries are negative"))
      .when(mockManagementService).setJobRetriesAsync(
      anyListOf(String.class),
      any(ProcessInstanceQuery.class),
      eq(-1));

  Map<String, Object> messageBodyJson = new HashMap<String, Object>();
  messageBodyJson.put(RETRIES, -1);
  HistoricProcessInstanceQueryDto query = new HistoricProcessInstanceQueryDto();
  messageBodyJson.put("processInstanceQuery", query);

  given()
      .contentType(ContentType.JSON).body(messageBodyJson)
      .then().expect()
      .statusCode(Status.BAD_REQUEST.getStatusCode())
      .when().post(SET_JOB_RETRIES_ASYNC_URL);
}
 
Example #18
Source File: ProcessInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testQueryWithReadInstancesPermissionOnAnyProcessDefinition() {
  // given
  startProcessInstanceByKey(PROCESS_KEY);
  startProcessInstanceByKey(PROCESS_KEY);
  startProcessInstanceByKey(PROCESS_KEY);

  startProcessInstanceByKey(MESSAGE_START_PROCESS_KEY);
  startProcessInstanceByKey(MESSAGE_START_PROCESS_KEY);
  startProcessInstanceByKey(MESSAGE_START_PROCESS_KEY);
  startProcessInstanceByKey(MESSAGE_START_PROCESS_KEY);

  createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, READ_INSTANCE);

  // when
  ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery();

  // then
  verifyQueryResults(query, 7);
}
 
Example #19
Source File: StartTimerEventTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment
  public void FAILING_testCycleDateStartTimerEvent() throws Exception {
    ClockUtil.setCurrentTime(new Date());

    // After process start, there should be timer created
    JobQuery jobQuery = managementService.createJobQuery();
    assertEquals(1, jobQuery.count());

    final ProcessInstanceQuery piq = runtimeService.createProcessInstanceQuery().processDefinitionKey("startTimerEventExample");

    assertEquals(0, piq.count());

    moveByMinutes(5);
    executeAllJobs();
    assertEquals(1, piq.count());
    assertEquals(1, jobQuery.count());

    moveByMinutes(5);
    executeAllJobs();
    assertEquals(1, piq.count());

    assertEquals(1, jobQuery.count());
    // have to manually delete pending timer
//    cleanDB();

  }
 
Example #20
Source File: MultiTenancyProcessDefinitionSuspensionStateTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void suspendProcessDefinitionIncludeInstancesForNonTenant() {
  // given activated process instances
  ProcessInstanceQuery query = engineRule.getRuntimeService().createProcessInstanceQuery();
  assertThat(query.active().count(), is(3L));
  assertThat(query.suspended().count(), is(0L));

  engineRule.getRepositoryService()
    .updateProcessDefinitionSuspensionState()
    .byProcessDefinitionKey(PROCESS_DEFINITION_KEY)
    .processDefinitionWithoutTenantId()
    .includeProcessInstances(true)
    .suspend();

  assertThat(query.active().count(), is(2L));
  assertThat(query.suspended().count(), is(1L));
  assertThat(query.suspended().withoutTenantId().count(), is(1L));
}
 
Example #21
Source File: MultiTenancyProcessDefinitionSuspensionStateTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void activateProcessDefinitionIncludeInstancesForTenant() {
  // given suspended process instances
  engineRule.getRepositoryService()
    .updateProcessDefinitionSuspensionState()
    .byProcessDefinitionKey(PROCESS_DEFINITION_KEY)
    .includeProcessInstances(true)
    .suspend();

  ProcessInstanceQuery query = engineRule.getRuntimeService().createProcessInstanceQuery();
  assertThat(query.suspended().count(), is(3L));
  assertThat(query.active().count(), is(0L));

  engineRule.getRepositoryService()
    .updateProcessDefinitionSuspensionState()
    .byProcessDefinitionKey(PROCESS_DEFINITION_KEY)
    .processDefinitionTenantId(TENANT_ONE)
    .includeProcessInstances(true)
    .activate();

  assertThat(query.suspended().count(), is(2L));
  assertThat(query.active().count(), is(1L));
  assertThat(query.active().tenantIdIn(TENANT_ONE).count(), is(1L));
}
 
Example #22
Source File: ProcessInstanceQueryOrTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources={"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"})
public void shouldReturnProcInstWithVariableValueEqualsOrVariableValueGreaterThan() {
  // given
  Map<String, Object> vars = new HashMap<>();
  vars.put("longVar", 12345L);
  runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);

  vars = new HashMap<>();
  vars.put("longerVar", 56789L);
  runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);

  vars = new HashMap<>();
  vars.put("longerVar", 56789L);
  runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);

  // when
  ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery()
      .or()
        .variableValueEquals("longVar", 12345L)
        .variableValueGreaterThan("longerVar", 20000L)
      .endOr();

  // then
  assertEquals(3, query.count());
}
 
Example #23
Source File: ProcessInstanceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = {
    "org/camunda/bpm/engine/test/api/cmmn/oneProcessTaskCase.cmmn",
    "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"
  })
public void testQueryByCaseInstanceId() {
  String caseInstanceId = caseService
    .withCaseDefinitionByKey("oneProcessTaskCase")
    .create()
    .getId();

  ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery();

  query.caseInstanceId(caseInstanceId);

  assertEquals(1, query.count());

  List<ProcessInstance> result = query.list();
  assertEquals(1, result.size());

  ProcessInstance processInstance = result.get(0);
  assertEquals(caseInstanceId, processInstance.getCaseInstanceId());
}
 
Example #24
Source File: BoundedNumberOfMaxResultsTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnUnboundedResults_NotAuthenticated() {
  // given
  identityService.clearAuthentication();

  ProcessInstanceQuery processInstanceQuery =
      runtimeService.createProcessInstanceQuery();

  // when
  List<ProcessInstance> processInstances = processInstanceQuery.list();

  // then
  assertThat(processInstances.size()).isEqualTo(0);
}
 
Example #25
Source File: MigrationHistoricProcessInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #26
Source File: MultiTenancySignalReceiveTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void sendSignalToStartEventForTenant() {
  testRule.deployForTenant(TENANT_ONE, SIGNAL_START_PROCESS);
  testRule.deployForTenant(TENANT_TWO, SIGNAL_START_PROCESS);

  engineRule.getRuntimeService().createSignalEvent("signal").tenantId(TENANT_ONE).send();
  engineRule.getRuntimeService().createSignalEvent("signal").tenantId(TENANT_TWO).send();

  ProcessInstanceQuery query = engineRule.getRuntimeService().createProcessInstanceQuery();
  assertThat(query.tenantIdIn(TENANT_ONE).count(), is(1L));
  assertThat(query.tenantIdIn(TENANT_TWO).count(), is(1L));
}
 
Example #27
Source File: ProcessInstanceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryByInvalidIncidentId() {
  ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery();

  assertEquals(0, query.incidentId("invalid").count());

  try {
    query.incidentId(null);
    fail();
  } catch (ProcessEngineException ignored) {}
}
 
Example #28
Source File: ProcessInstanceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryNoSpecificsSingleResult() {
  ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery();
  try {
    query.singleResult();
    fail();
  } catch (ProcessEngineException e) {
    // Exception is expected
  }
}
 
Example #29
Source File: ExternalTaskRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected UpdateExternalTaskRetriesBuilder updateRetries(SetRetriesForExternalTasksDto retriesDto) {

    ExternalTaskService externalTaskService = getProcessEngine().getExternalTaskService();

    List<String> externalTaskIds = retriesDto.getExternalTaskIds();
    List<String> processInstanceIds = retriesDto.getProcessInstanceIds();

    ExternalTaskQuery externalTaskQuery = null;
    ProcessInstanceQuery processInstanceQuery = null;
    HistoricProcessInstanceQuery historicProcessInstanceQuery = null;

    ExternalTaskQueryDto externalTaskQueryDto = retriesDto.getExternalTaskQuery();
    if (externalTaskQueryDto != null) {
      externalTaskQuery = externalTaskQueryDto.toQuery(getProcessEngine());
    }

    ProcessInstanceQueryDto processInstanceQueryDto = retriesDto.getProcessInstanceQuery();
    if (processInstanceQueryDto != null) {
      processInstanceQuery = processInstanceQueryDto.toQuery(getProcessEngine());
    }

    HistoricProcessInstanceQueryDto historicProcessInstanceQueryDto = retriesDto.getHistoricProcessInstanceQuery();
    if (historicProcessInstanceQueryDto != null) {
      historicProcessInstanceQuery = historicProcessInstanceQueryDto.toQuery(getProcessEngine());
    }

    return externalTaskService.updateRetries()
      .externalTaskIds(externalTaskIds)
      .processInstanceIds(processInstanceIds)
      .externalTaskQuery(externalTaskQuery)
      .processInstanceQuery(processInstanceQuery)
      .historicProcessInstanceQuery(historicProcessInstanceQuery);
  }
 
Example #30
Source File: MultiTenancyMessageCorrelationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void correlateMessageToStartEventWithTenantId() {
  testRule.deployForTenant(TENANT_ONE, MESSAGE_START_PROCESS);
  testRule.deployForTenant(TENANT_TWO, MESSAGE_START_PROCESS);

  engineRule.getRuntimeService().createMessageCorrelation("message")
    .tenantId(TENANT_ONE)
    .correlate();

  ProcessInstanceQuery query = engineRule.getRuntimeService().createProcessInstanceQuery();
  assertThat(query.tenantIdIn(TENANT_ONE).count(), is(1L));
  assertThat(query.tenantIdIn(TENANT_TWO).count(), is(0L));
}