iotagent-node-lib 2.23.0 → 2.25.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/.github/workflows/ci.yml +6 -7
- package/.nyc_output/33364de2-1199-4ec2-b33c-cae063ef8cc4.json +1 -0
- package/.nyc_output/processinfo/33364de2-1199-4ec2-b33c-cae063ef8cc4.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -1
- package/CHANGES_NEXT_RELEASE +1 -2
- package/doc/advanced-topics.md +78 -3
- package/doc/apiary/iotagent.apib +5 -5
- package/doc/architecture.md +52 -5
- package/doc/deprecated.md +10 -7
- package/doc/expressionLanguage.md +46 -35
- package/doc/getting-started.md +1 -1
- package/doc/usermanual.md +18 -16
- package/examples/TTOpen-service.json +1 -1
- package/lib/errors.js +9 -1
- package/lib/fiware-iotagent-lib.js +2 -1
- package/lib/jexlTranformsMap.js +12 -1
- package/lib/plugins/bidirectionalData.js +104 -6
- package/lib/plugins/expressionPlugin.js +10 -0
- package/lib/plugins/jexlParser.js +2 -2
- package/lib/plugins/pluginUtils.js +2 -1
- package/lib/request-shim.js +2 -1
- package/lib/services/devices/deviceService.js +53 -21
- package/lib/services/devices/devices-NGSI-v2.js +3 -1
- package/lib/services/ngsi/entities-NGSI-v2.js +14 -4
- package/lib/services/northBound/contextServer-NGSI-LD.js +96 -20
- package/lib/services/northBound/contextServer-NGSI-v2.js +1 -0
- package/lib/services/northBound/restUtils.js +3 -5
- package/lib/templates/deviceGroup.json +1 -1
- package/package.json +2 -2
- package/test/unit/examples/deviceProvisioningRequests/provisionNewDeviceEmpty.json +43 -0
- package/test/unit/examples/mongoCollections/configurations.json +3 -3
- package/test/unit/expressions/jexlExpression-test.js +29 -8
- package/test/unit/general/deviceService-test.js +31 -29
- package/test/unit/memoryRegistry/deviceRegistryMemory_test.js +62 -10
- package/test/unit/mongodb/mongodb-group-registry-test.js +24 -0
- package/test/unit/mongodb/mongodb-registry-test.js +68 -10
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin30.json +11 -0
- package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotificationWithDatasetId.json +21 -0
- package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotificationWithMetadata.json +17 -0
- package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +18 -4
- package/test/unit/ngsi-ld/general/deviceService-test.js +31 -29
- package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +656 -2
- package/test/unit/ngsi-ld/ngsiService/unsupported-endpoints-test.js +111 -0
- package/test/unit/ngsi-ld/plugins/bidirectional-plugin_test.js +221 -0
- package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +0 -3
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityJexlExpressionPlugin1.json +22 -0
- package/test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalNotificationWithMetadata.json +19 -0
- package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +21 -6
- package/test/unit/ngsiv2/general/deviceService-test.js +25 -23
- package/test/unit/ngsiv2/lazyAndCommands/command-test.js +106 -0
- package/test/unit/ngsiv2/plugins/bidirectional-plugin_test.js +115 -0
- package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +58 -0
- package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +25 -6
- package/.nyc_output/6e3d7795-bf8c-4a50-bd2f-f8221f27aeae.json +0 -1
- package/.nyc_output/processinfo/6e3d7795-bf8c-4a50-bd2f-f8221f27aeae.json +0 -1
- package/config +0 -0
- package/docker/Mosquitto/Dockerfile.debian +0 -38
- package/docker/Mosquitto/Dockerfile.debian~ +0 -23
- package/lib/plugins/multiEntity.js_avg2 +0 -343
- package/test/unit/ngsiv2/plugins/multientity-plugin_test.js_avg2 +0 -1224
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"devices": [
|
|
3
|
+
{
|
|
4
|
+
"device_id": "",
|
|
5
|
+
"protocol": "GENERIC_PROTO",
|
|
6
|
+
"entity_name": "TheFirstLight",
|
|
7
|
+
"entity_type": "TheLightType",
|
|
8
|
+
"timezone": "America/Santiago",
|
|
9
|
+
"endpoint": "http://fakedEndpoint:1234",
|
|
10
|
+
"transport": "MQTT",
|
|
11
|
+
"attributes": [
|
|
12
|
+
{
|
|
13
|
+
"name": "attr_name",
|
|
14
|
+
"type": "string"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"lazy": [
|
|
18
|
+
{
|
|
19
|
+
"name": "luminance",
|
|
20
|
+
"type": "lumens"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"static_attributes": [
|
|
24
|
+
{
|
|
25
|
+
"name": "hardcodedAttr",
|
|
26
|
+
"type": "hardcodedType",
|
|
27
|
+
"value": "hardcodedValue"
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
"commands": [
|
|
31
|
+
{
|
|
32
|
+
"name": "commandAttr",
|
|
33
|
+
"type": "commandType"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"internal_attributes": [
|
|
37
|
+
{
|
|
38
|
+
"customField": "customValue"
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
{
|
|
3
3
|
"apikey" : "7e5721f478220be21f41f4700e50be2",
|
|
4
4
|
"token" : "e50b7781d5e2d39d577e7c15e4a21f470ed39d5777e7c15e2e2d39d5777e7c1e2",
|
|
5
|
-
"
|
|
5
|
+
"cbHost" : "http://10.0.0.2:1026",
|
|
6
6
|
"entity_type" : "device",
|
|
7
7
|
"resource" : "/iot/d",
|
|
8
8
|
"service" : "smart_gondor",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
{
|
|
12
12
|
"apikey" : "gdb13gq3f8q4beuk263besr8eh9ri",
|
|
13
|
-
"
|
|
13
|
+
"cbHost" : "http://10.0.0.2:1026",
|
|
14
14
|
"entity_type" : "device",
|
|
15
15
|
"resource" : "/iot/d",
|
|
16
16
|
"service" : "dumb_mordor",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
27
|
"apikey" : "hs4h2ke7oerfdvrexbyh54w2",
|
|
28
|
-
"
|
|
28
|
+
"cbHost" : "http://10.0.0.2:1026",
|
|
29
29
|
"entity_type" : "device",
|
|
30
30
|
"resource" : "/iot/d",
|
|
31
31
|
"service" : "demo",
|
|
@@ -234,6 +234,26 @@ describe('Jexl expression interpreter', function () {
|
|
|
234
234
|
});
|
|
235
235
|
});
|
|
236
236
|
|
|
237
|
+
describe('When an concatarr function is used with an array', function () {
|
|
238
|
+
it('should work on the expression value', function (done) {
|
|
239
|
+
expressionParser.parse('array|concatarr(array)', scope, function (error, result) {
|
|
240
|
+
should.not.exist(error);
|
|
241
|
+
result.should.deepEqual([1, 2, 1, 2]);
|
|
242
|
+
done();
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
describe('When an joinarrtostr function is used with an array', function () {
|
|
248
|
+
it('should work on the expression value', function (done) {
|
|
249
|
+
expressionParser.parse('array|joinarrtostr("_")', scope, function (error, result) {
|
|
250
|
+
should.not.exist(error);
|
|
251
|
+
result.should.equal('1_2');
|
|
252
|
+
done();
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
|
|
237
257
|
describe('When a function is applied to an array', function () {
|
|
238
258
|
it('should work on the expression value', function (done) {
|
|
239
259
|
expressionParser.parse('array[1]+1', scope, function (error, result) {
|
|
@@ -313,14 +333,15 @@ describe('Jexl expression interpreter', function () {
|
|
|
313
333
|
|
|
314
334
|
describe('When a JSON parse transformation is applied', function () {
|
|
315
335
|
it('should work on the expression value', function (done) {
|
|
316
|
-
expressionParser.parse(
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
336
|
+
expressionParser.parse(
|
|
337
|
+
'"{\\"name\\":\\"John\\",\\"surname\\":\\"Doe\\"}"|jsonparse',
|
|
338
|
+
scope,
|
|
339
|
+
function (error, result) {
|
|
340
|
+
should.not.exist(error);
|
|
341
|
+
result.should.eql(scope.object);
|
|
342
|
+
done();
|
|
343
|
+
}
|
|
344
|
+
);
|
|
324
345
|
});
|
|
325
346
|
});
|
|
326
347
|
|
|
@@ -134,7 +134,7 @@ const groupCreation = {
|
|
|
134
134
|
apikey: '801230BJKL23Y9090DSFL123HJK09H324HV8732',
|
|
135
135
|
entity_type: 'TheLightType',
|
|
136
136
|
trust: '8970A9078A803H3BL98PINEQRW8342HBAMS',
|
|
137
|
-
cbHost: 'http://
|
|
137
|
+
cbHost: 'http://192.168.1.1:1026',
|
|
138
138
|
commands: [],
|
|
139
139
|
lazy: [],
|
|
140
140
|
attributes: [
|
|
@@ -181,7 +181,7 @@ describe('NGSI-v2 - Device Service: utils', function () {
|
|
|
181
181
|
|
|
182
182
|
describe('When an existing device tries to be retrieved with retrieveOrCreate()', function () {
|
|
183
183
|
beforeEach(function (done) {
|
|
184
|
-
contextBrokerMock = nock('http://
|
|
184
|
+
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
185
185
|
.matchHeader('fiware-service', 'testservice')
|
|
186
186
|
.matchHeader('fiware-servicepath', '/testingPath')
|
|
187
187
|
.post('/v2/registrations')
|
|
@@ -193,12 +193,12 @@ describe('NGSI-v2 - Device Service: utils', function () {
|
|
|
193
193
|
.post('/v2/entities?options=upsert')
|
|
194
194
|
.reply(204);
|
|
195
195
|
|
|
196
|
-
async.series(
|
|
197
|
-
|
|
198
|
-
results
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
196
|
+
async.series(
|
|
197
|
+
[request.bind(request, groupCreation), request.bind(request, deviceCreation)],
|
|
198
|
+
function (error, results) {
|
|
199
|
+
done();
|
|
200
|
+
}
|
|
201
|
+
);
|
|
202
202
|
});
|
|
203
203
|
|
|
204
204
|
it('should return the existing device', function (done) {
|
|
@@ -214,7 +214,7 @@ describe('NGSI-v2 - Device Service: utils', function () {
|
|
|
214
214
|
|
|
215
215
|
describe('When an unexisting device tries to be retrieved for an existing APIKey', function () {
|
|
216
216
|
beforeEach(function (done) {
|
|
217
|
-
contextBrokerMock = nock('http://
|
|
217
|
+
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
218
218
|
.matchHeader('fiware-service', 'testservice')
|
|
219
219
|
.matchHeader('fiware-servicepath', '/testingPath')
|
|
220
220
|
.post('/v2/registrations')
|
|
@@ -232,32 +232,34 @@ describe('NGSI-v2 - Device Service: utils', function () {
|
|
|
232
232
|
});
|
|
233
233
|
|
|
234
234
|
it('should register the device and return it', function (done) {
|
|
235
|
-
iotAgentLib.retrieveDevice(
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
235
|
+
iotAgentLib.retrieveDevice(
|
|
236
|
+
'UNEXISTENT_DEV',
|
|
237
|
+
'801230BJKL23Y9090DSFL123HJK09H324HV8732',
|
|
238
|
+
function (error, device) {
|
|
239
|
+
should.not.exist(error);
|
|
240
|
+
should.exist(device);
|
|
241
241
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
242
|
+
device.id.should.equal('UNEXISTENT_DEV');
|
|
243
|
+
should.exist(device.protocol);
|
|
244
|
+
device.protocol.should.equal('MQTT_UL');
|
|
245
|
+
done();
|
|
246
|
+
}
|
|
247
|
+
);
|
|
247
248
|
});
|
|
248
249
|
});
|
|
249
250
|
|
|
250
251
|
describe('When an unexisting device tries to be retrieved for an unexisting APIKey', function () {
|
|
251
252
|
it('should raise an error', function (done) {
|
|
252
|
-
iotAgentLib.retrieveDevice(
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
253
|
+
iotAgentLib.retrieveDevice(
|
|
254
|
+
'UNEXISTENT_DEV_AND_GROUP',
|
|
255
|
+
'H2332Y909DSF3H346yh20JK092',
|
|
256
|
+
function (error, device) {
|
|
257
|
+
should.exist(error);
|
|
258
|
+
error.name.should.equal('DEVICE_GROUP_NOT_FOUND');
|
|
259
|
+
should.not.exist(device);
|
|
260
|
+
done();
|
|
261
|
+
}
|
|
262
|
+
);
|
|
261
263
|
});
|
|
262
264
|
});
|
|
263
265
|
});
|
|
@@ -96,16 +96,19 @@ describe('NGSI-v2 - In memory device registry', function () {
|
|
|
96
96
|
iotAgentLib.clearRegistry(done);
|
|
97
97
|
});
|
|
98
98
|
it('should return the appropriate device', function (done) {
|
|
99
|
-
iotAgentLib.getDevicesByAttribute(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
99
|
+
iotAgentLib.getDevicesByAttribute(
|
|
100
|
+
'internalId',
|
|
101
|
+
'internal3',
|
|
102
|
+
'smartgondor',
|
|
103
|
+
'gardens',
|
|
104
|
+
function (error, devices) {
|
|
105
|
+
should.not.exist(error);
|
|
106
|
+
should.exist(devices);
|
|
107
|
+
devices.length.should.equal(1);
|
|
108
|
+
devices[0].id.should.equal('id3');
|
|
109
|
+
done();
|
|
110
|
+
}
|
|
111
|
+
);
|
|
109
112
|
});
|
|
110
113
|
});
|
|
111
114
|
|
|
@@ -194,4 +197,53 @@ describe('NGSI-v2 - In memory device registry', function () {
|
|
|
194
197
|
});
|
|
195
198
|
});
|
|
196
199
|
});
|
|
200
|
+
|
|
201
|
+
describe('When a the registry is queried for device in a particular name and type', function () {
|
|
202
|
+
beforeEach(function (done) {
|
|
203
|
+
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
204
|
+
.post('/v2/entities?options=upsert')
|
|
205
|
+
.times(10)
|
|
206
|
+
.reply(204);
|
|
207
|
+
|
|
208
|
+
const devices = [];
|
|
209
|
+
|
|
210
|
+
for (let i = 0; i < 10; i++) {
|
|
211
|
+
devices.push({
|
|
212
|
+
id: 'id' + i,
|
|
213
|
+
name: 'name' + i,
|
|
214
|
+
type: 'Light' + i,
|
|
215
|
+
internalId: 'internal' + i,
|
|
216
|
+
service: 'smartgondor',
|
|
217
|
+
subservice: 'gardens',
|
|
218
|
+
active: [
|
|
219
|
+
{
|
|
220
|
+
id: 'attrId',
|
|
221
|
+
type: 'attrType' + i,
|
|
222
|
+
value: i
|
|
223
|
+
}
|
|
224
|
+
]
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async.map(devices, iotAgentLib.register, function (error, results) {
|
|
229
|
+
done();
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
afterEach(function (done) {
|
|
234
|
+
iotAgentLib.clearRegistry(done);
|
|
235
|
+
});
|
|
236
|
+
it('should return the name and type of device', function (done) {
|
|
237
|
+
iotAgentLib.getDeviceByNameAndType('name5', 'Light5', 'smartgondor', 'gardens', function (error, device) {
|
|
238
|
+
should.not.exist(error);
|
|
239
|
+
should.exist(device);
|
|
240
|
+
should.exist(device.name);
|
|
241
|
+
should.exist(device.type);
|
|
242
|
+
device.name.should.equal('name5');
|
|
243
|
+
device.type.should.equal('Light5');
|
|
244
|
+
Object.keys(device).length.should.equal(11);
|
|
245
|
+
done();
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
});
|
|
197
249
|
});
|
|
@@ -448,4 +448,28 @@ describe('MongoDB Group Registry test', function () {
|
|
|
448
448
|
});
|
|
449
449
|
});
|
|
450
450
|
});
|
|
451
|
+
|
|
452
|
+
describe('When the device info request with name and type', function () {
|
|
453
|
+
beforeEach(function (done) {
|
|
454
|
+
async.series([async.apply(request, optionsCreation)], done);
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
afterEach(function (done) {
|
|
458
|
+
iotAgentLib.clearRegistry(done);
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
it('should return the name and type of device', function (done) {
|
|
462
|
+
request(optionsGet, function (error, response, body) {
|
|
463
|
+
should.exist(body);
|
|
464
|
+
should.exist(body.count);
|
|
465
|
+
body.count.should.equal(1);
|
|
466
|
+
should.exist(body.services);
|
|
467
|
+
should.exist(body.services.length);
|
|
468
|
+
body.services.length.should.equal(1);
|
|
469
|
+
should.exist(body.services[0].entity_type);
|
|
470
|
+
body.services[0].entity_type.should.equal('Light');
|
|
471
|
+
done();
|
|
472
|
+
});
|
|
473
|
+
});
|
|
474
|
+
});
|
|
451
475
|
});
|
|
@@ -440,16 +440,19 @@ describe('NGSI-v2 - MongoDB Device Registry', function () {
|
|
|
440
440
|
iotAgentLib.clearRegistry(done);
|
|
441
441
|
});
|
|
442
442
|
it('should return the appropriate device', function (done) {
|
|
443
|
-
iotAgentLib.getDevicesByAttribute(
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
443
|
+
iotAgentLib.getDevicesByAttribute(
|
|
444
|
+
'internalId',
|
|
445
|
+
'internal3',
|
|
446
|
+
'smartgondor',
|
|
447
|
+
'gardens',
|
|
448
|
+
function (error, devices) {
|
|
449
|
+
should.not.exist(error);
|
|
450
|
+
should.exist(devices);
|
|
451
|
+
devices.length.should.equal(1);
|
|
452
|
+
devices[0].id.should.equal('id3');
|
|
453
|
+
done();
|
|
454
|
+
}
|
|
455
|
+
);
|
|
453
456
|
});
|
|
454
457
|
});
|
|
455
458
|
|
|
@@ -507,4 +510,59 @@ describe('NGSI-v2 - MongoDB Device Registry', function () {
|
|
|
507
510
|
});
|
|
508
511
|
});
|
|
509
512
|
});
|
|
513
|
+
|
|
514
|
+
describe('When the device is queried with the name and type', function () {
|
|
515
|
+
beforeEach(function (done) {
|
|
516
|
+
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
517
|
+
.post('/v2/entities?options=upsert')
|
|
518
|
+
.times(10)
|
|
519
|
+
.matchHeader('fiware-service', 'smartgondor')
|
|
520
|
+
.matchHeader('fiware-servicepath', 'gardens')
|
|
521
|
+
.reply(204);
|
|
522
|
+
|
|
523
|
+
const devices = [];
|
|
524
|
+
|
|
525
|
+
for (let i = 0; i < 10; i++) {
|
|
526
|
+
devices.push({
|
|
527
|
+
id: 'id' + i,
|
|
528
|
+
type: 'Light' + i,
|
|
529
|
+
internalId: 'internal' + i,
|
|
530
|
+
service: 'smartgondor',
|
|
531
|
+
subservice: 'gardens',
|
|
532
|
+
active: [
|
|
533
|
+
{
|
|
534
|
+
id: 'attrId',
|
|
535
|
+
type: 'attrType' + i,
|
|
536
|
+
value: i
|
|
537
|
+
}
|
|
538
|
+
]
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
iotAgentLib.activate(iotAgentConfig, function (error) {
|
|
542
|
+
async.map(devices, iotAgentLib.register, function (error, results) {
|
|
543
|
+
done();
|
|
544
|
+
});
|
|
545
|
+
});
|
|
546
|
+
});
|
|
547
|
+
afterEach(function (done) {
|
|
548
|
+
iotAgentLib.clearRegistry(done);
|
|
549
|
+
});
|
|
550
|
+
it('should return the device with name and type', function (done) {
|
|
551
|
+
iotAgentLib.getDeviceByNameAndType(
|
|
552
|
+
'Light4:id4',
|
|
553
|
+
'Light4',
|
|
554
|
+
'smartgondor',
|
|
555
|
+
'gardens',
|
|
556
|
+
function (error, device) {
|
|
557
|
+
should.not.exist(error);
|
|
558
|
+
should.exist(device);
|
|
559
|
+
should.exist(device.name);
|
|
560
|
+
should.exist(device.type);
|
|
561
|
+
device.name.should.equal('Light4:id4');
|
|
562
|
+
device.type.should.equal('Light4');
|
|
563
|
+
done();
|
|
564
|
+
}
|
|
565
|
+
);
|
|
566
|
+
});
|
|
567
|
+
});
|
|
510
568
|
});
|
package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotificationWithDatasetId.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"data": [
|
|
3
|
+
{
|
|
4
|
+
"id": "TheFirstLight",
|
|
5
|
+
"location": [
|
|
6
|
+
{
|
|
7
|
+
"type": "GeoProperty",
|
|
8
|
+
"value": "12.4, -9.6",
|
|
9
|
+
"datasetId": "urn:ngsi-ld:Property:do-this"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"type": "GeoProperty",
|
|
13
|
+
"value": "6, 10",
|
|
14
|
+
"datasetId": "urn:ngsi-ld:Property:then-do-this"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"type": "TheLightType"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"subscriptionId": "51c0ac9ed714fb3b37d7d5a8"
|
|
21
|
+
}
|
package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotificationWithMetadata.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"data": [
|
|
3
|
+
{
|
|
4
|
+
"id": "TheFirstLight",
|
|
5
|
+
"location": {
|
|
6
|
+
"type": "GeoProperty",
|
|
7
|
+
"value": "12.4, -9.6",
|
|
8
|
+
"qos": {
|
|
9
|
+
"type": "Property",
|
|
10
|
+
"value": 1
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"type": "TheLightType"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"subscriptionId": "51c0ac9ed714fb3b37d7d5a8"
|
|
17
|
+
}
|
|
@@ -321,11 +321,25 @@ describe('NGSI-LD: JEXL', function () {
|
|
|
321
321
|
}
|
|
322
322
|
];
|
|
323
323
|
|
|
324
|
-
|
|
324
|
+
beforeEach(function () {
|
|
325
|
+
nock.cleanAll();
|
|
326
|
+
|
|
327
|
+
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
328
|
+
.matchHeader('fiware-service', 'smartgondor')
|
|
329
|
+
.matchHeader('fiware-servicepath', 'gardens')
|
|
330
|
+
.post(
|
|
331
|
+
'/ngsi-ld/v1/entityOperations/upsert/?options=update',
|
|
332
|
+
utils.readExampleFile(
|
|
333
|
+
'./test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin30.json'
|
|
334
|
+
)
|
|
335
|
+
)
|
|
336
|
+
.reply(204);
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it('should ignore the expression before sending the values', function (done) {
|
|
325
340
|
iotAgentLib.update('light1', 'LightError', '', values, function (error) {
|
|
326
|
-
should.exist(error);
|
|
327
|
-
|
|
328
|
-
error.code.should.equal(400);
|
|
341
|
+
should.not.exist(error);
|
|
342
|
+
contextBrokerMock.done();
|
|
329
343
|
done();
|
|
330
344
|
});
|
|
331
345
|
});
|
|
@@ -137,7 +137,7 @@ const groupCreation = {
|
|
|
137
137
|
apikey: '801230BJKL23Y9090DSFL123HJK09H324HV8732',
|
|
138
138
|
entity_type: 'TheLightType',
|
|
139
139
|
trust: '8970A9078A803H3BL98PINEQRW8342HBAMS',
|
|
140
|
-
cbHost: 'http://
|
|
140
|
+
cbHost: 'http://192.168.1.1:1026',
|
|
141
141
|
commands: [],
|
|
142
142
|
lazy: [],
|
|
143
143
|
attributes: [
|
|
@@ -187,17 +187,17 @@ describe('NGSI-LD - Device Service: utils', function () {
|
|
|
187
187
|
// This mock does not check the payload since the aim of the test is not to verify
|
|
188
188
|
// device provisioning functionality. Appropriate verification is done in tests under
|
|
189
189
|
// provisioning folder
|
|
190
|
-
contextBrokerMock = nock('http://
|
|
190
|
+
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
191
191
|
.matchHeader('fiware-service', 'testservice')
|
|
192
192
|
.post('/ngsi-ld/v1/entityOperations/upsert/')
|
|
193
193
|
.reply(204);
|
|
194
194
|
|
|
195
|
-
async.series(
|
|
196
|
-
|
|
197
|
-
results
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
195
|
+
async.series(
|
|
196
|
+
[request.bind(request, groupCreation), request.bind(request, deviceCreation)],
|
|
197
|
+
function (error, results) {
|
|
198
|
+
done();
|
|
199
|
+
}
|
|
200
|
+
);
|
|
201
201
|
});
|
|
202
202
|
|
|
203
203
|
it('should return the existing device', function (done) {
|
|
@@ -216,7 +216,7 @@ describe('NGSI-LD - Device Service: utils', function () {
|
|
|
216
216
|
// This mock does not check the payload since the aim of the test is not to verify
|
|
217
217
|
// device provisioning functionality. Appropriate verification is done in tests under
|
|
218
218
|
// provisioning folder
|
|
219
|
-
contextBrokerMock = nock('http://
|
|
219
|
+
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
220
220
|
.matchHeader('fiware-service', 'testservice')
|
|
221
221
|
.post('/ngsi-ld/v1/entityOperations/upsert/')
|
|
222
222
|
.reply(204);
|
|
@@ -227,32 +227,34 @@ describe('NGSI-LD - Device Service: utils', function () {
|
|
|
227
227
|
});
|
|
228
228
|
|
|
229
229
|
it('should register the device and return it', function (done) {
|
|
230
|
-
iotAgentLib.retrieveDevice(
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
230
|
+
iotAgentLib.retrieveDevice(
|
|
231
|
+
'UNEXISTENT_DEV',
|
|
232
|
+
'801230BJKL23Y9090DSFL123HJK09H324HV8732',
|
|
233
|
+
function (error, device) {
|
|
234
|
+
should.not.exist(error);
|
|
235
|
+
should.exist(device);
|
|
236
236
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
237
|
+
device.id.should.equal('UNEXISTENT_DEV');
|
|
238
|
+
should.exist(device.protocol);
|
|
239
|
+
device.protocol.should.equal('MQTT_UL');
|
|
240
|
+
done();
|
|
241
|
+
}
|
|
242
|
+
);
|
|
242
243
|
});
|
|
243
244
|
});
|
|
244
245
|
|
|
245
246
|
describe('When an unexisting device tries to be retrieved for an unexisting APIKey', function () {
|
|
246
247
|
it('should raise an error', function (done) {
|
|
247
|
-
iotAgentLib.retrieveDevice(
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
248
|
+
iotAgentLib.retrieveDevice(
|
|
249
|
+
'UNEXISTENT_DEV_AND_GROUP',
|
|
250
|
+
'H2332Y909DSF3H346yh20JK092',
|
|
251
|
+
function (error, device) {
|
|
252
|
+
should.exist(error);
|
|
253
|
+
error.name.should.equal('DEVICE_GROUP_NOT_FOUND');
|
|
254
|
+
should.not.exist(device);
|
|
255
|
+
done();
|
|
256
|
+
}
|
|
257
|
+
);
|
|
256
258
|
});
|
|
257
259
|
});
|
|
258
260
|
});
|