Search in sources :

Example 16 with CaseInstance

use of org.camunda.bpm.engine.runtime.CaseInstance in project camunda-bpm-platform by camunda.

the class CaseServiceCaseTaskTest method testManualStartWithVariable.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneCaseTaskCaseWithManualActivation.cmmn", "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testManualStartWithVariable() {
    // 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).setVariable("aVariableName", "abc").setVariable("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());
    verifyVariables(superCaseInstanceId, result);
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 17 with CaseInstance

use of org.camunda.bpm.engine.runtime.CaseInstance in project camunda-bpm-platform by camunda.

the class CaseServiceCaseInstanceTest method testCompleteWithEnabledStage.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneStageCase.cmmn" })
public void testCompleteWithEnabledStage() {
    // given:
    // a deployed case definition
    String caseDefinitionId = repositoryService.createCaseDefinitionQuery().singleResult().getId();
    // an active case instance
    caseService.withCaseDefinition(caseDefinitionId).create();
    CaseExecution caseExecution = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult();
    CaseExecution caseExecution2 = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_2").singleResult();
    // when
    caseService.withCaseExecution(caseExecution.getId()).complete();
    caseService.withCaseExecution(caseExecution2.getId()).complete();
    // then
    // the corresponding case execution has been also
    // deleted and completed
    CaseExecution caseExecution3 = caseService.createCaseExecutionQuery().activityId("PI_Stage_1").singleResult();
    assertNull(caseExecution3);
    CaseInstance caseInstance = caseService.createCaseInstanceQuery().singleResult();
    assertNotNull(caseInstance);
    assertTrue(caseInstance.isCompleted());
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 18 with CaseInstance

use of org.camunda.bpm.engine.runtime.CaseInstance in project camunda-bpm-platform by camunda.

the class CaseServiceCaseInstanceTest method testCreateByKeyWithVariable.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testCreateByKeyWithVariable() {
    // given a deployed case definition
    // when
    CaseInstance caseInstance = caseService.withCaseDefinitionByKey("oneTaskCase").setVariable("aVariableName", "aVariableValue").setVariable("anotherVariableName", 999).create();
    // then
    assertNotNull(caseInstance);
    // there should exist two variables
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery();
    List<VariableInstance> result = query.caseInstanceIdIn(caseInstance.getId()).orderByVariableName().asc().list();
    assertFalse(result.isEmpty());
    assertEquals(2, result.size());
    for (VariableInstance variableInstance : result) {
        if (variableInstance.getName().equals("aVariableName")) {
            assertEquals("aVariableName", variableInstance.getName());
            assertEquals("aVariableValue", variableInstance.getValue());
        } else if (variableInstance.getName().equals("anotherVariableName")) {
            assertEquals("anotherVariableName", variableInstance.getName());
            assertEquals(999, variableInstance.getValue());
        } else {
            fail("Unexpected variable: " + variableInstance.getName());
        }
    }
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) VariableInstanceQuery(org.camunda.bpm.engine.runtime.VariableInstanceQuery) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 19 with CaseInstance

use of org.camunda.bpm.engine.runtime.CaseInstance in project camunda-bpm-platform by camunda.

the class CaseServiceCaseInstanceTest method testCreateByKeyWithVariables.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testCreateByKeyWithVariables() {
    // given a deployed case definition
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("aVariableName", "aVariableValue");
    variables.put("anotherVariableName", 999);
    // when
    CaseInstance caseInstance = caseService.withCaseDefinitionByKey("oneTaskCase").setVariables(variables).create();
    // then
    assertNotNull(caseInstance);
    // there should exist two variables
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery();
    List<VariableInstance> result = query.caseInstanceIdIn(caseInstance.getId()).orderByVariableName().asc().list();
    assertFalse(result.isEmpty());
    assertEquals(2, result.size());
    for (VariableInstance variableInstance : result) {
        if (variableInstance.getName().equals("aVariableName")) {
            assertEquals("aVariableName", variableInstance.getName());
            assertEquals("aVariableValue", variableInstance.getValue());
        } else if (variableInstance.getName().equals("anotherVariableName")) {
            assertEquals("anotherVariableName", variableInstance.getName());
            assertEquals(999, variableInstance.getValue());
        } else {
            fail("Unexpected variable: " + variableInstance.getName());
        }
    }
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) HashMap(java.util.HashMap) VariableInstanceQuery(org.camunda.bpm.engine.runtime.VariableInstanceQuery) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 20 with CaseInstance

use of org.camunda.bpm.engine.runtime.CaseInstance in project camunda-bpm-platform by camunda.

the class CaseServiceCaseInstanceTest method testCreateByKey.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testCreateByKey() {
    // given a deployed case definition
    String caseDefinitionId = repositoryService.createCaseDefinitionQuery().singleResult().getId();
    // when
    CaseInstance caseInstance = caseService.withCaseDefinitionByKey("oneTaskCase").create();
    // then
    assertNotNull(caseInstance);
    // check properties
    assertNull(caseInstance.getBusinessKey());
    assertEquals(caseDefinitionId, caseInstance.getCaseDefinitionId());
    assertEquals(caseInstance.getId(), caseInstance.getCaseInstanceId());
    assertTrue(caseInstance.isActive());
    assertFalse(caseInstance.isEnabled());
    // get persisted case instance
    CaseInstance instance = caseService.createCaseInstanceQuery().singleResult();
    // should have the same properties
    assertEquals(caseInstance.getId(), instance.getId());
    assertEquals(caseInstance.getBusinessKey(), instance.getBusinessKey());
    assertEquals(caseInstance.getCaseDefinitionId(), instance.getCaseDefinitionId());
    assertEquals(caseInstance.getCaseInstanceId(), instance.getCaseInstanceId());
    assertEquals(caseInstance.isActive(), instance.isActive());
    assertEquals(caseInstance.isEnabled(), instance.isEnabled());
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

CaseInstance (org.camunda.bpm.engine.runtime.CaseInstance)183 Deployment (org.camunda.bpm.engine.test.Deployment)149 CaseExecution (org.camunda.bpm.engine.runtime.CaseExecution)62 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)23 Test (org.junit.Test)21 HistoricCaseInstance (org.camunda.bpm.engine.history.HistoricCaseInstance)18 Task (org.camunda.bpm.engine.task.Task)18 CaseExecutionQuery (org.camunda.bpm.engine.runtime.CaseExecutionQuery)16 CaseDefinition (org.camunda.bpm.engine.repository.CaseDefinition)13 VariableInstanceQuery (org.camunda.bpm.engine.runtime.VariableInstanceQuery)10 HashMap (java.util.HashMap)9 CaseInstanceQuery (org.camunda.bpm.engine.runtime.CaseInstanceQuery)9 ArrayList (java.util.ArrayList)6 CaseService (org.camunda.bpm.engine.CaseService)6 HistoricDetail (org.camunda.bpm.engine.history.HistoricDetail)6 Date (java.util.Date)5 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)5 NotAllowedException (org.camunda.bpm.engine.exception.NotAllowedException)5 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)5 VariableMap (org.camunda.bpm.engine.variable.VariableMap)5