iotagent-node-lib 2.23.0 → 2.25.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 (60) hide show
  1. package/.github/workflows/ci.yml +6 -7
  2. package/.nyc_output/33364de2-1199-4ec2-b33c-cae063ef8cc4.json +1 -0
  3. package/.nyc_output/processinfo/33364de2-1199-4ec2-b33c-cae063ef8cc4.json +1 -0
  4. package/.nyc_output/processinfo/index.json +1 -1
  5. package/CHANGES_NEXT_RELEASE +1 -2
  6. package/doc/advanced-topics.md +78 -3
  7. package/doc/apiary/iotagent.apib +5 -5
  8. package/doc/architecture.md +52 -5
  9. package/doc/deprecated.md +10 -7
  10. package/doc/expressionLanguage.md +46 -35
  11. package/doc/getting-started.md +1 -1
  12. package/doc/usermanual.md +18 -16
  13. package/examples/TTOpen-service.json +1 -1
  14. package/lib/errors.js +9 -1
  15. package/lib/fiware-iotagent-lib.js +2 -1
  16. package/lib/jexlTranformsMap.js +12 -1
  17. package/lib/plugins/bidirectionalData.js +104 -6
  18. package/lib/plugins/expressionPlugin.js +10 -0
  19. package/lib/plugins/jexlParser.js +2 -2
  20. package/lib/plugins/pluginUtils.js +2 -1
  21. package/lib/request-shim.js +2 -1
  22. package/lib/services/devices/deviceService.js +53 -21
  23. package/lib/services/devices/devices-NGSI-v2.js +3 -1
  24. package/lib/services/ngsi/entities-NGSI-v2.js +14 -4
  25. package/lib/services/northBound/contextServer-NGSI-LD.js +96 -20
  26. package/lib/services/northBound/contextServer-NGSI-v2.js +1 -0
  27. package/lib/services/northBound/restUtils.js +3 -5
  28. package/lib/templates/deviceGroup.json +1 -1
  29. package/package.json +2 -2
  30. package/test/unit/examples/deviceProvisioningRequests/provisionNewDeviceEmpty.json +43 -0
  31. package/test/unit/examples/mongoCollections/configurations.json +3 -3
  32. package/test/unit/expressions/jexlExpression-test.js +29 -8
  33. package/test/unit/general/deviceService-test.js +31 -29
  34. package/test/unit/memoryRegistry/deviceRegistryMemory_test.js +62 -10
  35. package/test/unit/mongodb/mongodb-group-registry-test.js +24 -0
  36. package/test/unit/mongodb/mongodb-registry-test.js +68 -10
  37. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin30.json +11 -0
  38. package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotificationWithDatasetId.json +21 -0
  39. package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotificationWithMetadata.json +17 -0
  40. package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +18 -4
  41. package/test/unit/ngsi-ld/general/deviceService-test.js +31 -29
  42. package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +656 -2
  43. package/test/unit/ngsi-ld/ngsiService/unsupported-endpoints-test.js +111 -0
  44. package/test/unit/ngsi-ld/plugins/bidirectional-plugin_test.js +221 -0
  45. package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +0 -3
  46. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityJexlExpressionPlugin1.json +22 -0
  47. package/test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalNotificationWithMetadata.json +19 -0
  48. package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +21 -6
  49. package/test/unit/ngsiv2/general/deviceService-test.js +25 -23
  50. package/test/unit/ngsiv2/lazyAndCommands/command-test.js +106 -0
  51. package/test/unit/ngsiv2/plugins/bidirectional-plugin_test.js +115 -0
  52. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +58 -0
  53. package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +25 -6
  54. package/.nyc_output/6e3d7795-bf8c-4a50-bd2f-f8221f27aeae.json +0 -1
  55. package/.nyc_output/processinfo/6e3d7795-bf8c-4a50-bd2f-f8221f27aeae.json +0 -1
  56. package/config +0 -0
  57. package/docker/Mosquitto/Dockerfile.debian +0 -38
  58. package/docker/Mosquitto/Dockerfile.debian~ +0 -23
  59. package/lib/plugins/multiEntity.js_avg2 +0 -343
  60. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js_avg2 +0 -1224
@@ -1,1224 +0,0 @@
1
- /*
2
- * Copyright 2016 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-unused-vars */
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
- const moment = require('moment');
34
- const timekeeper = require('timekeeper');
35
- let contextBrokerMock;
36
- const iotAgentConfig = {
37
- contextBroker: {
38
- host: '192.168.1.1',
39
- port: '1026',
40
- ngsiVersion: 'v2'
41
- },
42
- server: {
43
- port: 4041
44
- },
45
- types: {
46
- WeatherStation: {
47
- commands: [],
48
- type: 'WeatherStation',
49
- lazy: [],
50
- active: [
51
- {
52
- object_id: 'p',
53
- name: 'pressure',
54
- type: 'Hgmm'
55
- },
56
- {
57
- object_id: 'h',
58
- name: 'humidity',
59
- type: 'Percentage',
60
- entity_name: 'Higro2000',
61
- entity_type: 'Higrometer',
62
- metadata: {
63
- unitCode: {
64
- type: 'Text',
65
- value: 'Hgmm'
66
- }
67
- }
68
- }
69
- ]
70
- },
71
- WeatherStation2: {
72
- commands: [],
73
- type: 'WeatherStation',
74
- lazy: [],
75
- active: [
76
- {
77
- object_id: 'p',
78
- name: 'pressure',
79
- type: 'Hgmm'
80
- },
81
- {
82
- object_id: 'h',
83
- name: 'humidity',
84
- type: 'Percentage',
85
- entity_name: 'Higro2000'
86
- }
87
- ]
88
- },
89
- WeatherStation3: {
90
- commands: [],
91
- type: 'WeatherStation',
92
- lazy: [],
93
- active: [
94
- {
95
- object_id: 'p',
96
- name: 'pressure',
97
- type: 'Hgmm'
98
- },
99
- {
100
- object_id: 'h',
101
- name: 'humidity',
102
- type: 'Percentage',
103
- entity_name: 'Station Number ${@sn * 10}'
104
- }
105
- ]
106
- },
107
- WeatherStation4: {
108
- commands: [],
109
- type: 'WeatherStation',
110
- lazy: [],
111
- active: [
112
- {
113
- object_id: 'p',
114
- name: 'pressure',
115
- type: 'Hgmm',
116
- entity_name: 'Station Number ${@sn * 10}'
117
- },
118
- {
119
- object_id: 'h',
120
- name: 'humidity',
121
- type: 'Percentage',
122
- entity_name: 'Station Number ${@sn * 10}'
123
- }
124
- ]
125
- },
126
- WeatherStation5: {
127
- commands: [],
128
- type: 'WeatherStation',
129
- lazy: [],
130
- active: [
131
- {
132
- object_id: 'p',
133
- name: 'pressure',
134
- type: 'Hgmm'
135
- },
136
- {
137
- object_id: 'h',
138
- name: 'pressure',
139
- type: 'Hgmm',
140
- entity_name: 'Higro2000',
141
- entity_type: 'Higrometer'
142
- }
143
- ]
144
- },
145
- WeatherStation6: {
146
- commands: [],
147
- type: 'WeatherStation',
148
- lazy: [],
149
- active: [
150
- {
151
- object_id: 'p',
152
- name: 'pressure',
153
- type: 'Hgmm',
154
- entity_name: 'Higro2002',
155
- entity_type: 'Higrometer'
156
- },
157
- {
158
- object_id: 'h',
159
- name: 'pressure',
160
- type: 'Hgmm',
161
- entity_name: 'Higro2000',
162
- entity_type: 'Higrometer'
163
- }
164
- ]
165
- },
166
- WeatherStation7: {
167
- commands: [],
168
- type: 'WeatherStation',
169
- lazy: [],
170
- active: [
171
- {
172
- object_id: 'p',
173
- name: 'pressure',
174
- type: 'Hgmm',
175
- metadata: {
176
- unitCode: { type: 'Text', value: 'Hgmm' }
177
- },
178
- entity_name: 'Higro2002',
179
- entity_type: 'Higrometer'
180
- },
181
- {
182
- object_id: 'h',
183
- name: 'pressure',
184
- type: 'Hgmm',
185
- entity_name: 'Higro2000',
186
- entity_type: 'Higrometer'
187
- }
188
- ]
189
- },
190
- WeatherStation8: {
191
- commands: [],
192
- type: 'WeatherStation',
193
- lazy: [],
194
- active: [
195
- {
196
- object_id: 'v1',
197
- name: 'vol',
198
- expression: '${@v1*100}',
199
- type: 'Number',
200
- entity_name: 'WeatherStation1'
201
- },
202
- {
203
- object_id: 'v2',
204
- name: 'vol',
205
- expression: '${@v2*100}',
206
- type: 'Number',
207
- entity_name: 'WeatherStation2'
208
- },
209
- {
210
- object_id: 'v',
211
- name: 'vol',
212
- expression: '${@v*100}',
213
- type: 'Number'
214
- }
215
- ]
216
- },
217
- WeatherStation8Jexl: {
218
- commands: [],
219
- type: 'WeatherStation',
220
- expressionLanguage: 'jexl',
221
- lazy: [],
222
- active: [
223
- {
224
- object_id: 'v1',
225
- name: 'vol',
226
- expression: 'v1 * 100',
227
- type: 'Number',
228
- entity_name: 'WeatherStation1'
229
- },
230
- {
231
- object_id: 'v2',
232
- name: 'vol',
233
- expression: 'v2 * 100',
234
- type: 'Number',
235
- entity_name: 'WeatherStation2'
236
- },
237
- {
238
- object_id: 'v',
239
- name: 'vol',
240
- expression: 'v * 100',
241
- type: 'Number'
242
- }
243
- ]
244
- },
245
- Sensor001: {
246
- commands: [],
247
- type: 'Sensor',
248
- lazy: [],
249
- active: [
250
- {
251
- type: 'number',
252
- name: 'vol',
253
- object_id: 'cont1',
254
- entity_name: 'SO1',
255
- entity_type: 'WM'
256
- },
257
- {
258
- type: 'number',
259
- name: 'vol',
260
- object_id: 'cont2',
261
- entity_name: 'SO2',
262
- entity_type: 'WM'
263
- },
264
- {
265
- type: 'number',
266
- name: 'vol',
267
- object_id: 'cont3',
268
- entity_name: 'SO3',
269
- entity_type: 'WM'
270
- },
271
- {
272
- type: 'number',
273
- name: 'vol',
274
- object_id: 'cont4',
275
- entity_name: 'SO4',
276
- entity_type: 'WM'
277
- },
278
- {
279
- type: 'number',
280
- name: 'vol',
281
- object_id: 'cont5',
282
- entity_name: 'SO5',
283
- entity_type: 'WM'
284
- }
285
- ]
286
- },
287
- SensorCommand: {
288
- commands: [
289
- {
290
- name: 'PING',
291
- type: 'command'
292
- }
293
- ],
294
- type: 'SensorCommand',
295
- lazy: []
296
- },
297
- SharedIds1: {
298
- commands: [],
299
- type: 'ShareStation',
300
- lazy: [],
301
- active: [
302
- {
303
- object_id: 'v1',
304
- name: 'volt1',
305
- type: 'Number',
306
- entity_name: 'WeatherStation1',
307
- entity_type: 'Type1'
308
- },
309
- {
310
- object_id: 'v2',
311
- name: 'volt2',
312
- type: 'Number',
313
- entity_name: 'WeatherStation1',
314
- entity_type: 'Type2'
315
- },
316
- {
317
- object_id: 'v3',
318
- name: 'extravolt2',
319
- type: 'Number',
320
- entity_name: 'WeatherStation1',
321
- entity_type: 'Type2'
322
- },
323
- {
324
- object_id: 'v',
325
- name: 'vol',
326
- type: 'Number'
327
- }
328
- ]
329
- },
330
- SharedIds2: {
331
- commands: [],
332
- type: 'ShareStation',
333
- lazy: [],
334
- active: [
335
- {
336
- object_id: 'v1',
337
- name: 'vol',
338
- type: 'Number',
339
- entity_name: 'WeatherStation1',
340
- entity_type: 'Type1'
341
- },
342
- {
343
- object_id: 'v2',
344
- name: 'vol',
345
- type: 'Number',
346
- entity_name: 'WeatherStation1',
347
- entity_type: 'Type2'
348
- },
349
- {
350
- object_id: 'v3',
351
- name: 'extravol',
352
- type: 'Number',
353
- entity_name: 'WeatherStation1',
354
- entity_type: 'Type2'
355
- },
356
- {
357
- object_id: 'v',
358
- name: 'vol',
359
- type: 'Number'
360
- }
361
- ]
362
- },
363
- SharedIds3: {
364
- commands: [],
365
- type: 'ShareStation',
366
- expressionLanguage: 'jexl',
367
- lazy: [],
368
- active: [
369
- {
370
- object_id: 'v',
371
- //expression: 'v',
372
- name: 'vol',
373
- type: 'Number',
374
- entity_name: 'WeatherStation1',
375
- entity_type: 'Type1'
376
- },
377
- {
378
- object_id: 'v',
379
- //expression: 'v',
380
- name: 'vol',
381
- type: 'Number',
382
- entity_name: 'WeatherStation1',
383
- entity_type: 'Type2'
384
- },
385
- {
386
- object_id: 'v',
387
- //expression: 'v',
388
- name: 'extravol',
389
- type: 'Number',
390
- entity_name: 'WeatherStation1',
391
- entity_type: 'Type2'
392
- },
393
- {
394
- object_id: 'v',
395
- name: 'vol',
396
- type: 'Number'
397
- }
398
- ]
399
- }
400
- },
401
- service: 'smartgondor',
402
- subservice: 'gardens',
403
- providerUrl: 'http://smartgondor.com'
404
- };
405
-
406
- describe('NGSI-v2 - Multi-entity plugin', function () {
407
- beforeEach(function (done) {
408
- logger.setLevel('DEBUG');
409
-
410
- iotAgentLib.activate(iotAgentConfig, function () {
411
- iotAgentLib.clearAll(function () {
412
- iotAgentLib.addUpdateMiddleware(iotAgentLib.dataPlugins.attributeAlias.update);
413
- iotAgentLib.addQueryMiddleware(iotAgentLib.dataPlugins.attributeAlias.query);
414
- iotAgentLib.addUpdateMiddleware(iotAgentLib.dataPlugins.expressionTransformation.update);
415
- iotAgentLib.addUpdateMiddleware(iotAgentLib.dataPlugins.multiEntity.update);
416
- done();
417
- });
418
- });
419
- });
420
-
421
- afterEach(function (done) {
422
- iotAgentLib.clearAll(function () {
423
- iotAgentLib.deactivate(done);
424
- });
425
- });
426
-
427
- // describe('When an update comes for a multientity measurement', function () {
428
- // const values = [
429
- // {
430
- // name: 'p',
431
- // type: 'centigrades',
432
- // value: '52'
433
- // },
434
- // {
435
- // name: 'h',
436
- // type: 'Percentage',
437
- // value: '12'
438
- // }
439
- // ];
440
-
441
- // beforeEach(function () {
442
- // nock.cleanAll();
443
-
444
- // contextBrokerMock = nock('http://192.168.1.1:1026')
445
- // .matchHeader('fiware-service', 'smartgondor')
446
- // .matchHeader('fiware-servicepath', 'gardens')
447
- // .post(
448
- // '/v2/op/update',
449
- // utils.readExampleFile(
450
- // './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin1.json'
451
- // )
452
- // )
453
- // .reply(204);
454
- // });
455
-
456
- // it('should send two context elements, one for each entity', function (done) {
457
- // iotAgentLib.update('ws4', 'WeatherStation', '', values, function (error) {
458
- // should.not.exist(error);
459
- // contextBrokerMock.done();
460
- // done();
461
- // });
462
- // });
463
- // });
464
-
465
- // describe('When an update comes for a multientity measurement with same attribute name', function () {
466
- // const values = [
467
- // {
468
- // name: 'h',
469
- // type: 'Hgmm',
470
- // value: '16'
471
- // }
472
- // ];
473
-
474
- // beforeEach(function () {
475
- // nock.cleanAll();
476
-
477
- // contextBrokerMock = nock('http://192.168.1.1:1026')
478
- // .matchHeader('fiware-service', 'smartgondor')
479
- // .matchHeader('fiware-servicepath', 'gardens')
480
- // .post(
481
- // '/v2/op/update',
482
- // utils.readExampleFile(
483
- // './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin4.json'
484
- // )
485
- // )
486
- // .reply(204);
487
- // });
488
-
489
- // it('should send context elements', function (done) {
490
- // iotAgentLib.update('ws5', 'WeatherStation5', '', values, function (error) {
491
- // should.not.exist(error);
492
- // contextBrokerMock.done();
493
- // done();
494
- // });
495
- // });
496
- // });
497
-
498
- // describe('When an update comes for a multientity multi measurement with same attribute name', function () {
499
- // const values = [
500
- // {
501
- // name: 'h',
502
- // type: 'Hgmm',
503
- // value: '16'
504
- // },
505
- // {
506
- // name: 'p',
507
- // type: 'Hgmm',
508
- // value: '17'
509
- // }
510
- // ];
511
-
512
- // beforeEach(function () {
513
- // nock.cleanAll();
514
-
515
- // contextBrokerMock = nock('http://192.168.1.1:1026')
516
- // .matchHeader('fiware-service', 'smartgondor')
517
- // .matchHeader('fiware-servicepath', 'gardens')
518
- // .post(
519
- // '/v2/op/update',
520
- // utils.readExampleFile(
521
- // './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin5.json'
522
- // )
523
- // )
524
- // .reply(204);
525
- // });
526
-
527
- // it('should send context elements', function (done) {
528
- // iotAgentLib.update('ws6', 'WeatherStation6', '', values, function (error) {
529
- // should.not.exist(error);
530
- // contextBrokerMock.done();
531
- // done();
532
- // });
533
- // });
534
- // });
535
-
536
- // /* jshint maxlen: 200 */
537
- // describe('When an update comes for a multientity multi measurement with metadata and the same attribute name', function () {
538
- // const values = [
539
- // {
540
- // name: 'h',
541
- // type: 'Hgmm',
542
- // value: '16'
543
- // },
544
- // {
545
- // name: 'p',
546
- // type: 'Hgmm',
547
- // value: '17'
548
- // }
549
- // ];
550
-
551
- // beforeEach(function () {
552
- // nock.cleanAll();
553
-
554
- // contextBrokerMock = nock('http://192.168.1.1:1026')
555
- // .matchHeader('fiware-service', 'smartgondor')
556
- // .matchHeader('fiware-servicepath', 'gardens')
557
- // .post(
558
- // '/v2/op/update',
559
- // utils.readExampleFile(
560
- // './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin8.json'
561
- // )
562
- // )
563
- // .reply(204);
564
- // });
565
-
566
- // it('should send context elements', function (done) {
567
- // iotAgentLib.update('ws7', 'WeatherStation7', '', values, function (error) {
568
- // should.not.exist(error);
569
- // contextBrokerMock.done();
570
- // done();
571
- // });
572
- // });
573
- // });
574
-
575
- // describe('When an update comes for a multientity defined with an expression', function () {
576
- // const values = [
577
- // {
578
- // name: 'p',
579
- // type: 'centigrades',
580
- // value: '52'
581
- // },
582
- // {
583
- // name: 'h',
584
- // type: 'Percentage',
585
- // value: '12'
586
- // },
587
- // {
588
- // name: 'sn',
589
- // type: 'Number',
590
- // value: '5'
591
- // }
592
- // ];
593
-
594
- // beforeEach(function () {
595
- // nock.cleanAll();
596
-
597
- // contextBrokerMock = nock('http://192.168.1.1:1026')
598
- // .matchHeader('fiware-service', 'smartgondor')
599
- // .matchHeader('fiware-servicepath', 'gardens')
600
- // .post(
601
- // '/v2/op/update',
602
- // utils.readExampleFile(
603
- // './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin3.json'
604
- // )
605
- // )
606
- // .reply(204);
607
- // });
608
-
609
- // it('should send the update value to the resulting value of the expression', function (done) {
610
- // iotAgentLib.update('ws4', 'WeatherStation3', '', values, function (error) {
611
- // should.not.exist(error);
612
- // contextBrokerMock.done();
613
- // done();
614
- // });
615
- // });
616
- // });
617
-
618
- // describe('When an update comes for a multientity defined with an expression (multi values)', function () {
619
- // const values = [
620
- // {
621
- // name: 'p',
622
- // type: 'centigrades',
623
- // value: '52'
624
- // },
625
- // {
626
- // name: 'h',
627
- // type: 'Percentage',
628
- // value: '12'
629
- // },
630
- // {
631
- // name: 'sn',
632
- // type: 'Number',
633
- // value: '5'
634
- // }
635
- // ];
636
-
637
- // beforeEach(function () {
638
- // nock.cleanAll();
639
-
640
- // contextBrokerMock = nock('http://192.168.1.1:1026')
641
- // .matchHeader('fiware-service', 'smartgondor')
642
- // .matchHeader('fiware-servicepath', 'gardens')
643
- // .post(
644
- // '/v2/op/update',
645
- // utils.readExampleFile(
646
- // './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin9.json'
647
- // )
648
- // )
649
- // .reply(204);
650
- // });
651
-
652
- // it('should send the update value to the resulting value of the expression', function (done) {
653
- // iotAgentLib.update('ws8', 'WeatherStation4', '', values, function (error) {
654
- // should.not.exist(error);
655
- // contextBrokerMock.done();
656
- // done();
657
- // });
658
- // });
659
- // });
660
-
661
- // describe('When an update comes for a multientity defined with an expression (multi values / multiple entities / same attribute)', function () {
662
- // const values = [
663
- // {
664
- // name: 'v',
665
- // type: 'Number',
666
- // value: 0
667
- // },
668
- // {
669
- // name: 'v1',
670
- // type: 'Number',
671
- // value: 1
672
- // },
673
- // {
674
- // name: 'v2',
675
- // type: 'Number',
676
- // value: 2
677
- // }
678
- // ];
679
-
680
- // beforeEach(function () {
681
- // nock.cleanAll();
682
-
683
- // contextBrokerMock = nock('http://192.168.1.1:1026')
684
- // .matchHeader('fiware-service', 'smartgondor')
685
- // .matchHeader('fiware-servicepath', 'gardens')
686
- // .post(
687
- // '/v2/op/update',
688
- // utils.readExampleFile(
689
- // './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin10.json'
690
- // )
691
- // )
692
- // .reply(204);
693
- // });
694
-
695
- // it('should send the update value to the resulting value of the expression', function (done) {
696
- // iotAgentLib.update('ws9', 'WeatherStation8', '', values, function (error) {
697
- // should.not.exist(error);
698
- // contextBrokerMock.done();
699
- // done();
700
- // });
701
- // });
702
- // });
703
-
704
- // describe('When an update comes for a multientity with same entity_id and different entity_type with different attrs', function () {
705
- // const values = [
706
- // {
707
- // name: 'v',
708
- // type: 'Number',
709
- // value: 0
710
- // },
711
- // {
712
- // name: 'v1',
713
- // type: 'Number',
714
- // value: 1
715
- // },
716
- // {
717
- // name: 'v2',
718
- // type: 'Number',
719
- // value: 2
720
- // },
721
- // {
722
- // name: 'v3',
723
- // type: 'Number',
724
- // value: 3
725
- // }
726
- // ];
727
-
728
- // beforeEach(function () {
729
- // nock.cleanAll();
730
-
731
- // contextBrokerMock = nock('http://192.168.1.1:1026')
732
- // .matchHeader('fiware-service', 'smartgondor')
733
- // .matchHeader('fiware-servicepath', 'gardens')
734
- // .post(
735
- // '/v2/op/update',
736
- // utils.readExampleFile(
737
- // './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin12.json'
738
- // )
739
- // )
740
- // .reply(204);
741
- // });
742
-
743
- // it('should send the update value to three entities with different attribute names and different object_id', function (done) {
744
- // iotAgentLib.update('sh1', 'SharedIds1', '', values, function (error) {
745
- // should.not.exist(error);
746
- // contextBrokerMock.done();
747
- // done();
748
- // });
749
- // });
750
- // });
751
-
752
- // describe('When an update comes for a multientity with same entity_id and different entity_type whit shared attrs', function () {
753
- // const values = [
754
- // {
755
- // name: 'v',
756
- // type: 'Number',
757
- // value: 0
758
- // },
759
- // {
760
- // name: 'v1',
761
- // type: 'Number',
762
- // value: 1
763
- // },
764
- // {
765
- // name: 'v2',
766
- // type: 'Number',
767
- // value: 2
768
- // },
769
- // {
770
- // name: 'v3',
771
- // type: 'Number',
772
- // value: 3
773
- // }
774
- // ];
775
-
776
- // beforeEach(function () {
777
- // nock.cleanAll();
778
-
779
- // contextBrokerMock = nock('http://192.168.1.1:1026')
780
- // .matchHeader('fiware-service', 'smartgondor')
781
- // .matchHeader('fiware-servicepath', 'gardens')
782
- // .post(
783
- // '/v2/op/update',
784
- // utils.readExampleFile(
785
- // './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin13.json'
786
- // )
787
- // )
788
- // .reply(204);
789
- // });
790
-
791
- // it('should send the update value to three entities with same attribute names', function (done) {
792
- // iotAgentLib.update('sh2', 'SharedIds2', '', values, function (error) {
793
- // should.not.exist(error);
794
- // contextBrokerMock.done();
795
- // done();
796
- // });
797
- // });
798
- // });
799
-
800
- // FALLA
801
- describe('When an update comes for a multientity with same entity_id and different entity_type whit shared attrs and shared object_id', function () {
802
- const values = [
803
- {
804
- name: 'v',
805
- type: 'Number',
806
- value: 0
807
- }
808
- ];
809
-
810
- beforeEach(function () {
811
- nock.cleanAll();
812
-
813
- contextBrokerMock = nock('http://192.168.1.1:1026')
814
- .matchHeader('fiware-service', 'smartgondor')
815
- .matchHeader('fiware-servicepath', 'gardens')
816
- .post(
817
- '/v2/op/update',
818
- utils.readExampleFile(
819
- './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin14.json'
820
- )
821
- )
822
- .reply(204);
823
- });
824
-
825
- it('should send the update value to three entities with same attribute names', function (done) {
826
- iotAgentLib.update('sh3', 'SharedIds3', '', values, function (error) {
827
- should.not.exist(error);
828
- contextBrokerMock.done();
829
- done();
830
- });
831
- });
832
- });
833
-
834
- // describe('When an update comes for a multientity defined with an expression (multi values / multiple entities / same attribute) - JEXL', function () {
835
- // const values = [
836
- // {
837
- // name: 'v',
838
- // type: 'Number',
839
- // value: 0
840
- // },
841
- // {
842
- // name: 'v1',
843
- // type: 'Number',
844
- // value: 1
845
- // },
846
- // {
847
- // name: 'v2',
848
- // type: 'Number',
849
- // value: 2
850
- // }
851
- // ];
852
-
853
- // beforeEach(function () {
854
- // nock.cleanAll();
855
-
856
- // contextBrokerMock = nock('http://192.168.1.1:1026')
857
- // .matchHeader('fiware-service', 'smartgondor')
858
- // .matchHeader('fiware-servicepath', 'gardens')
859
- // .post(
860
- // '/v2/op/update',
861
- // utils.readExampleFile(
862
- // './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin10.json'
863
- // )
864
- // )
865
- // .reply(204);
866
- // });
867
-
868
- // it('should send the update value to the resulting value of the expression', function (done) {
869
- // iotAgentLib.update('ws9', 'WeatherStation8Jexl', '', values, function (error) {
870
- // should.not.exist(error);
871
- // contextBrokerMock.done();
872
- // done();
873
- // });
874
- // });
875
- // });
876
-
877
- // describe('When an update comes for a multientity measurement without type for one entity', function () {
878
- // const values = [
879
- // {
880
- // name: 'p',
881
- // type: 'centigrades',
882
- // value: '52'
883
- // },
884
- // {
885
- // name: 'h',
886
- // type: 'Percentage',
887
- // value: '12'
888
- // }
889
- // ];
890
-
891
- // beforeEach(function () {
892
- // nock.cleanAll();
893
-
894
- // contextBrokerMock = nock('http://192.168.1.1:1026')
895
- // .matchHeader('fiware-service', 'smartgondor')
896
- // .matchHeader('fiware-servicepath', 'gardens')
897
- // .post(
898
- // '/v2/op/update',
899
- // utils.readExampleFile(
900
- // './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin2.json'
901
- // )
902
- // )
903
- // .reply(204);
904
- // });
905
-
906
- // it('should use the device type as a default value', function (done) {
907
- // iotAgentLib.update('ws4', 'WeatherStation2', '', values, function (error) {
908
- // should.not.exist(error);
909
- // contextBrokerMock.done();
910
- // done();
911
- // });
912
- // });
913
- // });
914
-
915
- // describe(
916
- // 'When an update comes for a multientity measurement and there are attributes with' +
917
- // ' the same name but different alias and mapped to different CB entities',
918
- // function () {
919
- // const values = [
920
- // {
921
- // name: 'cont1',
922
- // type: 'number',
923
- // value: '38'
924
- // }
925
- // ];
926
-
927
- // beforeEach(function () {
928
- // nock.cleanAll();
929
-
930
- // contextBrokerMock = nock('http://192.168.1.1:1026')
931
- // .matchHeader('fiware-service', 'smartgondor')
932
- // .matchHeader('fiware-servicepath', 'gardens')
933
- // .post(
934
- // '/v2/op/update',
935
- // utils.readExampleFile(
936
- // './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin6.json'
937
- // )
938
- // )
939
- // .reply(204);
940
- // });
941
-
942
- // it('should update only the appropriate CB entity', function (done) {
943
- // iotAgentLib.update('Sensor', 'Sensor001', '', values, function (error) {
944
- // should.not.exist(error);
945
- // contextBrokerMock.done();
946
- // done();
947
- // });
948
- // });
949
- // }
950
- // );
951
-
952
- // describe(
953
- // 'When an update comes for a multientity multi measurement and there are attributes with' +
954
- // ' the same name but different alias and mapped to different CB entities',
955
- // function () {
956
- // const values = [
957
- // {
958
- // name: 'cont1',
959
- // type: 'number',
960
- // value: '38'
961
- // },
962
- // {
963
- // name: 'cont2',
964
- // type: 'number',
965
- // value: '39'
966
- // },
967
- // {
968
- // name: 'cont3',
969
- // type: 'number',
970
- // value: '40'
971
- // },
972
- // {
973
- // name: 'cont5',
974
- // type: 'number',
975
- // value: '42'
976
- // }
977
- // ];
978
-
979
- // beforeEach(function () {
980
- // nock.cleanAll();
981
-
982
- // contextBrokerMock = nock('http://192.168.1.1:1026')
983
- // .matchHeader('fiware-service', 'smartgondor')
984
- // .matchHeader('fiware-servicepath', 'gardens')
985
- // .post(
986
- // '/v2/op/update',
987
- // utils.readExampleFile(
988
- // './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin7.json'
989
- // )
990
- // )
991
- // .reply(204);
992
- // });
993
-
994
- // it('should update only the appropriate CB entity', function (done) {
995
- // iotAgentLib.update('Sensor', 'Sensor001', '', values, function (error) {
996
- // should.not.exist(error);
997
- // contextBrokerMock.done();
998
- // done();
999
- // });
1000
- // });
1001
- // }
1002
- // );
1003
- // });
1004
-
1005
- // describe('NGSI-v2 - Multi-entity plugin is executed before timestamp process plugin', function () {
1006
- // beforeEach(function (done) {
1007
- // logger.setLevel('FATAL');
1008
-
1009
- // iotAgentConfig.timestamp = true;
1010
- // iotAgentLib.activate(iotAgentConfig, function () {
1011
- // iotAgentLib.clearAll(function () {
1012
- // iotAgentLib.addUpdateMiddleware(iotAgentLib.dataPlugins.attributeAlias.update);
1013
- // iotAgentLib.addQueryMiddleware(iotAgentLib.dataPlugins.attributeAlias.query);
1014
- // iotAgentLib.addUpdateMiddleware(iotAgentLib.dataPlugins.multiEntity.update);
1015
- // iotAgentLib.addUpdateMiddleware(iotAgentLib.dataPlugins.timestampProcess.update);
1016
- // done();
1017
- // });
1018
- // });
1019
- // });
1020
-
1021
- // afterEach(function (done) {
1022
- // iotAgentLib.clearAll(function () {
1023
- // iotAgentLib.deactivate(done);
1024
- // });
1025
- // });
1026
-
1027
- // describe('When an update comes for a multientity measurement and timestamp is enabled in config file', function () {
1028
- // const values = [
1029
- // {
1030
- // name: 'p',
1031
- // type: 'centigrades',
1032
- // value: '52'
1033
- // },
1034
- // {
1035
- // name: 'h',
1036
- // type: 'Percentage',
1037
- // value: '12'
1038
- // },
1039
- // {
1040
- // name: 'TimeInstant',
1041
- // type: 'DateTime',
1042
- // value: '2016-05-30T16:25:22.304Z'
1043
- // }
1044
- // ];
1045
-
1046
- // const singleValue = [
1047
- // {
1048
- // name: 'h',
1049
- // type: 'Percentage',
1050
- // value: '12'
1051
- // }
1052
- // ];
1053
-
1054
- // beforeEach(function () {
1055
- // nock.cleanAll();
1056
- // });
1057
-
1058
- // it('should send two context elements, one for each entity', function (done) {
1059
- // contextBrokerMock = nock('http://192.168.1.1:1026')
1060
- // .matchHeader('fiware-service', 'smartgondor')
1061
- // .matchHeader('fiware-servicepath', 'gardens')
1062
- // .post('/v2/op/update', function (body) {
1063
- // const expectedBody = utils.readExampleFile(
1064
- // './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin1.json'
1065
- // );
1066
- // // Note that TimeInstant fields are not included in the json used by this mock as they are dynamic
1067
- // // fields. The following code just checks that TimeInstant fields are present.
1068
- // if (!body.entities[1].TimeInstant || !body.entities[1].humidity.metadata.TimeInstant) {
1069
- // return false;
1070
- // }
1071
-
1072
- // const timeInstantEntity = body.entities[1].TimeInstant;
1073
- // const timeInstantAtt = body.entities[1].humidity.metadata.TimeInstant;
1074
- // if (
1075
- // moment(timeInstantEntity, 'YYYY-MM-DDTHH:mm:ss.SSSZ').isValid &&
1076
- // moment(timeInstantAtt, 'YYYY-MM-DDTHH:mm:ss.SSSZ').isValid
1077
- // ) {
1078
- // delete body.entities[1].TimeInstant;
1079
- // delete body.entities[1].humidity.metadata.TimeInstant;
1080
-
1081
- // delete expectedBody.entities[1].TimeInstant;
1082
- // delete expectedBody.entities[1].humidity.metadata.TimeInstant;
1083
- // return JSON.stringify(body) === JSON.stringify(expectedBody);
1084
- // }
1085
- // return false;
1086
- // })
1087
- // .reply(204);
1088
-
1089
- // iotAgentLib.update('ws4', 'WeatherStation', '', values, function (error) {
1090
- // should.not.exist(error);
1091
- // contextBrokerMock.done();
1092
- // done();
1093
- // });
1094
- // });
1095
-
1096
- // it('should send two context elements, one for each entity', function (done) {
1097
- // contextBrokerMock = nock('http://192.168.1.1:1026')
1098
- // .matchHeader('fiware-service', 'smartgondor')
1099
- // .matchHeader('fiware-servicepath', 'gardens')
1100
- // .post('/v2/op/update', function (body) {
1101
- // const expectedBody = utils.readExampleFile(
1102
- // './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin2.json'
1103
- // );
1104
- // // Note that TimeInstant fields are not included in the json used by this mock as they are dynamic
1105
- // // fields. The following code just checks that TimeInstant fields are present.
1106
- // if (!body.entities[1].TimeInstant || !body.entities[1].humidity.metadata.TimeInstant) {
1107
- // return false;
1108
- // }
1109
-
1110
- // const timeInstantEntity2 = body.entities[1].TimeInstant;
1111
- // const timeInstantAtt = body.entities[1].humidity.metadata.TimeInstant;
1112
- // if (
1113
- // moment(timeInstantEntity2, 'YYYY-MM-DDTHH:mm:ss.SSSZ').isValid &&
1114
- // moment(timeInstantAtt, 'YYYY-MM-DDTHH:mm:ss.SSSZ').isValid
1115
- // ) {
1116
- // delete body.entities[1].TimeInstant;
1117
- // delete body.entities[1].humidity.metadata.TimeInstant;
1118
-
1119
- // delete expectedBody.entities[1].TimeInstant;
1120
- // delete expectedBody.entities[1].humidity.metadata.TimeInstant;
1121
- // return JSON.stringify(body) === JSON.stringify(expectedBody);
1122
- // }
1123
- // return false;
1124
- // })
1125
- // .reply(204);
1126
-
1127
- // iotAgentLib.update('ws4', 'WeatherStation', '', singleValue, function (error) {
1128
- // should.not.exist(error);
1129
- // contextBrokerMock.done();
1130
- // done();
1131
- // });
1132
- // });
1133
-
1134
- // it('should propagate user provider timestamp to mapped entities', function (done) {
1135
- // contextBrokerMock = nock('http://192.168.1.1:1026')
1136
- // .matchHeader('fiware-service', 'smartgondor')
1137
- // .matchHeader('fiware-servicepath', 'gardens')
1138
- // .post(
1139
- // '/v2/op/update',
1140
- // utils.readExampleFile(
1141
- // './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin3.json'
1142
- // )
1143
- // )
1144
- // .reply(204);
1145
-
1146
- // const tsValue = [
1147
- // {
1148
- // name: 'h',
1149
- // type: 'Percentage',
1150
- // value: '16'
1151
- // },
1152
- // {
1153
- // // Note this timestamp is the one used at updateContextMultientityTimestampPlugin3.json
1154
- // name: 'TimeInstant',
1155
- // type: 'DateTime',
1156
- // value: '2018-06-13T13:28:34.611Z'
1157
- // }
1158
- // ];
1159
-
1160
- // iotAgentLib.update('ws5', 'WeatherStation', '', tsValue, function (error) {
1161
- // should.not.exist(error);
1162
- // contextBrokerMock.done();
1163
- // done();
1164
- // });
1165
- // });
1166
- // });
1167
- // });
1168
-
1169
- // describe('NGSI-v2 - Multi-entity plugin is executed for a command update for a regular entity ', function () {
1170
- // beforeEach(function (done) {
1171
- // logger.setLevel('FATAL');
1172
-
1173
- // iotAgentConfig.timestamp = true;
1174
- // const time = new Date(1438760101468); // 2015-08-05T07:35:01.468+00:00
1175
- // timekeeper.freeze(time);
1176
- // iotAgentLib.activate(iotAgentConfig, function () {
1177
- // iotAgentLib.clearAll(function () {
1178
- // iotAgentLib.addUpdateMiddleware(iotAgentLib.dataPlugins.attributeAlias.update);
1179
- // iotAgentLib.addQueryMiddleware(iotAgentLib.dataPlugins.attributeAlias.query);
1180
- // iotAgentLib.addUpdateMiddleware(iotAgentLib.dataPlugins.multiEntity.update);
1181
- // iotAgentLib.addUpdateMiddleware(iotAgentLib.dataPlugins.timestampProcess.update);
1182
- // done();
1183
- // });
1184
- // });
1185
- // });
1186
-
1187
- // afterEach(function (done) {
1188
- // timekeeper.reset();
1189
- // iotAgentLib.clearAll(function () {
1190
- // iotAgentLib.deactivate(done);
1191
- // });
1192
- // });
1193
-
1194
- // it('Should send the update to the context broker', function (done) {
1195
- // contextBrokerMock = nock('http://192.168.1.1:1026')
1196
- // .matchHeader('fiware-service', 'smartgondor')
1197
- // .matchHeader('fiware-servicepath', 'gardens')
1198
- // .post(
1199
- // '/v2/op/update',
1200
- // utils.readExampleFile(
1201
- // './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin4.json'
1202
- // )
1203
- // )
1204
- // .reply(204);
1205
- // const commands = [
1206
- // {
1207
- // name: 'PING_status',
1208
- // type: 'commandStatus',
1209
- // value: 'OK'
1210
- // },
1211
- // {
1212
- // name: 'PING_info',
1213
- // type: 'commandResult',
1214
- // value: '1234567890'
1215
- // }
1216
- // ];
1217
-
1218
- // iotAgentLib.update('sensorCommand', 'SensorCommand', '', commands, function (error) {
1219
- // should.not.exist(error);
1220
- // contextBrokerMock.done();
1221
- // done();
1222
- // });
1223
- // });
1224
- });