fix(importer): show better error if no BPMNPlane#bpmnElement

Closes #40
This commit is contained in:
Nico Rehwaldt 2014-05-23 16:31:28 +02:00
parent 39d66069dc
commit 4b135fd9e7
3 changed files with 24 additions and 7 deletions

View File

@ -112,6 +112,10 @@ function BpmnTraverser(handler) {
var rootElement = diagram.plane.bpmnElement; var rootElement = diagram.plane.bpmnElement;
if (!rootElement) {
throw new Error('no rootElement referenced in BPMNPlane <' + diagram.plane.id + '>');
}
if (is(rootElement, 'bpmn:Process')) { if (is(rootElement, 'bpmn:Process')) {
handleProcess(rootElement); handleProcess(rootElement);
} else } else

View File

@ -1,13 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd" id="test" targetNamespace="http://bpmn.io/schema/bpmn"> <bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd" id="_F2BQoOJhEeOt3puKo8GLGA" targetNamespace="http://activiti.org/bpmn">
<!-- Collaboration_2 removed -->
<bpmn2:process id="Process_1" isExecutable="false"> <bpmn2:process id="Process_1" isExecutable="false">
<bpmn2:startEvent id="StartEvent_1"/>
</bpmn2:process> </bpmn2:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1"> <bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1"> <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_2">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2">
<dc:Bounds height="36.0" width="36.0" x="412.0" y="240.0"/>
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane> </bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram> </bpmndi:BPMNDiagram>
</bpmn2:definitions> </bpmn2:definitions>

View File

@ -43,7 +43,7 @@ describe('Viewer', function() {
describe('error handling', function() { describe('error handling', function() {
it('should handle errors', function(done) { it('should handle non-bpmn input', function(done) {
var xml = 'invalid stuff'; var xml = 'invalid stuff';
@ -57,6 +57,22 @@ describe('Viewer', function() {
}); });
}); });
it('should handle invalid BPMNPlane#bpmnElement', function(done) {
var xml = fs.readFileSync('test/fixtures/bpmn/error/di-plane-no-bpmn-element.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
expect(err).toBeDefined();
expect(err.message).toEqual('no rootElement referenced in BPMNPlane <BPMNPlane_1>');
done();
});
});
}); });