Search in sources :

Example 41 with VariableInstance

use of org.camunda.bpm.engine.runtime.VariableInstance 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);
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) HashMap(java.util.HashMap) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 42 with VariableInstance

use of org.camunda.bpm.engine.runtime.VariableInstance 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 43 with VariableInstance

use of org.camunda.bpm.engine.runtime.VariableInstance 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 44 with VariableInstance

use of org.camunda.bpm.engine.runtime.VariableInstance 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 45 with VariableInstance

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

the class MultiTenancyExecutionPropagationTest method testPropagateTenantIdToVariableInstanceFromHumanTask.

public void testPropagateTenantIdToVariableInstanceFromHumanTask() {
    deploymentForTenant(TENANT_ID, CMMN_FILE);
    createCaseInstance();
    VariableMap variables = Variables.createVariables().putValue("var", "test");
    CaseExecution caseExecution = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult();
    caseService.setVariables(caseExecution.getId(), variables);
    VariableInstance variableInstance = runtimeService.createVariableInstanceQuery().singleResult();
    assertThat(variableInstance, is(notNullValue()));
    // inherit the tenant id from human task
    assertThat(variableInstance.getTenantId(), is(TENANT_ID));
}
Also used : CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) VariableMap(org.camunda.bpm.engine.variable.VariableMap) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance)

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