iotagent-node-lib 3.1.0 → 3.3.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 (163) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.yml +134 -0
  2. package/.github/ISSUE_TEMPLATE/config.yml +16 -0
  3. package/.github/ISSUE_TEMPLATE/feature_request.yml +55 -0
  4. package/.github/advanced-issue-labeler.yml +30 -0
  5. package/.github/workflows/issue-labeler.yml +43 -0
  6. package/CHANGES_NEXT_RELEASE +0 -2
  7. package/config.js +5 -5
  8. package/doc/api.md +1483 -298
  9. package/doc/deprecated.md +7 -1
  10. package/doc/development.md +120 -0
  11. package/doc/howto.md +58 -62
  12. package/doc/installationguide.md +3 -11
  13. package/doc/requirements.txt +1 -1
  14. package/docker/Mosquitto/Dockerfile +1 -1
  15. package/lib/commonConfig.js +7 -10
  16. package/lib/fiware-iotagent-lib.js +0 -10
  17. package/lib/jexlTranformsMap.js +2 -1
  18. package/lib/model/Device.js +0 -1
  19. package/lib/model/Group.js +0 -1
  20. package/lib/model/dbConn.js +1 -7
  21. package/lib/plugins/bidirectionalData.js +8 -26
  22. package/lib/plugins/expressionPlugin.js +8 -40
  23. package/lib/plugins/jexlParser.js +28 -0
  24. package/lib/services/commands/commandService.js +1 -1
  25. package/lib/services/common/iotManagerService.js +0 -1
  26. package/lib/services/devices/deviceRegistryMongoDB.js +10 -10
  27. package/lib/services/devices/deviceService.js +16 -20
  28. package/lib/services/devices/devices-NGSI-v2.js +2 -5
  29. package/lib/services/ngsi/entities-NGSI-LD.js +16 -60
  30. package/lib/services/ngsi/entities-NGSI-v2.js +179 -119
  31. package/lib/services/northBound/deviceProvisioningServer.js +17 -17
  32. package/lib/templates/createDevice.json +5 -6
  33. package/lib/templates/createDeviceLax.json +6 -8
  34. package/lib/templates/deviceGroup.json +1 -5
  35. package/lib/templates/updateDevice.json +9 -2
  36. package/lib/templates/updateDeviceLax.json +14 -5
  37. package/package.json +1 -1
  38. package/scripts/legacy_expression_tool/README.md +262 -0
  39. package/scripts/legacy_expression_tool/legacy_expression_tool.py +423 -0
  40. package/scripts/legacy_expression_tool/requirements.txt +3 -0
  41. package/test/unit/examples/deviceProvisioningRequests/provisionBidirectionalDevice.json +5 -5
  42. package/test/unit/examples/groupProvisioningRequests/bidirectionalGroup.json +4 -4
  43. package/test/unit/general/contextBrokerKeystoneSecurityAccess-test.js +3 -13
  44. package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +0 -2
  45. package/test/unit/ngsi-ld/lazyAndCommands/merge-patch-test.js +31 -30
  46. package/test/unit/ngsi-ld/plugins/bidirectional-plugin_test.js +8 -8
  47. package/test/unit/ngsi-ld/plugins/custom-plugin_test.js +152 -0
  48. package/test/unit/ngsi-ld/plugins/multientity-plugin_test.js +1 -1
  49. package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +33 -37
  50. package/test/unit/ngsiv2/examples/contextRequests/createMinimumProvisionedDevice4.json +5 -1
  51. package/test/unit/ngsiv2/examples/contextRequests/updateContext.json +2 -0
  52. package/test/unit/ngsiv2/examples/contextRequests/updateContext1.json +3 -1
  53. package/test/unit/ngsiv2/examples/contextRequests/updateContext3WithStatic.json +2 -0
  54. package/test/unit/ngsiv2/examples/contextRequests/updateContext4.json +4 -1
  55. package/test/unit/ngsiv2/examples/contextRequests/updateContext5.json +12 -0
  56. package/test/unit/ngsiv2/examples/contextRequests/updateContext6.json +10 -0
  57. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin1.json +2 -0
  58. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin2.json +3 -1
  59. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin3.json +3 -1
  60. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin4.json +3 -1
  61. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin5.json +3 -1
  62. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin6.json +3 -1
  63. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin7.json +3 -1
  64. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin8.json +3 -1
  65. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin9.json +3 -1
  66. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast1.json +2 -0
  67. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast2.json +2 -0
  68. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast3.json +3 -1
  69. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast4.json +3 -1
  70. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast5.json +3 -1
  71. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast6.json +3 -1
  72. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast7.json +3 -1
  73. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandError.json +3 -1
  74. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandExpired.json +3 -1
  75. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandFinish.json +3 -1
  76. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandStatus.json +2 -0
  77. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandStatus2.json +2 -0
  78. package/test/unit/ngsiv2/examples/contextRequests/updateContextCompressTimestamp1.json +3 -1
  79. package/test/unit/ngsiv2/examples/contextRequests/updateContextCompressTimestamp2.json +3 -1
  80. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin1.json +2 -0
  81. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin11.json +2 -0
  82. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin12.json +2 -0
  83. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin13.json +3 -1
  84. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin2.json +2 -0
  85. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin29.json +2 -0
  86. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin3.json +2 -0
  87. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin30.json +2 -0
  88. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin31.json +2 -8
  89. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin32.json +2 -0
  90. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin33.json +2 -0
  91. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin34.json +2 -0
  92. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin35.json +22 -0
  93. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin36.json +1 -0
  94. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin4.json +2 -0
  95. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin40.json +42 -0
  96. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin41.json +33 -0
  97. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin5.json +2 -0
  98. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin6.json +2 -0
  99. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin7.json +2 -0
  100. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin8.json +2 -0
  101. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin9.json +2 -0
  102. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionSkip.json +12 -0
  103. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityJexlExpressionPlugin1.json +1 -1
  104. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin1.json +1 -1
  105. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin10.json +1 -1
  106. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin11.json +1 -1
  107. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin12.json +1 -1
  108. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin13.json +1 -1
  109. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin14.json +1 -1
  110. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin15.json +1 -1
  111. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin16.json +1 -1
  112. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin17.json +1 -1
  113. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin2.json +1 -1
  114. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin25.json +37 -0
  115. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin3.json +1 -1
  116. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin4.json +1 -1
  117. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin5.json +1 -1
  118. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin6.json +1 -1
  119. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin7.json +1 -1
  120. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin8.json +1 -1
  121. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin9.json +1 -1
  122. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +1 -1
  123. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +1 -1
  124. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin3.json +1 -1
  125. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin4.json +2 -0
  126. package/test/unit/ngsiv2/examples/contextRequests/updateContextProcessTimestamp.json +2 -0
  127. package/test/unit/ngsiv2/examples/contextRequests/updateContextStaticAttributes.json +2 -0
  128. package/test/unit/ngsiv2/examples/contextRequests/updateContextStaticAttributesMetadata.json +3 -1
  129. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestamp.json +3 -1
  130. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampFalse.json +12 -0
  131. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampFalseTimeInstant.json +12 -0
  132. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampOverride.json +2 -0
  133. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampOverrideWithoutMilis.json +2 -0
  134. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampTimezone.json +3 -1
  135. package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +355 -75
  136. package/test/unit/ngsiv2/general/contextBrokerOAuthSecurityAccess-test.js +18 -51
  137. package/test/unit/ngsiv2/general/https-support-test.js +1 -5
  138. package/test/unit/ngsiv2/lazyAndCommands/command-test.js +4 -10
  139. package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +9 -26
  140. package/test/unit/ngsiv2/ngsiService/active-devices-test.js +143 -57
  141. package/test/unit/ngsiv2/ngsiService/autocast-test.js +14 -21
  142. package/test/unit/ngsiv2/ngsiService/staticAttributes-test.js +3 -5
  143. package/test/unit/ngsiv2/ngsiService/subscriptions-test.js +1 -10
  144. package/test/unit/ngsiv2/plugins/alias-plugin_test.js +20 -30
  145. package/test/unit/ngsiv2/plugins/bidirectional-plugin_test.js +6 -69
  146. package/test/unit/ngsiv2/plugins/compress-timestamp-plugin_test.js +4 -6
  147. package/test/unit/ngsiv2/plugins/custom-plugin_test.js +150 -0
  148. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +87 -16
  149. package/test/unit/ngsiv2/plugins/timestamp-processing-plugin_test.js +2 -3
  150. package/test/unit/ngsiv2/provisioning/device-group-api-test.js +2 -3
  151. package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +15 -55
  152. package/test/unit/ngsiv2/provisioning/device-registration_test.js +1 -7
  153. package/test/unit/ngsiv2/provisioning/device-update-registration_test.js +2 -9
  154. package/test/unit/ngsiv2/provisioning/singleConfigurationMode-test.js +0 -11
  155. package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +0 -7
  156. package/test/unit/plugins/capture-provision-inPlugins_test.js +0 -6
  157. package/doc/advanced-topics.md +0 -626
  158. package/doc/expressionLanguage.md +0 -762
  159. package/lib/plugins/expressionParser.js +0 -205
  160. package/test/unit/expressions/expression-test.js +0 -197
  161. package/test/unit/ngsi-ld/expressions/expressionBasedTransformations-test.js +0 -882
  162. package/test/unit/ngsiv2/expressions/expressionBasedTransformations-test.js +0 -951
  163. package/test/unit/ngsiv2/expressions/expressionCombinedTransformations-test.js +0 -296
@@ -95,15 +95,6 @@ describe('NGSI-v2 - Bidirectional data plugin', function () {
95
95
  )
96
96
  )
97
97
  .reply(201, null, { Location: '/v2/subscriptions/51c0ac9ed714fb3b37d7d5a8' });
98
-
99
- contextBrokerMock
100
- .matchHeader('fiware-service', 'smartgondor')
101
- .matchHeader('fiware-servicepath', '/gardens')
102
- .post(
103
- '/v2/entities?options=upsert',
104
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/createBidirectionalDevice.json')
105
- )
106
- .reply(204);
107
98
  });
108
99
 
109
100
  it('should subscribe to the modification of the combined attribute with all the variables', function (done) {
@@ -137,15 +128,6 @@ describe('NGSI-v2 - Bidirectional data plugin', function () {
137
128
  )
138
129
  .reply(201, null, { Location: '/v2/subscriptions/51c0ac9ed714fb3b37d7d5a8' });
139
130
 
140
- contextBrokerMock
141
- .matchHeader('fiware-service', 'smartgondor')
142
- .matchHeader('fiware-servicepath', '/gardens')
143
- .post(
144
- '/v2/entities?options=upsert',
145
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/createBidirectionalDevice.json')
146
- )
147
- .reply(204);
148
-
149
131
  contextBrokerMock
150
132
  .matchHeader('fiware-service', 'smartgondor')
151
133
  .matchHeader('fiware-servicepath', '/gardens')
@@ -189,15 +171,6 @@ describe('NGSI-v2 - Bidirectional data plugin', function () {
189
171
  )
190
172
  )
191
173
  .reply(201, null, { Location: '/v2/subscriptions/51c0ac9ed714fb3b37d7d5a8' });
192
-
193
- contextBrokerMock
194
- .matchHeader('fiware-service', 'smartgondor')
195
- .matchHeader('fiware-servicepath', '/gardens')
196
- .post(
197
- '/v2/entities?options=upsert',
198
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/createBidirectionalDevice.json')
199
- )
200
- .reply(204);
201
174
  });
202
175
 
203
176
  afterEach(function () {
@@ -246,11 +219,11 @@ describe('NGSI-v2 - Bidirectional data plugin', function () {
246
219
  let longitudeFound = false;
247
220
 
248
221
  for (let i = 0; i < values.length; i++) {
249
- if (values[i].name === 'latitude' && values[i].type === 'string' && values[i].value === '-9.6') {
222
+ if (values[i].name === 'latitude' && values[i].type === 'Number' && values[i].value === -9.6) {
250
223
  latitudeFound = true;
251
224
  }
252
225
 
253
- if (values[i].name === 'longitude' && values[i].type === 'string' && values[i].value === '12.4') {
226
+ if (values[i].name === 'longitude' && values[i].type === 'Number' && values[i].value === 12.4) {
254
227
  longitudeFound = true;
255
228
  }
256
229
  }
@@ -296,15 +269,6 @@ describe('NGSI-v2 - Bidirectional data plugin', function () {
296
269
  )
297
270
  )
298
271
  .reply(201, null, { Location: '/v2/subscriptions/51c0ac9ed714fb3b37d7d5a8' });
299
-
300
- contextBrokerMock
301
- .matchHeader('fiware-service', 'smartgondor')
302
- .matchHeader('fiware-servicepath', '/gardens')
303
- .post(
304
- '/v2/entities?options=upsert',
305
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/createBidirectionalDevice.json')
306
- )
307
- .reply(204);
308
272
  });
309
273
 
310
274
  afterEach(function () {
@@ -357,11 +321,11 @@ describe('NGSI-v2 - Bidirectional data plugin', function () {
357
321
  let longitudeFound = false;
358
322
 
359
323
  for (let i = 0; i < values.length; i++) {
360
- if (values[i].name === 'latitude' && values[i].type === 'string' && values[i].value === '-9.6') {
324
+ if (values[i].name === 'latitude' && values[i].type === 'Number' && values[i].value === -9.6) {
361
325
  latitudeFound = true;
362
326
  }
363
327
 
364
- if (values[i].name === 'longitude' && values[i].type === 'string' && values[i].value === '12.4') {
328
+ if (values[i].name === 'longitude' && values[i].type === 'Number' && values[i].value === 12.4) {
365
329
  longitudeFound = true;
366
330
  }
367
331
  }
@@ -415,15 +379,6 @@ describe('NGSI-v2 - Bidirectional data plugin', function () {
415
379
  )
416
380
  )
417
381
  .reply(201, null, { Location: '/v2/subscriptions/51c0ac9ed714fb3b37d7d5a8' });
418
-
419
- contextBrokerMock
420
- .matchHeader('fiware-service', 'smartgondor')
421
- .matchHeader('fiware-servicepath', '/gardens')
422
- .post(
423
- '/v2/entities?options=upsert',
424
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/createBidirectionalDevice.json')
425
- )
426
- .reply(204);
427
382
  });
428
383
  it('should subscribe to the modification of the combined attribute with all the variables', function (done) {
429
384
  request(provisionGroup, function (error, response, body) {
@@ -480,15 +435,6 @@ describe('NGSI-v2 - Bidirectional data plugin', function () {
480
435
  )
481
436
  )
482
437
  .reply(201, null, { Location: '/v2/subscriptions/51c0ac9ed714fb3b37d7d5a8' });
483
-
484
- contextBrokerMock
485
- .matchHeader('fiware-service', 'smartgondor')
486
- .matchHeader('fiware-servicepath', '/gardens')
487
- .post(
488
- '/v2/entities?options=upsert',
489
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/createBidirectionalDevice.json')
490
- )
491
- .reply(204);
492
438
  });
493
439
 
494
440
  afterEach(function () {
@@ -503,11 +449,11 @@ describe('NGSI-v2 - Bidirectional data plugin', function () {
503
449
  let longitudeFound = false;
504
450
 
505
451
  for (let i = 0; i < values.length; i++) {
506
- if (values[i].name === 'latitude' && values[i].type === 'string' && values[i].value === '-9.6') {
452
+ if (values[i].name === 'latitude' && values[i].type === 'Number' && values[i].value === -9.6) {
507
453
  latitudeFound = true;
508
454
  }
509
455
 
510
- if (values[i].name === 'longitude' && values[i].type === 'string' && values[i].value === '12.4') {
456
+ if (values[i].name === 'longitude' && values[i].type === 'Number' && values[i].value === 12.4) {
511
457
  longitudeFound = true;
512
458
  }
513
459
  }
@@ -577,15 +523,6 @@ describe('NGSI-v2 - Bidirectional data plugin and CB is defined using environmen
577
523
  )
578
524
  )
579
525
  .reply(201, null, { Location: '/v2/subscriptions/51c0ac9ed714fb3b37d7d5a8' });
580
-
581
- contextBrokerMock
582
- .matchHeader('fiware-service', 'smartgondor')
583
- .matchHeader('fiware-servicepath', '/gardens')
584
- .post(
585
- '/v2/entities?options=upsert',
586
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/createBidirectionalDevice.json')
587
- )
588
- .reply(204);
589
526
  });
590
527
 
591
528
  it('should subscribe to the modification of the combined attribute with all the variables', function (done) {
@@ -153,13 +153,12 @@ describe('NGSI-v2 - Timestamp compression plugin', function () {
153
153
  contextBrokerMock = nock('http://192.168.1.1:1026')
154
154
  .matchHeader('fiware-service', 'smartgondor')
155
155
  .matchHeader('fiware-servicepath', 'gardens')
156
- .patch(
157
- '/v2/entities/light1/attrs',
156
+ .post(
157
+ '/v2/entities?options=upsert',
158
158
  utils.readExampleFile(
159
159
  './test/unit/ngsiv2/examples/contextRequests/updateContextCompressTimestamp1.json'
160
160
  )
161
161
  )
162
- .query({ type: 'Light' })
163
162
  .reply(204);
164
163
  });
165
164
 
@@ -198,13 +197,12 @@ describe('NGSI-v2 - Timestamp compression plugin', function () {
198
197
  contextBrokerMock = nock('http://192.168.1.1:1026')
199
198
  .matchHeader('fiware-service', 'smartgondor')
200
199
  .matchHeader('fiware-servicepath', 'gardens')
201
- .patch(
202
- '/v2/entities/light1/attrs',
200
+ .post(
201
+ '/v2/entities?options=upsert',
203
202
  utils.readExampleFile(
204
203
  './test/unit/ngsiv2/examples/contextRequests/updateContextCompressTimestamp2.json'
205
204
  )
206
205
  )
207
- .query({ type: 'Light' })
208
206
  .reply(204);
209
207
  });
210
208
 
@@ -0,0 +1,150 @@
1
+ /*
2
+ * Copyright 2015 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::daniel.moranjimenez@telefonica.com
22
+ *
23
+ * Modified by: Daniel Calvo - ATOS Research & Innovation
24
+ */
25
+
26
+ const iotAgentLib = require('../../../../lib/fiware-iotagent-lib');
27
+ const should = require('should');
28
+ const logger = require('logops');
29
+ const nock = require('nock');
30
+ let contextBrokerMock;
31
+ const iotAgentConfig = {
32
+ contextBroker: {
33
+ host: '192.168.1.1',
34
+ port: '1026',
35
+ ngsiVersion: 'v2'
36
+ },
37
+ server: {
38
+ port: 4041
39
+ },
40
+ types: {
41
+ Light: {
42
+ commands: [],
43
+ type: 'Light',
44
+ lazy: [
45
+ {
46
+ name: 'temperature',
47
+ type: 'centigrades'
48
+ }
49
+ ],
50
+ active: [
51
+ {
52
+ name: 'pressure',
53
+ type: 'Hgmm'
54
+ }
55
+ ]
56
+ }
57
+ },
58
+ service: 'smartgondor',
59
+ subservice: 'gardens',
60
+ providerUrl: 'http://smartgondor.com'
61
+ };
62
+
63
+ describe('NGSI-v2 - Custom plugin', function () {
64
+ let updateInvoked = false;
65
+ let queryInvoked = false;
66
+
67
+ function updatePlugin(entity, typeInformation, callback) {
68
+ updateInvoked = true;
69
+ return callback(null, entity, typeInformation);
70
+ }
71
+ function queryPlugin(entity, typeInformation, callback) {
72
+ queryInvoked = true;
73
+ return callback(null, entity, typeInformation);
74
+ }
75
+ beforeEach(function (done) {
76
+ logger.setLevel('FATAL');
77
+
78
+ iotAgentLib.activate(iotAgentConfig, function () {
79
+ iotAgentLib.clearAll(function () {
80
+ iotAgentLib.addUpdateMiddleware(updatePlugin);
81
+ iotAgentLib.addQueryMiddleware(queryPlugin);
82
+ done();
83
+ });
84
+ });
85
+ });
86
+
87
+ afterEach(function (done) {
88
+ iotAgentLib.clearAll(function () {
89
+ iotAgentLib.deactivate(done);
90
+ updateInvoked = false;
91
+ queryInvoked = false;
92
+ });
93
+ });
94
+ describe('When an update occurs', function () {
95
+ const values = [
96
+ {
97
+ name: 'state',
98
+ type: 'Boolean',
99
+ value: 'true'
100
+ },
101
+ {
102
+ name: 'dimming',
103
+ type: 'Number',
104
+ value: 23
105
+ }
106
+ ];
107
+
108
+ beforeEach(function () {
109
+ nock.cleanAll();
110
+
111
+ contextBrokerMock = nock('http://192.168.1.1:1026')
112
+ .matchHeader('fiware-service', 'smartgondor')
113
+ .matchHeader('fiware-servicepath', 'gardens')
114
+ .post('/v2/entities?options=upsert')
115
+ .reply(204);
116
+ });
117
+
118
+ it('should invoke the plugin', function (done) {
119
+ iotAgentLib.update('light1', 'Light', '', values, function (error) {
120
+ should.not.exist(error);
121
+ contextBrokerMock.done();
122
+ updateInvoked.should.equal(true);
123
+ done();
124
+ });
125
+ });
126
+ });
127
+ describe('When an query occurs', function () {
128
+ beforeEach(function () {
129
+ nock.cleanAll();
130
+
131
+ contextBrokerMock = nock('http://192.168.1.1:1026')
132
+ .matchHeader('fiware-service', 'smartgondor')
133
+ .matchHeader('fiware-servicepath', 'gardens')
134
+ .get('/v2/entities/light1/attrs')
135
+ .query({ type: 'Light', attrs: 'state,dimming' })
136
+ .reply(200, { state: 'good', dimming: '23' });
137
+ });
138
+
139
+ it('should invoke the plugin', function (done) {
140
+ const attributes = ['state', 'dimming'];
141
+ iotAgentLib.query('light1', 'Light', '', attributes, function (error) {
142
+ should.not.exist(error);
143
+ contextBrokerMock.done();
144
+ should.not.exist(error);
145
+ queryInvoked.should.equal(true);
146
+ done();
147
+ });
148
+ });
149
+ });
150
+ });
@@ -102,7 +102,7 @@ const iotAgentConfig = {
102
102
  object_id: 'h',
103
103
  name: 'humidity',
104
104
  type: 'Percentage',
105
- entity_name: 'Station Number ${@sn * 10}'
105
+ entity_name: '"Station Number "+sn*10'
106
106
  }
107
107
  ]
108
108
  },
@@ -115,13 +115,13 @@ const iotAgentConfig = {
115
115
  object_id: 'p',
116
116
  name: 'pressure',
117
117
  type: 'Hgmm',
118
- entity_name: 'Station Number ${@sn * 10}'
118
+ entity_name: '"Station Number "+sn*10'
119
119
  },
120
120
  {
121
121
  object_id: 'h',
122
122
  name: 'humidity',
123
123
  type: 'Percentage',
124
- entity_name: 'Station Number ${@sn * 10}'
124
+ entity_name: '"Station Number "+sn*10'
125
125
  }
126
126
  ]
127
127
  },
@@ -197,21 +197,21 @@ const iotAgentConfig = {
197
197
  {
198
198
  object_id: 'v1',
199
199
  name: 'vol',
200
- expression: '${@v1*100}',
200
+ expression: 'v1*100',
201
201
  type: 'Number',
202
202
  entity_name: 'WeatherStation1'
203
203
  },
204
204
  {
205
205
  object_id: 'v2',
206
206
  name: 'vol',
207
- expression: '${@v2*100}',
207
+ expression: 'v2*100',
208
208
  type: 'Number',
209
209
  entity_name: 'WeatherStation2'
210
210
  },
211
211
  {
212
212
  object_id: 'v',
213
213
  name: 'vol',
214
- expression: '${@v*100}',
214
+ expression: 'v*100',
215
215
  type: 'Number'
216
216
  }
217
217
  ]
@@ -244,7 +244,6 @@ const iotAgentConfig = {
244
244
  WeatherStation8Jexl: {
245
245
  commands: [],
246
246
  type: 'WeatherStation',
247
- expressionLanguage: 'jexl',
248
247
  lazy: [],
249
248
  active: [
250
249
  {
@@ -272,7 +271,6 @@ const iotAgentConfig = {
272
271
  WeatherStation9Jexl: {
273
272
  commands: [],
274
273
  type: 'WeatherStation',
275
- expressionLanguage: 'jexl',
276
274
  lazy: [],
277
275
  static: [
278
276
  {
@@ -364,7 +362,6 @@ const iotAgentConfig = {
364
362
  WrongStation: {
365
363
  commands: [],
366
364
  type: 'WrongStation',
367
- expressionLanguage: 'jexl',
368
365
  lazy: [],
369
366
  active: [
370
367
  {
@@ -456,7 +453,6 @@ const iotAgentConfig = {
456
453
  SharedIds3: {
457
454
  commands: [],
458
455
  type: 'ShareStation',
459
- expressionLanguage: 'jexl',
460
456
  lazy: [],
461
457
  active: [
462
458
  {
@@ -510,6 +506,41 @@ const iotAgentConfig = {
510
506
  ],
511
507
  explicitAttrs: true
512
508
  },
509
+ GPS1: {
510
+ commands: [],
511
+ type: 'GPS',
512
+ lazy: [],
513
+ active: [
514
+ {
515
+ name: 'explicit',
516
+ type: 'number',
517
+ object_id: 'z'
518
+ },
519
+ {
520
+ name: 'expectedAtt',
521
+ type: 'number',
522
+ expression: 'z+1'
523
+ },
524
+ {
525
+ name: 'nonexpectedAtt',
526
+ type: 'number',
527
+ expression: 'w+1'
528
+ },
529
+ {
530
+ name: 'explicit',
531
+ type: 'number',
532
+ entity_name: 'SO5',
533
+ object_id: 'x'
534
+ },
535
+ {
536
+ name: 'explicit',
537
+ type: 'number',
538
+ entity_name: 'SO6',
539
+ object_id: 'y'
540
+ }
541
+ ],
542
+ explicitAttrs: true
543
+ },
513
544
  GPS2: {
514
545
  commands: [],
515
546
  type: 'GPS',
@@ -559,8 +590,7 @@ const iotAgentConfig = {
559
590
  name: 'pressure',
560
591
  type: 'Number'
561
592
  }
562
- ],
563
- expressionLanguage: 'jexl'
593
+ ]
564
594
  }
565
595
  },
566
596
  service: 'smartgondor',
@@ -570,7 +600,7 @@ const iotAgentConfig = {
570
600
 
571
601
  describe('NGSI-v2 - Multi-entity plugin', function () {
572
602
  beforeEach(function (done) {
573
- logger.setLevel('FATAL');
603
+ logger.setLevel('DEBUG');
574
604
 
575
605
  iotAgentLib.activate(iotAgentConfig, function () {
576
606
  iotAgentLib.clearAll(function () {
@@ -1244,6 +1274,48 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
1244
1274
  });
1245
1275
  });
1246
1276
 
1277
+ describe('When an update comes for a multientity measurement explicitAttrs for several entities', function () {
1278
+ const values = [
1279
+ {
1280
+ name: 'x',
1281
+ type: 'Number',
1282
+ value: 52
1283
+ },
1284
+ {
1285
+ name: 'y',
1286
+ type: 'Number',
1287
+ value: 13
1288
+ },
1289
+ {
1290
+ name: 'z',
1291
+ type: 'Number',
1292
+ value: 12
1293
+ }
1294
+ ];
1295
+
1296
+ beforeEach(function () {
1297
+ nock.cleanAll();
1298
+ contextBrokerMock = nock('http://192.168.1.1:1026')
1299
+ .matchHeader('fiware-service', 'smartgondor')
1300
+ .matchHeader('fiware-servicepath', 'gardens')
1301
+ .post(
1302
+ '/v2/op/update',
1303
+ utils.readExampleFile(
1304
+ './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin25.json'
1305
+ )
1306
+ )
1307
+ .reply(204);
1308
+ });
1309
+
1310
+ it('should remove hidden attrs from the value', function (done) {
1311
+ iotAgentLib.update('gps1', 'GPS1', '', values, function (error) {
1312
+ should.not.exist(error);
1313
+ contextBrokerMock.done();
1314
+ done();
1315
+ });
1316
+ });
1317
+ });
1318
+
1247
1319
  describe('When an update comes for a multientity measurement explicitAttrs as jexl for one entity', function () {
1248
1320
  const values = [
1249
1321
  {
@@ -1599,9 +1671,8 @@ describe('NGSI-v2 - Multi-entity plugin is executed for a command update for a r
1599
1671
  contextBrokerMock = nock('http://192.168.1.1:1026')
1600
1672
  .matchHeader('fiware-service', 'smartgondor')
1601
1673
  .matchHeader('fiware-servicepath', 'gardens')
1602
- .patch(
1603
- //'/v2/op/update',
1604
- '/v2/entities/sensorCommand/attrs?type=SensorCommand',
1674
+ .post(
1675
+ '/v2/entities?options=upsert',
1605
1676
  utils.readExampleFile(
1606
1677
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin4.json'
1607
1678
  )
@@ -98,14 +98,13 @@ describe('NGSI-v2 - Timestamp processing plugin', function () {
98
98
  contextBrokerMock = nock('http://192.168.1.1:1026')
99
99
  .matchHeader('fiware-service', 'smartgondor')
100
100
  .matchHeader('fiware-servicepath', 'gardens')
101
- .patch(
102
- '/v2/entities/light1/attrs',
101
+ .post(
102
+ '/v2/entities?options=upsert',
103
103
  // this tests breaks jexlBasedTransformation-test with uses updateContextExpressionPlugin32 which do not includes Timestamp in metadata attributes
104
104
  utils.readExampleFile(
105
105
  './test/unit/ngsiv2/examples/contextRequests/updateContextProcessTimestamp.json'
106
106
  )
107
107
  )
108
- .query({ type: 'Light' })
109
108
  .reply(204);
110
109
  });
111
110
 
@@ -906,11 +906,10 @@ describe('NGSI-v2 - Device Group Configuration API', function () {
906
906
  contextBrokerMock = nock('http://unexistentHost:1026')
907
907
  .matchHeader('fiware-service', 'testservice')
908
908
  .matchHeader('fiware-servicepath', '/testingPath')
909
- .patch(
910
- '/v2/entities/machine1/attrs',
909
+ .post(
910
+ '/v2/entities?options=upsert',
911
911
  utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/updateContext3WithStatic.json')
912
912
  )
913
- .query({ type: 'SensorMachine' })
914
913
  .reply(204, {});
915
914
  async.series([async.apply(request, optionsCreation)], done);
916
915
  });