iotagent-node-lib 2.21.0 → 2.24.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 (62) hide show
  1. package/.nyc_output/33364de2-1199-4ec2-b33c-cae063ef8cc4.json +1 -0
  2. package/.nyc_output/processinfo/{76bc24ff-5fac-4b5a-997d-de2799342eb0.json → 33364de2-1199-4ec2-b33c-cae063ef8cc4.json} +1 -1
  3. package/.nyc_output/processinfo/index.json +1 -1
  4. package/CHANGES_NEXT_RELEASE +0 -1
  5. package/doc/Contribution.md +3 -3
  6. package/doc/advanced-topics.md +73 -9
  7. package/doc/api.md +7 -5
  8. package/doc/architecture.md +52 -5
  9. package/doc/expressionLanguage.md +18 -3
  10. package/doc/operations.md +8 -5
  11. package/doc/usermanual.md +18 -16
  12. package/docker/Mosquitto/Dockerfile +1 -1
  13. package/lib/errors.js +9 -1
  14. package/lib/model/Group.js +2 -1
  15. package/lib/model/dbConn.js +4 -0
  16. package/lib/plugins/bidirectionalData.js +104 -6
  17. package/lib/plugins/expressionPlugin.js +18 -7
  18. package/lib/plugins/multiEntity.js +42 -29
  19. package/lib/plugins/pluginUtils.js +17 -0
  20. package/lib/request-shim.js +2 -1
  21. package/lib/services/commands/commandService.js +29 -2
  22. package/lib/services/common/iotManagerService.js +2 -1
  23. package/lib/services/devices/deviceService.js +35 -9
  24. package/lib/services/groups/groupRegistryMongoDB.js +13 -12
  25. package/lib/services/ngsi/entities-NGSI-LD.js +7 -0
  26. package/lib/services/ngsi/entities-NGSI-v2.js +70 -11
  27. package/lib/services/ngsi/ngsiService.js +1 -1
  28. package/lib/services/northBound/contextServer-NGSI-LD.js +110 -15
  29. package/lib/services/northBound/contextServer-NGSI-v2.js +8 -3
  30. package/lib/services/northBound/contextServerUtils.js +9 -9
  31. package/lib/services/northBound/deviceProvisioningServer.js +2 -1
  32. package/lib/templates/createDevice.json +1 -2
  33. package/lib/templates/createDeviceLax.json +2 -3
  34. package/lib/templates/updateDevice.json +1 -2
  35. package/package.json +24 -24
  36. package/test/unit/examples/deviceProvisioningRequests/provisionMinimumDevice4.json +14 -0
  37. package/test/unit/memoryRegistry/deviceRegistryMemory_test.js +51 -0
  38. package/test/unit/mongodb/mongoDBUtils.js +2 -2
  39. package/test/unit/mongodb/mongodb-group-registry-test.js +25 -1
  40. package/test/unit/mongodb/mongodb-registry-test.js +51 -3
  41. package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgentCommands.json +2 -1
  42. package/test/unit/ngsi-ld/examples/contextRequests/updateContextLanguageProperties1.json +15 -0
  43. package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotificationWithDatasetId.json +21 -0
  44. package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotificationWithMetadata.json +17 -0
  45. package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +995 -27
  46. package/test/unit/ngsi-ld/ngsiService/languageProperties-test.js +112 -0
  47. package/test/unit/ngsi-ld/ngsiService/unsupported-endpoints-test.js +111 -0
  48. package/test/unit/ngsi-ld/plugins/bidirectional-plugin_test.js +221 -0
  49. package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +1 -1
  50. package/test/unit/ngsiv2/examples/contextRequests/createMinimumProvisionedDevice4.json +8 -0
  51. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandStatus2.json +6 -0
  52. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin36.json +12 -1
  53. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin17.json +27 -0
  54. package/test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalNotificationWithMetadata.json +19 -0
  55. package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +10 -8
  56. package/test/unit/ngsiv2/lazyAndCommands/command-test.js +106 -0
  57. package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +151 -0
  58. package/test/unit/ngsiv2/plugins/bidirectional-plugin_test.js +115 -0
  59. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +63 -0
  60. package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +60 -0
  61. package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +2 -1
  62. package/.nyc_output/76bc24ff-5fac-4b5a-997d-de2799342eb0.json +0 -1
@@ -179,7 +179,7 @@ describe('MongoDB Group Registry test', function () {
179
179
  beforeEach(function (done) {
180
180
  mongoUtils.cleanDbs(function () {
181
181
  iotAgentLib.activate(iotAgentConfig, function () {
182
- mongo.connect('mongodb://localhost:27017/iotagent', { useNewUrlParser: true }, function (err, db) {
182
+ mongo.connect('mongodb://localhost:27017/iotagent', function (err, db) {
183
183
  iotAgentDb = db;
184
184
  done();
185
185
  });
@@ -448,4 +448,28 @@ describe('MongoDB Group Registry test', function () {
448
448
  });
449
449
  });
450
450
  });
451
+
452
+ describe('When the device info request with name and type', function () {
453
+ beforeEach(function (done) {
454
+ async.series([async.apply(request, optionsCreation)], done);
455
+ });
456
+
457
+ afterEach(function (done) {
458
+ iotAgentLib.clearRegistry(done);
459
+ });
460
+
461
+ it('should return the name and type of device', function (done) {
462
+ request(optionsGet, function (error, response, body) {
463
+ should.exist(body);
464
+ should.exist(body.count);
465
+ body.count.should.equal(1);
466
+ should.exist(body.services);
467
+ should.exist(body.services.length);
468
+ body.services.length.should.equal(1);
469
+ should.exist(body.services[0].entity_type);
470
+ body.services[0].entity_type.should.equal('Light');
471
+ done();
472
+ });
473
+ });
474
+ });
451
475
  });
@@ -25,7 +25,6 @@
25
25
 
26
26
  const iotAgentLib = require('../../../lib/fiware-iotagent-lib');
27
27
  const utils = require('../../tools/utils');
28
- const request = utils.request;
29
28
  const should = require('should');
30
29
  const logger = require('logops');
31
30
  const mongo = require('mongodb').MongoClient;
@@ -191,7 +190,7 @@ describe('NGSI-v2 - MongoDB Device Registry', function () {
191
190
  logger.setLevel('FATAL');
192
191
 
193
192
  mongoUtils.cleanDbs(function () {
194
- mongo.connect('mongodb://localhost:27017/iotagent', { useNewUrlParser: true }, function (err, db) {
193
+ mongo.connect('mongodb://localhost:27017/iotagent', function (err, db) {
195
194
  iotAgentDb = db;
196
195
  done();
197
196
  });
@@ -204,7 +203,7 @@ describe('NGSI-v2 - MongoDB Device Registry', function () {
204
203
  iotAgentDb
205
204
  .db()
206
205
  .collection('devices')
207
- .deleteOne(function (error) {
206
+ .deleteOne({}, function (error) {
208
207
  iotAgentDb.close(function (error) {
209
208
  mongoUtils.cleanDbs(done);
210
209
  });
@@ -508,4 +507,53 @@ describe('NGSI-v2 - MongoDB Device Registry', function () {
508
507
  });
509
508
  });
510
509
  });
510
+
511
+ describe('When the device is queried with the name and type', function () {
512
+ beforeEach(function (done) {
513
+ contextBrokerMock = nock('http://192.168.1.1:1026')
514
+ .post('/v2/entities?options=upsert')
515
+ .times(10)
516
+ .matchHeader('fiware-service', 'smartgondor')
517
+ .matchHeader('fiware-servicepath', 'gardens')
518
+ .reply(204);
519
+
520
+ const devices = [];
521
+
522
+ for (let i = 0; i < 10; i++) {
523
+ devices.push({
524
+ id: 'id' + i,
525
+ type: 'Light' + i,
526
+ internalId: 'internal' + i,
527
+ service: 'smartgondor',
528
+ subservice: 'gardens',
529
+ active: [
530
+ {
531
+ id: 'attrId',
532
+ type: 'attrType' + i,
533
+ value: i
534
+ }
535
+ ]
536
+ });
537
+ }
538
+ iotAgentLib.activate(iotAgentConfig, function (error) {
539
+ async.map(devices, iotAgentLib.register, function (error, results) {
540
+ done();
541
+ });
542
+ });
543
+ });
544
+ afterEach(function (done) {
545
+ iotAgentLib.clearRegistry(done);
546
+ });
547
+ it('should return the device with name and type', function (done) {
548
+ iotAgentLib.getDeviceByNameAndType('Light4:id4', 'Light4', 'smartgondor', 'gardens', function ( error, device ) {
549
+ should.not.exist(error);
550
+ should.exist(device);
551
+ should.exist(device.name);
552
+ should.exist(device.type);
553
+ device.name.should.equal('Light4:id4');
554
+ device.type.should.equal('Light4');
555
+ done();
556
+ });
557
+ });
558
+ });
511
559
  });
@@ -10,7 +10,8 @@
10
10
  }
11
11
  ],
12
12
  "properties": [
13
- "position"
13
+ "position",
14
+ "orientation"
14
15
  ]
15
16
  }
16
17
  ],
@@ -0,0 +1,15 @@
1
+ [
2
+ {
3
+ "@context": "http://context.json-ld",
4
+ "name": {
5
+ "type": "LanguageProperty",
6
+ "languageMap": {
7
+ "el": "Κωνσταντινούπολις",
8
+ "en": "Constantinople",
9
+ "tr": "İstanbul"
10
+ }
11
+ },
12
+ "id": "urn:ngsi-ld:Light:light1",
13
+ "type": "Light"
14
+ }
15
+ ]
@@ -0,0 +1,21 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "id": "TheFirstLight",
5
+ "location": [
6
+ {
7
+ "type": "GeoProperty",
8
+ "value": "12.4, -9.6",
9
+ "datasetId": "urn:ngsi-ld:Property:do-this"
10
+ },
11
+ {
12
+ "type": "GeoProperty",
13
+ "value": "6, 10",
14
+ "datasetId": "urn:ngsi-ld:Property:then-do-this"
15
+ }
16
+ ],
17
+ "type": "TheLightType"
18
+ }
19
+ ],
20
+ "subscriptionId": "51c0ac9ed714fb3b37d7d5a8"
21
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "id": "TheFirstLight",
5
+ "location": {
6
+ "type": "GeoProperty",
7
+ "value": "12.4, -9.6",
8
+ "qos": {
9
+ "type": "Property",
10
+ "value": 1
11
+ }
12
+ },
13
+ "type": "TheLightType"
14
+ }
15
+ ],
16
+ "subscriptionId": "51c0ac9ed714fb3b37d7d5a8"
17
+ }