iotagent-node-lib 4.6.0 → 4.8.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 (70) hide show
  1. package/.github/workflows/ci.yml +2 -3
  2. package/CHANGES_NEXT_RELEASE +1 -0
  3. package/Changelog +20 -0
  4. package/config.js +3 -1
  5. package/doc/README.md +1 -0
  6. package/doc/admin.md +39 -5
  7. package/doc/api.md +74 -9
  8. package/doc/devel/northboundinteractions.md +122 -15
  9. package/doc/models/models.md +260 -0
  10. package/doc/requirements.txt +1 -1
  11. package/docker/Mosquitto/Dockerfile +1 -1
  12. package/lib/commonConfig.js +21 -2
  13. package/lib/fiware-iotagent-lib.js +15 -11
  14. package/lib/jexlTranformsMap.js +182 -35
  15. package/lib/model/Command.js +11 -2
  16. package/lib/model/Device.js +8 -3
  17. package/lib/model/Group.js +5 -3
  18. package/lib/model/dbConn.js +53 -112
  19. package/lib/services/commands/commandRegistryMongoDB.js +130 -76
  20. package/lib/services/commands/commandService.js +3 -3
  21. package/lib/services/common/iotManagerService.js +3 -1
  22. package/lib/services/devices/deviceRegistryMemory.js +36 -0
  23. package/lib/services/devices/deviceRegistryMongoDB.js +161 -88
  24. package/lib/services/devices/deviceService.js +44 -5
  25. package/lib/services/devices/devices-NGSI-v2.js +6 -1
  26. package/lib/services/groups/groupRegistryMongoDB.js +120 -83
  27. package/lib/services/ngsi/entities-NGSI-v2.js +14 -1
  28. package/lib/services/ngsi/ngsiService.js +32 -1
  29. package/lib/services/northBound/contextServer-NGSI-v2.js +12 -3
  30. package/lib/services/northBound/contextServer.js +2 -1
  31. package/lib/services/northBound/deviceProvisioningServer.js +12 -3
  32. package/lib/services/northBound/northboundServer.js +1 -0
  33. package/lib/templates/createDevice.json +4 -0
  34. package/lib/templates/updateDevice.json +16 -0
  35. package/lib/templates/updateDeviceLax.json +12 -0
  36. package/package.json +4 -4
  37. package/test/functional/config-test.js +3 -2
  38. package/test/functional/testUtils.js +15 -4
  39. package/test/unit/examples/groupProvisioningRequests/provisionFullGroup.json +1 -0
  40. package/test/unit/expressions/jexlExpression-test.js +165 -1
  41. package/test/unit/general/config-multi-core-test.js +1 -2
  42. package/test/unit/general/contextBrokerKeystoneSecurityAccess-test.js +5 -4
  43. package/test/unit/general/deviceService-test.js +6 -5
  44. package/test/unit/memoryRegistry/deviceRegistryMemory_test.js +6 -5
  45. package/test/unit/mongodb/mongodb-connectionoptions-test.js +7 -39
  46. package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +1 -2
  47. package/test/unit/ngsi-ld/general/config-jsonld-contexts-test.js +1 -2
  48. package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +8 -5
  49. package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +42 -41
  50. package/test/unit/ngsiv2/general/contextBrokerOAuthSecurityAccess-test.js +11 -10
  51. package/test/unit/ngsiv2/general/deviceService-test.js +6 -5
  52. package/test/unit/ngsiv2/general/https-support-test.js +1 -1
  53. package/test/unit/ngsiv2/lazyAndCommands/active-devices-attribute-update-test.js +4 -3
  54. package/test/unit/ngsiv2/lazyAndCommands/command-test.js +6 -5
  55. package/test/unit/ngsiv2/lazyAndCommands/lazy-devices-test.js +17 -16
  56. package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +10 -18
  57. package/test/unit/ngsiv2/ngsiService/active-devices-test.js +21 -20
  58. package/test/unit/ngsiv2/ngsiService/staticAttributes-test.js +8 -7
  59. package/test/unit/ngsiv2/plugins/alias-plugin_test.js +12 -11
  60. package/test/unit/ngsiv2/plugins/custom-plugin_test.js +3 -2
  61. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +28 -27
  62. package/test/unit/ngsiv2/provisioning/device-group-api-test.js +6 -4
  63. package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +12 -11
  64. package/test/unit/ngsiv2/provisioning/device-provisioning-configGroup-api_test.js +11 -10
  65. package/test/unit/ngsiv2/provisioning/device-registration_test.js +5 -4
  66. package/test/unit/ngsiv2/provisioning/listProvisionedDevices-test.js +6 -5
  67. package/test/unit/ngsiv2/provisioning/provisionDeviceMultientity-test.js +1 -1
  68. package/test/unit/ngsiv2/provisioning/removeProvisionedDevice-test.js +5 -4
  69. package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +8 -7
  70. package/test/unit/ngsiv2/ngsiService/subscriptions-test.js +0 -326
@@ -40,7 +40,12 @@ describe('Jexl expression interpreter', function () {
40
40
  object: {
41
41
  name: 'John',
42
42
  surname: 'Doe'
43
- }
43
+ },
44
+ invalidJson: '{"name": "John", surname": "Doe"}', // Invalid JSON for jsonparse
45
+ invalidDate: 'invalid-date', // Invalid date for toisodate and other date functions
46
+ emptyArray: [], // Empty array for addreduce
47
+ invalidHex: 'zz', // Invalid hex string for hextostring
48
+ nonNumeric: 'not-a-number' // Non-numeric input for parseint, parsefloat
44
49
  };
45
50
 
46
51
  describe('When a expression with a single value is parsed', function () {
@@ -392,4 +397,163 @@ describe('Jexl expression interpreter', function () {
392
397
  });
393
398
  });
394
399
  });
400
+
401
+ // Check errors
402
+ describe('When invalid inputs are used', function () {
403
+ describe('When an invalid JSON string is parsed', function () {
404
+ it('should return null for jsonparse', function (done) {
405
+ expressionParser.parse('invalidJson|jsonparse', scope, function (error, result) {
406
+ should.not.exist(error);
407
+ should(result).be.Null();
408
+ done();
409
+ });
410
+ });
411
+ });
412
+
413
+ describe('When an invalid date string is parsed', function () {
414
+ it('should return null for toisodate', function (done) {
415
+ expressionParser.parse('invalidDate|toisodate', scope, function (error, result) {
416
+ should.not.exist(error);
417
+ should(result).be.Null();
418
+ done();
419
+ });
420
+ });
421
+
422
+ it('should return null for timeoffset', function (done) {
423
+ expressionParser.parse('invalidDate|timeoffset', scope, function (error, result) {
424
+ should.not.exist(error);
425
+ should(result).be.Null();
426
+ done();
427
+ });
428
+ });
429
+ });
430
+
431
+ describe('When an empty array is processed with addreduce', function () {
432
+ it('should return null for addreduce', function (done) {
433
+ expressionParser.parse('emptyArray|addreduce', scope, function (error, result) {
434
+ should.not.exist(error);
435
+ should(result).be.Null();
436
+ done();
437
+ });
438
+ });
439
+ });
440
+
441
+ describe('When a non-numeric string is parsed by parseint and parsefloat', function () {
442
+ it('should return null for parseint', function (done) {
443
+ expressionParser.parse('nonNumeric|parseint', scope, function (error, result) {
444
+ should.not.exist(error);
445
+ should(result).be.Null();
446
+ done();
447
+ });
448
+ });
449
+
450
+ it('should return null for parsefloat', function (done) {
451
+ expressionParser.parse('nonNumeric|parsefloat', scope, function (error, result) {
452
+ should.not.exist(error);
453
+ should(result).be.Null();
454
+ done();
455
+ });
456
+ });
457
+ });
458
+
459
+ describe('When an invalid hex string is processed by hextostring', function () {
460
+ it('should return null for hextostring', function (done) {
461
+ expressionParser.parse('invalidHex|hextostring', scope, function (error, result) {
462
+ should.not.exist(error);
463
+ should(result).be.Null();
464
+ done();
465
+ });
466
+ });
467
+ });
468
+
469
+ describe('When invalid regular expressions are used in replace functions', function () {
470
+ it('should return null for replaceregexp with invalid regex', function (done) {
471
+ expressionParser.parse(
472
+ 'theString|replaceregexp("[a-z", "replacement")',
473
+ scope,
474
+ function (error, result) {
475
+ should.not.exist(error);
476
+ should(result).be.Null();
477
+ done();
478
+ }
479
+ );
480
+ });
481
+
482
+ it('should return null for replaceallregexp with invalid regex', function (done) {
483
+ expressionParser.parse(
484
+ 'theString|replaceallregexp("[a-z", "replacement")',
485
+ scope,
486
+ function (error, result) {
487
+ should.not.exist(error);
488
+ should(result).be.Null();
489
+ done();
490
+ }
491
+ );
492
+ });
493
+ });
494
+
495
+ describe('When tostring is used with null or undefined', function () {
496
+ it('should return null for tostring(null)', function (done) {
497
+ expressionParser.parse('null|tostring', scope, function (error, result) {
498
+ should.not.exist(error);
499
+ should(result).be.Null();
500
+ done();
501
+ });
502
+ });
503
+
504
+ it('should return null for tostring(undefined)', function (done) {
505
+ expressionParser.parse('undefined|tostring', scope, function (error, result) {
506
+ should.not.exist(error);
507
+ should(result).be.Null();
508
+ done();
509
+ });
510
+ });
511
+ });
512
+
513
+ describe('When urldecode is used with an invalid URI', function () {
514
+ it('should return null for urldecode with malformed URI', function (done) {
515
+ expressionParser.parse('"%%%invalidURI"|urldecode', scope, function (error, result) {
516
+ should.not.exist(error);
517
+ should(result).be.Null();
518
+ done();
519
+ });
520
+ });
521
+ });
522
+
523
+ describe('When tofixed is used with invalid inputs', function () {
524
+ it('should return null for tofixed with non-numeric value', function (done) {
525
+ expressionParser.parse('"notANumber"|tofixed(2)', scope, function (error, result) {
526
+ should.not.exist(error);
527
+ should(result).be.Null();
528
+ done();
529
+ });
530
+ });
531
+
532
+ it('should return null for tofixed with invalid decimal value', function (done) {
533
+ expressionParser.parse('"123.456"|tofixed("invalid")', scope, function (error, result) {
534
+ should.not.exist(error);
535
+ should(result).be.Null();
536
+ done();
537
+ });
538
+ });
539
+ });
540
+
541
+ describe('When gettime is used with invalid date', function () {
542
+ it('should return null for gettime with invalid date string', function (done) {
543
+ expressionParser.parse('"invalidDate"|gettime', scope, function (error, result) {
544
+ should.not.exist(error);
545
+ should(result).be.Null();
546
+ done();
547
+ });
548
+ });
549
+
550
+ it('should return null for gettime with null', function (done) {
551
+ expressionParser.parse('null|gettime', scope, function (error, result) {
552
+ should.not.exist(error);
553
+ should(result).be.Null();
554
+ done();
555
+ });
556
+ });
557
+ });
558
+ });
395
559
  });
@@ -54,8 +54,7 @@ const iotAgentConfig = {
54
54
  }
55
55
  },
56
56
  providerUrl: 'http://smartgondor.com',
57
- deviceRegistrationDuration: 'P1M',
58
- throttling: 'PT5S'
57
+ deviceRegistrationDuration: 'P1M'
59
58
  };
60
59
 
61
60
  describe('Startup Multi-Core tests', function () {
@@ -85,7 +85,8 @@ const iotAgentConfig = {
85
85
  service: 'smartgondor',
86
86
  subservice: 'gardens',
87
87
  providerUrl: 'http://smartgondor.com',
88
- deviceRegistrationDuration: 'P1M'
88
+ deviceRegistrationDuration: 'P1M',
89
+ useCBflowControl: true
89
90
  };
90
91
 
91
92
  describe('NGSI-v2 - Secured access to the Context Broker with Keystone', function () {
@@ -128,7 +129,7 @@ describe('NGSI-v2 - Secured access to the Context Broker with Keystone', functio
128
129
  .matchHeader('fiware-service', 'smartgondor')
129
130
  .matchHeader('fiware-servicepath', 'electricity')
130
131
  .matchHeader('X-Auth-Token', '12345679ABCDEF')
131
- .post('/v2/entities?options=upsert')
132
+ .post('/v2/entities?options=upsert,flowControl')
132
133
  .reply(204);
133
134
  iotAgentLib.activate(iotAgentConfig, done);
134
135
  });
@@ -165,7 +166,7 @@ describe('NGSI-v2 - Secured access to the Context Broker with Keystone', functio
165
166
  .matchHeader('fiware-service', 'smartgondor')
166
167
  .matchHeader('fiware-servicepath', 'electricity')
167
168
  .matchHeader('X-Auth-Token', '12345679ABCDEF')
168
- .post('/v2/entities?options=upsert')
169
+ .post('/v2/entities?options=upsert,flowControl')
169
170
  .reply(403, { name: 'ACCESS_FORBIDDEN' });
170
171
 
171
172
  iotAgentLib.activate(iotAgentConfig, done);
@@ -197,7 +198,7 @@ describe('NGSI-v2 - Secured access to the Context Broker with Keystone', functio
197
198
  .matchHeader('fiware-service', 'smartgondor')
198
199
  .matchHeader('fiware-servicepath', 'electricity')
199
200
  .matchHeader('X-Auth-Token', '12345679ABCDEF')
200
- .post('/v2/entities?options=upsert');
201
+ .post('/v2/entities?options=upsert,flowControl');
201
202
 
202
203
  iotAgentLib.activate(iotAgentConfig, done);
203
204
  });
@@ -123,7 +123,8 @@ const iotAgentConfig = {
123
123
  service: 'smartgondor',
124
124
  subservice: 'gardens',
125
125
  providerUrl: 'http://smartgondor.com',
126
- deviceRegistrationDuration: 'P1M'
126
+ deviceRegistrationDuration: 'P1M',
127
+ useCBflowControl: true
127
128
  };
128
129
  const groupCreation = {
129
130
  url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/services',
@@ -222,7 +223,7 @@ describe('NGSI-v2 - Device Service: utils', function () {
222
223
  contextBrokerMock
223
224
  .matchHeader('fiware-service', 'testservice')
224
225
  .matchHeader('fiware-servicepath', '/testingPath')
225
- .post('/v2/entities?options=upsert')
226
+ .post('/v2/entities?options=upsert,flowControl')
226
227
  .reply(204);
227
228
 
228
229
  async.series(
@@ -255,7 +256,7 @@ describe('NGSI-v2 - Device Service: utils', function () {
255
256
  contextBrokerMock
256
257
  .matchHeader('fiware-service', 'testservice')
257
258
  .matchHeader('fiware-servicepath', '/testingPath')
258
- .post('/v2/entities?options=upsert')
259
+ .post('/v2/entities?options=upsert,flowControl')
259
260
  .reply(204);
260
261
 
261
262
  async.series(
@@ -290,7 +291,7 @@ describe('NGSI-v2 - Device Service: utils', function () {
290
291
  contextBrokerMock
291
292
  .matchHeader('fiware-service', 'testservice')
292
293
  .matchHeader('fiware-servicepath', '/testingPath')
293
- .post('/v2/entities?options=upsert')
294
+ .post('/v2/entities?options=upsert,flowControl')
294
295
  .reply(204);
295
296
 
296
297
  async.series([request.bind(request, groupCreation)], function (error, results) {
@@ -326,7 +327,7 @@ describe('NGSI-v2 - Device Service: utils', function () {
326
327
  contextBrokerMock
327
328
  .matchHeader('fiware-service', 'testservice')
328
329
  .matchHeader('fiware-servicepath', '/testingPath')
329
- .post('/v2/entities?options=upsert')
330
+ .post('/v2/entities?options=upsert,flowControl')
330
331
  .reply(204);
331
332
 
332
333
  async.series([request.bind(request, configGroupCreation)], function (error, results) {
@@ -48,7 +48,8 @@ const iotAgentConfig = {
48
48
  service: 'smartgondor',
49
49
  subservice: 'gardens',
50
50
  providerUrl: 'http://smartgondor.com',
51
- deviceRegistrationDuration: 'P1M'
51
+ deviceRegistrationDuration: 'P1M',
52
+ useCBflowControl: true
52
53
  };
53
54
  let contextBrokerMock;
54
55
 
@@ -64,7 +65,7 @@ describe('NGSI-v2 - In memory device registry', function () {
64
65
  describe('When a the registry is queried for a device using an arbitrary attribute', function () {
65
66
  beforeEach(function (done) {
66
67
  contextBrokerMock = nock('http://192.168.1.1:1026')
67
- .post('/v2/entities?options=upsert')
68
+ .post('/v2/entities?options=upsert,flowControl')
68
69
  .times(10)
69
70
  .matchHeader('fiware-service', 'smartgondor')
70
71
  .matchHeader('fiware-servicepath', 'gardens')
@@ -116,7 +117,7 @@ describe('NGSI-v2 - In memory device registry', function () {
116
117
  describe('When a the registry is queried for devices in multiple services', function () {
117
118
  beforeEach(function (done) {
118
119
  contextBrokerMock = nock('http://192.168.1.1:1026')
119
- .post('/v2/entities?options=upsert')
120
+ .post('/v2/entities?options=upsert,flowControl')
120
121
  .times(10)
121
122
  .reply(204);
122
123
 
@@ -159,7 +160,7 @@ describe('NGSI-v2 - In memory device registry', function () {
159
160
  describe('When a the registry is queried for devices in a particular service', function () {
160
161
  beforeEach(function (done) {
161
162
  contextBrokerMock = nock('http://192.168.1.1:1026')
162
- .post('/v2/entities?options=upsert')
163
+ .post('/v2/entities?options=upsert,flowControl')
163
164
  .times(10)
164
165
  .reply(204);
165
166
 
@@ -202,7 +203,7 @@ describe('NGSI-v2 - In memory device registry', function () {
202
203
  describe('When a the registry is queried for device in a particular name and type', function () {
203
204
  beforeEach(function (done) {
204
205
  contextBrokerMock = nock('http://192.168.1.1:1026')
205
- .post('/v2/entities?options=upsert')
206
+ .post('/v2/entities?options=upsert,flowControl')
206
207
  .times(10)
207
208
  .reply(204);
208
209
 
@@ -75,8 +75,6 @@ describe('dbConn.configureDb', function () {
75
75
  expected: {
76
76
  url: 'mongodb://example.com:27017/' + dbConn.DEFAULT_DB_NAME,
77
77
  options: {
78
- useNewUrlParser: true,
79
- useUnifiedTopology: true
80
78
  }
81
79
  }
82
80
  },
@@ -88,8 +86,6 @@ describe('dbConn.configureDb', function () {
88
86
  expected: {
89
87
  url: 'mongodb://example.com:98765/' + dbConn.DEFAULT_DB_NAME,
90
88
  options: {
91
- useNewUrlParser: true,
92
- useUnifiedTopology: true
93
89
  }
94
90
  }
95
91
  },
@@ -101,8 +97,6 @@ describe('dbConn.configureDb', function () {
101
97
  expected: {
102
98
  url: 'mongodb://example.com:27017/examples',
103
99
  options: {
104
- useNewUrlParser: true,
105
- useUnifiedTopology: true
106
100
  }
107
101
  }
108
102
  },
@@ -114,9 +108,7 @@ describe('dbConn.configureDb', function () {
114
108
  expected: {
115
109
  url: 'mongodb://example.com:27017/' + dbConn.DEFAULT_DB_NAME,
116
110
  options: {
117
- replicaSet: 'rs0',
118
- useNewUrlParser: true,
119
- useUnifiedTopology: true
111
+ replicaSet: 'rs0'
120
112
  }
121
113
  }
122
114
  },
@@ -128,8 +120,6 @@ describe('dbConn.configureDb', function () {
128
120
  expected: {
129
121
  url: 'mongodb://example.com:27017/' + dbConn.DEFAULT_DB_NAME,
130
122
  options: {
131
- useNewUrlParser: true,
132
- useUnifiedTopology: true
133
123
  }
134
124
  }
135
125
  },
@@ -141,8 +131,6 @@ describe('dbConn.configureDb', function () {
141
131
  expected: {
142
132
  url: 'mongodb://example.com:27017/' + dbConn.DEFAULT_DB_NAME,
143
133
  options: {
144
- useNewUrlParser: true,
145
- useUnifiedTopology: true
146
134
  }
147
135
  }
148
136
  },
@@ -158,9 +146,7 @@ describe('dbConn.configureDb', function () {
158
146
  auth: {
159
147
  user: 'user01',
160
148
  password: 'pass01'
161
- },
162
- useNewUrlParser: true,
163
- useUnifiedTopology: true
149
+ }
164
150
  }
165
151
  }
166
152
  },
@@ -172,8 +158,6 @@ describe('dbConn.configureDb', function () {
172
158
  expected: {
173
159
  url: 'mongodb://example.com:27017/' + dbConn.DEFAULT_DB_NAME,
174
160
  options: {
175
- useNewUrlParser: true,
176
- useUnifiedTopology: true
177
161
  }
178
162
  }
179
163
  },
@@ -194,9 +178,7 @@ describe('dbConn.configureDb', function () {
194
178
  auth: {
195
179
  user: 'user01',
196
180
  password: 'pass01'
197
- },
198
- useNewUrlParser: true,
199
- useUnifiedTopology: true
181
+ }
200
182
  }
201
183
  }
202
184
  },
@@ -208,9 +190,7 @@ describe('dbConn.configureDb', function () {
208
190
  expected: {
209
191
  url: 'mongodb://example.com:27017/' + dbConn.DEFAULT_DB_NAME,
210
192
  options: {
211
- ssl: true,
212
- useNewUrlParser: true,
213
- useUnifiedTopology: true
193
+ ssl: true
214
194
  }
215
195
  }
216
196
  },
@@ -224,8 +204,6 @@ describe('dbConn.configureDb', function () {
224
204
  expected: {
225
205
  url: 'mongodb://example.com:27017/' + dbConn.DEFAULT_DB_NAME + '?retryWrites=true',
226
206
  options: {
227
- useNewUrlParser: true,
228
- useUnifiedTopology: true
229
207
  }
230
208
  }
231
209
  },
@@ -243,8 +221,6 @@ describe('dbConn.configureDb', function () {
243
221
  dbConn.DEFAULT_DB_NAME +
244
222
  '?retryWrites=true&readPreference=nearest',
245
223
  options: {
246
- useNewUrlParser: true,
247
- useUnifiedTopology: true
248
224
  }
249
225
  }
250
226
  },
@@ -256,8 +232,6 @@ describe('dbConn.configureDb', function () {
256
232
  expected: {
257
233
  url: 'mongodb://example.com:27017/' + dbConn.DEFAULT_DB_NAME,
258
234
  options: {
259
- useNewUrlParser: true,
260
- useUnifiedTopology: true
261
235
  }
262
236
  }
263
237
  },
@@ -269,8 +243,6 @@ describe('dbConn.configureDb', function () {
269
243
  expected: {
270
244
  url: 'mongodb://example.com:27017/' + dbConn.DEFAULT_DB_NAME,
271
245
  options: {
272
- useNewUrlParser: true,
273
- useUnifiedTopology: true
274
246
  }
275
247
  }
276
248
  },
@@ -282,8 +254,6 @@ describe('dbConn.configureDb', function () {
282
254
  expected: {
283
255
  url: 'mongodb://example.com:27017/' + dbConn.DEFAULT_DB_NAME,
284
256
  options: {
285
- useNewUrlParser: true,
286
- useUnifiedTopology: true
287
257
  }
288
258
  }
289
259
  },
@@ -312,9 +282,7 @@ describe('dbConn.configureDb', function () {
312
282
  user: 'user01',
313
283
  password: 'pass01'
314
284
  },
315
- ssl: true,
316
- useNewUrlParser: true,
317
- useUnifiedTopology: true
285
+ ssl: true
318
286
  }
319
287
  }
320
288
  }
@@ -330,7 +298,7 @@ describe('dbConn.configureDb', function () {
330
298
  const cfg = Object.assign({}, iotAgentConfig, {
331
299
  mongodb: params.mongodb
332
300
  });
333
- stub = sinon.stub(mongoose, 'createConnection').callsFake(function (url, options, fn) {
301
+ stub = sinon.stub(mongoose, 'connect').callsFake(function (url, options, fn) {
334
302
  url.should.be.equal(params.expected.url);
335
303
  options.should.be.eql(params.expected.options);
336
304
  done();
@@ -365,7 +333,7 @@ describe('dbConn.configureDb', function () {
365
333
  const cfg = Object.assign({}, iotAgentConfig, {
366
334
  mongodb: params.mongodb
367
335
  });
368
- stub = sinon.stub(mongoose, 'createConnection').callsFake(function (url, options, fn) {
336
+ stub = sinon.stub(mongoose, 'connect').callsFake(function (url, options, fn) {
369
337
  should.fail();
370
338
  });
371
339
  config.setConfig(cfg);
@@ -253,8 +253,7 @@ const iotAgentConfig = {
253
253
  service: 'smartgondor',
254
254
  subservice: 'gardens',
255
255
  providerUrl: 'http://smartgondor.com',
256
- deviceRegistrationDuration: 'P1M',
257
- throttling: 'PT5S'
256
+ deviceRegistrationDuration: 'P1M'
258
257
  };
259
258
 
260
259
  const iotAgentConfigTS = {
@@ -59,8 +59,7 @@ const iotAgentConfig = {
59
59
  }
60
60
  },
61
61
  providerUrl: 'http://smartgondor.com',
62
- deviceRegistrationDuration: 'P1M',
63
- throttling: 'PT5S'
62
+ deviceRegistrationDuration: 'P1M'
64
63
  };
65
64
 
66
65
  describe('NGSI-LD - JSON-LD @context parsing from environment variable', function () {
@@ -55,7 +55,8 @@ const iotAgentConfig = {
55
55
  service: 'smartgondor',
56
56
  subservice: 'gardens',
57
57
  providerUrl: 'http://smartgondor.com',
58
- deviceRegistrationDuration: 'P1M'
58
+ deviceRegistrationDuration: 'P1M',
59
+ useCBflowControl: true
59
60
  };
60
61
  const mongo = require('mongodb').MongoClient;
61
62
  const mongoUtils = require('../../mongodb/mongoDBUtils');
@@ -68,6 +69,7 @@ const optionsCreationDefault = {
68
69
  apikey: 'default-test',
69
70
  entity_type: 'Device',
70
71
  resource: '/iot/default',
72
+ useCBflowControl: true,
71
73
  attributes: [
72
74
  {
73
75
  object_id: 's',
@@ -93,6 +95,7 @@ const optionsCreationV2 = {
93
95
  ngsiVersion: 'v2',
94
96
  entity_type: 'Device',
95
97
  resource: '/iot/v2',
98
+ useCBflowControl: true,
96
99
  attributes: [
97
100
  {
98
101
  object_id: 's',
@@ -189,7 +192,7 @@ describe('Mixed Mode: ngsiVersion test', function () {
189
192
  nock.cleanAll();
190
193
  contextBrokerMock = nock('http://192.168.1.1:1026')
191
194
  .matchHeader('fiware-service', 'smartgondor')
192
- .post('/v2/entities?options=upsert')
195
+ .post('/v2/entities?options=upsert,flowControl')
193
196
  .reply(204);
194
197
 
195
198
  request(optionsCreationDefault, function (error, response, body) {
@@ -210,7 +213,7 @@ describe('Mixed Mode: ngsiVersion test', function () {
210
213
  nock.cleanAll();
211
214
  contextBrokerMock = nock('http://192.168.1.1:1026')
212
215
  .matchHeader('fiware-service', 'smartgondor')
213
- .post('/v2/entities?options=upsert')
216
+ .post('/v2/entities?options=upsert,flowControl')
214
217
  .reply(204);
215
218
 
216
219
  request(optionsCreationV2, function (error, response, body) {
@@ -254,10 +257,10 @@ describe('Mixed Mode: ngsiVersion test', function () {
254
257
  // contextBrokerMock = nock('http://192.168.1.1:1026')
255
258
  // .matchHeader('fiware-service', 'smartgondor')
256
259
  // .matchHeader('fiware-servicepath', 'gardens')
257
- // .post('/v2/entities?options=upsert')
260
+ // .post('/v2/entities?options=upsert,flowControl')
258
261
  // .reply(204);
259
262
 
260
- // contextBrokerMock = nock('http://192.168.1.1:1026').post('/v2/entities?options=upsert').reply(204);
263
+ // contextBrokerMock = nock('http://192.168.1.1:1026').post('/v2/entities?options=upsert,flowControl').reply(204);
261
264
  // request(optionsCreationLD, function (error, response, body) {
262
265
  // request(deviceCreationV2, function (error, response, body) {
263
266
  // done();