2014-03-13 10:21:03 +00:00
|
|
|
var SchemaValidator = require('xsd-schema-validator');
|
2014-03-11 14:54:36 +00:00
|
|
|
|
2014-03-13 10:21:03 +00:00
|
|
|
var BpmnModel = require('../../../../lib/Model'),
|
|
|
|
Helper = require('../Helper'),
|
|
|
|
Matchers = require('../../Matchers');
|
2014-03-11 14:54:36 +00:00
|
|
|
|
|
|
|
var BPMN_XSD = 'resources/bpmn/xsd/BPMN20.xsd';
|
|
|
|
|
|
|
|
|
2014-03-13 10:21:03 +00:00
|
|
|
describe('Model - roundtrip', function() {
|
2014-03-11 14:54:36 +00:00
|
|
|
|
|
|
|
var bpmnModel = BpmnModel.instance();
|
|
|
|
|
|
|
|
function readBpmnDiagram(file) {
|
|
|
|
return Helper.readFile('test/fixtures/bpmn/' + file);
|
|
|
|
}
|
|
|
|
|
|
|
|
function readBpmn(file, callback) {
|
|
|
|
BpmnModel.fromXML(readBpmnDiagram(file), 'bpmn:Definitions', callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
function writeBpmn(element, opts, callback) {
|
2014-03-13 10:21:03 +00:00
|
|
|
BpmnModel.toXML(element, opts, callback);
|
2014-03-11 14:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function validate(err, xml, done) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
done(err);
|
|
|
|
} else {
|
2014-03-13 10:21:03 +00:00
|
|
|
|
|
|
|
if (!xml) {
|
|
|
|
done(new Error('XML is not defined'));
|
|
|
|
}
|
|
|
|
|
2014-03-11 14:54:36 +00:00
|
|
|
SchemaValidator.validateXML(xml, BPMN_XSD, function(err, result) {
|
2014-03-13 10:21:03 +00:00
|
|
|
|
2014-03-11 14:54:36 +00:00
|
|
|
if (err) {
|
|
|
|
done(err);
|
|
|
|
} else {
|
|
|
|
expect(result.valid).toBe(true);
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-27 15:45:02 +00:00
|
|
|
|
2014-03-13 10:21:03 +00:00
|
|
|
beforeEach(Matchers.add);
|
2014-03-11 14:54:36 +00:00
|
|
|
|
2014-03-27 15:45:02 +00:00
|
|
|
|
2014-03-11 14:54:36 +00:00
|
|
|
describe('Roundtrip', function() {
|
|
|
|
|
|
|
|
it('should serialize home-made bpmn model', function(done) {
|
|
|
|
|
2014-03-13 10:21:03 +00:00
|
|
|
// given
|
2014-03-11 14:54:36 +00:00
|
|
|
var model = bpmnModel;
|
|
|
|
|
2014-03-13 10:21:03 +00:00
|
|
|
var definitions = model.create('bpmn:Definitions', { targetNamespace: 'http://foo' });
|
2014-03-11 14:54:36 +00:00
|
|
|
|
|
|
|
var ServiceTask = model.getType('bpmn:ServiceTask');
|
|
|
|
|
|
|
|
var process = model.create('bpmn:Process');
|
|
|
|
var serviceTask = model.create('bpmn:ServiceTask', { name: 'MyService Task'});
|
|
|
|
|
|
|
|
process.get('flowElements').push(serviceTask);
|
|
|
|
definitions.get('rootElements').push(process);
|
|
|
|
|
|
|
|
// when
|
|
|
|
writeBpmn(definitions, { format: true }, function(err, xml) {
|
2014-03-13 10:21:03 +00:00
|
|
|
|
|
|
|
// then
|
2014-03-11 14:54:36 +00:00
|
|
|
validate(err, xml, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-03-27 15:45:02 +00:00
|
|
|
|
|
|
|
it('should write complex process', function(done) {
|
2014-03-11 14:54:36 +00:00
|
|
|
|
|
|
|
// given
|
2014-03-27 15:45:02 +00:00
|
|
|
readBpmn('complex-no-extensions.bpmn', function(err, result) {
|
2014-03-11 14:54:36 +00:00
|
|
|
|
2014-03-13 10:21:03 +00:00
|
|
|
if (err) {
|
|
|
|
done(err);
|
|
|
|
return;
|
|
|
|
}
|
2014-03-27 15:45:02 +00:00
|
|
|
|
2014-03-11 14:54:36 +00:00
|
|
|
// when
|
|
|
|
writeBpmn(result, { format: true }, function(err, xml) {
|
|
|
|
validate(err, xml, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-03-27 15:45:02 +00:00
|
|
|
|
|
|
|
it('should write complex process / extensionElements', function(done) {
|
2014-03-11 14:54:36 +00:00
|
|
|
|
|
|
|
// given
|
2014-03-27 15:45:02 +00:00
|
|
|
readBpmn('complex.bpmn', function(err, result) {
|
2014-03-11 14:54:36 +00:00
|
|
|
|
2014-03-13 10:21:03 +00:00
|
|
|
if (err) {
|
|
|
|
done(err);
|
|
|
|
return;
|
|
|
|
}
|
2014-03-27 15:45:02 +00:00
|
|
|
|
2014-03-11 14:54:36 +00:00
|
|
|
// when
|
|
|
|
writeBpmn(result, { format: true }, function(err, xml) {
|
|
|
|
validate(err, xml, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-03-27 15:45:02 +00:00
|
|
|
|
2014-03-11 14:54:36 +00:00
|
|
|
it('should write simple process', function(done) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
readBpmn('simple.bpmn', function(err, result) {
|
|
|
|
|
2014-03-13 10:21:03 +00:00
|
|
|
if (err) {
|
|
|
|
done(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-11 14:54:36 +00:00
|
|
|
// when
|
|
|
|
writeBpmn(result, { format: true }, function(err, xml) {
|
|
|
|
validate(err, xml, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-03-27 15:45:02 +00:00
|
|
|
|
2014-03-11 14:54:36 +00:00
|
|
|
});
|
|
|
|
});
|