iotagent-node-lib 3.2.0 → 3.4.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 (184) 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/README.md +10 -11
  7. package/doc/README.md +16 -0
  8. package/doc/admin.md +565 -0
  9. package/doc/api.md +32 -85
  10. package/doc/deprecated.md +16 -10
  11. package/doc/{architecture.md → devel/architecture.md} +3 -3
  12. package/doc/{Contribution.md → devel/contribution-guidelines.md} +43 -35
  13. package/doc/devel/development.md +1879 -0
  14. package/doc/{northboundinteractions.md → devel/northboundinteractions.md} +18 -33
  15. package/doc/index.md +3 -5
  16. package/doc/requirements.txt +1 -1
  17. package/docker/Mosquitto/Dockerfile +1 -1
  18. package/docker/Mosquitto/README.md +1 -0
  19. package/lib/commonConfig.js +0 -5
  20. package/lib/fiware-iotagent-lib.js +1 -1
  21. package/lib/jexlTranformsMap.js +2 -1
  22. package/lib/model/Device.js +0 -1
  23. package/lib/model/Group.js +0 -1
  24. package/lib/model/dbConn.js +1 -7
  25. package/lib/plugins/jexlParser.js +1 -1
  26. package/lib/request-shim.js +2 -2
  27. package/lib/services/commands/commandService.js +1 -1
  28. package/lib/services/common/genericMiddleware.js +1 -1
  29. package/lib/services/common/iotManagerService.js +0 -1
  30. package/lib/services/devices/deviceRegistryMemory.js +2 -2
  31. package/lib/services/devices/deviceRegistryMongoDB.js +32 -19
  32. package/lib/services/devices/deviceService.js +44 -43
  33. package/lib/services/devices/devices-NGSI-LD.js +14 -2
  34. package/lib/services/devices/devices-NGSI-mixed.js +0 -2
  35. package/lib/services/devices/devices-NGSI-v2.js +23 -104
  36. package/lib/services/groups/groupService.js +1 -1
  37. package/lib/services/ngsi/entities-NGSI-LD.js +3 -3
  38. package/lib/services/ngsi/entities-NGSI-v2.js +28 -19
  39. package/lib/services/northBound/deviceProvisioningServer.js +14 -8
  40. package/lib/templates/createDevice.json +0 -4
  41. package/lib/templates/createDeviceLax.json +0 -4
  42. package/lib/templates/deviceGroup.json +1 -5
  43. package/lib/templates/updateDevice.json +4 -0
  44. package/lib/templates/updateDeviceLax.json +11 -0
  45. package/mkdocs.yml +6 -11
  46. package/package.json +3 -3
  47. package/scripts/legacy_expression_tool/README.md +280 -0
  48. package/scripts/legacy_expression_tool/legacy_expression_tool.py +423 -0
  49. package/scripts/legacy_expression_tool/requirements.txt +3 -0
  50. package/test/unit/examples/deviceProvisioningRequests/provisionMinimumDevice4.json +0 -1
  51. package/test/unit/general/contextBrokerKeystoneSecurityAccess-test.js +5 -15
  52. package/test/unit/mongodb/mongodb-registry-test.js +1 -1
  53. package/test/unit/ngsi-ld/general/contextBrokerOAuthSecurityAccess-test.js +66 -65
  54. package/test/unit/ngsi-ld/general/https-support-test.js +1 -1
  55. package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +8 -7
  56. package/test/unit/ngsi-ld/lazyAndCommands/merge-patch-test.js +31 -30
  57. package/test/unit/ngsi-ld/lazyAndCommands/polling-commands-test.js +12 -11
  58. package/test/unit/ngsi-ld/ngsiService/subscriptions-test.js +41 -39
  59. package/test/unit/ngsi-ld/provisioning/device-provisioning-api_test.js +122 -122
  60. package/test/unit/ngsi-ld/provisioning/device-registration_test.js +28 -28
  61. package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +18 -17
  62. package/test/unit/ngsi-ld/provisioning/singleConfigurationMode-test.js +7 -7
  63. package/test/unit/ngsi-ld/provisioning/updateProvisionedDevices-test.js +8 -7
  64. package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +33 -37
  65. package/test/unit/ngsiv2/examples/contextRequests/updateContext.json +2 -0
  66. package/test/unit/ngsiv2/examples/contextRequests/updateContext1.json +3 -1
  67. package/test/unit/ngsiv2/examples/contextRequests/updateContext3WithStatic.json +2 -0
  68. package/test/unit/ngsiv2/examples/contextRequests/updateContext4.json +4 -1
  69. package/test/unit/ngsiv2/examples/contextRequests/updateContext5.json +12 -0
  70. package/test/unit/ngsiv2/examples/contextRequests/updateContext6.json +12 -0
  71. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin1.json +2 -0
  72. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin2.json +3 -1
  73. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin3.json +3 -1
  74. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin4.json +3 -1
  75. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin5.json +3 -1
  76. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin6.json +3 -1
  77. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin7.json +3 -1
  78. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin8.json +3 -1
  79. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin9.json +3 -1
  80. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast1.json +2 -0
  81. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast2.json +2 -0
  82. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast3.json +3 -1
  83. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast4.json +3 -1
  84. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast5.json +3 -1
  85. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast6.json +3 -1
  86. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast7.json +3 -1
  87. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandError.json +3 -1
  88. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandExpired.json +3 -1
  89. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandFinish.json +3 -1
  90. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandStatus.json +2 -0
  91. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandStatus2.json +2 -0
  92. package/test/unit/ngsiv2/examples/contextRequests/updateContextCompressTimestamp1.json +3 -1
  93. package/test/unit/ngsiv2/examples/contextRequests/updateContextCompressTimestamp2.json +3 -1
  94. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin1.json +2 -12
  95. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin11.json +2 -4
  96. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin12.json +2 -4
  97. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin13.json +3 -1
  98. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin2.json +2 -12
  99. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin29.json +2 -12
  100. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin3.json +2 -4
  101. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin30.json +2 -0
  102. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin31.json +2 -0
  103. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin32.json +2 -0
  104. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin33.json +2 -0
  105. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin34.json +2 -0
  106. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin35.json +2 -0
  107. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin36.json +1 -0
  108. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin4.json +2 -0
  109. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin40.json +1 -1
  110. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin41.json +1 -10
  111. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin5.json +2 -4
  112. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin6.json +2 -4
  113. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin7.json +2 -4
  114. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin8.json +2 -12
  115. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin9.json +2 -4
  116. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionSkip.json +12 -0
  117. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityJexlExpressionPlugin1.json +1 -1
  118. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin1.json +1 -1
  119. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin10.json +1 -1
  120. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin11.json +1 -1
  121. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin12.json +1 -1
  122. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin13.json +1 -1
  123. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin14.json +1 -1
  124. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin15.json +1 -1
  125. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin16.json +1 -1
  126. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin17.json +1 -1
  127. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin2.json +1 -1
  128. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin25.json +2 -6
  129. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin3.json +1 -1
  130. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin4.json +1 -1
  131. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin5.json +1 -1
  132. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin6.json +1 -1
  133. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin7.json +1 -1
  134. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin8.json +1 -1
  135. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin9.json +1 -1
  136. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +1 -1
  137. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +1 -1
  138. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin3.json +1 -1
  139. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin4.json +2 -0
  140. package/test/unit/ngsiv2/examples/contextRequests/updateContextProcessTimestamp.json +2 -0
  141. package/test/unit/ngsiv2/examples/contextRequests/updateContextStaticAttributes.json +2 -0
  142. package/test/unit/ngsiv2/examples/contextRequests/updateContextStaticAttributesMetadata.json +3 -1
  143. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestamp.json +3 -1
  144. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampFalse.json +12 -0
  145. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampFalseTimeInstant.json +12 -0
  146. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampOverride.json +2 -0
  147. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampOverrideWithoutMilis.json +2 -0
  148. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampTimezone.json +3 -1
  149. package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +144 -85
  150. package/test/unit/ngsiv2/general/contextBrokerOAuthSecurityAccess-test.js +20 -53
  151. package/test/unit/ngsiv2/general/https-support-test.js +2 -6
  152. package/test/unit/ngsiv2/lazyAndCommands/command-test.js +4 -10
  153. package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +8 -24
  154. package/test/unit/ngsiv2/ngsiService/active-devices-test.js +146 -65
  155. package/test/unit/ngsiv2/ngsiService/autocast-test.js +14 -21
  156. package/test/unit/ngsiv2/ngsiService/staticAttributes-test.js +3 -5
  157. package/test/unit/ngsiv2/ngsiService/subscriptions-test.js +11 -20
  158. package/test/unit/ngsiv2/plugins/alias-plugin_test.js +20 -30
  159. package/test/unit/ngsiv2/plugins/compress-timestamp-plugin_test.js +4 -6
  160. package/test/unit/ngsiv2/plugins/custom-plugin_test.js +1 -2
  161. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +3 -5
  162. package/test/unit/ngsiv2/plugins/timestamp-processing-plugin_test.js +2 -3
  163. package/test/unit/ngsiv2/provisioning/device-group-api-test.js +2 -3
  164. package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +13 -156
  165. package/test/unit/ngsiv2/provisioning/device-registration_test.js +9 -13
  166. package/test/unit/ngsiv2/provisioning/device-update-registration_test.js +4 -10
  167. package/test/unit/ngsiv2/provisioning/singleConfigurationMode-test.js +0 -11
  168. package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +0 -8
  169. package/test/unit/plugins/capture-provision-inPlugins_test.js +0 -6
  170. package/.nyc_output/33364de2-1199-4ec2-b33c-cae063ef8cc4.json +0 -1
  171. package/.nyc_output/processinfo/33364de2-1199-4ec2-b33c-cae063ef8cc4.json +0 -1
  172. package/.nyc_output/processinfo/index.json +0 -1
  173. package/doc/config-basic-example.js +0 -20
  174. package/doc/development.md +0 -285
  175. package/doc/howto.md +0 -645
  176. package/doc/installationguide.md +0 -370
  177. package/doc/operations.md +0 -127
  178. package/doc/usermanual.md +0 -900
  179. package/lib/plugins/bidirectionalData.js +0 -356
  180. package/test/unit/ngsi-ld/plugins/bidirectional-plugin_test.js +0 -697
  181. package/test/unit/ngsiv2/plugins/bidirectional-plugin_test.js +0 -599
  182. /package/doc/{NorthboundInteractions.postman_collection → devel/NorthboundInteractions.postman_collection} +0 -0
  183. /package/doc/{echo.js → devel/echo.js} +0 -0
  184. /package/doc/{finalResult.js → devel/finalResult.js} +0 -0
@@ -1,697 +0,0 @@
1
- /*
2
- * Copyright 2020 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: Jason Fox - FIWARE Foundation
24
- */
25
-
26
- /* eslint-disable no-unused-vars */
27
-
28
- const iotAgentLib = require('../../../../lib/fiware-iotagent-lib');
29
- const utils = require('../../../tools/utils');
30
- const request = utils.request;
31
- const should = require('should');
32
- const logger = require('logops');
33
- const nock = require('nock');
34
-
35
- let contextBrokerMock;
36
- const iotAgentConfig = {
37
- contextBroker: {
38
- host: '192.168.1.1',
39
- port: '1026',
40
- ngsiVersion: 'ld',
41
- jsonLdContext: 'http://context.json-ld'
42
- },
43
- server: {
44
- port: 4041,
45
- host: 'localhost'
46
- },
47
- types: {},
48
- service: 'smartgondor',
49
- subservice: 'gardens',
50
- providerUrl: 'http://smartgondor.com'
51
- };
52
-
53
- describe('NGSI-LD - Bidirectional data plugin', function () {
54
- const options = {
55
- url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices',
56
- method: 'POST',
57
- json: utils.readExampleFile(
58
- './test/unit/examples/deviceProvisioningRequests/provisionBidirectionalDevice.json'
59
- ),
60
- headers: {
61
- 'fiware-service': 'smartgondor',
62
- 'fiware-servicepath': '/gardens'
63
- }
64
- };
65
-
66
- beforeEach(function (done) {
67
- iotAgentLib.activate(iotAgentConfig, function () {
68
- iotAgentLib.clearAll(function () {
69
- iotAgentLib.addDeviceProvisionMiddleware(iotAgentLib.dataPlugins.bidirectionalData.deviceProvision);
70
- iotAgentLib.addConfigurationProvisionMiddleware(
71
- iotAgentLib.dataPlugins.bidirectionalData.groupProvision
72
- );
73
- iotAgentLib.addNotificationMiddleware(iotAgentLib.dataPlugins.bidirectionalData.notification);
74
- done();
75
- });
76
- });
77
- });
78
-
79
- afterEach(function (done) {
80
- iotAgentLib.clearAll(function () {
81
- iotAgentLib.deactivate(done);
82
- });
83
- });
84
-
85
- describe('When a new provisioning request arrives to the IoTA with bidirectionality', function () {
86
- beforeEach(function () {
87
- logger.setLevel('FATAL');
88
-
89
- contextBrokerMock = nock('http://192.168.1.1:1026')
90
- .matchHeader('fiware-service', 'smartgondor')
91
- .post(
92
- '/ngsi-ld/v1/subscriptions/',
93
- utils.readExampleFile(
94
- './test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json'
95
- )
96
- )
97
- .reply(201, null, { Location: '/ngsi-ld/v1/subscriptions/51c0ac9ed714fb3b37d7d5a8' });
98
-
99
- contextBrokerMock
100
- .matchHeader('fiware-service', 'smartgondor')
101
- .post(
102
- '/ngsi-ld/v1/entityOperations/upsert/',
103
- utils.readExampleFile('./test/unit/ngsi-ld/examples/contextRequests/createBidirectionalDevice.json')
104
- )
105
- .reply(204);
106
- });
107
-
108
- it('should subscribe to the modification of the combined attribute with all the variables', function (done) {
109
- request(options, function (error, response, body) {
110
- should.not.exist(error);
111
- contextBrokerMock.done();
112
- done();
113
- });
114
- });
115
- });
116
-
117
- describe('When a device with bidirectionality subscriptions is removed', function () {
118
- const deleteRequest = {
119
- url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices/Light1',
120
- method: 'DELETE',
121
- headers: {
122
- 'fiware-service': 'smartgondor',
123
- 'fiware-servicepath': '/gardens'
124
- }
125
- };
126
-
127
- beforeEach(function () {
128
- contextBrokerMock
129
- .matchHeader('fiware-service', 'smartgondor')
130
- .post(
131
- '/ngsi-ld/v1/subscriptions/',
132
- utils.readExampleFile(
133
- './test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json'
134
- )
135
- )
136
- .reply(201, null, { Location: '/ngsi-ld/v1/subscriptions/51c0ac9ed714fb3b37d7d5a8' });
137
-
138
- contextBrokerMock
139
- .matchHeader('fiware-service', 'smartgondor')
140
- .post(
141
- '/ngsi-ld/v1/entityOperations/upsert/',
142
- utils.readExampleFile('./test/unit/ngsi-ld/examples/contextRequests/createBidirectionalDevice.json')
143
- )
144
- .reply(204);
145
-
146
- contextBrokerMock
147
- .matchHeader('fiware-service', 'smartgondor')
148
- .delete('/ngsi-ld/v1/subscriptions/51c0ac9ed714fb3b37d7d5a8', '')
149
- .reply(204);
150
- });
151
-
152
- it('should remove its subscriptions from the Context Broker', function (done) {
153
- request(options, function (error, response, body) {
154
- request(deleteRequest, function (error, response, body) {
155
- should.not.exist(error);
156
- contextBrokerMock.done();
157
- done();
158
- });
159
- });
160
- });
161
- });
162
-
163
- describe('When a notification arrives for a bidirectional attribute', function () {
164
- const notificationOptions = {
165
- url: 'http://localhost:' + iotAgentConfig.server.port + '/notify',
166
- method: 'POST',
167
- json: utils.readExampleFile(
168
- './test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotification.json'
169
- ),
170
- headers: {
171
- 'fiware-service': 'smartgondor',
172
- 'fiware-servicepath': '/gardens'
173
- }
174
- };
175
- let executedHandler = false;
176
-
177
- beforeEach(function () {
178
- contextBrokerMock
179
- .matchHeader('fiware-service', 'smartgondor')
180
- .post(
181
- '/ngsi-ld/v1/subscriptions/',
182
- utils.readExampleFile(
183
- './test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json'
184
- )
185
- )
186
- .reply(201, null, { Location: '/ngsi-ld/v1/subscriptions/51c0ac9ed714fb3b37d7d5a8' });
187
-
188
- contextBrokerMock
189
- .matchHeader('fiware-service', 'smartgondor')
190
- .post(
191
- '/ngsi-ld/v1/entityOperations/upsert/',
192
- utils.readExampleFile('./test/unit/ngsi-ld/examples/contextRequests/createBidirectionalDevice.json')
193
- )
194
- .reply(204);
195
- });
196
-
197
- afterEach(function () {
198
- iotAgentLib.setNotificationHandler();
199
- });
200
-
201
- it('should execute the original handler', function (done) {
202
- function mockedHandler(device, notification, callback) {
203
- executedHandler = true;
204
- callback();
205
- }
206
-
207
- iotAgentLib.setNotificationHandler(mockedHandler);
208
-
209
- request(options, function (error, response, body) {
210
- request(notificationOptions, function (error, response, body) {
211
- executedHandler.should.equal(true);
212
- contextBrokerMock.done();
213
- done();
214
- });
215
- });
216
- });
217
-
218
- it('should return a 200 OK', function (done) {
219
- function mockedHandler(device, notification, callback) {
220
- executedHandler = true;
221
- callback();
222
- }
223
-
224
- iotAgentLib.setNotificationHandler(mockedHandler);
225
-
226
- request(options, function (error, response, body) {
227
- request(notificationOptions, function (error, response, body) {
228
- response.statusCode.should.equal(200);
229
- contextBrokerMock.done();
230
- done();
231
- });
232
- });
233
- });
234
-
235
- it('should return the transformed values', function (done) {
236
- let transformedHandler = false;
237
-
238
- function mockedHandler(device, values, callback) {
239
- let latitudeFound = false;
240
- let longitudeFound = false;
241
-
242
- for (let i = 0; i < values.length; i++) {
243
- if (values[i].name === 'latitude' && values[i].type === 'Number' && values[i].value === -9.6) {
244
- latitudeFound = true;
245
- }
246
-
247
- if (values[i].name === 'longitude' && values[i].type === 'Number' && values[i].value === 12.4) {
248
- longitudeFound = true;
249
- }
250
- }
251
-
252
- transformedHandler = values.length >= 2 && longitudeFound && latitudeFound;
253
- callback();
254
- }
255
-
256
- iotAgentLib.setNotificationHandler(mockedHandler);
257
-
258
- request(options, function (error, response, body) {
259
- request(notificationOptions, function (error, response, body) {
260
- contextBrokerMock.done();
261
- transformedHandler.should.equal(true);
262
- done();
263
- });
264
- });
265
- });
266
- });
267
-
268
- describe('When a notification with metadata arrives for a bidirectional attribute', function () {
269
- const notificationOptions = {
270
- url: 'http://localhost:' + iotAgentConfig.server.port + '/notify',
271
- method: 'POST',
272
- json: utils.readExampleFile(
273
- './test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotificationWithMetadata.json'
274
- ),
275
- headers: {
276
- 'fiware-service': 'smartgondor',
277
- 'fiware-servicepath': '/gardens'
278
- }
279
- };
280
- let executedHandler = false;
281
-
282
- beforeEach(function () {
283
- contextBrokerMock
284
- .matchHeader('fiware-service', 'smartgondor')
285
- .post(
286
- '/ngsi-ld/v1/subscriptions/',
287
- utils.readExampleFile(
288
- './test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json'
289
- )
290
- )
291
- .reply(201, null, { Location: '/ngsi-ld/v1/subscriptions/51c0ac9ed714fb3b37d7d5a8' });
292
-
293
- contextBrokerMock
294
- .matchHeader('fiware-service', 'smartgondor')
295
- .post(
296
- '/ngsi-ld/v1/entityOperations/upsert/',
297
- utils.readExampleFile('./test/unit/ngsi-ld/examples/contextRequests/createBidirectionalDevice.json')
298
- )
299
- .reply(204);
300
- });
301
-
302
- afterEach(function () {
303
- iotAgentLib.setNotificationHandler();
304
- });
305
-
306
- it('should execute the original handler', function (done) {
307
- function mockedHandler(device, notification, callback) {
308
- notification[0].name.should.equal('location');
309
- notification[0].value.should.equal('12.4, -9.6');
310
- notification[0].metadata.qos.value.should.equal(1);
311
- executedHandler = true;
312
- callback();
313
- }
314
-
315
- iotAgentLib.setNotificationHandler(mockedHandler);
316
-
317
- request(options, function (error, response, body) {
318
- request(notificationOptions, function (error, response, body) {
319
- executedHandler.should.equal(true);
320
- contextBrokerMock.done();
321
- done();
322
- });
323
- });
324
- });
325
-
326
- it('should return a 200 OK', function (done) {
327
- function mockedHandler(device, notification, callback) {
328
- executedHandler = true;
329
- callback();
330
- }
331
-
332
- iotAgentLib.setNotificationHandler(mockedHandler);
333
-
334
- request(options, function (error, response, body) {
335
- request(notificationOptions, function (error, response, body) {
336
- response.statusCode.should.equal(200);
337
- contextBrokerMock.done();
338
- done();
339
- });
340
- });
341
- });
342
-
343
- it('should return the transformed values', function (done) {
344
- let transformedHandler = false;
345
-
346
- function mockedHandler(device, values, callback) {
347
- let latitudeFound = false;
348
- let longitudeFound = false;
349
-
350
- for (let i = 0; i < values.length; i++) {
351
- if (values[i].name === 'latitude' && values[i].type === 'Number' && values[i].value === -9.6) {
352
- latitudeFound = true;
353
- }
354
-
355
- if (values[i].name === 'longitude' && values[i].type === 'Number' && values[i].value === 12.4) {
356
- longitudeFound = true;
357
- }
358
- }
359
-
360
- transformedHandler = values.length >= 2 && longitudeFound && latitudeFound;
361
- callback();
362
- }
363
-
364
- iotAgentLib.setNotificationHandler(mockedHandler);
365
-
366
- request(options, function (error, response, body) {
367
- request(notificationOptions, function (error, response, body) {
368
- contextBrokerMock.done();
369
- transformedHandler.should.equal(true);
370
- done();
371
- });
372
- });
373
- });
374
- });
375
-
376
- describe('When a sequential notification with datasetId arrives for a bidirectional attribute', function () {
377
- const notificationOptions = {
378
- url: 'http://localhost:' + iotAgentConfig.server.port + '/notify',
379
- method: 'POST',
380
- json: utils.readExampleFile(
381
- './test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotificationWithDatasetId.json'
382
- ),
383
- headers: {
384
- 'fiware-service': 'smartgondor',
385
- 'fiware-servicepath': '/gardens'
386
- }
387
- };
388
- let executedHandler = false;
389
-
390
- beforeEach(function () {
391
- contextBrokerMock
392
- .matchHeader('fiware-service', 'smartgondor')
393
- .post(
394
- '/ngsi-ld/v1/subscriptions/',
395
- utils.readExampleFile(
396
- './test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json'
397
- )
398
- )
399
- .reply(201, null, { Location: '/ngsi-ld/v1/subscriptions/51c0ac9ed714fb3b37d7d5a8' });
400
-
401
- contextBrokerMock
402
- .matchHeader('fiware-service', 'smartgondor')
403
- .post(
404
- '/ngsi-ld/v1/entityOperations/upsert/',
405
- utils.readExampleFile('./test/unit/ngsi-ld/examples/contextRequests/createBidirectionalDevice.json')
406
- )
407
- .reply(204);
408
- });
409
-
410
- afterEach(function () {
411
- iotAgentLib.setNotificationHandler();
412
- });
413
-
414
- it('should execute the original handler', function (done) {
415
- function mockedHandler(device, notification, callback) {
416
- notification[0].name.should.equal('location');
417
- notification[0].value.should.equal('12.4, -9.6');
418
- notification[0].datasetId.should.equal('urn:ngsi-ld:Property:do-this');
419
-
420
- notification[1].name.should.equal('location');
421
- notification[1].value.should.equal('6, 10');
422
- notification[1].datasetId.should.equal('urn:ngsi-ld:Property:then-do-this');
423
-
424
- executedHandler = true;
425
- callback();
426
- }
427
-
428
- iotAgentLib.setNotificationHandler(mockedHandler);
429
-
430
- request(options, function (error, response, body) {
431
- request(notificationOptions, function (error, response, body) {
432
- executedHandler.should.equal(true);
433
- contextBrokerMock.done();
434
- done();
435
- });
436
- });
437
- });
438
-
439
- it('should return a 200 OK', function (done) {
440
- function mockedHandler(device, notification, callback) {
441
- executedHandler = true;
442
- callback();
443
- }
444
-
445
- iotAgentLib.setNotificationHandler(mockedHandler);
446
-
447
- request(options, function (error, response, body) {
448
- request(notificationOptions, function (error, response, body) {
449
- response.statusCode.should.equal(200);
450
- contextBrokerMock.done();
451
- done();
452
- });
453
- });
454
- });
455
-
456
- it('should return the transformed values', function (done) {
457
- let transformedHandler = false;
458
-
459
- function mockedHandler(device, values, callback) {
460
- let latitudeFound = false;
461
- let longitudeFound = false;
462
-
463
- for (let i = 0; i < values.length; i++) {
464
- if (values[i].name === 'latitude' && values[i].type === 'Number' && values[i].value === -9.6) {
465
- latitudeFound = true;
466
- }
467
-
468
- if (values[i].name === 'longitude' && values[i].type === 'Number' && values[i].value === 12.4) {
469
- longitudeFound = true;
470
- }
471
- }
472
-
473
- transformedHandler = values.length >= 2 && longitudeFound && latitudeFound;
474
- callback();
475
- }
476
-
477
- iotAgentLib.setNotificationHandler(mockedHandler);
478
-
479
- request(options, function (error, response, body) {
480
- request(notificationOptions, function (error, response, body) {
481
- contextBrokerMock.done();
482
- transformedHandler.should.equal(true);
483
- done();
484
- });
485
- });
486
- });
487
- });
488
-
489
- describe('When a new Group provisioning request arrives with bidirectional attributes', function () {
490
- const provisionGroup = {
491
- url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/services',
492
- method: 'POST',
493
- json: utils.readExampleFile('./test/unit/examples/groupProvisioningRequests/bidirectionalGroup.json'),
494
- headers: {
495
- 'fiware-service': 'smartgondor',
496
- 'fiware-servicepath': '/gardens'
497
- }
498
- };
499
- const provisionDevice = {
500
- url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices',
501
- method: 'POST',
502
- json: utils.readExampleFile(
503
- './test/unit/examples/deviceProvisioningRequests/provisionDeviceBidirectionalGroup.json'
504
- ),
505
- headers: {
506
- 'fiware-service': 'smartgondor',
507
- 'fiware-servicepath': '/gardens'
508
- }
509
- };
510
-
511
- beforeEach(function () {
512
- contextBrokerMock
513
- .matchHeader('fiware-service', 'smartgondor')
514
- .post(
515
- '/ngsi-ld/v1/subscriptions/',
516
- utils.readExampleFile(
517
- './test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json'
518
- )
519
- )
520
- .reply(201, null, { Location: '/ngsi-ld/v1/subscriptions/51c0ac9ed714fb3b37d7d5a8' });
521
-
522
- contextBrokerMock
523
- .matchHeader('fiware-service', 'smartgondor')
524
- .post(
525
- '/ngsi-ld/v1/entityOperations/upsert/',
526
- utils.readExampleFile('./test/unit/ngsi-ld/examples/contextRequests/createBidirectionalDevice.json')
527
- )
528
- .reply(204);
529
- });
530
- it('should subscribe to the modification of the combined attribute with all the variables', function (done) {
531
- request(provisionGroup, function (error, response, body) {
532
- request(provisionDevice, function (error, response, body) {
533
- should.not.exist(error);
534
- contextBrokerMock.done();
535
- done();
536
- });
537
- });
538
- });
539
- });
540
-
541
- describe('When a notification arrives for a bidirectional attribute in a Configuration Group', function () {
542
- const provisionGroup = {
543
- url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/services',
544
- method: 'POST',
545
- json: utils.readExampleFile('./test/unit/examples/groupProvisioningRequests/bidirectionalGroup.json'),
546
- headers: {
547
- 'fiware-service': 'smartgondor',
548
- 'fiware-servicepath': '/gardens'
549
- }
550
- };
551
- const notificationOptions = {
552
- url: 'http://localhost:' + iotAgentConfig.server.port + '/notify',
553
- method: 'POST',
554
- json: utils.readExampleFile(
555
- './test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotification.json'
556
- ),
557
- headers: {
558
- 'fiware-service': 'smartgondor',
559
- 'fiware-servicepath': '/gardens'
560
- }
561
- };
562
- const provisionDevice = {
563
- url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices',
564
- method: 'POST',
565
- json: utils.readExampleFile(
566
- './test/unit/examples/deviceProvisioningRequests/provisionDeviceBidirectionalGroup.json'
567
- ),
568
- headers: {
569
- 'fiware-service': 'smartgondor',
570
- 'fiware-servicepath': '/gardens'
571
- }
572
- };
573
-
574
- beforeEach(function () {
575
- contextBrokerMock
576
- .matchHeader('fiware-service', 'smartgondor')
577
- .post(
578
- '/ngsi-ld/v1/subscriptions/',
579
- utils.readExampleFile(
580
- './test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json'
581
- )
582
- )
583
- .reply(201, null, { Location: '/ngsi-ld/v1/subscriptions/51c0ac9ed714fb3b37d7d5a8' });
584
-
585
- contextBrokerMock
586
- .matchHeader('fiware-service', 'smartgondor')
587
- .post(
588
- '/ngsi-ld/v1/entityOperations/upsert/',
589
- utils.readExampleFile('./test/unit/ngsi-ld/examples/contextRequests/createBidirectionalDevice.json')
590
- )
591
- .reply(204);
592
- });
593
-
594
- afterEach(function () {
595
- iotAgentLib.setNotificationHandler();
596
- });
597
-
598
- it('should return the transformed values', function (done) {
599
- let transformedHandler = false;
600
-
601
- function mockedHandler(device, values, callback) {
602
- let latitudeFound = false;
603
- let longitudeFound = false;
604
-
605
- for (let i = 0; i < values.length; i++) {
606
- if (values[i].name === 'latitude' && values[i].type === 'Number' && values[i].value === -9.6) {
607
- latitudeFound = true;
608
- }
609
-
610
- if (values[i].name === 'longitude' && values[i].type === 'Number' && values[i].value === 12.4) {
611
- longitudeFound = true;
612
- }
613
- }
614
-
615
- transformedHandler = values.length >= 2 && longitudeFound && latitudeFound;
616
- callback();
617
- }
618
-
619
- iotAgentLib.setNotificationHandler(mockedHandler);
620
-
621
- request(provisionGroup, function (error, response, body) {
622
- request(provisionDevice, function (error, response, body) {
623
- request(notificationOptions, function (error, response, body) {
624
- transformedHandler.should.equal(true);
625
- done();
626
- });
627
- });
628
- });
629
- });
630
- });
631
- });
632
-
633
- describe('NGSI-LD - Bidirectional data plugin and CB is defined using environment variables', function () {
634
- const options = {
635
- url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices',
636
- method: 'POST',
637
- json: utils.readExampleFile(
638
- './test/unit/examples/deviceProvisioningRequests/provisionBidirectionalDevice.json'
639
- ),
640
- headers: {
641
- 'fiware-service': 'smartgondor',
642
- 'fiware-servicepath': '/gardens'
643
- }
644
- };
645
-
646
- beforeEach(function (done) {
647
- logger.setLevel('FATAL');
648
- process.env.IOTA_CB_HOST = 'cbhost';
649
- iotAgentLib.activate(iotAgentConfig, function () {
650
- iotAgentLib.clearAll(function () {
651
- iotAgentLib.addDeviceProvisionMiddleware(iotAgentLib.dataPlugins.bidirectionalData.deviceProvision);
652
- iotAgentLib.addConfigurationProvisionMiddleware(
653
- iotAgentLib.dataPlugins.bidirectionalData.groupProvision
654
- );
655
- iotAgentLib.addNotificationMiddleware(iotAgentLib.dataPlugins.bidirectionalData.notification);
656
- done();
657
- });
658
- });
659
- });
660
-
661
- afterEach(function (done) {
662
- process.env.IOTA_CB_HOST = '';
663
- iotAgentLib.clearAll(function () {
664
- iotAgentLib.deactivate(done);
665
- });
666
- });
667
-
668
- describe('When a new provisioning request arrives to the IoTA with bidirectionality', function () {
669
- beforeEach(function () {
670
- contextBrokerMock = nock('http://cbhost:1026')
671
- .matchHeader('fiware-service', 'smartgondor')
672
- .post(
673
- '/ngsi-ld/v1/subscriptions/',
674
- utils.readExampleFile(
675
- './test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json'
676
- )
677
- )
678
- .reply(201, null, { Location: '/ngsi-ld/v1/subscriptions/51c0ac9ed714fb3b37d7d5a8' });
679
-
680
- contextBrokerMock
681
- .matchHeader('fiware-service', 'smartgondor')
682
- .post(
683
- '/ngsi-ld/v1/entityOperations/upsert/',
684
- utils.readExampleFile('./test/unit/ngsi-ld/examples/contextRequests/createBidirectionalDevice.json')
685
- )
686
- .reply(204);
687
- });
688
-
689
- it('should subscribe to the modification of the combined attribute with all the variables', function (done) {
690
- request(options, function (error, response, body) {
691
- should.not.exist(error);
692
- contextBrokerMock.done();
693
- done();
694
- });
695
- });
696
- });
697
- });