iotagent-node-lib 3.1.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.yml +134 -0
  2. package/.github/ISSUE_TEMPLATE/config.yml +16 -0
  3. package/.github/ISSUE_TEMPLATE/feature_request.yml +55 -0
  4. package/.github/advanced-issue-labeler.yml +30 -0
  5. package/.github/workflows/issue-labeler.yml +43 -0
  6. package/CHANGES_NEXT_RELEASE +0 -2
  7. package/config.js +5 -5
  8. package/doc/api.md +1483 -298
  9. package/doc/deprecated.md +7 -1
  10. package/doc/development.md +120 -0
  11. package/doc/howto.md +58 -62
  12. package/doc/installationguide.md +3 -11
  13. package/doc/requirements.txt +1 -1
  14. package/docker/Mosquitto/Dockerfile +1 -1
  15. package/lib/commonConfig.js +7 -10
  16. package/lib/fiware-iotagent-lib.js +0 -10
  17. package/lib/jexlTranformsMap.js +2 -1
  18. package/lib/model/Device.js +0 -1
  19. package/lib/model/Group.js +0 -1
  20. package/lib/model/dbConn.js +1 -7
  21. package/lib/plugins/bidirectionalData.js +8 -26
  22. package/lib/plugins/expressionPlugin.js +8 -40
  23. package/lib/plugins/jexlParser.js +28 -0
  24. package/lib/services/commands/commandService.js +1 -1
  25. package/lib/services/common/iotManagerService.js +0 -1
  26. package/lib/services/devices/deviceRegistryMongoDB.js +10 -10
  27. package/lib/services/devices/deviceService.js +16 -20
  28. package/lib/services/devices/devices-NGSI-v2.js +2 -5
  29. package/lib/services/ngsi/entities-NGSI-LD.js +16 -60
  30. package/lib/services/ngsi/entities-NGSI-v2.js +179 -119
  31. package/lib/services/northBound/deviceProvisioningServer.js +17 -17
  32. package/lib/templates/createDevice.json +5 -6
  33. package/lib/templates/createDeviceLax.json +6 -8
  34. package/lib/templates/deviceGroup.json +1 -5
  35. package/lib/templates/updateDevice.json +9 -2
  36. package/lib/templates/updateDeviceLax.json +14 -5
  37. package/package.json +1 -1
  38. package/scripts/legacy_expression_tool/README.md +262 -0
  39. package/scripts/legacy_expression_tool/legacy_expression_tool.py +423 -0
  40. package/scripts/legacy_expression_tool/requirements.txt +3 -0
  41. package/test/unit/examples/deviceProvisioningRequests/provisionBidirectionalDevice.json +5 -5
  42. package/test/unit/examples/groupProvisioningRequests/bidirectionalGroup.json +4 -4
  43. package/test/unit/general/contextBrokerKeystoneSecurityAccess-test.js +3 -13
  44. package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +0 -2
  45. package/test/unit/ngsi-ld/lazyAndCommands/merge-patch-test.js +31 -30
  46. package/test/unit/ngsi-ld/plugins/bidirectional-plugin_test.js +8 -8
  47. package/test/unit/ngsi-ld/plugins/custom-plugin_test.js +152 -0
  48. package/test/unit/ngsi-ld/plugins/multientity-plugin_test.js +1 -1
  49. package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +33 -37
  50. package/test/unit/ngsiv2/examples/contextRequests/createMinimumProvisionedDevice4.json +5 -1
  51. package/test/unit/ngsiv2/examples/contextRequests/updateContext.json +2 -0
  52. package/test/unit/ngsiv2/examples/contextRequests/updateContext1.json +3 -1
  53. package/test/unit/ngsiv2/examples/contextRequests/updateContext3WithStatic.json +2 -0
  54. package/test/unit/ngsiv2/examples/contextRequests/updateContext4.json +4 -1
  55. package/test/unit/ngsiv2/examples/contextRequests/updateContext5.json +12 -0
  56. package/test/unit/ngsiv2/examples/contextRequests/updateContext6.json +10 -0
  57. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin1.json +2 -0
  58. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin2.json +3 -1
  59. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin3.json +3 -1
  60. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin4.json +3 -1
  61. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin5.json +3 -1
  62. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin6.json +3 -1
  63. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin7.json +3 -1
  64. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin8.json +3 -1
  65. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin9.json +3 -1
  66. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast1.json +2 -0
  67. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast2.json +2 -0
  68. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast3.json +3 -1
  69. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast4.json +3 -1
  70. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast5.json +3 -1
  71. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast6.json +3 -1
  72. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast7.json +3 -1
  73. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandError.json +3 -1
  74. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandExpired.json +3 -1
  75. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandFinish.json +3 -1
  76. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandStatus.json +2 -0
  77. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandStatus2.json +2 -0
  78. package/test/unit/ngsiv2/examples/contextRequests/updateContextCompressTimestamp1.json +3 -1
  79. package/test/unit/ngsiv2/examples/contextRequests/updateContextCompressTimestamp2.json +3 -1
  80. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin1.json +2 -0
  81. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin11.json +2 -0
  82. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin12.json +2 -0
  83. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin13.json +3 -1
  84. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin2.json +2 -0
  85. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin29.json +2 -0
  86. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin3.json +2 -0
  87. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin30.json +2 -0
  88. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin31.json +2 -8
  89. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin32.json +2 -0
  90. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin33.json +2 -0
  91. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin34.json +2 -0
  92. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin35.json +22 -0
  93. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin36.json +1 -0
  94. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin4.json +2 -0
  95. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin40.json +42 -0
  96. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin41.json +33 -0
  97. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin5.json +2 -0
  98. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin6.json +2 -0
  99. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin7.json +2 -0
  100. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin8.json +2 -0
  101. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin9.json +2 -0
  102. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionSkip.json +12 -0
  103. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityJexlExpressionPlugin1.json +1 -1
  104. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin1.json +1 -1
  105. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin10.json +1 -1
  106. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin11.json +1 -1
  107. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin12.json +1 -1
  108. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin13.json +1 -1
  109. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin14.json +1 -1
  110. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin15.json +1 -1
  111. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin16.json +1 -1
  112. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin17.json +1 -1
  113. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin2.json +1 -1
  114. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin25.json +37 -0
  115. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin3.json +1 -1
  116. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin4.json +1 -1
  117. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin5.json +1 -1
  118. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin6.json +1 -1
  119. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin7.json +1 -1
  120. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin8.json +1 -1
  121. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin9.json +1 -1
  122. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +1 -1
  123. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +1 -1
  124. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin3.json +1 -1
  125. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin4.json +2 -0
  126. package/test/unit/ngsiv2/examples/contextRequests/updateContextProcessTimestamp.json +2 -0
  127. package/test/unit/ngsiv2/examples/contextRequests/updateContextStaticAttributes.json +2 -0
  128. package/test/unit/ngsiv2/examples/contextRequests/updateContextStaticAttributesMetadata.json +3 -1
  129. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestamp.json +3 -1
  130. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampFalse.json +12 -0
  131. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampFalseTimeInstant.json +12 -0
  132. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampOverride.json +2 -0
  133. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampOverrideWithoutMilis.json +2 -0
  134. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampTimezone.json +3 -1
  135. package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +355 -75
  136. package/test/unit/ngsiv2/general/contextBrokerOAuthSecurityAccess-test.js +18 -51
  137. package/test/unit/ngsiv2/general/https-support-test.js +1 -5
  138. package/test/unit/ngsiv2/lazyAndCommands/command-test.js +4 -10
  139. package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +9 -26
  140. package/test/unit/ngsiv2/ngsiService/active-devices-test.js +143 -57
  141. package/test/unit/ngsiv2/ngsiService/autocast-test.js +14 -21
  142. package/test/unit/ngsiv2/ngsiService/staticAttributes-test.js +3 -5
  143. package/test/unit/ngsiv2/ngsiService/subscriptions-test.js +1 -10
  144. package/test/unit/ngsiv2/plugins/alias-plugin_test.js +20 -30
  145. package/test/unit/ngsiv2/plugins/bidirectional-plugin_test.js +6 -69
  146. package/test/unit/ngsiv2/plugins/compress-timestamp-plugin_test.js +4 -6
  147. package/test/unit/ngsiv2/plugins/custom-plugin_test.js +150 -0
  148. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +87 -16
  149. package/test/unit/ngsiv2/plugins/timestamp-processing-plugin_test.js +2 -3
  150. package/test/unit/ngsiv2/provisioning/device-group-api-test.js +2 -3
  151. package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +15 -55
  152. package/test/unit/ngsiv2/provisioning/device-registration_test.js +1 -7
  153. package/test/unit/ngsiv2/provisioning/device-update-registration_test.js +2 -9
  154. package/test/unit/ngsiv2/provisioning/singleConfigurationMode-test.js +0 -11
  155. package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +0 -7
  156. package/test/unit/plugins/capture-provision-inPlugins_test.js +0 -6
  157. package/doc/advanced-topics.md +0 -626
  158. package/doc/expressionLanguage.md +0 -762
  159. package/lib/plugins/expressionParser.js +0 -205
  160. package/test/unit/expressions/expression-test.js +0 -197
  161. package/test/unit/ngsi-ld/expressions/expressionBasedTransformations-test.js +0 -882
  162. package/test/unit/ngsiv2/expressions/expressionBasedTransformations-test.js +0 -951
  163. package/test/unit/ngsiv2/expressions/expressionCombinedTransformations-test.js +0 -296
@@ -1,882 +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::[contacto@tid.es]
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 should = require('should');
31
- const logger = require('logops');
32
- const nock = require('nock');
33
- let contextBrokerMock;
34
- const iotAgentConfig = {
35
- logLevel: 'FATAL',
36
- contextBroker: {
37
- host: '192.168.1.1',
38
- port: '1026',
39
- ngsiVersion: 'ld',
40
- jsonLdContext: 'http://context.json-ld'
41
- },
42
- server: {
43
- port: 4041,
44
- host: 'localhost'
45
- },
46
- types: {
47
- Light: {
48
- commands: [],
49
- type: 'Light',
50
- lazy: [],
51
- active: [
52
- {
53
- object_id: 'p',
54
- name: 'pressure',
55
- type: 'Number'
56
- },
57
- {
58
- object_id: 'e',
59
- name: 'consumption',
60
- type: 'Number'
61
- },
62
- {
63
- object_id: 'a',
64
- name: 'alive',
65
- type: 'None'
66
- },
67
- {
68
- object_id: 'u',
69
- name: 'updated',
70
- type: 'Boolean'
71
- },
72
- {
73
- object_id: 'm',
74
- name: 'manufacturer',
75
- type: 'Object'
76
- },
77
- {
78
- object_id: 'r',
79
- name: 'revisions',
80
- type: 'Array'
81
- },
82
- {
83
- object_id: 'x',
84
- name: 'consumption_x',
85
- type: 'Number',
86
- expression: '${@pressure * 20}'
87
- }
88
- ]
89
- },
90
- LightError: {
91
- commands: [],
92
- type: 'Light',
93
- lazy: [],
94
- active: [
95
- {
96
- object_id: 'p',
97
- name: 'pressure',
98
- type: 'Number',
99
- expression: '${@pressure * / 20}'
100
- }
101
- ]
102
- },
103
- WeatherStation: {
104
- commands: [],
105
- type: 'WeatherStation',
106
- lazy: [],
107
- active: [
108
- {
109
- object_id: 'p',
110
- name: 'pressure',
111
- type: 'Number',
112
- expression: '${@pressure * 20}'
113
- },
114
- {
115
- object_id: 'e',
116
- name: 'consumption',
117
- type: 'Number',
118
- expression: '${@consumption * 20}'
119
- },
120
- {
121
- object_id: 'h',
122
- name: 'humidity',
123
- type: 'Percentage'
124
- },
125
- {
126
- name: 'weather',
127
- type: 'Summary',
128
- expression: 'Humidity ${@humidity / 2} and pressure ${@pressure * 20}'
129
- },
130
- {
131
- object_id: 'a',
132
- name: 'alive',
133
- type: 'None',
134
- expression: '${@alive * 20}'
135
- },
136
- {
137
- object_id: 'u',
138
- name: 'updated',
139
- type: 'Boolean',
140
- expression: '${@updated * 20}'
141
- }
142
- ]
143
- },
144
- WeatherStationMultiple: {
145
- commands: [],
146
- type: 'WeatherStation',
147
- lazy: [],
148
- active: [
149
- {
150
- object_id: 'p',
151
- name: 'pressure',
152
- type: 'Number',
153
- expression: '${trim(@pressure)}'
154
- },
155
- {
156
- object_id: 'p25',
157
- name: 'pressure25',
158
- type: 'Number'
159
- },
160
- {
161
- object_id: 'e',
162
- name: 'consumption',
163
- type: 'Number',
164
- expression: '${trim(@consumption)}'
165
- },
166
- {
167
- object_id: 'h',
168
- name: 'humidity12',
169
- type: 'Percentage'
170
- },
171
- {
172
- name: 'weather',
173
- type: 'Summary',
174
- expression: 'Humidity ${@humidity12 / 2} and pressure ${@pressure25 * 20}'
175
- },
176
- {
177
- object_id: 'a',
178
- name: 'alive',
179
- type: 'None',
180
- expression: '${trim(@alive)}'
181
- },
182
- {
183
- object_id: 'u',
184
- name: 'updated',
185
- type: 'Boolean',
186
- expression: '${trim(@updated)}'
187
- }
188
- ]
189
- }
190
- },
191
- service: 'smartgondor',
192
- subservice: 'gardens',
193
- providerUrl: 'http://smartgondor.com'
194
- };
195
-
196
- describe('NGSI-LD - Expression-based transformations plugin', function () {
197
- beforeEach(function (done) {
198
- logger.setLevel('FATAL');
199
-
200
- iotAgentLib.activate(iotAgentConfig, function () {
201
- iotAgentLib.clearAll(function () {
202
- done();
203
- });
204
- });
205
- });
206
-
207
- afterEach(function (done) {
208
- iotAgentLib.clearAll(function () {
209
- iotAgentLib.deactivate(done);
210
- });
211
- });
212
-
213
- describe('When an update comes for expressions with syntax errors', function () {
214
- // Case: Update for an attribute with bad expression
215
- const values = [
216
- {
217
- name: 'p',
218
- type: 'centigrades',
219
- value: '52'
220
- }
221
- ];
222
-
223
- it('should apply the expression before sending the values', function (done) {
224
- iotAgentLib.update('light1', 'LightError', '', values, function (error) {
225
- should.exist(error);
226
- error.name.should.equal('INVALID_EXPRESSION');
227
- error.code.should.equal(400);
228
- done();
229
- });
230
- });
231
- });
232
-
233
- describe('When there are expression attributes that are just calculated (not sent by the device)', function () {
234
- // Case: Expression which results is sent as a new attribute
235
- const values = [
236
- {
237
- name: 'p',
238
- type: 'Number',
239
- value: 52
240
- },
241
- {
242
- name: 'h',
243
- type: 'Percentage',
244
- value: '12'
245
- }
246
- ];
247
-
248
- beforeEach(function () {
249
- nock.cleanAll();
250
-
251
- contextBrokerMock = nock('http://192.168.1.1:1026')
252
- .matchHeader('fiware-service', 'smartgondor')
253
- .post(
254
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
255
- utils.readExampleFile(
256
- './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin2.json'
257
- )
258
- )
259
- .reply(204);
260
- });
261
-
262
- it('should calculate them and add them to the payload', function (done) {
263
- iotAgentLib.update('ws1', 'WeatherStation', '', values, function (error) {
264
- should.not.exist(error);
265
- contextBrokerMock.done();
266
- done();
267
- });
268
- });
269
- });
270
-
271
- describe('When an expression with multiple variables with numbers arrive', function () {
272
- // Case: Update for integer and string attributes with expression
273
-
274
- const values = [
275
- {
276
- name: 'p25',
277
- type: 'Number',
278
- value: 52
279
- },
280
- {
281
- name: 'h',
282
- type: 'percentage',
283
- value: '12'
284
- }
285
- ];
286
-
287
- beforeEach(function () {
288
- nock.cleanAll();
289
-
290
- contextBrokerMock = nock('http://192.168.1.1:1026')
291
- .matchHeader('fiware-service', 'smartgondor')
292
- .post(
293
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
294
- utils.readExampleFile(
295
- './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin4.json'
296
- )
297
- )
298
- .reply(204);
299
- });
300
-
301
- it('should calculate it and add it to the payload', function (done) {
302
- iotAgentLib.update('ws1', 'WeatherStationMultiple', '', values, function (error) {
303
- should.not.exist(error);
304
- contextBrokerMock.done();
305
- done();
306
- });
307
- });
308
- });
309
-
310
- describe('When an update comes for attributes without expressions and type integer', function () {
311
- // Case: Update for an integer attribute without expression
312
- const values = [
313
- {
314
- name: 'e',
315
- type: 'Number',
316
- value: 52
317
- }
318
- ];
319
-
320
- beforeEach(function () {
321
- nock.cleanAll();
322
-
323
- contextBrokerMock = nock('http://192.168.1.1:1026')
324
- .matchHeader('fiware-service', 'smartgondor')
325
- .post(
326
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
327
- utils.readExampleFile(
328
- './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin11.json'
329
- )
330
- )
331
- .reply(204);
332
- });
333
-
334
- it('should apply the expression before sending the values', function (done) {
335
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
336
- should.not.exist(error);
337
- contextBrokerMock.done();
338
- done();
339
- });
340
- });
341
- });
342
-
343
- describe('When an update comes for attributes with numeric expressions and type integer', function () {
344
- // Case: Update for an integer attribute with arithmetic expression
345
- const values = [
346
- {
347
- name: 'p',
348
- type: 'Number',
349
- value: 52
350
- }
351
- ];
352
-
353
- beforeEach(function () {
354
- nock.cleanAll();
355
-
356
- contextBrokerMock = nock('http://192.168.1.1:1026')
357
- .matchHeader('fiware-service', 'smartgondor')
358
- .post(
359
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
360
- utils.readExampleFile(
361
- './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin1.json'
362
- )
363
- )
364
- .reply(204);
365
- });
366
-
367
- it('should apply the expression before sending the values', function (done) {
368
- iotAgentLib.update('ws1', 'WeatherStation', '', values, function (error) {
369
- should.not.exist(error);
370
- contextBrokerMock.done();
371
- done();
372
- });
373
- });
374
- });
375
-
376
- describe('When an update comes for attributes with string expression and type integer', function () {
377
- // Case: Update for an integer attribute with string expression
378
- const values = [
379
- {
380
- name: 'e',
381
- type: 'Number',
382
- value: 52
383
- }
384
- ];
385
-
386
- beforeEach(function () {
387
- nock.cleanAll();
388
-
389
- contextBrokerMock = nock('http://192.168.1.1:1026')
390
- .matchHeader('fiware-service', 'smartgondor')
391
- .post(
392
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
393
- utils.readExampleFile(
394
- './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin18.json'
395
- )
396
- )
397
- .reply(204);
398
- });
399
-
400
- it('should apply the expression before sending the values', function (done) {
401
- iotAgentLib.update('ws1', 'WeatherStationMultiple', '', values, function (error) {
402
- should.not.exist(error);
403
- contextBrokerMock.done();
404
- done();
405
- });
406
- });
407
- });
408
-
409
- describe('When an update comes for attributes without expressions and type float', function () {
410
- // Case: Update for a Float attribute without expressions
411
-
412
- const values = [
413
- {
414
- name: 'e',
415
- type: 'Number',
416
- value: 0.44
417
- }
418
- ];
419
-
420
- beforeEach(function () {
421
- nock.cleanAll();
422
-
423
- contextBrokerMock = nock('http://192.168.1.1:1026')
424
- .matchHeader('fiware-service', 'smartgondor')
425
- .post(
426
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
427
- utils.readExampleFile(
428
- './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin3.json'
429
- )
430
- )
431
- .reply(204);
432
- });
433
-
434
- it('should apply the expression before sending the values', function (done) {
435
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
436
- should.not.exist(error);
437
- contextBrokerMock.done();
438
- done();
439
- });
440
- });
441
- });
442
-
443
- describe('When an update comes for attributes with numeric expressions and type float', function () {
444
- // Case: Update for a Float attribute with arithmetic expression
445
-
446
- const values = [
447
- {
448
- name: 'e',
449
- type: 'Number',
450
- value: 0.44
451
- }
452
- ];
453
-
454
- beforeEach(function () {
455
- nock.cleanAll();
456
-
457
- contextBrokerMock = nock('http://192.168.1.1:1026')
458
- .matchHeader('fiware-service', 'smartgondor')
459
- .post(
460
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
461
- utils.readExampleFile(
462
- './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin8.json'
463
- )
464
- )
465
- .reply(204);
466
- });
467
-
468
- it('should apply the expression before sending the values', function (done) {
469
- iotAgentLib.update('ws1', 'WeatherStation', '', values, function (error) {
470
- should.not.exist(error);
471
- contextBrokerMock.done();
472
- done();
473
- });
474
- });
475
- });
476
-
477
- describe('When an update comes for attributes with string expressions and type float', function () {
478
- // Case: Update for a Float attribute with string expression
479
-
480
- const values = [
481
- {
482
- name: 'e',
483
- type: 'Number',
484
- value: 0.44
485
- }
486
- ];
487
-
488
- beforeEach(function () {
489
- nock.cleanAll();
490
-
491
- contextBrokerMock = nock('http://192.168.1.1:1026')
492
- .matchHeader('fiware-service', 'smartgondor')
493
- .post(
494
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
495
- utils.readExampleFile(
496
- './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin19.json'
497
- )
498
- )
499
- .reply(204);
500
- });
501
-
502
- it('should apply the expression before sending the values', function (done) {
503
- iotAgentLib.update('ws1', 'WeatherStationMultiple', '', values, function (error) {
504
- should.not.exist(error);
505
- contextBrokerMock.done();
506
- done();
507
- });
508
- });
509
- });
510
-
511
- describe('When an update comes for attributes without expressions and NULL type', function () {
512
- // Case: Update for a Null attribute without expression
513
-
514
- const values = [
515
- {
516
- name: 'a',
517
- type: 'None',
518
- value: null
519
- }
520
- ];
521
-
522
- beforeEach(function () {
523
- nock.cleanAll();
524
-
525
- contextBrokerMock = nock('http://192.168.1.1:1026')
526
- .matchHeader('fiware-service', 'smartgondor')
527
- .post(
528
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
529
- utils.readExampleFile(
530
- './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin5.json'
531
- )
532
- )
533
- .reply(204);
534
- });
535
-
536
- it('should apply the expression before sending the values', function (done) {
537
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
538
- should.not.exist(error);
539
- contextBrokerMock.done();
540
- done();
541
- });
542
- });
543
- });
544
-
545
- describe('When an update comes for attributes with numeric expressions and NULL type', function () {
546
- // Case: Update for a Null attribute with arithmetic expression
547
-
548
- const values = [
549
- {
550
- name: 'a',
551
- type: 'None',
552
- value: null
553
- }
554
- ];
555
-
556
- beforeEach(function () {
557
- nock.cleanAll();
558
-
559
- contextBrokerMock = nock('http://192.168.1.1:1026')
560
- .matchHeader('fiware-service', 'smartgondor')
561
- .post(
562
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
563
- utils.readExampleFile(
564
- './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin16.json'
565
- )
566
- )
567
- .reply(204);
568
- });
569
-
570
- it('should apply the expression before sending the values', function (done) {
571
- iotAgentLib.update('ws1', 'WeatherStation', '', values, function (error) {
572
- should.not.exist(error);
573
- contextBrokerMock.done();
574
- done();
575
- });
576
- });
577
- });
578
-
579
- describe('When an update comes for attributes with string expressions and NULL type', function () {
580
- // Case: Update for a Null attribute with string expression
581
-
582
- const values = [
583
- {
584
- name: 'a',
585
- type: 'None',
586
- value: null
587
- }
588
- ];
589
-
590
- beforeEach(function () {
591
- nock.cleanAll();
592
-
593
- contextBrokerMock = nock('http://192.168.1.1:1026')
594
- .matchHeader('fiware-service', 'smartgondor')
595
- .post(
596
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
597
- utils.readExampleFile(
598
- './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin17.json'
599
- )
600
- )
601
- .reply(204);
602
- });
603
-
604
- it('should apply the expression before sending the values', function (done) {
605
- iotAgentLib.update('ws1', 'WeatherStationMultiple', '', values, function (error) {
606
- should.not.exist(error);
607
- contextBrokerMock.done();
608
- done();
609
- });
610
- });
611
- });
612
-
613
- describe('When an update comes for attributes without expressions and Boolean type', function () {
614
- // Case: Update for a Boolean attribute without expression
615
-
616
- const values = [
617
- {
618
- name: 'u',
619
- type: 'Boolean',
620
- value: true
621
- }
622
- ];
623
-
624
- beforeEach(function () {
625
- nock.cleanAll();
626
-
627
- contextBrokerMock = nock('http://192.168.1.1:1026')
628
- .matchHeader('fiware-service', 'smartgondor')
629
- .post(
630
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
631
- utils.readExampleFile(
632
- './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin9.json'
633
- )
634
- )
635
- .reply(204);
636
- });
637
-
638
- it('should apply the expression before sending the values', function (done) {
639
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
640
- should.not.exist(error);
641
- contextBrokerMock.done();
642
- done();
643
- });
644
- });
645
- });
646
-
647
- describe('When an update comes for attributes with numeric expressions and Boolean type', function () {
648
- // Case: Update for a Boolean attribute with arithmetic expression
649
-
650
- const values = [
651
- {
652
- name: 'u',
653
- type: 'Boolean',
654
- value: true
655
- }
656
- ];
657
-
658
- beforeEach(function () {
659
- nock.cleanAll();
660
-
661
- contextBrokerMock = nock('http://192.168.1.1:1026')
662
- .matchHeader('fiware-service', 'smartgondor')
663
- .post(
664
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
665
- utils.readExampleFile(
666
- './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin10.json'
667
- )
668
- )
669
- .reply(204);
670
- });
671
-
672
- it('should apply the expression before sending the values', function (done) {
673
- iotAgentLib.update('ws1', 'WeatherStation', '', values, function (error) {
674
- should.not.exist(error);
675
- contextBrokerMock.done();
676
- done();
677
- });
678
- });
679
- });
680
-
681
- describe('When an update comes for attributes with string expressions and Boolean type', function () {
682
- // Case: Update for a Boolean attribute with string expression
683
- const values = [
684
- {
685
- name: 'u',
686
- type: 'Boolean',
687
- value: true
688
- }
689
- ];
690
-
691
- beforeEach(function () {
692
- nock.cleanAll();
693
-
694
- contextBrokerMock = nock('http://192.168.1.1:1026')
695
- .matchHeader('fiware-service', 'smartgondor')
696
- .post(
697
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
698
- utils.readExampleFile(
699
- './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin15.json'
700
- )
701
- )
702
- .reply(204);
703
- });
704
-
705
- it('should apply the expression before sending the values', function (done) {
706
- iotAgentLib.update('ws1', 'WeatherStationMultiple', '', values, function (error) {
707
- should.not.exist(error);
708
- contextBrokerMock.done();
709
- done();
710
- });
711
- });
712
- });
713
-
714
- describe('When an update comes for attributes without expressions and Object type', function () {
715
- // Case: Update for a JSON document attribute without expression
716
- const values = [
717
- {
718
- name: 'm',
719
- type: 'Object',
720
- value: { name: 'Manufacturer1', VAT: 'U12345678' }
721
- }
722
- ];
723
-
724
- beforeEach(function () {
725
- nock.cleanAll();
726
-
727
- contextBrokerMock = nock('http://192.168.1.1:1026')
728
- .matchHeader('fiware-service', 'smartgondor')
729
- .post(
730
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
731
- utils.readExampleFile(
732
- './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin6.json'
733
- )
734
- )
735
- .reply(204);
736
- });
737
-
738
- it('should apply the expression before sending the values', function (done) {
739
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
740
- should.not.exist(error);
741
- contextBrokerMock.done();
742
- done();
743
- });
744
- });
745
- });
746
-
747
- describe('When an update comes for attributes without expressions and Array type', function () {
748
- // Case: Update for a JSON array attribute without expression
749
-
750
- const values = [
751
- {
752
- name: 'r',
753
- type: 'Array',
754
- value: ['v0.1', 'v0.2', 'v0.3']
755
- }
756
- ];
757
-
758
- beforeEach(function () {
759
- nock.cleanAll();
760
-
761
- contextBrokerMock = nock('http://192.168.1.1:1026')
762
- .matchHeader('fiware-service', 'smartgondor')
763
- .post(
764
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
765
- utils.readExampleFile(
766
- './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin7.json'
767
- )
768
- )
769
- .reply(204);
770
- });
771
-
772
- it('should apply the expression before sending the values', function (done) {
773
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
774
- should.not.exist(error);
775
- contextBrokerMock.done();
776
- done();
777
- });
778
- });
779
- });
780
-
781
- describe('When there are expressions including other attributes and they are not updated', function () {
782
- const values = [
783
- {
784
- name: 'x',
785
- type: 'Number',
786
- value: 0.44
787
- }
788
- ];
789
-
790
- beforeEach(function () {
791
- nock.cleanAll();
792
-
793
- contextBrokerMock = nock('http://192.168.1.1:1026')
794
- .matchHeader('fiware-service', 'smartgondor')
795
- .post(
796
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
797
- utils.readExampleFile(
798
- './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin12.json'
799
- )
800
- )
801
- .reply(204);
802
- });
803
-
804
- it('should apply the expression before sending the values', function (done) {
805
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
806
- should.not.exist(error);
807
- contextBrokerMock.done();
808
- done();
809
- });
810
- });
811
- });
812
-
813
- describe('When there are expressions including other attributes and they are updated', function () {
814
- const values = [
815
- {
816
- name: 'p',
817
- type: 'Number',
818
- value: 10
819
- }
820
- ];
821
-
822
- beforeEach(function () {
823
- nock.cleanAll();
824
-
825
- contextBrokerMock = nock('http://192.168.1.1:1026')
826
- .matchHeader('fiware-service', 'smartgondor')
827
- .post(
828
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
829
- utils.readExampleFile(
830
- './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin13.json'
831
- )
832
- )
833
- .reply(204);
834
- });
835
-
836
- it('should apply the expression before sending the values', function (done) {
837
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
838
- should.not.exist(error);
839
- contextBrokerMock.done();
840
- done();
841
- });
842
- });
843
- });
844
-
845
- describe('When there are expressions including other attributes and they are updated (overriding situation)', function () {
846
- const values = [
847
- {
848
- name: 'x',
849
- type: 'Number',
850
- value: 0.44
851
- },
852
- {
853
- name: 'p',
854
- type: 'Number',
855
- value: 10
856
- }
857
- ];
858
-
859
- beforeEach(function () {
860
- nock.cleanAll();
861
-
862
- contextBrokerMock = nock('http://192.168.1.1:1026')
863
- .matchHeader('fiware-service', 'smartgondor')
864
- .post(
865
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
866
- utils.readExampleFile(
867
- './test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin14.json'
868
- )
869
- )
870
-
871
- .reply(204);
872
- });
873
-
874
- it('should apply the expression before sending the values', function (done) {
875
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
876
- should.not.exist(error);
877
- contextBrokerMock.done();
878
- done();
879
- });
880
- });
881
- });
882
- });