bpmn-js/test/spec/node/xml/RoundtripSpec.js

132 lines
2.8 KiB
JavaScript
Raw Normal View History

var SchemaValidator = require('xsd-schema-validator');
2014-03-11 14:54:36 +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';
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) {
BpmnModel.toXML(element, opts, callback);
2014-03-11 14:54:36 +00:00
}
function validate(err, xml, done) {
if (err) {
done(err);
} else {
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-11 14:54:36 +00:00
if (err) {
done(err);
} else {
expect(result.valid).toBe(true);
done();
}
});
}
}
beforeEach(Matchers.add);
2014-03-11 14:54:36 +00:00
2014-03-11 14:54:36 +00:00
describe('Roundtrip', function() {
it('should serialize home-made bpmn model', function(done) {
// given
2014-03-11 14:54:36 +00:00
var model = bpmnModel;
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) {
// then
2014-03-11 14:54:36 +00:00
validate(err, xml, done);
});
});
it('should write complex process', function(done) {
2014-03-11 14:54:36 +00:00
// given
readBpmn('complex-no-extensions.bpmn', function(err, result) {
2014-03-11 14:54:36 +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);
});
});
});
it('should write complex process / extensionElements', function(done) {
2014-03-11 14:54:36 +00:00
// given
readBpmn('complex.bpmn', function(err, result) {
2014-03-11 14:54:36 +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-11 14:54:36 +00:00
it('should write simple process', function(done) {
// given
readBpmn('simple.bpmn', function(err, result) {
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-11 14:54:36 +00:00
});
});