use of org.camunda.bpm.engine.runtime.CaseInstance in project camunda-bpm-platform by camunda.
the class CaseServiceStageTest method testCompleteShouldCompleteCaseInstance.
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneStageCase.cmmn" })
public void testCompleteShouldCompleteCaseInstance() {
// given:
// a deployed case definition
String caseDefinitionId = repositoryService.createCaseDefinitionQuery().singleResult().getId();
// an active case instance
caseService.withCaseDefinition(caseDefinitionId).create().getId();
String caseExecutionId = caseService.createCaseExecutionQuery().activityId("PI_Stage_1").singleResult().getId();
// when
caseService.withCaseExecution(queryCaseExecutionByActivityId("PI_HumanTask_1").getId()).complete();
caseService.withCaseExecution(queryCaseExecutionByActivityId("PI_HumanTask_2").getId()).complete();
// then
// the corresponding case execution has been also
// deleted and completed
CaseExecution caseExecution = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult();
assertNull(caseExecution);
// the case instance has been completed
CaseInstance caseInstance = caseService.createCaseInstanceQuery().completed().singleResult();
assertNotNull(caseInstance);
assertTrue(caseInstance.isCompleted());
}
use of org.camunda.bpm.engine.runtime.CaseInstance in project camunda-bpm-platform by camunda.
the class CaseServiceStageTest method testAutoCompletionOfEmptyStage.
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/emptyStageCase.cmmn" })
public void testAutoCompletionOfEmptyStage() {
// given:
// a deployed case definition
String caseDefinitionId = repositoryService.createCaseDefinitionQuery().singleResult().getId();
caseService.withCaseDefinition(caseDefinitionId).create();
// then
CaseExecution caseExecution = caseService.createCaseExecutionQuery().activityId("PI_Stage_1").singleResult();
assertNull(caseExecution);
CaseInstance caseInstance = caseService.createCaseInstanceQuery().completed().singleResult();
assertNotNull(caseInstance);
assertTrue(caseInstance.isCompleted());
}
use of org.camunda.bpm.engine.runtime.CaseInstance in project camunda-bpm-platform by camunda.
the class CaseServiceTest method testCaseExecutionQuery.
@Deployment(resources = "org/camunda/bpm/engine/test/api/cmmn/loan-application.cmmn")
public void testCaseExecutionQuery() {
// 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 are three case execution:
// - the case instance itself (ie. for the casePlanModel)
// - a case execution for the stage
// - a case execution for the humanTask
List<CaseExecution> caseExecutions = caseService.createCaseExecutionQuery().caseInstanceId(caseInstance.getId()).list();
assertEquals(3, caseExecutions.size());
CaseExecution casePlanModelExecution = caseService.createCaseExecutionQuery().activityId("CasePlanModel_1").singleResult();
assertNotNull(casePlanModelExecution);
CaseExecution stageExecution = caseService.createCaseExecutionQuery().activityId("PI_Stage_1").singleResult();
assertNotNull(stageExecution);
CaseExecution humanTaskExecution = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_6").singleResult();
assertNotNull(humanTaskExecution);
}
use of org.camunda.bpm.engine.runtime.CaseInstance in project camunda-bpm-platform by camunda.
the class CaseServiceCaseTaskTest method testManualStartWithLocalVariable.
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneCaseTaskCaseWithManualActivation.cmmn", "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testManualStartWithLocalVariable() {
// given
String superCaseInstanceId = createCaseInstance(DEFINITION_KEY).getId();
String caseTaskId = queryCaseExecutionByActivityId(CASE_TASK_KEY).getId();
CaseInstance subCaseInstance = queryCaseInstanceByKey(DEFINITION_KEY_2);
assertNull(subCaseInstance);
// when
caseService.withCaseExecution(caseTaskId).setVariableLocal("aVariableName", "abc").setVariableLocal("anotherVariableName", 999).manualStart();
// then
subCaseInstance = queryCaseInstanceByKey(DEFINITION_KEY_2);
assertNotNull(subCaseInstance);
assertTrue(subCaseInstance.isActive());
CaseExecution caseTask = queryCaseExecutionByActivityId(CASE_TASK_KEY);
assertTrue(caseTask.isActive());
// the case instance has two variables:
// - aVariableName
// - anotherVariableName
List<VariableInstance> result = runtimeService.createVariableInstanceQuery().list();
assertFalse(result.isEmpty());
assertEquals(2, result.size());
for (VariableInstance variable : result) {
assertEquals(caseTaskId, variable.getCaseExecutionId());
assertEquals(superCaseInstanceId, variable.getCaseInstanceId());
if (variable.getName().equals("aVariableName")) {
assertEquals("aVariableName", variable.getName());
assertEquals("abc", variable.getValue());
} else if (variable.getName().equals("anotherVariableName")) {
assertEquals("anotherVariableName", variable.getName());
assertEquals(999, variable.getValue());
} else {
fail("Unexpected variable: " + variable.getName());
}
}
}
use of org.camunda.bpm.engine.runtime.CaseInstance in project camunda-bpm-platform by camunda.
the class CaseServiceCaseTaskTest method testStartWithVariables.
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneCaseTaskCase.cmmn", "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testStartWithVariables() {
// given
// variables
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("aVariableName", "abc");
variables.put("anotherVariableName", 999);
String superCaseInstanceId = createCaseInstance(DEFINITION_KEY, variables).getId();
CaseInstance subCaseInstance;
// then
subCaseInstance = queryCaseInstanceByKey(DEFINITION_KEY_2);
assertNotNull(subCaseInstance);
assertTrue(subCaseInstance.isActive());
CaseExecution caseTask = queryCaseExecutionByActivityId(CASE_TASK_KEY);
assertTrue(caseTask.isActive());
// the case instance has two variables:
// - aVariableName
// - anotherVariableName
List<VariableInstance> result = runtimeService.createVariableInstanceQuery().list();
assertFalse(result.isEmpty());
assertEquals(2, result.size());
verifyVariables(superCaseInstanceId, result);
}
Aggregations