iotagent-node-lib 2.20.0 → 2.23.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.
- package/.nyc_output/6e3d7795-bf8c-4a50-bd2f-f8221f27aeae.json +1 -0
- package/.nyc_output/processinfo/6e3d7795-bf8c-4a50-bd2f-f8221f27aeae.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -1
- package/.readthedocs.yml +3 -1
- package/CHANGES_NEXT_RELEASE +1 -0
- package/README.md +2 -2
- package/config +0 -0
- package/doc/Contribution.md +3 -3
- package/doc/advanced-topics.md +19 -8
- package/doc/api.md +14 -3
- package/doc/expressionLanguage.md +17 -0
- package/doc/northboundinteractions.md +40 -33
- package/doc/operations.md +8 -5
- package/doc/requirements.txt +4 -0
- package/{docs → doc}/roadmap.md +21 -6
- package/doc/usermanual.md +4 -4
- package/docker/Mosquitto/Dockerfile +28 -12
- package/docker/Mosquitto/Dockerfile.debian +38 -0
- package/docker/Mosquitto/Dockerfile.debian~ +23 -0
- package/docker/Mosquitto/README.md +8 -7
- package/docker/Mosquitto/startMosquitto.sh +8 -0
- package/lib/fiware-iotagent-lib.js +1 -0
- package/lib/jexlTranformsMap.js +3 -1
- package/lib/model/Group.js +2 -1
- package/lib/model/dbConn.js +4 -0
- package/lib/plugins/expressionPlugin.js +56 -21
- package/lib/plugins/multiEntity.js +43 -49
- package/lib/plugins/multiEntity.js_avg2 +343 -0
- package/lib/plugins/pluginUtils.js +16 -0
- package/lib/services/commands/commandService.js +29 -2
- package/lib/services/common/iotManagerService.js +2 -1
- package/lib/services/devices/deviceRegistryMemory.js +13 -2
- package/lib/services/devices/deviceRegistryMongoDB.js +15 -7
- package/lib/services/devices/deviceService.js +52 -16
- package/lib/services/groups/groupRegistryMongoDB.js +13 -12
- package/lib/services/ngsi/entities-NGSI-LD.js +13 -4
- package/lib/services/ngsi/entities-NGSI-v2.js +64 -13
- package/lib/services/ngsi/ngsiService.js +3 -3
- package/lib/services/northBound/contextServer-NGSI-LD.js +20 -1
- package/lib/services/northBound/contextServer-NGSI-v2.js +39 -30
- package/lib/services/northBound/contextServerUtils.js +10 -10
- package/lib/services/northBound/deviceProvisioningServer.js +4 -1
- package/lib/templates/createDevice.json +13 -2
- package/lib/templates/createDeviceLax.json +2 -3
- package/lib/templates/updateDevice.json +13 -2
- package/package.json +26 -26
- package/test/unit/examples/deviceProvisioningRequests/provisionMinimumDevice4.json +14 -0
- package/test/unit/mongodb/mongoDBUtils.js +2 -2
- package/test/unit/mongodb/mongodb-group-registry-test.js +1 -1
- package/test/unit/mongodb/mongodb-registry-test.js +2 -3
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgentCommands.json +2 -1
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextLanguageProperties1.json +15 -0
- package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +315 -1
- package/test/unit/ngsi-ld/ngsiService/languageProperties-test.js +112 -0
- package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +1 -1
- package/test/unit/ngsiv2/examples/contextRequests/createMinimumProvisionedDevice4.json +8 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandStatus2.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin35.json +2 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin36.json +12 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin17.json +27 -0
- package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +72 -9
- package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +151 -0
- package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +63 -0
- package/test/unit/ngsiv2/plugins/multientity-plugin_test.js_avg2 +1224 -0
- package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +60 -0
- package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +2 -1
- package/.nyc_output/76bc24ff-5fac-4b5a-997d-de2799342eb0.json +0 -1
- package/.nyc_output/processinfo/76bc24ff-5fac-4b5a-997d-de2799342eb0.json +0 -1
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "iotagent-node-lib",
|
|
3
3
|
"license": "AGPL-3.0-only",
|
|
4
4
|
"description": "IoT Agent library to interface with NGSI Context Broker",
|
|
5
|
-
"version": "2.
|
|
5
|
+
"version": "2.23.0",
|
|
6
6
|
"homepage": "https://github.com/telefonicaid/iotagent-node-lib",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"fiware",
|
|
@@ -42,42 +42,42 @@
|
|
|
42
42
|
"watch": "watch 'npm test && npm run lint' ./lib ./test"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"async": "2.6.
|
|
46
|
-
"body-parser": "~1.
|
|
47
|
-
"express": "~4.
|
|
48
|
-
"got": "~11.8.
|
|
45
|
+
"async": "2.6.4",
|
|
46
|
+
"body-parser": "~1.20.0",
|
|
47
|
+
"express": "~4.18.1",
|
|
48
|
+
"got": "~11.8.5",
|
|
49
49
|
"jexl": "2.3.0",
|
|
50
50
|
"jison": "0.4.18",
|
|
51
51
|
"logops": "2.1.2",
|
|
52
|
-
"moment": "~2.
|
|
53
|
-
"moment-timezone": "~0.5.
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"query-string": "6.5.0",
|
|
52
|
+
"moment": "~2.29.2",
|
|
53
|
+
"moment-timezone": "~0.5.34",
|
|
54
|
+
"mongoose": "5.13.14",
|
|
55
|
+
"query-string": "7.1.1",
|
|
57
56
|
"revalidator": "~0.3.1",
|
|
58
|
-
"underscore": "~1.
|
|
59
|
-
"uuid": "~
|
|
57
|
+
"underscore": "~1.13.4",
|
|
58
|
+
"uuid": "~8.3.2"
|
|
60
59
|
},
|
|
61
60
|
"devDependencies": {
|
|
62
|
-
"coveralls": "~3.1.
|
|
63
|
-
"eslint": "~
|
|
64
|
-
"eslint-config-tamia": "~
|
|
65
|
-
"eslint-plugin-prettier": "~
|
|
61
|
+
"coveralls": "~3.1.1",
|
|
62
|
+
"eslint": "~8.18.0",
|
|
63
|
+
"eslint-config-tamia": "~8.0.0",
|
|
64
|
+
"eslint-plugin-prettier": "~4.0.0",
|
|
66
65
|
"husky": "~4.2.5",
|
|
67
|
-
"lint-staged": "~
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"nock": "13.
|
|
66
|
+
"lint-staged": "~12.3.8",
|
|
67
|
+
"mocha": "10.0.0",
|
|
68
|
+
"mongodb": "4.7.0",
|
|
69
|
+
"nock": "13.2.7",
|
|
71
70
|
"nyc": "~15.1.0",
|
|
72
|
-
"
|
|
73
|
-
"remark-
|
|
71
|
+
"prettier": "~2.7.1",
|
|
72
|
+
"remark-cli": "~10.0.1",
|
|
73
|
+
"remark-preset-lint-recommended": "~6.1.2",
|
|
74
74
|
"should": "13.2.3",
|
|
75
|
-
"sinon": "~
|
|
76
|
-
"textlint": "~
|
|
75
|
+
"sinon": "~14.0.0",
|
|
76
|
+
"textlint": "~12.2.1",
|
|
77
77
|
"textlint-filter-rule-comments": "~1.2.2",
|
|
78
78
|
"textlint-rule-common-misspellings": "~1.0.1",
|
|
79
|
-
"textlint-rule-terminology": "~
|
|
80
|
-
"textlint-rule-write-good": "~
|
|
79
|
+
"textlint-rule-terminology": "~3.0.2",
|
|
80
|
+
"textlint-rule-write-good": "~2.0.0",
|
|
81
81
|
"timekeeper": "2.2.0",
|
|
82
82
|
"watch": "~1.0.2"
|
|
83
83
|
},
|
|
@@ -29,7 +29,7 @@ const async = require('async');
|
|
|
29
29
|
function cleanDb(host, name, callback) {
|
|
30
30
|
const url = 'mongodb://' + host + ':27017/' + name;
|
|
31
31
|
|
|
32
|
-
MongoClient.connect(url,
|
|
32
|
+
MongoClient.connect(url, function (err, db) {
|
|
33
33
|
if (db && db.db()) {
|
|
34
34
|
db.db().dropDatabase(function (err, result) {
|
|
35
35
|
db.close();
|
|
@@ -46,7 +46,7 @@ function cleanDbs(callback) {
|
|
|
46
46
|
function populate(host, dbName, entityList, collectionName, callback) {
|
|
47
47
|
const url = 'mongodb://' + host + ':27017/' + dbName;
|
|
48
48
|
|
|
49
|
-
MongoClient.connect(url,
|
|
49
|
+
MongoClient.connect(url, function (err, db) {
|
|
50
50
|
if (db) {
|
|
51
51
|
db.db()
|
|
52
52
|
.collection(collectionName)
|
|
@@ -179,7 +179,7 @@ describe('MongoDB Group Registry test', function () {
|
|
|
179
179
|
beforeEach(function (done) {
|
|
180
180
|
mongoUtils.cleanDbs(function () {
|
|
181
181
|
iotAgentLib.activate(iotAgentConfig, function () {
|
|
182
|
-
mongo.connect('mongodb://localhost:27017/iotagent',
|
|
182
|
+
mongo.connect('mongodb://localhost:27017/iotagent', function (err, db) {
|
|
183
183
|
iotAgentDb = db;
|
|
184
184
|
done();
|
|
185
185
|
});
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
|
|
26
26
|
const iotAgentLib = require('../../../lib/fiware-iotagent-lib');
|
|
27
27
|
const utils = require('../../tools/utils');
|
|
28
|
-
const request = utils.request;
|
|
29
28
|
const should = require('should');
|
|
30
29
|
const logger = require('logops');
|
|
31
30
|
const mongo = require('mongodb').MongoClient;
|
|
@@ -191,7 +190,7 @@ describe('NGSI-v2 - MongoDB Device Registry', function () {
|
|
|
191
190
|
logger.setLevel('FATAL');
|
|
192
191
|
|
|
193
192
|
mongoUtils.cleanDbs(function () {
|
|
194
|
-
mongo.connect('mongodb://localhost:27017/iotagent',
|
|
193
|
+
mongo.connect('mongodb://localhost:27017/iotagent', function (err, db) {
|
|
195
194
|
iotAgentDb = db;
|
|
196
195
|
done();
|
|
197
196
|
});
|
|
@@ -204,7 +203,7 @@ describe('NGSI-v2 - MongoDB Device Registry', function () {
|
|
|
204
203
|
iotAgentDb
|
|
205
204
|
.db()
|
|
206
205
|
.collection('devices')
|
|
207
|
-
.deleteOne(function (error) {
|
|
206
|
+
.deleteOne({}, function (error) {
|
|
208
207
|
iotAgentDb.close(function (error) {
|
|
209
208
|
mongoUtils.cleanDbs(done);
|
|
210
209
|
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"@context": "http://context.json-ld",
|
|
4
|
+
"name": {
|
|
5
|
+
"type": "LanguageProperty",
|
|
6
|
+
"languageMap": {
|
|
7
|
+
"el": "Κωνσταντινούπολις",
|
|
8
|
+
"en": "Constantinople",
|
|
9
|
+
"tr": "İstanbul"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"id": "urn:ngsi-ld:Light:light1",
|
|
13
|
+
"type": "Light"
|
|
14
|
+
}
|
|
15
|
+
]
|
|
@@ -94,6 +94,10 @@ const iotAgentConfig = {
|
|
|
94
94
|
{
|
|
95
95
|
name: 'position',
|
|
96
96
|
type: 'Array'
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: 'orientation',
|
|
100
|
+
type: 'Array'
|
|
97
101
|
}
|
|
98
102
|
],
|
|
99
103
|
lazy: [],
|
|
@@ -158,7 +162,114 @@ describe('NGSI-LD - Command functionalities', function () {
|
|
|
158
162
|
});
|
|
159
163
|
});
|
|
160
164
|
});
|
|
161
|
-
|
|
165
|
+
|
|
166
|
+
describe('When multiple command updates via PATCH /attrs arrive to the IoT Agent as Context Provider', function () {
|
|
167
|
+
const options = {
|
|
168
|
+
url: 'http://localhost:' + iotAgentConfig.server.port + '/ngsi-ld/v1/entities/urn:ngsi-ld:Robot:r2d2/attrs',
|
|
169
|
+
method: 'PATCH',
|
|
170
|
+
json: {
|
|
171
|
+
orientation: {
|
|
172
|
+
type: 'Property',
|
|
173
|
+
value: [1, 2, 3]
|
|
174
|
+
},
|
|
175
|
+
position: {
|
|
176
|
+
type: 'Property',
|
|
177
|
+
value: [28, -104, 23]
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
headers: {
|
|
181
|
+
'fiware-service': 'smartgondor',
|
|
182
|
+
'content-type': 'application/ld+json'
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
beforeEach(function (done) {
|
|
187
|
+
logger.setLevel('ERROR');
|
|
188
|
+
iotAgentLib.register(device3, function (error) {
|
|
189
|
+
done();
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('should call the client handler once', function (done) {
|
|
194
|
+
let handlerCalled = 0;
|
|
195
|
+
|
|
196
|
+
iotAgentLib.setCommandHandler(function (id, type, service, subservice, attributes, callback) {
|
|
197
|
+
id.should.equal('urn:ngsi-ld:' + device3.type + ':' + device3.id);
|
|
198
|
+
type.should.equal(device3.type);
|
|
199
|
+
attributes[0].name.should.equal('position');
|
|
200
|
+
attributes[1].name.should.equal('orientation');
|
|
201
|
+
JSON.stringify(attributes[0].value).should.equal('[28,-104,23]');
|
|
202
|
+
JSON.stringify(attributes[1].value).should.equal('[1,2,3]');
|
|
203
|
+
handlerCalled++;
|
|
204
|
+
callback(null, {
|
|
205
|
+
id,
|
|
206
|
+
type,
|
|
207
|
+
attributes: [
|
|
208
|
+
{
|
|
209
|
+
name: 'position',
|
|
210
|
+
type: 'Array',
|
|
211
|
+
value: '[28, -104, 23]'
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
name: 'orientation',
|
|
215
|
+
type: 'Array',
|
|
216
|
+
value: '[1, 2, 3]'
|
|
217
|
+
}
|
|
218
|
+
]
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
request(options, function (error, response, body) {
|
|
223
|
+
should.not.exist(error);
|
|
224
|
+
handlerCalled.should.equal(1);
|
|
225
|
+
done();
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
it('should create the attribute with the "_status" prefix in the Context Broker', function (done) {
|
|
229
|
+
iotAgentLib.setCommandHandler(function (id, type, service, subservice, attributes, callback) {
|
|
230
|
+
callback(null, {
|
|
231
|
+
id,
|
|
232
|
+
type,
|
|
233
|
+
attributes: [
|
|
234
|
+
{
|
|
235
|
+
name: 'position',
|
|
236
|
+
type: 'Array',
|
|
237
|
+
value: '[28, -104, 23]'
|
|
238
|
+
}
|
|
239
|
+
]
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
request(options, function (error, response, body) {
|
|
244
|
+
should.not.exist(error);
|
|
245
|
+
done();
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
it('should create the attribute with the "_status" prefix in the Context Broker', function (done) {
|
|
249
|
+
let serviceReceived = false;
|
|
250
|
+
iotAgentLib.setCommandHandler(function (id, type, service, subservice, attributes, callback) {
|
|
251
|
+
serviceReceived = service === 'smartgondor';
|
|
252
|
+
callback(null, {
|
|
253
|
+
id,
|
|
254
|
+
type,
|
|
255
|
+
attributes: [
|
|
256
|
+
{
|
|
257
|
+
name: 'position',
|
|
258
|
+
type: 'Array',
|
|
259
|
+
value: '[28, -104, 23]'
|
|
260
|
+
}
|
|
261
|
+
]
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
request(options, function (error, response, body) {
|
|
266
|
+
serviceReceived.should.equal(true);
|
|
267
|
+
done();
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
describe('When a command update PATCH attrs/attr-name arrives to the IoT Agent as Context Provider', function () {
|
|
162
273
|
const options = {
|
|
163
274
|
url:
|
|
164
275
|
'http://localhost:' +
|
|
@@ -253,6 +364,209 @@ describe('NGSI-LD - Command functionalities', function () {
|
|
|
253
364
|
});
|
|
254
365
|
});
|
|
255
366
|
});
|
|
367
|
+
|
|
368
|
+
describe('When multiple command overwrites via PUT /attrs arrive to the IoT Agent as Context Provider', function () {
|
|
369
|
+
const options = {
|
|
370
|
+
url: 'http://localhost:' + iotAgentConfig.server.port + '/ngsi-ld/v1/entities/urn:ngsi-ld:Robot:r2d2/attrs',
|
|
371
|
+
method: 'PUT',
|
|
372
|
+
json: {
|
|
373
|
+
orientation: {
|
|
374
|
+
type: 'Property',
|
|
375
|
+
value: [1, 2, 3]
|
|
376
|
+
},
|
|
377
|
+
position: {
|
|
378
|
+
type: 'Property',
|
|
379
|
+
value: [28, -104, 23]
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
headers: {
|
|
383
|
+
'fiware-service': 'smartgondor',
|
|
384
|
+
'content-type': 'application/ld+json'
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
beforeEach(function (done) {
|
|
389
|
+
logger.setLevel('ERROR');
|
|
390
|
+
iotAgentLib.register(device3, function (error) {
|
|
391
|
+
done();
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
it('should call the client handler once', function (done) {
|
|
396
|
+
let handlerCalled = 0;
|
|
397
|
+
|
|
398
|
+
iotAgentLib.setCommandHandler(function (id, type, service, subservice, attributes, callback) {
|
|
399
|
+
id.should.equal('urn:ngsi-ld:' + device3.type + ':' + device3.id);
|
|
400
|
+
type.should.equal(device3.type);
|
|
401
|
+
attributes[0].name.should.equal('position');
|
|
402
|
+
attributes[1].name.should.equal('orientation');
|
|
403
|
+
JSON.stringify(attributes[0].value).should.equal('[28,-104,23]');
|
|
404
|
+
JSON.stringify(attributes[1].value).should.equal('[1,2,3]');
|
|
405
|
+
handlerCalled++;
|
|
406
|
+
callback(null, {
|
|
407
|
+
id,
|
|
408
|
+
type,
|
|
409
|
+
attributes: [
|
|
410
|
+
{
|
|
411
|
+
name: 'position',
|
|
412
|
+
type: 'Array',
|
|
413
|
+
value: '[28, -104, 23]'
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
name: 'orientation',
|
|
417
|
+
type: 'Array',
|
|
418
|
+
value: '[1, 2, 3]'
|
|
419
|
+
}
|
|
420
|
+
]
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
request(options, function (error, response, body) {
|
|
425
|
+
should.not.exist(error);
|
|
426
|
+
handlerCalled.should.equal(1);
|
|
427
|
+
done();
|
|
428
|
+
});
|
|
429
|
+
});
|
|
430
|
+
it('should create the attribute with the "_status" prefix in the Context Broker', function (done) {
|
|
431
|
+
iotAgentLib.setCommandHandler(function (id, type, service, subservice, attributes, callback) {
|
|
432
|
+
callback(null, {
|
|
433
|
+
id,
|
|
434
|
+
type,
|
|
435
|
+
attributes: [
|
|
436
|
+
{
|
|
437
|
+
name: 'position',
|
|
438
|
+
type: 'Array',
|
|
439
|
+
value: '[28, -104, 23]'
|
|
440
|
+
}
|
|
441
|
+
]
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
request(options, function (error, response, body) {
|
|
446
|
+
should.not.exist(error);
|
|
447
|
+
done();
|
|
448
|
+
});
|
|
449
|
+
});
|
|
450
|
+
it('should create the attribute with the "_status" prefix in the Context Broker', function (done) {
|
|
451
|
+
let serviceReceived = false;
|
|
452
|
+
iotAgentLib.setCommandHandler(function (id, type, service, subservice, attributes, callback) {
|
|
453
|
+
serviceReceived = service === 'smartgondor';
|
|
454
|
+
callback(null, {
|
|
455
|
+
id,
|
|
456
|
+
type,
|
|
457
|
+
attributes: [
|
|
458
|
+
{
|
|
459
|
+
name: 'position',
|
|
460
|
+
type: 'Array',
|
|
461
|
+
value: '[28, -104, 23]'
|
|
462
|
+
}
|
|
463
|
+
]
|
|
464
|
+
});
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
request(options, function (error, response, body) {
|
|
468
|
+
serviceReceived.should.equal(true);
|
|
469
|
+
done();
|
|
470
|
+
});
|
|
471
|
+
});
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
describe('When a command overwrite PUT attrs/attr-name arrives to the IoT Agent as Context Provider', function () {
|
|
475
|
+
const options = {
|
|
476
|
+
url:
|
|
477
|
+
'http://localhost:' +
|
|
478
|
+
iotAgentConfig.server.port +
|
|
479
|
+
'/ngsi-ld/v1/entities/urn:ngsi-ld:Robot:r2d2/attrs/position',
|
|
480
|
+
method: 'PUT',
|
|
481
|
+
json: {
|
|
482
|
+
type: 'Property',
|
|
483
|
+
value: [28, -104, 23]
|
|
484
|
+
},
|
|
485
|
+
headers: {
|
|
486
|
+
'fiware-service': 'smartgondor',
|
|
487
|
+
'content-type': 'application/ld+json'
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
beforeEach(function (done) {
|
|
492
|
+
logger.setLevel('ERROR');
|
|
493
|
+
iotAgentLib.register(device3, function (error) {
|
|
494
|
+
done();
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
it('should call the client handler once', function (done) {
|
|
499
|
+
let handlerCalled = 0;
|
|
500
|
+
|
|
501
|
+
iotAgentLib.setCommandHandler(function (id, type, service, subservice, attributes, callback) {
|
|
502
|
+
id.should.equal('urn:ngsi-ld:' + device3.type + ':' + device3.id);
|
|
503
|
+
type.should.equal(device3.type);
|
|
504
|
+
attributes[0].name.should.equal('position');
|
|
505
|
+
JSON.stringify(attributes[0].value).should.equal('[28,-104,23]');
|
|
506
|
+
handlerCalled++;
|
|
507
|
+
callback(null, {
|
|
508
|
+
id,
|
|
509
|
+
type,
|
|
510
|
+
attributes: [
|
|
511
|
+
{
|
|
512
|
+
name: 'position',
|
|
513
|
+
type: 'Array',
|
|
514
|
+
value: '[28, -104, 23]'
|
|
515
|
+
}
|
|
516
|
+
]
|
|
517
|
+
});
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
request(options, function (error, response, body) {
|
|
521
|
+
should.not.exist(error);
|
|
522
|
+
handlerCalled.should.equal(1);
|
|
523
|
+
done();
|
|
524
|
+
});
|
|
525
|
+
});
|
|
526
|
+
it('should create the attribute with the "_status" prefix in the Context Broker', function (done) {
|
|
527
|
+
iotAgentLib.setCommandHandler(function (id, type, service, subservice, attributes, callback) {
|
|
528
|
+
callback(null, {
|
|
529
|
+
id,
|
|
530
|
+
type,
|
|
531
|
+
attributes: [
|
|
532
|
+
{
|
|
533
|
+
name: 'position',
|
|
534
|
+
type: 'Array',
|
|
535
|
+
value: '[28, -104, 23]'
|
|
536
|
+
}
|
|
537
|
+
]
|
|
538
|
+
});
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
request(options, function (error, response, body) {
|
|
542
|
+
should.not.exist(error);
|
|
543
|
+
done();
|
|
544
|
+
});
|
|
545
|
+
});
|
|
546
|
+
it('should create the attribute with the "_status" prefix in the Context Broker', function (done) {
|
|
547
|
+
let serviceReceived = false;
|
|
548
|
+
iotAgentLib.setCommandHandler(function (id, type, service, subservice, attributes, callback) {
|
|
549
|
+
serviceReceived = service === 'smartgondor';
|
|
550
|
+
callback(null, {
|
|
551
|
+
id,
|
|
552
|
+
type,
|
|
553
|
+
attributes: [
|
|
554
|
+
{
|
|
555
|
+
name: 'position',
|
|
556
|
+
type: 'Array',
|
|
557
|
+
value: '[28, -104, 23]'
|
|
558
|
+
}
|
|
559
|
+
]
|
|
560
|
+
});
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
request(options, function (error, response, body) {
|
|
564
|
+
serviceReceived.should.equal(true);
|
|
565
|
+
done();
|
|
566
|
+
});
|
|
567
|
+
});
|
|
568
|
+
});
|
|
569
|
+
|
|
256
570
|
describe('When an update arrives from the south bound for a registered command', function () {
|
|
257
571
|
beforeEach(function (done) {
|
|
258
572
|
statusAttributeMock = nock('http://192.168.1.1:1026')
|
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
autocast: true,
|
|
37
|
+
contextBroker: {
|
|
38
|
+
host: '192.168.1.1',
|
|
39
|
+
port: '1026',
|
|
40
|
+
ngsiVersion: 'ld',
|
|
41
|
+
jsonLdContext: 'http://context.json-ld'
|
|
42
|
+
},
|
|
43
|
+
server: {
|
|
44
|
+
port: 4041
|
|
45
|
+
},
|
|
46
|
+
types: {
|
|
47
|
+
Light: {
|
|
48
|
+
commands: [],
|
|
49
|
+
type: 'Light',
|
|
50
|
+
active: [
|
|
51
|
+
{
|
|
52
|
+
name: 'name',
|
|
53
|
+
type: 'LanguageProperty'
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
service: 'smartgondor',
|
|
59
|
+
subservice: 'gardens',
|
|
60
|
+
providerUrl: 'http://smartgondor.com'
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
describe('NGSI-LD - LanguageProperty test', function () {
|
|
64
|
+
beforeEach(function () {
|
|
65
|
+
logger.setLevel('FATAL');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
afterEach(function (done) {
|
|
69
|
+
iotAgentLib.deactivate(done);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe(
|
|
73
|
+
'When the IoT Agent receives new exonym from a device name with LanguageProperty type and a JSON object',
|
|
74
|
+
function () {
|
|
75
|
+
const values = [
|
|
76
|
+
{
|
|
77
|
+
name: 'name',
|
|
78
|
+
type: 'LanguageProperty',
|
|
79
|
+
value: {
|
|
80
|
+
el: "Κωνσταντινούπολις",
|
|
81
|
+
en: "Constantinople",
|
|
82
|
+
tr: "İstanbul"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
beforeEach(function (done) {
|
|
88
|
+
nock.cleanAll();
|
|
89
|
+
|
|
90
|
+
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
91
|
+
.matchHeader('fiware-service', 'smartgondor')
|
|
92
|
+
.post(
|
|
93
|
+
'/ngsi-ld/v1/entityOperations/upsert/?options=update',
|
|
94
|
+
utils.readExampleFile(
|
|
95
|
+
'./test/unit/ngsi-ld/examples/contextRequests/updateContextLanguageProperties1.json'
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
.reply(204);
|
|
99
|
+
|
|
100
|
+
iotAgentLib.activate(iotAgentConfig, done);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('should change the value of the corresponding attribute in the context broker', function (done) {
|
|
104
|
+
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
105
|
+
should.not.exist(error);
|
|
106
|
+
contextBrokerMock.done();
|
|
107
|
+
done();
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
});
|
|
@@ -171,7 +171,7 @@ describe('Mixed Mode: ngsiVersion test', function () {
|
|
|
171
171
|
beforeEach(function (done) {
|
|
172
172
|
mongoUtils.cleanDbs(function () {
|
|
173
173
|
iotAgentLib.activate(iotAgentConfig, function () {
|
|
174
|
-
mongo.connect('mongodb://localhost:27017/iotagent',
|
|
174
|
+
mongo.connect('mongodb://localhost:27017/iotagent', function (err, db) {
|
|
175
175
|
iotAgentDb = db;
|
|
176
176
|
done();
|
|
177
177
|
});
|