iotagent-node-lib 4.7.0 → 4.9.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 (110) hide show
  1. package/.github/workflows/ci.yml +6 -3
  2. package/.nyc_output/e4b1fe20-197e-4221-9f8d-6db65ff234b2.json +1 -0
  3. package/.nyc_output/processinfo/e4b1fe20-197e-4221-9f8d-6db65ff234b2.json +1 -0
  4. package/.nyc_output/processinfo/index.json +1 -0
  5. package/CHANGES_NEXT_RELEASE +1 -0
  6. package/Changelog +793 -0
  7. package/doc/README.md +1 -0
  8. package/doc/admin.md +8 -4
  9. package/doc/api.md +8 -4
  10. package/doc/devel/northboundinteractions.md +122 -15
  11. package/doc/models/models.md +260 -0
  12. package/doc/requirements.txt +1 -1
  13. package/docker/Mosquitto/Dockerfile +1 -1
  14. package/lib/commonConfig.js +11 -2
  15. package/lib/fiware-iotagent-lib.js +15 -11
  16. package/lib/jexlTranformsMap.js +182 -35
  17. package/lib/model/Command.js +9 -0
  18. package/lib/model/Device.js +1 -0
  19. package/lib/services/commands/commandRegistryMongoDB.js +15 -1
  20. package/lib/services/commands/commandService.js +3 -3
  21. package/lib/services/common/domain.js +4 -3
  22. package/lib/services/devices/deviceRegistryMongoDB.js +1 -1
  23. package/lib/services/devices/deviceService.js +11 -2
  24. package/lib/services/devices/devices-NGSI-LD.js +1 -2
  25. package/lib/services/devices/devices-NGSI-v2.js +1 -2
  26. package/lib/services/ngsi/entities-NGSI-LD.js +69 -13
  27. package/lib/services/ngsi/ngsiService.js +3 -1
  28. package/lib/services/northBound/contextServer-NGSI-LD.js +5 -3
  29. package/lib/services/northBound/contextServer-NGSI-v2.js +12 -3
  30. package/lib/services/northBound/contextServer.js +2 -1
  31. package/lib/services/northBound/northboundServer.js +2 -1
  32. package/lib/services/northBound/restUtils.js +6 -2
  33. package/lib/templates/createDevice.json +4 -0
  34. package/lib/templates/updateDevice.json +4 -0
  35. package/package.json +1 -1
  36. package/test/functional/config-test.js +1 -1
  37. package/test/functional/testUtils.js +13 -2
  38. package/test/unit/expressions/jexlExpression-test.js +165 -1
  39. package/test/unit/ngsi-ld/examples/contextRequests/createDatetimeProvisionedDevice.json +1 -4
  40. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDevice.json +3 -12
  41. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceMultientity.json +3 -12
  42. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic.json +6 -24
  43. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic2.json +1 -4
  44. package/test/unit/ngsi-ld/examples/contextRequests/updateContext1.json +1 -4
  45. package/test/unit/ngsi-ld/examples/contextRequests/updateContext3WithStatic.json +1 -4
  46. package/test/unit/ngsi-ld/examples/contextRequests/updateContext4.json +1 -4
  47. package/test/unit/ngsi-ld/examples/contextRequests/updateContext5.json +1 -4
  48. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin6.json +1 -4
  49. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin7.json +1 -4
  50. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin8.json +4 -2
  51. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin9.json +1 -4
  52. package/test/unit/ngsi-ld/examples/contextRequests/updateContextCommandError.json +3 -9
  53. package/test/unit/ngsi-ld/examples/contextRequests/updateContextCommandExpired.json +13 -19
  54. package/test/unit/ngsi-ld/examples/contextRequests/updateContextCommandFinish.json +13 -19
  55. package/test/unit/ngsi-ld/examples/contextRequests/updateContextCommandStatus1.json +4 -9
  56. package/test/unit/ngsi-ld/examples/contextRequests/updateContextCompressTimestamp1.json +1 -4
  57. package/test/unit/ngsi-ld/examples/contextRequests/updateContextCompressTimestamp2.json +1 -4
  58. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin1a.json +1 -4
  59. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin2.json +2 -8
  60. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin29.json +1 -4
  61. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin4.json +2 -8
  62. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin4a.json +3 -12
  63. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin6.json +3 -5
  64. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin7.json +1 -4
  65. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin8a.json +1 -4
  66. package/test/unit/ngsi-ld/examples/contextRequests/updateContextJsonProperty.json +13 -0
  67. package/test/unit/ngsi-ld/examples/contextRequests/updateContextListProperty.json +14 -0
  68. package/test/unit/ngsi-ld/examples/contextRequests/updateContextListRelationship.json +14 -0
  69. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin1.json +2 -8
  70. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin2.json +2 -8
  71. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin3.json +3 -8
  72. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin4.json +1 -4
  73. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin5.json +2 -8
  74. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin8.json +2 -8
  75. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +2 -8
  76. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +1 -4
  77. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin3.json +1 -4
  78. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin4.json +2 -8
  79. package/test/unit/ngsi-ld/examples/contextRequests/updateContextRelationship.json +11 -0
  80. package/test/unit/ngsi-ld/examples/contextRequests/updateContextValueType1.json +51 -0
  81. package/test/unit/ngsi-ld/examples/contextRequests/updateContextValueType2.json +65 -0
  82. package/test/unit/ngsi-ld/examples/contextRequests/updateContextVocabProperty.json +11 -0
  83. package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionCommands1.json +2 -8
  84. package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionDeviceStatic.json +1 -4
  85. package/test/unit/ngsi-ld/general/startup-test.js +3 -0
  86. package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +1 -1
  87. package/test/unit/ngsi-ld/lazyAndCommands/lazy-devices-test.js +71 -1
  88. package/test/unit/ngsi-ld/ngsiService/attributeTypes-test.js +293 -0
  89. package/test/unit/ngsi-ld/ngsiService/unsupported-endpoints-test.js +0 -10
  90. package/test/unit/ngsi-ld/ngsiService/value-types-test.js +221 -0
  91. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast1.json +0 -11
  92. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast10.json +0 -14
  93. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast2.json +0 -11
  94. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast3.json +0 -11
  95. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast4.json +0 -11
  96. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast5.json +0 -7
  97. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast6.json +0 -17
  98. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast7.json +0 -19
  99. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast8.json +0 -14
  100. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast9.json +0 -14
  101. package/test/unit/ngsi-ld/ngsiService/languageProperties-test.js +0 -109
  102. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast1.json +0 -8
  103. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast2.json +0 -8
  104. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast3.json +0 -8
  105. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast4.json +0 -8
  106. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast5.json +0 -8
  107. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast6.json +0 -8
  108. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast7.json +0 -8
  109. package/test/unit/ngsiv2/ngsiService/subscriptions-test.js +0 -326
  110. /package/test/unit/ngsi-ld/examples/contextRequests/{updateContextLanguageProperties1.json → updateContextLanguageProperty.json} +0 -0
@@ -1187,7 +1187,7 @@ describe('NGSI-LD - Command functionalities', function () {
1187
1187
  });
1188
1188
 
1189
1189
  it('should update its value and status in the Context Broker', function (done) {
1190
- iotAgentLib.setCommandResult('r2d2', 'Robot', '', 'position', '[72, 368, 1]', 'FINISHED', function (error) {
1190
+ iotAgentLib.setCommandResult('r2d2', 'Robot', '', 'position', [72, 368, 1], 'FINISHED', function (error) {
1191
1191
  should.not.exist(error);
1192
1192
  statusAttributeMock.done();
1193
1193
  done();
@@ -226,7 +226,7 @@ describe('NGSI-LD - IoT Agent Lazy Devices', function () {
226
226
  it('should call the device handler for each of the contexts');
227
227
  });
228
228
 
229
- describe('When a context query arrives to the IoT Agent', function () {
229
+ describe('When a context query arrives to the IoT Agent using retrieveEntity', function () {
230
230
  const options = {
231
231
  url:
232
232
  'http://localhost:' +
@@ -294,6 +294,76 @@ describe('NGSI-LD - IoT Agent Lazy Devices', function () {
294
294
  });
295
295
  });
296
296
 
297
+ describe('When a context query arrives to the IoT Agent using queryEntities', function () {
298
+ const options = {
299
+ url:
300
+ 'http://localhost:' +
301
+ iotAgentConfig.server.port +
302
+ '/ngsi-ld/v1/entities/?id=urn:ngsi-ld:Light:light1&attrs=dimming',
303
+ method: 'GET',
304
+ headers: {
305
+ 'fiware-service': 'smartgondor',
306
+ 'fiware-servicepath': 'gardens'
307
+ }
308
+ };
309
+ const sensorData = [
310
+ {
311
+ id: 'Light:light1',
312
+ type: 'Light',
313
+ dimming: {
314
+ type: 'Percentage',
315
+ value: 19
316
+ }
317
+ }
318
+ ];
319
+
320
+ beforeEach(function (done) {
321
+ nock.cleanAll();
322
+
323
+ contextBrokerMock = nock('http://192.168.1.1:1026')
324
+ .matchHeader('fiware-service', 'smartgondor')
325
+ .post(
326
+ '/ngsi-ld/v1/csourceRegistrations/',
327
+ utils.readExampleFile(
328
+ './test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgent1.json'
329
+ )
330
+ )
331
+ .reply(201, null, { Location: '/ngsi-ld/v1/csourceRegistrations/6319a7f5254b05844116584d' });
332
+
333
+ contextBrokerMock
334
+ .matchHeader('fiware-service', 'smartgondor')
335
+ .post('/ngsi-ld/v1/entityOperations/upsert/')
336
+ .reply(204);
337
+
338
+ async.series([apply(iotAgentLib.activate, iotAgentConfig), apply(iotAgentLib.register, device1)], done);
339
+ });
340
+
341
+ it('should return the information querying the underlying devices', function (done) {
342
+ const expectedResponse = [
343
+ utils.readExampleFile(
344
+ './test/unit/ngsi-ld/examples/contextProviderResponses/queryInformationResponse.json'
345
+ )
346
+ ];
347
+
348
+ iotAgentLib.setDataUpdateHandler(function (id, type, service, subservice, attributes, callback) {
349
+ callback(null);
350
+ });
351
+
352
+ iotAgentLib.setDataQueryHandler(function (id, type, service, subservice, attributes, callback) {
353
+ id.should.equal('urn:ngsi-ld:' + device1.type + ':' + device1.id);
354
+ type.should.equal(device1.type);
355
+ attributes[0].should.equal('dimming');
356
+ callback(null, sensorData[0]);
357
+ });
358
+
359
+ request(options, function (error, response, body) {
360
+ should.not.exist(error);
361
+ body.should.eql(expectedResponse);
362
+ done();
363
+ });
364
+ });
365
+ });
366
+
297
367
  describe('When a context query arrives to the IoT Agent and no handler is set', function () {
298
368
  const options = {
299
369
  url:
@@ -0,0 +1,293 @@
1
+ /*
2
+ * Copyright 2022 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: 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
+ let contextBrokerMock;
35
+ const iotAgentConfig = {
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
+ active: [
51
+ {
52
+ name: 'name',
53
+ type: 'LanguageProperty'
54
+ },
55
+ {
56
+ name: 'locatedIn',
57
+ type: 'Relationship'
58
+ },
59
+ {
60
+ name: 'lightValues',
61
+ type: 'ListProperty'
62
+ },
63
+ {
64
+ name: 'placedIn',
65
+ type: 'ListRelationship'
66
+ },
67
+ {
68
+ name: 'categories',
69
+ type: 'VocabProperty'
70
+ },
71
+ {
72
+ name: 'config',
73
+ type: 'JsonProperty'
74
+ }
75
+ ]
76
+ }
77
+ },
78
+ service: 'smartgondor',
79
+ subservice: 'gardens',
80
+ providerUrl: 'http://smartgondor.com'
81
+ };
82
+
83
+ describe('NGSI-LD: Attribute types test', function () {
84
+ beforeEach(function () {
85
+ logger.setLevel('FATAL');
86
+ });
87
+
88
+ afterEach(function (done) {
89
+ iotAgentLib.deactivate(done);
90
+ });
91
+
92
+ describe('When the IoT Agent receives new exonym from a device name with LanguageProperty type and a JSON object', function () {
93
+ const values = [
94
+ {
95
+ name: 'name',
96
+ type: 'LanguageProperty',
97
+ value: {
98
+ el: 'Κωνσταντινούπολις',
99
+ en: 'Constantinople',
100
+ tr: 'İstanbul'
101
+ }
102
+ }
103
+ ];
104
+
105
+ beforeEach(function (done) {
106
+ nock.cleanAll();
107
+
108
+ contextBrokerMock = nock('http://192.168.1.1:1026')
109
+ .matchHeader('fiware-service', 'smartgondor')
110
+ .post(
111
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
112
+ utils.readExampleFile(
113
+ './test/unit/ngsi-ld/examples/contextRequests/updateContextLanguageProperty.json'
114
+ )
115
+ )
116
+ .reply(204);
117
+
118
+ iotAgentLib.activate(iotAgentConfig, done);
119
+ });
120
+
121
+ it('should change the LanguageMap of the corresponding attribute in the context broker', function (done) {
122
+ iotAgentLib.update('light1', 'Light', '', values, function (error) {
123
+ should.not.exist(error);
124
+ contextBrokerMock.done();
125
+ done();
126
+ });
127
+ });
128
+ });
129
+
130
+ describe('When the IoT Agent receives new list from a device with ListProperty type', function () {
131
+ const values = [
132
+ {
133
+ name: 'lightValues',
134
+ type: 'ListProperty',
135
+ value: [0, 1]
136
+ }
137
+ ];
138
+
139
+ beforeEach(function (done) {
140
+ nock.cleanAll();
141
+
142
+ contextBrokerMock = nock('http://192.168.1.1:1026')
143
+ .matchHeader('fiware-service', 'smartgondor')
144
+ .post(
145
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
146
+ utils.readExampleFile('./test/unit/ngsi-ld/examples/contextRequests/updateContextListProperty.json')
147
+ )
148
+ .reply(204);
149
+
150
+ iotAgentLib.activate(iotAgentConfig, done);
151
+ });
152
+
153
+ it('should change the listValue of the corresponding attribute in the context broker', function (done) {
154
+ iotAgentLib.update('light1', 'Light', '', values, function (error) {
155
+ should.not.exist(error);
156
+ contextBrokerMock.done();
157
+ done();
158
+ });
159
+ });
160
+ });
161
+
162
+ describe('When the IoT Agent receives new list from a device with ListRelationship type', function () {
163
+ const values = [
164
+ {
165
+ name: 'placedIn',
166
+ type: 'ListRelationship',
167
+ value: ['unr:ngsi-ld:xxx', 'unr:ngsi-ld:yyyy']
168
+ }
169
+ ];
170
+
171
+ beforeEach(function (done) {
172
+ nock.cleanAll();
173
+
174
+ contextBrokerMock = nock('http://192.168.1.1:1026')
175
+ .matchHeader('fiware-service', 'smartgondor')
176
+ .post(
177
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
178
+ utils.readExampleFile(
179
+ './test/unit/ngsi-ld/examples/contextRequests/updateContextListRelationship.json'
180
+ )
181
+ )
182
+ .reply(204);
183
+
184
+ iotAgentLib.activate(iotAgentConfig, done);
185
+ });
186
+
187
+ it('should change the listObject of the corresponding attribute in the context broker', function (done) {
188
+ iotAgentLib.update('light1', 'Light', '', values, function (error) {
189
+ should.not.exist(error);
190
+ contextBrokerMock.done();
191
+ done();
192
+ });
193
+ });
194
+ });
195
+
196
+ describe('When the IoT Agent receives new list from a device with JsonProperty type', function () {
197
+ const values = [
198
+ {
199
+ name: 'config',
200
+ type: 'JsonProperty',
201
+ value: { foo: 'bar' }
202
+ }
203
+ ];
204
+
205
+ beforeEach(function (done) {
206
+ nock.cleanAll();
207
+
208
+ contextBrokerMock = nock('http://192.168.1.1:1026')
209
+ .matchHeader('fiware-service', 'smartgondor')
210
+ .post(
211
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
212
+ utils.readExampleFile('./test/unit/ngsi-ld/examples/contextRequests/updateContextJsonProperty.json')
213
+ )
214
+ .reply(204);
215
+
216
+ iotAgentLib.activate(iotAgentConfig, done);
217
+ });
218
+
219
+ it('should change the json of the corresponding attribute in the context broker', function (done) {
220
+ iotAgentLib.update('light1', 'Light', '', values, function (error) {
221
+ should.not.exist(error);
222
+ contextBrokerMock.done();
223
+ done();
224
+ });
225
+ });
226
+ });
227
+
228
+ describe('When the IoT Agent receives new list from a device with VocabProperty type', function () {
229
+ const values = [
230
+ {
231
+ name: 'category',
232
+ type: 'VocabProperty',
233
+ value: 'actuator'
234
+ }
235
+ ];
236
+
237
+ beforeEach(function (done) {
238
+ nock.cleanAll();
239
+
240
+ contextBrokerMock = nock('http://192.168.1.1:1026')
241
+ .matchHeader('fiware-service', 'smartgondor')
242
+ .post(
243
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
244
+ utils.readExampleFile(
245
+ './test/unit/ngsi-ld/examples/contextRequests/updateContextVocabProperty.json'
246
+ )
247
+ )
248
+ .reply(204);
249
+
250
+ iotAgentLib.activate(iotAgentConfig, done);
251
+ });
252
+
253
+ it('should change the vocab of the corresponding attribute in the context broker', function (done) {
254
+ iotAgentLib.update('light1', 'Light', '', values, function (error) {
255
+ should.not.exist(error);
256
+ contextBrokerMock.done();
257
+ done();
258
+ });
259
+ });
260
+ });
261
+
262
+ describe('When the IoT Agent receives new urn from a device with Relationship type', function () {
263
+ const values = [
264
+ {
265
+ name: 'locatedIn',
266
+ type: 'Relationship',
267
+ value: 'urn:ngsi-ld:XXX'
268
+ }
269
+ ];
270
+
271
+ beforeEach(function (done) {
272
+ nock.cleanAll();
273
+
274
+ contextBrokerMock = nock('http://192.168.1.1:1026')
275
+ .matchHeader('fiware-service', 'smartgondor')
276
+ .post(
277
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
278
+ utils.readExampleFile('./test/unit/ngsi-ld/examples/contextRequests/updateContextRelationship.json')
279
+ )
280
+ .reply(204);
281
+
282
+ iotAgentLib.activate(iotAgentConfig, done);
283
+ });
284
+
285
+ it('should change the vocab of the corresponding attribute in the context broker', function (done) {
286
+ iotAgentLib.update('light1', 'Light', '', values, function (error) {
287
+ should.not.exist(error);
288
+ contextBrokerMock.done();
289
+ done();
290
+ });
291
+ });
292
+ });
293
+ });
@@ -108,16 +108,6 @@ describe('NGSI-LD - Unsupported Endpoints', function () {
108
108
  });
109
109
 
110
110
  describe('When accessing an Unsupported Endpoint', function () {
111
- it('GET /entities should return a valid NSGI-LD error message', function (done) {
112
- const options = {
113
- url: 'http://localhost:' + iotAgentConfig.server.port + '/ngsi-ld/v1/entities',
114
- method: 'GET'
115
- };
116
- request(options, function (error, response, body) {
117
- response.statusCode.should.equal(501);
118
- done();
119
- });
120
- });
121
111
  it('POST /entities should return a valid NSGI-LD error message', function (done) {
122
112
  const options = {
123
113
  url: 'http://localhost:' + iotAgentConfig.server.port + '/ngsi-ld/v1/entities',
@@ -0,0 +1,221 @@
1
+ /*
2
+ * Copyright 2014 Telefonica Investigación y Desarrollo, S.A.U
3
+ *
4
+ * This file is part of fiware-iotagent-lib
5
+ *
6
+ * fiware-iotagent-lib is free software: you can redistribute it and/or
7
+ * modify it under the terms of the GNU Affero General Public License as
8
+ * published by the Free Software Foundation, either version 3 of the License,
9
+ * or (at your option) any later version.
10
+ *
11
+ * fiware-iotagent-lib is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
+ * See the GNU Affero General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Affero General Public
17
+ * License along with fiware-iotagent-lib.
18
+ * If not, seehttp://www.gnu.org/licenses/.
19
+ *
20
+ * For those usages not covered by the GNU Affero General Public License
21
+ * please contact with::[contacto@tid.es]
22
+ *
23
+ * Developed by: Federico M. Facca - Martel Innovate
24
+ */
25
+
26
+ /* jshint camelcase: false */
27
+
28
+ const iotAgentLib = require('../../../../lib/fiware-iotagent-lib');
29
+ const utils = require('../../../tools/utils');
30
+ const should = require('should');
31
+ const nock = require('nock');
32
+ let contextBrokerMock;
33
+ const iotAgentConfig = {
34
+ logLevel: 'FATAL',
35
+ contextBroker: {
36
+ host: '192.168.1.1',
37
+ port: '1026',
38
+ ngsiVersion: 'ld',
39
+ jsonLdContext: 'http://context.json-ld'
40
+ },
41
+ server: {
42
+ port: 4041,
43
+ ldSupport: {
44
+ dataType: 'valueType'
45
+ }
46
+ },
47
+ types: {
48
+ Light: {
49
+ commands: [],
50
+ type: 'Light',
51
+ lazy: [],
52
+ active: [
53
+ {
54
+ object_id: 'p',
55
+ name: 'pressure',
56
+ type: 'Number'
57
+ },
58
+ {
59
+ object_id: 'e',
60
+ name: 'consumption',
61
+ type: 'Number'
62
+ },
63
+ {
64
+ object_id: 'a',
65
+ name: 'alive',
66
+ type: 'Property'
67
+ },
68
+ {
69
+ object_id: 'u',
70
+ name: 'updated',
71
+ type: 'Boolean'
72
+ },
73
+ {
74
+ object_id: 'm',
75
+ name: 'manufacturer',
76
+ type: 'Object'
77
+ },
78
+ {
79
+ object_id: 'r',
80
+ name: 'revisions',
81
+ type: 'Array'
82
+ },
83
+ {
84
+ object_id: 'd',
85
+ name: 'date',
86
+ type: 'Date'
87
+ },
88
+ {
89
+ object_id: 't',
90
+ name: 'time',
91
+ type: 'Time'
92
+ },
93
+ {
94
+ object_id: 'dt',
95
+ name: 'datetime',
96
+ type: 'DateTime'
97
+ }
98
+ ]
99
+ }
100
+ },
101
+ service: 'smartgondor',
102
+ subservice: 'gardens',
103
+ providerUrl: 'http://smartgondor.com',
104
+ deviceRegistrationDuration: 'P1M'
105
+ };
106
+
107
+ describe('NGSI-LD: Value Type', function () {
108
+ // Case: Expression which results is sent as a new attribute
109
+ const values = [
110
+ {
111
+ name: 'e',
112
+ type: 'Number',
113
+ value: 1
114
+ },
115
+ {
116
+ name: 'a',
117
+ type: 'Property',
118
+ value: 'foo'
119
+ },
120
+ {
121
+ name: 'u',
122
+ type: 'Boolean',
123
+ value: false
124
+ },
125
+ {
126
+ name: 'm',
127
+ type: 'Object',
128
+ value: '{"hello": "world"}'
129
+ },
130
+ {
131
+ name: 'r',
132
+ type: 'Array',
133
+ value: '[1,2]'
134
+ },
135
+ {
136
+ name: 'd',
137
+ type: 'Date',
138
+ value: '2025-07-18'
139
+ },
140
+ {
141
+ name: 't',
142
+ type: 'Time',
143
+ value: '14:22:11Z'
144
+ },
145
+ {
146
+ name: 'dt',
147
+ type: 'Datetime',
148
+ value: '2025-07-18T14:22:11Z'
149
+ }
150
+ ];
151
+
152
+ describe('When valueType is set to valueType', function () {
153
+ beforeEach(function (done) {
154
+ nock.cleanAll();
155
+
156
+ iotAgentConfig.contextBroker.valueType = 'valueType';
157
+ iotAgentLib.activate(iotAgentConfig, function () {
158
+ iotAgentLib.clearAll(function () {
159
+ done();
160
+ });
161
+ });
162
+
163
+ contextBrokerMock = nock('http://192.168.1.1:1026')
164
+ .matchHeader('fiware-service', 'smartgondor')
165
+ .matchHeader('fiware-servicepath', 'gardens')
166
+ .post(
167
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
168
+ utils.readExampleFile('./test/unit/ngsi-ld/examples/contextRequests/updateContextValueType1.json')
169
+ )
170
+ .reply(204);
171
+ });
172
+
173
+ afterEach(function (done) {
174
+ iotAgentLib.clearAll(function () {
175
+ iotAgentLib.deactivate(done);
176
+ });
177
+ });
178
+
179
+ it('should add valueType to the payload', function (done) {
180
+ iotAgentLib.update('ws1', 'Light', '', values, function (error) {
181
+ should.not.exist(error);
182
+ contextBrokerMock.done();
183
+ done();
184
+ });
185
+ });
186
+ });
187
+ describe('When valueType is set to @type', function () {
188
+ beforeEach(function (done) {
189
+ iotAgentConfig.server.ldSupport.dataType = '@type';
190
+ iotAgentLib.activate(iotAgentConfig, function () {
191
+ iotAgentLib.clearAll(function () {
192
+ done();
193
+ });
194
+ });
195
+ nock.cleanAll();
196
+
197
+ contextBrokerMock = nock('http://192.168.1.1:1026')
198
+ .matchHeader('fiware-service', 'smartgondor')
199
+ .matchHeader('fiware-servicepath', 'gardens')
200
+ .post(
201
+ '/ngsi-ld/v1/entityOperations/upsert/?options=update',
202
+ utils.readExampleFile('./test/unit/ngsi-ld/examples/contextRequests/updateContextValueType2.json')
203
+ )
204
+ .reply(204);
205
+ });
206
+
207
+ afterEach(function (done) {
208
+ iotAgentLib.clearAll(function () {
209
+ iotAgentLib.deactivate(done);
210
+ });
211
+ });
212
+
213
+ it('should add @type to the payload', function (done) {
214
+ iotAgentLib.update('ws1', 'Light', '', values, function (error) {
215
+ should.not.exist(error);
216
+ contextBrokerMock.done();
217
+ done();
218
+ });
219
+ });
220
+ });
221
+ });
@@ -1,11 +0,0 @@
1
- [
2
- {
3
- "@context": "http://context.json-ld",
4
- "id": "urn:ngsi-ld:Light:light1",
5
- "pressure": {
6
- "type": "Property",
7
- "value": 23
8
- },
9
- "type": "Light"
10
- }
11
- ]
@@ -1,14 +0,0 @@
1
- [
2
- {
3
- "@context": "http://context.json-ld",
4
- "date": {
5
- "type": "Property",
6
- "value": {
7
- "@type": "Date",
8
- "@value": "2016-04-30"
9
- }
10
- },
11
- "id": "urn:ngsi-ld:Light:light1",
12
- "type": "Light"
13
- }
14
- ]
@@ -1,11 +0,0 @@
1
- [
2
- {
3
- "@context": "http://context.json-ld",
4
- "id": "urn:ngsi-ld:Light:light1",
5
- "temperature": {
6
- "type": "Property",
7
- "value": 14.4
8
- },
9
- "type": "Light"
10
- }
11
- ]
@@ -1,11 +0,0 @@
1
- [
2
- {
3
- "@context": "http://context.json-ld",
4
- "id": "urn:ngsi-ld:Light:light1",
5
- "status": {
6
- "type": "Property",
7
- "value": true
8
- },
9
- "type": "Light"
10
- }
11
- ]
@@ -1,11 +0,0 @@
1
- [
2
- {
3
- "@context": "http://context.json-ld",
4
- "id": "urn:ngsi-ld:Light:light1",
5
- "status": {
6
- "type": "Property",
7
- "value": false
8
- },
9
- "type": "Light"
10
- }
11
- ]