Skip to content

Commit

Permalink
test(JsonBuilder): not possible to have NONE eventDefinitionOn and …
Browse files Browse the repository at this point in the history
…`eventDefinitionKind` in same time in `BuildEventParameter` (#2899)

To avoid confusion, if the property `eventDefinitionOn` is set to `NONE` and the property `eventDefinitionKind` is set in the same instance of `BuildEventParameter`, an error is thrown.
  • Loading branch information
csouchet authored Sep 29, 2023
1 parent 68ff296 commit cdac517
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 50 deletions.
156 changes: 106 additions & 50 deletions test/unit/helpers/JsonBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1908,7 +1908,7 @@ describe('build json', () => {
event: [
{
bpmnKind,
eventDefinitionParameter: { eventDefinitionKind: 'message', eventDefinitionOn: EventDefinitionOn.NONE, eventDefinition: { id: '9' } },
eventDefinitionParameter: { eventDefinitionKind: 'message', eventDefinitionOn: EventDefinitionOn.EVENT, eventDefinition: { id: '9' } },
},
],
},
Expand All @@ -1920,7 +1920,12 @@ describe('build json', () => {
collaboration: { id: 'collaboration_id_0' },
process: {
id: '0',
[bpmnKind]: { id: 'event_id_0_0' },
[bpmnKind]: {
id: 'event_id_0_0',
messageEventDefinition: {
id: '9',
},
},
},
BPMNDiagram: {
name: 'process 0',
Expand Down Expand Up @@ -2402,14 +2407,109 @@ describe('build json', () => {
});
});

it(`build json of definitions containing one process with none ${bpmnKind}`, () => {
const json = buildDefinitions({
process: {
event: [
{
bpmnKind,
eventDefinitionParameter: { eventDefinitionOn: EventDefinitionOn.NONE },
},
],
},
});

expect(json).toEqual({
definitions: {
targetNamespace: '',
collaboration: { id: 'collaboration_id_0' },
process: {
id: '0',
[bpmnKind]: {
id: 'event_id_0_0',
},
},
BPMNDiagram: {
name: 'process 0',
BPMNPlane: {
BPMNShape: {
id: 'shape_event_id_0_0',
bpmnElement: 'event_id_0_0',
Bounds: { x: 362, y: 232, width: 36, height: 45 },
},
},
},
},
});
});

it(`not possible to have eventDefinitionOn=NONE with defined eventDefinitionKind`, () => {
expect(() => {
buildDefinitions({
process: {
event: [
{
bpmnKind,
eventDefinitionParameter: { eventDefinitionKind: 'message', eventDefinitionOn: EventDefinitionOn.NONE },
},
],
},
});
}).toThrow("Must use another value than NONE for 'eventDefinitionOn' when 'eventDefinitionKind' is set !!");
});

it(`incoming and outgoing for ${bpmnKind}`, () => {
const json = buildDefinitions({
process: {
event: [
{
bpmnKind,
name: 'name',
id: 'another_id',
eventDefinitionParameter: { eventDefinitionKind: 'message', eventDefinitionOn: EventDefinitionOn.EVENT },
incoming: ['incoming_id'],
outgoing: ['outgoing_id'],
},
],
},
});

expect(json).toEqual({
definitions: {
targetNamespace: '',
collaboration: { id: 'collaboration_id_0' },
process: {
id: '0',
[bpmnKind]: {
id: 'another_id',
messageEventDefinition: '',
name: 'name',
incoming: ['incoming_id'],
outgoing: ['outgoing_id'],
},
},
BPMNDiagram: {
name: 'process 0',
BPMNPlane: {
BPMNShape: {
id: 'shape_another_id',
bpmnElement: 'another_id',
Bounds: { x: 362, y: 232, width: 36, height: 45 },
},
},
},
},
});
});

if (bpmnKind === 'startEvent') {
it('build json of definitions containing one process with interrupting startEvent', () => {
const json = buildDefinitions({
process: {
event: [
{
bpmnKind,
eventDefinitionParameter: { eventDefinitionKind: 'message', eventDefinitionOn: EventDefinitionOn.NONE, eventDefinition: {} },
eventDefinitionParameter: { eventDefinitionKind: 'message', eventDefinitionOn: EventDefinitionOn.EVENT, eventDefinition: {} },
isInterrupting: true,
},
],
Expand All @@ -2422,7 +2522,7 @@ describe('build json', () => {
collaboration: { id: 'collaboration_id_0' },
process: {
id: '0',
startEvent: { id: 'event_id_0_0', cancelActivity: true },
startEvent: { id: 'event_id_0_0', messageEventDefinition: {}, cancelActivity: true },
},
BPMNDiagram: {
name: 'process 0',
Expand All @@ -2444,7 +2544,7 @@ describe('build json', () => {
event: [
{
bpmnKind,
eventDefinitionParameter: { eventDefinitionKind: 'message', eventDefinitionOn: EventDefinitionOn.NONE, eventDefinition: {} },
eventDefinitionParameter: { eventDefinitionKind: 'message', eventDefinitionOn: EventDefinitionOn.EVENT, eventDefinition: {} },
isInterrupting: false,
},
],
Expand All @@ -2457,7 +2557,7 @@ describe('build json', () => {
collaboration: { id: 'collaboration_id_0' },
process: {
id: '0',
startEvent: { id: 'event_id_0_0', cancelActivity: false },
startEvent: { id: 'event_id_0_0', cancelActivity: false, messageEventDefinition: {} },
},
BPMNDiagram: {
name: 'process 0',
Expand All @@ -2473,50 +2573,6 @@ describe('build json', () => {
});
});
}

it(`incoming and outgoing for ${bpmnKind}`, () => {
const json = buildDefinitions({
process: {
event: [
{
bpmnKind,
name: 'name',
id: 'another_id',
eventDefinitionParameter: { eventDefinitionKind: 'message', eventDefinitionOn: EventDefinitionOn.EVENT },
incoming: ['incoming_id'],
outgoing: ['outgoing_id'],
},
],
},
});

expect(json).toEqual({
definitions: {
targetNamespace: '',
collaboration: { id: 'collaboration_id_0' },
process: {
id: '0',
[bpmnKind]: {
id: 'another_id',
messageEventDefinition: '',
name: 'name',
incoming: ['incoming_id'],
outgoing: ['outgoing_id'],
},
},
BPMNDiagram: {
name: 'process 0',
BPMNPlane: {
BPMNShape: {
id: 'shape_another_id',
bpmnElement: 'another_id',
Bounds: { x: 362, y: 232, width: 36, height: 45 },
},
},
},
},
});
});
},
);

Expand Down
3 changes: 3 additions & 0 deletions test/unit/helpers/JsonBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,9 @@ function addEvent(
break;
}
case EventDefinitionOn.NONE: {
if (eventDefinitionParameter.eventDefinitionKind) {
throw new Error("Must use another value than NONE for 'eventDefinitionOn' when 'eventDefinitionKind' is set !!");
}
break;
}
}
Expand Down

0 comments on commit cdac517

Please sign in to comment.