diff --git a/src/element-templates/CreateHelper.js b/src/element-templates/CreateHelper.js index 87a7e4a2..ebbf668f 100644 --- a/src/element-templates/CreateHelper.js +++ b/src/element-templates/CreateHelper.js @@ -153,11 +153,12 @@ export function createCamundaOut(binding, value, bpmnFactory) { export function createCamundaExecutionListener(binding, value, bpmnFactory) { const { event, - name, + implementationType, scriptFormat } = binding; - if (scriptFormat) { + // To guarantee backwards compatibility scriptFormat is taken into account and has precedence before any other type + if (implementationType === 'script' || scriptFormat) { return bpmnFactory.create('camunda:ExecutionListener', { event, script: bpmnFactory.create('camunda:Script', { @@ -167,10 +168,9 @@ export function createCamundaExecutionListener(binding, value, bpmnFactory) { }); } - const boundPropertyName = name || 'value'; return bpmnFactory.create('camunda:ExecutionListener', { event, - [boundPropertyName]: value + [implementationType]: value }); } diff --git a/test/spec/element-templates/CreateHelper.spec.js b/test/spec/element-templates/CreateHelper.spec.js index 2bc7bee3..f8f72604 100644 --- a/test/spec/element-templates/CreateHelper.spec.js +++ b/test/spec/element-templates/CreateHelper.spec.js @@ -461,12 +461,37 @@ describe('provider/element-templates - CreateHelper', function() { describe('createExecutionListener', function() { - it('should create script', inject(function(bpmnFactory) { + it('should create script without explicit implementation type', inject(function(bpmnFactory) { + + // given + const binding = { + type: 'camunda:executionListener', + event: 'end', + scriptFormat: 'groovy' + }; + + // when + const listener = createCamundaExecutionListener(binding, 'println execution.eventName', bpmnFactory); + + // then + expect(listener).to.jsonEqual({ + $type: 'camunda:ExecutionListener', + event: 'end', + script: { + $type: 'camunda:Script', + scriptFormat: 'groovy', + value: 'println execution.eventName' + } + }); + })); + + it('should create script with implementation type script', inject(function(bpmnFactory) { // given const binding = { type: 'camunda:executionListener', event: 'end', + implementationType: 'script', scriptFormat: 'groovy' }; @@ -485,13 +510,38 @@ describe('provider/element-templates - CreateHelper', function() { }); })); - it('should bind value to configured property', inject(function(bpmnFactory) { + it('should create script with with script format ignoring the implementation type for backwards compatibility', inject(function(bpmnFactory) { // given const binding = { type: 'camunda:executionListener', event: 'end', - name: 'class' + implementationType: 'class', + scriptFormat: 'groovy' + }; + + // when + const listener = createCamundaExecutionListener(binding, 'println execution.eventName', bpmnFactory); + + // then + expect(listener).to.jsonEqual({ + $type: 'camunda:ExecutionListener', + event: 'end', + script: { + $type: 'camunda:Script', + scriptFormat: 'groovy', + value: 'println execution.eventName' + } + }); + })); + + it('should create class-based execution listener', inject(function(bpmnFactory) { + + // given + const binding = { + type: 'camunda:executionListener', + event: 'end', + implementationType: 'class' }; // when @@ -505,6 +555,46 @@ describe('provider/element-templates - CreateHelper', function() { }); })); + it('should create expression-based execution listener', inject(function(bpmnFactory) { + + // given + const binding = { + type: 'camunda:executionListener', + event: 'end', + implementationType: 'expression' + }; + + // when + const listener = createCamundaExecutionListener(binding, '${expression}', bpmnFactory); + + // then + expect(listener).to.jsonEqual({ + $type: 'camunda:ExecutionListener', + event: 'end', + expression: '${expression}' + }); + })); + + it('should create delegateExpression-based execution listener', inject(function(bpmnFactory) { + + // given + const binding = { + type: 'camunda:executionListener', + event: 'end', + implementationType: 'delegateExpression' + }; + + // when + const listener = createCamundaExecutionListener(binding, '${delegate}', bpmnFactory); + + // then + expect(listener).to.jsonEqual({ + $type: 'camunda:ExecutionListener', + event: 'end', + delegateExpression: '${delegate}' + }); + })); + });