iotagent-node-lib 2.19.0 → 2.22.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 (67) hide show
  1. package/.nyc_output/33364de2-1199-4ec2-b33c-cae063ef8cc4.json +1 -0
  2. package/.nyc_output/processinfo/33364de2-1199-4ec2-b33c-cae063ef8cc4.json +1 -0
  3. package/.nyc_output/processinfo/index.json +1 -0
  4. package/.readthedocs.yml +3 -1
  5. package/CHANGES_NEXT_RELEASE +1 -0
  6. package/README.md +5 -56
  7. package/doc/Contribution.md +3 -3
  8. package/doc/advanced-topics.md +8 -41
  9. package/doc/api.md +14 -3
  10. package/doc/expressionLanguage.md +17 -0
  11. package/doc/northboundinteractions.md +40 -33
  12. package/doc/operations.md +8 -5
  13. package/doc/requirements.txt +4 -0
  14. package/{docs → doc}/roadmap.md +21 -6
  15. package/doc/usermanual.md +4 -4
  16. package/docker/Mosquitto/Dockerfile +28 -12
  17. package/docker/Mosquitto/README.md +8 -7
  18. package/docker/Mosquitto/startMosquitto.sh +8 -0
  19. package/lib/fiware-iotagent-lib.js +1 -2
  20. package/lib/jexlTranformsMap.js +3 -1
  21. package/lib/model/Group.js +2 -1
  22. package/lib/model/dbConn.js +4 -0
  23. package/lib/plugins/expressionPlugin.js +56 -21
  24. package/lib/plugins/multiEntity.js +43 -49
  25. package/lib/plugins/pluginUtils.js +16 -0
  26. package/lib/services/commands/commandService.js +29 -2
  27. package/lib/services/common/domain.js +6 -2
  28. package/lib/services/common/iotManagerService.js +2 -1
  29. package/lib/services/devices/deviceRegistryMemory.js +13 -2
  30. package/lib/services/devices/deviceRegistryMongoDB.js +15 -7
  31. package/lib/services/devices/deviceService.js +52 -16
  32. package/lib/services/groups/groupRegistryMongoDB.js +13 -12
  33. package/lib/services/ngsi/entities-NGSI-LD.js +13 -4
  34. package/lib/services/ngsi/entities-NGSI-v2.js +8 -6
  35. package/lib/services/ngsi/ngsiService.js +3 -3
  36. package/lib/services/northBound/contextServer-NGSI-LD.js +20 -1
  37. package/lib/services/northBound/contextServer-NGSI-v2.js +39 -30
  38. package/lib/services/northBound/contextServerUtils.js +10 -10
  39. package/lib/services/northBound/deviceProvisioningServer.js +4 -1
  40. package/lib/templates/createDevice.json +13 -2
  41. package/lib/templates/createDeviceLax.json +2 -3
  42. package/lib/templates/updateDevice.json +13 -2
  43. package/package.json +27 -33
  44. package/test/unit/examples/deviceProvisioningRequests/provisionMinimumDevice4.json +14 -0
  45. package/test/unit/mongodb/mongoDBUtils.js +2 -2
  46. package/test/unit/mongodb/mongodb-group-registry-test.js +1 -1
  47. package/test/unit/mongodb/mongodb-registry-test.js +2 -3
  48. package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgentCommands.json +2 -1
  49. package/test/unit/ngsi-ld/examples/contextRequests/updateContextLanguageProperties1.json +15 -0
  50. package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +315 -1
  51. package/test/unit/ngsi-ld/ngsiService/languageProperties-test.js +112 -0
  52. package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +1 -1
  53. package/test/unit/ngsiv2/examples/contextRequests/createMinimumProvisionedDevice4.json +8 -0
  54. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandStatus2.json +6 -0
  55. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin35.json +2 -0
  56. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin36.json +1 -0
  57. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin17.json +27 -0
  58. package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +63 -2
  59. package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +151 -0
  60. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +63 -0
  61. package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +60 -0
  62. package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +2 -1
  63. package/bin/agentConsole.js +0 -257
  64. package/bin/iotAgentTester.js +0 -44
  65. package/lib/command/commandLine.js +0 -918
  66. package/lib/command/migration.js +0 -176
  67. package/test/unit/general/migration-test.js +0 -257
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "iotagent-node-lib",
3
3
  "license": "AGPL-3.0-only",
4
4
  "description": "IoT Agent library to interface with NGSI Context Broker",
5
- "version": "2.19.0",
5
+ "version": "2.22.0",
6
6
  "homepage": "https://github.com/telefonicaid/iotagent-node-lib",
7
7
  "keywords": [
8
8
  "fiware",
@@ -21,17 +21,13 @@
21
21
  "bugs": {
22
22
  "url": "https://github.com/telefonicaid/iotagent-node-lib/issues"
23
23
  },
24
- "bin": {
25
- "agentConsole": "bin/agentConsole.js",
26
- "iotAgentTester": "bin/iotAgentTester.js"
27
- },
28
24
  "main": "lib/fiware-iotagent-lib",
29
25
  "engines": {
30
26
  "node": ">=12"
31
27
  },
32
28
  "scripts": {
33
29
  "clean": "rm -rf package-lock.json && rm -rf node_modules && rm -rf coverage",
34
- "lint": "eslint lib/ bin/ test/ --cache --fix",
30
+ "lint": "eslint lib/ test/ --cache --fix",
35
31
  "lint:md": "remark -f '*.md' 'doc/*.md'",
36
32
  "lint:text": "textlint '*.md' 'doc/*.md'",
37
33
  "prettier": "prettier --config .prettierrc.json --write '**/**/**/**/*.js' '**/**/**/*.js' '**/**/*.js' '**/*.js' '*.js'",
@@ -46,44 +42,42 @@
46
42
  "watch": "watch 'npm test && npm run lint' ./lib ./test"
47
43
  },
48
44
  "dependencies": {
49
- "async": "2.6.2",
50
- "body-parser": "~1.19.0",
51
- "command-shell-lib": "1.0.0",
52
- "express": "~4.16.4",
53
- "got": "~11.8.2",
45
+ "async": "2.6.4",
46
+ "body-parser": "~1.20.0",
47
+ "express": "~4.18.1",
48
+ "got": "~11.8.5",
54
49
  "jexl": "2.3.0",
55
50
  "jison": "0.4.18",
56
51
  "logops": "2.1.2",
57
- "moment": "~2.24.0",
58
- "moment-timezone": "~0.5.25",
59
- "mongodb": "3.6.8",
60
- "mongoose": "5.7.7",
61
- "mu2": "~0.5.20",
62
- "query-string": "6.5.0",
52
+ "moment": "~2.29.2",
53
+ "moment-timezone": "~0.5.34",
54
+ "mongoose": "5.13.14",
55
+ "query-string": "7.1.1",
63
56
  "revalidator": "~0.3.1",
64
- "underscore": "~1.12.1",
65
- "uuid": "~3.3.2"
57
+ "underscore": "~1.13.4",
58
+ "uuid": "~8.3.2"
66
59
  },
67
60
  "devDependencies": {
68
- "coveralls": "~3.1.0",
69
- "eslint": "~7.5.0",
70
- "eslint-config-tamia": "~7.2.5",
71
- "eslint-plugin-prettier": "~3.1.4",
61
+ "coveralls": "~3.1.1",
62
+ "eslint": "~8.18.0",
63
+ "eslint-config-tamia": "~8.0.0",
64
+ "eslint-plugin-prettier": "~4.0.0",
72
65
  "husky": "~4.2.5",
73
- "lint-staged": "~10.2.11",
74
- "prettier": "~2.0.5",
75
- "mocha": "8.0.1",
76
- "nock": "13.0.3",
66
+ "lint-staged": "~12.3.8",
67
+ "mocha": "10.0.0",
68
+ "mongodb": "4.7.0",
69
+ "nock": "13.2.7",
77
70
  "nyc": "~15.1.0",
78
- "remark-cli": "~8.0.1",
79
- "remark-preset-lint-recommended": "~4.0.1",
71
+ "prettier": "~2.7.1",
72
+ "remark-cli": "~10.0.1",
73
+ "remark-preset-lint-recommended": "~6.1.2",
80
74
  "should": "13.2.3",
81
- "sinon": "~9.0.2",
82
- "textlint": "~11.7.6",
75
+ "sinon": "~14.0.0",
76
+ "textlint": "~12.2.1",
83
77
  "textlint-filter-rule-comments": "~1.2.2",
84
78
  "textlint-rule-common-misspellings": "~1.0.1",
85
- "textlint-rule-terminology": "~2.1.4",
86
- "textlint-rule-write-good": "~1.6.2",
79
+ "textlint-rule-terminology": "~3.0.2",
80
+ "textlint-rule-write-good": "~2.0.0",
87
81
  "timekeeper": "2.2.0",
88
82
  "watch": "~1.0.2"
89
83
  },
@@ -0,0 +1,14 @@
1
+ {
2
+ "devices": [
3
+ {
4
+ "device_id": "MicroLight1",
5
+ "protocol": "GENERIC_PROTO",
6
+ "attributes": [
7
+ {
8
+ "name": "attr_name",
9
+ "type": "string"
10
+ }
11
+ ]
12
+ }
13
+ ]
14
+ }
@@ -29,7 +29,7 @@ const async = require('async');
29
29
  function cleanDb(host, name, callback) {
30
30
  const url = 'mongodb://' + host + ':27017/' + name;
31
31
 
32
- MongoClient.connect(url, { useNewUrlParser: true }, function (err, db) {
32
+ MongoClient.connect(url, function (err, db) {
33
33
  if (db && db.db()) {
34
34
  db.db().dropDatabase(function (err, result) {
35
35
  db.close();
@@ -46,7 +46,7 @@ function cleanDbs(callback) {
46
46
  function populate(host, dbName, entityList, collectionName, callback) {
47
47
  const url = 'mongodb://' + host + ':27017/' + dbName;
48
48
 
49
- MongoClient.connect(url, { useNewUrlParser: true }, function (err, db) {
49
+ MongoClient.connect(url, function (err, db) {
50
50
  if (db) {
51
51
  db.db()
52
52
  .collection(collectionName)
@@ -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
  });
@@ -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
  });
@@ -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
+ ]
@@ -94,6 +94,10 @@ const iotAgentConfig = {
94
94
  {
95
95
  name: 'position',
96
96
  type: 'Array'
97
+ },
98
+ {
99
+ name: 'orientation',
100
+ type: 'Array'
97
101
  }
98
102
  ],
99
103
  lazy: [],
@@ -158,7 +162,114 @@ describe('NGSI-LD - Command functionalities', function () {
158
162
  });
159
163
  });
160
164
  });
161
- describe('When a command update arrives to the IoT Agent as Context Provider', function () {
165
+
166
+ describe('When multiple command updates via PATCH /attrs arrive to the IoT Agent as Context Provider', function () {
167
+ const options = {
168
+ url: 'http://localhost:' + iotAgentConfig.server.port + '/ngsi-ld/v1/entities/urn:ngsi-ld:Robot:r2d2/attrs',
169
+ method: 'PATCH',
170
+ json: {
171
+ orientation: {
172
+ type: 'Property',
173
+ value: [1, 2, 3]
174
+ },
175
+ position: {
176
+ type: 'Property',
177
+ value: [28, -104, 23]
178
+ }
179
+ },
180
+ headers: {
181
+ 'fiware-service': 'smartgondor',
182
+ 'content-type': 'application/ld+json'
183
+ }
184
+ };
185
+
186
+ beforeEach(function (done) {
187
+ logger.setLevel('ERROR');
188
+ iotAgentLib.register(device3, function (error) {
189
+ done();
190
+ });
191
+ });
192
+
193
+ it('should call the client handler once', function (done) {
194
+ let handlerCalled = 0;
195
+
196
+ iotAgentLib.setCommandHandler(function (id, type, service, subservice, attributes, callback) {
197
+ id.should.equal('urn:ngsi-ld:' + device3.type + ':' + device3.id);
198
+ type.should.equal(device3.type);
199
+ attributes[0].name.should.equal('position');
200
+ attributes[1].name.should.equal('orientation');
201
+ JSON.stringify(attributes[0].value).should.equal('[28,-104,23]');
202
+ JSON.stringify(attributes[1].value).should.equal('[1,2,3]');
203
+ handlerCalled++;
204
+ callback(null, {
205
+ id,
206
+ type,
207
+ attributes: [
208
+ {
209
+ name: 'position',
210
+ type: 'Array',
211
+ value: '[28, -104, 23]'
212
+ },
213
+ {
214
+ name: 'orientation',
215
+ type: 'Array',
216
+ value: '[1, 2, 3]'
217
+ }
218
+ ]
219
+ });
220
+ });
221
+
222
+ request(options, function (error, response, body) {
223
+ should.not.exist(error);
224
+ handlerCalled.should.equal(1);
225
+ done();
226
+ });
227
+ });
228
+ it('should create the attribute with the "_status" prefix in the Context Broker', function (done) {
229
+ iotAgentLib.setCommandHandler(function (id, type, service, subservice, attributes, callback) {
230
+ callback(null, {
231
+ id,
232
+ type,
233
+ attributes: [
234
+ {
235
+ name: 'position',
236
+ type: 'Array',
237
+ value: '[28, -104, 23]'
238
+ }
239
+ ]
240
+ });
241
+ });
242
+
243
+ request(options, function (error, response, body) {
244
+ should.not.exist(error);
245
+ done();
246
+ });
247
+ });
248
+ it('should create the attribute with the "_status" prefix in the Context Broker', function (done) {
249
+ let serviceReceived = false;
250
+ iotAgentLib.setCommandHandler(function (id, type, service, subservice, attributes, callback) {
251
+ serviceReceived = service === 'smartgondor';
252
+ callback(null, {
253
+ id,
254
+ type,
255
+ attributes: [
256
+ {
257
+ name: 'position',
258
+ type: 'Array',
259
+ value: '[28, -104, 23]'
260
+ }
261
+ ]
262
+ });
263
+ });
264
+
265
+ request(options, function (error, response, body) {
266
+ serviceReceived.should.equal(true);
267
+ done();
268
+ });
269
+ });
270
+ });
271
+
272
+ describe('When a command update PATCH attrs/attr-name arrives to the IoT Agent as Context Provider', function () {
162
273
  const options = {
163
274
  url:
164
275
  'http://localhost:' +
@@ -253,6 +364,209 @@ describe('NGSI-LD - Command functionalities', function () {
253
364
  });
254
365
  });
255
366
  });
367
+
368
+ describe('When multiple command overwrites via PUT /attrs arrive to the IoT Agent as Context Provider', function () {
369
+ const options = {
370
+ url: 'http://localhost:' + iotAgentConfig.server.port + '/ngsi-ld/v1/entities/urn:ngsi-ld:Robot:r2d2/attrs',
371
+ method: 'PUT',
372
+ json: {
373
+ orientation: {
374
+ type: 'Property',
375
+ value: [1, 2, 3]
376
+ },
377
+ position: {
378
+ type: 'Property',
379
+ value: [28, -104, 23]
380
+ }
381
+ },
382
+ headers: {
383
+ 'fiware-service': 'smartgondor',
384
+ 'content-type': 'application/ld+json'
385
+ }
386
+ };
387
+
388
+ beforeEach(function (done) {
389
+ logger.setLevel('ERROR');
390
+ iotAgentLib.register(device3, function (error) {
391
+ done();
392
+ });
393
+ });
394
+
395
+ it('should call the client handler once', function (done) {
396
+ let handlerCalled = 0;
397
+
398
+ iotAgentLib.setCommandHandler(function (id, type, service, subservice, attributes, callback) {
399
+ id.should.equal('urn:ngsi-ld:' + device3.type + ':' + device3.id);
400
+ type.should.equal(device3.type);
401
+ attributes[0].name.should.equal('position');
402
+ attributes[1].name.should.equal('orientation');
403
+ JSON.stringify(attributes[0].value).should.equal('[28,-104,23]');
404
+ JSON.stringify(attributes[1].value).should.equal('[1,2,3]');
405
+ handlerCalled++;
406
+ callback(null, {
407
+ id,
408
+ type,
409
+ attributes: [
410
+ {
411
+ name: 'position',
412
+ type: 'Array',
413
+ value: '[28, -104, 23]'
414
+ },
415
+ {
416
+ name: 'orientation',
417
+ type: 'Array',
418
+ value: '[1, 2, 3]'
419
+ }
420
+ ]
421
+ });
422
+ });
423
+
424
+ request(options, function (error, response, body) {
425
+ should.not.exist(error);
426
+ handlerCalled.should.equal(1);
427
+ done();
428
+ });
429
+ });
430
+ it('should create the attribute with the "_status" prefix in the Context Broker', function (done) {
431
+ iotAgentLib.setCommandHandler(function (id, type, service, subservice, attributes, callback) {
432
+ callback(null, {
433
+ id,
434
+ type,
435
+ attributes: [
436
+ {
437
+ name: 'position',
438
+ type: 'Array',
439
+ value: '[28, -104, 23]'
440
+ }
441
+ ]
442
+ });
443
+ });
444
+
445
+ request(options, function (error, response, body) {
446
+ should.not.exist(error);
447
+ done();
448
+ });
449
+ });
450
+ it('should create the attribute with the "_status" prefix in the Context Broker', function (done) {
451
+ let serviceReceived = false;
452
+ iotAgentLib.setCommandHandler(function (id, type, service, subservice, attributes, callback) {
453
+ serviceReceived = service === 'smartgondor';
454
+ callback(null, {
455
+ id,
456
+ type,
457
+ attributes: [
458
+ {
459
+ name: 'position',
460
+ type: 'Array',
461
+ value: '[28, -104, 23]'
462
+ }
463
+ ]
464
+ });
465
+ });
466
+
467
+ request(options, function (error, response, body) {
468
+ serviceReceived.should.equal(true);
469
+ done();
470
+ });
471
+ });
472
+ });
473
+
474
+ describe('When a command overwrite PUT attrs/attr-name arrives to the IoT Agent as Context Provider', function () {
475
+ const options = {
476
+ url:
477
+ 'http://localhost:' +
478
+ iotAgentConfig.server.port +
479
+ '/ngsi-ld/v1/entities/urn:ngsi-ld:Robot:r2d2/attrs/position',
480
+ method: 'PUT',
481
+ json: {
482
+ type: 'Property',
483
+ value: [28, -104, 23]
484
+ },
485
+ headers: {
486
+ 'fiware-service': 'smartgondor',
487
+ 'content-type': 'application/ld+json'
488
+ }
489
+ };
490
+
491
+ beforeEach(function (done) {
492
+ logger.setLevel('ERROR');
493
+ iotAgentLib.register(device3, function (error) {
494
+ done();
495
+ });
496
+ });
497
+
498
+ it('should call the client handler once', function (done) {
499
+ let handlerCalled = 0;
500
+
501
+ iotAgentLib.setCommandHandler(function (id, type, service, subservice, attributes, callback) {
502
+ id.should.equal('urn:ngsi-ld:' + device3.type + ':' + device3.id);
503
+ type.should.equal(device3.type);
504
+ attributes[0].name.should.equal('position');
505
+ JSON.stringify(attributes[0].value).should.equal('[28,-104,23]');
506
+ handlerCalled++;
507
+ callback(null, {
508
+ id,
509
+ type,
510
+ attributes: [
511
+ {
512
+ name: 'position',
513
+ type: 'Array',
514
+ value: '[28, -104, 23]'
515
+ }
516
+ ]
517
+ });
518
+ });
519
+
520
+ request(options, function (error, response, body) {
521
+ should.not.exist(error);
522
+ handlerCalled.should.equal(1);
523
+ done();
524
+ });
525
+ });
526
+ it('should create the attribute with the "_status" prefix in the Context Broker', function (done) {
527
+ iotAgentLib.setCommandHandler(function (id, type, service, subservice, attributes, callback) {
528
+ callback(null, {
529
+ id,
530
+ type,
531
+ attributes: [
532
+ {
533
+ name: 'position',
534
+ type: 'Array',
535
+ value: '[28, -104, 23]'
536
+ }
537
+ ]
538
+ });
539
+ });
540
+
541
+ request(options, function (error, response, body) {
542
+ should.not.exist(error);
543
+ done();
544
+ });
545
+ });
546
+ it('should create the attribute with the "_status" prefix in the Context Broker', function (done) {
547
+ let serviceReceived = false;
548
+ iotAgentLib.setCommandHandler(function (id, type, service, subservice, attributes, callback) {
549
+ serviceReceived = service === 'smartgondor';
550
+ callback(null, {
551
+ id,
552
+ type,
553
+ attributes: [
554
+ {
555
+ name: 'position',
556
+ type: 'Array',
557
+ value: '[28, -104, 23]'
558
+ }
559
+ ]
560
+ });
561
+ });
562
+
563
+ request(options, function (error, response, body) {
564
+ serviceReceived.should.equal(true);
565
+ done();
566
+ });
567
+ });
568
+ });
569
+
256
570
  describe('When an update arrives from the south bound for a registered command', function () {
257
571
  beforeEach(function (done) {
258
572
  statusAttributeMock = nock('http://192.168.1.1:1026')
@@ -0,0 +1,112 @@
1
+ /*
2
+ * Copyright 2022 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 request = utils.request;
31
+ const should = require('should');
32
+ const logger = require('logops');
33
+ const nock = require('nock');
34
+ let contextBrokerMock;
35
+ const iotAgentConfig = {
36
+ autocast: true,
37
+ contextBroker: {
38
+ host: '192.168.1.1',
39
+ port: '1026',
40
+ ngsiVersion: 'ld',
41
+ jsonLdContext: 'http://context.json-ld'
42
+ },
43
+ server: {
44
+ port: 4041
45
+ },
46
+ types: {
47
+ Light: {
48
+ commands: [],
49
+ type: 'Light',
50
+ active: [
51
+ {
52
+ name: 'name',
53
+ type: 'LanguageProperty'
54
+ }
55
+ ]
56
+ }
57
+ },
58
+ service: 'smartgondor',
59
+ subservice: 'gardens',
60
+ providerUrl: 'http://smartgondor.com'
61
+ };
62
+
63
+ describe('NGSI-LD - LanguageProperty test', function () {
64
+ beforeEach(function () {
65
+ logger.setLevel('FATAL');
66
+ });
67
+
68
+ afterEach(function (done) {
69
+ iotAgentLib.deactivate(done);
70
+ });
71
+
72
+ describe(
73
+ 'When the IoT Agent receives new exonym from a device name with LanguageProperty type and a JSON object',
74
+ function () {
75
+ const values = [
76
+ {
77
+ name: 'name',
78
+ type: 'LanguageProperty',
79
+ value: {
80
+ el: "Κωνσταντινούπολις",
81
+ en: "Constantinople",
82
+ tr: "İstanbul"
83
+ }
84
+ }
85
+ ];
86
+
87
+ beforeEach(function (done) {
88
+ nock.cleanAll();
89
+
90
+ contextBrokerMock = nock('http://192.168.1.1:1026')
91
+ .matchHeader('fiware-service', 'smartgondor')
92
+ .post(
93
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
94
+ utils.readExampleFile(
95
+ './test/unit/ngsi-ld/examples/contextRequests/updateContextLanguageProperties1.json'
96
+ )
97
+ )
98
+ .reply(204);
99
+
100
+ iotAgentLib.activate(iotAgentConfig, done);
101
+ });
102
+
103
+ it('should change the value of the corresponding attribute in the context broker', function (done) {
104
+ iotAgentLib.update('light1', 'Light', '', values, function (error) {
105
+ should.not.exist(error);
106
+ contextBrokerMock.done();
107
+ done();
108
+ });
109
+ });
110
+ }
111
+ );
112
+ });
@@ -171,7 +171,7 @@ describe('Mixed Mode: ngsiVersion test', function () {
171
171
  beforeEach(function (done) {
172
172
  mongoUtils.cleanDbs(function () {
173
173
  iotAgentLib.activate(iotAgentConfig, function () {
174
- mongo.connect('mongodb://localhost:27017/iotagent', { useNewUrlParser: true }, function (err, db) {
174
+ mongo.connect('mongodb://localhost:27017/iotagent', function (err, db) {
175
175
  iotAgentDb = db;
176
176
  done();
177
177
  });
@@ -0,0 +1,8 @@
1
+ {
2
+ "id": "EntityNameByExp",
3
+ "type": "MicroLights",
4
+ "attr_name": {
5
+ "type": "string",
6
+ "value": null
7
+ }
8
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "positionExp_status": {
3
+ "type": "commandStatus",
4
+ "value": "PENDING"
5
+ }
6
+ }
@@ -0,0 +1 @@
1
+ {"myattr":{"type": "String","value": "location"}}