Skip to content

Commit

Permalink
revert signal functionality
Browse files Browse the repository at this point in the history
forgot about signal- and message event definitions
  • Loading branch information
paed01 committed Jul 19, 2023
1 parent 7c2ac1d commit 2de2c1c
Show file tree
Hide file tree
Showing 8 changed files with 380 additions and 121 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bpmn-middleware",
"version": "0.0.4",
"version": "0.0.5",
"description": "BPMN engine express middleware",
"type": "module",
"main": "dist/main.cjs",
Expand Down
7 changes: 3 additions & 4 deletions src/Engines.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,22 @@ Engines.prototype.resume = async function resume(token, listener) {

Engines.prototype.signalActivity = async function signalActivity(token, listener, body) {
const engine = await this.resume(token, listener);
const api = await this._getActivityApi(engine, body);

api.signal(body.message);
engine.execution.signal(body);

return engine;
};

Engines.prototype.cancelActivity = async function cancelActivity(token, listener, body) {
const engine = await this.resume(token, listener);
const api = await this._getActivityApi(engine, body);
const api = this._getActivityApi(engine, body);
api.cancel();
return engine;
};

Engines.prototype.failActivity = async function failActivity(token, listener, body) {
const engine = await this.resume(token, listener);
const api = await this._getActivityApi(engine, body);
const api = this._getActivityApi(engine, body);
api.sendApiMessage('error', body, { type: 'error' });
return engine;
};
Expand Down
82 changes: 78 additions & 4 deletions test/features/call-activity-feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,80 @@ Feature('call activity', () => {
Then('run completes', () => {
return end;
});

Given('a process with a call activity referencing a process with user task', () => {
return createDeployment(apps.balance(), 'call-internal-user-process', `<definitions id="Def_1" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<process id="main-process" isExecutable="true">
<startEvent id="start" />
<sequenceFlow id="to-call-activity" sourceRef="start" targetRef="call-activity" />
<callActivity id="call-activity" calledElement="called-process" />
<endEvent id="end" />
<sequenceFlow id="to-end" sourceRef="call-activity" targetRef="end" />
</process>
<process id="called-process" isExecutable="false">
<userTask id="task" />
</process>
</definitions>`);
});

let token, wait;
When('when process is started', async () => {
const app = apps.balance();
wait = waitForProcess(app, 'call-internal-user-process').wait('task');

const response = await request(app)
.post('/rest/process-definition/call-internal-user-process/start')
.expect(201);

token = response.body.id;
});

Then('internal process user task is waiting', () => {
return wait;
});

When('user task is signalled', () => {
const app = apps.balance();
wait = waitForProcess(app, token).end();

return request(app)
.post(`/rest/signal/${token}`)
.send({ id: 'task' })
.expect(200);
});

Then('run completes', () => {
return end;
});

When('when process is started again', async () => {
const app = apps.balance();
wait = waitForProcess(app, 'call-internal-user-process').wait('task');

const response = await request(app)
.post('/rest/process-definition/call-internal-user-process/start')
.expect(201);

token = response.body.id;
});

Then('internal process user task is waiting', () => {
return wait;
});

When('user task is errored', () => {
const app = apps.balance();
wait = waitForProcess(app, token).end();

return request(app)
.post(`/rest/fail/${token}`)
.send({ id: 'task', message: 'foo' })
.expect(200);
});

Then('run completes', () => {
return end;
});
});

Scenario('call deployed process', () => {
Expand All @@ -62,7 +136,7 @@ Feature('call activity', () => {
<callActivity id="call-activity" calledElement="deployment:called-deployment">
<extensionElements>
<camunda:inputOutput>
<camunda:outputParameter name="from">\${content.output}</camunda:outputParameter>
<camunda:outputParameter name="from">\${content.output.message}</camunda:outputParameter>
</camunda:inputOutput>
</extensionElements>
</callActivity>
Expand Down Expand Up @@ -106,7 +180,7 @@ Feature('call activity', () => {
<userTask id="task">
<extensionElements>
<camunda:inputOutput>
<camunda:outputParameter name="user">\${content.output}</camunda:outputParameter>
<camunda:outputParameter name="user">\${content.output.message}</camunda:outputParameter>
</camunda:inputOutput>
</extensionElements>
</userTask>
Expand Down Expand Up @@ -605,7 +679,7 @@ Feature('call activity', () => {
<callActivity id="call-activity" calledElement="deployment:called-deployment">
<extensionElements>
<camunda:inputOutput>
<camunda:outputParameter name="from">\${content.output}</camunda:outputParameter>
<camunda:outputParameter name="from">\${content.output.message}</camunda:outputParameter>
</camunda:inputOutput>
</extensionElements>
</callActivity>
Expand Down Expand Up @@ -648,7 +722,7 @@ Feature('call activity', () => {
<userTask id="task">
<extensionElements>
<camunda:inputOutput>
<camunda:outputParameter name="user">\${content.output}</camunda:outputParameter>
<camunda:outputParameter name="user">\${content.output.message}</camunda:outputParameter>
</camunda:inputOutput>
</extensionElements>
</userTask>
Expand Down
183 changes: 99 additions & 84 deletions test/features/cancel-activity-feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@ Feature('cancel activity', () => {
});
after(() => apps.stop());

Given('a process with a parallel multi-instance user task', async () => {
await createDeployment(apps.balance(), 'task-to-cancel', `<definitions id="Child" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
Scenario('cancel running process activity', () => {
Given('a process with a parallel multi-instance user task', async () => {
await createDeployment(apps.balance(), 'task-to-cancel', `<definitions id="Child" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<process id="user-task" isExecutable="true">
<startEvent id="start" />
<sequenceFlow id="to-task" sourceRef="start" targetRef="task" />
<userTask id="task">
<multiInstanceLoopCharacteristics isSequential="false">
<loopCardinality>4</loopCardinality>
</multiInstanceLoopCharacteristics>
</userTask>
</process>
</definitions>`);
});
});

And('another process with a long running timer', async () => {
await createDeployment(apps.balance(), 'timer-to-cancel', `<definitions id="Child" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
And('another process with a long running timer', async () => {
await createDeployment(apps.balance(), 'timer-to-cancel', `<definitions id="Child" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<process id="user-task" isExecutable="true">
<startEvent id="start" name="Long running">
<timerEventDefinition>
Expand All @@ -31,84 +34,96 @@ Feature('cancel activity', () => {
</startEvent>
</process>
</definitions>`);
});

When('when processes are started', async () => {
await apps.request()
.post('/rest/process-definition/task-to-cancel/start')
.expect(201);

await apps.request()
.post('/rest/process-definition/task-to-cancel/start')
.expect(201);

await apps.request()
.post('/rest/process-definition/timer-to-cancel/start')
.expect(201);

await apps.request()
.post('/rest/process-definition/timer-to-cancel/start')
.expect(201);
});

let response, running;
Then('all are running', async () => {
response = await apps.request()
.get('/rest/running')
.expect(200);

expect(response.body.engines).to.have.length(4);
running = response.body.engines;
});

When('attempting to cancel user task process but with wrong id', async () => {
const bp = running.find((p) => p.name === 'task-to-cancel');
response = await apps.request()
.post(`/rest/cancel/${bp.token}`)
.send({ id: 'foo' });
});

Then('bad request is returned', () => {
expect(response.statusCode, response.text).to.equal(400);
});

let bp;
When('timer process postponed activity is fetched', async () => {
bp = running.find((p) => p.name === 'timer-to-cancel');

response = await apps.request()
.get(`/rest/status/${bp.token}/${bp.postponed[0].id}`);
});

let activity;
Then('timer execution activity is presented', () => {
expect(response.statusCode, response.text).to.equal(200);
activity = response.body;

expect(activity).to.have.property('token', bp.token);
expect(activity).to.have.property('id', 'start');
expect(activity).to.have.property('type', 'bpmn:StartEvent');
expect(activity).to.have.property('name', 'Long running');
expect(activity).to.have.property('executing').with.length(1);
});

When('attempting to cancel timer process with correct id', async () => {
response = await apps.request()
.post(`/rest/cancel/${bp.token}`)
.send(activity.executing[0]);
});

Then('ok is returned', () => {
expect(response.statusCode, response.text).to.equal(200);
});

And('only three processes are running', async () => {
expect(response.statusCode, response.text).to.equal(200);

response = await apps.request()
.get('/rest/running')
.expect(200);

expect(response.body.engines).to.have.length(3);
});

When('when processes are started', async () => {
await apps.request()
.post('/rest/process-definition/task-to-cancel/start')
.expect(201);

await apps.request()
.post('/rest/process-definition/task-to-cancel/start')
.expect(201);

await apps.request()
.post('/rest/process-definition/timer-to-cancel/start')
.expect(201);

await apps.request()
.post('/rest/process-definition/timer-to-cancel/start')
.expect(201);
});

let response, running;
Then('all are running', async () => {
response = await apps.request()
.get('/rest/running')
.expect(200);

expect(response.body.engines).to.have.length(4);
running = response.body.engines;
});

When('attempting to cancel user task process start event', async () => {
const bp = running.find((p) => p.name === 'task-to-cancel');
response = await apps.request()
.post(`/rest/cancel/${bp.token}`)
.send({ id: 'start' });
});

Then('bad request is returned since it is not running', () => {
expect(response.statusCode, response.text).to.equal(400);
});

When('attempting to cancel user task process but with wrong id', async () => {
const bp = running.find((p) => p.name === 'task-to-cancel');
response = await apps.request()
.post(`/rest/cancel/${bp.token}`)
.send({ id: 'foo' });
});

Then('bad request is returned', () => {
expect(response.statusCode, response.text).to.equal(400);
});

let bp;
When('timer process postponed activity is fetched', async () => {
bp = running.find((p) => p.name === 'timer-to-cancel');

response = await apps.request()
.get(`/rest/status/${bp.token}/${bp.postponed[0].id}`);
});

let activity;
Then('timer execution activity is presented', () => {
expect(response.statusCode, response.text).to.equal(200);
activity = response.body;

expect(activity).to.have.property('token', bp.token);
expect(activity).to.have.property('id', 'start');
expect(activity).to.have.property('type', 'bpmn:StartEvent');
expect(activity).to.have.property('name', 'Long running');
expect(activity).to.have.property('executing').with.length(1);
});

When('attempting to cancel timer process with correct id', async () => {
response = await apps.request()
.post(`/rest/cancel/${bp.token}`)
.send(activity.executing[0]);
});

Then('ok is returned', () => {
expect(response.statusCode, response.text).to.equal(200);
});

And('only three processes are running', async () => {
expect(response.statusCode, response.text).to.equal(200);

response = await apps.request()
.get('/rest/running')
.expect(200);

expect(response.body.engines).to.have.length(3);
});
});
});
Loading

0 comments on commit 2de2c1c

Please sign in to comment.