Java Code Examples for org.camunda.bpm.engine.variable.VariableMap#getValueTyped()
The following examples show how to use
org.camunda.bpm.engine.variable.VariableMap#getValueTyped() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VariableApiTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void testTransientVariables() throws URISyntaxException { VariableMap variableMap = createVariables().putValueTyped("foo", doubleValue(10.0, true)) .putValueTyped("bar", integerValue(10, true)) .putValueTyped("aa", booleanValue(true, true)) .putValueTyped("bb", stringValue("bb", true)) .putValueTyped("test", byteArrayValue("test".getBytes(), true)) .putValueTyped("blob", fileValue(new File(this.getClass().getClassLoader().getResource("org/camunda/bpm/engine/test/variables/simpleFile.txt").toURI()), true)) .putValueTyped("val", dateValue(new Date(), true)) .putValueTyped("var", objectValue(new Integer(10), true).create()) .putValueTyped("short", shortValue((short)12, true)) .putValueTyped("long", longValue((long)10, true)) .putValueTyped("file", fileValue("org/camunda/bpm/engine/test/variables/simpleFile.txt").setTransient(true).create()) .putValueTyped("hi", untypedValue("stringUntyped", true)) .putValueTyped("null", untypedValue(null, true)) .putValueTyped("ser", serializedObjectValue("{\"name\" : \"foo\"}", true).create()); for (Entry<String, Object> e : variableMap.entrySet()) { TypedValue value = (TypedValue) variableMap.getValueTyped(e.getKey()); assertTrue(value.isTransient()); } }
Example 2
Source File: PrimitiveValueTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void testCreatePrimitiveVariableUntyped() { VariableMap variables = createVariables().putValue(variableName, value); assertEquals(value, variables.get(variableName)); assertEquals(value, variables.getValueTyped(variableName).getValue()); // no type information present TypedValue typedValue = variables.getValueTyped(variableName); if (!(typedValue instanceof NullValueImpl)) { assertNull(typedValue.getType()); assertEquals(variables.get(variableName), typedValue.getValue()); } else { assertEquals(NULL, typedValue.getType()); } }
Example 3
Source File: FormServiceTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test @Deployment(resources = "org/camunda/bpm/engine/test/api/twoTasksProcess.bpmn20.xml") public void testSubmitTaskFormWithVarialbesInReturnShouldDeserializeObjectValue() { // given ObjectValue value = Variables.objectValue("value").create(); VariableMap variables = Variables.createVariables().putValue("var", value); runtimeService.startProcessInstanceByKey("twoTasksProcess", variables); Task task = taskService.createTaskQuery().singleResult(); // when VariableMap result = formService.submitTaskFormWithVariablesInReturn(task.getId(), null, true); // then ObjectValue returnedValue = result.getValueTyped("var"); assertThat(returnedValue.isDeserialized()).isTrue(); assertThat(returnedValue.getValue()).isEqualTo("value"); }
Example 4
Source File: FormServiceTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test @Deployment(resources = "org/camunda/bpm/engine/test/api/twoTasksProcess.bpmn20.xml") public void testSubmitTaskFormWithVarialbesInReturnShouldNotDeserializeObjectValue() { // given ObjectValue value = Variables.objectValue("value").create(); VariableMap variables = Variables.createVariables().putValue("var", value); ProcessInstance instance = runtimeService.startProcessInstanceByKey("twoTasksProcess", variables); String serializedValue = ((ObjectValue) runtimeService.getVariableTyped(instance.getId(), "var")).getValueSerialized(); Task task = taskService.createTaskQuery().singleResult(); // when VariableMap result = formService.submitTaskFormWithVariablesInReturn(task.getId(), null, false); // then ObjectValue returnedValue = result.getValueTyped("var"); assertThat(returnedValue.isDeserialized()).isFalse(); assertThat(returnedValue.getValueSerialized()).isEqualTo(serializedValue); }
Example 5
Source File: TaskServiceTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test @Deployment(resources = "org/camunda/bpm/engine/test/api/twoTasksProcess.bpmn20.xml") public void testCompleteTaskWithVariablesInReturnShouldNotDeserializeObjectValue() { // given ObjectValue value = Variables.objectValue("value").create(); VariableMap variables = Variables.createVariables().putValue("var", value); ProcessInstance instance = runtimeService.startProcessInstanceByKey("twoTasksProcess", variables); String serializedValue = ((ObjectValue) runtimeService.getVariableTyped(instance.getId(), "var")).getValueSerialized(); Task task = taskService.createTaskQuery().singleResult(); // when VariableMap result = taskService.completeWithVariablesInReturn(task.getId(), null, false); // then ObjectValue returnedValue = result.getValueTyped("var"); assertThat(returnedValue.isDeserialized()).isFalse(); assertThat(returnedValue.getValueSerialized()).isEqualTo(serializedValue); }
Example 6
Source File: TaskServiceTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test @Deployment(resources = "org/camunda/bpm/engine/test/api/twoTasksProcess.bpmn20.xml") public void testCompleteTaskWithVariablesInReturnShouldDeserializeObjectValue() { // given ObjectValue value = Variables.objectValue("value").create(); VariableMap variables = Variables.createVariables().putValue("var", value); runtimeService.startProcessInstanceByKey("twoTasksProcess", variables); Task task = taskService.createTaskQuery().singleResult(); // when VariableMap result = taskService.completeWithVariablesInReturn(task.getId(), null, true); // then ObjectValue returnedValue = result.getValueTyped("var"); assertThat(returnedValue.isDeserialized()).isTrue(); assertThat(returnedValue.getValue()).isEqualTo("value"); }
Example 7
Source File: MessageCorrelationTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test public void testCorrelateAllWithVariablesInReturnShouldDeserializeObjectValue() { // given BpmnModelInstance model = Bpmn.createExecutableProcess("process") .startEvent() .intermediateCatchEvent("Message_1") .message("1") .userTask("UserTask_1") .endEvent() .done(); testRule.deploy(model); ObjectValue value = Variables.objectValue("value").create(); VariableMap variables = Variables.createVariables().putValue("var", value); runtimeService.startProcessInstanceByKey("process", variables); // when List<MessageCorrelationResultWithVariables> result = runtimeService.createMessageCorrelation("1") .correlateAllWithResultAndVariables(true); // then assertThat(result).hasSize(1); VariableMap resultVariables = result.get(0).getVariables(); ObjectValue returnedValue = resultVariables.getValueTyped("var"); assertThat(returnedValue.isDeserialized()).isTrue(); assertThat(returnedValue.getValue()).isEqualTo("value"); }
Example 8
Source File: TaskRestServiceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "unchecked" }) @Test public void testSubmitTaskFormWithFileValue() { String variableKey = "aVariable"; String filename = "test.txt"; Map<String, Object> variables = VariablesBuilder.create().variable(variableKey, Base64.encodeBase64String("someBytes".getBytes()), "File") .getVariables(); ((Map<String, Object>)variables.get(variableKey)).put("valueInfo", Collections.<String, Object>singletonMap("filename", filename)); Map<String, Object> json = new HashMap<>(); json.put("variables", variables); given().pathParam("id", EXAMPLE_TASK_ID) .header("accept", MediaType.APPLICATION_JSON) .contentType(POST_JSON_CONTENT_TYPE).body(json) .then().expect() .statusCode(Status.NO_CONTENT.getStatusCode()) .when().post(SUBMIT_FORM_URL); ArgumentCaptor<VariableMap> captor = ArgumentCaptor.forClass(VariableMap.class); verify(formServiceMock).submitTaskForm(eq(EXAMPLE_TASK_ID), captor.capture()); VariableMap map = captor.getValue(); FileValue fileValue = (FileValue) map.getValueTyped(variableKey); assertThat(fileValue, is(notNullValue())); assertThat(fileValue.getFilename(), is(filename)); assertThat(IoUtil.readInputStream(fileValue.getValue(), null), is("someBytes".getBytes())); }
Example 9
Source File: EqualsMap.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
protected boolean matchesMatchers(Object argument) { if (argument == null) { return false; } Map<String, Object> argumentMap = (Map<String, Object>) argument; boolean containSameKeys = matchers.keySet().containsAll(argumentMap.keySet()) && argumentMap.keySet().containsAll(matchers.keySet()); if (!containSameKeys) { return false; } for (String key : argumentMap.keySet()) { Matcher<?> matcher = matchers.get(key); Object value = null; if (argumentMap instanceof VariableMap) { VariableMap varMap = (VariableMap) argumentMap; value = varMap.getValueTyped(key); } else { value = argumentMap.get(key); } if (!matcher.matches(value)) { return false; } } return true; }
Example 10
Source File: ProcessInstantiationWithVariablesInReturnTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
private void testVariablesWithoutDeserialization(String processDefinitionKey) throws Exception { //given serializable variable JavaSerializable javaSerializable = new JavaSerializable("foo"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); new ObjectOutputStream(baos).writeObject(javaSerializable); String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), engineRule.getProcessEngine()); //when execute process with serialized variable and wait state ProcessInstanceWithVariables procInstance = engineRule.getRuntimeService() .createProcessInstanceByKey(processDefinitionKey) .setVariable("serializedVar", serializedObjectValue(serializedObject) .serializationDataFormat(Variables.SerializationDataFormats.JAVA) .objectTypeName(JavaSerializable.class.getName()) .create()) .executeWithVariablesInReturn(false, false); //then returned instance contains serialized variable VariableMap map = procInstance.getVariables(); assertNotNull(map); ObjectValue serializedVar = (ObjectValue) map.getValueTyped("serializedVar"); assertFalse(serializedVar.isDeserialized()); assertObjectValueSerializedJava(serializedVar, javaSerializable); //access on value should fail because variable is not deserialized try { serializedVar.getValue(); Assert.fail("Deserialization should fail!"); } catch (IllegalStateException ise) { assertTrue(ise.getMessage().equals("Object is not deserialized.")); } }
Example 11
Source File: MessageCorrelationTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test public void testCorrelateAllWithVariablesInReturnShouldNotDeserializeObjectValue() { // given BpmnModelInstance model = Bpmn.createExecutableProcess("process") .startEvent() .intermediateCatchEvent("Message_1") .message("1") .userTask("UserTask_1") .endEvent() .done(); testRule.deploy(model); ObjectValue value = Variables.objectValue("value").create(); VariableMap variables = Variables.createVariables().putValue("var", value); ProcessInstance instance = runtimeService.startProcessInstanceByKey("process", variables); String serializedValue = ((ObjectValue) runtimeService.getVariableTyped(instance.getId(), "var")).getValueSerialized(); // when List<MessageCorrelationResultWithVariables> result = runtimeService.createMessageCorrelation("1") .correlateAllWithResultAndVariables(false); // then assertThat(result).hasSize(1); VariableMap resultVariables = result.get(0).getVariables(); ObjectValue returnedValue = resultVariables.getValueTyped("var"); assertThat(returnedValue.isDeserialized()).isFalse(); assertThat(returnedValue.getValueSerialized()).isEqualTo(serializedValue); }
Example 12
Source File: MessageCorrelationTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test public void testCorrelateWithVariablesInReturnShouldNotDeserializeObjectValue() { // given BpmnModelInstance model = Bpmn.createExecutableProcess("process") .startEvent() .intermediateCatchEvent("Message_1") .message("1") .userTask("UserTask_1") .endEvent() .done(); testRule.deploy(model); ObjectValue value = Variables.objectValue("value").create(); VariableMap variables = Variables.createVariables().putValue("var", value); ProcessInstance instance = runtimeService.startProcessInstanceByKey("process", variables); String serializedValue = ((ObjectValue) runtimeService.getVariableTyped(instance.getId(), "var")).getValueSerialized(); // when MessageCorrelationResultWithVariables result = runtimeService.createMessageCorrelation("1") .correlateWithResultAndVariables(false); // then VariableMap resultVariables = result.getVariables(); ObjectValue returnedValue = resultVariables.getValueTyped("var"); assertThat(returnedValue.isDeserialized()).isFalse(); assertThat(returnedValue.getValueSerialized()).isEqualTo(serializedValue); }
Example 13
Source File: MessageCorrelationTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test public void testCorrelateWithVariablesInReturnShouldDeserializeObjectValue() { // given BpmnModelInstance model = Bpmn.createExecutableProcess("process") .startEvent() .intermediateCatchEvent("Message_1") .message("1") .userTask("UserTask_1") .endEvent() .done(); testRule.deploy(model); ObjectValue value = Variables.objectValue("value").create(); VariableMap variables = Variables.createVariables().putValue("var", value); runtimeService.startProcessInstanceByKey("process", variables); // when MessageCorrelationResultWithVariables result = runtimeService.createMessageCorrelation("1") .correlateWithResultAndVariables(true); // then VariableMap resultVariables = result.getVariables(); ObjectValue returnedValue = resultVariables.getValueTyped("var"); assertThat(returnedValue.isDeserialized()).isTrue(); assertThat(returnedValue.getValue()).isEqualTo("value"); }
Example 14
Source File: FormFieldHandler.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
public void handleSubmit(VariableScope variableScope, VariableMap values, VariableMap allValues) { TypedValue submittedValue = (TypedValue) values.getValueTyped(id); values.remove(id); // perform validation for (FormFieldValidationConstraintHandler validationHandler : validationHandlers) { Object value = null; if(submittedValue != null) { value = submittedValue.getValue(); } validationHandler.validate(value, allValues, this, variableScope); } // update variable(s) TypedValue modelValue = null; if (submittedValue != null) { if (type != null) { modelValue = type.convertToModelValue(submittedValue); } else { modelValue = submittedValue; } } else if (defaultValueExpression != null) { final TypedValue expressionValue = Variables.untypedValue(defaultValueExpression.getValue(variableScope)); if (type != null) { // first, need to convert to model value since the default value may be a String Constant specified in the model xml. modelValue = type.convertToModelValue(Variables.untypedValue(expressionValue)); } else if (expressionValue != null) { modelValue = Variables.stringValue(expressionValue.getValue().toString()); } } if (modelValue != null) { if (id != null) { variableScope.setVariable(id, modelValue); } } }
Example 15
Source File: PrimitiveVariableIT.java From camunda-external-task-client-java with Apache License 2.0 | 4 votes |
@Test public void shoudGetAllVariableTyped() { // given Map<String, TypedValue> variables = new HashMap<>(); variables.put(VARIABLE_NAME_INT, Variables.integerValue(VARIABLE_VALUE_INT)); variables.put(VARIABLE_NAME_LONG, Variables.longValue(VARIABLE_VALUE_LONG)); variables.put(VARIABLE_NAME_SHORT, Variables.shortValue(VARIABLE_VALUE_SHORT)); variables.put(VARIABLE_NAME_DOUBLE, Variables.doubleValue(VARIABLE_VALUE_DOUBLE)); variables.put(VARIABLE_NAME_STRING, Variables.stringValue(VARIABLE_VALUE_STRING)); variables.put(VARIABLE_NAME_BOOLEAN, Variables.booleanValue(VARIABLE_VALUE_BOOLEAN)); variables.put(VARIABLE_NAME_DATE, Variables.dateValue(VARIABLE_VALUE_DATE)); variables.put(VARIABLE_NAME_BYTES, Variables.byteArrayValue(VARIABLE_VALUE_BYTES)); variables.put(VARIABLE_NAME_NULL, Variables.untypedNullValue()); engineRule.startProcessInstance(processDefinition.getId(), variables); // when client.subscribe(EXTERNAL_TASK_TOPIC_FOO) .handler(handler) .open(); // then clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty()); ExternalTask task = handler.getHandledTasks().get(0); VariableMap fetchedVariables = task.getAllVariablesTyped(); assertThat(fetchedVariables).hasSize(variables.size()); assertThat(fetchedVariables.get(VARIABLE_NAME_INT)).isEqualTo(VARIABLE_VALUE_INT); assertThat(fetchedVariables.get(VARIABLE_NAME_LONG)).isEqualTo(VARIABLE_VALUE_LONG); assertThat(fetchedVariables.get(VARIABLE_NAME_SHORT)).isEqualTo(VARIABLE_VALUE_SHORT); assertThat(fetchedVariables.get(VARIABLE_NAME_DOUBLE)).isEqualTo(VARIABLE_VALUE_DOUBLE); assertThat(fetchedVariables.get(VARIABLE_NAME_STRING)).isEqualTo(VARIABLE_VALUE_STRING); assertThat(fetchedVariables.get(VARIABLE_NAME_BOOLEAN)).isEqualTo(VARIABLE_VALUE_BOOLEAN); assertThat(fetchedVariables.get(VARIABLE_NAME_DATE)).isEqualTo(VARIABLE_VALUE_DATE); assertThat(fetchedVariables.get(VARIABLE_NAME_BYTES)).isEqualTo(VARIABLE_VALUE_BYTES); TypedValue intTypedValue = fetchedVariables.getValueTyped(VARIABLE_NAME_INT); assertThat(intTypedValue.getValue()).isEqualTo(VARIABLE_VALUE_INT); assertThat(intTypedValue.getType()).isEqualTo(INTEGER); TypedValue longTypedValue = fetchedVariables.getValueTyped(VARIABLE_NAME_LONG); assertThat(longTypedValue.getValue()).isEqualTo(VARIABLE_VALUE_LONG); assertThat(longTypedValue.getType()).isEqualTo(LONG); TypedValue shortTypedValue = fetchedVariables.getValueTyped(VARIABLE_NAME_SHORT); assertThat(shortTypedValue.getValue()).isEqualTo(VARIABLE_VALUE_SHORT); assertThat(shortTypedValue.getType()).isEqualTo(SHORT); TypedValue doubleTypedValue = fetchedVariables.getValueTyped(VARIABLE_NAME_DOUBLE); assertThat(doubleTypedValue.getValue()).isEqualTo(VARIABLE_VALUE_DOUBLE); assertThat(doubleTypedValue.getType()).isEqualTo(DOUBLE); TypedValue stringTypedValue = fetchedVariables.getValueTyped(VARIABLE_NAME_STRING); assertThat(stringTypedValue.getValue()).isEqualTo(VARIABLE_VALUE_STRING); assertThat(stringTypedValue.getType()).isEqualTo(STRING); TypedValue booleanTypedValue = fetchedVariables.getValueTyped(VARIABLE_NAME_BOOLEAN); assertThat(booleanTypedValue.getValue()).isEqualTo(VARIABLE_VALUE_BOOLEAN); assertThat(booleanTypedValue.getType()).isEqualTo(BOOLEAN); TypedValue dateTypedValue = fetchedVariables.getValueTyped(VARIABLE_NAME_DATE); assertThat(dateTypedValue.getValue()).isEqualTo(VARIABLE_VALUE_DATE); assertThat(dateTypedValue.getType()).isEqualTo(DATE); TypedValue bytesTypedValue = fetchedVariables.getValueTyped(VARIABLE_NAME_BYTES); assertThat(bytesTypedValue.getValue()).isEqualTo(VARIABLE_VALUE_BYTES); assertThat(bytesTypedValue.getType()).isEqualTo(BYTES); TypedValue nullTypedValue = fetchedVariables.getValueTyped(VARIABLE_NAME_NULL); assertThat(nullTypedValue.getValue()).isNull(); assertThat(nullTypedValue.getType()).isEqualTo(NULL); }
Example 16
Source File: ProcessVariableMapTest.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
@Test @Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml") public void testProcessVariableMapLocal() { BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class); businessProcess.startProcessByKey("businessProcessBeanTest"); VariableMap variables = (VariableMap) getBeanInstance("processVariableMapLocal"); assertNotNull(variables); /////////////////////////////////////////////////////////////////// // Put a variable via BusinessProcess and get it via VariableMap // /////////////////////////////////////////////////////////////////// String aValue = "aValue"; businessProcess.setVariableLocal(VARNAME_1, Variables.stringValue(aValue)); // Legacy API assertEquals(aValue, variables.get(VARNAME_1)); // Typed variable API TypedValue aTypedValue = variables.getValueTyped(VARNAME_1); assertEquals(ValueType.STRING, aTypedValue.getType()); assertEquals(aValue, aTypedValue.getValue()); assertEquals(aValue, variables.getValue(VARNAME_1, String.class)); // Type API with wrong type try { variables.getValue(VARNAME_1, Integer.class); fail("ClassCastException expected!"); } catch(ClassCastException ex) { assertEquals("Cannot cast variable named 'aVariable' with value 'aValue' to type 'class java.lang.Integer'.", ex.getMessage()); } /////////////////////////////////////////////////////////////////// // Put a variable via VariableMap and get it via BusinessProcess // /////////////////////////////////////////////////////////////////// String anotherValue = "anotherValue"; variables.put(VARNAME_2, Variables.stringValue(anotherValue)); // Legacy API assertEquals(anotherValue, businessProcess.getVariableLocal(VARNAME_2)); // Typed variable API TypedValue anotherTypedValue = businessProcess.getVariableLocalTyped(VARNAME_2); assertEquals(ValueType.STRING, anotherTypedValue.getType()); assertEquals(anotherValue, anotherTypedValue.getValue()); }
Example 17
Source File: ProcessVariableMapTest.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
@Test public void testProcessVariableMap() { BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class); VariableMap variables = (VariableMap) getBeanInstance("processVariableMap"); assertNotNull(variables); /////////////////////////////////////////////////////////////////// // Put a variable via BusinessProcess and get it via VariableMap // /////////////////////////////////////////////////////////////////// String aValue = "aValue"; businessProcess.setVariable(VARNAME_1, Variables.stringValue(aValue)); // Legacy API assertEquals(aValue, variables.get(VARNAME_1)); // Typed variable API TypedValue aTypedValue = variables.getValueTyped(VARNAME_1); assertEquals(ValueType.STRING, aTypedValue.getType()); assertEquals(aValue, aTypedValue.getValue()); assertEquals(aValue, variables.getValue(VARNAME_1, String.class)); // Type API with wrong type try { variables.getValue(VARNAME_1, Integer.class); fail("ClassCastException expected!"); } catch(ClassCastException ex) { assertEquals("Cannot cast variable named 'aVariable' with value 'aValue' to type 'class java.lang.Integer'.", ex.getMessage()); } /////////////////////////////////////////////////////////////////// // Put a variable via VariableMap and get it via BusinessProcess // /////////////////////////////////////////////////////////////////// String anotherValue = "anotherValue"; variables.put(VARNAME_2, Variables.stringValue(anotherValue)); // Legacy API assertEquals(anotherValue, businessProcess.getVariable(VARNAME_2)); // Typed variable API TypedValue anotherTypedValue = businessProcess.getVariableTyped(VARNAME_2); assertEquals(ValueType.STRING, anotherTypedValue.getType()); assertEquals(anotherValue, anotherTypedValue.getValue()); }