2014-05-21 14:23:52 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-06-18 09:45:30 +00:00
|
|
|
var Matchers = require('../../Matchers'),
|
|
|
|
TestHelper = require('../../TestHelper');
|
|
|
|
|
|
|
|
/* global bootstrapBpmnJS, inject */
|
|
|
|
|
|
|
|
|
2014-06-11 12:41:55 +00:00
|
|
|
var fs = require('fs');
|
2014-04-03 09:47:26 +00:00
|
|
|
|
2014-06-11 12:41:55 +00:00
|
|
|
var Diagram = require('diagram-js/lib/Diagram'),
|
|
|
|
BpmnModel = require('bpmn-moddle'),
|
|
|
|
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
|
|
|
|
|
|
|
var bpmnModel = BpmnModel.instance();
|
|
|
|
|
|
|
|
function read(xml, opts, callback) {
|
|
|
|
return BpmnModel.fromXML(xml, 'bpmn:Definitions', opts, callback);
|
|
|
|
}
|
|
|
|
|
2014-06-18 09:45:30 +00:00
|
|
|
beforeEach(Matchers.add);
|
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-11 12:41:55 +00:00
|
|
|
modules: Viewer.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-04-03 09:47:26 +00:00
|
|
|
BpmnModel.fromXML(xml, function(err, definitions) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2014-06-23 12:44:03 +00:00
|
|
|
Importer.importBpmnDiagram(diagram, definitions, done);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
describe('event emitter', function() {
|
|
|
|
|
|
|
|
it('should fire <bpmn.element.add> during import', function(done) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var xml = fs.readFileSync('test/fixtures/bpmn/simple.bpmn', 'utf8');
|
|
|
|
|
|
|
|
var events = [];
|
|
|
|
|
|
|
|
// log events
|
|
|
|
diagram.get('eventBus').on('bpmn.element.add', function(e) {
|
|
|
|
events.push({ type: 'add', semantic: e.semantic.id, di: e.di.id, diagramElement: e.diagramElement.id });
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
expect(events).toEqual([
|
|
|
|
{ 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: 'SequenceFlow_1', di: 'BPMNEdge_SequenceFlow_1', diagramElement: 'SequenceFlow_1' }
|
|
|
|
]);
|
|
|
|
|
|
|
|
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-06-23 12:44:03 +00:00
|
|
|
it('should import process', function(done) {
|
2014-06-18 11:05:32 +00:00
|
|
|
|
2014-06-23 12:44:03 +00:00
|
|
|
// given
|
|
|
|
var xml = fs.readFileSync('test/fixtures/bpmn/simple.bpmn', 'utf8');
|
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
|
|
|
|
diagram.get('eventBus').on('bpmn.element.add', function(e) {
|
|
|
|
events.push({ type: 'add', semantic: e.semantic.id, di: e.di.id, diagramElement: e.diagramElement.id });
|
|
|
|
});
|
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([
|
|
|
|
{ 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: 'SequenceFlow_1', di: 'BPMNEdge_SequenceFlow_1', diagramElement: 'SequenceFlow_1' }
|
|
|
|
]);
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should import collaboration', function(done) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var xml = fs.readFileSync('test/fixtures/bpmn/collaboration.bpmn', 'utf8');
|
|
|
|
|
|
|
|
var events = [];
|
|
|
|
|
|
|
|
// log events
|
|
|
|
diagram.get('eventBus').on('bpmn.element.add', function(e) {
|
|
|
|
events.push({ type: 'add', semantic: e.semantic.id, di: e.di.id, diagramElement: e.diagramElement.id });
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
runImport(diagram, xml, function(err, warnings) {
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(events).toEqual([
|
|
|
|
{ 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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('command stack integration', function() {
|
|
|
|
|
|
|
|
it('should clear stack after import', function(done) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var xml = fs.readFileSync('test/fixtures/bpmn/simple.bpmn', 'utf8');
|
|
|
|
|
|
|
|
var commandStack = diagram.get('commandStack');
|
|
|
|
|
|
|
|
// when
|
|
|
|
runImport(diagram, xml, function(err, warnings) {
|
|
|
|
|
|
|
|
// then
|
2014-06-18 11:05:32 +00:00
|
|
|
expect(commandStack.getStack()).toEqual([]);
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
2014-06-23 12:44:03 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('forgiveness', function() {
|
|
|
|
|
|
|
|
it('should import invalid flowElement', function(done) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var xml = fs.readFileSync('test/fixtures/bpmn/error/invalid-flow-element.bpmn', 'utf8');
|
|
|
|
|
|
|
|
var commandStack = diagram.get('commandStack');
|
|
|
|
|
|
|
|
// when
|
|
|
|
runImport(diagram, xml, function(err, warnings) {
|
|
|
|
|
|
|
|
expect(warnings.length).toBe(1);
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-06-18 11:05:32 +00:00
|
|
|
});
|
|
|
|
|
2014-04-03 09:47:26 +00:00
|
|
|
});
|