Skip to content

Commit

Permalink
feat(element-templates): use new property implementationType
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderSkrock committed Sep 29, 2023
1 parent 19dea3a commit 2ae93b8
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/element-templates/CreateHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand All @@ -167,10 +168,9 @@ export function createCamundaExecutionListener(binding, value, bpmnFactory) {
});
}

const boundPropertyName = name || 'value';
return bpmnFactory.create('camunda:ExecutionListener', {
event,
[boundPropertyName]: value
[implementationType]: value
});
}

Expand Down
96 changes: 93 additions & 3 deletions test/spec/element-templates/CreateHelper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};

Expand All @@ -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
Expand All @@ -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}'
});
}));

});


Expand Down

0 comments on commit 2ae93b8

Please sign in to comment.