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