iotagent-node-lib 2.17.0 → 2.20.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 (347) hide show
  1. package/.github/workflows/ci.yml +17 -2
  2. package/.nyc_output/76bc24ff-5fac-4b5a-997d-de2799342eb0.json +1 -0
  3. package/.nyc_output/processinfo/76bc24ff-5fac-4b5a-997d-de2799342eb0.json +1 -0
  4. package/.nyc_output/processinfo/index.json +1 -1
  5. package/CHANGES_NEXT_RELEASE +1 -0
  6. package/README.md +3 -54
  7. package/doc/advanced-topics.md +121 -85
  8. package/doc/api.md +52 -52
  9. package/doc/development.md +13 -6
  10. package/doc/expressionLanguage.md +514 -312
  11. package/doc/installationguide.md +66 -64
  12. package/doc/usermanual.md +48 -16
  13. package/docker/Mosquitto/Dockerfile +1 -0
  14. package/docker/Mosquitto/README.md +1 -0
  15. package/docker/Mosquitto/startMosquitto.sh +9 -4
  16. package/lib/commonConfig.js +1 -14
  17. package/lib/errors.js +0 -16
  18. package/lib/fiware-iotagent-lib.js +4 -2
  19. package/lib/jexlTranformsMap.js +13 -2
  20. package/lib/model/Device.js +4 -1
  21. package/lib/model/Group.js +19 -1
  22. package/lib/plugins/attributeAlias.js +6 -13
  23. package/lib/plugins/bidirectionalData.js +1 -21
  24. package/lib/plugins/expressionParser.js +7 -6
  25. package/lib/plugins/expressionPlugin.js +11 -25
  26. package/lib/plugins/jexlParser.js +8 -4
  27. package/lib/plugins/multiEntity.js +54 -145
  28. package/lib/plugins/pluginUtils.js +12 -48
  29. package/lib/plugins/timestampProcessPlugin.js +1 -46
  30. package/lib/request-shim.js +111 -0
  31. package/lib/services/common/domain.js +6 -2
  32. package/lib/services/common/genericMiddleware.js +6 -2
  33. package/lib/services/common/iotManagerService.js +1 -1
  34. package/lib/services/common/securityServiceKeystone.js +1 -1
  35. package/lib/services/common/securityServiceOAuth2.js +3 -2
  36. package/lib/services/devices/deviceRegistryMongoDB.js +2 -0
  37. package/lib/services/devices/deviceService.js +2 -5
  38. package/lib/services/devices/devices-NGSI-LD.js +1 -1
  39. package/lib/services/devices/devices-NGSI-v2.js +4 -8
  40. package/lib/services/devices/registrationUtils.js +1 -134
  41. package/lib/services/ngsi/entities-NGSI-LD.js +205 -124
  42. package/lib/services/ngsi/entities-NGSI-v2.js +109 -15
  43. package/lib/services/ngsi/ngsiService.js +4 -6
  44. package/lib/services/ngsi/ngsiUtils.js +0 -36
  45. package/lib/services/ngsi/subscriptionService.js +1 -4
  46. package/lib/services/northBound/contextServer-NGSI-LD.js +7 -2
  47. package/lib/services/northBound/contextServer-NGSI-v2.js +24 -12
  48. package/lib/services/northBound/contextServer.js +1 -4
  49. package/lib/services/northBound/contextServerUtils.js +0 -81
  50. package/lib/services/northBound/deviceProvisioningServer.js +31 -7
  51. package/lib/services/northBound/northboundServer.js +2 -0
  52. package/lib/services/northBound/restUtils.js +1 -38
  53. package/lib/templates/updateDevice.json +4 -0
  54. package/lib/templates/updateDeviceLax.json +4 -0
  55. package/package.json +10 -16
  56. package/test/tools/utils.js +2 -0
  57. package/test/unit/examples/groupProvisioningRequests/multipleGroupsCreation.json +1 -1
  58. package/test/unit/expressions/jexlExpression-test.js +44 -5
  59. package/test/unit/general/contextBrokerKeystoneSecurityAccess-test.js +19 -66
  60. package/test/unit/general/deviceService-test.js +11 -27
  61. package/test/unit/general/loglevel-api_test.js +6 -11
  62. package/test/unit/general/startup-test.js +2 -1
  63. package/test/unit/memoryRegistry/deviceRegistryMemory_test.js +8 -16
  64. package/test/unit/mongodb/mongodb-group-registry-test.js +1 -1
  65. package/test/unit/mongodb/mongodb-registry-test.js +38 -114
  66. package/test/unit/ngsi-ld/examples/contextRequests/createMinimumProvisionedDevice.json +0 -7
  67. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDevice.json +0 -7
  68. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceMultientity.json +0 -7
  69. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic.json +0 -14
  70. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic2.json +0 -14
  71. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic3.json +1 -15
  72. package/test/unit/ngsi-ld/examples/contextRequests/createTimeInstantMinimumDevice.json +0 -7
  73. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin6.json +0 -7
  74. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast5.json +0 -7
  75. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin12a.json +7 -0
  76. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin13.json +13 -13
  77. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin16.json +0 -7
  78. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin17.json +0 -7
  79. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin1a.json +18 -0
  80. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin29.json +18 -0
  81. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin31.json +15 -0
  82. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin32.json +17 -0
  83. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin33.json +18 -0
  84. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin34.json +17 -0
  85. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin4a.json +36 -0
  86. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin5.json +0 -7
  87. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin7.json +16 -16
  88. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin8a.json +18 -0
  89. package/test/unit/ngsi-ld/examples/contextRequests/updateContextGeoproperties3.json +0 -7
  90. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin15.json +25 -0
  91. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +6 -6
  92. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +3 -3
  93. package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionActiveAttributes1.json +0 -7
  94. package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionCommands1.json +0 -7
  95. package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionDeviceStatic.json +0 -7
  96. package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionMinimumDevice.json +0 -7
  97. package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +1018 -0
  98. package/test/unit/ngsi-ld/general/contextBrokerOAuthSecurityAccess-test.js +2 -2
  99. package/test/unit/ngsi-ld/general/deviceService-test.js +1 -1
  100. package/test/unit/ngsi-ld/general/https-support-test.js +2 -1
  101. package/test/unit/ngsi-ld/general/iotam-autoregistration-test.js +2 -1
  102. package/test/unit/ngsi-ld/general/startup-test.js +1 -0
  103. package/test/unit/ngsi-ld/lazyAndCommands/active-devices-attribute-update-test.js +3 -1
  104. package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +2 -1
  105. package/test/unit/ngsi-ld/lazyAndCommands/lazy-devices-test.js +2 -6
  106. package/test/unit/ngsi-ld/lazyAndCommands/polling-commands-test.js +2 -1
  107. package/test/unit/ngsi-ld/ngsiService/active-devices-test.js +1 -0
  108. package/test/unit/ngsi-ld/ngsiService/autocast-test.js +1 -0
  109. package/test/unit/ngsi-ld/ngsiService/geoproperties-test.js +1 -0
  110. package/test/unit/ngsi-ld/ngsiService/subscriptions-test.js +4 -3
  111. package/test/unit/ngsi-ld/plugins/alias-plugin_test.js +1 -0
  112. package/test/unit/ngsi-ld/plugins/bidirectional-plugin_test.js +3 -2
  113. package/test/unit/ngsi-ld/plugins/multientity-plugin_test.js +61 -0
  114. package/test/unit/ngsi-ld/provisioning/device-provisioning-api_test.js +2 -1
  115. package/test/unit/ngsi-ld/provisioning/device-registration_test.js +3 -2
  116. package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +1 -0
  117. package/test/unit/ngsi-ld/provisioning/listProvisionedDevices-test.js +42 -54
  118. package/test/unit/ngsi-ld/provisioning/provisionDeviceMultientity-test.js +2 -1
  119. package/test/unit/ngsi-ld/provisioning/removeProvisionedDevice-test.js +4 -4
  120. package/test/unit/ngsi-ld/provisioning/singleConfigurationMode-test.js +3 -5
  121. package/test/unit/ngsi-ld/provisioning/updateProvisionedDevices-test.js +12 -18
  122. package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +3 -1
  123. package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgent3.json +19 -0
  124. package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgent5.json +19 -0
  125. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin17.json +1 -1
  126. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin29.json +22 -0
  127. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin30.json +6 -0
  128. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin31.json +18 -0
  129. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin32.json +16 -0
  130. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin33.json +22 -0
  131. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin34.json +12 -0
  132. package/test/unit/ngsiv2/examples/contextRequests/updateContextMiddleware1.json +10 -0
  133. package/test/unit/ngsiv2/examples/contextRequests/updateContextMiddleware2.json +10 -0
  134. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin11.json +13 -0
  135. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin12.json +33 -0
  136. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin13.json +33 -0
  137. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin14.json +33 -0
  138. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin15.json +25 -0
  139. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin16.json +25 -0
  140. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +6 -6
  141. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +3 -3
  142. package/test/unit/{examples → ngsiv2/examples}/contextRequests/updateProvisionDevice.json +0 -0
  143. package/test/unit/ngsiv2/expressions/expressionBasedTransformations-test.js +37 -4
  144. package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +598 -0
  145. package/test/unit/ngsiv2/general/contextBrokerOAuthSecurityAccess-test.js +3 -2
  146. package/test/unit/ngsiv2/general/deviceService-test.js +9 -8
  147. package/test/unit/ngsiv2/general/https-support-test.js +2 -1
  148. package/test/unit/ngsiv2/general/iotam-autoregistration-test.js +2 -1
  149. package/test/unit/ngsiv2/general/startup-test.js +1 -0
  150. package/test/unit/ngsiv2/lazyAndCommands/active-devices-attribute-update-test.js +3 -1
  151. package/test/unit/ngsiv2/lazyAndCommands/command-test.js +2 -1
  152. package/test/unit/ngsiv2/lazyAndCommands/lazy-devices-test.js +287 -15
  153. package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +3 -1
  154. package/test/unit/ngsiv2/ngsiService/active-devices-test.js +88 -0
  155. package/test/unit/{ngsiService → ngsiv2/ngsiService}/queryDeviceInformationInCb-test.js +20 -49
  156. package/test/unit/ngsiv2/ngsiService/subscriptions-test.js +4 -3
  157. package/test/unit/ngsiv2/plugins/bidirectional-plugin_test.js +3 -2
  158. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +526 -0
  159. package/test/unit/{plugins → ngsiv2/plugins}/translation-inPlugins_test.js +21 -21
  160. package/test/unit/{provisioning → ngsiv2/provisioning}/device-group-api-test.js +19 -50
  161. package/test/unit/{provisioning/device-group-utils_test.js → ngsiv2/provisioning/device-group-utils-test.js} +5 -4
  162. package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +2 -1
  163. package/test/unit/ngsiv2/provisioning/device-registration_test.js +3 -2
  164. package/test/unit/ngsiv2/provisioning/device-update-registration_test.js +4 -3
  165. package/test/unit/ngsiv2/provisioning/listProvisionedDevices-test.js +42 -53
  166. package/test/unit/ngsiv2/provisioning/provisionDeviceMultientity-test.js +2 -1
  167. package/test/unit/ngsiv2/provisioning/removeProvisionedDevice-test.js +4 -4
  168. package/test/unit/ngsiv2/provisioning/singleConfigurationMode-test.js +3 -4
  169. package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +14 -20
  170. package/test/unit/plugins/capture-configuration-inPlugins_test.js +3 -1
  171. package/test/unit/plugins/capture-provision-inPlugins_test.js +8 -18
  172. package/.eslintcache +0 -1
  173. package/.nyc_output/dca24ca1-851e-490c-9d34-8d13b3330297.json +0 -1
  174. package/.nyc_output/processinfo/dca24ca1-851e-490c-9d34-8d13b3330297.json +0 -1
  175. package/bin/agentConsole.js +0 -257
  176. package/bin/iotAgentTester.js +0 -44
  177. package/lib/command/commandLine.js +0 -918
  178. package/lib/command/migration.js +0 -176
  179. package/lib/services/devices/devices-NGSI-v1.js +0 -310
  180. package/lib/services/ngsi/entities-NGSI-v1.js +0 -299
  181. package/lib/services/ngsi/subscription-NGSI-v1.js +0 -234
  182. package/lib/services/northBound/contextServer-NGSI-v1.js +0 -526
  183. package/lib/templates/notificationTemplateNgsi1.json +0 -75
  184. package/lib/templates/updateContextNgsi1.json +0 -50
  185. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent1.json +0 -21
  186. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent2.json +0 -21
  187. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent3.json +0 -25
  188. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent4.json +0 -22
  189. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgentAttributeUpdates.json +0 -16
  190. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgentCommands.json +0 -21
  191. package/test/unit/examples/contextAvailabilityRequests/registerNewDevice1.json +0 -21
  192. package/test/unit/examples/contextAvailabilityRequests/registerNewDevice2.json +0 -21
  193. package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDevice.json +0 -25
  194. package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDevice2.json +0 -21
  195. package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup.json +0 -33
  196. package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup2.json +0 -33
  197. package/test/unit/examples/contextAvailabilityRequests/unregisterDevice1.json +0 -22
  198. package/test/unit/examples/contextAvailabilityRequests/unregisterDevice3.json +0 -26
  199. package/test/unit/examples/contextAvailabilityRequests/unregisterProvisionedDevice.json +0 -26
  200. package/test/unit/examples/contextAvailabilityRequests/updateCommands1.json +0 -22
  201. package/test/unit/examples/contextAvailabilityRequests/updateIoTAgent1.json +0 -22
  202. package/test/unit/examples/contextAvailabilityRequests/updateIoTAgent2.json +0 -26
  203. package/test/unit/examples/contextAvailabilityRequests/updateIoTAgent3.json +0 -26
  204. package/test/unit/examples/contextAvailabilityResponses/registerIoTAgent1Failed.json +0 -8
  205. package/test/unit/examples/contextAvailabilityResponses/registerIoTAgent1Success.json +0 -4
  206. package/test/unit/examples/contextAvailabilityResponses/registerNewDevice1Success.json +0 -4
  207. package/test/unit/examples/contextAvailabilityResponses/registerNewDevice2Success.json +0 -4
  208. package/test/unit/examples/contextAvailabilityResponses/registerProvisionedDeviceSuccess.json +0 -4
  209. package/test/unit/examples/contextAvailabilityResponses/unregisterDevice1Failed.json +0 -8
  210. package/test/unit/examples/contextAvailabilityResponses/unregisterDevice1Success.json +0 -4
  211. package/test/unit/examples/contextAvailabilityResponses/updateCommands1Success.json +0 -4
  212. package/test/unit/examples/contextAvailabilityResponses/updateIoTAgent1Success.json +0 -6
  213. package/test/unit/examples/contextProviderResponses/queryInformationResponse.json +0 -22
  214. package/test/unit/examples/contextProviderResponses/queryInformationResponseEmptyAttributes.json +0 -22
  215. package/test/unit/examples/contextProviderResponses/queryInformationStaticAttributesResponse.json +0 -27
  216. package/test/unit/examples/contextProviderResponses/updateInformationResponse.json +0 -22
  217. package/test/unit/examples/contextProviderResponses/updateInformationResponse2.json +0 -22
  218. package/test/unit/examples/contextRequests/contextSubscriptionRequest.json +0 -20
  219. package/test/unit/examples/contextRequests/contextSubscriptionRequest2.json +0 -20
  220. package/test/unit/examples/contextRequests/createBidirectionalDevice.json +0 -17
  221. package/test/unit/examples/contextRequests/createDatetimeProvisionedDevice.json +0 -17
  222. package/test/unit/examples/contextRequests/createGeopointProvisionedDevice.json +0 -17
  223. package/test/unit/examples/contextRequests/createMinimumProvisionedDevice.json +0 -17
  224. package/test/unit/examples/contextRequests/createProvisionedDevice.json +0 -32
  225. package/test/unit/examples/contextRequests/createProvisionedDeviceMultientity.json +0 -32
  226. package/test/unit/examples/contextRequests/createProvisionedDeviceWithGroup.json +0 -47
  227. package/test/unit/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic.json +0 -52
  228. package/test/unit/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic2.json +0 -52
  229. package/test/unit/examples/contextRequests/createTimeinstantDevice.json +0 -17
  230. package/test/unit/examples/contextRequests/queryContext1.json +0 -13
  231. package/test/unit/examples/contextRequests/queryContext2.json +0 -13
  232. package/test/unit/examples/contextRequests/queryContextAliasPlugin1.json +0 -10
  233. package/test/unit/examples/contextRequests/queryContextCompressTimestamp1.json +0 -13
  234. package/test/unit/examples/contextRequests/updateActiveAttributes.json +0 -32
  235. package/test/unit/examples/contextRequests/updateContext1.json +0 -22
  236. package/test/unit/examples/contextRequests/updateContext2.json +0 -22
  237. package/test/unit/examples/contextRequests/updateContext3.json +0 -17
  238. package/test/unit/examples/contextRequests/updateContext3WithStatic.json +0 -22
  239. package/test/unit/examples/contextRequests/updateContext4.json +0 -22
  240. package/test/unit/examples/contextRequests/updateContext5.json +0 -19
  241. package/test/unit/examples/contextRequests/updateContextAliasPlugin.json +0 -22
  242. package/test/unit/examples/contextRequests/updateContextAliasPlugin2.json +0 -17
  243. package/test/unit/examples/contextRequests/updateContextAppendMode.json +0 -22
  244. package/test/unit/examples/contextRequests/updateContextCommandError.json +0 -22
  245. package/test/unit/examples/contextRequests/updateContextCommandExpired.json +0 -22
  246. package/test/unit/examples/contextRequests/updateContextCommandFinish.json +0 -22
  247. package/test/unit/examples/contextRequests/updateContextCommandStatus.json +0 -17
  248. package/test/unit/examples/contextRequests/updateContextCompressTimestamp1.json +0 -22
  249. package/test/unit/examples/contextRequests/updateContextCompressTimestamp2.json +0 -29
  250. package/test/unit/examples/contextRequests/updateContextExpressionPlugin1.json +0 -17
  251. package/test/unit/examples/contextRequests/updateContextExpressionPlugin10.json +0 -17
  252. package/test/unit/examples/contextRequests/updateContextExpressionPlugin2.json +0 -27
  253. package/test/unit/examples/contextRequests/updateContextExpressionPlugin3.json +0 -17
  254. package/test/unit/examples/contextRequests/updateContextExpressionPlugin4.json +0 -17
  255. package/test/unit/examples/contextRequests/updateContextExpressionPlugin5.json +0 -27
  256. package/test/unit/examples/contextRequests/updateContextExpressionPlugin6.json +0 -17
  257. package/test/unit/examples/contextRequests/updateContextExpressionPlugin7.json +0 -27
  258. package/test/unit/examples/contextRequests/updateContextExpressionPlugin8.json +0 -22
  259. package/test/unit/examples/contextRequests/updateContextExpressionPlugin9.json +0 -27
  260. package/test/unit/examples/contextRequests/updateContextMiddleware1.json +0 -22
  261. package/test/unit/examples/contextRequests/updateContextMultiEntityPlugin3.json +0 -35
  262. package/test/unit/examples/contextRequests/updateContextMultientityPlugin1.json +0 -30
  263. package/test/unit/examples/contextRequests/updateContextMultientityPlugin2.json +0 -30
  264. package/test/unit/examples/contextRequests/updateContextProcessTimestamp1.json +0 -29
  265. package/test/unit/examples/contextRequests/updateContextStaticAttributes.json +0 -22
  266. package/test/unit/examples/contextRequests/updateContextTimestamp.json +0 -41
  267. package/test/unit/examples/contextRequests/updateContextTimestampOverride.json +0 -22
  268. package/test/unit/examples/contextRequests/updateContextTimestampOverrideWithoutMilis.json +0 -22
  269. package/test/unit/examples/contextRequests/updateContextTimestampTimezone.json +0 -41
  270. package/test/unit/examples/contextRequests/updateProvisionActiveAttributes1.json +0 -17
  271. package/test/unit/examples/contextRequests/updateProvisionCommands1.json +0 -27
  272. package/test/unit/examples/contextRequests/updateProvisionDeviceStatic.json +0 -38
  273. package/test/unit/examples/contextRequests/updateProvisionMinimumDevice.json +0 -17
  274. package/test/unit/examples/contextResponses/contextSubscriptionRequest2Success.json +0 -7
  275. package/test/unit/examples/contextResponses/contextSubscriptionRequestSuccess.json +0 -7
  276. package/test/unit/examples/contextResponses/createBidirectionalDeviceSuccess.json +0 -22
  277. package/test/unit/examples/contextResponses/createDatetimeProvisionedDeviceSuccess.json +0 -22
  278. package/test/unit/examples/contextResponses/createGeopointProvisionedDeviceSuccess.json +0 -22
  279. package/test/unit/examples/contextResponses/createProvisionedDeviceSuccess.json +0 -22
  280. package/test/unit/examples/contextResponses/createTimeinstantSuccess.json +0 -22
  281. package/test/unit/examples/contextResponses/queryContext1Success.json +0 -27
  282. package/test/unit/examples/contextResponses/queryContext2Error.json +0 -7
  283. package/test/unit/examples/contextResponses/queryContext2UnknownError.json +0 -6
  284. package/test/unit/examples/contextResponses/queryContext3Error.json +0 -34
  285. package/test/unit/examples/contextResponses/queryContextAliasPlugin1Success.json +0 -27
  286. package/test/unit/examples/contextResponses/queryContextCompressTimestamp1Success.json +0 -27
  287. package/test/unit/examples/contextResponses/updateActiveAttributesSuccess.json +0 -42
  288. package/test/unit/examples/contextResponses/updateContext1Failed.json +0 -7
  289. package/test/unit/examples/contextResponses/updateContext1Success.json +0 -27
  290. package/test/unit/examples/contextResponses/updateContext2Failed.json +0 -35
  291. package/test/unit/examples/contextResponses/updateContextAliasPlugin2Success.json +0 -27
  292. package/test/unit/examples/contextResponses/updateContextAliasPluginSuccess.json +0 -27
  293. package/test/unit/examples/contextResponses/updateContextCommandFinishSuccess.json +0 -27
  294. package/test/unit/examples/contextResponses/updateContextCommandStatusSuccess.json +0 -22
  295. package/test/unit/examples/contextResponses/updateContextCompressTimestamp1Success.json +0 -27
  296. package/test/unit/examples/contextResponses/updateContextCompressTimestamp2Success.json +0 -34
  297. package/test/unit/examples/contextResponses/updateContextEvents1Success.json +0 -27
  298. package/test/unit/examples/contextResponses/updateContextExpressionPlugin1Success.json +0 -22
  299. package/test/unit/examples/contextResponses/updateContextExpressionPlugin2Success.json +0 -22
  300. package/test/unit/examples/contextResponses/updateContextExpressionPlugin3Success.json +0 -22
  301. package/test/unit/examples/contextResponses/updateContextExpressionPlugin5Success.json +0 -32
  302. package/test/unit/examples/contextResponses/updateContextMultientityPlugin1Success.json +0 -40
  303. package/test/unit/examples/contextResponses/updateContextMultientityPlugin2Success.json +0 -40
  304. package/test/unit/examples/contextResponses/updateContextMultientityPlugin3Success.json +0 -40
  305. package/test/unit/examples/contextResponses/updateContextProcessTimestamp1Success.json +0 -27
  306. package/test/unit/examples/contextResponses/updateProvisionActiveAttributes1Success.json +0 -22
  307. package/test/unit/examples/contextResponses/updateProvisionCommands1Success.json +0 -32
  308. package/test/unit/examples/contextResponses/updateProvisionMinimumDeviceSuccess.json +0 -22
  309. package/test/unit/examples/subscriptionRequests/bidirectionalNotification.json +0 -24
  310. package/test/unit/examples/subscriptionRequests/bidirectionalSubscriptionRemove.json +0 -3
  311. package/test/unit/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json +0 -22
  312. package/test/unit/examples/subscriptionRequests/errorNotification.json +0 -24
  313. package/test/unit/examples/subscriptionRequests/simpleNotification.json +0 -24
  314. package/test/unit/examples/subscriptionRequests/simpleSubscriptionRemove.json +0 -3
  315. package/test/unit/examples/subscriptionRequests/simpleSubscriptionRequest.json +0 -19
  316. package/test/unit/examples/subscriptionRequests/simpleSubscriptionRequest1.json +0 -19
  317. package/test/unit/examples/subscriptionResponses/bidirectionalSubscriptionSuccess.json +0 -6
  318. package/test/unit/examples/subscriptionResponses/simpleSubscriptionSuccess.json +0 -6
  319. package/test/unit/expressions/expressionBasedTransformations-test.js +0 -328
  320. package/test/unit/expressions/expressionCombinedTransformations-test.js +0 -306
  321. package/test/unit/expressions/jexlBasedTransformations-test.js +0 -334
  322. package/test/unit/general/contextBrokerOAuthSecurityAccess-test.js +0 -902
  323. package/test/unit/general/https-support-test.js +0 -286
  324. package/test/unit/general/iotam-autoregistration-test.js +0 -368
  325. package/test/unit/general/migration-test.js +0 -256
  326. package/test/unit/lazyAndCommands/active-devices-attribute-update-test.js +0 -168
  327. package/test/unit/lazyAndCommands/command-test.js +0 -341
  328. package/test/unit/lazyAndCommands/lazy-devices-test.js +0 -878
  329. package/test/unit/lazyAndCommands/polling-commands-test.js +0 -421
  330. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin20.json +0 -25
  331. package/test/unit/ngsiService/active-devices-test.js +0 -692
  332. package/test/unit/ngsiService/staticAttributes-test.js +0 -148
  333. package/test/unit/ngsiService/subscriptions-test.js +0 -345
  334. package/test/unit/plugins/alias-plugin_test.js +0 -158
  335. package/test/unit/plugins/bidirectional-plugin_test.js +0 -564
  336. package/test/unit/plugins/compress-timestamp-plugin_test.js +0 -257
  337. package/test/unit/plugins/event-plugin_test.js +0 -119
  338. package/test/unit/plugins/multientity-plugin_test.js +0 -248
  339. package/test/unit/plugins/timestamp-processing-plugin_test.js +0 -119
  340. package/test/unit/provisioning/device-provisioning-api_test.js +0 -748
  341. package/test/unit/provisioning/device-registration_test.js +0 -432
  342. package/test/unit/provisioning/device-update-registration_test.js +0 -326
  343. package/test/unit/provisioning/listProvisionedDevices-test.js +0 -488
  344. package/test/unit/provisioning/provisionDeviceMultientity-test.js +0 -123
  345. package/test/unit/provisioning/removeProvisionedDevice-test.js +0 -244
  346. package/test/unit/provisioning/singleConfigurationMode-test.js +0 -346
  347. package/test/unit/provisioning/updateProvisionedDevices-test.js +0 -436
@@ -0,0 +1,1018 @@
1
+ /*
2
+ * Copyright 2014 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, seehttp://www.gnu.org/licenses/.
19
+ *
20
+ * For those usages not covered by the GNU Affero General Public License
21
+ * please contact with::[contacto@tid.es]
22
+ *
23
+ * Developed by: Federico M. Facca - Martel Innovate
24
+ */
25
+
26
+ /* jshint camelcase: false */
27
+
28
+ const iotAgentLib = require('../../../../lib/fiware-iotagent-lib');
29
+ const utils = require('../../../tools/utils');
30
+ const should = require('should');
31
+ const logger = require('logops');
32
+ const nock = require('nock');
33
+ const timekeeper = require('timekeeper');
34
+ let contextBrokerMock;
35
+ const iotAgentConfig = {
36
+ logLevel: 'FATAL',
37
+ contextBroker: {
38
+ host: '192.168.1.1',
39
+ port: '1026',
40
+ ngsiVersion: 'ld',
41
+ jsonLdContext: 'http://context.json-ld'
42
+ },
43
+ defaultExpressionLanguage: 'jexl',
44
+ server: {
45
+ port: 4041
46
+ },
47
+ types: {
48
+ Light: {
49
+ commands: [],
50
+ type: 'Light',
51
+ lazy: [],
52
+ active: [
53
+ {
54
+ object_id: 'p',
55
+ name: 'pressure',
56
+ type: 'Number'
57
+ },
58
+ {
59
+ object_id: 'e',
60
+ name: 'consumption',
61
+ type: 'Number'
62
+ },
63
+ {
64
+ object_id: 'a',
65
+ name: 'alive',
66
+ type: 'None'
67
+ },
68
+ {
69
+ object_id: 'u',
70
+ name: 'updated',
71
+ type: 'Boolean'
72
+ },
73
+ {
74
+ object_id: 'm',
75
+ name: 'manufacturer',
76
+ type: 'Object'
77
+ },
78
+ {
79
+ object_id: 'r',
80
+ name: 'revisions',
81
+ type: 'Array'
82
+ },
83
+ {
84
+ object_id: 'x',
85
+ name: 'consumption_x',
86
+ type: 'Number',
87
+ expression: 'pressure * 20'
88
+ }
89
+ ]
90
+ },
91
+ LightError: {
92
+ commands: [],
93
+ type: 'Light',
94
+ lazy: [],
95
+ active: [
96
+ {
97
+ object_id: 'p',
98
+ name: 'pressure',
99
+ type: 'Number',
100
+ expression: 'pressure * / 20'
101
+ }
102
+ ]
103
+ },
104
+ WeatherStation: {
105
+ commands: [],
106
+ type: 'WeatherStation',
107
+ lazy: [],
108
+ active: [
109
+ {
110
+ object_id: 'p',
111
+ name: 'pressure',
112
+ type: 'Number',
113
+ expression: 'pressure * 20'
114
+ },
115
+ {
116
+ object_id: 'e',
117
+ name: 'consumption',
118
+ type: 'Number',
119
+ expression: 'consumption * 20'
120
+ },
121
+ {
122
+ object_id: 'h',
123
+ name: 'humidity',
124
+ type: 'Percentage'
125
+ },
126
+ {
127
+ name: 'weather',
128
+ type: 'Summary',
129
+ expression: '"Humidity " + (humidity / 2) + " and pressure " + (pressure * 20)'
130
+ },
131
+ {
132
+ object_id: 'a',
133
+ name: 'alive',
134
+ type: 'None',
135
+ expression: 'alive * 20'
136
+ },
137
+ {
138
+ object_id: 'u',
139
+ name: 'updated',
140
+ type: 'Boolean',
141
+ expression: 'updated * 20'
142
+ }
143
+ ]
144
+ },
145
+ WeatherStationUndef: {
146
+ commands: [],
147
+ type: 'WeatherStation',
148
+ lazy: [],
149
+ active: [
150
+ {
151
+ object_id: 'u',
152
+ name: 'undef',
153
+ type: 'json',
154
+ expression: 'u["no"]'
155
+ },
156
+ {
157
+ object_id: 'n',
158
+ name: 'nil',
159
+ type: 'json',
160
+ expression: 'u["no"]?u["no"]:null'
161
+ },
162
+ {
163
+ object_id: 'f',
164
+ name: 'falsy',
165
+ type: 'Boolean',
166
+ expression: 'u["no"]?u["no"]:false'
167
+ },
168
+ {
169
+ object_id: 'z',
170
+ name: 'zero',
171
+ type: 'Number',
172
+ expression: 'u["no"]?u["no"]:0'
173
+ }
174
+ ]
175
+ },
176
+ WeatherStationMultiple: {
177
+ commands: [],
178
+ type: 'WeatherStation',
179
+ lazy: [],
180
+ active: [
181
+ {
182
+ object_id: 'p',
183
+ name: 'pressure',
184
+ type: 'Number',
185
+ expression: 'pressure|trim'
186
+ },
187
+ {
188
+ object_id: 'p25',
189
+ name: 'pressure25',
190
+ type: 'Number'
191
+ },
192
+ {
193
+ object_id: 'e',
194
+ name: 'consumption',
195
+ type: 'Number',
196
+ expression: 'consumption|trim'
197
+ },
198
+ {
199
+ object_id: 'h',
200
+ name: 'humidity12',
201
+ type: 'Percentage'
202
+ },
203
+ {
204
+ name: 'weather',
205
+ type: 'Summary',
206
+ expression: '"Humidity " + (humidity12 / 2) + " and pressure " + (pressure25 * 20)'
207
+ },
208
+ {
209
+ object_id: 'a',
210
+ name: 'alive',
211
+ type: 'None',
212
+ expression: 'alive|trim'
213
+ },
214
+ {
215
+ object_id: 'u',
216
+ name: 'updated',
217
+ type: 'Boolean',
218
+ expression: 'updated|trim'
219
+ }
220
+ ]
221
+ },
222
+ GPS: {
223
+ commands: [],
224
+ type: 'GPS',
225
+ lazy: [],
226
+ active: [
227
+ {
228
+ name: 'location',
229
+ type: 'geo:json',
230
+ expression: "{coordinates: [lon,lat], type: 'Point'}"
231
+ },
232
+ {
233
+ name: 'TimeInstant',
234
+ type: 'DateTime',
235
+ expression: 'ts|toisodate'
236
+ }
237
+ ],
238
+ explicitAttrs: true
239
+ },
240
+ GPS2: {
241
+ commands: [],
242
+ type: 'GPS',
243
+ lazy: [],
244
+ active: [
245
+ {
246
+ name: 'location',
247
+ type: 'geo:json',
248
+ expression: "{coordinates: [lon,lat], type: 'Point'}"
249
+ }
250
+ ],
251
+ explicitAttrs: true
252
+ }
253
+ },
254
+ service: 'smartgondor',
255
+ subservice: 'gardens',
256
+ providerUrl: 'http://smartgondor.com',
257
+ deviceRegistrationDuration: 'P1M',
258
+ throttling: 'PT5S'
259
+ };
260
+
261
+ const iotAgentConfigTS = {
262
+ logLevel: 'FATAL',
263
+ contextBroker: {
264
+ host: '192.168.1.1',
265
+ port: '1026',
266
+ ngsiVersion: 'ld',
267
+ jsonLdContext: 'http://context.json-ld'
268
+ },
269
+ defaultExpressionLanguage: 'jexl',
270
+ server: {
271
+ port: 4041
272
+ },
273
+ types: {
274
+ GPS: {
275
+ commands: [],
276
+ type: 'GPS',
277
+ lazy: [],
278
+ active: [
279
+ {
280
+ name: 'location',
281
+ type: 'geo:json',
282
+ expression: "{coordinates: [lon,lat], type: 'Point'}"
283
+ }
284
+ ],
285
+ explicitAttrs: true
286
+ }
287
+ },
288
+ timestamp: true,
289
+ service: 'smartgondor',
290
+ subservice: 'gardens',
291
+ providerUrl: 'http://smartgondor.com'
292
+ };
293
+
294
+ describe('NGSI-LD: JEXL', function () {
295
+ beforeEach(function (done) {
296
+ logger.setLevel('FATAL');
297
+
298
+ iotAgentLib.activate(iotAgentConfig, function () {
299
+ iotAgentLib.clearAll(function () {
300
+ iotAgentLib.addUpdateMiddleware(iotAgentLib.dataPlugins.attributeAlias.update);
301
+ iotAgentLib.addQueryMiddleware(iotAgentLib.dataPlugins.attributeAlias.query);
302
+ iotAgentLib.addUpdateMiddleware(iotAgentLib.dataPlugins.expressionTransformation.update);
303
+ done();
304
+ });
305
+ });
306
+ });
307
+
308
+ afterEach(function (done) {
309
+ iotAgentLib.clearAll(function () {
310
+ iotAgentLib.deactivate(done);
311
+ });
312
+ });
313
+
314
+ describe('When an update comes for expressions with syntax errors', function () {
315
+ // Case: Update for an attribute with bad expression
316
+ const values = [
317
+ {
318
+ name: 'p',
319
+ type: 'centigrades',
320
+ value: '52'
321
+ }
322
+ ];
323
+
324
+ it('should apply the expression before sending the values', function (done) {
325
+ iotAgentLib.update('light1', 'LightError', '', values, function (error) {
326
+ should.exist(error);
327
+ error.name.should.equal('INVALID_EXPRESSION');
328
+ error.code.should.equal(400);
329
+ done();
330
+ });
331
+ });
332
+ });
333
+
334
+ describe('When there are expression attributes that are just calculated (not sent by the device)', function () {
335
+ // Case: Expression which results is sent as a new attribute
336
+ const values = [
337
+ {
338
+ name: 'p',
339
+ type: 'Number',
340
+ value: 52
341
+ },
342
+ {
343
+ name: 'h',
344
+ type: 'Percentage',
345
+ value: '12'
346
+ }
347
+ ];
348
+
349
+ beforeEach(function () {
350
+ nock.cleanAll();
351
+
352
+ contextBrokerMock = nock('http://192.168.1.1:1026')
353
+ .matchHeader('fiware-service', 'smartgondor')
354
+ .matchHeader('fiware-servicepath', 'gardens')
355
+ .post(
356
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
357
+ utils.readExampleFile(
358
+ './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin2.json'
359
+ )
360
+ )
361
+ .reply(204);
362
+ });
363
+
364
+ it('should calculate them and add them to the payload', function (done) {
365
+ iotAgentLib.update('ws1', 'WeatherStation', '', values, function (error) {
366
+ should.not.exist(error);
367
+ contextBrokerMock.done();
368
+ done();
369
+ });
370
+ });
371
+ });
372
+
373
+ describe('When an expression with multiple variables with numbers arrive', function () {
374
+ // Case: Update for integer and string attributes with expression
375
+
376
+ const values = [
377
+ {
378
+ name: 'p25',
379
+ type: 'Number',
380
+ value: 52
381
+ },
382
+ {
383
+ name: 'h',
384
+ type: 'percentage',
385
+ value: '12'
386
+ }
387
+ ];
388
+
389
+ beforeEach(function () {
390
+ nock.cleanAll();
391
+
392
+ contextBrokerMock = nock('http://192.168.1.1:1026')
393
+ .matchHeader('fiware-service', 'smartgondor')
394
+ .matchHeader('fiware-servicepath', 'gardens')
395
+ .post(
396
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
397
+ utils.readExampleFile(
398
+ './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin4a.json'
399
+ )
400
+ )
401
+ .reply(204);
402
+ });
403
+
404
+ it('should calculate it and add it to the payload', function (done) {
405
+ iotAgentLib.update('ws1', 'WeatherStationMultiple', '', values, function (error) {
406
+ should.not.exist(error);
407
+ contextBrokerMock.done();
408
+ done();
409
+ });
410
+ });
411
+ });
412
+
413
+ describe('When an update comes for attributes without expressions and type integer', function () {
414
+ // Case: Update for an integer attribute without expression
415
+ const values = [
416
+ {
417
+ name: 'e',
418
+ type: 'Number',
419
+ value: 52
420
+ }
421
+ ];
422
+
423
+ beforeEach(function () {
424
+ nock.cleanAll();
425
+
426
+ contextBrokerMock = nock('http://192.168.1.1:1026')
427
+ .matchHeader('fiware-service', 'smartgondor')
428
+ .matchHeader('fiware-servicepath', 'gardens')
429
+ .post(
430
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
431
+ utils.readExampleFile(
432
+ './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin11.json'
433
+ )
434
+ )
435
+ .reply(204);
436
+ });
437
+
438
+ it('should apply the expression before sending the values', function (done) {
439
+ iotAgentLib.update('light1', 'Light', '', values, function (error) {
440
+ should.not.exist(error);
441
+ contextBrokerMock.done();
442
+ done();
443
+ });
444
+ });
445
+ });
446
+
447
+ describe('When an update comes for attributes with numeric expressions and type integer', function () {
448
+ // Case: Update for an integer attribute with arithmetic expression
449
+ const values = [
450
+ {
451
+ name: 'p',
452
+ type: 'Number',
453
+ value: 52
454
+ }
455
+ ];
456
+
457
+ beforeEach(function () {
458
+ nock.cleanAll();
459
+
460
+ contextBrokerMock = nock('http://192.168.1.1:1026')
461
+ .matchHeader('fiware-service', 'smartgondor')
462
+ .matchHeader('fiware-servicepath', 'gardens')
463
+ .post(
464
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
465
+ utils.readExampleFile(
466
+ './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin1a.json'
467
+ )
468
+ )
469
+ .reply(204);
470
+ });
471
+
472
+ it('should apply the expression before sending the values', function (done) {
473
+ iotAgentLib.update('ws1', 'WeatherStation', '', values, function (error) {
474
+ should.not.exist(error);
475
+ contextBrokerMock.done();
476
+ done();
477
+ });
478
+ });
479
+ });
480
+
481
+ describe('When an update comes for attributes without expressions and type float', function () {
482
+ // Case: Update for a Float attribute without expressions
483
+
484
+ const values = [
485
+ {
486
+ name: 'e',
487
+ type: 'Number',
488
+ value: 0.44
489
+ }
490
+ ];
491
+
492
+ beforeEach(function () {
493
+ nock.cleanAll();
494
+
495
+ contextBrokerMock = nock('http://192.168.1.1:1026')
496
+ .matchHeader('fiware-service', 'smartgondor')
497
+ .matchHeader('fiware-servicepath', 'gardens')
498
+ .post(
499
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
500
+ utils.readExampleFile(
501
+ './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin3.json'
502
+ )
503
+ )
504
+ .reply(204);
505
+ });
506
+
507
+ it('should apply the expression before sending the values', function (done) {
508
+ iotAgentLib.update('light1', 'Light', '', values, function (error) {
509
+ should.not.exist(error);
510
+ contextBrokerMock.done();
511
+ done();
512
+ });
513
+ });
514
+ });
515
+
516
+ describe('When an update comes for attributes with numeric expressions and type float', function () {
517
+ // Case: Update for a Float attribute with arithmetic expression
518
+
519
+ const values = [
520
+ {
521
+ name: 'e',
522
+ type: 'Number',
523
+ value: 0.44
524
+ }
525
+ ];
526
+
527
+ beforeEach(function () {
528
+ nock.cleanAll();
529
+
530
+ contextBrokerMock = nock('http://192.168.1.1:1026')
531
+ .matchHeader('fiware-service', 'smartgondor')
532
+ .matchHeader('fiware-servicepath', 'gardens')
533
+ .post(
534
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
535
+ utils.readExampleFile(
536
+ './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin8a.json'
537
+ )
538
+ )
539
+ .reply(204);
540
+ });
541
+
542
+ it('should apply the expression before sending the values', function (done) {
543
+ iotAgentLib.update('ws1', 'WeatherStation', '', values, function (error) {
544
+ should.not.exist(error);
545
+ contextBrokerMock.done();
546
+ done();
547
+ });
548
+ });
549
+ });
550
+
551
+ describe('When an update comes for attributes without expressions and NULL type', function () {
552
+ // Case: Update for a Null attribute without expression
553
+
554
+ const values = [
555
+ {
556
+ name: 'a',
557
+ type: 'None',
558
+ value: null
559
+ }
560
+ ];
561
+
562
+ beforeEach(function () {
563
+ nock.cleanAll();
564
+
565
+ contextBrokerMock = nock('http://192.168.1.1:1026')
566
+ .matchHeader('fiware-service', 'smartgondor')
567
+ .matchHeader('fiware-servicepath', 'gardens')
568
+ .post(
569
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
570
+ utils.readExampleFile(
571
+ './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin5.json'
572
+ )
573
+ )
574
+ .reply(204);
575
+ });
576
+
577
+ it('should apply the expression before sending the values', function (done) {
578
+ iotAgentLib.update('light1', 'Light', '', values, function (error) {
579
+ should.not.exist(error);
580
+ contextBrokerMock.done();
581
+ done();
582
+ });
583
+ });
584
+ });
585
+
586
+ describe('When an update comes for attributes without expressions and Boolean type', function () {
587
+ // Case: Update for a Boolean attribute without expression
588
+
589
+ const values = [
590
+ {
591
+ name: 'u',
592
+ type: 'Boolean',
593
+ value: true
594
+ }
595
+ ];
596
+
597
+ beforeEach(function () {
598
+ nock.cleanAll();
599
+
600
+ contextBrokerMock = nock('http://192.168.1.1:1026')
601
+ .matchHeader('fiware-service', 'smartgondor')
602
+ .matchHeader('fiware-servicepath', 'gardens')
603
+ .post(
604
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
605
+ utils.readExampleFile(
606
+ './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin9.json'
607
+ )
608
+ )
609
+ .reply(204);
610
+ });
611
+
612
+ it('should apply the expression before sending the values', function (done) {
613
+ iotAgentLib.update('light1', 'Light', '', values, function (error) {
614
+ should.not.exist(error);
615
+ contextBrokerMock.done();
616
+ done();
617
+ });
618
+ });
619
+ });
620
+
621
+ describe('When an update comes for attributes without expressions and Object type', function () {
622
+ // Case: Update for a JSON document attribute without expression
623
+ const values = [
624
+ {
625
+ name: 'm',
626
+ type: 'Object',
627
+ value: { name: 'Manufacturer1', VAT: 'U12345678' }
628
+ }
629
+ ];
630
+
631
+ beforeEach(function () {
632
+ nock.cleanAll();
633
+
634
+ contextBrokerMock = nock('http://192.168.1.1:1026')
635
+ .matchHeader('fiware-service', 'smartgondor')
636
+ .matchHeader('fiware-servicepath', 'gardens')
637
+ .post(
638
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
639
+ utils.readExampleFile(
640
+ './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin6.json'
641
+ )
642
+ )
643
+ .reply(204);
644
+ });
645
+
646
+ it('should apply the expression before sending the values', function (done) {
647
+ iotAgentLib.update('light1', 'Light', '', values, function (error) {
648
+ should.not.exist(error);
649
+ contextBrokerMock.done();
650
+ done();
651
+ });
652
+ });
653
+ });
654
+
655
+ describe('When an update comes for attributes without expressions and Object type', function () {
656
+ // Case: Update for a JSON array attribute without expression
657
+
658
+ const values = [
659
+ {
660
+ name: 'r',
661
+ type: 'Object',
662
+ value: ['v0.1', 'v0.2', 'v0.3']
663
+ }
664
+ ];
665
+
666
+ beforeEach(function () {
667
+ nock.cleanAll();
668
+
669
+ contextBrokerMock = nock('http://192.168.1.1:1026')
670
+ .matchHeader('fiware-service', 'smartgondor')
671
+ .matchHeader('fiware-servicepath', 'gardens')
672
+ .post(
673
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
674
+ utils.readExampleFile(
675
+ './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin7.json'
676
+ )
677
+ )
678
+ .reply(204);
679
+ });
680
+
681
+ it('should apply the expression before sending the values', function (done) {
682
+ iotAgentLib.update('light1', 'Light', '', values, function (error) {
683
+ should.not.exist(error);
684
+ contextBrokerMock.done();
685
+ done();
686
+ });
687
+ });
688
+ });
689
+
690
+ describe('When there are expressions including other attributes and they are not updated', function () {
691
+ const values = [
692
+ {
693
+ name: 'x',
694
+ type: 'Number',
695
+ value: 0.44
696
+ }
697
+ ];
698
+
699
+ beforeEach(function () {
700
+ nock.cleanAll();
701
+
702
+ contextBrokerMock = nock('http://192.168.1.1:1026')
703
+ .matchHeader('fiware-service', 'smartgondor')
704
+ .matchHeader('fiware-servicepath', 'gardens')
705
+ .post(
706
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
707
+ utils.readExampleFile(
708
+ './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin12a.json'
709
+ )
710
+ )
711
+ .reply(204);
712
+ });
713
+
714
+ it('should apply the expression before sending the values', function (done) {
715
+ iotAgentLib.update('light1', 'Light', '', values, function (error) {
716
+ should.not.exist(error);
717
+ contextBrokerMock.done();
718
+ done();
719
+ });
720
+ });
721
+ });
722
+
723
+ describe('When there are expressions including other attributes and they are updated', function () {
724
+ const values = [
725
+ {
726
+ name: 'p',
727
+ type: 'Number',
728
+ value: 10
729
+ }
730
+ ];
731
+
732
+ beforeEach(function () {
733
+ nock.cleanAll();
734
+
735
+ contextBrokerMock = nock('http://192.168.1.1:1026')
736
+ .matchHeader('fiware-service', 'smartgondor')
737
+ .matchHeader('fiware-servicepath', 'gardens')
738
+ .post(
739
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
740
+ utils.readExampleFile(
741
+ './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin13.json'
742
+ )
743
+ )
744
+ .reply(204);
745
+ });
746
+
747
+ it('should apply the expression before sending the values', function (done) {
748
+ iotAgentLib.update('light1', 'Light', '', values, function (error) {
749
+ should.not.exist(error);
750
+ contextBrokerMock.done();
751
+ done();
752
+ });
753
+ });
754
+ });
755
+
756
+ describe('When there are expressions including other attributes and they are updated (overriding situation)', function () {
757
+ const values = [
758
+ {
759
+ name: 'x',
760
+ type: 'Number',
761
+ value: 0.44
762
+ },
763
+ {
764
+ name: 'p',
765
+ type: 'Number',
766
+ value: 10
767
+ }
768
+ ];
769
+
770
+ beforeEach(function () {
771
+ nock.cleanAll();
772
+
773
+ contextBrokerMock = nock('http://192.168.1.1:1026')
774
+ .matchHeader('fiware-service', 'smartgondor')
775
+ .matchHeader('fiware-servicepath', 'gardens')
776
+ .post(
777
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
778
+ utils.readExampleFile(
779
+ './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin13.json'
780
+ )
781
+ )
782
+ .reply(204);
783
+ });
784
+
785
+ it('should apply the expression before sending the values', function (done) {
786
+ iotAgentLib.update('light1', 'Light', '', values, function (error) {
787
+ should.not.exist(error);
788
+ contextBrokerMock.done();
789
+ done();
790
+ });
791
+ });
792
+ });
793
+
794
+ describe('When a measure arrives and there is not enough information to calculate an expression', function () {
795
+ const values = [
796
+ {
797
+ name: 'p',
798
+ type: 'centigrades',
799
+ value: '52'
800
+ }
801
+ ];
802
+
803
+ beforeEach(function () {
804
+ nock.cleanAll();
805
+
806
+ contextBrokerMock = nock('http://192.168.1.1:1026')
807
+ .matchHeader('fiware-service', 'smartgondor')
808
+ .matchHeader('fiware-servicepath', 'gardens')
809
+ .post(
810
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
811
+ utils.readExampleFile(
812
+ './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin29.json'
813
+ )
814
+ )
815
+ .reply(204);
816
+ });
817
+
818
+ it('should not calculate the expression', function (done) {
819
+ iotAgentLib.update('ws1', 'WeatherStation', '', values, function (error) {
820
+ should.not.exist(error);
821
+ contextBrokerMock.done();
822
+ done();
823
+ });
824
+ });
825
+ });
826
+ describe('When a measure arrives and there is not enough information to calculate an expression', function () {
827
+ const values = [
828
+ {
829
+ name: 'u',
830
+ type: 'json',
831
+ value: '{}'
832
+ }
833
+ ];
834
+
835
+ beforeEach(function () {
836
+ nock.cleanAll();
837
+
838
+ contextBrokerMock = nock('http://192.168.1.1:1026')
839
+ .matchHeader('fiware-service', 'smartgondor')
840
+ .matchHeader('fiware-servicepath', 'gardens')
841
+ .post(
842
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
843
+ utils.readExampleFile(
844
+ './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin31.json'
845
+ )
846
+ )
847
+ .reply(204);
848
+ });
849
+
850
+ it('should not calculate the expression and allow falsy values', function (done) {
851
+ iotAgentLib.update('ws1', 'WeatherStationUndef', '', values, function (error) {
852
+ should.not.exist(error);
853
+ contextBrokerMock.done();
854
+ done();
855
+ });
856
+ });
857
+ });
858
+
859
+ describe('When there are additional attributes sent by the device to be calculated and removed', function () {
860
+ // Case: Expression which results is sent as a new attribute
861
+ const values = [
862
+ {
863
+ name: 'lat',
864
+ type: 'Number',
865
+ value: 52
866
+ },
867
+ {
868
+ name: 'lon',
869
+ type: 'Number',
870
+ value: 13
871
+ },
872
+ {
873
+ name: 'ts',
874
+ type: 'Number',
875
+ value: 1
876
+ }
877
+ ];
878
+
879
+ beforeEach(function () {
880
+ nock.cleanAll();
881
+
882
+ contextBrokerMock = nock('http://192.168.1.1:1026')
883
+ .matchHeader('fiware-service', 'smartgondor')
884
+ .matchHeader('fiware-servicepath', 'gardens')
885
+ .post(
886
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
887
+ utils.readExampleFile(
888
+ './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin32.json'
889
+ )
890
+ )
891
+ .reply(204);
892
+ });
893
+
894
+ it('should calculate them and remove non-explicitAttrs from the payload', function (done) {
895
+ iotAgentLib.update('gps1', 'GPS', '', values, function (error) {
896
+ should.not.exist(error);
897
+ contextBrokerMock.done();
898
+ done();
899
+ });
900
+ });
901
+ });
902
+ describe('When there is an extra TimeInstant sent by the device to be removed', function () {
903
+ // Case: Expression which results is sent as a new attribute
904
+ const values = [
905
+ {
906
+ name: 'lat',
907
+ type: 'Number',
908
+ value: 52
909
+ },
910
+ {
911
+ name: 'lon',
912
+ type: 'Number',
913
+ value: 13
914
+ },
915
+ {
916
+ name: 'TimeInstant',
917
+ type: 'DateTime',
918
+ value: '2015-08-05T07:35:01.468+00:00'
919
+ }
920
+ ];
921
+
922
+ beforeEach(function () {
923
+ nock.cleanAll();
924
+
925
+ contextBrokerMock = nock('http://192.168.1.1:1026')
926
+ .matchHeader('fiware-service', 'smartgondor')
927
+ .matchHeader('fiware-servicepath', 'gardens')
928
+ .post(
929
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
930
+ utils.readExampleFile(
931
+ './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin34.json'
932
+ )
933
+ )
934
+ .reply(204);
935
+ });
936
+
937
+ it('should calculate them and remove non-explicitAttrs from the payload', function (done) {
938
+ iotAgentLib.update('gps1', 'GPS2', '', values, function (error) {
939
+ should.not.exist(error);
940
+ contextBrokerMock.done();
941
+ done();
942
+ });
943
+ });
944
+ });
945
+ });
946
+
947
+ describe('NGSI-LD: JEXL - Timestamps', function () {
948
+ beforeEach(function (done) {
949
+ logger.setLevel('FATAL');
950
+
951
+ iotAgentLib.activate(iotAgentConfigTS, function () {
952
+ iotAgentLib.clearAll(function () {
953
+ iotAgentLib.addUpdateMiddleware(iotAgentLib.dataPlugins.attributeAlias.update);
954
+ iotAgentLib.addQueryMiddleware(iotAgentLib.dataPlugins.attributeAlias.query);
955
+ iotAgentLib.addUpdateMiddleware(iotAgentLib.dataPlugins.expressionTransformation.update);
956
+ done();
957
+ });
958
+ });
959
+ });
960
+
961
+ afterEach(function (done) {
962
+ iotAgentLib.clearAll(function () {
963
+ iotAgentLib.deactivate(done);
964
+ });
965
+ });
966
+
967
+ describe('When timestamps are added but are not explicitly defined', function () {
968
+ // Case: Expression which results is sent as a new attribute
969
+ const values = [
970
+ {
971
+ name: 'lat',
972
+ type: 'Number',
973
+ value: 52
974
+ },
975
+ {
976
+ name: 'lon',
977
+ type: 'Number',
978
+ value: 13
979
+ },
980
+ {
981
+ name: 'ts',
982
+ type: 'Number',
983
+ value: 1
984
+ }
985
+ ];
986
+
987
+ beforeEach(function () {
988
+ const time = new Date(1438760101468); // 2015-08-05T07:35:01.468+00:00
989
+
990
+ timekeeper.freeze(time);
991
+ nock.cleanAll();
992
+
993
+ contextBrokerMock = nock('http://192.168.1.1:1026')
994
+ .matchHeader('fiware-service', 'smartgondor')
995
+ .matchHeader('fiware-servicepath', 'gardens')
996
+ .post(
997
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
998
+ utils.readExampleFile(
999
+ './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin33.json'
1000
+ )
1001
+ )
1002
+ .reply(204);
1003
+ });
1004
+
1005
+ afterEach(function (done) {
1006
+ timekeeper.reset();
1007
+ done();
1008
+ });
1009
+
1010
+ it('should calculate them and not remove the timestamp from the payload', function (done) {
1011
+ iotAgentLib.update('gps1', 'GPS', '', values, function (error) {
1012
+ should.not.exist(error);
1013
+ contextBrokerMock.done();
1014
+ done();
1015
+ });
1016
+ });
1017
+ });
1018
+ });