Search in sources :

Example 36 with TypedValue

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

the class CreateProcessInstanceWithJsonVariablesTest method testCreateProcessInstanceWithVariable.

@ScenarioUnderTest("initProcessInstance.1")
@Test
public void testCreateProcessInstanceWithVariable() {
    // then
    ProcessInstance processInstance = engineRule.getRuntimeService().createProcessInstanceQuery().processInstanceBusinessKey("processWithJsonVariables").singleResult();
    List<VariableInstance> variables = engineRule.getRuntimeService().createVariableInstanceQuery().processInstanceIdIn(processInstance.getId()).list();
    assertEquals(4, variables.size());
    final Object objectVariable = engineRule.getRuntimeService().getVariable(processInstance.getId(), "objectVariable");
    assertObjectVariable(objectVariable);
    final Object plainTypeArrayVariable = engineRule.getRuntimeService().getVariable(processInstance.getId(), "plainTypeArrayVariable");
    assertPlainTypeArrayVariable(plainTypeArrayVariable);
    final Object notGenericObjectListVariable = engineRule.getRuntimeService().getVariable(processInstance.getId(), "notGenericObjectListVariable");
    assertNotGenericObjectListVariable(notGenericObjectListVariable);
    final TypedValue serializedObject = engineRule.getRuntimeService().getVariableTyped(processInstance.getId(), "serializedMapVariable", true);
    assertSerializedMap(serializedObject);
}
Also used : ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) TypedValue(org.camunda.bpm.engine.variable.value.TypedValue) Test(org.junit.Test) ScenarioUnderTest(org.camunda.bpm.qa.upgrade.ScenarioUnderTest) ScenarioUnderTest(org.camunda.bpm.qa.upgrade.ScenarioUnderTest)

Example 37 with TypedValue

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

the class DmnBusinessRuleTaskResultMappingTest method testSingleResultEmptyResult.

@Deployment(resources = { SINGLE_RESULT_BPMN, TEST_DECISION })
public void testSingleResultEmptyResult() {
    ProcessInstance processInstance = startTestProcess("empty result");
    Object result = runtimeService.getVariable(processInstance.getId(), "result");
    assertNull(result);
    TypedValue resultTyped = runtimeService.getVariableTyped(processInstance.getId(), "result");
    assertEquals(Variables.untypedNullValue(), resultTyped);
}
Also used : ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) TypedValue(org.camunda.bpm.engine.variable.value.TypedValue) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 38 with TypedValue

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

the class ProcessTaskTest method testInputOutputLimitedTypedVariables.

@Deployment(resources = { "org/camunda/bpm/engine/test/cmmn/processtask/ProcessTaskTest.testVariablesRoundtrip.cmmn", "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testInputOutputLimitedTypedVariables() {
    String variableName = "aVariable";
    String variableName2 = "anotherVariable";
    TypedValue caseVariableValue = Variables.stringValue("abc");
    TypedValue caseVariableValue2 = Variables.integerValue(null);
    String caseInstanceId = createCaseInstanceByKey(ONE_PROCESS_TASK_CASE, Variables.createVariables().putValue(variableName, caseVariableValue).putValue(variableName2, caseVariableValue2)).getId();
    String processInstanceId = queryProcessInstance().getId();
    TypedValue value = runtimeService.getVariableTyped(processInstanceId, variableName);
    assertThat(value, is(caseVariableValue));
    value = runtimeService.getVariableTyped(processInstanceId, variableName2);
    assertThat(value, is(caseVariableValue2));
    TypedValue processVariableValue = Variables.stringValue("cba");
    TypedValue processVariableValue2 = Variables.booleanValue(null);
    runtimeService.setVariable(processInstanceId, variableName, processVariableValue);
    runtimeService.setVariable(processInstanceId, variableName2, processVariableValue2);
    // should also complete process instance
    taskService.complete(queryTask().getId());
    value = caseService.getVariableTyped(caseInstanceId, variableName);
    assertThat(value, is(processVariableValue));
    value = caseService.getVariableTyped(caseInstanceId, variableName2);
    assertThat(value, is(processVariableValue2));
    // complete ////////////////////////////////////////////////////////
    assertProcessEnded(processInstanceId);
    close(caseInstanceId);
    assertCaseEnded(caseInstanceId);
}
Also used : TypedValue(org.camunda.bpm.engine.variable.value.TypedValue) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 39 with TypedValue

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

the class UpdateValueDelegate method execute.

public void execute(DelegateExecution execution) throws Exception {
    TypedValue typedValue = execution.getVariableTyped("listVar");
    List<JsonSerializable> var = (List<JsonSerializable>) typedValue.getValue();
    JsonSerializable newElement = new JsonSerializable();
    newElement.setStringProperty(STRING_PROPERTY);
    // implicit update of the list, so no execution.setVariable call
    var.add(newElement);
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) TypedValue(org.camunda.bpm.engine.variable.value.TypedValue)

Example 40 with TypedValue

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

the class BusinessProcessBeanTest method test.

/* General test asserting that the business process bean is functional */
@Test
@Deployment
public void test() throws Exception {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    // start the process
    businessProcess.startProcessByKey("businessProcessBeanTest").getId();
    // ensure that the process is started:
    assertNotNull(processEngine.getRuntimeService().createProcessInstanceQuery().singleResult());
    // ensure that there is a single task waiting
    Task task = processEngine.getTaskService().createTaskQuery().singleResult();
    assertNotNull(task);
    String value = "value";
    businessProcess.setVariable("key", Variables.stringValue(value));
    assertEquals(value, businessProcess.getVariable("key"));
    // Typed variable API
    TypedValue typedValue = businessProcess.getVariableTyped("key");
    assertEquals(ValueType.STRING, typedValue.getType());
    assertEquals(value, typedValue.getValue());
    // Local variables
    String localValue = "localValue";
    businessProcess.setVariableLocal("localKey", Variables.stringValue(localValue));
    assertEquals(localValue, businessProcess.getVariableLocal("localKey"));
    // Local typed variable API
    TypedValue typedLocalValue = businessProcess.getVariableLocalTyped("localKey");
    assertEquals(ValueType.STRING, typedLocalValue.getType());
    assertEquals(localValue, typedLocalValue.getValue());
    // complete the task
    assertEquals(task.getId(), businessProcess.startTask(task.getId()).getId());
    businessProcess.completeTask();
    // assert the task is completed
    assertNull(processEngine.getTaskService().createTaskQuery().singleResult());
    // assert that the process is ended:
    assertNull(processEngine.getRuntimeService().createProcessInstanceQuery().singleResult());
}
Also used : Task(org.camunda.bpm.engine.task.Task) BusinessProcess(org.camunda.bpm.engine.cdi.BusinessProcess) TypedValue(org.camunda.bpm.engine.variable.value.TypedValue) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

TypedValue (org.camunda.bpm.engine.variable.value.TypedValue)81 Test (org.junit.Test)25 Deployment (org.camunda.bpm.engine.test.Deployment)15 DmnEngineTest (org.camunda.bpm.dmn.engine.test.DmnEngineTest)14 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)11 DecisionResource (org.camunda.bpm.dmn.engine.test.DecisionResource)8 VariableMap (org.camunda.bpm.engine.variable.VariableMap)7 DmnDataTypeTransformer (org.camunda.bpm.dmn.engine.impl.spi.type.DmnDataTypeTransformer)6 BusinessProcess (org.camunda.bpm.engine.cdi.BusinessProcess)6 DmnDecisionResult (org.camunda.bpm.dmn.engine.DmnDecisionResult)4 DmnDecisionTableResult (org.camunda.bpm.dmn.engine.DmnDecisionTableResult)4 DmnExpressionImpl (org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl)3 DeclarativeProcessController (org.camunda.bpm.engine.cdi.test.impl.beans.DeclarativeProcessController)3 RestException (org.camunda.bpm.engine.rest.exception.RestException)3 Task (org.camunda.bpm.engine.task.Task)3 ArrayList (java.util.ArrayList)2 DmnDecisionResultEntries (org.camunda.bpm.dmn.engine.DmnDecisionResultEntries)2 DmnDecisionRuleResult (org.camunda.bpm.dmn.engine.DmnDecisionRuleResult)2 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)2 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)2