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 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); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void execute(org.camunda.bpm.engine.delegate.DelegateExecution execution) throws Exception public virtual void execute(DelegateExecution execution) { TypedValue typedValue = execution.getVariableTyped("listVar"); IList <JsonSerializable> var = (IList <JsonSerializable>)typedValue.Value; JsonSerializable newElement = new JsonSerializable(); newElement.StringProperty = STRING_PROPERTY; // implicit update of the list, so no execution.setVariable call var.Add(newElement); }
public Void execute(CommandContext commandContext) { JsonSerializable bean = new JsonSerializable("a String", 42, true); outerInstance.runtimeService.setVariable(instance.Id, "simpleBean", bean); object returnedBean = outerInstance.runtimeService.getVariable(instance.Id, "simpleBean"); assertSame(bean, returnedBean); return(null); }
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 testFailForNonExistingSerializationFormat() { ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); JsonSerializable jsonSerializable = new JsonSerializable(); try { runtimeService.setVariable(instance.Id, "simpleBean", objectValue(jsonSerializable).serializationDataFormat("non existing data format")); fail("Exception expected"); } catch (ProcessEngineException e) { assertTextPresent("Cannot find serializer for value", e.Message); // happy path } }
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 testSetTypedNullForExistingVariable() { ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); // initially the variable has a value JsonSerializable javaSerializable = new JsonSerializable(); runtimeService.setVariable(instance.Id, "varName", objectValue(javaSerializable).serializationDataFormat(JSON_FORMAT_NAME).create()); // get value via untyped api assertEquals(javaSerializable, runtimeService.getVariable(instance.Id, "varName")); // set the variable to null via typed Api runtimeService.setVariable(instance.Id, "varName", objectValue(null)); // variable is still of type object ObjectValue typedValue = runtimeService.getVariableTyped(instance.Id, "varName"); assertObjectValueDeserializedNull(typedValue); }
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 testSetUntypedNullForExistingVariable() { ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); // initially the variable has a value JsonSerializable @object = new JsonSerializable(); runtimeService.setVariable(instance.Id, "varName", objectValue(@object).serializationDataFormat(JSON_FORMAT_NAME).create()); // get value via untyped api assertEquals(@object, runtimeService.getVariable(instance.Id, "varName")); // set the variable to null via untyped Api runtimeService.setVariable(instance.Id, "varName", null); // variable is now untyped null TypedValue nullValue = runtimeService.getVariableTyped(instance.Id, "varName"); assertUntypedNullValue(nullValue); }
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 testSelectHistoricVariableInstances() { 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).create()); HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().singleResult(); assertNotNull(historicVariable.Value); assertNull(historicVariable.ErrorMessage); assertEquals(ValueType.OBJECT.Name, historicVariable.TypeName); assertEquals(ValueType.OBJECT.Name, historicVariable.VariableTypeName); JsonSerializable historyValue = (JsonSerializable)historicVariable.Value; assertEquals(bean.StringProperty, historyValue.StringProperty); assertEquals(bean.IntProperty, historyValue.IntProperty); assertEquals(bean.BooleanProperty, historyValue.BooleanProperty); } }
public virtual void testSetSerializedVariableValueNull() { ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); //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().serializationDataFormat(JSON_FORMAT_NAME).objectTypeName(typeof(JsonSerializable).FullName); runtimeService.setVariable(instance.Id, "simpleBean", serializedValue); // null can be retrieved JsonSerializable returnedBean = (JsonSerializable)runtimeService.getVariable(instance.Id, "simpleBean"); assertNull(returnedBean); // validate typed value metadata ObjectValue typedValue = runtimeService.getVariableTyped(instance.Id, "simpleBean"); assertNull(typedValue.Value); assertNull(typedValue.ValueSerialized); 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(typeof(JsonSerializable).FullName, typedValue.ObjectTypeName); }
public virtual void testSetSerializedVariableValueNullNoTypeName() { ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); SerializedObjectValueBuilder serializedValue = serializedObjectValue().serializationDataFormat(JSON_FORMAT_NAME); // no objectTypeName specified runtimeService.setVariable(instance.Id, "simpleBean", serializedValue); // null can be retrieved JsonSerializable returnedBean = (JsonSerializable)runtimeService.getVariable(instance.Id, "simpleBean"); assertNull(returnedBean); // validate typed value metadata ObjectValue typedValue = runtimeService.getVariableTyped(instance.Id, "simpleBean"); assertNull(typedValue.Value); assertNull(typedValue.ValueSerialized); assertEquals(JSON_FORMAT_NAME, typedValue.SerializationDataFormat); assertNull(typedValue.ObjectTypeName); }
public override bool Equals(object obj) { if (this == obj) { return(true); } if (obj == null) { return(false); } if (this.GetType() != obj.GetType()) { return(false); } JsonSerializable other = (JsonSerializable)obj; if (booleanProperty != other.booleanProperty) { return(false); } if (intProperty != other.intProperty) { return(false); } if (string.ReferenceEquals(stringProperty, null)) { if (!string.ReferenceEquals(other.stringProperty, null)) { return(false); } } else if (!stringProperty.Equals(other.stringProperty)) { return(false); } return(true); }