Skip to content

Commit

Permalink
[TEST] To be able to override the generic id of the generated event w…
Browse files Browse the repository at this point in the history
…ith JsonBuilder (#2132)
  • Loading branch information
csouchet authored Jul 22, 2022
1 parent d0230ab commit de5e0ed
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,14 @@ describe('parse bpmn as json for message flow', () => {
const isBoundaryEvent = kind === ShapeBpmnElementKind.EVENT_BOUNDARY;
const eventParameter: BuildEventParameter = isBoundaryEvent
? {
id,
bpmnKind: kind,
isInterrupting: true,
attachedToRef: 'task_id_0',
eventDefinitionParameter: { eventDefinitionKind: 'message', eventDefinitionOn: EventDefinitionOn.EVENT },
}
: {
id,
bpmnKind: kind,
eventDefinitionParameter: { eventDefinitionKind: 'message', eventDefinitionOn: EventDefinitionOn.EVENT },
};
Expand Down
32 changes: 18 additions & 14 deletions test/unit/helpers/JsonBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,16 @@ describe('build json', () => {

describe('build json with boundary event', () => {
describe('build json with interrupting boundary event', () => {
it('build json of definitions containing one process with task and interrupting boundary event (with attachedToRef & empty messageEventDefinition)', () => {
it('build json of definitions containing one process with task and interrupting boundary event (with attachedToRef, empty messageEventDefinition, name & id)', () => {
const json = buildDefinitions({
process: {
event: [
{
bpmnKind: 'boundaryEvent',
isInterrupting: true,
attachedToRef: 'task_id_0_0',
name: 'name',
id: 'another_id',
eventDefinitionParameter: { eventDefinitionKind: 'message', eventDefinitionOn: EventDefinitionOn.EVENT },
},
],
Expand All @@ -397,11 +399,11 @@ describe('build json', () => {
name: 'task name',
},
boundaryEvent: {
id: 'event_id_0_0',
id: 'another_id',
cancelActivity: true,
attachedToRef: 'task_id_0_0',
messageEventDefinition: '',
name: undefined,
name: 'name',
},
},
BPMNDiagram: {
Expand All @@ -419,8 +421,8 @@ describe('build json', () => {
},
},
{
id: 'shape_event_id_0_0',
bpmnElement: 'event_id_0_0',
id: 'shape_another_id',
bpmnElement: 'another_id',
Bounds: {
x: 362,
y: 232,
Expand Down Expand Up @@ -1187,14 +1189,15 @@ describe('build json', () => {
});

describe('build json with non-interrupting boundary event', () => {
it('build json of definitions containing one process with task and non-interrupting boundary event (with attachedToRef, empty messageEventDefinition and name, without cancelActivity)', () => {
it('build json of definitions containing one process with task and non-interrupting boundary event (with attachedToRef, empty messageEventDefinition, name & id, without cancelActivity)', () => {
const json = buildDefinitions({
process: {
event: [
{
bpmnKind: 'boundaryEvent',
attachedToRef: 'task_id_0_0',
name: 'name',
id: 'another_id',
eventDefinitionParameter: { eventDefinitionKind: 'message', eventDefinitionOn: EventDefinitionOn.EVENT },
},
],
Expand All @@ -1215,7 +1218,7 @@ describe('build json', () => {
name: 'task name',
},
boundaryEvent: {
id: 'event_id_0_0',
id: 'another_id',
attachedToRef: 'task_id_0_0',
messageEventDefinition: '',
name: 'name',
Expand All @@ -1236,8 +1239,8 @@ describe('build json', () => {
},
},
{
id: 'shape_event_id_0_0',
bpmnElement: 'event_id_0_0',
id: 'shape_another_id',
bpmnElement: 'another_id',
Bounds: {
x: 362,
y: 232,
Expand Down Expand Up @@ -2070,7 +2073,7 @@ describe('build json', () => {
});

describe.each(['startEvent', 'endEvent', 'intermediateCatchEvent', 'intermediateThrowEvent'])('build json with %s event', (bpmnKind: string) => {
it('build json of definitions containing one process with ${bpmnKind} (without eventDefinition)', () => {
it('build json of definitions containing one process with ${bpmnKind} (without eventDefinition & id)', () => {
const json = buildDefinitions({
process: {
event: [
Expand Down Expand Up @@ -2115,13 +2118,14 @@ describe('build json', () => {
});
});

it('build json of definitions containing one process with ${bpmnKind} (with one messageEventDefinition & name)', () => {
it('build json of definitions containing one process with ${bpmnKind} (with one messageEventDefinition & name & id)', () => {
const json = buildDefinitions({
process: {
event: [
{
bpmnKind,
name: 'name',
id: 'another_id',
eventDefinitionParameter: { eventDefinitionKind: 'message', eventDefinitionOn: EventDefinitionOn.EVENT },
},
],
Expand All @@ -2137,7 +2141,7 @@ describe('build json', () => {
process: {
id: '0',
[bpmnKind]: {
id: 'event_id_0_0',
id: 'another_id',
messageEventDefinition: '',
name: 'name',
},
Expand All @@ -2146,8 +2150,8 @@ describe('build json', () => {
name: 'process 0',
BPMNPlane: {
BPMNShape: {
id: 'shape_event_id_0_0',
bpmnElement: 'event_id_0_0',
id: 'shape_another_id',
bpmnElement: 'another_id',
Bounds: {
x: 362,
y: 232,
Expand Down
25 changes: 21 additions & 4 deletions test/unit/helpers/JsonBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export enum EventDefinitionOn {
}

export interface BuildEventParameter {
/**
* If it sets, the default id is override.
* Otherwise, the id has the format: `event_id_${processIndex}_${index}`
*/
id?: string;
bpmnKind: string;
name?: string;
isInterrupting?: boolean;
Expand All @@ -51,14 +56,26 @@ export interface BuildEventDefinitionParameter {
}

export interface BuildTaskParameter {
/**
* If it sets, the default id is override.
* Otherwise, the id has the format: `task_id_${processIndex}_${index}`
*/
id?: string;
}

export interface BuildCallActivityParameter {
/**
* If it sets, the default id is override.
* Otherwise, the id has the format: `callActivity_id_${processIndex}_${index}`
*/
id?: string;
}

export interface BuildExclusiveGatewayParameter {
/**
* If it sets, the default id is override.
* Otherwise, the id has the format: `exclusiveGateway_id_${processIndex}_${index}`
*/
id?: string;
}

Expand Down Expand Up @@ -365,9 +382,9 @@ function addEventDefinitionsOnEvent(event: TCatchEvent | TThrowEvent | TBoundary
}
}

function buildEvent(index: number, processIndex: number, name?: string, isInterrupting?: boolean, attachedToRef?: string): BPMNTEvent {
function buildEvent(index: number, processIndex: number, name: string, isInterrupting: boolean, attachedToRef: string, id: string): BPMNTEvent {
const event: BPMNTEvent = {
id: `event_id_${processIndex}_${index}`,
id: id ? id : `event_id_${processIndex}_${index}`,
name: name,
};

Expand All @@ -382,11 +399,11 @@ function buildEvent(index: number, processIndex: number, name?: string, isInterr

function addEvent(
jsonModel: BpmnJsonModel,
{ bpmnKind, eventDefinitionParameter, name, isInterrupting, attachedToRef }: BuildEventParameter,
{ id, bpmnKind, eventDefinitionParameter, name, isInterrupting, attachedToRef }: BuildEventParameter,
index: number,
processIndex: number,
): void {
const event = buildEvent(index, processIndex, name, isInterrupting, attachedToRef);
const event = buildEvent(index, processIndex, name, isInterrupting, attachedToRef, id);
switch (eventDefinitionParameter.eventDefinitionOn) {
case EventDefinitionOn.BOTH:
addEventDefinitionsOnEvent(event, eventDefinitionParameter);
Expand Down

0 comments on commit de5e0ed

Please sign in to comment.