iotagent-node-lib 3.4.3 → 4.0.0

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 (94) hide show
  1. package/CHANGES_NEXT_RELEASE +0 -1
  2. package/README.md +4 -0
  3. package/doc/admin.md +1 -13
  4. package/doc/api.md +118 -14
  5. package/doc/devel/architecture.md +0 -12
  6. package/doc/index.md +1 -1
  7. package/doc/roadmap.md +22 -10
  8. package/lib/commonConfig.js +0 -11
  9. package/lib/model/Device.js +2 -1
  10. package/lib/model/Group.js +2 -1
  11. package/lib/model/dbConn.js +22 -11
  12. package/lib/plugins/expressionPlugin.js +0 -5
  13. package/lib/plugins/jexlParser.js +15 -31
  14. package/lib/services/common/genericMiddleware.js +14 -2
  15. package/lib/services/common/iotManagerService.js +2 -1
  16. package/lib/services/devices/deviceRegistryMongoDB.js +3 -1
  17. package/lib/services/devices/deviceService.js +16 -21
  18. package/lib/services/devices/devices-NGSI-LD.js +5 -98
  19. package/lib/services/devices/devices-NGSI-mixed.js +0 -14
  20. package/lib/services/devices/devices-NGSI-v2.js +3 -0
  21. package/lib/services/groups/groupRegistryMemory.js +0 -25
  22. package/lib/services/groups/groupRegistryMongoDB.js +20 -19
  23. package/lib/services/groups/groupService.js +3 -14
  24. package/lib/services/ngsi/entities-NGSI-LD.js +81 -6
  25. package/lib/services/ngsi/entities-NGSI-v2.js +304 -687
  26. package/lib/services/ngsi/ngsiUtils.js +0 -30
  27. package/lib/services/northBound/deviceProvisioningServer.js +6 -3
  28. package/lib/templates/createDevice.json +4 -0
  29. package/lib/templates/createDeviceLax.json +4 -0
  30. package/lib/templates/deviceGroup.json +4 -0
  31. package/lib/templates/updateDevice.json +4 -0
  32. package/lib/templates/updateDeviceLax.json +4 -0
  33. package/package.json +6 -2
  34. package/test/functional/README.md +378 -0
  35. package/test/functional/config-test.js +70 -0
  36. package/test/functional/functional-tests-runner.js +126 -0
  37. package/test/functional/functional-tests.js +241 -0
  38. package/test/functional/testCases.js +2944 -0
  39. package/test/functional/testUtils.js +251 -0
  40. package/test/tools/utils.js +25 -0
  41. package/test/unit/mongodb/mongodb-connectionoptions-test.js +35 -22
  42. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic2.json +3 -34
  43. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin6.json +8 -1
  44. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin7.json +1 -4
  45. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin8.json +1 -6
  46. package/test/unit/ngsi-ld/general/contextBrokerOAuthSecurityAccess-test.js +67 -87
  47. package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +7 -13
  48. package/test/unit/ngsi-ld/lazyAndCommands/merge-patch-test.js +43 -43
  49. package/test/unit/ngsi-ld/lazyAndCommands/polling-commands-test.js +19 -29
  50. package/test/unit/ngsi-ld/ngsiService/languageProperties-test.js +0 -1
  51. package/test/unit/ngsi-ld/ngsiService/subscriptions-test.js +35 -46
  52. package/test/unit/ngsi-ld/plugins/alias-plugin_test.js +8 -9
  53. package/test/unit/ngsi-ld/provisioning/device-provisioning-api_test.js +96 -221
  54. package/test/unit/ngsi-ld/provisioning/device-registration_test.js +18 -27
  55. package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +8 -16
  56. package/test/unit/ngsi-ld/provisioning/updateProvisionedDevices-test.js +0 -13
  57. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin8.json +4 -4
  58. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin29b.json +8 -0
  59. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin30.json +1 -1
  60. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin32.json +0 -6
  61. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin34.json +8 -0
  62. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin34b.json +14 -0
  63. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin35.json +1 -11
  64. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin36b.json +13 -0
  65. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin37.json +8 -0
  66. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin41.json +1 -11
  67. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin10b.json +37 -0
  68. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin11.json +0 -4
  69. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin15.json +0 -4
  70. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin16.json +0 -4
  71. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin25.json +4 -0
  72. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin4.json +0 -3
  73. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin5.json +10 -12
  74. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin6.json +0 -4
  75. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin7.json +1 -5
  76. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin8.json +8 -12
  77. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +0 -4
  78. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin3.json +0 -8
  79. package/test/unit/ngsiv2/examples/contextRequests/updateContextStaticAttributesMetadata.json +7 -1
  80. package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +898 -28
  81. package/test/unit/ngsiv2/ngsiService/active-devices-test.js +188 -1
  82. package/test/unit/ngsiv2/ngsiService/staticAttributes-test.js +267 -0
  83. package/test/unit/ngsiv2/plugins/alias-plugin_test.js +19 -21
  84. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +21 -24
  85. package/test/unit/ngsiv2/provisioning/device-group-utils-test.js +1 -21
  86. package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +4 -6
  87. package/test/unit/ngsi-ld/ngsiService/autocast-test.js +0 -438
  88. package/test/unit/ngsi-ld/ngsiService/geoproperties-test.js +0 -381
  89. package/test/unit/ngsi-ld/provisioning/singleConfigurationMode-test.js +0 -311
  90. package/test/unit/ngsiv2/ngsiService/autocast-test.js +0 -325
  91. package/test/unit/ngsiv2/ngsiService/geoproperties-test.js +0 -427
  92. package/test/unit/ngsiv2/plugins/compress-timestamp-plugin_test.js +0 -217
  93. package/test/unit/ngsiv2/plugins/timestamp-processing-plugin_test.js +0 -119
  94. package/test/unit/ngsiv2/provisioning/singleConfigurationMode-test.js +0 -309
@@ -1,325 +0,0 @@
1
- /*
2
- * Copyright 2014 Telefonica Investigación y Desarrollo, S.A.U
3
- *
4
- * This file is part of fiware-iotagent-lib
5
- *
6
- * fiware-iotagent-lib is free software: you can redistribute it and/or
7
- * modify it under the terms of the GNU Affero General Public License as
8
- * published by the Free Software Foundation, either version 3 of the License,
9
- * or (at your option) any later version.
10
- *
11
- * fiware-iotagent-lib is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
- * See the GNU Affero General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Affero General Public
17
- * License along with fiware-iotagent-lib.
18
- * If not, see http://www.gnu.org/licenses/.
19
- *
20
- * For those usages not covered by the GNU Affero General Public License
21
- * please contact with::[contacto@tid.es]
22
- *
23
- * Modified by: Daniel Calvo - ATOS Research & Innovation
24
- */
25
-
26
- /* eslint-disable no-useless-concat */
27
-
28
- const iotAgentLib = require('../../../../lib/fiware-iotagent-lib');
29
- const utils = require('../../../tools/utils');
30
- const should = require('should');
31
- const logger = require('logops');
32
- const nock = require('nock');
33
- let contextBrokerMock;
34
- const iotAgentConfig = {
35
- autocast: true,
36
- contextBroker: {
37
- host: '192.168.1.1',
38
- port: '1026',
39
- ngsiVersion: 'v2'
40
- },
41
- server: {
42
- port: 4041,
43
- host: 'localhost'
44
- },
45
- types: {
46
- Light: {
47
- commands: [],
48
- type: 'Light',
49
- active: [
50
- {
51
- name: 'pressure',
52
- type: 'Number'
53
- },
54
- {
55
- name: 'temperature',
56
- type: 'Number'
57
- },
58
- {
59
- name: 'id',
60
- type: 'String'
61
- },
62
- {
63
- name: 'status',
64
- type: 'Boolean'
65
- },
66
- {
67
- name: 'keep_alive',
68
- type: 'None'
69
- },
70
- {
71
- name: 'tags',
72
- type: 'Array'
73
- },
74
- {
75
- name: 'configuration',
76
- type: 'Object'
77
- }
78
- ]
79
- }
80
- },
81
- service: 'smartgondor',
82
- subservice: 'gardens',
83
- providerUrl: 'http://smartgondor.com'
84
- };
85
-
86
- describe('NGSI-v2 - JSON native types autocast test', function () {
87
- beforeEach(function () {
88
- logger.setLevel('FATAL');
89
- });
90
-
91
- afterEach(function (done) {
92
- iotAgentLib.deactivate(done);
93
- });
94
-
95
- describe('When the IoT Agent receives new information from a device. Observation with Number type and Integer value', function () {
96
- const values = [
97
- {
98
- name: 'pressure',
99
- type: 'Number',
100
- value: '23'
101
- }
102
- ];
103
-
104
- beforeEach(function (done) {
105
- nock.cleanAll();
106
-
107
- contextBrokerMock = nock('http://192.168.1.1:1026')
108
- .matchHeader('fiware-service', 'smartgondor')
109
- .matchHeader('fiware-servicepath', 'gardens')
110
- .post(
111
- '/v2/entities?options=upsert',
112
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/updateContextAutocast1.json')
113
- )
114
- .reply(204);
115
-
116
- iotAgentLib.activate(iotAgentConfig, done);
117
- });
118
-
119
- it('should change the value of the corresponding attribute in the context broker', function (done) {
120
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
121
- should.not.exist(error);
122
- contextBrokerMock.done();
123
- done();
124
- });
125
- });
126
- });
127
-
128
- describe('When the IoT Agent receives new information from a device. Observation with Number type and Float value', function () {
129
- const values = [
130
- {
131
- name: 'temperature',
132
- type: 'Number',
133
- value: '14.4'
134
- }
135
- ];
136
-
137
- beforeEach(function (done) {
138
- nock.cleanAll();
139
-
140
- contextBrokerMock = nock('http://192.168.1.1:1026')
141
- .matchHeader('fiware-service', 'smartgondor')
142
- .matchHeader('fiware-servicepath', 'gardens')
143
- .post(
144
- '/v2/entities?options=upsert',
145
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/updateContextAutocast2.json')
146
- )
147
- .reply(204);
148
-
149
- iotAgentLib.activate(iotAgentConfig, done);
150
- });
151
-
152
- it('should change the value of the corresponding attribute in the context broker', function (done) {
153
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
154
- should.not.exist(error);
155
- contextBrokerMock.done();
156
- done();
157
- });
158
- });
159
- });
160
-
161
- describe('When the IoT Agent receives new information from a device. Observation with Boolean type and True value', function () {
162
- const values = [
163
- {
164
- name: 'status',
165
- type: 'Boolean',
166
- value: 'true'
167
- }
168
- ];
169
-
170
- beforeEach(function (done) {
171
- nock.cleanAll();
172
-
173
- contextBrokerMock = nock('http://192.168.1.1:1026')
174
- .matchHeader('fiware-service', 'smartgondor')
175
- .matchHeader('fiware-servicepath', 'gardens')
176
- .post(
177
- '/v2/entities?options=upsert',
178
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/updateContextAutocast3.json')
179
- )
180
- .reply(204);
181
-
182
- iotAgentLib.activate(iotAgentConfig, done);
183
- });
184
-
185
- it('should change the value of the corresponding attribute in the context broker', function (done) {
186
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
187
- should.not.exist(error);
188
- contextBrokerMock.done();
189
- done();
190
- });
191
- });
192
- });
193
-
194
- describe('When the IoT Agent receives new information from a device. Observation with Boolean type and False value', function () {
195
- const values = [
196
- {
197
- name: 'status',
198
- type: 'Boolean',
199
- value: 'false'
200
- }
201
- ];
202
-
203
- beforeEach(function (done) {
204
- nock.cleanAll();
205
-
206
- contextBrokerMock = nock('http://192.168.1.1:1026')
207
- .matchHeader('fiware-service', 'smartgondor')
208
- .matchHeader('fiware-servicepath', 'gardens')
209
- .post(
210
- '/v2/entities?options=upsert',
211
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/updateContextAutocast4.json')
212
- )
213
- .reply(204);
214
-
215
- iotAgentLib.activate(iotAgentConfig, done);
216
- });
217
-
218
- it('should change the value of the corresponding attribute in the context broker', function (done) {
219
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
220
- should.not.exist(error);
221
- contextBrokerMock.done();
222
- done();
223
- });
224
- });
225
- });
226
-
227
- describe('When the IoT Agent receives new information from a device. Observation with None type', function () {
228
- const values = [
229
- {
230
- name: 'keep_alive',
231
- type: 'None',
232
- value: 'null'
233
- }
234
- ];
235
-
236
- beforeEach(function (done) {
237
- nock.cleanAll();
238
-
239
- contextBrokerMock = nock('http://192.168.1.1:1026')
240
- .matchHeader('fiware-service', 'smartgondor')
241
- .matchHeader('fiware-servicepath', 'gardens')
242
- .post(
243
- '/v2/entities?options=upsert',
244
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/updateContextAutocast5.json')
245
- )
246
- .reply(204);
247
-
248
- iotAgentLib.activate(iotAgentConfig, done);
249
- });
250
-
251
- it('should change the value of the corresponding attribute in the context broker', function (done) {
252
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
253
- should.not.exist(error);
254
- contextBrokerMock.done();
255
- done();
256
- });
257
- });
258
- });
259
-
260
- describe('When the IoT Agent receives new information from a device. Observation with Array type', function () {
261
- const values = [
262
- {
263
- name: 'tags',
264
- type: 'Array',
265
- value: '["iot","device"]'
266
- }
267
- ];
268
-
269
- beforeEach(function (done) {
270
- nock.cleanAll();
271
-
272
- contextBrokerMock = nock('http://192.168.1.1:1026')
273
- .matchHeader('fiware-service', 'smartgondor')
274
- .matchHeader('fiware-servicepath', 'gardens')
275
- .post(
276
- '/v2/entities?options=upsert',
277
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/updateContextAutocast6.json')
278
- )
279
- .reply(204);
280
-
281
- iotAgentLib.activate(iotAgentConfig, done);
282
- });
283
-
284
- it('should change the value of the corresponding attribute in the context broker', function (done) {
285
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
286
- should.not.exist(error);
287
- contextBrokerMock.done();
288
- done();
289
- });
290
- });
291
- });
292
-
293
- describe('When the IoT Agent receives new information from a device. Observation with Object type', function () {
294
- const values = [
295
- {
296
- name: 'configuration',
297
- type: 'Object',
298
- value: '{"firmware": {"version": "1.1.0","hash": "cf23df2207d99a74fbe169e3eba035e633b65d94"}}'
299
- }
300
- ];
301
-
302
- beforeEach(function (done) {
303
- nock.cleanAll();
304
-
305
- contextBrokerMock = nock('http://192.168.1.1:1026')
306
- .matchHeader('fiware-service', 'smartgondor')
307
- .matchHeader('fiware-servicepath', 'gardens')
308
- .post(
309
- '/v2/entities?options=upsert',
310
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/updateContextAutocast7.json')
311
- )
312
- .reply(204);
313
-
314
- iotAgentLib.activate(iotAgentConfig, done);
315
- });
316
-
317
- it('should change the value of the corresponding attribute in the context broker', function (done) {
318
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
319
- should.not.exist(error);
320
- contextBrokerMock.done();
321
- done();
322
- });
323
- });
324
- });
325
- });