bpmn-moddle 0.10.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -49,6 +49,56 @@ describe('bpmn-moddle - write', function() {
49
49
  });
50
50
 
51
51
 
52
+ it('Definitions (participant + interface)', function(done) {
53
+
54
+ // given
55
+ var interfaceElement = moddle.create('bpmn:Interface', {
56
+ id: 'Interface_1'
57
+ });
58
+
59
+ var participantElement = moddle.create('bpmn:Participant', {
60
+ id: 'Process_1',
61
+ interfaceRef: [
62
+ interfaceElement
63
+ ]
64
+ });
65
+
66
+ var collaborationElement = moddle.create('bpmn:Collaboration', {
67
+ participants: [
68
+ participantElement
69
+ ]
70
+ });
71
+
72
+ var definitions = moddle.create('bpmn:Definitions', {
73
+ targetNamespace: 'http://bpmn.io/bpmn',
74
+ rootElements: [
75
+ interfaceElement,
76
+ collaborationElement
77
+ ]
78
+ });
79
+
80
+ var expectedXML =
81
+ '<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" ' +
82
+ 'targetNamespace="http://bpmn.io/bpmn">' +
83
+ '<bpmn:interface id="Interface_1" />' +
84
+ '<bpmn:collaboration>' +
85
+ '<bpmn:participant id="Process_1">' +
86
+ '<bpmn:interfaceRef>Interface_1</bpmn:interfaceRef>' +
87
+ '</bpmn:participant>' +
88
+ '</bpmn:collaboration>' +
89
+ '</bpmn:definitions>';
90
+
91
+ // when
92
+ write(definitions, function(err, result) {
93
+
94
+ // then
95
+ expect(result).to.eql(expectedXML);
96
+
97
+ done(err);
98
+ });
99
+ });
100
+
101
+
52
102
  it('ScriptTask#script', function(done) {
53
103
 
54
104
  // given
@@ -106,7 +156,57 @@ describe('bpmn-moddle - write', function() {
106
156
  });
107
157
 
108
158
 
109
- it.skip('Process', function(done) {
159
+ it('MultiInstanceLoopCharacteristics', function(done) {
160
+
161
+ // given
162
+ var loopCharacteristics = moddle.create('bpmn:MultiInstanceLoopCharacteristics', {
163
+ loopCardinality: moddle.create('bpmn:FormalExpression', { body: '${ foo < bar }' }),
164
+ loopDataInputRef: moddle.create('bpmn:Property', { id: 'loopDataInputRef' }),
165
+ loopDataOutputRef: moddle.create('bpmn:Property', { id: 'loopDataOutputRef' }),
166
+ inputDataItem: moddle.create('bpmn:DataInput', { id: 'inputDataItem' }),
167
+ outputDataItem: moddle.create('bpmn:DataOutput', { id: 'outputDataItem' }),
168
+ complexBehaviorDefinition: [
169
+ moddle.create('bpmn:ComplexBehaviorDefinition', { id: 'complexBehaviorDefinition' })
170
+ ],
171
+ completionCondition: moddle.create('bpmn:FormalExpression', { body: '${ done }' }),
172
+ isSequential: true,
173
+ behavior: 'One',
174
+ oneBehaviorEventRef: moddle.create('bpmn:CancelEventDefinition', { id: 'oneBehaviorEventRef' }),
175
+ noneBehaviorEventRef: moddle.create('bpmn:MessageEventDefinition', { id: 'noneBehaviorEventRef' })
176
+ });
177
+
178
+ var expectedXML =
179
+ '<bpmn:multiInstanceLoopCharacteristics xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" ' +
180
+ 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
181
+ 'isSequential="true" ' +
182
+ 'behavior="One" ' +
183
+ 'oneBehaviorEventRef="oneBehaviorEventRef" ' +
184
+ 'noneBehaviorEventRef="noneBehaviorEventRef">' +
185
+ '<bpmn:loopCardinality xsi:type="bpmn:tFormalExpression"><![CDATA[${ foo < bar }]]></bpmn:loopCardinality>' +
186
+ '<bpmn:loopDataInputRef>loopDataInputRef</bpmn:loopDataInputRef>' +
187
+ '<bpmn:loopDataOutputRef>loopDataOutputRef</bpmn:loopDataOutputRef>' +
188
+ '<bpmn:inputDataItem id="inputDataItem" />' +
189
+ '<bpmn:outputDataItem id="outputDataItem" />' +
190
+ '<bpmn:complexBehaviorDefinition id="complexBehaviorDefinition" />' +
191
+ '<bpmn:completionCondition xsi:type="bpmn:tFormalExpression">${ done }</bpmn:completionCondition>' +
192
+ '</bpmn:multiInstanceLoopCharacteristics>';
193
+
194
+ // when
195
+ write(loopCharacteristics, function(err, result) {
196
+
197
+ if (err) {
198
+ return done(err);
199
+ }
200
+
201
+ // then
202
+ expect(result).to.eql(expectedXML);
203
+
204
+ done(err);
205
+ });
206
+ });
207
+
208
+
209
+ it('Process', function(done) {
110
210
 
111
211
  // given
112
212
  var processElement = moddle.create('bpmn:Process', {
@@ -285,6 +385,43 @@ describe('bpmn-moddle - write', function() {
285
385
  });
286
386
 
287
387
 
388
+ it('ResourceAssignmentExpression', function(done) {
389
+
390
+ // given
391
+ var expression = moddle.create('bpmn:FormalExpression', { body: '${ foo < bar }' });
392
+
393
+ var assignmentExpression =
394
+ moddle.create('bpmn:ResourceAssignmentExpression', {
395
+ id: 'FOO BAR',
396
+ expression: expression
397
+ });
398
+
399
+ var expectedXML =
400
+ '<bpmn:resourceAssignmentExpression ' +
401
+ 'xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" ' +
402
+ 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
403
+ 'id="FOO BAR">' +
404
+ '<bpmn:expression xsi:type="bpmn:tFormalExpression">' +
405
+ '<![CDATA[${ foo < bar }]]>' +
406
+ '</bpmn:expression>' +
407
+ '</bpmn:resourceAssignmentExpression>';
408
+
409
+ // when
410
+ write(assignmentExpression, function(err, result, context) {
411
+
412
+ if (err) {
413
+ return done(err);
414
+ }
415
+
416
+ // then
417
+ expect(result).to.eql(expectedXML);
418
+
419
+ done(err);
420
+ });
421
+
422
+ });
423
+
424
+
288
425
  it('CallActivity#calledElement', function(done) {
289
426
 
290
427
  // given
@@ -333,6 +470,41 @@ describe('bpmn-moddle - write', function() {
333
470
  });
334
471
 
335
472
 
473
+ it('ItemDefinition#structureRef with ns', function(done) {
474
+
475
+ // given
476
+ var itemDefinition = moddle.create('bpmn:ItemDefinition', {
477
+ 'xmlns:xs': 'http://xml-types',
478
+ id: 'xsdBool',
479
+ isCollection: true,
480
+ itemKind: 'Information',
481
+ structureRef: 'xs:tBool'
482
+ });
483
+
484
+ var expectedXML =
485
+ '<bpmn:itemDefinition xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" ' +
486
+ 'xmlns:xs="http://xml-types" ' +
487
+ 'id="xsdBool" ' +
488
+ 'itemKind="Information" ' +
489
+ 'structureRef="xs:tBool" ' +
490
+ 'isCollection="true" />';
491
+
492
+
493
+ // when
494
+ write(itemDefinition, function(err, result) {
495
+
496
+ if (err) {
497
+ return done(err);
498
+ }
499
+
500
+ // then
501
+ expect(result).to.eql(expectedXML);
502
+
503
+ done();
504
+ });
505
+ });
506
+
507
+
336
508
  it('Operation#implementationRef', function(done) {
337
509
 
338
510
  // given
@@ -457,41 +629,6 @@ describe('bpmn-moddle - write', function() {
457
629
  });
458
630
 
459
631
 
460
- it.skip('ItemDefinition#structureRef', function(done) {
461
-
462
- // given
463
- var itemDefinition = moddle.create('bpmn:ItemDefinition', {
464
- 'xmlns:xs': 'http://xml-types',
465
- id: 'xsdBool',
466
- isCollection: true,
467
- itemKind: 'Information',
468
- structureRef: 'xs:tBool'
469
- });
470
-
471
- var expectedXML =
472
- '<bpmn:itemDefinition xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" ' +
473
- 'xmlns:xs="http://xml-types" ' +
474
- 'id="xsdBool" ' +
475
- 'itemKind="Information" ' +
476
- 'structureRef="xs:tBool" ' +
477
- 'isCollection="true" />';
478
-
479
-
480
- // when
481
- write(itemDefinition, function(err, result) {
482
-
483
- if (err) {
484
- return done(err);
485
- }
486
-
487
- // then
488
- expect(result).to.eql(expectedXML);
489
-
490
- done();
491
- });
492
- });
493
-
494
-
495
632
  it('Operation#messageRef', function(done) {
496
633
  // given
497
634
  var inMessage = moddle.create('bpmn:Message', {
@@ -528,17 +665,23 @@ describe('bpmn-moddle - write', function() {
528
665
 
529
666
  describe('bpmndi', function() {
530
667
 
531
- it.skip('BPMNDiagram', function(done) {
668
+ it('BPMNDiagram', function(done) {
532
669
 
533
670
  // given
534
- var diagram = moddle.create('bpmndi:BPMNDiagram', { name: 'FOO' });
671
+ var diagram = moddle.create('bpmndi:BPMNDiagram', { name: 'FOO', resolution: 96.5 });
535
672
 
536
673
  var expectedXML =
537
- '<bpmndi:BPMNDiagram xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" name="FOO" />';
674
+ '<bpmndi:BPMNDiagram xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" ' +
675
+ 'name="FOO" ' +
676
+ 'resolution="96.5" />';
538
677
 
539
678
  // when
540
679
  write(diagram, function(err, result) {
541
680
 
681
+ if (err) {
682
+ return done(err);
683
+ }
684
+
542
685
  // then
543
686
  expect(result).to.eql(expectedXML);
544
687
 
@@ -577,8 +720,35 @@ describe('bpmn-moddle - write', function() {
577
720
 
578
721
  describe('should export extensions', function() {
579
722
 
723
+ it('manually added custom namespace', function(done) {
724
+
725
+ // given
726
+ var definitions = moddle.create('bpmn:Definitions');
727
+
728
+ definitions.set('xmlns:foo', 'http://foobar');
729
+
730
+ // or alternatively directly assign it to definitions.$attrs
731
+
732
+ var expectedXML =
733
+ '<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" ' +
734
+ 'xmlns:foo="http://foobar" />';
735
+
736
+ // when
737
+ write(definitions, function(err, result) {
738
+
739
+ if (err) {
740
+ return done(err);
741
+ }
742
+
743
+ // then
744
+ expect(result).to.eql(expectedXML);
745
+
746
+ done(err);
747
+ });
748
+ });
749
+
580
750
 
581
- it('as attributes', function(done) {
751
+ it('attributes on root', function(done) {
582
752
 
583
753
  // given
584
754
  var definitions = moddle.create('bpmn:Definitions');
@@ -603,7 +773,38 @@ describe('bpmn-moddle - write', function() {
603
773
  });
604
774
 
605
775
 
606
- it('as elements', function(done) {
776
+ it('attributes on nested element', function(done) {
777
+
778
+ // given
779
+ var signal = moddle.create('bpmn:Signal', {
780
+ 'foo:bar': 'BAR'
781
+ });
782
+
783
+ var definitions = moddle.create('bpmn:Definitions');
784
+
785
+ definitions.set('xmlns:foo', 'http://foobar');
786
+ definitions.get('rootElements').push(signal);
787
+
788
+ // or alternatively directly assign it to definitions.$attrs
789
+
790
+ var expectedXML =
791
+ '<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" ' +
792
+ 'xmlns:foo="http://foobar">' +
793
+ '<bpmn:signal foo:bar="BAR" />' +
794
+ '</bpmn:definitions>';
795
+
796
+ // when
797
+ write(definitions, function(err, result) {
798
+
799
+ // then
800
+ expect(result).to.eql(expectedXML);
801
+
802
+ done(err);
803
+ });
804
+ });
805
+
806
+
807
+ it('elements via bpmn:extensionElements', function(done) {
607
808
 
608
809
  // given
609
810
 
@@ -647,6 +848,56 @@ describe('bpmn-moddle - write', function() {
647
848
  });
648
849
  });
649
850
 
851
+
852
+ it('nested elements via bpmn:extensionElements', function(done) {
853
+
854
+ var camundaNs = 'http://camunda.org/schema/1.0/bpmn';
855
+
856
+ // when
857
+
858
+ var inputParameter = moddle.createAny('camunda:inputParameter', camundaNs, {
859
+ name: 'assigneeEntity',
860
+ $body: 'user'
861
+ });
862
+
863
+ var inputOutput = moddle.createAny('camunda:inputOutput', camundaNs, {
864
+ $children: [
865
+ inputParameter
866
+ ]
867
+ });
868
+
869
+ var extensionElements = moddle.create('bpmn:ExtensionElements', {
870
+ values: [ inputOutput ]
871
+ });
872
+
873
+ var userTask = moddle.create('bpmn:UserTask', {
874
+ extensionElements: extensionElements
875
+ });
876
+
877
+ var expectedXML =
878
+ '<bpmn:userTask xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" ' +
879
+ 'xmlns:camunda="' + camundaNs + '">' +
880
+ '<bpmn:extensionElements>' +
881
+ '<camunda:inputOutput>' +
882
+ '<camunda:inputParameter name="assigneeEntity">user</camunda:inputParameter>' +
883
+ '</camunda:inputOutput>' +
884
+ '</bpmn:extensionElements>' +
885
+ '</bpmn:userTask>';
886
+
887
+ // when
888
+ write(userTask, function(err, result) {
889
+
890
+ if (err) {
891
+ return done(err);
892
+ }
893
+
894
+ // then
895
+ expect(result).to.eql(expectedXML);
896
+
897
+ done();
898
+ });
899
+ });
900
+
650
901
  });
651
902
 
652
903
  });
package/lib/id-support.js DELETED
@@ -1,55 +0,0 @@
1
- 'use strict';
2
-
3
- var ID_PATTERN = /^(.*:)?id$/;
4
-
5
- /**
6
- * Extends the bpmn instance with id support.
7
- *
8
- * @example
9
- *
10
- * var moddle, ids;
11
- *
12
- * require('id-support').extend(moddle, ids);
13
- *
14
- * moddle.ids.next(); // create a next id
15
- * moddle.ids; // ids instance
16
- *
17
- * // claims id as used
18
- * moddle.create('foo:Bar', { id: 'fooobar1' });
19
- *
20
- *
21
- * @param {Moddle} model
22
- * @param {Ids} ids
23
- *
24
- * @return {Moddle} the extended moddle instance
25
- */
26
- module.exports.extend = function(model, ids) {
27
-
28
- var set = model.properties.set;
29
-
30
- // do not reinitialize setter
31
- // unless it is already initialized
32
- if (!model.ids) {
33
-
34
- model.properties.set = function(target, property, value) {
35
-
36
- // ensure we log used ids once they are assigned
37
- // to model elements
38
- if (ID_PATTERN.test(property)) {
39
-
40
- var assigned = model.ids.assigned(value);
41
- if (assigned && assigned !== target) {
42
- throw new Error('id <' + value + '> already used');
43
- }
44
-
45
- model.ids.claim(value, target);
46
- }
47
-
48
- set.call(this, target, property, value);
49
- };
50
- }
51
-
52
- model.ids = ids;
53
-
54
- return model;
55
- };
@@ -1,97 +0,0 @@
1
- 'use strict';
2
-
3
- var Helper = require('../helper');
4
-
5
- var Ids = require('ids'),
6
- IdSupport = require('../../lib/id-support');
7
-
8
-
9
- describe('bpmn-moddle - id-support', function() {
10
-
11
- describe('.extend', function() {
12
-
13
- it('should extend bpmn-moddle with ids', function() {
14
-
15
- // given
16
- var moddle = Helper.createModdle();
17
- var ids = new Ids();
18
-
19
- // when
20
- IdSupport.extend(moddle, ids);
21
-
22
- // then
23
- expect(moddle.ids).to.equal(ids);
24
- });
25
-
26
- });
27
-
28
-
29
- describe('functionality', function() {
30
-
31
- it('should claim ids during object creation', function() {
32
-
33
- // given
34
- var moddle = Helper.createModdle();
35
- var ids = new Ids();
36
-
37
- IdSupport.extend(moddle, ids);
38
-
39
- // when
40
- var serviceTask = moddle.create('bpmn:ServiceTask', {
41
- id: 'ServiceTask_1'
42
- });
43
-
44
- // then
45
- expect(serviceTask.id).to.equal('ServiceTask_1');
46
- expect(moddle.ids.assigned(serviceTask.id)).to.equal(serviceTask);
47
- });
48
-
49
-
50
- it('should claim ids during object creation', function() {
51
-
52
- // given
53
- var moddle = Helper.createModdle();
54
- var ids = new Ids();
55
-
56
- IdSupport.extend(moddle, ids);
57
-
58
- // when
59
- moddle.create('bpmn:ServiceTask', {
60
- id: 'ServiceTask_1'
61
- });
62
-
63
- // then
64
- expect(function() {
65
-
66
- moddle.create('bpmn:ServiceTask', {
67
- id: 'ServiceTask_1'
68
- });
69
- }).to.throw('id <ServiceTask_1> already used');
70
- });
71
-
72
-
73
- it('should reset and allow reclaim of ids', function() {
74
-
75
- // given
76
- var moddle = Helper.createModdle();
77
- IdSupport.extend(moddle, new Ids());
78
-
79
- moddle.create('bpmn:ServiceTask', {
80
- id: 'ServiceTask_1'
81
- });
82
-
83
- // when
84
- IdSupport.extend(moddle, new Ids());
85
-
86
- // then
87
- // expect id to have been reset
88
- expect(function() {
89
-
90
- moddle.create('bpmn:ServiceTask', {
91
- id: 'ServiceTask_1'
92
- });
93
- }).not.to.throw();
94
- });
95
- });
96
-
97
- });