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

The following examples show how to use org.camunda.bpm.engine.repository.CaseDefinition. 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: TenantIdProviderTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void providerCalledWithSuperCaseInstance() {

  ContextLoggingTenantIdProvider tenantIdProvider = new ContextLoggingTenantIdProvider();
  TestTenantIdProvider.delegate = tenantIdProvider;

  testRule.deploy(CMMN_SUBPROCESS_FILE, CMMN_FILE_WITH_MANUAL_ACTIVATION);
  CaseDefinition superCaseDefinition = engineRule.getRepositoryService().createCaseDefinitionQuery().caseDefinitionKey(CASE_DEFINITION_KEY).singleResult();


  // if a case instance is created
  engineRule.getCaseService().withCaseDefinitionByKey(CASE_DEFINITION_KEY).create();
  startCaseTask();

  // then the tenant id provider is passed in the case definition
  DelegateCaseExecution superCaseExecution = tenantIdProvider.caseParameters.get(1).getSuperCaseExecution();
  assertThat(superCaseExecution, is(notNullValue()));
  assertThat(superCaseExecution.getCaseDefinitionId(), is(superCaseDefinition.getId()));
}
 
Example #3
Source File: MultiTenancyCaseTaskTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testStartCaseInstanceWithLatestBindingDifferentVersion() {

    deploymentForTenant(TENANT_ONE, CMMN_LATEST_WITH_MANUAL_ACTIVATION, CMMN_CASE);

    deploymentForTenant(TENANT_TWO, CMMN_LATEST_WITH_MANUAL_ACTIVATION, CMMN_CASE);
    deploymentForTenant(TENANT_TWO, CMMN_CASE);

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

    CaseInstanceQuery query = caseService.createCaseInstanceQuery().caseDefinitionKey("oneTaskCase");
    assertThat(query.tenantIdIn(TENANT_ONE).count(), is(1L));

    CaseDefinition latestCaseDefinitionTenantTwo = repositoryService.createCaseDefinitionQuery().
        caseDefinitionKey("oneTaskCase").tenantIdIn(TENANT_TWO).latestVersion().singleResult();
    query = caseService.createCaseInstanceQuery().caseDefinitionId(latestCaseDefinitionTenantTwo.getId());
    assertThat(query.count(), is(1L));
  }
 
Example #4
Source File: MultiTenancyRepositoryServiceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void getPreviousCaseDefinitionWithTenantId() {
  testRule.deployForTenant(TENANT_ONE, CMMN);
  testRule.deployForTenant(TENANT_ONE, CMMN);
  testRule.deployForTenant(TENANT_ONE, CMMN);

  testRule.deployForTenant(TENANT_TWO, CMMN);
  testRule.deployForTenant(TENANT_TWO, CMMN);

  List<CaseDefinition> latestCaseDefinitions = repositoryService.createCaseDefinitionQuery()
    .latestVersion()
    .orderByTenantId()
    .asc()
    .list();

  CaseDefinitionEntity previousDefinitionTenantOne = getPreviousDefinition((CaseDefinitionEntity) latestCaseDefinitions.get(0));
  CaseDefinitionEntity previousDefinitionTenantTwo = getPreviousDefinition((CaseDefinitionEntity) latestCaseDefinitions.get(1));

  assertThat(previousDefinitionTenantOne.getVersion(), is(2));
  assertThat(previousDefinitionTenantOne.getTenantId(), is(TENANT_ONE));

  assertThat(previousDefinitionTenantTwo.getVersion(), is(1));
  assertThat(previousDefinitionTenantTwo.getTenantId(), is(TENANT_TWO));
}
 
Example #5
Source File: TenantIdProviderTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void providerCalledWithCaseDefinition_SubCaseInstance() {

  ContextLoggingTenantIdProvider tenantIdProvider = new ContextLoggingTenantIdProvider();
  TestTenantIdProvider.delegate = tenantIdProvider;

  testRule.deploy(CMMN_SUBPROCESS_FILE, CMMN_FILE);
  CaseDefinition deployedCaseDefinition = engineRule.getRepositoryService().createCaseDefinitionQuery().caseDefinitionKey("oneTaskCase").singleResult();

  // if a case instance is created
  engineRule.getCaseService().withCaseDefinitionByKey(CASE_DEFINITION_KEY).create();

  // then the tenant id provider is passed in the case definition
  CaseDefinition passedCaseDefinition = tenantIdProvider.caseParameters.get(1).getCaseDefinition();
  assertThat(passedCaseDefinition, is(notNullValue()));
  assertThat(passedCaseDefinition.getId(), is(deployedCaseDefinition.getId()));
}
 
Example #6
Source File: CaseExecutionEntity.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void provideTenantId(Map<String, Object> variables) {
  TenantIdProvider tenantIdProvider = Context.getProcessEngineConfiguration().getTenantIdProvider();

  if(tenantIdProvider != null) {
    VariableMap variableMap = Variables.fromMap(variables);
    CaseDefinition caseDefinition = (CaseDefinition) getCaseDefinition();

    TenantIdProviderCaseInstanceContext ctx = null;

    if(superExecutionId != null) {
      ctx = new TenantIdProviderCaseInstanceContext(caseDefinition, variableMap, getSuperExecution());
    }
    else if(superCaseExecutionId != null) {
      ctx = new TenantIdProviderCaseInstanceContext(caseDefinition, variableMap, getSuperCaseExecution());
    }
    else {
      ctx = new TenantIdProviderCaseInstanceContext(caseDefinition, variableMap);
    }

    tenantId = tenantIdProvider.provideTenantIdForCaseInstance(ctx);
  }
}
 
Example #7
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 #8
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 #9
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 #10
Source File: ProcessApplicationManager.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void logCaseDefinitionRegistrations(StringBuilder builder, List<CaseDefinition> caseDefinitions) {
  if(caseDefinitions.isEmpty()) {
    builder.append("Deployment does not provide any case definitions.");

  } else {
    builder.append("\n");
    builder.append("Will execute case definitions ");
    builder.append("\n");
    for (CaseDefinition caseDefinition : caseDefinitions) {
      builder.append("\n");
      builder.append("        ");
      builder.append(caseDefinition.getKey());
      builder.append("[version: ");
      builder.append(caseDefinition.getVersion());
      builder.append(", id: ");
      builder.append(caseDefinition.getId());
      builder.append("]");
    }
    builder.append("\n");
  }
}
 
Example #11
Source File: CaseDefinitionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testNonExistingCaseDefinitionRetrieval_ByKey() {
  String nonExistingKey = "aNonExistingDefinitionKey";

  when(repositoryServiceMock.createCaseDefinitionQuery().caseDefinitionKey(nonExistingKey)).thenReturn(caseDefinitionQueryMock);
  when(caseDefinitionQueryMock.latestVersion()).thenReturn(caseDefinitionQueryMock);
  when(caseDefinitionQueryMock.singleResult()).thenReturn(null);
  when(caseDefinitionQueryMock.list()).thenReturn(Collections.<CaseDefinition> emptyList());

  given()
    .pathParam("key", nonExistingKey)
  .then()
    .expect()
      .statusCode(Status.NOT_FOUND.getStatusCode()).contentType(ContentType.JSON)
      .body("type", is(RestException.class.getSimpleName()))
      .body("message", containsString("No matching case definition with key: " + nonExistingKey))
  .when()
    .get(SINGLE_CASE_DEFINITION_BY_KEY_URL);
}
 
Example #12
Source File: TenantIdProviderTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void providerCalledWithCaseDefinition() {

  ContextLoggingTenantIdProvider tenantIdProvider = new ContextLoggingTenantIdProvider();
  TestTenantIdProvider.delegate = tenantIdProvider;

  testRule.deploy(CMMN_FILE_WITH_MANUAL_ACTIVATION);
  CaseDefinition deployedCaseDefinition = engineRule.getRepositoryService().createCaseDefinitionQuery().singleResult();

  // if a case instance is created
  engineRule.getCaseService().withCaseDefinitionByKey(CASE_DEFINITION_KEY).create();

  // then the tenant id provider is passed in the case definition
  CaseDefinition passedCaseDefinition = tenantIdProvider.caseParameters.get(0).getCaseDefinition();
  assertThat(passedCaseDefinition, is(notNullValue()));
  assertThat(passedCaseDefinition.getId(), is(deployedCaseDefinition.getId()));
}
 
Example #13
Source File: RepositoryServiceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources={"org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn"})
public void testUpdateHistoryTimeToLiveInCache() {
  // given
  // there exists a deployment containing a case definition with key "oneTaskCase"

  CaseDefinition caseDefinition = findOnlyCaseDefinition();

  // assume
  assertNull(caseDefinition.getHistoryTimeToLive());

  // when
  repositoryService.updateCaseDefinitionHistoryTimeToLive(caseDefinition.getId(), 10);

  CaseDefinition definition = repositoryService.getCaseDefinition(caseDefinition.getId());
  assertEquals(Integer.valueOf(10), definition.getHistoryTimeToLive());
}
 
Example #14
Source File: CaseDefinitionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Before
public void setUpRuntime() {
  CaseDefinition mockCaseDefinition = MockProvider.createMockCaseDefinition();

  setUpRuntimeData(mockCaseDefinition);

  caseServiceMock = mock(CaseService.class);

  when(processEngine.getCaseService()).thenReturn(caseServiceMock);

  caseInstanceBuilder = mock(CaseInstanceBuilder.class);
  CaseInstance mockCaseInstance = MockProvider.createMockCaseInstance();

  when(caseServiceMock.withCaseDefinition(MockProvider.EXAMPLE_CASE_DEFINITION_ID)).thenReturn(caseInstanceBuilder);
  when(caseInstanceBuilder.businessKey(anyString())).thenReturn(caseInstanceBuilder);
  when(caseInstanceBuilder.setVariables(Matchers.<Map<String, Object>>any())).thenReturn(caseInstanceBuilder);
  when(caseInstanceBuilder.create()).thenReturn(mockCaseInstance);
}
 
Example #15
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 #16
Source File: CaseDefinitionRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public CaseDefinitionResource getCaseDefinitionByKey(String caseDefinitionKey) {

  CaseDefinition caseDefinition = getProcessEngine()
      .getRepositoryService()
      .createCaseDefinitionQuery()
      .caseDefinitionKey(caseDefinitionKey)
      .withoutTenantId()
      .latestVersion()
      .singleResult();

  if (caseDefinition == null) {
    String errorMessage = String.format("No matching case definition with key: %s and no tenant-id", caseDefinitionKey);
    throw new RestException(Status.NOT_FOUND, errorMessage);

  } else {
    return getCaseDefinitionById(caseDefinition.getId());
  }
}
 
Example #17
Source File: MultiTenancyCreateCaseInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testFailToCreateCaseInstanceByIdNoAuthenticatedTenants() {
  deploymentForTenant(TENANT_ONE, CMMN_FILE);

  CaseDefinition caseDefinition = repositoryService
    .createCaseDefinitionQuery()
    .singleResult();

  identityService.setAuthentication("user", null, null);

  try {
    caseService.withCaseDefinition(caseDefinition.getId()).create();

    fail("expected exception");
  } catch (ProcessEngineException e) {
    assertThat(e.getMessage(), containsString("Cannot create an instance of the case definition"));
  }
}
 
Example #18
Source File: CleanableHistoricCaseInstanceReportTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
private void prepareCaseInstances(String key, int daysInThePast, Integer historyTimeToLive, int instanceCount) {
  // update time to live
  List<CaseDefinition> caseDefinitions = repositoryService.createCaseDefinitionQuery().caseDefinitionKey(key).list();
  assertEquals(1, caseDefinitions.size());
  repositoryService.updateCaseDefinitionHistoryTimeToLive(caseDefinitions.get(0).getId(), historyTimeToLive);

  Date oldCurrentTime = ClockUtil.getCurrentTime();
  ClockUtil.setCurrentTime(DateUtils.addDays(oldCurrentTime, daysInThePast));

  for (int i = 0; i < instanceCount; i++) {
    CaseInstance caseInstance = caseService.createCaseInstanceByKey(key);
    caseService.terminateCaseExecution(caseInstance.getId());
    caseService.closeCaseInstance(caseInstance.getId());
  }

  ClockUtil.setCurrentTime(oldCurrentTime);
}
 
Example #19
Source File: CaseDefinitionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefinitionRetrieval_ByKeyAndTenantId() {
  CaseDefinition mockDefinition = MockProvider.mockCaseDefinition().tenantId(MockProvider.EXAMPLE_TENANT_ID).build();
  setUpRuntimeData(mockDefinition);

  given()
    .pathParam("key", MockProvider.EXAMPLE_CASE_DEFINITION_KEY)
    .pathParam("tenant-id", MockProvider.EXAMPLE_TENANT_ID)
  .then()
    .expect()
      .statusCode(Status.OK.getStatusCode())
      .body("id", equalTo(MockProvider.EXAMPLE_CASE_DEFINITION_ID))
      .body("key", equalTo(MockProvider.EXAMPLE_CASE_DEFINITION_KEY))
      .body("category", equalTo(MockProvider.EXAMPLE_CASE_DEFINITION_CATEGORY))
      .body("name", equalTo(MockProvider.EXAMPLE_CASE_DEFINITION_NAME))
      .body("deploymentId", equalTo(MockProvider.EXAMPLE_DEPLOYMENT_ID))
      .body("version", equalTo(MockProvider.EXAMPLE_CASE_DEFINITION_VERSION))
      .body("resource", equalTo(MockProvider.EXAMPLE_CASE_DEFINITION_RESOURCE_NAME))
      .body("tenantId", equalTo(MockProvider.EXAMPLE_TENANT_ID))
  .when()
    .get(SINGLE_CASE_DEFINITION_BY_KEY_AND_TENANT_ID_URL);

  verify(caseDefinitionQueryMock).tenantIdIn(MockProvider.EXAMPLE_TENANT_ID);
  verify(repositoryServiceMock).getCaseDefinition(MockProvider.EXAMPLE_CASE_DEFINITION_ID);
}
 
Example #20
Source File: MultiTenancyCallActivityTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testStartCaseInstanceWithLatestBindingDifferentVersion() {

    BpmnModelInstance callingProcess = Bpmn.createExecutableProcess("callingProcess")
        .startEvent()
        .callActivity()
          .camundaCaseRef("Case_1")
          .camundaCaseBinding("latest")
        .endEvent()
        .done();

    deploymentForTenant(TENANT_ONE, CMMN, callingProcess);

    deploymentForTenant(TENANT_TWO, CMMN, callingProcess);
    deploymentForTenant(TENANT_TWO, CMMN);

    runtimeService.createProcessInstanceByKey("callingProcess").processDefinitionTenantId(TENANT_ONE).execute();
    runtimeService.createProcessInstanceByKey("callingProcess").processDefinitionTenantId(TENANT_TWO).execute();

    CaseInstanceQuery query = caseService.createCaseInstanceQuery().caseDefinitionKey("Case_1");
    assertThat(query.tenantIdIn(TENANT_ONE).count(), is(1L));

    CaseDefinition latestCaseDefinitionTenantTwo = repositoryService.createCaseDefinitionQuery().tenantIdIn(TENANT_TWO).latestVersion().singleResult();
    query = caseService.createCaseInstanceQuery().caseDefinitionId(latestCaseDefinitionTenantTwo.getId());
    assertThat(query.count(), is(1L));
  }
 
Example #21
Source File: CaseDefinitionRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public CaseDefinitionResource getCaseDefinitionByKeyAndTenantId(String caseDefinitionKey, String tenantId) {

    CaseDefinition caseDefinition = getProcessEngine()
        .getRepositoryService()
        .createCaseDefinitionQuery()
        .caseDefinitionKey(caseDefinitionKey)
        .tenantIdIn(tenantId)
        .latestVersion()
        .singleResult();

    if (caseDefinition == null) {
      String errorMessage = String.format("No matching case definition with key: %s and tenant-id: %s", caseDefinitionKey, tenantId);
      throw new RestException(Status.NOT_FOUND, errorMessage);

    } else {
      return getCaseDefinitionById(caseDefinition.getId());
    }
  }
 
Example #22
Source File: TestOrderingUtil.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static NullTolerantComparator<CaseExecution> caseExecutionByDefinitionKey(ProcessEngine processEngine) {
  final RepositoryService repositoryService = processEngine.getRepositoryService();
  return propertyComparator(new PropertyAccessor<CaseExecution, String>() {
    @Override
    public String getProperty(CaseExecution obj) {
      CaseDefinition caseDefinition = repositoryService.getCaseDefinition(obj.getCaseDefinitionId());
      return caseDefinition.getKey();
    }
  });
}
 
Example #23
Source File: MultiTenancyExecutionPropagationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testPropagateTenantIdToVariableInstanceOnCreateCaseInstance() {

    deploymentForTenant(TENANT_ID, CMMN_FILE);

    VariableMap variables = Variables.putValue("var", "test");

    CaseDefinition caseDefinition = repositoryService.createCaseDefinitionQuery().singleResult();
    caseService.createCaseInstanceById(caseDefinition.getId(), variables);

    VariableInstance variableInstance = runtimeService.createVariableInstanceQuery().singleResult();
    assertThat(variableInstance, is(notNullValue()));
    // inherit the tenant id from case instance
    assertThat(variableInstance.getTenantId(), is(TENANT_ID));
  }
 
Example #24
Source File: VariableListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testInvokeBuiltinListenersOnly() {
  // disable custom variable listener invocation
  processEngineConfiguration.setInvokeCustomVariableListeners(false);

  // add a builtin variable listener the hard way
  CaseDefinition caseDefinition = repositoryService.createCaseDefinitionQuery().singleResult();
  processEngineConfiguration
    .getDeploymentCache()
    .getCaseDefinitionById(caseDefinition.getId())
    .findActivity("PI_HumanTask_1")
    .addBuiltInVariableListener(CaseVariableListener.CREATE, new LogVariableListener());

  caseService
    .withCaseDefinitionByKey("case")
    .create();

  CaseExecution taskExecution =
      caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult();
  assertNotNull(taskExecution);

  // when i set a variable
  caseService.withCaseExecution(taskExecution.getId()).setVariableLocal("testVariable", "value1").execute();

  // then the builtin listener is invoked
  assertEquals(1, LogVariableListener.getInvocations().size());

  // but the custom listener is not invoked
  assertEquals(0, LogExecutionContextListener.getCaseExecutionContexts().size());

  LogVariableListener.reset();
  LogExecutionContextListener.reset();

  // restore configuration
  processEngineConfiguration.setInvokeCustomVariableListeners(true);
}
 
Example #25
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 #26
Source File: TaskQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * @return the case definition ids
 */
protected List<String> getCaseDefinitionIds() {
  List<String> caseDefinitionIds = new ArrayList<String>();
  List<CaseDefinition> caseDefinitions = repositoryService.createCaseDefinitionQuery().list();
  for (CaseDefinition caseDefinition: caseDefinitions) {
    caseDefinitionIds.add(caseDefinition.getId());
  }
  return caseDefinitionIds;
}
 
Example #27
Source File: CaseServiceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/api/cmmn/loan-application.cmmn")
public void testCaseInstanceQuery() {
  // given
  // there exists a deployment containing a case definition with key "loanApplication"

  CaseDefinition caseDefinition = repositoryService
    .createCaseDefinitionQuery()
    .caseDefinitionKey("loanApplication")
    .singleResult();

  assertNotNull(caseDefinition);

  // when
  // create a new case instance by key

  CaseInstance caseInstance = caseService
    .withCaseDefinitionByKey(caseDefinition.getKey())
    .create();

  // then
  // the returned caseInstance is not null

  assertNotNull(caseInstance);

  // verify that there is one caseInstance

  // only select ACTIVE case instances
  List<CaseInstance> caseInstances = caseService
      .createCaseInstanceQuery()
      .active()
      .list();

  assertEquals(1, caseInstances.size());
}
 
Example #28
Source File: MultiTenancyCaseDefinitionCmdsTenantCheckTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void getCaseDefinitionDisabledTenantCheck() {
  processEngineConfiguration.setTenantCheckEnabled(false);
  identityService.setAuthentication("user", null, null);

  CaseDefinition definition = repositoryService.getCaseDefinition(caseDefinitionId);

  assertThat(definition.getTenantId(), is(TENANT_ONE));
}
 
Example #29
Source File: MultiTenancyCaseDefinitionCmdsTenantCheckTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void updateHistoryTimeToLiveDisabledTenantCheck() {
  processEngineConfiguration.setTenantCheckEnabled(false);
  identityService.setAuthentication("user", null, null);

  repositoryService.updateCaseDefinitionHistoryTimeToLive(caseDefinitionId, 6);

  CaseDefinition definition = repositoryService.getCaseDefinition(caseDefinitionId);

  assertThat(definition.getTenantId(), is(TENANT_ONE));
  assertThat(definition.getHistoryTimeToLive(), is(6));
}
 
Example #30
Source File: MultiTenancyExecutionPropagationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testPropagateTenantIdToTaskOnCreateCaseInstance() {
  deploymentForTenant(TENANT_ID, CMMN_FILE);

  CaseDefinition caseDefinition = repositoryService.createCaseDefinitionQuery().singleResult();
  caseService.createCaseInstanceById(caseDefinition.getId());

  Task task = taskService.createTaskQuery().taskName("A HumanTask").singleResult();
  assertThat(task, is(notNullValue()));
  // inherit the tenant id from case instance
  assertThat(task.getTenantId(), is(TENANT_ID));
}