Unit Testing a process that uses Json

I want to test my process that is usually started via REST API and so it requires JSONs as input variables.

I use the following call to start the process:

runtimeService.startProcessInstanceByKey(
        "myProcess",
        in.asJavaVars()
      )

The in.asJavaVars() is a Map<String, Object> as required.

I tried different things to provide my Jsons. The most promising were:
String myJson = "{\"tag\":\"okidoki\",\"isOk\":\"false\"}"
Spin.JSON(myJson)
new JsonValueImpl(Spin.JSON(myJson), null, null, true)

Both give me:
org.camunda.bpm.engine.ProcessEngineException: Cannot find serializer for value 'Untyped value '{"tag":"okidoki","isOk":"false"}', isTransient = false'.

I found no other API that allows to start the Process with Typed Variables.

Hi @pme123,

I recently did it this way:

ProcessUnitTest snippet:

    ObjectMapper objectMapper = new ObjectMapper();
    List<OrderItem> orderItems = List.of(new OrderItem().articleId("2").quantity(1));
    SpinValue orderItemsJson = SpinValues.jsonValue(objectMapper.writeValueAsString(orderItems)).create();

    ProcessInstance processInstance = runtimeService().startProcessInstanceByKey("OrderHandlingProcess",
        withVariables("orderItems", orderItemsJson));

and configured the engine with Spin in camunda.cfg.xml:

    <property name="processEnginePlugins">
      <list>
        <bean class="org.camunda.spin.plugin.impl.SpinProcessEnginePlugin"/>
      </list>
    </property>

Hope this helps, Ingo

2 Likes

Hi @Ingo_Richtsmeier
Thanks :partying_face: - that was all that was needed - I was mislead, as it worked in the Spring Boot App without any configuration (dependency is enough).
Greetings, Pascal