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,599 +0,0 @@
1
- /*
2
- * Copyright 2016 Telefonica Investigación y Desarrollo, S.A.U
3
- *
4
- * This file is part of fiware-iotagent-lib
5
- *
6
- * fiware-iotagent-lib is free software: you can redistribute it and/or
7
- * modify it under the terms of the GNU Affero General Public License as
8
- * published by the Free Software Foundation, either version 3 of the License,
9
- * or (at your option) any later version.
10
- *
11
- * fiware-iotagent-lib is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
- * See the GNU Affero General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Affero General Public
17
- * License along with fiware-iotagent-lib.
18
- * If not, see http://www.gnu.org/licenses/.
19
- *
20
- * For those usages not covered by the GNU Affero General Public License
21
- * please contact with::daniel.moranjimenez@telefonica.com
22
- *
23
- * Modified by: Daniel Calvo - ATOS Research & Innovation
24
- */
25
-
26
- /* 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: 'v2'
41
- },
42
- server: {
43
- port: 4041,
44
- host: 'localhost'
45
- },
46
- types: {},
47
- service: 'smartgondor',
48
- subservice: 'gardens',
49
- providerUrl: 'http://smartgondor.com'
50
- };
51
-
52
- describe('NGSI-v2 - Bidirectional data plugin', function () {
53
- const options = {
54
- url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices',
55
- method: 'POST',
56
- json: utils.readExampleFile(
57
- './test/unit/examples/deviceProvisioningRequests/provisionBidirectionalDevice.json'
58
- ),
59
- headers: {
60
- 'fiware-service': 'smartgondor',
61
- 'fiware-servicepath': '/gardens'
62
- }
63
- };
64
-
65
- beforeEach(function (done) {
66
- logger.setLevel('FATAL');
67
-
68
- iotAgentLib.activate(iotAgentConfig, function () {
69
- iotAgentLib.clearAll(function () {
70
- iotAgentLib.addDeviceProvisionMiddleware(iotAgentLib.dataPlugins.bidirectionalData.deviceProvision);
71
- iotAgentLib.addConfigurationProvisionMiddleware(
72
- iotAgentLib.dataPlugins.bidirectionalData.groupProvision
73
- );
74
- iotAgentLib.addNotificationMiddleware(iotAgentLib.dataPlugins.bidirectionalData.notification);
75
- done();
76
- });
77
- });
78
- });
79
-
80
- afterEach(function (done) {
81
- iotAgentLib.clearAll(function () {
82
- iotAgentLib.deactivate(done);
83
- });
84
- });
85
-
86
- describe('When a new provisioning request arrives to the IoTA with bidirectionality', function () {
87
- beforeEach(function () {
88
- contextBrokerMock = nock('http://192.168.1.1:1026')
89
- .matchHeader('fiware-service', 'smartgondor')
90
- .matchHeader('fiware-servicepath', '/gardens')
91
- .post(
92
- '/v2/subscriptions',
93
- utils.readExampleFile(
94
- './test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json'
95
- )
96
- )
97
- .reply(201, null, { Location: '/v2/subscriptions/51c0ac9ed714fb3b37d7d5a8' });
98
-
99
- contextBrokerMock
100
- .matchHeader('fiware-service', 'smartgondor')
101
- .matchHeader('fiware-servicepath', '/gardens')
102
- .post(
103
- '/v2/entities?options=upsert',
104
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/createBidirectionalDevice.json')
105
- )
106
- .reply(204);
107
- });
108
-
109
- it('should subscribe to the modification of the combined attribute with all the variables', function (done) {
110
- request(options, function (error, response, body) {
111
- should.not.exist(error);
112
- contextBrokerMock.done();
113
- done();
114
- });
115
- });
116
- });
117
-
118
- describe('When a device with bidirectionality subscriptions is removed', function () {
119
- const deleteRequest = {
120
- url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices/Light1',
121
- method: 'DELETE',
122
- headers: {
123
- 'fiware-service': 'smartgondor',
124
- 'fiware-servicepath': '/gardens'
125
- }
126
- };
127
-
128
- beforeEach(function () {
129
- contextBrokerMock
130
- .matchHeader('fiware-service', 'smartgondor')
131
- .matchHeader('fiware-servicepath', '/gardens')
132
- .post(
133
- '/v2/subscriptions',
134
- utils.readExampleFile(
135
- './test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json'
136
- )
137
- )
138
- .reply(201, null, { Location: '/v2/subscriptions/51c0ac9ed714fb3b37d7d5a8' });
139
-
140
- contextBrokerMock
141
- .matchHeader('fiware-service', 'smartgondor')
142
- .matchHeader('fiware-servicepath', '/gardens')
143
- .post(
144
- '/v2/entities?options=upsert',
145
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/createBidirectionalDevice.json')
146
- )
147
- .reply(204);
148
-
149
- contextBrokerMock
150
- .matchHeader('fiware-service', 'smartgondor')
151
- .matchHeader('fiware-servicepath', '/gardens')
152
- .delete('/v2/subscriptions/51c0ac9ed714fb3b37d7d5a8', '')
153
- .reply(204);
154
- });
155
-
156
- it('should remove its subscriptions from the Context Broker', function (done) {
157
- request(options, function (error, response, body) {
158
- request(deleteRequest, function (error, response, body) {
159
- should.not.exist(error);
160
- contextBrokerMock.done();
161
- done();
162
- });
163
- });
164
- });
165
- });
166
-
167
- describe('When a notification arrives for a bidirectional attribute', function () {
168
- const notificationOptions = {
169
- url: 'http://localhost:' + iotAgentConfig.server.port + '/notify',
170
- method: 'POST',
171
- json: utils.readExampleFile(
172
- './test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalNotification.json'
173
- ),
174
- headers: {
175
- 'fiware-service': 'smartgondor',
176
- 'fiware-servicepath': '/gardens'
177
- }
178
- };
179
- let executedHandler = false;
180
-
181
- beforeEach(function () {
182
- contextBrokerMock
183
- .matchHeader('fiware-service', 'smartgondor')
184
- .matchHeader('fiware-servicepath', '/gardens')
185
- .post(
186
- '/v2/subscriptions',
187
- utils.readExampleFile(
188
- './test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json'
189
- )
190
- )
191
- .reply(201, null, { Location: '/v2/subscriptions/51c0ac9ed714fb3b37d7d5a8' });
192
-
193
- contextBrokerMock
194
- .matchHeader('fiware-service', 'smartgondor')
195
- .matchHeader('fiware-servicepath', '/gardens')
196
- .post(
197
- '/v2/entities?options=upsert',
198
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/createBidirectionalDevice.json')
199
- )
200
- .reply(204);
201
- });
202
-
203
- afterEach(function () {
204
- iotAgentLib.setNotificationHandler();
205
- });
206
-
207
- it('should execute the original handler', function (done) {
208
- function mockedHandler(device, notification, callback) {
209
- executedHandler = true;
210
- callback();
211
- }
212
-
213
- iotAgentLib.setNotificationHandler(mockedHandler);
214
-
215
- request(options, function (error, response, body) {
216
- request(notificationOptions, function (error, response, body) {
217
- executedHandler.should.equal(true);
218
- contextBrokerMock.done();
219
- done();
220
- });
221
- });
222
- });
223
-
224
- it('should return a 200 OK', function (done) {
225
- function mockedHandler(device, notification, callback) {
226
- executedHandler = true;
227
- callback();
228
- }
229
-
230
- iotAgentLib.setNotificationHandler(mockedHandler);
231
-
232
- request(options, function (error, response, body) {
233
- request(notificationOptions, function (error, response, body) {
234
- response.statusCode.should.equal(200);
235
- contextBrokerMock.done();
236
- done();
237
- });
238
- });
239
- });
240
-
241
- it('should return the transformed values', function (done) {
242
- let transformedHandler = false;
243
-
244
- function mockedHandler(device, values, callback) {
245
- let latitudeFound = false;
246
- let longitudeFound = false;
247
-
248
- for (let i = 0; i < values.length; i++) {
249
- if (values[i].name === 'latitude' && values[i].type === 'Number' && values[i].value === -9.6) {
250
- latitudeFound = true;
251
- }
252
-
253
- if (values[i].name === 'longitude' && values[i].type === 'Number' && values[i].value === 12.4) {
254
- longitudeFound = true;
255
- }
256
- }
257
-
258
- transformedHandler = values.length >= 2 && longitudeFound && latitudeFound;
259
- callback();
260
- }
261
-
262
- iotAgentLib.setNotificationHandler(mockedHandler);
263
-
264
- request(options, function (error, response, body) {
265
- request(notificationOptions, function (error, response, body) {
266
- contextBrokerMock.done();
267
- transformedHandler.should.equal(true);
268
- done();
269
- });
270
- });
271
- });
272
- });
273
-
274
- describe('When a notification with metadata arrives for a bidirectional attribute', function () {
275
- const notificationOptions = {
276
- url: 'http://localhost:' + iotAgentConfig.server.port + '/notify',
277
- method: 'POST',
278
- json: utils.readExampleFile(
279
- './test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalNotificationWithMetadata.json'
280
- ),
281
- headers: {
282
- 'fiware-service': 'smartgondor',
283
- 'fiware-servicepath': '/gardens'
284
- }
285
- };
286
- let executedHandler = false;
287
-
288
- beforeEach(function () {
289
- contextBrokerMock
290
- .matchHeader('fiware-service', 'smartgondor')
291
- .matchHeader('fiware-servicepath', '/gardens')
292
- .post(
293
- '/v2/subscriptions',
294
- utils.readExampleFile(
295
- './test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json'
296
- )
297
- )
298
- .reply(201, null, { Location: '/v2/subscriptions/51c0ac9ed714fb3b37d7d5a8' });
299
-
300
- contextBrokerMock
301
- .matchHeader('fiware-service', 'smartgondor')
302
- .matchHeader('fiware-servicepath', '/gardens')
303
- .post(
304
- '/v2/entities?options=upsert',
305
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/createBidirectionalDevice.json')
306
- )
307
- .reply(204);
308
- });
309
-
310
- afterEach(function () {
311
- iotAgentLib.setNotificationHandler();
312
- });
313
-
314
- it('should execute the original handler', function (done) {
315
- function mockedHandler(device, notification, callback) {
316
- notification[0].name.should.equal('location');
317
- notification[0].value.should.equal('12.4, -9.6');
318
- notification[0].metadata.qos.value.should.equal(1);
319
-
320
- executedHandler = true;
321
- callback();
322
- }
323
-
324
- iotAgentLib.setNotificationHandler(mockedHandler);
325
-
326
- request(options, function (error, response, body) {
327
- request(notificationOptions, function (error, response, body) {
328
- executedHandler.should.equal(true);
329
- contextBrokerMock.done();
330
- done();
331
- });
332
- });
333
- });
334
-
335
- it('should return a 200 OK', function (done) {
336
- function mockedHandler(device, notification, callback) {
337
- executedHandler = true;
338
- callback();
339
- }
340
-
341
- iotAgentLib.setNotificationHandler(mockedHandler);
342
-
343
- request(options, function (error, response, body) {
344
- request(notificationOptions, function (error, response, body) {
345
- response.statusCode.should.equal(200);
346
- contextBrokerMock.done();
347
- done();
348
- });
349
- });
350
- });
351
-
352
- it('should return the transformed values', function (done) {
353
- let transformedHandler = false;
354
-
355
- function mockedHandler(device, values, callback) {
356
- let latitudeFound = false;
357
- let longitudeFound = false;
358
-
359
- for (let i = 0; i < values.length; i++) {
360
- if (values[i].name === 'latitude' && values[i].type === 'Number' && values[i].value === -9.6) {
361
- latitudeFound = true;
362
- }
363
-
364
- if (values[i].name === 'longitude' && values[i].type === 'Number' && values[i].value === 12.4) {
365
- longitudeFound = true;
366
- }
367
- }
368
-
369
- transformedHandler = values.length >= 2 && longitudeFound && latitudeFound;
370
- callback();
371
- }
372
-
373
- iotAgentLib.setNotificationHandler(mockedHandler);
374
-
375
- request(options, function (error, response, body) {
376
- request(notificationOptions, function (error, response, body) {
377
- contextBrokerMock.done();
378
- transformedHandler.should.equal(true);
379
- done();
380
- });
381
- });
382
- });
383
- });
384
-
385
- describe('When a new Group provisioning request arrives with bidirectional attributes', function () {
386
- const provisionGroup = {
387
- url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/services',
388
- method: 'POST',
389
- json: utils.readExampleFile('./test/unit/examples/groupProvisioningRequests/bidirectionalGroup.json'),
390
- headers: {
391
- 'fiware-service': 'smartgondor',
392
- 'fiware-servicepath': '/gardens'
393
- }
394
- };
395
- const provisionDevice = {
396
- url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices',
397
- method: 'POST',
398
- json: utils.readExampleFile(
399
- './test/unit/examples/deviceProvisioningRequests/provisionDeviceBidirectionalGroup.json'
400
- ),
401
- headers: {
402
- 'fiware-service': 'smartgondor',
403
- 'fiware-servicepath': '/gardens'
404
- }
405
- };
406
-
407
- beforeEach(function () {
408
- contextBrokerMock
409
- .matchHeader('fiware-service', 'smartgondor')
410
- .matchHeader('fiware-servicepath', '/gardens')
411
- .post(
412
- '/v2/subscriptions',
413
- utils.readExampleFile(
414
- './test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json'
415
- )
416
- )
417
- .reply(201, null, { Location: '/v2/subscriptions/51c0ac9ed714fb3b37d7d5a8' });
418
-
419
- contextBrokerMock
420
- .matchHeader('fiware-service', 'smartgondor')
421
- .matchHeader('fiware-servicepath', '/gardens')
422
- .post(
423
- '/v2/entities?options=upsert',
424
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/createBidirectionalDevice.json')
425
- )
426
- .reply(204);
427
- });
428
- it('should subscribe to the modification of the combined attribute with all the variables', function (done) {
429
- request(provisionGroup, function (error, response, body) {
430
- request(provisionDevice, function (error, response, body) {
431
- should.not.exist(error);
432
- contextBrokerMock.done();
433
- done();
434
- });
435
- });
436
- });
437
- });
438
-
439
- describe('When a notification arrives for a bidirectional attribute in a Configuration Group', function () {
440
- const provisionGroup = {
441
- url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/services',
442
- method: 'POST',
443
- json: utils.readExampleFile('./test/unit/examples/groupProvisioningRequests/bidirectionalGroup.json'),
444
- headers: {
445
- 'fiware-service': 'smartgondor',
446
- 'fiware-servicepath': '/gardens'
447
- }
448
- };
449
- const notificationOptions = {
450
- url: 'http://localhost:' + iotAgentConfig.server.port + '/notify',
451
- method: 'POST',
452
- json: utils.readExampleFile(
453
- './test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalNotification.json'
454
- ),
455
- headers: {
456
- 'fiware-service': 'smartgondor',
457
- 'fiware-servicepath': '/gardens'
458
- }
459
- };
460
- const provisionDevice = {
461
- url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices',
462
- method: 'POST',
463
- json: utils.readExampleFile(
464
- './test/unit/examples/deviceProvisioningRequests/provisionDeviceBidirectionalGroup.json'
465
- ),
466
- headers: {
467
- 'fiware-service': 'smartgondor',
468
- 'fiware-servicepath': '/gardens'
469
- }
470
- };
471
-
472
- beforeEach(function () {
473
- contextBrokerMock
474
- .matchHeader('fiware-service', 'smartgondor')
475
- .matchHeader('fiware-servicepath', '/gardens')
476
- .post(
477
- '/v2/subscriptions',
478
- utils.readExampleFile(
479
- './test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json'
480
- )
481
- )
482
- .reply(201, null, { Location: '/v2/subscriptions/51c0ac9ed714fb3b37d7d5a8' });
483
-
484
- contextBrokerMock
485
- .matchHeader('fiware-service', 'smartgondor')
486
- .matchHeader('fiware-servicepath', '/gardens')
487
- .post(
488
- '/v2/entities?options=upsert',
489
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/createBidirectionalDevice.json')
490
- )
491
- .reply(204);
492
- });
493
-
494
- afterEach(function () {
495
- iotAgentLib.setNotificationHandler();
496
- });
497
-
498
- it('should return the transformed values', function (done) {
499
- let transformedHandler = false;
500
-
501
- function mockedHandler(device, values, callback) {
502
- let latitudeFound = false;
503
- let longitudeFound = false;
504
-
505
- for (let i = 0; i < values.length; i++) {
506
- if (values[i].name === 'latitude' && values[i].type === 'Number' && values[i].value === -9.6) {
507
- latitudeFound = true;
508
- }
509
-
510
- if (values[i].name === 'longitude' && values[i].type === 'Number' && values[i].value === 12.4) {
511
- longitudeFound = true;
512
- }
513
- }
514
-
515
- transformedHandler = values.length >= 2 && longitudeFound && latitudeFound;
516
- callback();
517
- }
518
-
519
- iotAgentLib.setNotificationHandler(mockedHandler);
520
-
521
- request(provisionGroup, function (error, response, body) {
522
- request(provisionDevice, function (error, response, body) {
523
- request(notificationOptions, function (error, response, body) {
524
- transformedHandler.should.equal(true);
525
- done();
526
- });
527
- });
528
- });
529
- });
530
- });
531
- });
532
-
533
- describe('NGSI-v2 - Bidirectional data plugin and CB is defined using environment variables', function () {
534
- const options = {
535
- url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices',
536
- method: 'POST',
537
- json: utils.readExampleFile(
538
- './test/unit/examples/deviceProvisioningRequests/provisionBidirectionalDevice.json'
539
- ),
540
- headers: {
541
- 'fiware-service': 'smartgondor',
542
- 'fiware-servicepath': '/gardens'
543
- }
544
- };
545
-
546
- beforeEach(function (done) {
547
- logger.setLevel('FATAL');
548
- process.env.IOTA_CB_HOST = 'cbhost';
549
- iotAgentLib.activate(iotAgentConfig, function () {
550
- iotAgentLib.clearAll(function () {
551
- iotAgentLib.addDeviceProvisionMiddleware(iotAgentLib.dataPlugins.bidirectionalData.deviceProvision);
552
- iotAgentLib.addConfigurationProvisionMiddleware(
553
- iotAgentLib.dataPlugins.bidirectionalData.groupProvision
554
- );
555
- iotAgentLib.addNotificationMiddleware(iotAgentLib.dataPlugins.bidirectionalData.notification);
556
- done();
557
- });
558
- });
559
- });
560
-
561
- afterEach(function (done) {
562
- process.env.IOTA_CB_HOST = '';
563
- iotAgentLib.clearAll(function () {
564
- iotAgentLib.deactivate(done);
565
- });
566
- });
567
-
568
- describe('When a new provisioning request arrives to the IoTA with bidirectionality', function () {
569
- beforeEach(function () {
570
- contextBrokerMock = nock('http://cbhost:1026')
571
- .matchHeader('fiware-service', 'smartgondor')
572
- .matchHeader('fiware-servicepath', '/gardens')
573
- .post(
574
- '/v2/subscriptions',
575
- utils.readExampleFile(
576
- './test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json'
577
- )
578
- )
579
- .reply(201, null, { Location: '/v2/subscriptions/51c0ac9ed714fb3b37d7d5a8' });
580
-
581
- contextBrokerMock
582
- .matchHeader('fiware-service', 'smartgondor')
583
- .matchHeader('fiware-servicepath', '/gardens')
584
- .post(
585
- '/v2/entities?options=upsert',
586
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/createBidirectionalDevice.json')
587
- )
588
- .reply(204);
589
- });
590
-
591
- it('should subscribe to the modification of the combined attribute with all the variables', function (done) {
592
- request(options, function (error, response, body) {
593
- should.not.exist(error);
594
- contextBrokerMock.done();
595
- done();
596
- });
597
- });
598
- });
599
- });
File without changes
File without changes