Search in sources :

Example 1 with XmlValue

use of org.camunda.spin.plugin.variable.value.XmlValue in project camunda-bpm-platform by camunda.

the class XmlValueTest method testXmlValueInCondition.

@Deployment(resources = "org/camunda/spin/plugin/xmlConditionProcess.bpmn20.xml")
public void testXmlValueInCondition() {
    // given
    String xmlString = "<customer age=\"22\" />";
    XmlValue value = xmlValue(xmlString).create();
    VariableMap variables = Variables.createVariables().putValueTyped("customer", value);
    // when
    runtimeService.startProcessInstanceByKey("process", variables);
    // then
    Task task = taskService.createTaskQuery().singleResult();
    assertEquals("task1", task.getTaskDefinitionKey());
}
Also used : Task(org.camunda.bpm.engine.task.Task) VariableMap(org.camunda.bpm.engine.variable.VariableMap) XmlValue(org.camunda.spin.plugin.variable.value.XmlValue) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 2 with XmlValue

use of org.camunda.spin.plugin.variable.value.XmlValue 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 XmlValue

use of org.camunda.spin.plugin.variable.value.XmlValue in project camunda-bpm-platform by camunda.

the class XmlValueTest method testFailingDeserialization.

@Deployment(resources = ONE_TASK_PROCESS)
public void testFailingDeserialization() {
    // given
    XmlValue value = xmlValue(brokenXmlString).create();
    String processInstanceId = runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS_KEY).getId();
    runtimeService.setVariable(processInstanceId, variableName, value);
    try {
        // when
        runtimeService.getVariable(processInstanceId, variableName);
        fail("exception expected");
    } catch (ProcessEngineException e) {
    // happy path
    }
    try {
        runtimeService.getVariableTyped(processInstanceId, variableName);
        fail("exception expected");
    } catch (ProcessEngineException e) {
    // happy path
    }
    // However, I can access the serialized value
    XmlValue xmlValue = runtimeService.getVariableTyped(processInstanceId, variableName, false);
    assertFalse(xmlValue.isDeserialized());
    assertEquals(brokenXmlString, xmlValue.getValueSerialized());
    // but not the deserialized properties
    try {
        xmlValue.getValue();
        fail("exception expected");
    } catch (SpinRuntimeException e) {
    }
}
Also used : SpinRuntimeException(org.camunda.spin.SpinRuntimeException) XmlValue(org.camunda.spin.plugin.variable.value.XmlValue) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 4 with XmlValue

use of org.camunda.spin.plugin.variable.value.XmlValue in project camunda-bpm-platform by camunda.

the class XmlValueTest method testGetUntypedXmlValue.

@Deployment(resources = ONE_TASK_PROCESS)
public void testGetUntypedXmlValue() {
    // given
    XmlValue xmlValue = xmlValue(xmlString).create();
    VariableMap variables = Variables.createVariables().putValueTyped(variableName, xmlValue);
    String processInstanceId = runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS_KEY, variables).getId();
    // when
    SpinXmlElement value = (SpinXmlElement) runtimeService.getVariable(processInstanceId, variableName);
    // then
    assertTrue(value.hasAttr("attrName"));
    assertEquals("attrValue", value.attr("attrName").value());
    assertTrue(value.childElements().isEmpty());
    assertEquals(xml().getName(), value.getDataFormatName());
}
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 5 with XmlValue

use of org.camunda.spin.plugin.variable.value.XmlValue in project camunda-bpm-platform by camunda.

the class XmlValueTest method testBrokenXmlSerialization.

@Deployment(resources = ONE_TASK_PROCESS)
public void testBrokenXmlSerialization() {
    // given
    XmlValue value = xmlValue(brokenXmlString).create();
    String processInstanceId = runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS_KEY).getId();
    try {
        // when
        runtimeService.setVariable(processInstanceId, variableName, value);
    } catch (Exception e) {
        fail("no exception expected");
    }
}
Also used : XmlValue(org.camunda.spin.plugin.variable.value.XmlValue) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) SpinRuntimeException(org.camunda.spin.SpinRuntimeException) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

Deployment (org.camunda.bpm.engine.test.Deployment)6 XmlValue (org.camunda.spin.plugin.variable.value.XmlValue)6 VariableMap (org.camunda.bpm.engine.variable.VariableMap)4 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)2 SpinRuntimeException (org.camunda.spin.SpinRuntimeException)2 SpinXmlElement (org.camunda.spin.xml.SpinXmlElement)2 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)1 Task (org.camunda.bpm.engine.task.Task)1