Skip to content

Commit

Permalink
chore: simplify tests
Browse files Browse the repository at this point in the history
* make test BPMN maintainable
* ensure correct variables are resolved (name is not sufficient)
  • Loading branch information
philippfromme committed Jan 23, 2025
1 parent 633ad3c commit 9ab2d32
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 90 deletions.
4 changes: 2 additions & 2 deletions lib/zeebe/util/feelUtility.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ export function getResultContext(expression, variables = {}) {
*/
function getExpressionDetails(variable, origin) {

// if variable scope is parent scope, first check IoExpression and then ScriptExpression
// if variable is local scope (origin), first check ScriptExpression and then IoExpression
// if variable scope is !== origin (global), prioritize IoExpression over ScriptExpression
// if variable scope is === origin (local), prioritize ScriptExpression over IoExpression
const expression = variable.scope !== origin
? getIoExpression(variable, origin) || getScriptExpression(variable, origin)
: getScriptExpression(variable, origin) || getIoExpression(variable, origin);
Expand Down
127 changes: 66 additions & 61 deletions test/fixtures/zeebe/mappings/scope.bpmn
Original file line number Diff line number Diff line change
@@ -1,145 +1,150 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1noegy9" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.28.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.1.0">
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1noegy9" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.31.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.1.0">
<bpmn:collaboration id="Collaboration_0e60zir">
<bpmn:participant id="Participant_1" processRef="Process_1" />
<bpmn:participant id="Participant_2" processRef="Process_2" />
<bpmn:participant id="Participant_3" processRef="Process_3" />
<bpmn:participant id="Participant_4" processRef="Process_4" />
<bpmn:participant id="Participant_5" processRef="Process_5" />
<bpmn:participant id="Participant_6" processRef="Process_6" />
<bpmn:participant id="Participant_7" processRef="Process_7" />
<bpmn:participant id="Participant_1" name="Participant_1" processRef="Process_1" />
<bpmn:participant id="Participant_2" name="Participant_2" processRef="Process_2" />
<bpmn:participant id="Participant_3" name="Participant_3" processRef="Process_3" />
<bpmn:participant id="Participant_4" name="Participant_4" processRef="Process_4" />
<bpmn:participant id="Participant_5" name="Participant_5" processRef="Process_5" />
<bpmn:participant id="Participant_6" name="Participant_6" processRef="Process_6" />
<bpmn:participant id="Participant_7" name="Participant_7" processRef="Process_7" />
</bpmn:collaboration>
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:serviceTask id="scopedContext" name="Scoped Context">
<bpmn:serviceTask id="ServiceTask_1" name="Input &#38; output in scope">
<bpmn:extensionElements>
<zeebe:ioMapping>
<zeebe:input source="=globalVariable" target="scopedInput" />
<zeebe:output source="=scopedInput" target="validMapping" />
<zeebe:input source="=globalVariable" target="fooInputVariable" />
<zeebe:output source="=fooInputVariable" target="fooOutputVariable" />
</zeebe:ioMapping>
</bpmn:extensionElements>
</bpmn:serviceTask>
<bpmn:serviceTask id="Activity_0kafybg">
<bpmn:serviceTask id="ServiceTask_2" name="Input out of scope">
<bpmn:extensionElements>
<zeebe:ioMapping>
<zeebe:output source="=scopedInput" target="invalidMapping" />
<zeebe:output source="=fooInputVariable" target="barOutputVariable" />
</zeebe:ioMapping>
</bpmn:extensionElements>
</bpmn:serviceTask>
</bpmn:process>
<bpmn:process id="Process_2" isExecutable="false">
<bpmn:scriptTask id="Activity_1" name="Script Task">
<bpmn:scriptTask id="ScriptTask_1" name="Result variable &#38; input with same name">
<bpmn:extensionElements>
<zeebe:script expression="={}" resultVariable="foo" />
<zeebe:script expression="=&#34;1&#34;" resultVariable="foo" />
<zeebe:ioMapping>
<zeebe:input source="=123" target="foo" />
<zeebe:output target="output" />
<zeebe:input source="=&#34;2&#34;" target="foo" />
<zeebe:output source="=&#34;3&#34;" target="output" />
</zeebe:ioMapping>
</bpmn:extensionElements>
</bpmn:scriptTask>
</bpmn:process>
<bpmn:process id="Process_3" isExecutable="false">
<bpmn:scriptTask id="Activity_2" name="Script Task">
<bpmn:scriptTask id="ScriptTask_2" name="Result variable &#38; outputs">
<bpmn:extensionElements>
<zeebe:script expression="={}" resultVariable="resultVariable" />
<zeebe:script expression="=&#34;1&#34;" resultVariable="resultVariable" />
<zeebe:ioMapping>
<zeebe:output source="={}" target="output" />
<zeebe:output source="=&#34;2&#34;" target="output" />
</zeebe:ioMapping>
</bpmn:extensionElements>
</bpmn:scriptTask>
</bpmn:process>
<bpmn:process id="Process_4" isExecutable="false">
<bpmn:scriptTask id="Activity_4" name="Script Task">
<bpmn:scriptTask id="ScriptTask_3" name="Result variable &#38; no outputs">
<bpmn:extensionElements>
<zeebe:script expression="={}" resultVariable="resultVariable" />
<zeebe:script expression="=&#34;1&#34;" resultVariable="resultVariable" />
</bpmn:extensionElements>
</bpmn:scriptTask>
</bpmn:process>
<bpmn:process id="Process_5" isExecutable="false">
<bpmn:scriptTask id="Activity_5" name="Script Task">
<bpmn:scriptTask id="ScriptTask_4" name="Result variable &#38; output with same name">
<bpmn:extensionElements>
<zeebe:script expression="={}" resultVariable="foo" />
<zeebe:script expression="=&#34;1&#34;" resultVariable="foo" />
<zeebe:ioMapping>
<zeebe:input source="=123" target="foo" />
<zeebe:output source="=&#34;bar&#34;" target="foo" />
<zeebe:output target="output" />
<zeebe:output source="=&#34;2&#34;" target="foo" />
<zeebe:output source="=&#34;3&#34;" target="output" />
</zeebe:ioMapping>
</bpmn:extensionElements>
</bpmn:scriptTask>
</bpmn:process>
<bpmn:process id="Process_6" isExecutable="false">
<bpmn:userTask id="Activity_6" name="User Task">
<bpmn:serviceTask id="ServiceTask_3" name="Input &#38; output with same name">
<bpmn:extensionElements>
<zeebe:ioMapping>
<zeebe:input source="=123" target="foo" />
<zeebe:output source="={}" target="foo" />
<zeebe:output target="output" />
<zeebe:input source="=&#34;1&#34;" target="foo" />
<zeebe:output source="=&#34;2&#34;" target="foo" />
<zeebe:output source="=&#34;3&#34;" target="output" />
</zeebe:ioMapping>
</bpmn:extensionElements>
</bpmn:userTask>
</bpmn:serviceTask>
</bpmn:process>
<bpmn:process id="Process_7" isExecutable="false">
<bpmn:userTask id="Activity_7" name="User Task">
<bpmn:serviceTask id="ServiceTask_4" name="Inputs with same name">
<bpmn:extensionElements>
<zeebe:ioMapping>
<zeebe:input source="={}" target="foo" />
<zeebe:input source="=&#34;abc&#34;" target="foo" />
<zeebe:input source="=123" target="foo" />
<zeebe:input source="=&#34;1&#34;" target="foo" />
<zeebe:input source="=&#34;2&#34;" target="foo" />
</zeebe:ioMapping>
</bpmn:extensionElements>
</bpmn:userTask>
</bpmn:serviceTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_0e60zir">
<bpmndi:BPMNShape id="Participant_10jajek_di" bpmnElement="Participant_1" isHorizontal="true">
<dc:Bounds x="160" y="85" width="600" height="250" />
<dc:Bounds x="180" y="60" width="300" height="120" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1n52sm3_di" bpmnElement="scopedContext">
<dc:Bounds x="330" y="170" width="100" height="80" />
<bpmndi:BPMNShape id="Activity_1n52sm3_di" bpmnElement="ServiceTask_1">
<dc:Bounds x="230" y="80" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1hlau9e_di" bpmnElement="Activity_0kafybg">
<dc:Bounds x="480" y="170" width="100" height="80" />
<bpmndi:BPMNShape id="Activity_1hlau9e_di" bpmnElement="ServiceTask_2">
<dc:Bounds x="350" y="80" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Participant_0o4apj6_di" bpmnElement="Participant_2" isHorizontal="true">
<dc:Bounds x="160" y="380" width="600" height="250" />
<dc:Bounds x="500" y="60" width="300" height="120" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_06g1sod_di" bpmnElement="Activity_1">
<dc:Bounds x="290" y="460" width="100" height="80" />
<bpmndi:BPMNShape id="Activity_06g1sod_di" bpmnElement="ScriptTask_1">
<dc:Bounds x="550" y="80" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Participant_13eqjzi_di" bpmnElement="Participant_3" isHorizontal="true">
<dc:Bounds x="160" y="690" width="600" height="250" />
<dc:Bounds x="820" y="60" width="300" height="120" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1c85kz4_di" bpmnElement="Activity_2">
<dc:Bounds x="280" y="780" width="100" height="80" />
<bpmndi:BPMNShape id="Activity_1c85kz4_di" bpmnElement="ScriptTask_2">
<dc:Bounds x="870" y="80" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_0o2k4bk" bpmnElement="Participant_4" isHorizontal="true">
<dc:Bounds x="160" y="1010" width="600" height="250" />
<dc:Bounds x="180" y="200" width="300" height="120" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_1wqur3c" bpmnElement="Activity_4">
<dc:Bounds x="280" y="1100" width="100" height="80" />
<bpmndi:BPMNShape id="BPMNShape_1wqur3c" bpmnElement="ScriptTask_3">
<dc:Bounds x="230" y="220" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Participant_08w9t3p_di" bpmnElement="Participant_5" isHorizontal="true">
<dc:Bounds x="160" y="1330" width="600" height="250" />
<dc:Bounds x="500" y="200" width="300" height="120" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0jkek8a_di" bpmnElement="Activity_5">
<dc:Bounds x="280" y="1410" width="100" height="80" />
<bpmndi:BPMNShape id="Activity_0jkek8a_di" bpmnElement="ScriptTask_4">
<dc:Bounds x="550" y="220" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Participant_1cpioa5_di" bpmnElement="Participant_6" isHorizontal="true">
<dc:Bounds x="160" y="1660" width="600" height="250" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0gwc003_di" bpmnElement="Activity_6">
<dc:Bounds x="310" y="1740" width="100" height="80" />
<dc:Bounds x="820" y="200" width="300" height="120" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0pvyvzm_di" bpmnElement="ServiceTask_3">
<dc:Bounds x="870" y="220" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Participant_0hcijo0_di" bpmnElement="Participant_7" isHorizontal="true">
<dc:Bounds x="160" y="1980" width="600" height="250" />
<dc:Bounds x="180" y="340" width="300" height="120" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1aor9g3_di" bpmnElement="Activity_7">
<dc:Bounds x="310" y="2060" width="100" height="80" />
<bpmndi:BPMNShape id="Activity_1533gjq_di" bpmnElement="ServiceTask_4">
<dc:Bounds x="230" y="360" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
Expand Down
54 changes: 27 additions & 27 deletions test/spec/zeebe/Mappings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ describe('ZeebeVariableResolver - Variable Mappings', function() {

const initialVariables = [ {
name: 'globalVariable',
type: 'TestVariable',
info: 'TestInfo',
type: 'String',
info: '1',
entries: [ ]
} ];

Expand All @@ -305,20 +305,20 @@ describe('ZeebeVariableResolver - Variable Mappings', function() {
expect(variables).to.variableEqual([
...initialVariables,
{
name: 'validMapping',
type: 'TestVariable',
info: 'TestInfo'
name: 'fooOutputVariable',
type: 'String',
info: '1'
},
{
name: 'invalidMapping',
name: 'barOutputVariable',
type: '',
info: ''
}
]);
}));


it('should only resolve the result variable globally given no output exists', inject(async function(variableResolver, elementRegistry) {
it('should resolve result variable if no outputs exist', inject(async function(variableResolver, elementRegistry) {

// given
const root = elementRegistry.get('Participant_4');
Expand All @@ -330,14 +330,14 @@ describe('ZeebeVariableResolver - Variable Mappings', function() {
expect(variables).to.variableEqual([
{
name: 'resultVariable',
type: '',
info: '',
type: 'String',
info: '1'
}
]);
}));


it('should only resolve the result variable locally if output exists', inject(async function(variableResolver, elementRegistry) {
it('should resolve output instead of result variable if outputs exist', inject(async function(variableResolver, elementRegistry) {

// given
const root = elementRegistry.get('Participant_3');
Expand All @@ -349,17 +349,17 @@ describe('ZeebeVariableResolver - Variable Mappings', function() {
expect(variables).to.variableEqual([
{
name: 'output',
type: '',
info: '',
type: 'String',
info: '2'
}
]);
}));


it('should only resolve the result variable if input and result variable names conflict', inject(async function(variableResolver, elementRegistry) {
it('should only resolve result variable if input and result variable with same name exist', inject(async function(variableResolver, elementRegistry) {

// given
const root = elementRegistry.get('Activity_1');
const root = elementRegistry.get('ScriptTask_1');
const bo = root.businessObject;
const output = getInputOutput(bo).outputParameters[0];

Expand All @@ -370,17 +370,17 @@ describe('ZeebeVariableResolver - Variable Mappings', function() {
expect(variables).to.variableEqual([
{
name: 'foo',
type: '',
info: '',
type: 'String',
info: '1'
}
]);
}));


it('should only resolve the output variable if result variable and output names conflict', inject(async function(variableResolver, elementRegistry) {
it('should only resolve the output variable if result variable and output with same name exist', inject(async function(variableResolver, elementRegistry) {

// given
const root = elementRegistry.get('Activity_5');
const root = elementRegistry.get('ScriptTask_4');
const bo = root.businessObject;
const output = getInputOutput(bo).outputParameters[1];

Expand All @@ -392,16 +392,16 @@ describe('ZeebeVariableResolver - Variable Mappings', function() {
{
name: 'foo',
type: 'String',
info: 'bar',
info: '2'
}
]);
}));


it('should only resolve the output variable if input and output names conflict', inject(async function(variableResolver, elementRegistry) {
it('should only resolve the output variable if input and output with same name exist', inject(async function(variableResolver, elementRegistry) {

// given
const root = elementRegistry.get('Activity_6');
const root = elementRegistry.get('ServiceTask_3');
const bo = root.businessObject;
const output = getInputOutput(bo).outputParameters[1];

Expand All @@ -412,17 +412,17 @@ describe('ZeebeVariableResolver - Variable Mappings', function() {
expect(variables).to.variableEqual([
{
name: 'foo',
type: '',
info: '',
type: 'String',
info: '2'
}
]);
}));


it('should only resolve the latest variable if same name input/output exists', inject(async function(variableResolver, elementRegistry) {
it('should only resolve the latest variable if inputs with same name exist', inject(async function(variableResolver, elementRegistry) {

// given
const root = elementRegistry.get('Activity_7');
const root = elementRegistry.get('ServiceTask_4');

// when
const variables = await variableResolver.getVariablesForElement(root.businessObject);
Expand All @@ -431,8 +431,8 @@ describe('ZeebeVariableResolver - Variable Mappings', function() {
expect(variables).to.variableEqual([
{
name: 'foo',
type: 'Number',
info: '123',
type: 'String',
info: '2'
}
]);
}));
Expand Down

0 comments on commit 9ab2d32

Please sign in to comment.