Search in sources :

Example 1 with SpinXmlElement

use of org.camunda.spin.xml.SpinXmlElement in project camunda-bpm-platform by camunda.

the class XmlSerializationTest method testGetSerializedVariableValue.

@Deployment(resources = ONE_TASK_PROCESS)
public void testGetSerializedVariableValue() {
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    XmlSerializable bean = new XmlSerializable("a String", 42, true);
    runtimeService.setVariable(instance.getId(), "simpleBean", objectValue(bean).serializationDataFormat(XML_FORMAT_NAME).create());
    ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "simpleBean", false);
    SpinXmlElement serializedValue = Spin.XML(typedValue.getValueSerialized());
    assertEquals(bean.getStringProperty(), serializedValue.childElement("stringProperty").textContent());
    assertEquals(bean.getBooleanProperty(), Boolean.parseBoolean(serializedValue.childElement("booleanProperty").textContent()));
    assertEquals(bean.getIntProperty(), Integer.parseInt(serializedValue.childElement("intProperty").textContent()));
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) Variables.serializedObjectValue(org.camunda.bpm.engine.variable.Variables.serializedObjectValue) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) SpinXmlElement(org.camunda.spin.xml.SpinXmlElement) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 2 with SpinXmlElement

use of org.camunda.spin.xml.SpinXmlElement in project camunda-bpm-platform by camunda.

the class XmlValueTest method testGetTypedXmlValue.

@Deployment(resources = ONE_TASK_PROCESS)
public void testGetTypedXmlValue() {
    // given
    XmlValue xmlValue = xmlValue(xmlString).create();
    VariableMap variables = Variables.createVariables().putValueTyped(variableName, xmlValue);
    String processInstanceId = runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS_KEY, variables).getId();
    // when
    XmlValue typedValue = runtimeService.getVariableTyped(processInstanceId, variableName);
    // then
    SpinXmlElement value = typedValue.getValue();
    assertTrue(value.hasAttr("attrName"));
    assertEquals("attrValue", value.attr("attrName").value());
    assertTrue(value.childElements().isEmpty());
    assertTrue(typedValue.isDeserialized());
    assertEquals(XML, typedValue.getType());
    assertEquals(XML_FORMAT_NAME, typedValue.getSerializationDataFormat());
    assertEquals(xmlString, typedValue.getValueSerialized());
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) XmlValue(org.camunda.spin.plugin.variable.value.XmlValue) SpinXmlElement(org.camunda.spin.xml.SpinXmlElement) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 3 with SpinXmlElement

use of org.camunda.spin.xml.SpinXmlElement in project camunda-bpm-platform by camunda.

the class SpinFunctionMapperTest method testSpin_S_Available.

public void testSpin_S_Available() {
    SpinXmlElement spinXmlEl = executeExpression("${ S('" + xmlString + "') }");
    assertNotNull(spinXmlEl);
    assertEquals("elementName", spinXmlEl.name());
}
Also used : SpinXmlElement(org.camunda.spin.xml.SpinXmlElement)

Example 4 with SpinXmlElement

use of org.camunda.spin.xml.SpinXmlElement in project camunda-bpm-platform by camunda.

the class SpinFunctionMapperTest method testSpin_XML_Available.

public void testSpin_XML_Available() {
    SpinXmlElement spinXmlEl = executeExpression("${ XML('" + xmlString + "') }");
    assertNotNull(spinXmlEl);
    assertEquals("elementName", spinXmlEl.name());
}
Also used : SpinXmlElement(org.camunda.spin.xml.SpinXmlElement)

Example 5 with SpinXmlElement

use of org.camunda.spin.xml.SpinXmlElement in project camunda-bpm-platform by camunda.

the class XmlSerializationTest method testSerializationAsXml.

@Deployment(resources = ONE_TASK_PROCESS)
public void testSerializationAsXml() {
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    XmlSerializable bean = new XmlSerializable("a String", 42, true);
    // request object to be serialized as XML
    runtimeService.setVariable(instance.getId(), "simpleBean", objectValue(bean).serializationDataFormat(XML_FORMAT_NAME).create());
    // validate untyped value
    Object value = runtimeService.getVariable(instance.getId(), "simpleBean");
    assertEquals(bean, value);
    // validate typed value
    ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "simpleBean");
    assertEquals(ValueType.OBJECT, typedValue.getType());
    assertTrue(typedValue.isDeserialized());
    assertEquals(bean, typedValue.getValue());
    assertEquals(bean, typedValue.getValue(XmlSerializable.class));
    assertEquals(XmlSerializable.class, typedValue.getObjectType());
    assertEquals(XML_FORMAT_NAME, typedValue.getSerializationDataFormat());
    assertEquals(XmlSerializable.class.getName(), typedValue.getObjectTypeName());
    SpinXmlElement serializedValue = Spin.XML(typedValue.getValueSerialized());
    assertEquals(bean.getStringProperty(), serializedValue.childElement("stringProperty").textContent());
    assertEquals(bean.getBooleanProperty(), Boolean.parseBoolean(serializedValue.childElement("booleanProperty").textContent()));
    assertEquals(bean.getIntProperty(), Integer.parseInt(serializedValue.childElement("intProperty").textContent()));
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) Variables.serializedObjectValue(org.camunda.bpm.engine.variable.Variables.serializedObjectValue) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) SpinXmlElement(org.camunda.spin.xml.SpinXmlElement) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

SpinXmlElement (org.camunda.spin.xml.SpinXmlElement)6 Deployment (org.camunda.bpm.engine.test.Deployment)4 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)2 VariableMap (org.camunda.bpm.engine.variable.VariableMap)2 Variables.serializedObjectValue (org.camunda.bpm.engine.variable.Variables.serializedObjectValue)2 ObjectValue (org.camunda.bpm.engine.variable.value.ObjectValue)2 XmlValue (org.camunda.spin.plugin.variable.value.XmlValue)2