Using SPIN in javascript tests / `setVariable` with array

Hello,

I am using Camunda 7.19.0 and writing unit tests for a bpmn that use script elements implemented in javascript.

The script works and I am able to access the execution with its getVariable and setVariable methods.

The setVariable works fine with string objects, but it fails with arrays.

    // fails with: Cannot find serializer for value 'Untyped value '(3)[4, 5, 6]', isTransient = false'.
    execution.setVariable("var1", [4, 5, 6]);

I see that SPIN could/should be used to add such serialization capabilities.

I have included the following in the POM

        <dependency>
            <groupId>org.camunda.spin</groupId>
            <artifactId>camunda-spin-dataformat-all</artifactId>
        </dependency>
        <dependency>
            <groupId>org.camunda.bpm</groupId>
            <artifactId>camunda-engine-plugin-spin</artifactId>
        </dependency>

and from the start-up logs it seems detected

17:47:37.948 [main] INFO org.camunda.bpm.dmn.feel.scala - FEEL/SCALA-01001 Spin value mapper detected
17:47:38.037 [main] INFO org.camunda.feel.FeelEngine - Engine created. [value-mapper: CompositeValueMapper(List(org.camunda.feel.impl.JavaValueMapper@6b85300e, org.camunda.spin.plugin.impl.feel.integration.SpinValueMapper@3aaf4f07)), function-provider: org.camunda.bpm.dmn.feel.impl.scala.function.CustomFunctionTransformer@1556f2dd, clock: SystemClock, configuration: Configuration(false)]

I cannot manage to access the S function


    // fails with: ReferenceError: S is not defined
    execution.setVariable("var1", S(JSON.stringify([4, 5, 6])));

the script is declared as follows in the bpmn

<bpmn:scriptTask id="Activity_0crcxhm" name="script" scriptFormat="javascript" camunda:resource="deployment://serialize/serialize.js">

the tests are run using org.camunda.bpm.engine.test.junit5.ProcessEngineExtension;

the JS engine is added to the pom as:

        <dependency>
            <groupId>org.graalvm.js</groupId>
            <artifactId>js</artifactId>
            <version>23.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.graalvm.js</groupId>
            <artifactId>js-scriptengine</artifactId>
            <version>23.0.1</version>
        </dependency>

I imagine something goes wrong when setting up the javascript engine, so that SPIN is not available there.

Any ideas?

problem solved.

I was missing

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

in camunda.cfg.xml.

relevant docs: https://github.com/camunda/camunda-bpm-examples/tree/master/servicetask/rest-service

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.