Skip to content

Commit

Permalink
test: split the file containing the unit tests for all events (#2896)
Browse files Browse the repository at this point in the history
  • Loading branch information
csouchet authored Sep 28, 2023
1 parent a467ac9 commit ebffc93
Show file tree
Hide file tree
Showing 5 changed files with 589 additions and 516 deletions.
148 changes: 148 additions & 0 deletions test/unit/component/parser/json/BpmnJsonParser.event.boundary.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
Copyright 2023 Bonitasoft S.A.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import type { BuildDefinitionParameter } from '../../../helpers/JsonBuilder';

import { buildDefinitions, EventDefinitionOn } from '../../../helpers/JsonBuilder';
import { expectAsWarning, parseJsonAndExpectOnlyFlowNodes, parsingMessageCollector } from '../../../helpers/JsonTestUtils';
import { getEventShapes } from '../../../helpers/TestUtils';
import { eventDefinitionsParameters, executeEventCommonTests, testMustConvertShapes } from '../../../helpers/TestUtils.BpmnJsonParser.event';

import { BoundaryEventNotAttachedToActivityWarning, ShapeUnknownBpmnElementWarning } from '@lib/component/parser/json/warnings';
import { ShapeBpmnElementKind, ShapeBpmnEventDefinitionKind } from '@lib/model/bpmn/internal';

function testMustNotConvertBoundaryEvent(definitionParameter: BuildDefinitionParameter, numberOfExpectedFlowNodes = 1): void {
const json = buildDefinitions(definitionParameter);

const bpmnModel = parseJsonAndExpectOnlyFlowNodes(json, numberOfExpectedFlowNodes, 2);

expect(getEventShapes(bpmnModel)).toHaveLength(0);
const warnings = parsingMessageCollector.getWarnings();

const warning0 = expectAsWarning<BoundaryEventNotAttachedToActivityWarning>(warnings[0], BoundaryEventNotAttachedToActivityWarning);
expect(warning0.bpmnElementId).toBe('event_id_0_0');
expect(warning0.attachedToReference).toEqual(numberOfExpectedFlowNodes == 0 ? 'unexisting_activity_id_0' : 'not_activity_id_0');
expect(warning0.attachedToKind).toEqual(numberOfExpectedFlowNodes == 0 ? undefined : ShapeBpmnElementKind.GATEWAY_EXCLUSIVE);

const warning1 = expectAsWarning<ShapeUnknownBpmnElementWarning>(warnings[1], ShapeUnknownBpmnElementWarning);
expect(warning1.bpmnElementId).toBe('event_id_0_0');
}

describe('for boundaryEvents', () => {
describe.each(eventDefinitionsParameters)(`for %s boundaryEvent`, (eventDefinitionKind: string, expectedEventDefinitionKind: ShapeBpmnEventDefinitionKind) => {
if (
expectedEventDefinitionKind === ShapeBpmnEventDefinitionKind.NONE ||
expectedEventDefinitionKind === ShapeBpmnEventDefinitionKind.LINK ||
expectedEventDefinitionKind === ShapeBpmnEventDefinitionKind.TERMINATE
) {
// Not supported in BPMN specification
return;
}

const titlesForEventDefinitionIsAttributeOf: [string, EventDefinitionOn][] = [
[`'boundaryEvent' has '${eventDefinitionKind}EventDefinition' & no 'eventDefinitionRef'`, EventDefinitionOn.EVENT],
[
`'definitions' has '${eventDefinitionKind}EventDefinition' and 'boundaryEvent' has no '${eventDefinitionKind}EventDefinition' & 'eventDefinitionRef'`,
EventDefinitionOn.DEFINITIONS,
],
];

describe.each([[true], [false]])(`for %s ${eventDefinitionKind} intermediate boundary events`, (isInterrupting: boolean) => {
if (
(!isInterrupting && expectedEventDefinitionKind === ShapeBpmnEventDefinitionKind.ERROR) ||
expectedEventDefinitionKind === ShapeBpmnEventDefinitionKind.CANCEL ||
expectedEventDefinitionKind === ShapeBpmnEventDefinitionKind.COMPENSATION
) {
// Not supported in BPMN specification
return;
}

describe.each(titlesForEventDefinitionIsAttributeOf)(`when %s`, (titleForEventDefinitionIsAttributeOf: string, eventDefinitionOn: EventDefinitionOn) => {
const isInterruptingTitle = isInterrupting ? 'interrupting' : 'non-interrupting';

executeEventCommonTests(
{
bpmnKind: 'boundaryEvent',
eventDefinitionParameter: { eventDefinitionKind, eventDefinitionOn },
isInterrupting,
attachedToRef: 'task_id_0_0',
},
{
parentId: 'task_id_0_0',
bpmnElementKind: ShapeBpmnElementKind.EVENT_BOUNDARY,
bpmnElementName: undefined,
eventDefinitionKind: expectedEventDefinitionKind,
isInterrupting,
},
`'boundaryEvent' is ${isInterruptingTitle} & attached to an 'activity', (${titleForEventDefinitionIsAttributeOf})`,
);

if (isInterrupting) {
it(`should convert as Shape, when 'boundaryEvent' has no 'cancelActivity' & is attached to an 'activity', ${titleForEventDefinitionIsAttributeOf}'`, () => {
testMustConvertShapes(
{
bpmnKind: 'boundaryEvent',
eventDefinitionParameter: { eventDefinitionKind, eventDefinitionOn },
isInterrupting: undefined,
attachedToRef: 'task_id_0_0',
},
{
parentId: 'task_id_0_0',
bpmnElementKind: ShapeBpmnElementKind.EVENT_BOUNDARY,
bpmnElementName: undefined,
eventDefinitionKind: expectedEventDefinitionKind,
isInterrupting: true,
},
);
});
}

it(`should NOT convert, when 'boundaryEvent' is ${isInterruptingTitle} & attached to anything than an 'activity', ${titleForEventDefinitionIsAttributeOf}`, () => {
testMustNotConvertBoundaryEvent({
process: {
event: {
bpmnKind: 'boundaryEvent',
eventDefinitionParameter: { eventDefinitionKind, eventDefinitionOn },
isInterrupting,
attachedToRef: 'not_activity_id_0',
},
gateway: {
id: 'not_activity_id_0',
bpmnKind: ShapeBpmnElementKind.GATEWAY_EXCLUSIVE,
},
},
});
});

it(`should NOT convert, when 'boundaryEvent' is ${isInterruptingTitle} & attached to no existing activity, ${titleForEventDefinitionIsAttributeOf}`, () => {
testMustNotConvertBoundaryEvent(
{
process: {
event: {
bpmnKind: 'boundaryEvent',
eventDefinitionParameter: { eventDefinitionKind, eventDefinitionOn },
isInterrupting,
attachedToRef: 'unexisting_activity_id_0',
},
},
},
0,
);
});
});
});
});
});
107 changes: 107 additions & 0 deletions test/unit/component/parser/json/BpmnJsonParser.event.none.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
Copyright 2023 Bonitasoft S.A.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import type { OtherBuildEventKind } from '../../../helpers/JsonBuilder';

import { verifyShape } from '../../../helpers/bpmn-model-expect';
import { buildDefinitions, EventDefinitionOn } from '../../../helpers/JsonBuilder';
import { parseJsonAndExpectEvent } from '../../../helpers/JsonTestUtils';
import { executeEventCommonTests } from '../../../helpers/TestUtils.BpmnJsonParser.event';

import { ShapeBpmnElementKind, ShapeBpmnEventDefinitionKind } from '@lib/model/bpmn/internal';

// None intermediateCatchEvent not supported in BPMN specification
describe.each([
[ShapeBpmnElementKind.EVENT_START, ['message', 'timer', 'conditional', 'signal']],
[ShapeBpmnElementKind.EVENT_END, ['message', 'error', 'escalation', 'cancel', 'compensate', 'signal', 'terminate']],
[ShapeBpmnElementKind.EVENT_INTERMEDIATE_THROW, ['message', 'escalation', 'compensate', 'link', 'signal']],
])('for none %s', (expectedShapeBpmnElementKind: ShapeBpmnElementKind, allDefinitionKinds: string[]) => {
executeEventCommonTests(
{
bpmnKind: expectedShapeBpmnElementKind as OtherBuildEventKind | 'startEvent',
eventDefinitionParameter: { eventDefinitionKind: 'none', eventDefinitionOn: EventDefinitionOn.NONE },
},
{
bpmnElementKind: expectedShapeBpmnElementKind,
bpmnElementName: undefined,
eventDefinitionKind: ShapeBpmnEventDefinitionKind.NONE,
},
`'${expectedShapeBpmnElementKind}' has no 'eventDefinition' & no 'eventDefinitionRef'`,
);

it(`should convert as NONE Shape only the '${expectedShapeBpmnElementKind}' without 'eventDefinition' & without 'eventDefinitionRef', when an array of '${expectedShapeBpmnElementKind}' (without/with one or several event definition) is an attribute of 'process'`, () => {
const json = buildDefinitions({
process: {
event: [
{
id: `none_${expectedShapeBpmnElementKind}_id`,
name: `none ${expectedShapeBpmnElementKind}`,
bpmnKind: expectedShapeBpmnElementKind as OtherBuildEventKind | 'startEvent',
eventDefinitionParameter: { eventDefinitionOn: EventDefinitionOn.NONE },
},
{
bpmnKind: expectedShapeBpmnElementKind as OtherBuildEventKind | 'startEvent',
eventDefinitionParameter: {
eventDefinitionKind: 'message',
eventDefinitionOn: EventDefinitionOn.EVENT,
withDifferentDefinition: true,
},
},
{
bpmnKind: expectedShapeBpmnElementKind as OtherBuildEventKind | 'startEvent',
eventDefinitionParameter: {
eventDefinitionKind: 'message',
eventDefinitionOn: EventDefinitionOn.DEFINITIONS,
withDifferentDefinition: true,
},
},
{
bpmnKind: expectedShapeBpmnElementKind as OtherBuildEventKind | 'startEvent',
eventDefinitionParameter: {
eventDefinitionKind: 'message',
eventDefinitionOn: EventDefinitionOn.BOTH,
withDifferentDefinition: true,
},
},

...allDefinitionKinds.map((definitionKind, index) => ({
id: `${definitionKind}_${expectedShapeBpmnElementKind}_id_${index}`,
bpmnKind: expectedShapeBpmnElementKind as OtherBuildEventKind | 'startEvent',
eventDefinitionParameter: {
eventDefinitionKind: definitionKind,
eventDefinitionOn: EventDefinitionOn.EVENT,
},
})),
],
},
});

const model = parseJsonAndExpectEvent(json, ShapeBpmnEventDefinitionKind.NONE, 1);

verifyShape(model.flowNodes[0], {
shapeId: `shape_none_${expectedShapeBpmnElementKind}_id`,
bpmnElementId: `none_${expectedShapeBpmnElementKind}_id`,
bpmnElementName: `none ${expectedShapeBpmnElementKind}`,
bpmnElementKind: expectedShapeBpmnElementKind,
bounds: {
x: 362,
y: 232,
width: 36,
height: 45,
},
});
});
});
Loading

0 comments on commit ebffc93

Please sign in to comment.