org.camunda.bpm.engine.repository.ProcessDefinitionQuery Java Examples

The following examples show how to use org.camunda.bpm.engine.repository.ProcessDefinitionQuery. 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: MultiTenancyProcessDefinitionCmdsTenantCheckTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteProcessDefinitionWithAuthenticatedTenant() {
  //given deployment with two process definitions
  Deployment deployment = testRule.deployForTenant(TENANT_ONE, "org/camunda/bpm/engine/test/repository/twoProcesses.bpmn20.xml");
  ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId());
  List<ProcessDefinition> processDefinitions = processDefinitionQuery.list();
  //and user with tenant authentication
  identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE));

  //when delete process definition with authenticated user
  repositoryService.deleteProcessDefinition(processDefinitions.get(0).getId());

  //then process definition should be deleted
  identityService.clearAuthentication();
  assertThat(processDefinitionQuery.count(), is(1L));
  assertThat(processDefinitionQuery.tenantIdIn(TENANT_ONE).count(), is(1L));
}
 
Example #2
Source File: MultiTenancyProcessDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testQueryByKey() {
  ProcessDefinitionQuery query = repositoryService
      .createProcessDefinitionQuery()
      .processDefinitionKey(PROCESS_DEFINITION_KEY);
  // one definition for each tenant
  assertThat(query.count(), is(3L));

  query = repositoryService
      .createProcessDefinitionQuery()
      .processDefinitionKey(PROCESS_DEFINITION_KEY)
      .withoutTenantId();
  // one definition without tenant id
  assertThat(query.count(), is(1L));

  query = repositoryService
      .createProcessDefinitionQuery()
      .processDefinitionKey(PROCESS_DEFINITION_KEY)
      .tenantIdIn(TENANT_ONE);
  // one definition for tenant one
  assertThat(query.count(), is(1L));
}
 
Example #3
Source File: ProcessDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@org.camunda.bpm.engine.test.Deployment(resources={"org/camunda/bpm/engine/test/api/repository/failingProcessCreateOneIncident.bpmn20.xml"})
public void testQueryByIncidentType() {
  assertThat(repositoryService.createProcessDefinitionQuery()
      .processDefinitionKey("failingProcess")
      .count()).isEqualTo(1);

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("failingProcess");

  testRule.waitForJobExecutorToProcessAllJobs();

  List<Incident> incidentList = runtimeService.createIncidentQuery().list();
  assertThat(incidentList).hasSize(1);

  Incident incident = runtimeService.createIncidentQuery().processInstanceId(processInstance.getId()).singleResult();

  ProcessDefinitionQuery query = repositoryService
      .createProcessDefinitionQuery()
      .incidentType(incident.getIncidentType());

  verifyQueryResults(query, 1);
}
 
Example #4
Source File: ProcessDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@org.camunda.bpm.engine.test.Deployment(resources={"org/camunda/bpm/engine/test/api/repository/failingProcessCreateOneIncident.bpmn20.xml"})
public void testQueryByIncidentMessageLike() {
  assertThat(repositoryService.createProcessDefinitionQuery()
      .processDefinitionKey("failingProcess")
      .count()).isEqualTo(1);

  runtimeService.startProcessInstanceByKey("failingProcess");

  testRule.waitForJobExecutorToProcessAllJobs();

  List<Incident> incidentList = runtimeService.createIncidentQuery().list();
  assertThat(incidentList).hasSize(1);

  ProcessDefinitionQuery query = repositoryService
      .createProcessDefinitionQuery()
      .incidentMessageLike("%expected%");

  verifyQueryResults(query, 1);

  query = repositoryService
      .createProcessDefinitionQuery()
      .incidentMessageLike("%\\_expected%");

  verifyQueryResults(query, 1);
}
 
Example #5
Source File: MultiTenancyProcessDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testQueryByLatestWithTenantIds() {
  // deploy a second version for tenant one
  deploymentForTenant(TENANT_ONE, emptyProcess);

  ProcessDefinitionQuery query = repositoryService
      .createProcessDefinitionQuery()
      .processDefinitionKey(PROCESS_DEFINITION_KEY)
      .latestVersion()
      .tenantIdIn(TENANT_ONE, TENANT_TWO);
  // one definition for each tenant
  assertThat(query.count(), is(2L));

  Map<String, ProcessDefinition> processDefinitionsForTenant = getProcessDefinitionsForTenant(query.list());
  assertThat(processDefinitionsForTenant.get(TENANT_ONE).getVersion(), is(2));
  assertThat(processDefinitionsForTenant.get(TENANT_TWO).getVersion(), is(1));
}
 
Example #6
Source File: TestAdditionalResourceSuffixes.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeployProcessArchive() {
  assertNotNull(processEngine);
  RepositoryService repositoryService = processEngine.getRepositoryService();

  ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery()
    .processDefinitionKey("invoice-it");

  assertEquals(1, processDefinitionQuery.count());
  ProcessDefinition processDefinition = processDefinitionQuery.singleResult();

  String deploymentId = repositoryService.createDeploymentQuery()
    .deploymentId(processDefinition.getDeploymentId())
    .singleResult()
    .getId();
  List<Resource> deploymentResources = repositoryService.getDeploymentResources(deploymentId);
  assertEquals(3, deploymentResources.size());
}
 
Example #7
Source File: ProcessDefinitionAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testQueryWithGroupAuthorizationRevokedReadPermission() {
  // given
  // given user gets all permissions on any process definition
  Authorization authorization = createGrantAuthorization(PROCESS_DEFINITION, ANY);
  authorization.setGroupId(groupId);
  authorization.addPermission(ALL);
  saveAuthorization(authorization);

  authorization = createRevokeAuthorization(PROCESS_DEFINITION, ONE_TASK_PROCESS_KEY);
  authorization.setGroupId(groupId);
  authorization.removePermission(READ);
  saveAuthorization(authorization);

  // when
  ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery();

  // then
  verifyQueryResults(query, 1);

  ProcessDefinition definition = query.singleResult();
  assertNotNull(definition);
  assertEquals(TWO_TASKS_PROCESS_KEY, definition.getKey());
}
 
Example #8
Source File: MultiTenancyProcessDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testQueryByLatestWithoutTenantId() {
  // deploy a second version without tenant id
  deployment(emptyProcess);

  ProcessDefinitionQuery query = repositoryService
      .createProcessDefinitionQuery()
      .processDefinitionKey(PROCESS_DEFINITION_KEY)
      .latestVersion()
      .withoutTenantId();

  assertThat(query.count(), is(1L));

  ProcessDefinition processDefinition = query.singleResult();
  assertThat(processDefinition.getTenantId(), is(nullValue()));
  assertThat(processDefinition.getVersion(), is(2));
}
 
Example #9
Source File: MultiTenancyProcessDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testQueryByLatestWithTenantIdsIncludeDefinitionsWithoutTenantId() {
  // deploy a second version without tenant id
  deployment(emptyProcess);
  // deploy a third version for tenant one
  deploymentForTenant(TENANT_ONE, emptyProcess);
  deploymentForTenant(TENANT_ONE, emptyProcess);

  ProcessDefinitionQuery query = repositoryService
      .createProcessDefinitionQuery()
      .processDefinitionKey(PROCESS_DEFINITION_KEY)
      .latestVersion()
      .tenantIdIn(TENANT_ONE, TENANT_TWO)
      .includeProcessDefinitionsWithoutTenantId();

  assertThat(query.count(), is(3L));

  Map<String, ProcessDefinition> processDefinitionsForTenant = getProcessDefinitionsForTenant(query.list());
  assertThat(processDefinitionsForTenant.get(TENANT_ONE).getVersion(), is(3));
  assertThat(processDefinitionsForTenant.get(TENANT_TWO).getVersion(), is(1));
  assertThat(processDefinitionsForTenant.get(null).getVersion(), is(2));
}
 
Example #10
Source File: ProcessDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryOrderByDeployTime() {
  // given a deployment that is guaranteed to be deployed later than the default deployments
  ClockUtil.offset(TimeUnit.MINUTES.toMillis(10));
  Deployment tempDeploymentOne = repositoryService.createDeployment()
      .addClasspathResource(getResourceOnePath()).addClasspathResource(getResourceOnePath()).deploy();
  engineRule.manageDeployment(tempDeploymentOne);
  
  // when
  ProcessDefinitionQuery processDefinitionOrderByDeploymentTimeAscQuery = 
      repositoryService.createProcessDefinitionQuery().orderByDeploymentTime().asc();
  ProcessDefinitionQuery processDefinitionOrderByDeploymentTimeDescQuery = 
      repositoryService.createProcessDefinitionQuery().orderByDeploymentTime().desc();

  // then
  verifySortingAndCount(processDefinitionOrderByDeploymentTimeAscQuery, 5, 
      processDefinitionByDeployTime(engineRule.getProcessEngine()));
  verifySortingAndCount(processDefinitionOrderByDeploymentTimeDescQuery, 5, 
      inverted(processDefinitionByDeployTime(engineRule.getProcessEngine())));
}
 
Example #11
Source File: ProcessDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@org.camunda.bpm.engine.test.Deployment(resources={"org/camunda/bpm/engine/test/api/repository/failingProcessCreateOneIncident.bpmn20.xml"})
public void testQueryByIncidentId() {
  assertThat(repositoryService.createProcessDefinitionQuery()
      .processDefinitionKey("failingProcess")
      .count()).isEqualTo(1);

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("failingProcess");

  testRule.waitForJobExecutorToProcessAllJobs();

  List<Incident> incidentList = runtimeService.createIncidentQuery().list();
  assertThat(incidentList.size()).isEqualTo(1);

  Incident incident = runtimeService.createIncidentQuery().processInstanceId(processInstance.getId()).singleResult();

  ProcessDefinitionQuery query = repositoryService
      .createProcessDefinitionQuery()
      .incidentId(incident.getId());

  verifyQueryResults(query, 1);
}
 
Example #12
Source File: MultiTenancyProcessDefinitionCmdsTenantCheckTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteCascadeProcessDefinitionWithAuthenticatedTenant() {
  //given deployment with a process definition and process instance
  BpmnModelInstance bpmnModel = Bpmn.createExecutableProcess("process").startEvent().userTask().endEvent().done();
  testRule.deployForTenant(TENANT_ONE, bpmnModel);
  ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
  ProcessDefinition processDefinition = processDefinitionQuery.processDefinitionKey("process").singleResult();
  engineRule.getRuntimeService().createProcessInstanceByKey("process").executeWithVariablesInReturn();

  //and user with tenant authentication
  identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE));

  //when the corresponding process definition is cascading deleted from the deployment
  repositoryService.deleteProcessDefinition(processDefinition.getId(), true);

  //then exist no process instance and one definition
  identityService.clearAuthentication();
  assertEquals(0, engineRule.getRuntimeService().createProcessInstanceQuery().count());
  if (processEngineConfiguration.getHistoryLevel().getId() >= HistoryLevel.HISTORY_LEVEL_ACTIVITY.getId()) {
    assertEquals(0, engineRule.getHistoryService().createHistoricActivityInstanceQuery().count());
  }
  assertThat(repositoryService.createProcessDefinitionQuery().count(), is(1L));
  assertThat(repositoryService.createProcessDefinitionQuery().tenantIdIn(TENANT_ONE).count(), is(1L));
}
 
Example #13
Source File: MultiTenancyProcessDefinitionCmdsTenantCheckTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteProcessDefinitionDisabledTenantCheck() {
  //given deployment with two process definitions
  Deployment deployment = testRule.deployForTenant(TENANT_ONE, "org/camunda/bpm/engine/test/repository/twoProcesses.bpmn20.xml");
  //tenant check disabled
  processEngineConfiguration.setTenantCheckEnabled(false);
  ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId());
  List<ProcessDefinition> processDefinitions = processDefinitionQuery.list();
  //user with no authentication
  identityService.setAuthentication("user", null, null);

  //when process definition should be deleted without tenant check
  repositoryService.deleteProcessDefinition(processDefinitions.get(0).getId());

  //then process definition is deleted
  identityService.clearAuthentication();
  assertThat(processDefinitionQuery.count(), is(1L));
  assertThat(processDefinitionQuery.tenantIdIn(TENANT_ONE).count(), is(1L));
}
 
Example #14
Source File: MultiTenancyProcessDefinitionCmdsTenantCheckTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteCascadeProcessDefinitionDisabledTenantCheck() {
  //given deployment with a process definition and process instances
  BpmnModelInstance bpmnModel = Bpmn.createExecutableProcess("process").startEvent().userTask().endEvent().done();
  testRule.deployForTenant(TENANT_ONE, bpmnModel);
  //tenant check disabled
  processEngineConfiguration.setTenantCheckEnabled(false);
  ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
  ProcessDefinition processDefinition = processDefinitionQuery.processDefinitionKey("process").singleResult();
  engineRule.getRuntimeService().createProcessInstanceByKey("process").executeWithVariablesInReturn();
  //user with no authentication
  identityService.setAuthentication("user", null, null);

  //when the corresponding process definition is cascading deleted from the deployment
  repositoryService.deleteProcessDefinition(processDefinition.getId(), true);

  //then exist no process instance and one definition, because test case deployes per default one definition
  identityService.clearAuthentication();
  assertEquals(0, engineRule.getRuntimeService().createProcessInstanceQuery().count());
  if (processEngineConfiguration.getHistoryLevel().getId() >= HistoryLevel.HISTORY_LEVEL_ACTIVITY.getId()) {
    assertEquals(0, engineRule.getHistoryService().createHistoricActivityInstanceQuery().count());
  }
  assertThat(repositoryService.createProcessDefinitionQuery().count(), is(1L));
  assertThat(repositoryService.createProcessDefinitionQuery().tenantIdIn(TENANT_ONE).count(), is(1L));
}
 
Example #15
Source File: MultiTenancyProcessDefinitionSuspensionStateTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void activateProcessDefinitionForTenant() {
  // given suspend process definitions
  engineRule.getRepositoryService()
    .updateProcessDefinitionSuspensionState()
    .byProcessDefinitionKey(PROCESS_DEFINITION_KEY)
    .suspend();

  ProcessDefinitionQuery query = engineRule.getRepositoryService().createProcessDefinitionQuery();
  assertThat(query.suspended().count(), is(3L));
  assertThat(query.active().count(), is(0L));

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

  assertThat(query.suspended().count(), is(2L));
  assertThat(query.active().count(), is(1L));
  assertThat(query.active().tenantIdIn(TENANT_ONE).count(), is(1L));
}
 
Example #16
Source File: MultiTenancyProcessDefinitionSuspensionStateTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void suspendProcessDefinitionDisabledTenantCheck() {
  // given activated process definitions
  ProcessDefinitionQuery query = engineRule.getRepositoryService().createProcessDefinitionQuery();
  assertThat(query.active().count(), is(3L));
  assertThat(query.suspended().count(), is(0L));

  ProcessEngineConfigurationImpl processEngineConfiguration = engineRule.getProcessEngineConfiguration();
  processEngineConfiguration.setTenantCheckEnabled(false);
  engineRule.getIdentityService().setAuthentication("user", null, null);

  engineRule.getRepositoryService()
    .updateProcessDefinitionSuspensionState()
    .byProcessDefinitionKey(PROCESS_DEFINITION_KEY)
    .suspend();

  assertThat(query.active().count(), is(0L));
  assertThat(query.suspended().count(), is(3L));
  assertThat(query.suspended().tenantIdIn(TENANT_ONE, TENANT_TWO).includeProcessDefinitionsWithoutTenantId().count(), is(3L));
}
 
Example #17
Source File: MultiTenancyProcessDefinitionSuspensionStateTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void delayedSuspendProcessDefinitionsForAllTenants() {
  // given activated process definitions

  engineRule.getRepositoryService()
    .updateProcessDefinitionSuspensionState()
    .byProcessDefinitionKey(PROCESS_DEFINITION_KEY)
    .executionDate(tomorrow())
    .suspend();

  ProcessDefinitionQuery query = engineRule.getRepositoryService().createProcessDefinitionQuery();
  assertThat(query.active().count(), is(3L));
  assertThat(query.suspended().count(), is(0L));

  // when execute the job to suspend the process definitions
  Job job = engineRule.getManagementService().createJobQuery().timers().singleResult();
  assertThat(job, is(notNullValue()));
  List<String> expectedDeploymentIds = query.active().list().stream().map(ProcessDefinition::getDeploymentId).collect(Collectors.toList());
  assertThat(expectedDeploymentIds, hasItem(job.getDeploymentId()));

  engineRule.getManagementService().executeJob(job.getId());

  assertThat(query.active().count(), is(0L));
  assertThat(query.suspended().count(), is(3L));
}
 
Example #18
Source File: MultiTenancyProcessDefinitionSuspensionStateTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void suspendProcessDefinitionWithAuthenticatedTenant() {
  // given activated process definitions
  ProcessDefinitionQuery query = engineRule.getRepositoryService().createProcessDefinitionQuery();
  assertThat(query.active().count(), is(3L));
  assertThat(query.suspended().count(), is(0L));

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

  engineRule.getRepositoryService()
    .updateProcessDefinitionSuspensionState()
    .byProcessDefinitionKey(PROCESS_DEFINITION_KEY)
    .suspend();

  engineRule.getIdentityService().clearAuthentication();

  assertThat(query.active().count(), is(1L));
  assertThat(query.suspended().count(), is(2L));
  assertThat(query.active().tenantIdIn(TENANT_TWO).count(), is(1L));
  assertThat(query.suspended().tenantIdIn(TENANT_ONE).count(), is(1L));
  assertThat(query.suspended().withoutTenantId().count(), is(1L));
}
 
Example #19
Source File: ProcessDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryByLatestAndName_NotFound() {
  String firstDeployment = repositoryService
      .createDeployment()
      .addClasspathResource("org/camunda/bpm/engine/test/api/repository/first-process.bpmn20.xml")
      .deploy()
      .getId();

  String secondDeployment = repositoryService
      .createDeployment()
      .addClasspathResource("org/camunda/bpm/engine/test/api/repository/second-process.bpmn20.xml")
      .deploy()
      .getId();

  ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery();

  query
    .processDefinitionName("First Test Process")
    .latestVersion();

  verifyQueryResults(query, 0);

  repositoryService.deleteDeployment(firstDeployment, true);
  repositoryService.deleteDeployment(secondDeployment, true);

}
 
Example #20
Source File: ProcessDefinitionQueryDto.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
protected void applySortBy(ProcessDefinitionQuery query, String sortBy, Map<String, Object> parameters, ProcessEngine engine) {
  if (sortBy.equals(SORT_BY_CATEGORY_VALUE)) {
    query.orderByProcessDefinitionCategory();
  } else if (sortBy.equals(SORT_BY_KEY_VALUE)) {
    query.orderByProcessDefinitionKey();
  } else if (sortBy.equals(SORT_BY_ID_VALUE)) {
    query.orderByProcessDefinitionId();
  } else if (sortBy.equals(SORT_BY_VERSION_VALUE)) {
    query.orderByProcessDefinitionVersion();
  } else if (sortBy.equals(SORT_BY_NAME_VALUE)) {
    query.orderByProcessDefinitionName();
  } else if (sortBy.equals(SORT_BY_DEPLOYMENT_ID_VALUE)) {
    query.orderByDeploymentId();
  } else if (sortBy.equals(SORT_BY_DEPLOY_TIME_VALUE)) {
    query.orderByDeploymentTime();
  } else if (sortBy.equals(SORT_BY_TENANT_ID)) {
    query.orderByTenantId();
  } else if (sortBy.equals(SORT_BY_VERSION_TAG)) {
    query.orderByVersionTag();
  }
}
 
Example #21
Source File: ExecutionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQueryByInvalidIncidentMessage() {
  ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery();

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

  try {
    query.incidentMessage(null);
    fail();
  } catch (ProcessEngineException e) {}
}
 
Example #22
Source File: ProcessApplicationDeploymentTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessApplicationAndNullDeploymentSourceAwareDuplicateFilter() {
  // given

  String key = "process";
  String name = "my-deployment";

  BpmnModelInstance model = Bpmn.createExecutableProcess(key).done();

  ProcessDefinitionQuery processDefinitionQuery = repositoryService
      .createProcessDefinitionQuery()
      .processDefinitionKey(key);

  DeploymentQuery deploymentQuery = repositoryService
      .createDeploymentQuery()
      .deploymentName(name);

  // when

  testRule.deploy(repositoryService
      .createDeployment(processApplication.getReference())
      .name(name)
      .addModelInstance("process.bpmn", model)
      .enableDuplicateFiltering(true));

  assertEquals(1, processDefinitionQuery.count());
  assertEquals(1, deploymentQuery.count());

  testRule.deploy(repositoryService
      .createDeployment(processApplication.getReference())
      .name(name)
      .source(null)
      .addModelInstance("process.bpmn", model)
      .enableDuplicateFiltering(true));

  // then

  assertEquals(1, processDefinitionQuery.count());
  assertEquals(1, deploymentQuery.count());
}
 
Example #23
Source File: ProcessDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryByInvalidKey() {
  ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery().processDefinitionKey("invalid");
  verifyQueryResults(query, 0);

  exceptionRule.expect(ProcessEngineException.class);
  repositoryService.createProcessDefinitionQuery().processDefinitionKey(null);
}
 
Example #24
Source File: RedeploymentTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testRedeployAllDeploymentResources() {
  // given
  ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery();

  BpmnModelInstance model1 = createProcessWithServiceTask(PROCESS_1_KEY);
  BpmnModelInstance model2 = createProcessWithUserTask(PROCESS_2_KEY);

  // first deployment
  Deployment deployment1 = testRule.deploy(repositoryService
      .createDeployment()
      .name(DEPLOYMENT_NAME)
      .addModelInstance(RESOURCE_1_NAME, model1)
      .addModelInstance(RESOURCE_2_NAME, model2));

  verifyQueryResults(query.processDefinitionKey(PROCESS_1_KEY), 1);
  verifyQueryResults(query.processDefinitionKey(PROCESS_2_KEY), 1);

  // second deployment
  testRule.deploy(repositoryService
      .createDeployment()
      .name(DEPLOYMENT_NAME)
      .addModelInstance(RESOURCE_1_NAME, model2)
      .addModelInstance(RESOURCE_2_NAME, model1));

  verifyQueryResults(query.processDefinitionKey(PROCESS_1_KEY), 2);
  verifyQueryResults(query.processDefinitionKey(PROCESS_2_KEY), 2);

  // when
  testRule.deploy(repositoryService
      .createDeployment()
      .name(DEPLOYMENT_NAME)
      .addDeploymentResources(deployment1.getId()));

  // then
  verifyQueryResults(query.processDefinitionKey(PROCESS_1_KEY), 3);
  verifyQueryResults(query.processDefinitionKey(PROCESS_2_KEY), 3);
}
 
Example #25
Source File: MultiTenancyProcessDefinitionSuspensionStateTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void delayedActivateProcessDefinitionsForNonTenant() {
  // given suspended process definitions
  engineRule.getRepositoryService()
    .updateProcessDefinitionSuspensionState()
    .byProcessDefinitionKey(PROCESS_DEFINITION_KEY)
    .suspend();

  engineRule.getRepositoryService()
    .updateProcessDefinitionSuspensionState()
    .byProcessDefinitionKey(PROCESS_DEFINITION_KEY)
    .processDefinitionWithoutTenantId()
    .executionDate(tomorrow())
    .activate();

  ProcessDefinitionQuery query = engineRule.getRepositoryService().createProcessDefinitionQuery();
  assertThat(query.suspended().count(), is(3L));
  assertThat(query.active().count(), is(0L));

  // when execute the job to activate the process definition
  Job job = engineRule.getManagementService().createJobQuery().timers().singleResult();
  assertThat(job, is(notNullValue()));
  String expectedDeploymentId = engineRule.getRepositoryService().createProcessDefinitionQuery()
      .suspended().withoutTenantId().singleResult().getDeploymentId();
  assertThat(job.getDeploymentId(), is(expectedDeploymentId));

  engineRule.getManagementService().executeJob(job.getId());

  assertThat(query.suspended().count(), is(2L));
  assertThat(query.active().count(), is(1L));
  assertThat(query.active().withoutTenantId().count(), is(1L));
}
 
Example #26
Source File: StatisticsRestTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private void setupProcessDefinitionMock() {
  ProcessDefinition mockDefinition = MockProvider.createMockDefinition();
  processDefinitionQueryMock = mock(ProcessDefinitionQuery.class);
  when(processDefinitionQueryMock.processDefinitionKey(MockProvider.EXAMPLE_PROCESS_DEFINITION_KEY)).thenReturn(processDefinitionQueryMock);
  when(processDefinitionQueryMock.tenantIdIn(anyString())).thenReturn(processDefinitionQueryMock);
  when(processDefinitionQueryMock.withoutTenantId()).thenReturn(processDefinitionQueryMock);
  when(processDefinitionQueryMock.latestVersion()).thenReturn(processDefinitionQueryMock);
  when(processDefinitionQueryMock.singleResult()).thenReturn(mockDefinition);
  when(processDefinitionQueryMock.list()).thenReturn(Collections.singletonList(mockDefinition));
  when(processDefinitionQueryMock.count()).thenReturn(1L);
  when(processEngine.getRepositoryService().createProcessDefinitionQuery()).thenReturn(processDefinitionQueryMock);
}
 
Example #27
Source File: ProcessDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryByNameLike() {
  ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery().processDefinitionNameLike("%w%");
  verifyQueryResults(query, 1);
  query = query.processDefinitionNameLike("%z\\_%");
  verifyQueryResults(query, 1);
}
 
Example #28
Source File: MultiTenancyProcessDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQueryByTenantId() {
  ProcessDefinitionQuery query = repositoryService
      .createProcessDefinitionQuery()
      .tenantIdIn(TENANT_ONE);

  assertThat(query.count(), is(1L));

  query = repositoryService.
      createProcessDefinitionQuery()
      .tenantIdIn(TENANT_TWO);

  assertThat(query.count(), is(1L));
}
 
Example #29
Source File: ProcessDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryByInvalidName() {
  ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery().processDefinitionName("invalid");
  verifyQueryResults(query, 0);

  exceptionRule.expect(ProcessEngineException.class);
  repositoryService.createProcessDefinitionQuery().processDefinitionName(null);
}
 
Example #30
Source File: WorkflowEngineService.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
public ProcessInstance startProcessInstance(String processDefinitionId, String processInstanceKey) {
	if (StringUtils.isBlank(processDefinitionId)) {
		throw new IllegalArgumentException("Process definition ID is blank.");
	}

	if (log.isDebugEnabled()) {
		log.debug("try to start process instance with id {} and key {}", processDefinitionId, processInstanceKey);
	}

	ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery()
			.processDefinitionId(processDefinitionId);
	ProcessDefinition procDef = query.singleResult();
	if (procDef == null) {
		log.warn("such process definition did not exist,processDefinitionId={}", processDefinitionId);
		throw new WecubeCoreException(
				String.format("Such proccess definition [%s] does not exist.", processDefinitionId));
	}

	ProcessInstance instance = runtimeService.startProcessInstanceById(processDefinitionId, processInstanceKey);

	if (instance == null) {
		log.warn("Failed to create process instance with id {} and key {}", processDefinitionId,
				processInstanceKey);
		throw new WecubeCoreException(String.format("Failed to create process instance with id %s and key %s.",
				processDefinitionId, processInstanceKey));
	}

	return instance;
}