-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
escalation-boundary-event-attached-to-ref
rule
Closes #110
- Loading branch information
1 parent
30044bb
commit 16ab601
Showing
10 changed files
with
246 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
rules/camunda-cloud/escalation-boundary-event-attached-to-ref.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const { | ||
is, | ||
isAny | ||
} = require('bpmnlint-utils'); | ||
|
||
const { | ||
getEventDefinition, | ||
isAnyExactly | ||
} = require('../utils/element'); | ||
|
||
const { ERROR_TYPES } = require('../utils/error-types'); | ||
|
||
const { reportErrors } = require('../utils/reporter'); | ||
|
||
const { skipInNonExecutableProcess } = require('../utils/rule'); | ||
|
||
module.exports = skipInNonExecutableProcess(function() { | ||
function check(node, reporter) { | ||
if (!isAny(node, [ 'bpmn:CatchEvent', 'bpmn:ThrowEvent' ])) { | ||
return; | ||
} | ||
|
||
const eventDefinition = getEventDefinition(node); | ||
|
||
if (!eventDefinition || !is(eventDefinition, 'bpmn:EscalationEventDefinition')) { | ||
return; | ||
} | ||
|
||
const attachedToRef = node.get('attachedToRef'); | ||
|
||
if (attachedToRef && !isAnyExactly(attachedToRef, [ 'bpmn:CallActivity', 'bpmn:SubProcess' ])) { | ||
reportErrors(node, reporter, { | ||
message: `Element of type <bpmn:BoundaryEvent> with event definition of type <bpmn:EscalationEventDefinition> is not allowed to be attached to element of type <${ attachedToRef.$type }>`, | ||
path: null, | ||
data: { | ||
type: ERROR_TYPES.ATTACHED_TO_REF_ELEMENT_TYPE_NOT_ALLOWED, | ||
node, | ||
parentNode: null, | ||
attachedToRef | ||
} | ||
}); | ||
} | ||
} | ||
|
||
return { | ||
check | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
test/camunda-cloud/escalation-boundary-event-attached-to-ref.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
const RuleTester = require('bpmnlint/lib/testers/rule-tester'); | ||
|
||
const rule = require('../../rules/camunda-cloud/escalation-boundary-event-attached-to-ref'); | ||
|
||
const { | ||
createDefinitions, | ||
createModdle, | ||
createProcess | ||
} = require('../helper'); | ||
|
||
const { ERROR_TYPES } = require('../../rules/utils/element'); | ||
|
||
const valid = [ | ||
{ | ||
name: 'escalation boundary event (attached to call activity)', | ||
moddleElement: createModdle(createProcess(` | ||
<bpmn:callActivity id="CallActivity_1" /> | ||
<bpmn:boundaryEvent id="BoundaryEvent_1" attachedToRef="CallActivity_1"> | ||
<bpmn:escalationEventDefinition id="EscalationEventDefinition_1" /> | ||
</bpmn:boundaryEvent> | ||
`)) | ||
}, | ||
{ | ||
name: 'escalation boundary event (attached to sub process)', | ||
moddleElement: createModdle(createProcess(` | ||
<bpmn:subProcess id="SubProcess_1" /> | ||
<bpmn:boundaryEvent id="BoundaryEvent_1" attachedToRef="SubProcess_1"> | ||
<bpmn:escalationEventDefinition id="EscalationEventDefinition_1" /> | ||
</bpmn:boundaryEvent> | ||
`)) | ||
}, | ||
{ | ||
name: 'task', | ||
moddleElement: createModdle(createProcess('<bpmn:task id="Task_1" />')) | ||
}, | ||
{ | ||
name: 'escalation boundary event (attached to task) (non-executable process)', | ||
config: { version: '8.2' }, | ||
moddleElement: createModdle(createDefinitions(` | ||
<bpmn:process id="Process_1"> | ||
<bpmn:task id="Task_1" /> | ||
<bpmn:boundaryEvent id="BoundaryEvent_1" attachedToRef="Task_1"> | ||
<bpmn:escalationEventDefinition id="EscalationEventDefinition_1" /> | ||
</bpmn:boundaryEvent> | ||
</bpmn:process> | ||
`)) | ||
} | ||
]; | ||
|
||
const invalid = [ | ||
{ | ||
name: 'escalation boundary event (attached to task)', | ||
moddleElement: createModdle(createProcess(` | ||
<bpmn:task id="Task_1" /> | ||
<bpmn:boundaryEvent id="BoundaryEvent_1" attachedToRef="Task_1"> | ||
<bpmn:escalationEventDefinition id="EscalationEventDefinition_1" /> | ||
</bpmn:boundaryEvent> | ||
`)), | ||
report: { | ||
id: 'BoundaryEvent_1', | ||
message: 'Element of type <bpmn:BoundaryEvent> with event definition of type <bpmn:EscalationEventDefinition> is not allowed to be attached to element of type <bpmn:Task>', | ||
path: null, | ||
data: { | ||
type: ERROR_TYPES.ATTACHED_TO_REF_ELEMENT_TYPE_NOT_ALLOWED, | ||
node: 'BoundaryEvent_1', | ||
parentNode: null, | ||
attachedToRef: 'Task_1' | ||
} | ||
} | ||
} | ||
]; | ||
|
||
RuleTester.verify('escalation-boundary-event-attached-to-ref', rule, { | ||
valid, | ||
invalid | ||
}); |
19 changes: 19 additions & 0 deletions
19
test/camunda-cloud/integration/escalation-boundary-event-attached-to-ref-errors.bpmn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?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:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0n9flo1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.14.0-dev" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.2.0"> | ||
<bpmn:process id="Process_1" isExecutable="true"> | ||
<bpmn:task id="Task_1" /> | ||
<bpmn:boundaryEvent id="EscalationBoundaryEvent_1" attachedToRef="Task_1"> | ||
<bpmn:escalationEventDefinition id="EscalationEventDefinition_1n0kjrs" /> | ||
</bpmn:boundaryEvent> | ||
</bpmn:process> | ||
<bpmndi:BPMNDiagram id="BPMNDiagram_1"> | ||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1"> | ||
<bpmndi:BPMNShape id="Activity_03iss7o_di" bpmnElement="Task_1"> | ||
<dc:Bounds x="160" y="80" width="100" height="80" /> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNShape id="Event_1i5x106_di" bpmnElement="EscalationBoundaryEvent_1"> | ||
<dc:Bounds x="242" y="142" width="36" height="36" /> | ||
</bpmndi:BPMNShape> | ||
</bpmndi:BPMNPlane> | ||
</bpmndi:BPMNDiagram> | ||
</bpmn:definitions> |
23 changes: 23 additions & 0 deletions
23
test/camunda-cloud/integration/escalation-boundary-event-attached-to-ref.bpmn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?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_0n9flo1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.14.0-dev" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.2.0"> | ||
<bpmn:process id="Process_1" isExecutable="true"> | ||
<bpmn:boundaryEvent id="EscalationBoundaryEvent_1" attachedToRef="CallActivity_1"> | ||
<bpmn:escalationEventDefinition id="EscalationEventDefinition_1n0kjrs" /> | ||
</bpmn:boundaryEvent> | ||
<bpmn:callActivity id="CallActivity_1"> | ||
<bpmn:extensionElements> | ||
<zeebe:calledElement processId="foo" propagateAllChildVariables="false" /> | ||
</bpmn:extensionElements> | ||
</bpmn:callActivity> | ||
</bpmn:process> | ||
<bpmndi:BPMNDiagram id="BPMNDiagram_1"> | ||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1"> | ||
<bpmndi:BPMNShape id="Activity_04f9rp4_di" bpmnElement="CallActivity_1"> | ||
<dc:Bounds x="160" y="80" width="100" height="80" /> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNShape id="Event_1i5x106_di" bpmnElement="EscalationBoundaryEvent_1"> | ||
<dc:Bounds x="242" y="142" width="36" height="36" /> | ||
</bpmndi:BPMNShape> | ||
</bpmndi:BPMNPlane> | ||
</bpmndi:BPMNDiagram> | ||
</bpmn:definitions> |
69 changes: 69 additions & 0 deletions
69
test/camunda-cloud/integration/escalation-boundary-event-attached-to-ref.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const { expect } = require('chai'); | ||
|
||
const Linter = require('bpmnlint/lib/linter'); | ||
|
||
const NodeResolver = require('bpmnlint/lib/resolver/node-resolver'); | ||
|
||
const { readModdle } = require('../../helper'); | ||
|
||
const versions = [ | ||
'8.2', | ||
'8.3' | ||
]; | ||
|
||
describe('integration - escalation-boundary-event-attached-to-ref', function() { | ||
|
||
versions.forEach(function(version) { | ||
|
||
let linter; | ||
|
||
beforeEach(function() { | ||
linter = new Linter({ | ||
config: { | ||
extends: `plugin:camunda-compat/camunda-cloud-${ version.replace('.', '-') }` | ||
}, | ||
resolver: new NodeResolver() | ||
}); | ||
}); | ||
|
||
|
||
describe(`Camunda Cloud ${ version }`, function() { | ||
|
||
describe('no errors', function() { | ||
|
||
it('should not have errors', async function() { | ||
|
||
// given | ||
const { root } = await readModdle('test/camunda-cloud/integration/escalation-boundary-event-attached-to-ref.bpmn'); | ||
|
||
// when | ||
const reports = await linter.lint(root); | ||
|
||
// then | ||
expect(reports[ 'camunda-compat/escalation-boundary-event-attached-to-ref' ]).not.to.exist; | ||
}); | ||
|
||
}); | ||
|
||
|
||
describe('errors', function() { | ||
|
||
it('should have errors', async function() { | ||
|
||
// given | ||
const { root } = await readModdle('test/camunda-cloud/integration/escalation-boundary-event-attached-to-ref-errors.bpmn'); | ||
|
||
// when | ||
const reports = await linter.lint(root); | ||
|
||
// then | ||
expect(reports[ 'camunda-compat/escalation-boundary-event-attached-to-ref' ]).to.exist; | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters