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

The following examples show how to use org.camunda.bpm.engine.repository.CaseDefinitionQuery. 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: CaseDefinitionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
private void setUpRuntimeData(CaseDefinition mockCaseDefinition) {
  repositoryServiceMock = mock(RepositoryService.class);

  when(processEngine.getRepositoryService()).thenReturn(repositoryServiceMock);
  when(repositoryServiceMock.getCaseDefinition(eq(MockProvider.EXAMPLE_CASE_DEFINITION_ID))).thenReturn(mockCaseDefinition);
  when(repositoryServiceMock.getCaseModel(eq(MockProvider.EXAMPLE_CASE_DEFINITION_ID))).thenReturn(createMockCaseDefinitionCmmnXml());

  caseDefinitionQueryMock = mock(CaseDefinitionQuery.class);
  when(caseDefinitionQueryMock.caseDefinitionKey(MockProvider.EXAMPLE_CASE_DEFINITION_KEY)).thenReturn(caseDefinitionQueryMock);
  when(caseDefinitionQueryMock.tenantIdIn(anyString())).thenReturn(caseDefinitionQueryMock);
  when(caseDefinitionQueryMock.withoutTenantId()).thenReturn(caseDefinitionQueryMock);
  when(caseDefinitionQueryMock.latestVersion()).thenReturn(caseDefinitionQueryMock);
  when(caseDefinitionQueryMock.singleResult()).thenReturn(mockCaseDefinition);
  when(caseDefinitionQueryMock.list()).thenReturn(Collections.singletonList(mockCaseDefinition));
  when(repositoryServiceMock.createCaseDefinitionQuery()).thenReturn(caseDefinitionQueryMock);
}
 
Example #2
Source File: CaseDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryByKey() {
  CaseDefinitionQuery query = repositoryService.createCaseDefinitionQuery();

  // case one
  query
    .caseDefinitionKey("one");

  verifyQueryResults(query, 2);

  // case two
  query
    .caseDefinitionKey("two");

  verifyQueryResults(query, 1);
}
 
Example #3
Source File: CaseDefinitionRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public List<CaseDefinitionDto> getCaseDefinitions(UriInfo uriInfo, Integer firstResult, Integer maxResults) {
  CaseDefinitionQueryDto queryDto = new CaseDefinitionQueryDto(getObjectMapper(), uriInfo.getQueryParameters());
  List<CaseDefinitionDto> definitions = new ArrayList<CaseDefinitionDto>();

  ProcessEngine engine = getProcessEngine();
  CaseDefinitionQuery query = queryDto.toQuery(engine);

  List<CaseDefinition> matchingDefinitions = null;

  if (firstResult != null || maxResults != null) {
    matchingDefinitions = executePaginatedQuery(query, firstResult, maxResults);
  } else {
    matchingDefinitions = query.list();
  }

  for (CaseDefinition definition : matchingDefinitions) {
    CaseDefinitionDto def = CaseDefinitionDto.fromCaseDefinition(definition);
    definitions.add(def);
  }
  return definitions;
}
 
Example #4
Source File: CaseDefinitionQueryDto.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
protected void applySortBy(CaseDefinitionQuery query, String sortBy, Map<String, Object> parameters, ProcessEngine engine) {
  if (sortBy.equals(SORT_BY_CATEGORY_VALUE)) {
    query.orderByCaseDefinitionCategory();
  } else if (sortBy.equals(SORT_BY_KEY_VALUE)) {
    query.orderByCaseDefinitionKey();
  } else if (sortBy.equals(SORT_BY_ID_VALUE)) {
    query.orderByCaseDefinitionId();
  } else if (sortBy.equals(SORT_BY_VERSION_VALUE)) {
    query.orderByCaseDefinitionVersion();
  } else if (sortBy.equals(SORT_BY_NAME_VALUE)) {
    query.orderByCaseDefinitionName();
  } else if (sortBy.equals(SORT_BY_DEPLOYMENT_ID_VALUE)) {
    query.orderByDeploymentId();
  } else if (sortBy.equals(SORT_BY_TENANT_ID)) {
    query.orderByTenantId();
  }
}
 
Example #5
Source File: MultiTenancyCaseDefinitionQueryTest.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(CMMN);
  // deploy a third version for tenant one
  deploymentForTenant(TENANT_ONE, CMMN);
  deploymentForTenant(TENANT_ONE, CMMN);

  CaseDefinitionQuery query = repositoryService
      .createCaseDefinitionQuery()
      .caseDefinitionKey(CASE_DEFINITION_KEY)
      .latestVersion()
      .tenantIdIn(TENANT_ONE, TENANT_TWO)
      .includeCaseDefinitionsWithoutTenantId();

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

  Map<String, CaseDefinition> caseDefinitionsForTenant = getCaseDefinitionsForTenant(query.list());
  assertThat(caseDefinitionsForTenant.get(TENANT_ONE).getVersion(), is(3));
  assertThat(caseDefinitionsForTenant.get(TENANT_TWO).getVersion(), is(1));
  assertThat(caseDefinitionsForTenant.get(null).getVersion(), is(2));
}
 
Example #6
Source File: CaseDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryByLatest() {
  CaseDefinitionQuery query = repositoryService.createCaseDefinitionQuery();

  query
    .latestVersion();

  verifyQueryResults(query, 3);

  query
    .caseDefinitionKey("one")
    .latestVersion();

  verifyQueryResults(query, 1);

  query
    .caseDefinitionKey("two").latestVersion();
  verifyQueryResults(query, 1);
}
 
Example #7
Source File: MultiTenancyCaseDefinitionQueryTest.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(CMMN);

  CaseDefinitionQuery query = repositoryService
      .createCaseDefinitionQuery()
      .caseDefinitionKey(CASE_DEFINITION_KEY)
      .latestVersion()
      .withoutTenantId();

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

  CaseDefinition cDefinition = query.singleResult();
  assertThat(cDefinition.getTenantId(), is(nullValue()));
  assertThat(cDefinition.getVersion(), is(2));
}
 
Example #8
Source File: MultiTenancyCaseDefinitionQueryTest.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, CMMN);

  CaseDefinitionQuery query = repositoryService
      .createCaseDefinitionQuery()
      .caseDefinitionKey(CASE_DEFINITION_KEY)
      .latestVersion()
      .tenantIdIn(TENANT_ONE, TENANT_TWO);
  // one definition for each tenant
  assertThat(query.count(), is(2L));

  Map<String, CaseDefinition> caseDefinitionsForTenant = getCaseDefinitionsForTenant(query.list());
  assertThat(caseDefinitionsForTenant.get(TENANT_ONE).getVersion(), is(2));
  assertThat(caseDefinitionsForTenant.get(TENANT_TWO).getVersion(), is(1));
}
 
Example #9
Source File: MultiTenancyCaseDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testQueryByLatestNoTenantIdSet() {
  // deploy a second version for tenant one
  deploymentForTenant(TENANT_ONE, CMMN);

  CaseDefinitionQuery query = repositoryService
      .createCaseDefinitionQuery()
      .caseDefinitionKey(CASE_DEFINITION_KEY)
      .latestVersion();
  // one definition for each tenant
  assertThat(query.count(), is(3L));

  Map<String, CaseDefinition> caseDefinitionsForTenant = getCaseDefinitionsForTenant(query.list());
  assertThat(caseDefinitionsForTenant.get(TENANT_ONE).getVersion(), is(2));
  assertThat(caseDefinitionsForTenant.get(TENANT_TWO).getVersion(), is(1));
  assertThat(caseDefinitionsForTenant.get(null).getVersion(), is(1));
}
 
Example #10
Source File: MultiTenancyCaseDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testQueryByKey() {
  CaseDefinitionQuery query = repositoryService
      .createCaseDefinitionQuery()
      .caseDefinitionKey(CASE_DEFINITION_KEY);
  // one definition for each tenant
  assertThat(query.count(), is(3L));

  query = repositoryService
      .createCaseDefinitionQuery()
      .caseDefinitionKey(CASE_DEFINITION_KEY)
      .withoutTenantId();
  // one definition without tenant id
  assertThat(query.count(), is(1L));

  query = repositoryService
      .createCaseDefinitionQuery()
      .caseDefinitionKey(CASE_DEFINITION_KEY)
      .tenantIdIn(TENANT_ONE);
  // one definition for tenant one
  assertThat(query.count(), is(1L));
}
 
Example #11
Source File: MultiTenancyCaseDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testQueryByTenantIdsIncludeDefinitionsWithoutTenantId() {
  CaseDefinitionQuery query = repositoryService
      .createCaseDefinitionQuery()
      .tenantIdIn(TENANT_ONE)
      .includeCaseDefinitionsWithoutTenantId();

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

  query = repositoryService
      .createCaseDefinitionQuery()
      .tenantIdIn(TENANT_TWO)
      .includeCaseDefinitionsWithoutTenantId();

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

  query = repositoryService
      .createCaseDefinitionQuery()
      .tenantIdIn(TENANT_ONE, TENANT_TWO)
      .includeCaseDefinitionsWithoutTenantId();

  assertThat(query.count(), is(3L));
}
 
Example #12
Source File: CaseDefinitionRestServiceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private CaseDefinitionQuery createMockCaseDefinitionQuery(List<CaseDefinition> mockedDefinitions) {
  CaseDefinitionQuery sampleDefinitionsQuery = mock(CaseDefinitionQuery.class);

  when(sampleDefinitionsQuery.list()).thenReturn(mockedDefinitions);
  when(sampleDefinitionsQuery.count()).thenReturn((long) mockedDefinitions.size());
  when(processEngine.getRepositoryService().createCaseDefinitionQuery()).thenReturn(sampleDefinitionsQuery);

  return sampleDefinitionsQuery;
}
 
Example #13
Source File: CaseDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryByInvalidResourceNameLike() {
  CaseDefinitionQuery query = repositoryService.createCaseDefinitionQuery();

  query
      .caseDefinitionResourceNameLike("%invalid%");

  verifyQueryResults(query, 0);

  exceptionRule.expect(NotValidException.class);
  query.caseDefinitionNameLike(null);
}
 
Example #14
Source File: CaseDefinitionRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public CountResultDto getCaseDefinitionsCount(UriInfo uriInfo) {
  CaseDefinitionQueryDto queryDto = new CaseDefinitionQueryDto(getObjectMapper(), uriInfo.getQueryParameters());

  ProcessEngine engine = getProcessEngine();
  CaseDefinitionQuery query = queryDto.toQuery(engine);

  long count = query.count();
  CountResultDto result = new CountResultDto();
  result.setCount(count);
  return result;
}
 
Example #15
Source File: CaseDefinitionRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private List<CaseDefinition> executePaginatedQuery(CaseDefinitionQuery query, Integer firstResult, Integer maxResults) {
  if (firstResult == null) {
    firstResult = 0;
  }
  if (maxResults == null) {
    maxResults = Integer.MAX_VALUE;
  }
  return query.listPage(firstResult, maxResults);
}
 
Example #16
Source File: CaseDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidUsageOfLatest() {
  CaseDefinitionQuery query = repositoryService.createCaseDefinitionQuery();

  exceptionRule.expect(NotValidException.class);
  query
    .caseDefinitionId("test")
    .latestVersion()
    .list();


  exceptionRule.expect(NotValidException.class);
  query
    .caseDefinitionName("test")
    .latestVersion()
    .list();

  exceptionRule.expect(NotValidException.class);
  query
    .caseDefinitionNameLike("test")
    .latestVersion()
    .list();

  exceptionRule.expect(NotValidException.class);
  query
    .caseDefinitionVersion(1)
    .latestVersion()
    .list();

  exceptionRule.expect(NotValidException.class);
  query
    .deploymentId("test")
    .latestVersion()
    .list();
}
 
Example #17
Source File: CaseDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryByInvalidVersion() {
  CaseDefinitionQuery query = repositoryService.createCaseDefinitionQuery();

  query
    .caseDefinitionVersion(3);

  verifyQueryResults(query, 0);

  exceptionRule.expect(NotValidException.class);
  query.caseDefinitionVersion(-1);

  exceptionRule.expect(NotValidException.class);
  query.caseDefinitionVersion(null);
}
 
Example #18
Source File: CaseDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryByCategory() {
  CaseDefinitionQuery query = repositoryService.createCaseDefinitionQuery();

  query
    .caseDefinitionCategory("Examples");

  verifyQueryResults(query, 2);
}
 
Example #19
Source File: MultiTenancyCaseExecutionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void createCaseInstance(String tenantId) {
  String caseDefinitionId = null;

  CaseDefinitionQuery caseDefinitionQuery = repositoryService.createCaseDefinitionQuery().caseDefinitionKey("oneTaskCase");
  if (tenantId == null) {
    caseDefinitionId = caseDefinitionQuery.withoutTenantId().singleResult().getId();
  } else {
    caseDefinitionId = caseDefinitionQuery.tenantIdIn(tenantId).singleResult().getId();
  }

  caseService.withCaseDefinition(caseDefinitionId).create();
}
 
Example #20
Source File: CaseDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryByInvalidKeyLike() {
  CaseDefinitionQuery query = repositoryService.createCaseDefinitionQuery();

  query
    .caseDefinitionKeyLike("%invalid%");

  verifyQueryResults(query, 0);

  exceptionRule.expect(NotValidException.class);
  query.caseDefinitionKeyLike(null);
}
 
Example #21
Source File: CaseDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryByInvalidKey() {
  CaseDefinitionQuery query = repositoryService.createCaseDefinitionQuery();

  query
    .caseDefinitionKey("invalid");

  verifyQueryResults(query, 0);

  exceptionRule.expect(NotValidException.class);
  query.caseDefinitionKey(null);
}
 
Example #22
Source File: ProcessEngineRestServiceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private void createCaseDefinitionMock() {
  List<CaseDefinition> caseDefinitions = new ArrayList<CaseDefinition>();
  CaseDefinition mockCaseDefinition = MockProvider.createMockCaseDefinition();
  caseDefinitions.add(mockCaseDefinition);

  CaseDefinitionQuery mockCaseDefinitionQuery = mock(CaseDefinitionQuery.class);
  when(mockCaseDefinitionQuery.list()).thenReturn(caseDefinitions);
  when(mockRepoService.createCaseDefinitionQuery()).thenReturn(mockCaseDefinitionQuery);
}
 
Example #23
Source File: CaseDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryByVersion() {
  CaseDefinitionQuery query = repositoryService.createCaseDefinitionQuery();

  query
    .caseDefinitionVersion(2);

  verifyQueryResults(query, 1);

  query
    .caseDefinitionVersion(1);

  verifyQueryResults(query, 3);
}
 
Example #24
Source File: CaseDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryByInvalidNameLike() {
  CaseDefinitionQuery query = repositoryService.createCaseDefinitionQuery();

  query
    .caseDefinitionNameLike("%invalid%");

  verifyQueryResults(query, 0);

  exceptionRule.expect(NotValidException.class);
  query.caseDefinitionNameLike(null);
}
 
Example #25
Source File: CaseDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryByInvalidName() {
  CaseDefinitionQuery query = repositoryService.createCaseDefinitionQuery();

  query
    .caseDefinitionName("invalid");

  verifyQueryResults(query, 0);

  exceptionRule.expect(NotValidException.class);
  query.caseDefinitionName(null);
}
 
Example #26
Source File: CaseDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryByName() {
  CaseDefinitionQuery query = repositoryService.createCaseDefinitionQuery();

  query
    .caseDefinitionName("Two");

  verifyQueryResults(query, 1);

  query
    .caseDefinitionName("One");

  verifyQueryResults(query, 2);
}
 
Example #27
Source File: CaseDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryByInvalidDeploymentId() {
  CaseDefinitionQuery query = repositoryService.createCaseDefinitionQuery();

 query
   .deploymentId("invalid");

  verifyQueryResults(query, 0);

  exceptionRule.expect(NotValidException.class);
  query.deploymentId(null);
}
 
Example #28
Source File: CaseDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryByDeploymentId() {
  CaseDefinitionQuery query = repositoryService.createCaseDefinitionQuery();

  query
    .deploymentId(deploymentOneId);

  verifyQueryResults(query, 2);
}
 
Example #29
Source File: RepositoryServiceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/camunda/bpm/engine/test/repository/one.cmmn" })
public void testGetCaseDefinition() {
  CaseDefinitionQuery query = repositoryService.createCaseDefinitionQuery();

  CaseDefinition caseDefinition = query.singleResult();
  String caseDefinitionId = caseDefinition.getId();

  CaseDefinition definition = repositoryService.getCaseDefinition(caseDefinitionId);

  assertNotNull(definition);
  assertEquals(caseDefinitionId, definition.getId());
}
 
Example #30
Source File: MultiTenancyCaseInstanceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void createCaseInstance(String tenantId) {
  String caseDefinitionId = null;

  CaseDefinitionQuery caseDefinitionQuery = repositoryService.createCaseDefinitionQuery().caseDefinitionKey("oneTaskCase");
  if (tenantId == null) {
    caseDefinitionId = caseDefinitionQuery.withoutTenantId().singleResult().getId();
  } else {
    caseDefinitionId = caseDefinitionQuery.tenantIdIn(tenantId).singleResult().getId();
  }

  caseService.withCaseDefinition(caseDefinitionId).create();
}