Search in sources :

Example 36 with VariableInstance

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

the class CaseServiceTest method testExecuteSetVariableAndVariablesLocal.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testExecuteSetVariableAndVariablesLocal() {
    // given:
    // a deployed case definition
    String caseDefinitionId = repositoryService.createCaseDefinitionQuery().singleResult().getId();
    // an active case instance
    String caseInstanceId = caseService.withCaseDefinition(caseDefinitionId).create().getId();
    String caseExecutionId = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult().getId();
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("aVariableName", "abc");
    variables.put("anotherVariableName", 999);
    // when
    caseService.withCaseExecution(caseExecutionId).setVariables(variables).setVariableLocal("aThirdVariable", 123).execute();
    // then
    // query by caseExecutionId
    List<VariableInstance> result = runtimeService.createVariableInstanceQuery().caseExecutionIdIn(caseExecutionId).list();
    assertFalse(result.isEmpty());
    assertEquals(1, result.size());
    VariableInstance aThirdVariable = result.get(0);
    assertNotNull(aThirdVariable);
    assertEquals("aThirdVariable", aThirdVariable.getName());
    assertEquals(123, aThirdVariable.getValue());
    // query by caseInstanceId
    result = runtimeService.createVariableInstanceQuery().caseInstanceIdIn(caseInstanceId).list();
    assertFalse(result.isEmpty());
    assertEquals(3, result.size());
    for (VariableInstance variable : result) {
        if (variable.getName().equals("aVariableName")) {
            assertEquals(caseInstanceId, variable.getCaseExecutionId());
            assertEquals(caseInstanceId, variable.getCaseInstanceId());
            assertEquals("aVariableName", variable.getName());
            assertEquals("abc", variable.getValue());
        } else if (variable.getName().equals("anotherVariableName")) {
            assertEquals(caseInstanceId, variable.getCaseExecutionId());
            assertEquals(caseInstanceId, variable.getCaseInstanceId());
            assertEquals("anotherVariableName", variable.getName());
            assertEquals(999, variable.getValue());
        } else if (variable.getName().equals("aThirdVariable")) {
            assertEquals(caseExecutionId, variable.getCaseExecutionId());
            assertEquals(caseInstanceId, variable.getCaseInstanceId());
            assertEquals("aThirdVariable", variable.getName());
            assertEquals(123, variable.getValue());
        } else {
            fail("Unexpected variable: " + variable.getName());
        }
    }
}
Also used : HashMap(java.util.HashMap) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 37 with VariableInstance

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

the class CaseServiceTest method testRemoveVariablesLocal.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testRemoveVariablesLocal() {
    // given:
    // a deployed case definition
    // and an active case instance
    String caseInstanceId = caseService.withCaseDefinitionByKey("oneTaskCase").create().getId();
    String caseExecutionId = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult().getId();
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("aVariable", "abc");
    variables.put("anotherVariable", 123);
    caseService.setVariablesLocal(caseExecutionId, variables);
    caseService.setVariableLocal(caseExecutionId, "aThirdVariable", "def");
    // when
    caseService.removeVariablesLocal(caseInstanceId, variables.keySet());
    // then no variables should have been removed
    assertEquals(3, runtimeService.createVariableInstanceQuery().count());
    // when
    caseService.removeVariablesLocal(caseExecutionId, variables.keySet());
    // then there should be only one variable left
    VariableInstance variable = runtimeService.createVariableInstanceQuery().singleResult();
    assertNotNull(variable);
    assertEquals("aThirdVariable", variable.getName());
}
Also used : HashMap(java.util.HashMap) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 38 with VariableInstance

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

the class CaseServiceTest method testExecuteSetVariableLocal.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testExecuteSetVariableLocal() {
    // given:
    // a deployed case definition
    String caseDefinitionId = repositoryService.createCaseDefinitionQuery().singleResult().getId();
    // an active case instance
    String caseInstanceId = caseService.withCaseDefinition(caseDefinitionId).create().getId();
    String caseExecutionId = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult().getId();
    // when
    caseService.withCaseExecution(caseExecutionId).setVariableLocal("aVariableName", "abc").setVariableLocal("anotherVariableName", 999).execute();
    // then
    // query by caseExecutionId
    List<VariableInstance> result = runtimeService.createVariableInstanceQuery().caseExecutionIdIn(caseExecutionId).list();
    assertFalse(result.isEmpty());
    assertEquals(2, result.size());
    for (VariableInstance variable : result) {
        assertEquals(caseExecutionId, variable.getCaseExecutionId());
        assertEquals(caseInstanceId, 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());
        }
    }
    // query by case instance id
    result = runtimeService.createVariableInstanceQuery().caseInstanceIdIn(caseInstanceId).list();
    assertFalse(result.isEmpty());
    assertEquals(2, result.size());
    for (VariableInstance variable : result) {
        assertEquals(caseExecutionId, variable.getCaseExecutionId());
        assertEquals(caseInstanceId, 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());
        }
    }
}
Also used : VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 39 with VariableInstance

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

the class CaseServiceTest method testExecuteSetVariablesLocal.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testExecuteSetVariablesLocal() {
    // given:
    // a deployed case definition
    String caseDefinitionId = repositoryService.createCaseDefinitionQuery().singleResult().getId();
    // an active case instance
    String caseInstanceId = caseService.withCaseDefinition(caseDefinitionId).create().getId();
    String caseExecutionId = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult().getId();
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("aVariableName", "abc");
    variables.put("anotherVariableName", 999);
    // when
    caseService.withCaseExecution(caseExecutionId).setVariablesLocal(variables).execute();
    // then
    // query by caseExecutionId
    List<VariableInstance> result = runtimeService.createVariableInstanceQuery().caseExecutionIdIn(caseExecutionId).list();
    assertFalse(result.isEmpty());
    assertEquals(2, result.size());
    for (VariableInstance variable : result) {
        assertEquals(caseExecutionId, variable.getCaseExecutionId());
        assertEquals(caseInstanceId, 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());
        }
    }
    // query by case instance id
    result = runtimeService.createVariableInstanceQuery().caseInstanceIdIn(caseInstanceId).list();
    assertFalse(result.isEmpty());
    assertEquals(2, result.size());
    for (VariableInstance variable : result) {
        assertEquals(caseExecutionId, variable.getCaseExecutionId());
        assertEquals(caseInstanceId, 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());
        }
    }
}
Also used : HashMap(java.util.HashMap) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 40 with VariableInstance

use of org.camunda.bpm.engine.runtime.VariableInstance 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());
        }
    }
}
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)

Aggregations

VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)374 Deployment (org.camunda.bpm.engine.test.Deployment)265 Test (org.junit.Test)167 HashMap (java.util.HashMap)136 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)122 VariableInstanceQuery (org.camunda.bpm.engine.runtime.VariableInstanceQuery)93 Task (org.camunda.bpm.engine.task.Task)67 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)42 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)39 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)33 Execution (org.camunda.bpm.engine.runtime.Execution)33 VariableMap (org.camunda.bpm.engine.variable.VariableMap)30 CaseExecution (org.camunda.bpm.engine.runtime.CaseExecution)27 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)26 CaseInstance (org.camunda.bpm.engine.runtime.CaseInstance)23 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)21 ExecutionTree (org.camunda.bpm.engine.test.util.ExecutionTree)17 CaseExecutionQuery (org.camunda.bpm.engine.runtime.CaseExecutionQuery)13 CaseExecutionEntity (org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity)11 List (java.util.List)10