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

The following examples show how to use org.camunda.bpm.engine.runtime.CaseExecutionQuery. 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: CaseServiceStageTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void verifyTasksState(CaseExecutionQuery caseExecutionQuery) {
  // (1) one case case execution representing "PI_HumanTask_1"
  CaseExecution firstHumanTask = caseExecutionQuery
      .activityId("PI_HumanTask_1")
      .singleResult();

  assertNotNull(firstHumanTask);
  assertTrue(firstHumanTask.isActive());
  assertFalse(firstHumanTask.isEnabled());

  // (2) one case case execution representing "PI_HumanTask_2"
  CaseExecution secondHumanTask = caseExecutionQuery
      .activityId("PI_HumanTask_2")
      .singleResult();

  assertNotNull(secondHumanTask);
  assertTrue(secondHumanTask.isActive());
  assertFalse(secondHumanTask.isEnabled());
}
 
Example #2
Source File: AutoCompleteTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testNested() {
  // given
  // a deployed case definition

  CaseExecutionQuery executionQuery = caseService.createCaseExecutionQuery();

  // when
  String caseInstanceId = createCaseInstanceByKey(CASE_DEFINITION_KEY).getId();

  // then
  CaseInstance caseInstance = caseService
      .createCaseInstanceQuery()
      .caseInstanceId(caseInstanceId)
      .singleResult();
  assertNotNull(caseInstance);
  assertTrue(caseInstance.isCompleted());

  // stage, humanTask1, humanTask2, humanTask3 are not available
  assertNull(executionQuery.activityId("PI_Stage_1").singleResult());
  assertNull(executionQuery.activityId("PI_HumanTask_1").singleResult());
  assertNull(executionQuery.activityId("PI_HumanTask_2").singleResult());
  assertNull(executionQuery.activityId("PI_HumanTask_3").singleResult());
}
 
Example #3
Source File: RepetitionRuleTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testDefaultValueWithEmptyCondition() {
  createCaseInstanceByKey("case");
  String humanTask1 = queryCaseExecutionByActivityId("PI_HumanTask_1").getId();

  // when
  complete(humanTask1);

  CaseExecutionQuery query = caseService
      .createCaseExecutionQuery()
      .activityId("PI_HumanTask_2");

  assertEquals(2, query.count());
  assertEquals(1, query.available().count());
  assertEquals(1, query.active().count());
}
 
Example #4
Source File: CaseExecutionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testQueryBySerializableVariableLessThan() {
  List<String> serializable = new ArrayList<String>();
  serializable.add("one");
  serializable.add("two");
  serializable.add("three");

  caseService
    .withCaseDefinitionByKey(CASE_DEFINITION_KEY)
    .setVariable("aSerializableValue", serializable)
    .create();

  CaseExecutionQuery query = caseService.createCaseExecutionQuery();

  try {
    query.variableValueLessThan("aSerializableValue", serializable).list();
    fail();
  } catch (ProcessEngineException e) {}
}
 
Example #5
Source File: RepetitionRuleTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testRepeatTask() {
  // given
  createCaseInstance();

  String firstHumanTaskId = queryCaseExecutionByActivityId("PI_HumanTask_1").getId();

  // when
  complete(firstHumanTaskId);

  // then
  CaseExecutionQuery query = caseService
      .createCaseExecutionQuery()
      .activityId("PI_HumanTask_2");

  assertEquals(2, query.count());

  CaseExecution originInstance = query.active().singleResult();
  assertNotNull(originInstance);

  CaseExecution repetitionInstance = query.available().singleResult();
  assertNotNull(repetitionInstance);
}
 
Example #6
Source File: CaseExecutionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testQueryBySerializableVariableGreaterThanOrEqual() {
  List<String> serializable = new ArrayList<String>();
  serializable.add("one");
  serializable.add("two");
  serializable.add("three");

  caseService
    .withCaseDefinitionByKey(CASE_DEFINITION_KEY)
    .setVariable("aSerializableValue", serializable)
    .create();

  CaseExecutionQuery query = caseService.createCaseExecutionQuery();

  try {
    query.variableValueGreaterThanOrEqual("aSerializableValue", serializable).list();
    fail();
  } catch (ProcessEngineException e) {}
}
 
Example #7
Source File: CaseExecutionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testQueryBySerializableCaseInstanceVariableLessThanOrEqual() {
  List<String> serializable = new ArrayList<String>();
  serializable.add("one");
  serializable.add("two");
  serializable.add("three");

  caseService
    .withCaseDefinitionByKey(CASE_DEFINITION_KEY)
    .setVariable("aSerializableValue", serializable)
    .create();

  CaseExecutionQuery query = caseService.createCaseExecutionQuery();

  try {
    query.caseInstanceVariableValueLessThanOrEqual("aSerializableValue", serializable).list();
    fail();
  } catch (ProcessEngineException e) {}
}
 
Example #8
Source File: RepetitionRuleTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/cmmn/repetition/RepetitionRuleTest.testDefaultVariableBasedRule.cmmn")
public void testDefaultVariableBasedRepetitionRuleEvaluatesToFalse() {
  // given
  VariableMap variables = Variables.createVariables().putValue("repeat", false);
  createCaseInstanceByKey("case", variables);

  String humanTask1 = queryCaseExecutionByActivityId("PI_HumanTask_1").getId();

  // when
  complete(humanTask1);

  // then
  CaseExecutionQuery query = caseService
      .createCaseExecutionQuery()
      .activityId("PI_HumanTask_2");
  assertEquals(1, query.count());
  assertEquals(1, query.active().count());
}
 
Example #9
Source File: CaseExecutionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testQueryBySerializableVariableValueEquals() {
  List<String> serializable = new ArrayList<String>();
  serializable.add("one");
  serializable.add("two");
  serializable.add("three");

  caseService
    .withCaseDefinitionByKey(CASE_DEFINITION_KEY)
    .setVariable("aSerializableValue", serializable)
    .create();

  CaseExecutionQuery query = caseService.createCaseExecutionQuery();

  try {
    query.variableValueEquals("aSerializableValue", serializable).list();
    fail();
  } catch (ProcessEngineException e) {}
}
 
Example #10
Source File: CaseExecutionRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public List<CaseExecutionDto> queryCaseExecutions(CaseExecutionQueryDto queryDto, Integer firstResult, Integer maxResults) {
  ProcessEngine engine = getProcessEngine();
  queryDto.setObjectMapper(getObjectMapper());
  CaseExecutionQuery query = queryDto.toQuery(engine);

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

  List<CaseExecutionDto> executionResults = new ArrayList<CaseExecutionDto>();
  for (CaseExecution execution : matchingExecutions) {
    CaseExecutionDto resultExecution = CaseExecutionDto.fromCaseExecution(execution);
    executionResults.add(resultExecution);
  }
  return executionResults;
}
 
Example #11
Source File: RepetitionRuleTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testRepeatMilestone() {
  // given
  createCaseInstance();

  String firstHumanTaskId = queryCaseExecutionByActivityId("PI_HumanTask_1").getId();
  String milestoneId = queryCaseExecutionByActivityId("PI_Milestone_1").getId();

  // when
  complete(firstHumanTaskId);

  // then
  CaseExecutionQuery query = caseService
      .createCaseExecutionQuery()
      .activityId("PI_Milestone_1");

  assertEquals(1, query.count());
  assertTrue(query.singleResult().isAvailable());
  assertFalse(milestoneId.equals(query.singleResult().getId()));
}
 
Example #12
Source File: SentryScenario.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@DescribesScenario("newSentryInstance")
public static ScenarioSetup newSentryInstance() {
  return new ScenarioSetup() {
    public void execute(ProcessEngine engine, String scenarioName) {
      CaseService caseService = engine.getCaseService();
      CaseInstance caseInstance = caseService.createCaseInstanceByKey("case", scenarioName);
      String caseInstanceId = caseInstance.getId();
      
      CaseExecutionQuery query = caseService.createCaseExecutionQuery().caseInstanceId(caseInstanceId);

      String firstHumanTaskId = query.activityId("PI_HumanTask_1").singleResult().getId();
      caseService.manuallyStartCaseExecution(firstHumanTaskId);
      caseService.completeCaseExecution(firstHumanTaskId);

      String secondHumanTaskId = query.activityId("PI_HumanTask_2").singleResult().getId();
      caseService.manuallyStartCaseExecution(secondHumanTaskId);
      caseService.completeCaseExecution(secondHumanTaskId);
    }
  };
}
 
Example #13
Source File: CaseExecutionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQueryByLongCaseInstanceVariableValueEquals() {
  caseService
    .withCaseDefinitionByKey(CASE_DEFINITION_KEY)
    .setVariable("aLongValue", (long) 789)
    .create();

  CaseExecutionQuery query = caseService.createCaseExecutionQuery();

  query.caseInstanceVariableValueEquals("aLongValue", (long) 789);

  verifyQueryResults(query, 2);
}
 
Example #14
Source File: CaseExecutionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQueryByByteArrayCaseInstanceVariableValueLessThanOrEqual() {
  byte[] bytes = "somebytes".getBytes();

  caseService
    .withCaseDefinitionByKey(CASE_DEFINITION_KEY)
    .setVariable("aByteArrayValue", bytes)
    .create();

  CaseExecutionQuery query = caseService.createCaseExecutionQuery();

  try {
    query.caseInstanceVariableValueLessThanOrEqual("aByteArrayValue", bytes).list();
    fail();
  } catch (ProcessEngineException e) {}
}
 
Example #15
Source File: MultiTenancyCaseExecutionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQueryAuthenticatedTenant() {
  identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE));

  CaseExecutionQuery query = caseService.createCaseExecutionQuery();

  assertThat(query.count(), is(4L));
  assertThat(query.tenantIdIn(TENANT_ONE).count(), is(2L));
  assertThat(query.tenantIdIn(TENANT_TWO).count(), is(0L));
  assertThat(query.tenantIdIn(TENANT_ONE, TENANT_TWO).count(), is(2L));
}
 
Example #16
Source File: CaseExecutionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQueryByNullCaseInstanceVariableValueGreaterThanOrEqual() {
  caseService
    .withCaseDefinitionByKey(CASE_DEFINITION_KEY)
    .setVariable("aNullValue", null)
    .create();

  CaseExecutionQuery query = caseService.createCaseExecutionQuery();

  try {
    query.caseInstanceVariableValueGreaterThanOrEqual("aNullValue", null).list();
    fail();
  } catch (NotValidException e) {}

}
 
Example #17
Source File: CaseServiceHumanTaskTest.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/oneTaskCase.cmmn"})
public void testManualStartNonFluent() {
  // given:
  // a deployed case definition
  String caseDefinitionId = repositoryService
      .createCaseDefinitionQuery()
      .singleResult()
      .getId();

  // an active case instance
  caseService
    .withCaseDefinition(caseDefinitionId)
    .create();

  CaseExecutionQuery caseExecutionQuery = caseService.createCaseExecutionQuery();

  // an enabled child case execution of
  // the case instance
  String caseExecutionId = caseExecutionQuery
    .activityId("PI_HumanTask_1")
    .singleResult()
    .getId();

  // then

  // the child case execution is active...
  CaseExecution caseExecution = caseExecutionQuery.singleResult();
  assertTrue(caseExecution.isActive());
  // ... and not enabled
  assertFalse(caseExecution.isEnabled());

  // there exists a task
  Task task = taskService
    .createTaskQuery()
    .caseExecutionId(caseExecutionId)
    .singleResult();

  assertNotNull(task);
}
 
Example #18
Source File: CaseExecutionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQueryByLongVariableValueEquals() {
  caseService
    .withCaseDefinitionByKey(CASE_DEFINITION_KEY)
    .setVariable("aLongValue", (long) 789)
    .create();

  CaseExecutionQuery query = caseService.createCaseExecutionQuery();

  query.variableValueEquals("aLongValue", (long) 789);

  verifyQueryResults(query, 1);
}
 
Example #19
Source File: CaseServiceHumanTaskTest.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/twoTaskCase.cmmn"})
public void testDisableNonFluent() {
  // given:
  // a deployed case definition
  String caseDefinitionId = repositoryService
      .createCaseDefinitionQuery()
      .singleResult()
      .getId();

  // an active case instance and the containing
  // human task is enabled
  caseService
      .withCaseDefinition(caseDefinitionId)
      .create();

  CaseExecutionQuery caseExecutionQuery = caseService.createCaseExecutionQuery();

  String caseExecutionId = caseExecutionQuery
      .activityId("PI_HumanTask_1")
      .singleResult()
      .getId();

  // when
  caseService.disableCaseExecution(caseExecutionId);

  // then
  CaseExecution caseExecution = caseExecutionQuery.singleResult();
  // the human task is disabled
  assertTrue(caseExecution.isDisabled());
  assertFalse(caseExecution.isActive());
  assertFalse(caseExecution.isEnabled());
}
 
Example #20
Source File: CaseServiceHumanTaskTest.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/twoTaskCase.cmmn"})
public void testReenableNonFluent() {
  // given:
  // a deployed case definition
  String caseDefinitionId = repositoryService
      .createCaseDefinitionQuery()
      .singleResult()
      .getId();

  // an active case instance
  caseService
      .withCaseDefinition(caseDefinitionId)
      .create();

  CaseExecutionQuery caseExecutionQuery = caseService.createCaseExecutionQuery();

  String caseExecutionId = caseExecutionQuery
      .activityId("PI_HumanTask_1")
      .singleResult()
      .getId();

  // the human task is disabled
  caseService
    .withCaseExecution(caseExecutionId)
    .disable();

  // when
  caseService.reenableCaseExecution(caseExecutionId);

  // then
  CaseExecution caseExecution = caseExecutionQuery.singleResult();
  // the human task is disabled
  assertFalse(caseExecution.isDisabled());
  assertFalse(caseExecution.isActive());
  assertTrue(caseExecution.isEnabled());

}
 
Example #21
Source File: CaseExecutionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQueryByIntegerCaseInstanceVariableValueEquals() {
  caseService
    .withCaseDefinitionByKey(CASE_DEFINITION_KEY)
    .setVariable("anIntegerValue", 456)
    .create();

  CaseExecutionQuery query = caseService.createCaseExecutionQuery();

  query.caseInstanceVariableValueEquals("anIntegerValue", 456);

  verifyQueryResults(query, 2);
}
 
Example #22
Source File: CaseServiceStageTest.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/oneTaskAndOneStageWithManualActivationCase.cmmn"})
public void testReenableAnDisabledStage() {
  // given:
  // a deployed case definition
  String caseDefinitionId = repositoryService
      .createCaseDefinitionQuery()
      .singleResult()
      .getId();

  // an active case instance
  caseService
      .withCaseDefinition(caseDefinitionId)
      .create();

  CaseExecutionQuery caseExecutionQuery = caseService.createCaseExecutionQuery();

  String caseExecutionId = caseExecutionQuery
      .activityId("PI_Stage_1")
      .singleResult()
      .getId();

  // the human task is disabled
  caseService
    .withCaseExecution(caseExecutionId)
    .disable();

  // when
  caseService
    .withCaseExecution(caseExecutionId)
    .reenable();

  // then
  CaseExecution caseExecution = caseExecutionQuery.singleResult();
  // the human task is disabled
  assertFalse(caseExecution.isDisabled());
  assertFalse(caseExecution.isActive());
  assertTrue(caseExecution.isEnabled());

}
 
Example #23
Source File: CaseExecutionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQueryByByteArrayCaseInstanceVariableValueEquals() {
  byte[] bytes = "somebytes".getBytes();

  caseService
    .withCaseDefinitionByKey(CASE_DEFINITION_KEY)
    .setVariable("aByteArrayValue", bytes)
    .create();

  CaseExecutionQuery query = caseService.createCaseExecutionQuery();

  try {
    query.caseInstanceVariableValueEquals("aByteArrayValue", bytes).list();
    fail();
  } catch (ProcessEngineException e) {}
}
 
Example #24
Source File: CaseExecutionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQueryByShortCaseInstanceVariableValueEquals() {
  caseService
    .withCaseDefinitionByKey(CASE_DEFINITION_KEY)
    .setVariable("aShortValue", (short) 123)
    .create();

  CaseExecutionQuery query = caseService.createCaseExecutionQuery();

  query.caseInstanceVariableValueEquals("aShortValue", (short) 123);

  verifyQueryResults(query, 2);
}
 
Example #25
Source File: CaseServiceStageTest.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/oneTaskAndOneStageWithManualActivationCase.cmmn"})
public void testDisableADisabledStage() {
  // given:
  // a deployed case definition
  String caseDefinitionId = repositoryService
      .createCaseDefinitionQuery()
      .singleResult()
      .getId();

  // an active case instance
  caseService
      .withCaseDefinition(caseDefinitionId)
      .create();

  CaseExecutionQuery caseExecutionQuery = caseService.createCaseExecutionQuery();

  String caseExecutionId = caseExecutionQuery
      .activityId("PI_Stage_1")
      .singleResult()
      .getId();

  // the human task is disabled
  caseService
    .withCaseExecution(caseExecutionId)
    .disable();

  try {
    // when
    caseService
      .withCaseExecution(caseExecutionId)
      .disable();
    fail("It should not be possible to disable a already disabled human task.");
  } catch (NotAllowedException e) {
  }
}
 
Example #26
Source File: CaseExecutionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQueryByBooleanVariableValueGreaterThanOrEqual() {
  caseService
    .withCaseDefinitionByKey(CASE_DEFINITION_KEY)
    .setVariable("aBooleanValue", true)
    .create();

  CaseExecutionQuery query = caseService.createCaseExecutionQuery();

  try {
    query.variableValueGreaterThanOrEqual("aBooleanValue", false).list();
    fail();
  } catch (NotValidException e) {}

}
 
Example #27
Source File: RepetitionRuleTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/cmmn/repetition/RepetitionRuleTest.testRepeatTask.cmmn")
public void testShouldNotRepeatTaskAfterCompletion() {
  // given
  createCaseInstance();
  String humanTask1 = queryCaseExecutionByActivityId("PI_HumanTask_1").getId();

  // when (1)
  complete(humanTask1);

  // then (1)
  CaseExecutionQuery query = caseService
      .createCaseExecutionQuery()
      .activityId("PI_HumanTask_2");
  assertEquals(2, query.count());
  assertEquals(1, query.available().count());
  assertEquals(1, query.active().count());

  // when (2)
  String humanTask2 = query.active().singleResult().getId();
  complete(humanTask2);

  // then (2)
  query = caseService
      .createCaseExecutionQuery()
      .activityId("PI_HumanTask_2");
  assertEquals(1, query.count());
  assertEquals(1, query.available().count());
}
 
Example #28
Source File: RepetitionRuleTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testRepeatMilestoneMultipleTimes() {
  // given
  createCaseInstance();

  String firstHumanTaskId = queryCaseExecutionByActivityId("PI_HumanTask_1").getId();
  String milestoneId = queryCaseExecutionByActivityId("PI_Milestone_1").getId();

  // when (1)
  disable(firstHumanTaskId);

  // then (2)
  CaseExecutionQuery query = caseService
      .createCaseExecutionQuery()
      .activityId("PI_Milestone_1");

  assertEquals(1, query.count());
  assertTrue(query.singleResult().isAvailable());
  assertFalse(milestoneId.equals(query.singleResult().getId()));

  // when (2)
  reenable(firstHumanTaskId);
  disable(firstHumanTaskId);

  // then (2)
  query = caseService
      .createCaseExecutionQuery()
      .activityId("PI_Milestone_1");

  assertEquals(1, query.count());
  assertTrue(query.singleResult().isAvailable());
  assertFalse(milestoneId.equals(query.singleResult().getId()));
}
 
Example #29
Source File: CaseExecutionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQueryByDoubleCaseInstanceVariableValueNotEquals() {
  caseService
    .withCaseDefinitionByKey(CASE_DEFINITION_KEY)
    .setVariable("aDoubleValue", 1.5)
    .create();

  CaseExecutionQuery query = caseService.createCaseExecutionQuery();

  query.caseInstanceVariableValueNotEquals("aDoubleValue", 1.6);

  verifyQueryResults(query, 2);
}
 
Example #30
Source File: CaseExecutionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQueryByLongVariableValueNotEquals() {
  caseService
    .withCaseDefinitionByKey(CASE_DEFINITION_KEY)
    .setVariable("aLongValue", (long) 789)
    .create();

  CaseExecutionQuery query = caseService.createCaseExecutionQuery();

  query.variableValueNotEquals("aLongValue", (long) 790);

  verifyQueryResults(query, 1);
}