Unable to start process in unit test

I am writing a unit test for a process and want to start the process using the following:

String businessKey = "aBusinessKey";
ProcessInstance processInstance = processEngine().getRuntimeService()
    .startProcessInstanceByKey("ST_Onboard_Merchant", businessKey,
     withVariables(
         "correlationKey", "1234-1234-1234",
         "merchant", merchant
    ));

The last process variable (merchant) is a POJO called Merchant that contains a bunch of strings and an ArrayList of enum values.
When I execute the unit test I get the following error message:

**org.camunda.bpm.engine.ProcessEngineException: Cannot find serializer for value 'Untyped value 'model.Merchant@758f4f03''.**

Any idea what is going wrong? The process itself appears to work correctly when run inside a Tomcat instance running Camunda 7.4

Hi,

Does the Merchant class implement java.io.Serializable?

Also, see these docs: https://docs.camunda.org/manual/7.4/user-guide/process-engine/variables/#object-value-serialization

Cheers,
Thorben

No it doesnā€™t. Why is this needed for unit tests but not for running in an actual Camunda instance?

The unit tests are now working (added implements Serializable). Thanks for the help.

Hi @mike_g,

Good to read that you were able to resolve that problem.

I guess the Camunda instance has additional serializers configured that enable serializing objects as JSON and XML, which are not present in your unit test setting (see the documentation on integrating Camunda Spin https://docs.camunda.org/manual/7.4/user-guide/data-formats/). Afaik, the XML serializer attempts to serialize any object if no other serializer is able to handle it.

Cheers,
Thorben

If youā€™re relying on Camunda Spin to automatically serialise your object to JSON or XML then Iā€™ve found adding Serializable actually breaks this functionality (youā€™ll get a text representation of the Java object serialisation instead of JSON or XML). The error youā€™re receiving is likely related to not explicitly configuring the Camunda Spin plugin in the unit test engine i.e.

<bean id="processEngineConfiguration"
      class="org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
    <property name="databaseSchemaUpdate" value="true"/>
    <property name="jobExecutorActivate" value="false"/>
    <property name="expressionManager">
        <bean class="org.camunda.bpm.engine.test.mock.MockExpressionManager"/>
    </property>
    <property name="processEnginePlugins">
        <list>
            <bean class="org.camunda.spin.plugin.impl.SpinProcessEnginePlugin"/>
        </list>
    </property>
</bean>

Youā€™ll also have to add the Camunda Spin related dependencies to your pom file with ā€˜testā€™ scope.

2 Likes

I totally agree with that: Serializable should not be needed if you use SPIN Dataformats.

But even with the SPIN plugin added to unit tests, the problem persists. The error is gone when I add ā€œimplements Serializableā€.

Here we see that SPIN is loaded with my custom configuration of the DataFormat (mapper)

    [Test worker] INFO  org.camunda.bpm.engine.cfg - ENGINE-12003 Plugin 'SpinProcessEnginePlugin' activated on process engine 'default'
    [Test worker] INFO  org.camunda.spin - SPIN-01010 Discovered Spin data format provider: org.camunda.spin.impl.json.jackson.format.JacksonJsonDataFormatProvider[name = application/json]
    [Test worker] INFO  org.camunda.spin - SPIN-01011 Discovered Spin data format configurator: class my.company.workflow.engine.config.JacksonDataFormatConfigurator[dataformat = org.camunda.spin.impl.json.jackson.format.JacksonJsonDataFormat]
    [Test worker] INFO  org.camunda.spin - SPIN-01009 Discovered Spin data format: org.camunda.spin.impl.json.jackson.format.JacksonJsonDataFormat[name = application/json]
    [Test worker] INFO  org.camunda.bpm.dmn.feel.scala - FEEL/SCALA-01001 Spin value mapper detected
    [Test worker] INFO  org.camunda.feel.FeelEngine - Engine created. [value-mapper: CompositeValueMapper(List(org.camunda.feel.impl.JavaValueMapper@81d998d, org.camunda.spin.plugin.impl.feel.integration.SpinValueMapper@648499b5)), function-provider: org.camunda.bpm.dmn.feel.impl.scala.function.CustomFunctionTransformer@381d6f65, configuration: Configuration(false)]

The test fails but is successful with ā€œimplements Serializableā€
In real life, the object is well managed by the engine (without ā€œimplements Serializableā€).

It is weird !

Camunda version: 7.13.0
testImplementation ā€˜org.camunda.bpm.extension:camunda-bpm-junit5:1.0.1ā€™
testImplementation ā€˜org.camunda.bpm.assert:camunda-bpm-assert:7.0.0ā€™
testImplementation ā€˜org.camunda.bpm.extension.mockito:camunda-bpm-mockito:5.15.0ā€™
testImplementation ā€˜org.camunda.bpm.extension:camunda-bpm-assert-scenario:1.0.0ā€™

Hi @NicolasD-J and @Anderb,

I remember vaguely from the past, that you can serialize to JSON, if you add the spin libraries and set the defaultSerializationFormat to application/json.

The objects were serialized as JSON without implementing Serializable.

Hope this helps, Ingo

Thank you very much Ingo. It was exactly the solution. It works with:

Here is the configuration OK for my Unit test:

<bean id="processEngineConfiguration" class="org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
<!-- <bean id="processEngineConfiguration" class="org.camunda.bpm.extension.process_test_coverage.junit.rules.ProcessCoverageInMemProcessEngineConfiguration"> -->
            <property name="history" value="audit" />
            <property name="databaseSchemaUpdate" value="true" />
            <property name="jobExecutorActivate" value="false" />
            <property name="defaultSerializationFormat" value="application/json" />
            <!--<property name="expressionManager">
                <bean class="org.camunda.bpm.engine.test.mock.MockExpressionManager" />
            </property>-->
            <!-- engine plugins -->
			<property name="processEnginePlugins">
			  <list>
				<!--<ref bean="connectProcessEnginePlugin" />-->
				<ref bean="spinProcessEnginePlugin" />
			  </list>
			</property>
			<!-- <property name="idGenerator">
				<bean class="org.camunda.bpm.engine.impl.persistence.StrongUuidGenerator"/>
			</property> -->
    </bean>
    <!-- engine plugin beans -->
    <!--  <bean id="connectProcessEnginePlugin" class="org.camunda.connect.plugin.impl.ConnectProcessEnginePlugin" /> -->
    <bean id="spinProcessEnginePlugin" class="org.camunda.spin.plugin.impl.SpinProcessEnginePlugin" />

</beans>
1 Like