iotagent-node-lib 4.5.0 → 4.7.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 (124) hide show
  1. package/.github/workflows/ci.yml +0 -1
  2. package/Changelog +12 -0
  3. package/README.md +67 -272
  4. package/config.js +3 -1
  5. package/doc/README.md +1 -1
  6. package/doc/admin.md +40 -18
  7. package/doc/api.md +532 -136
  8. package/doc/deprecated.md +4 -0
  9. package/doc/devel/architecture.md +5 -135
  10. package/doc/devel/development.md +224 -12
  11. package/doc/getting-started.md +114 -53
  12. package/doc/requirements.txt +1 -1
  13. package/doc/roadmap.md +5 -5
  14. package/docker/Mosquitto/Dockerfile +2 -2
  15. package/docker/Mosquitto/README.md +14 -11
  16. package/lib/commonConfig.js +21 -2
  17. package/lib/constants.js +3 -0
  18. package/lib/fiware-iotagent-lib.js +12 -15
  19. package/lib/jexlTranformsMap.js +3 -1
  20. package/lib/model/Command.js +2 -2
  21. package/lib/model/Device.js +7 -3
  22. package/lib/model/Group.js +5 -3
  23. package/lib/model/dbConn.js +53 -115
  24. package/lib/services/commands/commandRegistryMongoDB.js +115 -75
  25. package/lib/services/common/alarmManagement.js +3 -0
  26. package/lib/services/common/iotManagerService.js +3 -1
  27. package/lib/services/devices/deviceRegistryMemory.js +36 -0
  28. package/lib/services/devices/deviceRegistryMongoDB.js +160 -87
  29. package/lib/services/devices/deviceService.js +33 -3
  30. package/lib/services/devices/devices-NGSI-v2.js +6 -1
  31. package/lib/services/groups/groupRegistryMongoDB.js +120 -83
  32. package/lib/services/groups/groupService.js +1 -1
  33. package/lib/services/ngsi/entities-NGSI-LD.js +320 -570
  34. package/lib/services/ngsi/entities-NGSI-v2.js +51 -3
  35. package/lib/services/ngsi/ngsiService.js +34 -1
  36. package/lib/services/northBound/deviceGroupAdministrationServer.js +42 -6
  37. package/lib/services/northBound/deviceProvisioningServer.js +12 -4
  38. package/lib/services/northBound/northboundServer.js +2 -0
  39. package/lib/services/stats/statsRegistry.js +128 -101
  40. package/lib/templates/createDevice.json +0 -24
  41. package/lib/templates/createDeviceLax.json +0 -23
  42. package/lib/templates/deviceGroup.json +1 -25
  43. package/lib/templates/updateDevice.json +12 -24
  44. package/lib/templates/updateDeviceLax.json +12 -23
  45. package/package.json +5 -5
  46. package/scripts/legacy_expression_tool/README.md +0 -1
  47. package/test/functional/README.md +22 -17
  48. package/test/functional/config-test.js +3 -2
  49. package/test/functional/functional-tests-runner.js +9 -4
  50. package/test/functional/functional-tests.js +4 -4
  51. package/test/functional/testCases.js +245 -4
  52. package/test/functional/testUtils.js +2 -2
  53. package/test/unit/examples/deviceProvisioningRequests/provisionFullDevice.json +1 -13
  54. package/test/unit/examples/groupProvisioningRequests/multipleConfigGroupsCreation.json +44 -0
  55. package/test/unit/examples/groupProvisioningRequests/provisionDuplicateConfigGroup.json +35 -0
  56. package/test/unit/examples/groupProvisioningRequests/provisionFullConfigGroup.json +36 -0
  57. package/test/unit/examples/groupProvisioningRequests/provisionFullConfigGroupAlternate.json +36 -0
  58. package/test/unit/examples/groupProvisioningRequests/provisionFullGroup.json +1 -0
  59. package/test/unit/general/config-multi-core-test.js +1 -2
  60. package/test/unit/general/contextBrokerKeystoneSecurityAccess-test.js +5 -4
  61. package/test/unit/general/deviceService-test.js +106 -3
  62. package/test/unit/general/statistics-service_test.js +1 -74
  63. package/test/unit/memoryRegistry/deviceRegistryMemory_test.js +6 -5
  64. package/test/unit/mongodb/mongodb-configGroup-registry-test.js +452 -0
  65. package/test/unit/mongodb/mongodb-connectionoptions-test.js +9 -42
  66. package/test/unit/mongodb/mongodb-group-registry-test.js +34 -33
  67. package/test/unit/mongodb/mongodb-service-registry-test.js +477 -0
  68. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin1a.json +4 -4
  69. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin2.json +22 -22
  70. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin29.json +4 -4
  71. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin32.json +14 -15
  72. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin1.json +23 -23
  73. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin15.json +0 -5
  74. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin4.json +11 -16
  75. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin5.json +23 -28
  76. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin6.json +8 -13
  77. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin7.json +0 -5
  78. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin8.json +24 -29
  79. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +12 -17
  80. package/test/unit/ngsi-ld/examples/contextRequests/updateContextStaticLinkedAttributes.json +12 -10
  81. package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +1 -104
  82. package/test/unit/ngsi-ld/general/config-jsonld-contexts-test.js +1 -2
  83. package/test/unit/ngsi-ld/plugins/multientity-plugin_test.js +4 -5
  84. package/test/unit/ngsi-ld/provisioning/listProvisionedDevices-test.js +0 -4
  85. package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +8 -5
  86. package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +42 -41
  87. package/test/unit/ngsiv2/general/contextBrokerOAuthSecurityAccess-test.js +11 -10
  88. package/test/unit/ngsiv2/general/deviceService-test.js +98 -4
  89. package/test/unit/ngsiv2/general/https-support-test.js +1 -1
  90. package/test/unit/ngsiv2/general/iotam-autoregistration-test.js +195 -0
  91. package/test/unit/ngsiv2/lazyAndCommands/active-devices-attribute-update-test.js +4 -3
  92. package/test/unit/ngsiv2/lazyAndCommands/command-test.js +6 -5
  93. package/test/unit/ngsiv2/lazyAndCommands/lazy-devices-test.js +17 -16
  94. package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +10 -18
  95. package/test/unit/ngsiv2/ngsiService/active-devices-test.js +21 -20
  96. package/test/unit/ngsiv2/ngsiService/staticAttributes-test.js +8 -7
  97. package/test/unit/ngsiv2/plugins/alias-plugin_test.js +12 -11
  98. package/test/unit/ngsiv2/plugins/custom-plugin_test.js +3 -2
  99. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +28 -27
  100. package/test/unit/ngsiv2/provisioning/device-group-api-test.js +265 -4
  101. package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +12 -11
  102. package/test/unit/ngsiv2/provisioning/device-provisioning-configGroup-api_test.js +1190 -0
  103. package/test/unit/ngsiv2/provisioning/device-registration_test.js +5 -4
  104. package/test/unit/ngsiv2/provisioning/listProvisionedDevices-test.js +6 -9
  105. package/test/unit/ngsiv2/provisioning/provisionDeviceMultientity-test.js +1 -1
  106. package/test/unit/ngsiv2/provisioning/removeProvisionedDevice-test.js +5 -4
  107. package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +8 -7
  108. package/test/unit/statsRegistry/openmetrics-test.js +167 -0
  109. package/lib/templates/queryContext.json +0 -25
  110. package/test/unit/examples/deviceProvisioningRequests/provisionBidirectionalDevice.json +0 -35
  111. package/test/unit/examples/deviceProvisioningRequests/provisionDeviceBidirectionalGroup.json +0 -17
  112. package/test/unit/examples/groupProvisioningRequests/bidirectionalGroup.json +0 -31
  113. package/test/unit/general/statistics-persistence_test.js +0 -121
  114. package/test/unit/ngsi-ld/examples/contextRequests/createBidirectionalDevice.json +0 -17
  115. package/test/unit/ngsi-ld/examples/contextRequests/updateContextProcessTimestamp.json +0 -12
  116. package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotification.json +0 -13
  117. package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotificationWithDatasetId.json +0 -21
  118. package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotificationWithMetadata.json +0 -17
  119. package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json +0 -23
  120. package/test/unit/ngsi-ld/plugins/timestamp-processing-plugin_test.js +0 -132
  121. package/test/unit/ngsiv2/examples/contextRequests/createBidirectionalDevice.json +0 -8
  122. package/test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalNotification.json +0 -13
  123. package/test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalNotificationWithMetadata.json +0 -19
  124. package/test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json +0 -24
@@ -633,7 +633,8 @@ const iotAgentConfig = {
633
633
  },
634
634
  service: 'smartgondor',
635
635
  subservice: 'gardens',
636
- providerUrl: 'http://smartgondor.com'
636
+ providerUrl: 'http://smartgondor.com',
637
+ useCBflowControl: true
637
638
  };
638
639
 
639
640
  describe('NGSI-v2 - Multi-entity plugin', function () {
@@ -674,7 +675,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
674
675
  .matchHeader('fiware-service', 'smartgondor')
675
676
  .matchHeader('fiware-servicepath', 'gardens')
676
677
  .post(
677
- '/v2/op/update',
678
+ '/v2/op/update?options=flowControl',
678
679
  utils.readExampleFile(
679
680
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin1.json'
680
681
  )
@@ -712,7 +713,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
712
713
  .matchHeader('fiware-service', 'smartgondor')
713
714
  .matchHeader('fiware-servicepath', 'gardens')
714
715
  .post(
715
- '/v2/op/update',
716
+ '/v2/op/update?options=flowControl',
716
717
  utils.readExampleFile(
717
718
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin17.json'
718
719
  )
@@ -744,7 +745,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
744
745
  .matchHeader('fiware-service', 'smartgondor')
745
746
  .matchHeader('fiware-servicepath', 'gardens')
746
747
  .post(
747
- '/v2/op/update',
748
+ '/v2/op/update?options=flowControl',
748
749
  utils.readExampleFile(
749
750
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin4.json'
750
751
  )
@@ -781,7 +782,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
781
782
  .matchHeader('fiware-service', 'smartgondor')
782
783
  .matchHeader('fiware-servicepath', 'gardens')
783
784
  .post(
784
- '/v2/op/update',
785
+ '/v2/op/update?options=flowControl',
785
786
  utils.readExampleFile(
786
787
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin5.json'
787
788
  )
@@ -819,7 +820,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
819
820
  .matchHeader('fiware-service', 'smartgondor')
820
821
  .matchHeader('fiware-servicepath', 'gardens')
821
822
  .post(
822
- '/v2/op/update',
823
+ '/v2/op/update?options=flowControl',
823
824
  utils.readExampleFile(
824
825
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin8.json'
825
826
  )
@@ -862,7 +863,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
862
863
  .matchHeader('fiware-service', 'smartgondor')
863
864
  .matchHeader('fiware-servicepath', 'gardens')
864
865
  .post(
865
- '/v2/op/update',
866
+ '/v2/op/update?options=flowControl',
866
867
  utils.readExampleFile(
867
868
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin3.json'
868
869
  )
@@ -905,7 +906,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
905
906
  .matchHeader('fiware-service', 'smartgondor')
906
907
  .matchHeader('fiware-servicepath', 'gardens')
907
908
  .post(
908
- '/v2/op/update',
909
+ '/v2/op/update?options=flowControl',
909
910
  utils.readExampleFile(
910
911
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin9.json'
911
912
  )
@@ -948,7 +949,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
948
949
  .matchHeader('fiware-service', 'smartgondor')
949
950
  .matchHeader('fiware-servicepath', 'gardens')
950
951
  .post(
951
- '/v2/op/update',
952
+ '/v2/op/update?options=flowControl',
952
953
  utils.readExampleFile(
953
954
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin10.json'
954
955
  )
@@ -996,7 +997,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
996
997
  .matchHeader('fiware-service', 'smartgondor')
997
998
  .matchHeader('fiware-servicepath', 'gardens')
998
999
  .post(
999
- '/v2/op/update',
1000
+ '/v2/op/update?options=flowControl',
1000
1001
  utils.readExampleFile(
1001
1002
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin12.json'
1002
1003
  )
@@ -1044,7 +1045,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
1044
1045
  .matchHeader('fiware-service', 'smartgondor')
1045
1046
  .matchHeader('fiware-servicepath', 'gardens')
1046
1047
  .post(
1047
- '/v2/op/update',
1048
+ '/v2/op/update?options=flowControl',
1048
1049
  utils.readExampleFile(
1049
1050
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin13.json'
1050
1051
  )
@@ -1077,7 +1078,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
1077
1078
  .matchHeader('fiware-service', 'smartgondor')
1078
1079
  .matchHeader('fiware-servicepath', 'gardens')
1079
1080
  .post(
1080
- '/v2/op/update',
1081
+ '/v2/op/update?options=flowControl',
1081
1082
  utils.readExampleFile(
1082
1083
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin14.json'
1083
1084
  )
@@ -1120,7 +1121,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
1120
1121
  .matchHeader('fiware-service', 'smartgondor')
1121
1122
  .matchHeader('fiware-servicepath', 'gardens')
1122
1123
  .post(
1123
- '/v2/op/update',
1124
+ '/v2/op/update?options=flowControl',
1124
1125
  utils.readExampleFile(
1125
1126
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin10.json'
1126
1127
  )
@@ -1153,7 +1154,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
1153
1154
  .matchHeader('fiware-service', 'smartgondor')
1154
1155
  .matchHeader('fiware-servicepath', 'gardens')
1155
1156
  .post(
1156
- '/v2/op/update',
1157
+ '/v2/op/update?options=flowControl',
1157
1158
  utils.readExampleFile(
1158
1159
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin10b.json'
1159
1160
  )
@@ -1177,7 +1178,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
1177
1178
  .matchHeader('fiware-service', 'smartgondor')
1178
1179
  .matchHeader('fiware-servicepath', 'gardens')
1179
1180
  .post(
1180
- '/v2/op/update',
1181
+ '/v2/op/update?options=flowControl',
1181
1182
  utils.readExampleFile(
1182
1183
  // Updated test same case that updateContextMultientityPlugin4.json
1183
1184
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin11.json'
@@ -1211,7 +1212,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
1211
1212
  .matchHeader('fiware-service', 'smartgondor')
1212
1213
  .matchHeader('fiware-servicepath', 'gardens')
1213
1214
  .post(
1214
- '/v2/op/update',
1215
+ '/v2/op/update?options=flowControl',
1215
1216
  utils.readExampleFile(
1216
1217
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin11.json'
1217
1218
  )
@@ -1249,7 +1250,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
1249
1250
  .matchHeader('fiware-service', 'smartgondor')
1250
1251
  .matchHeader('fiware-servicepath', 'gardens')
1251
1252
  .post(
1252
- '/v2/op/update',
1253
+ '/v2/op/update?options=flowControl',
1253
1254
  utils.readExampleFile(
1254
1255
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin2.json'
1255
1256
  )
@@ -1291,7 +1292,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
1291
1292
  .matchHeader('fiware-service', 'smartgondor')
1292
1293
  .matchHeader('fiware-servicepath', 'gardens')
1293
1294
  .post(
1294
- '/v2/op/update',
1295
+ '/v2/op/update?options=flowControl',
1295
1296
  utils.readExampleFile(
1296
1297
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin15.json'
1297
1298
  )
@@ -1333,7 +1334,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
1333
1334
  .matchHeader('fiware-service', 'smartgondor')
1334
1335
  .matchHeader('fiware-servicepath', 'gardens')
1335
1336
  .post(
1336
- '/v2/op/update',
1337
+ '/v2/op/update?options=flowControl',
1337
1338
  utils.readExampleFile(
1338
1339
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin25.json'
1339
1340
  )
@@ -1375,7 +1376,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
1375
1376
  .matchHeader('fiware-service', 'smartgondor')
1376
1377
  .matchHeader('fiware-servicepath', 'gardens')
1377
1378
  .post(
1378
- '/v2/op/update',
1379
+ '/v2/op/update?options=flowControl',
1379
1380
  utils.readExampleFile(
1380
1381
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin16.json'
1381
1382
  )
@@ -1410,7 +1411,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
1410
1411
  .matchHeader('fiware-service', 'smartgondor')
1411
1412
  .matchHeader('fiware-servicepath', 'gardens')
1412
1413
  .post(
1413
- '/v2/op/update',
1414
+ '/v2/op/update?options=flowControl',
1414
1415
  utils.readExampleFile(
1415
1416
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin6.json'
1416
1417
  )
@@ -1461,7 +1462,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
1461
1462
  .matchHeader('fiware-service', 'smartgondor')
1462
1463
  .matchHeader('fiware-servicepath', 'gardens')
1463
1464
  .post(
1464
- '/v2/op/update',
1465
+ '/v2/op/update?options=flowControl',
1465
1466
  utils.readExampleFile(
1466
1467
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin7.json'
1467
1468
  )
@@ -1500,7 +1501,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
1500
1501
  .matchHeader('fiware-service', 'smartgondor')
1501
1502
  .matchHeader('fiware-servicepath', 'gardens')
1502
1503
  .post(
1503
- '/v2/op/update',
1504
+ '/v2/op/update?options=flowControl',
1504
1505
  utils.readExampleFile(
1505
1506
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityJexlExpressionPlugin1.json'
1506
1507
  )
@@ -1570,7 +1571,7 @@ describe('NGSI-v2 - Multi-entity plugin is executed before timestamp process plu
1570
1571
  contextBrokerMock = nock('http://192.168.1.1:1026')
1571
1572
  .matchHeader('fiware-service', 'smartgondor')
1572
1573
  .matchHeader('fiware-servicepath', 'gardens')
1573
- .post('/v2/op/update', function (body) {
1574
+ .post('/v2/op/update?options=flowControl', function (body) {
1574
1575
  const expectedBody = utils.readExampleFile(
1575
1576
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin1.json'
1576
1577
  );
@@ -1608,7 +1609,7 @@ describe('NGSI-v2 - Multi-entity plugin is executed before timestamp process plu
1608
1609
  contextBrokerMock = nock('http://192.168.1.1:1026')
1609
1610
  .matchHeader('fiware-service', 'smartgondor')
1610
1611
  .matchHeader('fiware-servicepath', 'gardens')
1611
- .post('/v2/op/update', function (body) {
1612
+ .post('/v2/op/update?options=flowControl', function (body) {
1612
1613
  const expectedBody = utils.readExampleFile(
1613
1614
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin2.json'
1614
1615
  );
@@ -1647,7 +1648,7 @@ describe('NGSI-v2 - Multi-entity plugin is executed before timestamp process plu
1647
1648
  .matchHeader('fiware-service', 'smartgondor')
1648
1649
  .matchHeader('fiware-servicepath', 'gardens')
1649
1650
  .post(
1650
- '/v2/op/update',
1651
+ '/v2/op/update?options=flowControl',
1651
1652
  utils.readExampleFile(
1652
1653
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin3.json'
1653
1654
  )
@@ -1701,7 +1702,7 @@ describe('NGSI-v2 - Multi-entity plugin is executed for a command update for a r
1701
1702
  .matchHeader('fiware-service', 'smartgondor')
1702
1703
  .matchHeader('fiware-servicepath', 'gardens')
1703
1704
  .post(
1704
- '/v2/entities?options=upsert',
1705
+ '/v2/entities?options=upsert,flowControl',
1705
1706
  utils.readExampleFile(
1706
1707
  './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin4.json'
1707
1708
  )
@@ -23,6 +23,8 @@
23
23
 
24
24
  /* eslint-disable no-unused-vars */
25
25
 
26
+ // #FIXME1649: parallel tests in device-provisioning-configGroup-api_test.js.
27
+
26
28
  const iotAgentLib = require('../../../../lib/fiware-iotagent-lib');
27
29
  const _ = require('underscore');
28
30
  const async = require('async');
@@ -48,7 +50,8 @@ const iotAgentConfig = {
48
50
  service: 'smartgondor',
49
51
  subservice: 'gardens',
50
52
  providerUrl: 'http://smartgondor.com',
51
- deviceRegistrationDuration: 'P1M'
53
+ deviceRegistrationDuration: 'P1M',
54
+ useCBflowControl: true
52
55
  };
53
56
  const optionsCreation = {
54
57
  url: 'http://localhost:4041/iot/services',
@@ -63,6 +66,7 @@ const optionsCreation = {
63
66
  cbHost: 'http://unexistentHost:1026',
64
67
  transport: 'HTTP',
65
68
  endpoint: 'http://myendpoint.com',
69
+ useCBflowControl: true,
66
70
  commands: [
67
71
  {
68
72
  name: 'wheel1',
@@ -118,6 +122,19 @@ const optionsDelete = {
118
122
  apikey: '801230BJKL23Y9090DSFL123HJK09H324HV8732'
119
123
  }
120
124
  };
125
+ const optionsDeleteGroup = {
126
+ url: 'http://localhost:4041/iot/services',
127
+ method: 'DELETE',
128
+ json: {},
129
+ headers: {
130
+ 'fiware-service': 'Testservice',
131
+ 'fiware-servicepath': '/testingPath'
132
+ },
133
+ qs: {
134
+ resource: '/deviceTest',
135
+ apikey: '801230BJKL23Y9090DSFL123HJK09H324HV8732'
136
+ }
137
+ };
121
138
  const optionsDeleteDevice = {
122
139
  url: 'http://localhost:4041/iot/services',
123
140
  method: 'DELETE',
@@ -175,6 +192,49 @@ const optionsUpdate = {
175
192
  apikey: '801230BJKL23Y9090DSFL123HJK09H324HV8732'
176
193
  }
177
194
  };
195
+ const optionsUpdateGroup = {
196
+ url: 'http://localhost:4041/iot/services',
197
+ method: 'PUT',
198
+ json: {
199
+ trust: '8970A9078A803H3BL98PINEQRW8342HBAMS',
200
+ cbHost: 'http://anotherUnexistentHost:1026',
201
+ transport: 'MQTT',
202
+ endpoint: 'http://yourendpoint.com',
203
+ commands: [
204
+ {
205
+ name: 'wheel1',
206
+ type: 'Wheel'
207
+ }
208
+ ],
209
+ lazy: [
210
+ {
211
+ name: 'luminescence',
212
+ type: 'Lumens'
213
+ }
214
+ ],
215
+ attributes: [
216
+ {
217
+ name: 'status',
218
+ type: 'Boolean'
219
+ }
220
+ ],
221
+ static_attributes: [
222
+ {
223
+ name: 'identifier',
224
+ type: 'UUID',
225
+ value: 'WERTYUIOP234567890'
226
+ }
227
+ ]
228
+ },
229
+ headers: {
230
+ 'fiware-service': 'Testservice',
231
+ 'fiware-servicepath': '/testingPath'
232
+ },
233
+ qs: {
234
+ resource: '/deviceTest',
235
+ apikey: '801230BJKL23Y9090DSFL123HJK09H324HV8732'
236
+ }
237
+ };
178
238
  const optionsList = {
179
239
  url: 'http://localhost:4041/iot/services',
180
240
  method: 'GET',
@@ -194,6 +254,20 @@ const optionsGet = {
194
254
  }
195
255
  };
196
256
 
257
+ // Add new options using the literal groups instead of services
258
+ const configGroupTerm = 'groups';
259
+
260
+ const newOptionsCreation = JSON.parse(JSON.stringify(optionsCreation));
261
+ newOptionsCreation.url = newOptionsCreation.url.replace('services', configGroupTerm);
262
+ newOptionsCreation.json[configGroupTerm] = newOptionsCreation.json.services;
263
+ delete newOptionsCreation.json.services;
264
+
265
+ const newOptionsList = JSON.parse(JSON.stringify(optionsList));
266
+ newOptionsList.url = newOptionsList.url.replace('services', configGroupTerm);
267
+
268
+ const newOptionsGet = JSON.parse(JSON.stringify(optionsGet));
269
+ newOptionsGet.url = newOptionsGet.url.replace('services', configGroupTerm);
270
+
197
271
  describe('NGSI-v2 - Device Group Configuration API', function () {
198
272
  beforeEach(function (done) {
199
273
  iotAgentLib.activate(iotAgentConfig, function () {
@@ -411,6 +485,33 @@ describe('NGSI-v2 - Device Group Configuration API', function () {
411
485
  });
412
486
  });
413
487
  });
488
+ describe('When a device group removal request arrives with service-header in uppercase', function () {
489
+ beforeEach(function (done) {
490
+ request(optionsCreation, done);
491
+ });
492
+
493
+ it('should return a 204 OK', function (done) {
494
+ request(optionsDeleteGroup, function (error, response, body) {
495
+ should.not.exist(error);
496
+ response.statusCode.should.equal(204);
497
+ done();
498
+ });
499
+ });
500
+ it('should remove it from the database', function (done) {
501
+ request(optionsDeleteGroup, function (error, response, body) {
502
+ request(optionsList, function (error, response, body) {
503
+ body.count.should.equal(0);
504
+ done();
505
+ });
506
+ });
507
+ });
508
+ it('should remove it from the configuration', function (done) {
509
+ request(optionsDeleteGroup, function (error, response, body) {
510
+ should.not.exist(iotAgentConfig.types.SensorMachine);
511
+ done();
512
+ });
513
+ });
514
+ });
414
515
  describe('When a device group removal request arrives with device=true option', function () {
415
516
  let contextBrokerMock;
416
517
 
@@ -420,7 +521,7 @@ describe('NGSI-v2 - Device Group Configuration API', function () {
420
521
  contextBrokerMock = nock('http://192.168.1.1:1026')
421
522
  .matchHeader('fiware-service', 'testservice')
422
523
  .matchHeader('fiware-servicepath', '/testingPath')
423
- .post('/v2/entities?options=upsert')
524
+ .post('/v2/entities?options=upsert,flowControl')
424
525
  .reply(204);
425
526
 
426
527
  contextBrokerMock
@@ -438,7 +539,7 @@ describe('NGSI-v2 - Device Group Configuration API', function () {
438
539
  contextBrokerMock
439
540
  .matchHeader('fiware-service', 'testservice')
440
541
  .matchHeader('fiware-servicepath', '/testingPath')
441
- .post('/v2/entities?options=upsert')
542
+ .post('/v2/entities?options=upsert,flowControl')
442
543
  .reply(204);
443
544
 
444
545
  async.series(
@@ -704,6 +805,83 @@ describe('NGSI-v2 - Device Group Configuration API', function () {
704
805
  });
705
806
  });
706
807
 
808
+ describe('When a device group update request arrives with service-header in uppercase', function () {
809
+ beforeEach(function (done) {
810
+ const optionsCreation1 = _.clone(optionsCreation);
811
+ const optionsCreation2 = _.clone(optionsCreation);
812
+ const optionsCreation3 = _.clone(optionsCreation);
813
+
814
+ optionsCreation1.json = { services: [] };
815
+ optionsCreation3.json = { services: [] };
816
+
817
+ optionsCreation1.json.services[0] = _.clone(optionsCreation.json.services[0]);
818
+ optionsCreation3.json.services[0] = _.clone(optionsCreation.json.services[0]);
819
+
820
+ optionsCreation1.json.services[0].apikey = 'qwertyuiop';
821
+ optionsCreation3.json.services[0].apikey = 'lkjhgfds';
822
+
823
+ async.series(
824
+ [
825
+ async.apply(request, optionsCreation1),
826
+ async.apply(request, optionsCreation2),
827
+ async.apply(request, optionsCreation3)
828
+ ],
829
+ done
830
+ );
831
+ });
832
+
833
+ it('should return a 204 OK', function (done) {
834
+ request(optionsUpdateGroup, function (error, response, body) {
835
+ should.not.exist(error);
836
+ response.statusCode.should.equal(204);
837
+ done();
838
+ });
839
+ });
840
+ it('should update the appropriate values in the database', function (done) {
841
+ request(optionsUpdateGroup, function (error, response, body) {
842
+ request(optionsList, function (error, response, body) {
843
+ let found = false;
844
+ body.count.should.equal(3);
845
+
846
+ for (let i = 0; i < body.services.length; i++) {
847
+ if (
848
+ body.services[i].apikey === '801230BJKL23Y9090DSFL123HJK09H324HV8732' &&
849
+ body.services[i].resource === '/deviceTest'
850
+ ) {
851
+ body.services[i].cbHost.should.equal('http://anotherUnexistentHost:1026');
852
+ body.services[i].static_attributes.length.should.equal(1);
853
+ found = true;
854
+ }
855
+ }
856
+
857
+ found.should.equal(true);
858
+ done();
859
+ });
860
+ });
861
+ });
862
+ it('should call the configuration creation handler', function (done) {
863
+ let handlerCalled = false;
864
+
865
+ iotAgentLib.setConfigurationHandler(function (newConfiguration, callback) {
866
+ should.exist(newConfiguration);
867
+ should.exist(callback);
868
+ newConfiguration.cbHost.should.equal('http://anotherUnexistentHost:1026');
869
+ newConfiguration.trust.should.equal('8970A9078A803H3BL98PINEQRW8342HBAMS');
870
+ newConfiguration.service.should.equal('Testservice');
871
+ newConfiguration.subservice.should.equal('/testingPath');
872
+ newConfiguration.resource.should.equal('/deviceTest');
873
+ newConfiguration.apikey.should.equal('801230BJKL23Y9090DSFL123HJK09H324HV8732');
874
+ handlerCalled = true;
875
+ callback();
876
+ });
877
+
878
+ request(optionsUpdateGroup, function (error, response, body) {
879
+ handlerCalled.should.equal(true);
880
+ done();
881
+ });
882
+ });
883
+ });
884
+
707
885
  describe('When a device group update request arrives declaring a different service', function () {
708
886
  beforeEach(function (done) {
709
887
  optionsUpdate.headers['fiware-service'] = 'UnexistentService';
@@ -915,7 +1093,7 @@ describe('NGSI-v2 - Device Group Configuration API', function () {
915
1093
  .matchHeader('fiware-service', 'testservice')
916
1094
  .matchHeader('fiware-servicepath', '/testingPath')
917
1095
  .post(
918
- '/v2/entities?options=upsert',
1096
+ '/v2/entities?options=upsert,flowControl',
919
1097
  utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/updateContext3WithStatic.json')
920
1098
  )
921
1099
  .reply(204, {});
@@ -996,4 +1174,87 @@ describe('NGSI-v2 - Device Group Configuration API', function () {
996
1174
  });
997
1175
  });
998
1176
  });
1177
+
1178
+ describe('When a new device group creation request arrives with the NEW API endpoint ', function () {
1179
+ it('should return a 200 OK', function (done) {
1180
+ request(newOptionsCreation, function (error, response, body) {
1181
+ should.not.exist(error);
1182
+ response.statusCode.should.equal(201);
1183
+ done();
1184
+ });
1185
+ });
1186
+ it('should be recovered using the OLD API endpoint', function (done) {
1187
+ request(newOptionsCreation, function (error, response, body) {
1188
+ request(optionsList, function (error, response, body) {
1189
+ body.count.should.equal(1);
1190
+ body.services[0].apikey.should.equal('801230BJKL23Y9090DSFL123HJK09H324HV8732');
1191
+ body.services[0].transport.should.equal('HTTP');
1192
+ body.services[0].endpoint.should.equal('http://myendpoint.com');
1193
+
1194
+ body.count.should.equal(1);
1195
+ should.exist(body.services[0].attributes);
1196
+ body.services[0].attributes.length.should.equal(1);
1197
+ body.services[0].attributes[0].name.should.equal('status');
1198
+
1199
+ should.exist(body.services[0].lazy);
1200
+ body.services[0].lazy.length.should.equal(1);
1201
+ body.services[0].lazy[0].name.should.equal('luminescence');
1202
+
1203
+ should.exist(body.services[0].commands);
1204
+ body.services[0].commands.length.should.equal(1);
1205
+ body.services[0].commands[0].name.should.equal('wheel1');
1206
+
1207
+ should.exist(body.services[0].static_attributes);
1208
+ body.services[0].static_attributes.length.should.equal(1);
1209
+ body.services[0].static_attributes[0].name.should.equal('bootstrapServer');
1210
+
1211
+ body.count.should.equal(1);
1212
+ body.services[0].service.should.equal('testservice');
1213
+ body.services[0].subservice.should.equal('/testingPath');
1214
+ done();
1215
+ });
1216
+ });
1217
+ });
1218
+ });
1219
+ describe('When a new device group creation request arrives with the NEW OLD endpoint ', function () {
1220
+ it('should return a 200 OK', function (done) {
1221
+ request(optionsCreation, function (error, response, body) {
1222
+ should.not.exist(error);
1223
+ response.statusCode.should.equal(201);
1224
+ done();
1225
+ });
1226
+ });
1227
+ it('should be recovered using the NEW API endpoint', function (done) {
1228
+ request(optionsCreation, function (error, response, body) {
1229
+ request(newOptionsList, function (error, response, body) {
1230
+ body.count.should.equal(1);
1231
+ body[configGroupTerm][0].apikey.should.equal('801230BJKL23Y9090DSFL123HJK09H324HV8732');
1232
+ body[configGroupTerm][0].transport.should.equal('HTTP');
1233
+ body[configGroupTerm][0].endpoint.should.equal('http://myendpoint.com');
1234
+
1235
+ body.count.should.equal(1);
1236
+ should.exist(body[configGroupTerm][0].attributes);
1237
+ body[configGroupTerm][0].attributes.length.should.equal(1);
1238
+ body[configGroupTerm][0].attributes[0].name.should.equal('status');
1239
+
1240
+ should.exist(body[configGroupTerm][0].lazy);
1241
+ body[configGroupTerm][0].lazy.length.should.equal(1);
1242
+ body[configGroupTerm][0].lazy[0].name.should.equal('luminescence');
1243
+
1244
+ should.exist(body[configGroupTerm][0].commands);
1245
+ body[configGroupTerm][0].commands.length.should.equal(1);
1246
+ body[configGroupTerm][0].commands[0].name.should.equal('wheel1');
1247
+
1248
+ should.exist(body[configGroupTerm][0].static_attributes);
1249
+ body[configGroupTerm][0].static_attributes.length.should.equal(1);
1250
+ body[configGroupTerm][0].static_attributes[0].name.should.equal('bootstrapServer');
1251
+
1252
+ body.count.should.equal(1);
1253
+ body[configGroupTerm][0].service.should.equal('testservice');
1254
+ body[configGroupTerm][0].subservice.should.equal('/testingPath');
1255
+ done();
1256
+ });
1257
+ });
1258
+ });
1259
+ });
999
1260
  });