Search in sources :

Example 36 with VariableMap

use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.

the class CaseServiceTest method testExecuteSetVariablesLocalTyped.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testExecuteSetVariablesLocalTyped() {
    // 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();
    VariableMap variables = createVariables().putValueTyped("aVariableName", stringValue("abc")).putValueTyped("anotherVariableName", integerValue(null));
    // 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(stringValue("abc"), variable.getTypedValue());
        } else if (variable.getName().equals("anotherVariableName")) {
            assertEquals("anotherVariableName", variable.getName());
            assertEquals(integerValue(null), variable.getTypedValue());
        } else {
            fail("Unexpected variable: " + variable.getName());
        }
    }
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 37 with VariableMap

use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.

the class CaseServiceTest method testGetVariablesWithVariableNamesTyped.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testGetVariablesWithVariableNamesTyped() {
    // given:
    // a deployed case definition
    String caseDefinitionId = repositoryService.createCaseDefinitionQuery().singleResult().getId();
    // an active case instance
    caseService.withCaseDefinition(caseDefinitionId).setVariable("aVariableName", "abc").setVariable("anotherVariableName", 999).setVariable("thirVariable", "xyz").create().getId();
    String caseExecutionId = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult().getId();
    List<String> names = new ArrayList<String>();
    names.add("aVariableName");
    names.add("anotherVariableName");
    // when
    VariableMap variables = caseService.getVariablesTyped(caseExecutionId, names, true);
    // then
    assertNotNull(variables);
    assertFalse(variables.isEmpty());
    assertEquals(2, variables.size());
    assertEquals("abc", variables.get("aVariableName"));
    assertEquals(999, variables.get("anotherVariableName"));
    assertEquals(variables, caseService.getVariables(caseExecutionId, names));
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) ArrayList(java.util.ArrayList) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 38 with VariableMap

use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.

the class MultiTenancyVariableInstanceQueryTest method startProcessInstanceForTenant.

protected void startProcessInstanceForTenant(String tenant) {
    String processDefinitionId = repositoryService.createProcessDefinitionQuery().tenantIdIn(tenant).singleResult().getId();
    VariableMap variables = Variables.createVariables().putValue("var", "test");
    runtimeService.startProcessInstanceById(processDefinitionId, variables);
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap)

Example 39 with VariableMap

use of org.camunda.bpm.engine.variable.VariableMap 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)

Example 40 with VariableMap

use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.

the class MultiTenancyExecutionPropagationTest method testPropagateTenantIdToVariableInstanceOnCreateCaseInstance.

public void testPropagateTenantIdToVariableInstanceOnCreateCaseInstance() {
    deploymentForTenant(TENANT_ID, CMMN_FILE);
    VariableMap variables = Variables.putValue("var", "test");
    CaseDefinition caseDefinition = repositoryService.createCaseDefinitionQuery().singleResult();
    caseService.createCaseInstanceById(caseDefinition.getId(), variables);
    VariableInstance variableInstance = runtimeService.createVariableInstanceQuery().singleResult();
    assertThat(variableInstance, is(notNullValue()));
    // inherit the tenant id from case instance
    assertThat(variableInstance.getTenantId(), is(TENANT_ID));
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) CaseDefinition(org.camunda.bpm.engine.repository.CaseDefinition) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance)

Aggregations

VariableMap (org.camunda.bpm.engine.variable.VariableMap)230 Deployment (org.camunda.bpm.engine.test.Deployment)107 Test (org.junit.Test)59 Task (org.camunda.bpm.engine.task.Task)38 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)32 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)30 VariableMapImpl (org.camunda.bpm.engine.variable.impl.VariableMapImpl)15 CaseExecutionEntity (org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity)13 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)13 HashMap (java.util.HashMap)12 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)12 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)12 ProcessInstanceWithVariables (org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables)9 LockedExternalTask (org.camunda.bpm.engine.externaltask.LockedExternalTask)8 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)8 RestException (org.camunda.bpm.engine.rest.exception.RestException)8 CaseExecutionQuery (org.camunda.bpm.engine.runtime.CaseExecutionQuery)8 Execution (org.camunda.bpm.engine.runtime.Execution)8 CaseExecution (org.camunda.bpm.engine.runtime.CaseExecution)7 ThrowErrorDelegate (org.camunda.bpm.engine.test.bpmn.event.error.ThrowErrorDelegate)7