From 225cbb914c16620fcb0ad0c0b9f630cdad743be4 Mon Sep 17 00:00:00 2001 From: jdotzki Date: Wed, 4 Mar 2015 10:20:37 +0100 Subject: [PATCH] fix(rules): fix modeling rules for event based gateways Allow condition and signal catching events after event based gateways. close #213 --- lib/features/modeling/rules/ModelingRules.js | 4 +- .../event-based-gateway-outgoing-edge.bpmn | 72 +++++++++ test/spec/features/rules/ModelingRulesSpec.js | 151 +++++++++++++++++- 3 files changed, 219 insertions(+), 8 deletions(-) create mode 100644 test/fixtures/bpmn/features/rules/event-based-gateway-outgoing-edge.bpmn diff --git a/lib/features/modeling/rules/ModelingRules.js b/lib/features/modeling/rules/ModelingRules.js index dc403609..f86c9734 100644 --- a/lib/features/modeling/rules/ModelingRules.js +++ b/lib/features/modeling/rules/ModelingRules.js @@ -49,8 +49,8 @@ ModelingRules.prototype.init = function() { targetBo.eventDefinitions && ( targetBo.eventDefinitions[0].$type === 'bpmn:MessageEventDefinition' || targetBo.eventDefinitions[0].$type === 'bpmn:TimerEventDefinition' || - targetBo.eventDefinitions[0].$type === 'bpmn:ConditionEventDefinition' || - targetBo.eventDefinitions[0].$type === 'bpmn:SignalConditionEventDefinition')) { + targetBo.eventDefinitions[0].$type === 'bpmn:ConditionalEventDefinition' || + targetBo.eventDefinitions[0].$type === 'bpmn:SignalEventDefinition')) { eventBasedGatewayCheck = false; } diff --git a/test/fixtures/bpmn/features/rules/event-based-gateway-outgoing-edge.bpmn b/test/fixtures/bpmn/features/rules/event-based-gateway-outgoing-edge.bpmn new file mode 100644 index 00000000..55a4d7dd --- /dev/null +++ b/test/fixtures/bpmn/features/rules/event-based-gateway-outgoing-edge.bpmn @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/spec/features/rules/ModelingRulesSpec.js b/test/spec/features/rules/ModelingRulesSpec.js index 4917db8f..88ccf34f 100644 --- a/test/spec/features/rules/ModelingRulesSpec.js +++ b/test/spec/features/rules/ModelingRulesSpec.js @@ -19,23 +19,23 @@ describe('features/ModelingRules', function() { beforeEach(Matchers.addDeepEquals); - var diagramXML = fs.readFileSync('test/fixtures/bpmn/sequence-flows.bpmn', 'utf8'); + var sequenceXML = fs.readFileSync('test/fixtures/bpmn/sequence-flows.bpmn', 'utf8'); + var eventGatewaysEdgeXML = + fs.readFileSync('test/fixtures/bpmn/features/rules/event-based-gateway-outgoing-edge.bpmn', 'utf8'); var testModules = [ coreModule, modelingModule, rulesModule ]; - beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); - // See workaround https://github.com/bpmn-io/bpmn-js/issues/176 // The wanted behavior until https://github.com/bpmn-io/bpmn-js/issues/176 is fixed describe('connect with source == target', function() { + beforeEach(bootstrapModeler(sequenceXML, { modules: testModules })); + it('should not allow connection', inject(function(elementRegistry, modeling, rules) { // given - var taskShape = elementRegistry.get('Task_1'), - task = taskShape.businessObject; - + var taskShape = elementRegistry.get('Task_1'); // when var allowed = rules.allowed('connection.create', { @@ -49,4 +49,143 @@ describe('features/ModelingRules', function() { expect(allowed).toBe(false); })); }); + + describe('eventbased gateway', function() { + + beforeEach(bootstrapModeler(eventGatewaysEdgeXML, { modules: testModules })); + + it('should allow catching message intermediate event on outgoing edges', inject(function(elementRegistry, modeling, rules) { + + // given + var eventGateway = elementRegistry.get('EventBasedGateway_1'), + messageEvent = elementRegistry.get('IntermediateCatchEvent_0'); + + + // when + var allowed = rules.allowed('connection.create', { + connection: null, + source: eventGateway, + target: messageEvent + }); + + // then + // connection should not be allowed + expect(allowed).toBe(true); + })); + + it('should allow catching timer intermediate event on outgoing edges', inject(function(elementRegistry, modeling, rules) { + + // given + var eventGateway = elementRegistry.get('EventBasedGateway_1'), + timerEvent = elementRegistry.get('IntermediateCatchEvent_1'); + + + // when + var allowed = rules.allowed('connection.create', { + connection: null, + source: eventGateway, + target: timerEvent + }); + + // then + // connection should not be allowed + expect(allowed).toBe(true); + })); + + it('should allow catching condition intermediate event on outgoing edges', inject(function(elementRegistry, modeling, rules) { + + // given + var eventGateway = elementRegistry.get('EventBasedGateway_1'), + conditionEvent = elementRegistry.get('IntermediateCatchEvent_2'); + + + // when + var allowed = rules.allowed('connection.create', { + connection: null, + source: eventGateway, + target: conditionEvent + }); + + // then + // connection should not be allowed + expect(allowed).toBe(true); + })); + + it('should allow catching signal intermediate event on outgoing edges', inject(function(elementRegistry, modeling, rules) { + + // given + var eventGateway = elementRegistry.get('EventBasedGateway_1'), + signalEvent = elementRegistry.get('IntermediateCatchEvent_3'); + + + // when + var allowed = rules.allowed('connection.create', { + connection: null, + source: eventGateway, + target: signalEvent + }); + + // then + // connection should not be allowed + expect(allowed).toBe(true); + })); + + it('should allow receive task on outgoing edges', inject(function(elementRegistry, modeling, rules) { + + // given + var eventGateway = elementRegistry.get('EventBasedGateway_1'), + receiveTask = elementRegistry.get('ReceiveTask_1'); + + + // when + var allowed = rules.allowed('connection.create', { + connection: null, + source: eventGateway, + target: receiveTask + }); + + // then + // connection should not be allowed + expect(allowed).toBe(true); + })); + + it('should not allow throw event on outgoing edges', inject(function(elementRegistry, modeling, rules) { + + // given + var eventGateway = elementRegistry.get('EventBasedGateway_1'), + throwEvent = elementRegistry.get('IntermediateThrowEvent_0'); + + + // when + var allowed = rules.allowed('connection.create', { + connection: null, + source: eventGateway, + target: throwEvent + }); + + // then + // connection should not be allowed + expect(allowed).toBe(false); + })); + + it('should not allow task on outgoing edges', inject(function(elementRegistry, modeling, rules) { + + // given + var eventGateway = elementRegistry.get('EventBasedGateway_1'), + task = elementRegistry.get('Task_1'); + + + // when + var allowed = rules.allowed('connection.create', { + connection: null, + source: eventGateway, + target: task + }); + + // then + // connection should not be allowed + expect(allowed).toBe(false); + })); + + }); });