public virtual void testTransientJsonValue() { // given BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("foo").startEvent().exclusiveGateway("gtw").sequenceFlowId("flow1").condition("cond", "${x.stringProperty == \"bar\"}").userTask("userTask1").endEvent().moveToLastGateway().sequenceFlowId("flow2").userTask("userTask2").endEvent().done(); deployment(modelInstance); JsonSerializable bean = new JsonSerializable("bar", 42, true); //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: ObjectValue jsonValue = serializedObjectValue(bean.toExpectedJsonString(), true).serializationDataFormat(JSON_FORMAT_NAME).objectTypeName(typeof(JsonSerializable).FullName).create(); VariableMap variables = Variables.createVariables().putValueTyped("x", jsonValue); // when runtimeService.startProcessInstanceByKey("foo", variables); // then IList <VariableInstance> variableInstances = runtimeService.createVariableInstanceQuery().list(); assertEquals(0, variableInstances.Count); Task task = taskService.createTaskQuery().singleResult(); assertNotNull(task); assertEquals("userTask1", task.TaskDefinitionKey); }
public virtual void testSelectHistoricSerializedValuesUpdate() { ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); JsonSerializable bean = new JsonSerializable("a String", 42, false); runtimeService.setVariable(instance.Id, "simpleBean", objectValue(bean).serializationDataFormat(JSON_FORMAT_NAME)); if (ProcessEngineConfiguration.HISTORY_FULL.Equals(processEngineConfiguration.History)) { HistoricVariableUpdate historicUpdate = (HistoricVariableUpdate)historyService.createHistoricDetailQuery().variableUpdates().singleResult(); assertNotNull(historicUpdate.Value); assertNull(historicUpdate.ErrorMessage); assertEquals(ValueType.OBJECT.Name, historicUpdate.TypeName); assertEquals(ValueType.OBJECT.Name, historicUpdate.VariableTypeName); JsonSerializable historyValue = (JsonSerializable)historicUpdate.Value; assertEquals(bean.StringProperty, historyValue.StringProperty); assertEquals(bean.IntProperty, historyValue.IntProperty); assertEquals(bean.BooleanProperty, historyValue.BooleanProperty); ObjectValue typedValue = (ObjectValue)historicUpdate.TypedValue; assertEquals(JSON_FORMAT_NAME, typedValue.SerializationDataFormat); JSONAssert.assertEquals(bean.toExpectedJsonString(), new string(typedValue.ValueSerialized), true); //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: assertEquals(typeof(JsonSerializable).FullName, typedValue.ObjectTypeName); } }
public virtual void testSerializationAsJson() { ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); JsonSerializable bean = new JsonSerializable("a String", 42, true); // request object to be serialized as JSON runtimeService.setVariable(instance.Id, "simpleBean", objectValue(bean).serializationDataFormat(JSON_FORMAT_NAME).create()); // validate untyped value object value = runtimeService.getVariable(instance.Id, "simpleBean"); assertEquals(bean, value); // validate typed value ObjectValue typedValue = runtimeService.getVariableTyped(instance.Id, "simpleBean"); assertEquals(ValueType.OBJECT, typedValue.Type); assertTrue(typedValue.Deserialized); assertEquals(bean, typedValue.Value); assertEquals(bean, typedValue.getValue(typeof(JsonSerializable))); assertEquals(typeof(JsonSerializable), typedValue.ObjectType); assertEquals(JSON_FORMAT_NAME, typedValue.SerializationDataFormat); //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: assertEquals(typeof(JsonSerializable).FullName, typedValue.ObjectTypeName); JSONAssert.assertEquals(bean.toExpectedJsonString(), new string(typedValue.ValueSerialized), true); }
public virtual void testSetSerializedVariableValueMismatchingTypeName() { ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); JsonSerializable bean = new JsonSerializable("a String", 42, true); string beanAsJson = bean.toExpectedJsonString(); SerializedObjectValueBuilder serializedValue = serializedObjectValue(beanAsJson).serializationDataFormat(JSON_FORMAT_NAME).objectTypeName("Insensible type name."); // < not a valid type name runtimeService.setVariable(instance.Id, "simpleBean", serializedValue); try { runtimeService.getVariable(instance.Id, "simpleBean"); fail("Exception expected."); } catch (Exception) { // happy path } //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: serializedValue = serializedObjectValue(beanAsJson).serializationDataFormat(JSON_FORMAT_NAME).objectTypeName(typeof(JsonSerializationTest).FullName); // < not the right type name runtimeService.setVariable(instance.Id, "simpleBean", serializedValue); try { runtimeService.getVariable(instance.Id, "simpleBean"); fail("Exception expected."); } catch (Exception) { // happy path } }
public virtual void testGetSerializedVariableValue() { ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); JsonSerializable bean = new JsonSerializable("a String", 42, true); runtimeService.setVariable(instance.Id, "simpleBean", objectValue(bean).serializationDataFormat(JSON_FORMAT_NAME).create()); ObjectValue typedValue = runtimeService.getVariableTyped(instance.Id, "simpleBean", false); string serializedValue = typedValue.ValueSerialized; JSONAssert.assertEquals(bean.toExpectedJsonString(), serializedValue, true); }
public virtual void testSelectHistoricSerializedValues() { if (processEngineConfiguration.HistoryLevel.Id >= org.camunda.bpm.engine.impl.history.HistoryLevel_Fields.HISTORY_LEVEL_AUDIT.Id) { ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); JsonSerializable bean = new JsonSerializable("a String", 42, false); runtimeService.setVariable(instance.Id, "simpleBean", objectValue(bean).serializationDataFormat(JSON_FORMAT_NAME)); HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().singleResult(); assertNotNull(historicVariable.Value); assertNull(historicVariable.ErrorMessage); ObjectValue typedValue = (ObjectValue)historicVariable.TypedValue; assertEquals(JSON_FORMAT_NAME, typedValue.SerializationDataFormat); JSONAssert.assertEquals(bean.toExpectedJsonString(), new string(typedValue.ValueSerialized), true); //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: assertEquals(typeof(JsonSerializable).FullName, typedValue.ObjectTypeName); } }
public virtual void testRemoveVariable() { // given a serialized json variable ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); JsonSerializable bean = new JsonSerializable("a String", 42, true); string beanAsJson = bean.toExpectedJsonString(); //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getCanonicalName method: SerializedObjectValueBuilder serializedValue = serializedObjectValue(beanAsJson).serializationDataFormat(JSON_FORMAT_NAME).objectTypeName(bean.GetType().FullName); runtimeService.setVariable(instance.Id, "simpleBean", serializedValue); // when runtimeService.removeVariable(instance.Id, "simpleBean"); // then assertNull(runtimeService.getVariable(instance.Id, "simpleBean")); assertNull(runtimeService.getVariableTyped(instance.Id, "simpleBean")); assertNull(runtimeService.getVariableTyped(instance.Id, "simpleBean", false)); }
public virtual void testSetSerializedVariableValueNoTypeName() { ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); JsonSerializable bean = new JsonSerializable("a String", 42, true); string beanAsJson = bean.toExpectedJsonString(); SerializedObjectValueBuilder serializedValue = serializedObjectValue(beanAsJson).serializationDataFormat(JSON_FORMAT_NAME); // no type name try { runtimeService.setVariable(instance.Id, "simpleBean", serializedValue); fail("Exception expected."); } catch (Exception e) { assertTextPresent("no 'objectTypeName' provided for non-null value", e.Message); } }
public virtual void testSetSerializedVariableValue() { ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); JsonSerializable bean = new JsonSerializable("a String", 42, true); string beanAsJson = bean.toExpectedJsonString(); //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getCanonicalName method: SerializedObjectValueBuilder serializedValue = serializedObjectValue(beanAsJson).serializationDataFormat(JSON_FORMAT_NAME).objectTypeName(bean.GetType().FullName); runtimeService.setVariable(instance.Id, "simpleBean", serializedValue); // java object can be retrieved JsonSerializable returnedBean = (JsonSerializable)runtimeService.getVariable(instance.Id, "simpleBean"); assertEquals(bean, returnedBean); // validate typed value metadata ObjectValue typedValue = runtimeService.getVariableTyped(instance.Id, "simpleBean"); assertEquals(bean, typedValue.Value); assertEquals(JSON_FORMAT_NAME, typedValue.SerializationDataFormat); //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getCanonicalName method: assertEquals(bean.GetType().FullName, typedValue.ObjectTypeName); }