@eclipse-glsp/server 2.8.0-next.1 → 2.8.0-next.12

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.
Files changed (132) hide show
  1. package/lib/browser/launch/worker-server-launcher.js +3 -5
  2. package/lib/browser/launch/worker-server-launcher.js.map +1 -1
  3. package/lib/common/actions/action-dispatcher.js +5 -8
  4. package/lib/common/actions/action-dispatcher.js.map +1 -1
  5. package/lib/common/actions/action-handler-registry.js +1 -1
  6. package/lib/common/actions/action-handler-registry.js.map +1 -1
  7. package/lib/common/actions/global-action-provider.js +1 -2
  8. package/lib/common/actions/global-action-provider.js.map +1 -1
  9. package/lib/common/command/command.js +1 -2
  10. package/lib/common/command/command.js.map +1 -1
  11. package/lib/common/command/recording-command.js +3 -6
  12. package/lib/common/command/recording-command.js.map +1 -1
  13. package/lib/common/di/diagram-module.js +5 -6
  14. package/lib/common/di/diagram-module.js.map +1 -1
  15. package/lib/common/di/glsp-module.js +1 -1
  16. package/lib/common/di/glsp-module.js.map +1 -1
  17. package/lib/common/di/server-module.js +1 -1
  18. package/lib/common/di/server-module.js.map +1 -1
  19. package/lib/common/features/directediting/context-edit-validator.js +3 -3
  20. package/lib/common/features/directediting/context-edit-validator.js.map +1 -1
  21. package/lib/common/features/directediting/label-edit-validator.js +1 -1
  22. package/lib/common/features/directediting/label-edit-validator.js.map +1 -1
  23. package/lib/common/features/layout/computed-bounds-action-handler.d.ts +16 -1
  24. package/lib/common/features/layout/computed-bounds-action-handler.d.ts.map +1 -1
  25. package/lib/common/features/layout/computed-bounds-action-handler.js +41 -4
  26. package/lib/common/features/layout/computed-bounds-action-handler.js.map +1 -1
  27. package/lib/common/features/layout/layout-operation-handler.js +1 -2
  28. package/lib/common/features/layout/layout-operation-handler.js.map +1 -1
  29. package/lib/common/features/model/gmodel-index.js +3 -5
  30. package/lib/common/features/model/gmodel-index.js.map +1 -1
  31. package/lib/common/features/model/gmodel-serializer.js +1 -2
  32. package/lib/common/features/model/gmodel-serializer.js.map +1 -1
  33. package/lib/common/features/model/model-submission-handler.d.ts +1 -2
  34. package/lib/common/features/model/model-submission-handler.d.ts.map +1 -1
  35. package/lib/common/features/model/model-submission-handler.js +3 -6
  36. package/lib/common/features/model/model-submission-handler.js.map +1 -1
  37. package/lib/common/features/model/request-model-action-handler.js +4 -6
  38. package/lib/common/features/model/request-model-action-handler.js.map +1 -1
  39. package/lib/common/features/navigation/navigation-target-resolution.js +1 -1
  40. package/lib/common/features/navigation/navigation-target-resolution.js.map +1 -1
  41. package/lib/common/features/progress/progress-service.d.ts.map +1 -1
  42. package/lib/common/features/progress/progress-service.js +1 -2
  43. package/lib/common/features/progress/progress-service.js.map +1 -1
  44. package/lib/common/features/validation/request-markers-handler.js +1 -2
  45. package/lib/common/features/validation/request-markers-handler.js.map +1 -1
  46. package/lib/common/gmodel/change-routing-points-operation-handler.js +1 -2
  47. package/lib/common/gmodel/change-routing-points-operation-handler.js.map +1 -1
  48. package/lib/common/gmodel/gmodel-create-node-operation-handler.js +3 -5
  49. package/lib/common/gmodel/gmodel-create-node-operation-handler.js.map +1 -1
  50. package/lib/common/gmodel/paste-operation-handler.d.ts +1 -1
  51. package/lib/common/gmodel/paste-operation-handler.d.ts.map +1 -1
  52. package/lib/common/gmodel/paste-operation-handler.js +8 -11
  53. package/lib/common/gmodel/paste-operation-handler.js.map +1 -1
  54. package/lib/common/launch/glsp-server-launcher.d.ts +8 -1
  55. package/lib/common/launch/glsp-server-launcher.d.ts.map +1 -1
  56. package/lib/common/launch/glsp-server-launcher.js +11 -1
  57. package/lib/common/launch/glsp-server-launcher.js.map +1 -1
  58. package/lib/common/launch/jsonrpc-server-launcher.d.ts +51 -2
  59. package/lib/common/launch/jsonrpc-server-launcher.d.ts.map +1 -1
  60. package/lib/common/launch/jsonrpc-server-launcher.js +82 -3
  61. package/lib/common/launch/jsonrpc-server-launcher.js.map +1 -1
  62. package/lib/common/operations/compound-operation-handler.js +1 -1
  63. package/lib/common/operations/compound-operation-handler.js.map +1 -1
  64. package/lib/common/operations/json-operation-handler.js +2 -3
  65. package/lib/common/operations/json-operation-handler.js.map +1 -1
  66. package/lib/common/protocol/glsp-server.js +6 -7
  67. package/lib/common/protocol/glsp-server.js.map +1 -1
  68. package/lib/common/session/client-session-manager.js +3 -5
  69. package/lib/common/session/client-session-manager.js.map +1 -1
  70. package/lib/common/utils/action-queue.js +2 -4
  71. package/lib/common/utils/action-queue.js.map +1 -1
  72. package/lib/common/utils/client-options-util.js +2 -2
  73. package/lib/common/utils/client-options-util.js.map +1 -1
  74. package/lib/common/utils/glsp-server-error.d.ts +2 -3
  75. package/lib/common/utils/glsp-server-error.d.ts.map +1 -1
  76. package/lib/common/utils/glsp-server-error.js +1 -1
  77. package/lib/common/utils/glsp-server-error.js.map +1 -1
  78. package/lib/common/utils/layout-util.d.ts +5 -5
  79. package/lib/common/utils/layout-util.d.ts.map +1 -1
  80. package/lib/common/utils/layout-util.js +17 -19
  81. package/lib/common/utils/layout-util.js.map +1 -1
  82. package/lib/common/utils/logger.js +1 -2
  83. package/lib/common/utils/logger.js.map +1 -1
  84. package/lib/node/abstract-json-model-storage.js +2 -4
  85. package/lib/node/abstract-json-model-storage.js.map +1 -1
  86. package/lib/node/launch/socket-server-launcher.d.ts +39 -2
  87. package/lib/node/launch/socket-server-launcher.d.ts.map +1 -1
  88. package/lib/node/launch/socket-server-launcher.js +50 -31
  89. package/lib/node/launch/socket-server-launcher.js.map +1 -1
  90. package/lib/node/launch/websocket-server-launcher.d.ts +36 -5
  91. package/lib/node/launch/websocket-server-launcher.d.ts.map +1 -1
  92. package/lib/node/launch/websocket-server-launcher.js +54 -13
  93. package/lib/node/launch/websocket-server-launcher.js.map +1 -1
  94. package/package.json +17 -21
  95. package/src/common/features/directediting/context-edit-validator.ts +2 -2
  96. package/src/common/features/layout/computed-bounds-action-handler.ts +52 -4
  97. package/src/common/features/model/model-submission-handler.ts +3 -2
  98. package/src/common/features/progress/progress-service.ts +2 -3
  99. package/src/common/gmodel/paste-operation-handler.ts +6 -6
  100. package/src/common/launch/glsp-server-launcher.ts +12 -1
  101. package/src/common/launch/jsonrpc-server-launcher.ts +89 -2
  102. package/src/common/utils/glsp-server-error.ts +3 -5
  103. package/src/common/utils/layout-util.ts +13 -12
  104. package/src/node/launch/socket-server-launcher.ts +54 -31
  105. package/src/node/launch/websocket-server-launcher.ts +72 -14
  106. package/src/browser/di/browser-action-dispatch-scope.spec.ts +0 -75
  107. package/src/common/actions/action-handler-registry.spec.ts +0 -52
  108. package/src/common/actions/global-action-provider.spec.ts +0 -68
  109. package/src/common/command/command-stack.spec.ts +0 -239
  110. package/src/common/command/command.spec.ts +0 -92
  111. package/src/common/command/recording-command.spec.ts +0 -86
  112. package/src/common/di/binding-target.spec.ts +0 -147
  113. package/src/common/di/multi-bindings.spec.ts +0 -133
  114. package/src/common/features/contextactions/context-actions-provider-registry.spec.ts +0 -69
  115. package/src/common/features/contextactions/request-context-actions-handler.spec.ts +0 -75
  116. package/src/common/features/contextactions/tool-palette-item-provider.spec.ts +0 -46
  117. package/src/common/features/directediting/context-edit-validator-registry.spec.ts +0 -54
  118. package/src/common/features/directediting/request-edit-validation-handler.spec.ts +0 -131
  119. package/src/common/features/model/gmodel-serializer.spec.ts +0 -141
  120. package/src/common/features/type-hints/request-type-hints-action-handler.spec.ts +0 -59
  121. package/src/common/operations/operation-handler-registry.spec.ts +0 -50
  122. package/src/common/protocol/glsp-server.spec.ts +0 -154
  123. package/src/common/session/client-session-factory.spec.ts +0 -60
  124. package/src/common/session/client-session-manager.spec.ts +0 -83
  125. package/src/common/test/mock-util.ts +0 -281
  126. package/src/common/utils/action-queue.spec.ts +0 -133
  127. package/src/common/utils/promise-queue.spec.ts +0 -142
  128. package/src/common/utils/registry.spec.ts +0 -225
  129. package/src/node/actions/action-dispatcher.spec.ts +0 -678
  130. package/src/node/launch/cli-parser.spec.ts +0 -61
  131. package/src/node/launch/socket-cli-parser.spec.ts +0 -73
  132. package/src/node/launch/socket-server-launcher.spec.ts +0 -74
@@ -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
- });
@@ -1,83 +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 { expect } from 'chai';
17
- import { Container, ContainerModule } from 'inversify';
18
- import * as sinon from 'sinon';
19
- import * as mock from '../test/mock-util';
20
- import { Logger } from '../utils/logger';
21
- import { ClientSessionFactory } from './client-session-factory';
22
- import { DefaultClientSessionManager } from './client-session-manager';
23
-
24
- describe('test DefaultClientSessionManager', () => {
25
- const testSession = mock.createClientSession('myId', 'myDiagram');
26
- const testSessionListener = new mock.StubClientSessionListener();
27
-
28
- const sessionFactory = new mock.StubClientSessionFactory();
29
- sinon.stub(sessionFactory, 'create').returns(testSession);
30
-
31
- const container = new Container();
32
- container.load(
33
- new ContainerModule(bind => {
34
- bind(Logger).toConstantValue(new mock.StubLogger());
35
- bind(ClientSessionFactory).toConstantValue(sessionFactory);
36
- })
37
- );
38
- const sessionManager = container.resolve(DefaultClientSessionManager);
39
-
40
- it('add listener', () => {
41
- expect(sessionManager.addListener(testSessionListener, testSession.id)).true;
42
- });
43
-
44
- it('add create client session', () => {
45
- // Mock setup
46
- const listener_create = sinon.spy(testSessionListener, 'sessionCreated');
47
- // Test execution
48
- const createdSession = sessionManager.getOrCreateClientSession({
49
- clientSessionId: testSession.id,
50
- diagramType: testSession.diagramType,
51
- clientActionKinds: []
52
- });
53
- expect(createdSession).to.not.be.undefined;
54
- expect(createdSession.id).to.be.equal(testSession.id);
55
- expect(createdSession.diagramType).to.be.equal(testSession.diagramType);
56
-
57
- const retrievedSession = sessionManager.getSession(testSession.id);
58
- expect(retrievedSession).to.not.be.undefined;
59
- expect(retrievedSession).to.be.equal(createdSession);
60
- expect(listener_create.calledWith(testSession));
61
- });
62
-
63
- it('get sessions by type', () => {
64
- const clientSessions = sessionManager.getSessionsByType(testSession.diagramType);
65
- expect(clientSessions.length).to.be.equal(1);
66
- expect(clientSessions[0]).to.be.equal(testSession);
67
- });
68
-
69
- it('get sessions by type that does no exist', async () => {
70
- const clientSessions = sessionManager.getSessionsByType('wrongType');
71
- expect(clientSessions.length).to.be.equal(0);
72
- });
73
-
74
- it('dispose client session', () => {
75
- // Mock setup
76
- const listener_dispose = sinon.spy(testSessionListener, 'sessionDisposed');
77
- // Test execution
78
- expect(sessionManager.disposeClientSession(testSession.id)).to.be.equal(true);
79
- const session = sessionManager.getSession(testSession.id);
80
- expect(session).to.be.undefined;
81
- expect(listener_dispose.calledWith(testSession));
82
- });
83
- });