2014-05-21 14:23:52 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-10-30 11:06:43 +00:00
|
|
|
var TestHelper = require('../../TestHelper');
|
2014-06-18 09:45:30 +00:00
|
|
|
|
|
|
|
|
2014-06-11 12:41:55 +00:00
|
|
|
var Diagram = require('diagram-js/lib/Diagram'),
|
2014-08-04 14:32:11 +00:00
|
|
|
BpmnModdle = require('bpmn-moddle'),
|
2014-08-01 05:16:59 +00:00
|
|
|
Importer = require('../../../lib/import/Importer'),
|
|
|
|
Viewer = require('../../../lib/Viewer');
|
2014-04-03 09:47:26 +00:00
|
|
|
|
2014-05-21 14:23:52 +00:00
|
|
|
|
2014-06-18 09:45:30 +00:00
|
|
|
describe('import - importer', function() {
|
2014-04-03 09:47:26 +00:00
|
|
|
|
2014-08-04 14:32:11 +00:00
|
|
|
var moddle = new BpmnModdle();
|
2014-04-03 09:47:26 +00:00
|
|
|
|
2014-06-18 09:45:30 +00:00
|
|
|
var container;
|
2014-04-03 09:47:26 +00:00
|
|
|
|
|
|
|
beforeEach(function() {
|
2014-06-18 09:45:30 +00:00
|
|
|
container = jasmine.getEnv().getTestContainer();
|
2014-04-03 09:47:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function createDiagram() {
|
|
|
|
return new Diagram({
|
|
|
|
canvas: { container: container },
|
2014-06-30 14:58:23 +00:00
|
|
|
modules: Viewer.prototype._modules
|
2014-04-03 09:47:26 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-06-23 12:44:03 +00:00
|
|
|
var diagram;
|
2014-05-21 14:23:52 +00:00
|
|
|
|
2014-06-23 12:44:03 +00:00
|
|
|
beforeEach(function() {
|
|
|
|
diagram = createDiagram();
|
|
|
|
});
|
2014-04-03 09:47:26 +00:00
|
|
|
|
|
|
|
|
2014-06-23 12:44:03 +00:00
|
|
|
function runImport(diagram, xml, done) {
|
2014-08-04 14:32:11 +00:00
|
|
|
moddle.fromXML(xml, function(err, definitions) {
|
2014-04-03 09:47:26 +00:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2014-06-23 12:44:03 +00:00
|
|
|
Importer.importBpmnDiagram(diagram, definitions, done);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
describe('event emitter', function() {
|
|
|
|
|
2014-07-16 14:15:23 +00:00
|
|
|
it('should fire <shape.added> during import', function(done) {
|
2014-06-23 12:44:03 +00:00
|
|
|
|
|
|
|
// given
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../../fixtures/bpmn/simple.bpmn');
|
2014-06-23 12:44:03 +00:00
|
|
|
|
2014-07-01 09:33:28 +00:00
|
|
|
var eventCount = 0;
|
2014-06-23 12:44:03 +00:00
|
|
|
|
|
|
|
// log events
|
2014-07-16 14:15:23 +00:00
|
|
|
diagram.get('eventBus').on('bpmnElement.added', function(e) {
|
2014-07-01 09:33:28 +00:00
|
|
|
eventCount++;
|
2014-06-23 12:44:03 +00:00
|
|
|
});
|
|
|
|
|
2014-04-03 09:47:26 +00:00
|
|
|
// when
|
2014-06-23 12:44:03 +00:00
|
|
|
runImport(diagram, xml, function(err, warnings) {
|
2014-04-03 09:47:26 +00:00
|
|
|
|
|
|
|
// then
|
2014-11-28 10:38:06 +00:00
|
|
|
expect(eventCount).toEqual(9);
|
2014-04-03 09:47:26 +00:00
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
2014-06-23 12:44:03 +00:00
|
|
|
|
2014-04-03 09:47:26 +00:00
|
|
|
});
|
|
|
|
|
2014-06-18 11:05:32 +00:00
|
|
|
|
2014-06-23 12:44:03 +00:00
|
|
|
describe('basics', function() {
|
2014-06-18 11:05:32 +00:00
|
|
|
|
2014-11-28 10:38:06 +00:00
|
|
|
it('should import simple process', function(done) {
|
2014-06-18 11:05:32 +00:00
|
|
|
|
2014-06-23 12:44:03 +00:00
|
|
|
// given
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../../fixtures/bpmn/simple.bpmn');
|
2014-06-18 11:05:32 +00:00
|
|
|
|
2014-06-23 12:44:03 +00:00
|
|
|
var events = [];
|
2014-06-18 11:05:32 +00:00
|
|
|
|
2014-06-23 12:44:03 +00:00
|
|
|
// log events
|
2014-07-16 14:15:23 +00:00
|
|
|
diagram.get('eventBus').on('bpmnElement.added', function(e) {
|
2014-07-01 09:33:28 +00:00
|
|
|
events.push({
|
|
|
|
type: 'add',
|
2014-07-16 14:15:23 +00:00
|
|
|
semantic: e.element.businessObject.id,
|
|
|
|
di: e.element.businessObject.di.id,
|
|
|
|
diagramElement: e.element && e.element.id
|
2014-07-01 09:33:28 +00:00
|
|
|
});
|
2014-06-23 12:44:03 +00:00
|
|
|
});
|
2014-06-18 11:05:32 +00:00
|
|
|
|
|
|
|
// when
|
2014-06-23 12:44:03 +00:00
|
|
|
runImport(diagram, xml, function(err, warnings) {
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(events).toEqual([
|
2014-11-28 10:38:06 +00:00
|
|
|
{ type: 'add', semantic: 'Process_1', di: 'BPMNPlane_1', diagramElement: 'Process_1' },
|
|
|
|
{ type: 'add', semantic: 'SubProcess_1', di: '_BPMNShape_SubProcess_2', diagramElement: 'SubProcess_1' },
|
|
|
|
{ type: 'add', semantic: 'StartEvent_1', di: '_BPMNShape_StartEvent_2', diagramElement: 'StartEvent_1' },
|
|
|
|
{ type: 'add', semantic: 'Task_1', di: '_BPMNShape_Task_2', diagramElement: 'Task_1' },
|
|
|
|
{ type: 'add', semantic: 'EndEvent_1', di: '_BPMNShape_EndEvent_2', diagramElement: 'EndEvent_1' },
|
|
|
|
{ type: 'add', semantic: 'StartEvent_2', di: '_BPMNShape_StartEvent_11', diagramElement: 'StartEvent_2' },
|
|
|
|
{ type: 'add', semantic: 'SequenceFlow_1', di: 'BPMNEdge_SequenceFlow_1', diagramElement: 'SequenceFlow_1' },
|
|
|
|
{ type: 'add', semantic: 'SequenceFlow_2', di: 'BPMNEdge_SequenceFlow_2', diagramElement: 'SequenceFlow_2' },
|
|
|
|
{ type: 'add', semantic: 'SequenceFlow_3', di: 'BPMNEdge_SequenceFlow_3', diagramElement: 'SequenceFlow_3' }
|
2014-06-23 12:44:03 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should import collaboration', function(done) {
|
|
|
|
|
|
|
|
// given
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../../fixtures/bpmn/collaboration.bpmn');
|
2014-06-23 12:44:03 +00:00
|
|
|
|
|
|
|
var events = [];
|
|
|
|
|
|
|
|
// log events
|
2014-07-16 14:15:23 +00:00
|
|
|
diagram.get('eventBus').on('bpmnElement.added', function(e) {
|
2014-07-01 09:33:28 +00:00
|
|
|
events.push({
|
|
|
|
type: 'add',
|
2014-07-16 14:15:23 +00:00
|
|
|
semantic: e.element.businessObject.id,
|
|
|
|
di: e.element.businessObject.di.id,
|
|
|
|
diagramElement: e.element && e.element.id
|
2014-07-01 09:33:28 +00:00
|
|
|
});
|
2014-06-23 12:44:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
runImport(diagram, xml, function(err, warnings) {
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(events).toEqual([
|
2014-07-16 14:15:23 +00:00
|
|
|
{ type: 'add', semantic: '_Collaboration_2', di: 'BPMNPlane_1', diagramElement: '_Collaboration_2' },
|
2014-06-23 12:44:03 +00:00
|
|
|
{ type: 'add', semantic: 'Participant_2', di: '_BPMNShape_Participant_2', diagramElement: 'Participant_2' },
|
|
|
|
{ type: 'add', semantic: 'Lane_1', di: '_BPMNShape_Lane_2', diagramElement: 'Lane_1' },
|
|
|
|
{ type: 'add', semantic: 'Lane_2', di: '_BPMNShape_Lane_3', diagramElement: 'Lane_2' },
|
|
|
|
{ type: 'add', semantic: 'Lane_3', di: '_BPMNShape_Lane_4', diagramElement: 'Lane_3' },
|
|
|
|
{ type: 'add', semantic: 'Task_1', di: '_BPMNShape_Task_3', diagramElement: 'Task_1' },
|
|
|
|
{ type: 'add', semantic: 'Participant_1', di: '_BPMNShape_Participant_3', diagramElement: 'Participant_1' },
|
|
|
|
{ type: 'add', semantic: 'StartEvent_1', di: '_BPMNShape_StartEvent_3', diagramElement: 'StartEvent_1' }
|
|
|
|
]);
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-07-16 14:15:23 +00:00
|
|
|
describe('model wiring', function() {
|
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../../fixtures/bpmn/simple.bpmn');
|
2014-07-16 14:15:23 +00:00
|
|
|
|
|
|
|
var elements;
|
|
|
|
|
|
|
|
beforeEach(function(done) {
|
|
|
|
elements = [];
|
|
|
|
|
|
|
|
// log events
|
|
|
|
diagram.get('eventBus').on('bpmnElement.added', function(e) {
|
|
|
|
elements.push(e.element);
|
|
|
|
});
|
|
|
|
|
|
|
|
runImport(diagram, xml, done);
|
|
|
|
});
|
2014-06-23 12:44:03 +00:00
|
|
|
|
|
|
|
|
2014-11-26 10:49:14 +00:00
|
|
|
it('should wire root element', function() {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var canvas = diagram.get('canvas');
|
|
|
|
|
|
|
|
// when
|
|
|
|
var root = elements[0];
|
|
|
|
var anyChild = elements[1];
|
|
|
|
|
|
|
|
// assume
|
|
|
|
expect(root.businessObject.$instanceOf('bpmn:Process')).toBe(true);
|
|
|
|
expect(anyChild.parent).toBe(root);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(canvas.getRootElement()).toBe(root);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-07-16 14:15:23 +00:00
|
|
|
it('should wire parent child relationship', function() {
|
2014-06-23 12:44:03 +00:00
|
|
|
|
|
|
|
// when
|
2014-07-16 14:15:23 +00:00
|
|
|
var subProcessShape = elements[1];
|
|
|
|
var startEventShape = elements[2];
|
2014-06-23 12:44:03 +00:00
|
|
|
|
2014-07-16 14:15:23 +00:00
|
|
|
// then
|
|
|
|
expect(startEventShape.type).toBe('bpmn:StartEvent');
|
|
|
|
expect(startEventShape.parent).toBe(subProcessShape);
|
2014-08-28 12:27:13 +00:00
|
|
|
|
|
|
|
expect(subProcessShape.children.length).toBe(5);
|
2014-07-16 14:15:23 +00:00
|
|
|
});
|
2014-06-18 11:05:32 +00:00
|
|
|
|
2014-07-16 14:15:23 +00:00
|
|
|
|
|
|
|
it('should wire label relationship', function() {
|
|
|
|
|
|
|
|
// when
|
|
|
|
var startEventShape = elements[2];
|
|
|
|
var label = startEventShape.label;
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(label).toBeDefined();
|
|
|
|
expect(label.id).toBe(startEventShape.id + '_label');
|
|
|
|
|
|
|
|
expect(label.labelTarget).toBe(startEventShape);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should wire businessObject', function() {
|
|
|
|
|
|
|
|
// when
|
|
|
|
var subProcessShape = elements[1];
|
|
|
|
var startEventShape = elements[2];
|
|
|
|
|
|
|
|
var subProcess = subProcessShape.businessObject,
|
|
|
|
startEvent = startEventShape.businessObject;
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(subProcess).toBeDefined();
|
|
|
|
expect(subProcess.$instanceOf('bpmn:SubProcess')).toBe(true);
|
|
|
|
|
|
|
|
expect(startEvent).toBeDefined();
|
|
|
|
expect(startEvent.$instanceOf('bpmn:StartEvent')).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should wire di', function() {
|
|
|
|
|
|
|
|
// when
|
|
|
|
var subProcessShape = elements[1];
|
|
|
|
var startEventShape = elements[2];
|
|
|
|
|
|
|
|
var subProcess = subProcessShape.businessObject,
|
|
|
|
startEvent = startEventShape.businessObject;
|
|
|
|
|
|
|
|
var subProcessDi = subProcess.di,
|
|
|
|
startEventDi = startEvent.di;
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(subProcessDi).toBeDefined();
|
|
|
|
expect(subProcessDi.bpmnElement).toBe(subProcess);
|
|
|
|
|
|
|
|
expect(startEventDi).toBeDefined();
|
|
|
|
expect(startEventDi.bpmnElement).toBe(startEvent);
|
2014-06-18 11:05:32 +00:00
|
|
|
});
|
2014-06-23 12:44:03 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('forgiveness', function() {
|
|
|
|
|
|
|
|
it('should import invalid flowElement', function(done) {
|
|
|
|
|
|
|
|
// given
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../../fixtures/bpmn/error/invalid-flow-element.bpmn');
|
2014-06-23 12:44:03 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
runImport(diagram, xml, function(err, warnings) {
|
|
|
|
|
|
|
|
expect(warnings.length).toBe(1);
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-11-26 19:54:52 +00:00
|
|
|
|
|
|
|
it('should import multiple dis', function(done) {
|
|
|
|
|
|
|
|
// given
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../../fixtures/bpmn/error/multiple-dis.bpmn');
|
2014-11-26 19:54:52 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
runImport(diagram, xml, function(err, warnings) {
|
|
|
|
|
2015-02-17 09:55:28 +00:00
|
|
|
var expectedMessage =
|
|
|
|
'multiple DI elements defined for <bpmn:InclusiveGateway id="InclusiveGateway_1" />';
|
|
|
|
|
2014-11-26 19:54:52 +00:00
|
|
|
expect(warnings.length).toBe(1);
|
2015-02-17 09:55:28 +00:00
|
|
|
expect(warnings[0].message).toBe(expectedMessage);
|
2014-11-26 19:54:52 +00:00
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-08-18 10:38:41 +00:00
|
|
|
it('should extend missing attribute with default value', function(done) {
|
|
|
|
|
|
|
|
// given
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../../fixtures//bpmn/draw/gateway-type-default.bpmn');
|
2014-08-18 10:38:41 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
runImport(diagram, xml, function(err, warnings) {
|
|
|
|
|
|
|
|
var elementRegistry = diagram.get('elementRegistry');
|
|
|
|
|
2014-11-17 16:36:22 +00:00
|
|
|
var element = elementRegistry.get('GATEWAY_1');
|
2014-08-18 10:38:41 +00:00
|
|
|
|
|
|
|
expect(element.businessObject.eventGatewayType).toEqual('Exclusive');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
2014-10-31 14:05:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('integration', function() {
|
|
|
|
|
|
|
|
it('should import complex', function(done) {
|
|
|
|
|
|
|
|
// given
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../../fixtures/bpmn/complex.bpmn');
|
2014-10-31 14:05:16 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
runImport(diagram, xml, function(err, warnings) {
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(warnings.length).toBe(0);
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
2015-01-02 11:56:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
it('should import dangling process message flows', function(done) {
|
|
|
|
|
|
|
|
// given
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../../fixtures/bpmn/import/dangling-process-message-flow.bpmn');
|
2015-01-02 11:56:32 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
runImport(diagram, xml, function(err, warnings) {
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(warnings.length).toBe(0);
|
|
|
|
|
|
|
|
expect(diagram.get('elementRegistry').get('_b467921a-ef7b-44c5-bf78-fd624c400d17')).toBeDefined();
|
|
|
|
expect(diagram.get('elementRegistry').get('_c311cc87-677e-47a4-bdb1-8744c4ec3147')).toBeDefined();
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
2014-06-18 11:05:32 +00:00
|
|
|
});
|
|
|
|
|
2015-02-17 09:55:28 +00:00
|
|
|
|
2014-12-22 10:44:44 +00:00
|
|
|
describe('position', function() {
|
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml1 = require('../../fixtures/bpmn/import/position/position-testcase.bpmn');
|
2014-12-22 10:44:44 +00:00
|
|
|
|
|
|
|
it('should round shape\'s x and y coordinates', function(done) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var events = {};
|
|
|
|
|
|
|
|
// log events
|
|
|
|
diagram.get('eventBus').on('bpmnElement.added', function(e) {
|
|
|
|
|
|
|
|
events[e.element.id] = e.element;
|
|
|
|
});
|
|
|
|
|
|
|
|
runImport(diagram, xml1, function(err, warnings) {
|
|
|
|
|
|
|
|
//round up
|
|
|
|
expect(events.ID_End.x).toBe(Math.round(340.6));
|
|
|
|
expect(events.ID_End.y).toBe(Math.round(136.6));
|
|
|
|
|
|
|
|
//round down
|
|
|
|
expect(events.ID_Start.x).toBe(Math.round(120.4));
|
|
|
|
expect(events.ID_Start.y).toBe(Math.round(135.4));
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-02-17 09:55:28 +00:00
|
|
|
|
2014-12-22 10:44:44 +00:00
|
|
|
it('should round shape\'s height and width', function(done) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var events = {};
|
|
|
|
|
|
|
|
// log events
|
|
|
|
diagram.get('eventBus').on('bpmnElement.added', function(e) {
|
|
|
|
|
|
|
|
events[e.element.id] = e.element;
|
|
|
|
});
|
|
|
|
|
|
|
|
runImport(diagram, xml1, function(err, warnings) {
|
|
|
|
|
|
|
|
//round down
|
|
|
|
expect(events.ID_Start.height).toBe(Math.round(30.4));
|
|
|
|
expect(events.ID_Start.width).toBe(Math.round(30.4));
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2015-02-17 09:55:28 +00:00
|
|
|
|
2014-12-22 10:44:44 +00:00
|
|
|
});
|