@eclipse-glsp/server 2.8.0-next.5 → 2.8.0-next.6
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.
- package/lib/common/features/directediting/context-edit-validator.js +3 -3
- package/lib/common/features/directediting/context-edit-validator.js.map +1 -1
- package/package.json +8 -8
- package/src/common/features/directediting/context-edit-validator.ts +2 -2
- package/src/browser/di/browser-action-dispatch-scope.spec.ts +0 -75
- package/src/common/actions/action-handler-registry.spec.ts +0 -52
- package/src/common/actions/global-action-provider.spec.ts +0 -68
- package/src/common/command/command-stack.spec.ts +0 -239
- package/src/common/command/command.spec.ts +0 -92
- package/src/common/command/recording-command.spec.ts +0 -86
- package/src/common/di/binding-target.spec.ts +0 -147
- package/src/common/di/multi-bindings.spec.ts +0 -133
- package/src/common/features/contextactions/context-actions-provider-registry.spec.ts +0 -69
- package/src/common/features/contextactions/request-context-actions-handler.spec.ts +0 -75
- package/src/common/features/contextactions/tool-palette-item-provider.spec.ts +0 -46
- package/src/common/features/directediting/context-edit-validator-registry.spec.ts +0 -54
- package/src/common/features/directediting/request-edit-validation-handler.spec.ts +0 -131
- package/src/common/features/model/gmodel-serializer.spec.ts +0 -141
- package/src/common/features/type-hints/request-type-hints-action-handler.spec.ts +0 -59
- package/src/common/operations/operation-handler-registry.spec.ts +0 -50
- package/src/common/protocol/glsp-server.spec.ts +0 -154
- package/src/common/session/client-session-factory.spec.ts +0 -60
- package/src/common/session/client-session-manager.spec.ts +0 -83
- package/src/common/test/mock-util.ts +0 -281
- package/src/common/utils/action-queue.spec.ts +0 -133
- package/src/common/utils/promise-queue.spec.ts +0 -142
- package/src/common/utils/registry.spec.ts +0 -225
- package/src/node/actions/action-dispatcher.spec.ts +0 -678
- package/src/node/launch/cli-parser.spec.ts +0 -61
- package/src/node/launch/socket-cli-parser.spec.ts +0 -73
- package/src/node/launch/socket-server-launcher.spec.ts +0 -74
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2022-2023 STMicroelectronics and others.
|
|
3
|
-
*
|
|
4
|
-
* This program and the accompanying materials are made available under the
|
|
5
|
-
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
*
|
|
8
|
-
* This Source Code may also be made available under the following Secondary
|
|
9
|
-
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
* with the GNU Classpath Exception which is available at
|
|
12
|
-
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
*
|
|
14
|
-
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
********************************************************************************/
|
|
16
|
-
import { GNode } from '@eclipse-glsp/graph';
|
|
17
|
-
import { RequestEditValidationAction, SetEditValidationResultAction, ValidationStatus } from '@eclipse-glsp/protocol';
|
|
18
|
-
import { expect } from 'chai';
|
|
19
|
-
import * as sinon from 'sinon';
|
|
20
|
-
import { TestContextEditValidator, TestLabelEditValidator } from '../../test/mock-util';
|
|
21
|
-
import { GModelIndex } from '../model/gmodel-index';
|
|
22
|
-
import { DefaultModelState } from '../model/model-state';
|
|
23
|
-
import { ContextEditValidator } from './context-edit-validator';
|
|
24
|
-
import { DefaultContextEditValidatorRegistry } from './context-edit-validator-registry';
|
|
25
|
-
import { LabelEditValidator } from './label-edit-validator';
|
|
26
|
-
import { RequestEditValidationHandler } from './request-edit-validation-handler';
|
|
27
|
-
|
|
28
|
-
describe('Test RequestEditValidationHandler', () => {
|
|
29
|
-
const contextEditValidators: ContextEditValidator[] = [new TestContextEditValidator()];
|
|
30
|
-
const modelState = new DefaultModelState();
|
|
31
|
-
Object.defineProperty(modelState, 'index', { value: new GModelIndex() });
|
|
32
|
-
sinon.stub(modelState.index, 'get').callsFake(() => new GNode());
|
|
33
|
-
const contextEditValidatorsRegistry = new DefaultContextEditValidatorRegistry(
|
|
34
|
-
modelState,
|
|
35
|
-
contextEditValidators,
|
|
36
|
-
new TestLabelEditValidator()
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
const requestEditValidationHandler = new RequestEditValidationHandler();
|
|
40
|
-
requestEditValidationHandler['contextEditValidatorRegistry'] = contextEditValidatorsRegistry;
|
|
41
|
-
|
|
42
|
-
it('requestContextEditValidation with ok result', async () => {
|
|
43
|
-
const actions = await requestEditValidationHandler.execute(
|
|
44
|
-
RequestEditValidationAction.create({ contextId: 'test', modelElementId: '', text: 'ok' })
|
|
45
|
-
);
|
|
46
|
-
expect(actions).to.have.length(1);
|
|
47
|
-
const action = actions[0];
|
|
48
|
-
|
|
49
|
-
expect(SetEditValidationResultAction.is(action)).to.be.true;
|
|
50
|
-
const setEditValidationResultAction = action as SetEditValidationResultAction;
|
|
51
|
-
const status = setEditValidationResultAction.status;
|
|
52
|
-
|
|
53
|
-
expect(status.severity).to.be.equal(ValidationStatus.Severity.OK);
|
|
54
|
-
expect(status.message).to.be.equal('ok');
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('requestContextEditValidation with warning result', async () => {
|
|
58
|
-
const actions = await requestEditValidationHandler.execute(
|
|
59
|
-
RequestEditValidationAction.create({ contextId: 'test', modelElementId: '', text: 'warning' })
|
|
60
|
-
);
|
|
61
|
-
expect(actions).to.have.length(1);
|
|
62
|
-
const action = actions[0];
|
|
63
|
-
|
|
64
|
-
expect(SetEditValidationResultAction.is(action)).to.be.true;
|
|
65
|
-
const setEditValidationResultAction = action as SetEditValidationResultAction;
|
|
66
|
-
const status = setEditValidationResultAction.status;
|
|
67
|
-
|
|
68
|
-
expect(status.severity).to.be.equal(ValidationStatus.Severity.WARNING);
|
|
69
|
-
expect(status.message).to.be.equal('warning');
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('requestContextEditValidation with error result', async () => {
|
|
73
|
-
const actions = await requestEditValidationHandler.execute(
|
|
74
|
-
RequestEditValidationAction.create({ contextId: 'test', modelElementId: '', text: 'error' })
|
|
75
|
-
);
|
|
76
|
-
expect(actions).to.have.length(1);
|
|
77
|
-
const action = actions[0];
|
|
78
|
-
|
|
79
|
-
expect(SetEditValidationResultAction.is(action)).to.be.true;
|
|
80
|
-
const setEditValidationResultAction = action as SetEditValidationResultAction;
|
|
81
|
-
const status = setEditValidationResultAction.status;
|
|
82
|
-
|
|
83
|
-
expect(status.severity).to.be.equal(ValidationStatus.Severity.ERROR);
|
|
84
|
-
expect(status.message).to.be.equal('error');
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('requestLabelEditValidation with ok result', async () => {
|
|
88
|
-
const actions = await requestEditValidationHandler.execute(
|
|
89
|
-
RequestEditValidationAction.create({ contextId: LabelEditValidator.CONTEXT_ID, modelElementId: '', text: 'ok' })
|
|
90
|
-
);
|
|
91
|
-
expect(actions).to.have.length(1);
|
|
92
|
-
const action = actions[0];
|
|
93
|
-
|
|
94
|
-
expect(SetEditValidationResultAction.is(action)).to.be.true;
|
|
95
|
-
const setEditValidationResultAction = action as SetEditValidationResultAction;
|
|
96
|
-
const status = setEditValidationResultAction.status;
|
|
97
|
-
|
|
98
|
-
expect(status.severity).to.be.equal(ValidationStatus.Severity.OK);
|
|
99
|
-
expect(status.message).to.be.equal('ok');
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('requestLabelEditValidation with warning result', async () => {
|
|
103
|
-
const actions = await requestEditValidationHandler.execute(
|
|
104
|
-
RequestEditValidationAction.create({ contextId: LabelEditValidator.CONTEXT_ID, modelElementId: '', text: 'warning' })
|
|
105
|
-
);
|
|
106
|
-
expect(actions).to.have.length(1);
|
|
107
|
-
const action = actions[0];
|
|
108
|
-
|
|
109
|
-
expect(SetEditValidationResultAction.is(action)).to.be.true;
|
|
110
|
-
const setEditValidationResultAction = action as SetEditValidationResultAction;
|
|
111
|
-
const status = setEditValidationResultAction.status;
|
|
112
|
-
|
|
113
|
-
expect(status.severity).to.be.equal(ValidationStatus.Severity.WARNING);
|
|
114
|
-
expect(status.message).to.be.equal('warning');
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('requestLabelEditValidation with error result', async () => {
|
|
118
|
-
const actions = await requestEditValidationHandler.execute(
|
|
119
|
-
RequestEditValidationAction.create({ contextId: LabelEditValidator.CONTEXT_ID, modelElementId: '', text: 'error' })
|
|
120
|
-
);
|
|
121
|
-
expect(actions).to.have.length(1);
|
|
122
|
-
const action = actions[0];
|
|
123
|
-
|
|
124
|
-
expect(SetEditValidationResultAction.is(action)).to.be.true;
|
|
125
|
-
const setEditValidationResultAction = action as SetEditValidationResultAction;
|
|
126
|
-
const status = setEditValidationResultAction.status;
|
|
127
|
-
|
|
128
|
-
expect(status.severity).to.be.equal(ValidationStatus.Severity.ERROR);
|
|
129
|
-
expect(status.message).to.be.equal('error');
|
|
130
|
-
});
|
|
131
|
-
});
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2022-2023 STMicroelectronics and others.
|
|
3
|
-
*
|
|
4
|
-
* This program and the accompanying materials are made available under the
|
|
5
|
-
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
*
|
|
8
|
-
* This Source Code may also be made available under the following Secondary
|
|
9
|
-
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
* with the GNU Classpath Exception which is available at
|
|
12
|
-
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
*
|
|
14
|
-
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
********************************************************************************/
|
|
16
|
-
import { GEdge, getDefaultMapping, GGraph, GNode } from '@eclipse-glsp/graph';
|
|
17
|
-
import { expect } from 'chai';
|
|
18
|
-
import { Container, ContainerModule } from 'inversify';
|
|
19
|
-
import { DiagramConfiguration } from '../../diagram/diagram-configuration';
|
|
20
|
-
import * as mock from '../../test/mock-util';
|
|
21
|
-
import { GLSPServerError } from '../../utils/glsp-server-error';
|
|
22
|
-
import { Logger } from '../../utils/logger';
|
|
23
|
-
import { DefaultGModelSerializer } from './gmodel-serializer';
|
|
24
|
-
|
|
25
|
-
class TestNode extends GNode {
|
|
26
|
-
foo(): void {
|
|
27
|
-
// should not be serialized to schema
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
let testRootSchema: any;
|
|
32
|
-
|
|
33
|
-
let testNodeSchema: any;
|
|
34
|
-
|
|
35
|
-
let testNodeSchemaWithParent: any;
|
|
36
|
-
|
|
37
|
-
describe('test DefaultGModelSerializer', () => {
|
|
38
|
-
const container = new Container();
|
|
39
|
-
const diagramConfiguration = new mock.StubDiagramConfiguration();
|
|
40
|
-
diagramConfiguration['typeMapping'] = getDefaultMapping();
|
|
41
|
-
diagramConfiguration.typeMapping.set('node', TestNode);
|
|
42
|
-
|
|
43
|
-
container.load(
|
|
44
|
-
new ContainerModule(bind => {
|
|
45
|
-
bind(Logger).toConstantValue(new mock.StubLogger());
|
|
46
|
-
bind(DiagramConfiguration).toConstantValue(diagramConfiguration);
|
|
47
|
-
})
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
const serializer = container.resolve(DefaultGModelSerializer);
|
|
51
|
-
|
|
52
|
-
beforeEach(() => {
|
|
53
|
-
testRootSchema = {
|
|
54
|
-
id: 'graph',
|
|
55
|
-
type: 'graph',
|
|
56
|
-
children: [
|
|
57
|
-
{ id: 'node1', type: 'node', position: { x: 5, y: 10 } },
|
|
58
|
-
{ id: 'node2', type: 'node', position: { x: 15, y: 5 } },
|
|
59
|
-
{ id: 'edge1', type: 'edge', sourceId: 'node1', targetId: 'node2' }
|
|
60
|
-
]
|
|
61
|
-
};
|
|
62
|
-
testNodeSchema = { id: 'node1', type: 'node', position: { x: 5, y: 10 }, children: [], cssClasses: [] };
|
|
63
|
-
testNodeSchemaWithParent = {
|
|
64
|
-
id: 'node1',
|
|
65
|
-
type: 'node',
|
|
66
|
-
position: { x: 5, y: 10 },
|
|
67
|
-
children: [],
|
|
68
|
-
cssClasses: [],
|
|
69
|
-
parent: new GNode()
|
|
70
|
-
};
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('createElement - unregistered type', () => {
|
|
74
|
-
testNodeSchema['type'] = 'notRegistered';
|
|
75
|
-
expect(() => serializer.createElement(testNodeSchema)).to.throw(GLSPServerError);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('createElement - with root schema', () => {
|
|
79
|
-
expect(() => serializer.createElement(testRootSchema)).to.throw(GLSPServerError);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('createElement - with node schema', () => {
|
|
83
|
-
const node = serializer.createElement(testNodeSchema);
|
|
84
|
-
expect(node).to.be.an.instanceOf(TestNode);
|
|
85
|
-
expect(node).to.be.deep.include(testNodeSchema);
|
|
86
|
-
expect((node as TestNode).foo).to.not.be.undefined;
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('createElement- with sub type of registered schema', () => {
|
|
90
|
-
testNodeSchema.type = 'node:rectangular';
|
|
91
|
-
const node = serializer.createElement(testNodeSchema);
|
|
92
|
-
expect(node).to.be.an.instanceOf(TestNode);
|
|
93
|
-
expect(node).to.be.deep.include(testNodeSchema);
|
|
94
|
-
expect((node as TestNode).foo).to.not.be.undefined;
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('createElement - with parent', () => {
|
|
98
|
-
const parent = new GNode();
|
|
99
|
-
const child = serializer.createElement(testNodeSchema, parent);
|
|
100
|
-
expect(child).to.be.an.instanceOf(TestNode);
|
|
101
|
-
expect(child).to.be.deep.include(testNodeSchemaWithParent);
|
|
102
|
-
expect(child.parent).to.be.equal(parent);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('createRoot - unregistered type', () => {
|
|
106
|
-
testRootSchema['type'] = 'notRegistered';
|
|
107
|
-
expect(() => serializer.createRoot(testNodeSchema)).to.throw(GLSPServerError);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('createRoot - with child schema ', () => {
|
|
111
|
-
expect(() => serializer.createRoot(testNodeSchema)).to.throw(GLSPServerError);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('createRoot - with registered root schema', () => {
|
|
115
|
-
const root = serializer.createRoot(testRootSchema);
|
|
116
|
-
expect(root).to.be.an.instanceOf(GGraph);
|
|
117
|
-
expect(root.children.length).to.be.equal(3);
|
|
118
|
-
const node1 = root.children[0];
|
|
119
|
-
expect(node1).to.be.an.instanceOf(TestNode);
|
|
120
|
-
const node2 = root.children[1];
|
|
121
|
-
expect(node2).to.be.an.instanceOf(TestNode);
|
|
122
|
-
expect(root.children[2]).to.be.an.instanceOf(GEdge);
|
|
123
|
-
const edge = root.children[2] as GEdge;
|
|
124
|
-
expect(edge.sourceId).to.be.equal(node1.id);
|
|
125
|
-
expect(edge.targetId).to.be.equal(node2.id);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('createSchema- unregistered type', () => {
|
|
129
|
-
expect(() => serializer.createRoot({ id: 'id', type: 'unregistered' })).to.throw(GLSPServerError);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('createSchema- with node', () => {
|
|
133
|
-
const testNode = new TestNode();
|
|
134
|
-
testNode.position = { x: 5, y: 10 };
|
|
135
|
-
testNode.size = { width: 10, height: 100 };
|
|
136
|
-
testNode.layoutOptions = { ['my']: 'Options' };
|
|
137
|
-
const schema = serializer.createSchema(testNode);
|
|
138
|
-
delete (testNode as Partial<TestNode>).foo;
|
|
139
|
-
expect(schema).to.be.deep.include(testNode);
|
|
140
|
-
});
|
|
141
|
-
});
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2022-2023 STMicroelectronics and others.
|
|
3
|
-
*
|
|
4
|
-
* This program and the accompanying materials are made available under the
|
|
5
|
-
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
*
|
|
8
|
-
* This Source Code may also be made available under the following Secondary
|
|
9
|
-
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
* with the GNU Classpath Exception which is available at
|
|
12
|
-
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
*
|
|
14
|
-
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
********************************************************************************/
|
|
16
|
-
import { EdgeTypeHint, RequestTypeHintsAction, SetTypeHintsAction, ShapeTypeHint } from '@eclipse-glsp/protocol';
|
|
17
|
-
import { expect } from 'chai';
|
|
18
|
-
import { Container, ContainerModule } from 'inversify';
|
|
19
|
-
import { DiagramConfiguration } from '../../diagram/diagram-configuration';
|
|
20
|
-
import * as mock from '../../test/mock-util';
|
|
21
|
-
import { RequestTypeHintsActionHandler } from './request-type-hints-action-handler';
|
|
22
|
-
|
|
23
|
-
describe('test RequestTypeHintsActionHandler', () => {
|
|
24
|
-
const container = new Container();
|
|
25
|
-
const diagramConfiguration = new mock.StubDiagramConfiguration();
|
|
26
|
-
const shapeTypeHint: ShapeTypeHint = {
|
|
27
|
-
elementTypeId: 'test',
|
|
28
|
-
deletable: true,
|
|
29
|
-
resizable: true,
|
|
30
|
-
repositionable: true,
|
|
31
|
-
reparentable: true
|
|
32
|
-
};
|
|
33
|
-
const edgeTypeHint: EdgeTypeHint = {
|
|
34
|
-
elementTypeId: 'test',
|
|
35
|
-
deletable: true,
|
|
36
|
-
repositionable: true,
|
|
37
|
-
routable: true,
|
|
38
|
-
sourceElementTypeIds: [],
|
|
39
|
-
targetElementTypeIds: []
|
|
40
|
-
};
|
|
41
|
-
diagramConfiguration.shapeTypeHints = [shapeTypeHint];
|
|
42
|
-
diagramConfiguration.edgeTypeHints = [edgeTypeHint];
|
|
43
|
-
container.load(
|
|
44
|
-
new ContainerModule(bind => {
|
|
45
|
-
bind(DiagramConfiguration).toConstantValue(diagramConfiguration);
|
|
46
|
-
})
|
|
47
|
-
);
|
|
48
|
-
const handler = container.resolve(RequestTypeHintsActionHandler);
|
|
49
|
-
|
|
50
|
-
it('execute with correct action', async () => {
|
|
51
|
-
const result = await handler.execute(RequestTypeHintsAction.create());
|
|
52
|
-
|
|
53
|
-
expect(result).to.have.length(1);
|
|
54
|
-
expect(SetTypeHintsAction.is(result[0])).true;
|
|
55
|
-
expect(result).to.be.deep.equal([
|
|
56
|
-
{ edgeHints: [edgeTypeHint], kind: 'setTypeHints', shapeHints: [shapeTypeHint], responseId: '' } as SetTypeHintsAction
|
|
57
|
-
]);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2022-2023 STMicroelectronics and others.
|
|
3
|
-
*
|
|
4
|
-
* This program and the accompanying materials are made available under the
|
|
5
|
-
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
*
|
|
8
|
-
* This Source Code may also be made available under the following Secondary
|
|
9
|
-
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
* with the GNU Classpath Exception which is available at
|
|
12
|
-
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
*
|
|
14
|
-
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
********************************************************************************/
|
|
16
|
-
import { CompoundOperation, CreateEdgeOperation, CreateNodeOperation } from '@eclipse-glsp/protocol';
|
|
17
|
-
import { expect } from 'chai';
|
|
18
|
-
import * as mock from '../test/mock-util';
|
|
19
|
-
import { CompoundOperationHandler } from './compound-operation-handler';
|
|
20
|
-
import { OperationHandlerRegistry } from './operation-handler-registry';
|
|
21
|
-
|
|
22
|
-
describe('Test OperationHandlerRegistry', () => {
|
|
23
|
-
const stubANode = new mock.StubCreateNodeOperationHandler('ANode');
|
|
24
|
-
const stubBNode = new mock.StubCreateNodeOperationHandler('BNode');
|
|
25
|
-
const stubAEdge = new mock.StubCreateEdgeOperationHandler('AEdge');
|
|
26
|
-
const stubBEdge = new mock.StubCreateEdgeOperationHandler('BEdge');
|
|
27
|
-
const operationHandlerRegistry = new OperationHandlerRegistry();
|
|
28
|
-
|
|
29
|
-
it('register OperationActionHandler', () => {
|
|
30
|
-
operationHandlerRegistry.registerHandler(new CompoundOperationHandler());
|
|
31
|
-
expect(operationHandlerRegistry.keys()).to.have.length(1);
|
|
32
|
-
expect(operationHandlerRegistry.keys()).to.contain(CompoundOperation.KIND);
|
|
33
|
-
expect(operationHandlerRegistry.get(CompoundOperation.KIND)).to.be.an.instanceOf(CompoundOperationHandler);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('register CreateOperationActionHandlers', () => {
|
|
37
|
-
operationHandlerRegistry.registerHandler(stubANode);
|
|
38
|
-
operationHandlerRegistry.registerHandler(stubBNode);
|
|
39
|
-
operationHandlerRegistry.registerHandler(stubAEdge);
|
|
40
|
-
operationHandlerRegistry.registerHandler(stubBEdge);
|
|
41
|
-
expect(operationHandlerRegistry.keys()).to.contain(`${CreateNodeOperation.KIND}_ANode`);
|
|
42
|
-
expect(operationHandlerRegistry.get(`${CreateNodeOperation.KIND}_ANode`)).to.be.equal(stubANode);
|
|
43
|
-
expect(operationHandlerRegistry.keys()).to.contain(`${CreateNodeOperation.KIND}_BNode`);
|
|
44
|
-
expect(operationHandlerRegistry.get(`${CreateNodeOperation.KIND}_BNode`)).to.be.equal(stubBNode);
|
|
45
|
-
expect(operationHandlerRegistry.keys()).to.contain(`${CreateEdgeOperation.KIND}_AEdge`);
|
|
46
|
-
expect(operationHandlerRegistry.get(`${CreateEdgeOperation.KIND}_AEdge`)).to.be.equal(stubAEdge);
|
|
47
|
-
expect(operationHandlerRegistry.keys()).to.contain(`${CreateEdgeOperation.KIND}_BEdge`);
|
|
48
|
-
expect(operationHandlerRegistry.get(`${CreateEdgeOperation.KIND}_BEdge`)).to.be.equal(stubBEdge);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2022-2023 STMicroelectronics and others.
|
|
3
|
-
*
|
|
4
|
-
* This program and the accompanying materials are made available under the
|
|
5
|
-
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
*
|
|
8
|
-
* This Source Code may also be made available under the following Secondary
|
|
9
|
-
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
* with the GNU Classpath Exception which is available at
|
|
12
|
-
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
*
|
|
14
|
-
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
********************************************************************************/
|
|
16
|
-
import {
|
|
17
|
-
DisposeClientSessionParameters,
|
|
18
|
-
GLSPClientProxy,
|
|
19
|
-
GLSPServerListener,
|
|
20
|
-
InitializeClientSessionParameters,
|
|
21
|
-
InitializeParameters
|
|
22
|
-
} from '@eclipse-glsp/protocol';
|
|
23
|
-
import * as assert from 'assert';
|
|
24
|
-
import { expect } from 'chai';
|
|
25
|
-
import { Container, ContainerModule } from 'inversify';
|
|
26
|
-
import * as sinon from 'sinon';
|
|
27
|
-
import { GlobalActionProvider } from '../actions/global-action-provider';
|
|
28
|
-
import { ClientSessionManager } from '../session/client-session-manager';
|
|
29
|
-
import * as mock from '../test/mock-util';
|
|
30
|
-
import { Logger } from '../utils/logger';
|
|
31
|
-
import { DefaultGLSPServer } from './glsp-server';
|
|
32
|
-
|
|
33
|
-
describe('test DefaultGLSPServer', () => {
|
|
34
|
-
const container = new Container();
|
|
35
|
-
const clientSessionId = 'myClientSession';
|
|
36
|
-
const diagramType = 'myDiagram';
|
|
37
|
-
const applicationId = 'Test';
|
|
38
|
-
const protocolVersion = '1.0.0';
|
|
39
|
-
const actionKinds = new Map<string, string[]>();
|
|
40
|
-
actionKinds.set(diagramType, ['A1', 'A2']);
|
|
41
|
-
const sessionManager = new mock.StubClientSessionManager();
|
|
42
|
-
const spy_sessionManager_getOrCreate = sinon.spy(sessionManager, 'getOrCreateClientSession');
|
|
43
|
-
const spy_sessionManager_dispose = sinon.spy(sessionManager, 'disposeClientSession');
|
|
44
|
-
const listener1 = new mock.StubGLSPServerListener();
|
|
45
|
-
const spy_listener1_initialize = sinon.spy(listener1, 'serverInitialized');
|
|
46
|
-
const spy_listener1_shutdown = sinon.spy(listener1, 'serverShutDown');
|
|
47
|
-
const listener2 = new mock.StubGLSPServerListener();
|
|
48
|
-
const spy_listener2_initialize = sinon.spy(listener2, 'serverInitialized');
|
|
49
|
-
const spy_listener2_shutdown = sinon.spy(listener2, 'serverShutDown');
|
|
50
|
-
|
|
51
|
-
container.load(
|
|
52
|
-
new ContainerModule(bind => {
|
|
53
|
-
bind(Logger).toConstantValue(new mock.StubLogger());
|
|
54
|
-
bind(GLSPClientProxy).toConstantValue(new mock.StubGLSPClientProxy());
|
|
55
|
-
bind(ClientSessionManager).toConstantValue(sessionManager);
|
|
56
|
-
bind(GlobalActionProvider).toConstantValue(<GlobalActionProvider>{ actionKinds });
|
|
57
|
-
bind(GLSPServerListener).toConstantValue(listener1);
|
|
58
|
-
})
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
const glspServer = container.resolve(DefaultGLSPServer);
|
|
62
|
-
|
|
63
|
-
beforeEach(() => {
|
|
64
|
-
spy_sessionManager_getOrCreate.restore();
|
|
65
|
-
spy_sessionManager_dispose.restore();
|
|
66
|
-
spy_listener1_initialize.restore();
|
|
67
|
-
spy_listener1_shutdown.restore();
|
|
68
|
-
spy_listener2_initialize.restore();
|
|
69
|
-
spy_listener2_shutdown.restore();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('Test calls before server initialization (should throw errors)', async () => {
|
|
73
|
-
assert.rejects(() => glspServer.initializeClientSession({ clientSessionId: 'id', diagramType: 'type', clientActionKinds: [] }));
|
|
74
|
-
assert.rejects(() => glspServer.disposeClientSession({ clientSessionId: 'id' }));
|
|
75
|
-
assert.throws(() => glspServer.process({ clientId: 'id', action: { kind: 'action' } }));
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('addListener - add existing listener', () => {
|
|
79
|
-
const originalSize = glspServer['serverListeners'].length;
|
|
80
|
-
glspServer.addListener(listener1);
|
|
81
|
-
expect(glspServer['serverListeners'].length).to.be.equal(originalSize);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('addListener - add new listener', () => {
|
|
85
|
-
const originalSize = glspServer['serverListeners'].length;
|
|
86
|
-
glspServer.addListener(listener2);
|
|
87
|
-
expect(glspServer['serverListeners']).to.include(listener2);
|
|
88
|
-
expect(glspServer['serverListeners'].length).to.be.equal(originalSize + 1);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('removeListener - remove non-existing listener', () => {
|
|
92
|
-
const originalSize = glspServer['serverListeners'].length;
|
|
93
|
-
glspServer.removeListener({});
|
|
94
|
-
expect(glspServer['serverListeners'].length).to.be.equal(originalSize);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('removeListener - remove existing listener', () => {
|
|
98
|
-
const originalSize = glspServer['serverListeners'].length;
|
|
99
|
-
glspServer.removeListener(listener2);
|
|
100
|
-
expect(glspServer['serverListeners'].length).to.be.equal(originalSize - 1);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('initialize - with wrong protocol version', async () => {
|
|
104
|
-
const initializeParameters: InitializeParameters = { applicationId, protocolVersion: 'abc' };
|
|
105
|
-
assert.rejects(glspServer.initialize(initializeParameters));
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('initialize - with correct parameters', async () => {
|
|
109
|
-
const initializeParameters: InitializeParameters = { applicationId, protocolVersion };
|
|
110
|
-
const result = await glspServer.initialize(initializeParameters);
|
|
111
|
-
expect(result.protocolVersion).to.be.equal(protocolVersion);
|
|
112
|
-
expect(result.serverActions[diagramType]).to.be.equal(actionKinds.get(diagramType));
|
|
113
|
-
expect(result.serverActions[diagramType]).to.be.equal(actionKinds.get(diagramType));
|
|
114
|
-
expect(spy_listener1_initialize.calledWith(glspServer));
|
|
115
|
-
expect(spy_listener2_initialize.notCalled);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('initialize - subsequent call with same parameters', async () => {
|
|
119
|
-
const initializeParameters: InitializeParameters = { applicationId, protocolVersion };
|
|
120
|
-
const result = await glspServer.initialize(initializeParameters);
|
|
121
|
-
expect(result.protocolVersion).to.be.equal(protocolVersion);
|
|
122
|
-
expect(result.serverActions[diagramType]).to.be.equal(actionKinds.get(diagramType));
|
|
123
|
-
expect(result.serverActions[diagramType]).to.be.equal(actionKinds.get(diagramType));
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('initialize - subsequent call with other parameters', async () => {
|
|
127
|
-
const initializeParameters = { applicationId: 'someOtherApp', protocolVersion: 'AnotherProtocolVersion' };
|
|
128
|
-
await assert.rejects(() => glspServer.initialize(initializeParameters));
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('initialize client session', async () => {
|
|
132
|
-
const initializeClientSessionParameters: InitializeClientSessionParameters = {
|
|
133
|
-
clientSessionId,
|
|
134
|
-
diagramType,
|
|
135
|
-
clientActionKinds: []
|
|
136
|
-
};
|
|
137
|
-
await glspServer.initializeClientSession(initializeClientSessionParameters);
|
|
138
|
-
expect(spy_sessionManager_getOrCreate.calledWith(initializeClientSessionParameters));
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('dispose client session', async () => {
|
|
142
|
-
const disposeClientSessionParameters: DisposeClientSessionParameters = {
|
|
143
|
-
clientSessionId
|
|
144
|
-
};
|
|
145
|
-
await glspServer.disposeClientSession(disposeClientSessionParameters);
|
|
146
|
-
expect(spy_sessionManager_dispose.calledWith(clientSessionId));
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('shutdown server', async () => {
|
|
150
|
-
glspServer.shutdown();
|
|
151
|
-
expect(spy_listener1_shutdown.calledWith(glspServer));
|
|
152
|
-
expect(spy_listener2_shutdown.notCalled);
|
|
153
|
-
});
|
|
154
|
-
});
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2022-2023 STMicroelectronics and others.
|
|
3
|
-
*
|
|
4
|
-
* This program and the accompanying materials are made available under the
|
|
5
|
-
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
*
|
|
8
|
-
* This Source Code may also be made available under the following Secondary
|
|
9
|
-
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
* with the GNU Classpath Exception which is available at
|
|
12
|
-
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
*
|
|
14
|
-
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
********************************************************************************/
|
|
16
|
-
import { GLSPClientProxy } from '@eclipse-glsp/protocol';
|
|
17
|
-
import { expect } from 'chai';
|
|
18
|
-
import { Container, ContainerModule } from 'inversify';
|
|
19
|
-
import { ActionDispatcher } from '../actions/action-dispatcher';
|
|
20
|
-
import { DiagramModules, InjectionContainer } from '../di/service-identifiers';
|
|
21
|
-
import * as mock from '../test/mock-util';
|
|
22
|
-
import { GLSPServerError } from '../utils/glsp-server-error';
|
|
23
|
-
import { Logger } from '../utils/logger';
|
|
24
|
-
import { DefaultClientSessionFactory } from './client-session-factory';
|
|
25
|
-
import { ClientSessionInitializer } from './client-session-initializer';
|
|
26
|
-
|
|
27
|
-
describe('test DefaultClientSessionFactory', () => {
|
|
28
|
-
const clientSessionId = 'myClientId';
|
|
29
|
-
const diagramType = 'myDiagramType';
|
|
30
|
-
const container = new Container();
|
|
31
|
-
const diagramModule = new ContainerModule(bind => {
|
|
32
|
-
bind(ActionDispatcher).toConstantValue(new mock.StubActionDispatcher());
|
|
33
|
-
bind(ClientSessionInitializer).toConstantValue(new mock.StubClientSessionInitializer());
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const diagramModules = new Map<string, ContainerModule[]>();
|
|
37
|
-
diagramModules.set(diagramType, [diagramModule]);
|
|
38
|
-
|
|
39
|
-
container.load(
|
|
40
|
-
new ContainerModule(bind => {
|
|
41
|
-
bind(Logger).toConstantValue(new mock.StubLogger());
|
|
42
|
-
bind(InjectionContainer).toConstantValue(container);
|
|
43
|
-
bind(DiagramModules).toConstantValue(diagramModules);
|
|
44
|
-
bind(GLSPClientProxy).toConstantValue(new mock.StubGLSPClientProxy());
|
|
45
|
-
})
|
|
46
|
-
);
|
|
47
|
-
const factory = container.resolve(DefaultClientSessionFactory);
|
|
48
|
-
|
|
49
|
-
it('create - new client session', () => {
|
|
50
|
-
const session = factory.create({ clientSessionId, diagramType, clientActionKinds: [] });
|
|
51
|
-
expect(session.id).to.be.equal(clientSessionId);
|
|
52
|
-
expect(session.diagramType).to.be.equal(diagramType);
|
|
53
|
-
expect(session.container.parent).to.be.equal(container);
|
|
54
|
-
expect(session.actionDispatcher).to.be.an.instanceOf(mock.StubActionDispatcher);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('create - unknown diagram type', () => {
|
|
58
|
-
expect(() => factory.create({ clientSessionId, diagramType: 'unknown-type', clientActionKinds: [] })).to.throw(GLSPServerError);
|
|
59
|
-
});
|
|
60
|
-
});
|