iotagent-node-lib 4.8.0 → 4.10.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 +10 -9
- package/.nyc_output/e4b1fe20-197e-4221-9f8d-6db65ff234b2.json +1 -0
- package/.nyc_output/processinfo/e4b1fe20-197e-4221-9f8d-6db65ff234b2.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -0
- package/Changelog +791 -0
- package/config.js +2 -1
- package/doc/admin.md +20 -4
- package/doc/api.md +34 -4
- package/doc/devel/northboundinteractions.md +200 -112
- package/lib/commonConfig.js +16 -3
- package/lib/model/Device.js +3 -1
- package/lib/model/Group.js +2 -1
- package/lib/services/common/domain.js +4 -3
- package/lib/services/common/iotManagerService.js +2 -1
- package/lib/services/devices/deviceRegistryMongoDB.js +5 -1
- package/lib/services/devices/deviceService.js +17 -1
- package/lib/services/devices/devices-NGSI-LD.js +4 -4
- package/lib/services/devices/devices-NGSI-mixed.js +16 -0
- package/lib/services/devices/devices-NGSI-v2.js +123 -10
- package/lib/services/devices/registrationUtils.js +97 -30
- package/lib/services/groups/groupRegistryMongoDB.js +2 -1
- package/lib/services/ngsi/entities-NGSI-LD.js +69 -13
- package/lib/services/ngsi/ngsiService.js +3 -1
- package/lib/services/ngsi/subscription-NGSI-LD.js +2 -2
- package/lib/services/ngsi/subscription-NGSI-mixed.js +3 -3
- package/lib/services/ngsi/subscription-NGSI-v2.js +20 -6
- package/lib/services/ngsi/subscriptionService.js +2 -2
- package/lib/services/northBound/contextServer-NGSI-LD.js +5 -3
- package/lib/services/northBound/deviceProvisioningServer.js +6 -3
- package/lib/services/northBound/northboundServer.js +1 -1
- package/lib/services/northBound/restUtils.js +6 -2
- package/lib/templates/updateDevice.json +12 -0
- package/lib/templates/updateDeviceLax.json +4 -0
- package/package.json +2 -2
- package/test/functional/config-test.js +1 -1
- package/test/unit/general/contextBrokerKeystoneSecurityAccess-test.js +2 -2
- package/test/unit/memoryRegistry/deviceRegistryMemory_test.js +1 -1
- package/test/unit/ngsi-ld/examples/contextRequests/createDatetimeProvisionedDevice.json +1 -4
- package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDevice.json +3 -12
- package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceMultientity.json +3 -12
- package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic.json +6 -24
- package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic2.json +1 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContext1.json +1 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContext3WithStatic.json +1 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContext4.json +1 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContext5.json +1 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin6.json +1 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin7.json +1 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin8.json +4 -2
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin9.json +1 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextCommandError.json +3 -9
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextCommandExpired.json +13 -19
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextCommandFinish.json +13 -19
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextCommandStatus1.json +4 -9
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextCompressTimestamp1.json +1 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextCompressTimestamp2.json +1 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin1a.json +1 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin2.json +2 -8
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin29.json +1 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin4.json +2 -8
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin4a.json +3 -12
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin6.json +3 -5
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin7.json +1 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin8a.json +1 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextJsonProperty.json +13 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextListProperty.json +14 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextListRelationship.json +14 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin1.json +2 -8
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin2.json +2 -8
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin3.json +3 -8
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin4.json +1 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin5.json +2 -8
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin8.json +2 -8
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +2 -8
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +1 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin3.json +1 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin4.json +2 -8
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextRelationship.json +11 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextValueType1.json +51 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextValueType2.json +65 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextVocabProperty.json +11 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionCommands1.json +2 -8
- package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionDeviceStatic.json +1 -4
- package/test/unit/ngsi-ld/general/contextBrokerOAuthSecurityAccess-test.js +2 -2
- package/test/unit/ngsi-ld/general/https-support-test.js +1 -1
- package/test/unit/ngsi-ld/general/startup-test.js +3 -0
- package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +1 -1
- package/test/unit/ngsi-ld/lazyAndCommands/lazy-devices-test.js +71 -1
- package/test/unit/ngsi-ld/ngsiService/attributeTypes-test.js +293 -0
- package/test/unit/ngsi-ld/ngsiService/subscriptions-test.js +6 -6
- package/test/unit/ngsi-ld/ngsiService/unsupported-endpoints-test.js +0 -10
- package/test/unit/ngsi-ld/ngsiService/value-types-test.js +221 -0
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/subscribeIoTAgentCommands.json +24 -0
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/subscribeIoTAgentCommands2.json +24 -0
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/subscribeIoTAgentCommands3.json +24 -0
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/subscribeIoTAgentCommands4.json +24 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateEntity.json +5 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateEntity2.json +5 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateEntity2b.json +7 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateEntity3.json +5 -0
- package/test/unit/ngsiv2/examples/subscriptionRequests/simpleSubscriptionRequest.json +4 -2
- package/test/unit/ngsiv2/examples/subscriptionRequests/simpleSubscriptionRequest2.json +4 -2
- package/test/unit/ngsiv2/general/contextBrokerOAuthSecurityAccess-test.js +2 -2
- package/test/unit/ngsiv2/general/https-support-test.js +1 -1
- package/test/unit/ngsiv2/lazyAndCommands/command-test.js +245 -2
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast1.json +0 -11
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast10.json +0 -14
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast2.json +0 -11
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast3.json +0 -11
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast4.json +0 -11
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast5.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast6.json +0 -17
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast7.json +0 -19
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast8.json +0 -14
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast9.json +0 -14
- package/test/unit/ngsi-ld/ngsiService/languageProperties-test.js +0 -109
- package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast1.json +0 -8
- package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast2.json +0 -8
- package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast3.json +0 -8
- package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast4.json +0 -8
- package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast5.json +0 -8
- package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast6.json +0 -8
- package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast7.json +0 -8
- /package/test/unit/ngsi-ld/examples/contextRequests/{updateContextLanguageProperties1.json → updateContextLanguageProperty.json} +0 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"@context": "http://context.json-ld",
|
|
4
|
+
"id": "urn:ngsi-ld:Light:ws1",
|
|
5
|
+
"type": "Light",
|
|
6
|
+
"consumption": {
|
|
7
|
+
"type": "Property",
|
|
8
|
+
"value": 1,
|
|
9
|
+
"valueType": "Number"
|
|
10
|
+
},
|
|
11
|
+
"alive": {
|
|
12
|
+
"type": "Property",
|
|
13
|
+
"value": "foo"
|
|
14
|
+
},
|
|
15
|
+
"updated": {
|
|
16
|
+
"type": "Property",
|
|
17
|
+
"value": false,
|
|
18
|
+
"valueType": "Boolean"
|
|
19
|
+
},
|
|
20
|
+
"manufacturer": {
|
|
21
|
+
"type": "Property",
|
|
22
|
+
"value": {
|
|
23
|
+
"hello": "world"
|
|
24
|
+
},
|
|
25
|
+
"valueType": "Object"
|
|
26
|
+
},
|
|
27
|
+
"revisions": {
|
|
28
|
+
"type": "Property",
|
|
29
|
+
"value": [
|
|
30
|
+
1,
|
|
31
|
+
2
|
|
32
|
+
],
|
|
33
|
+
"valueType": "Array"
|
|
34
|
+
},
|
|
35
|
+
"date": {
|
|
36
|
+
"type": "Property",
|
|
37
|
+
"value": "2025-07-18",
|
|
38
|
+
"valueType": "Date"
|
|
39
|
+
},
|
|
40
|
+
"time": {
|
|
41
|
+
"type": "Property",
|
|
42
|
+
"value": "14:22:11",
|
|
43
|
+
"valueType": "Time"
|
|
44
|
+
},
|
|
45
|
+
"datetime": {
|
|
46
|
+
"type": "Property",
|
|
47
|
+
"value": "2025-07-18T14:22:11.000Z",
|
|
48
|
+
"valueType": "DateTime"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
]
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"@context": "http://context.json-ld",
|
|
4
|
+
"id": "urn:ngsi-ld:Light:ws1",
|
|
5
|
+
"type": "Light",
|
|
6
|
+
"consumption": {
|
|
7
|
+
"type": "Property",
|
|
8
|
+
"value": {
|
|
9
|
+
"@type": "Number",
|
|
10
|
+
"@value": 1
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"alive": {
|
|
14
|
+
"type": "Property",
|
|
15
|
+
"value": "foo"
|
|
16
|
+
},
|
|
17
|
+
"updated": {
|
|
18
|
+
"type": "Property",
|
|
19
|
+
"value": {
|
|
20
|
+
"@type": "Boolean",
|
|
21
|
+
"@value": false
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"manufacturer": {
|
|
25
|
+
"type": "Property",
|
|
26
|
+
"value": {
|
|
27
|
+
"@type": "Object",
|
|
28
|
+
"@value": {
|
|
29
|
+
"hello": "world"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"revisions": {
|
|
34
|
+
"type": "Property",
|
|
35
|
+
"value": {
|
|
36
|
+
"@type": "Array",
|
|
37
|
+
"@value": [
|
|
38
|
+
1,
|
|
39
|
+
2
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"date": {
|
|
44
|
+
"type": "Property",
|
|
45
|
+
"value": {
|
|
46
|
+
"@type": "Date",
|
|
47
|
+
"@value": "2025-07-18"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"time": {
|
|
51
|
+
"type": "Property",
|
|
52
|
+
"value": {
|
|
53
|
+
"@type": "Time",
|
|
54
|
+
"@value": "14:22:11"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"datetime": {
|
|
58
|
+
"type": "Property",
|
|
59
|
+
"value": {
|
|
60
|
+
"@type": "DateTime",
|
|
61
|
+
"@value": "2025-07-18T14:22:11.000Z"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
]
|
|
@@ -4,17 +4,11 @@
|
|
|
4
4
|
"id": "urn:ngsi-ld:Light:light1",
|
|
5
5
|
"move_info": {
|
|
6
6
|
"type": "Property",
|
|
7
|
-
"value":
|
|
8
|
-
"@type": "commandResult",
|
|
9
|
-
"@value": " "
|
|
10
|
-
}
|
|
7
|
+
"value": " "
|
|
11
8
|
},
|
|
12
9
|
"move_status": {
|
|
13
10
|
"type": "Property",
|
|
14
|
-
"value":
|
|
15
|
-
"@type": "commandStatus",
|
|
16
|
-
"@value": "UNKNOWN"
|
|
17
|
-
}
|
|
11
|
+
"value": "UNKNOWN"
|
|
18
12
|
},
|
|
19
13
|
"type": "Light"
|
|
20
14
|
}
|
|
@@ -309,7 +309,7 @@ describe('NGSI-LD - Secured access to the Context Broker with OAuth2 provider',
|
|
|
309
309
|
|
|
310
310
|
it('subscribe requests use auth header', function (done) {
|
|
311
311
|
iotAgentLib.getDevice('Light1', null, 'smartgondor', 'electricity', function (error, device) {
|
|
312
|
-
iotAgentLib.subscribe(device, ['dimming'], null, function (error) {
|
|
312
|
+
iotAgentLib.subscribe(device, ['dimming'], null, 'normalized', function (error) {
|
|
313
313
|
should.not.exist(error);
|
|
314
314
|
|
|
315
315
|
contextBrokerMock.done();
|
|
@@ -330,7 +330,7 @@ describe('NGSI-LD - Secured access to the Context Broker with OAuth2 provider',
|
|
|
330
330
|
contextBrokerMock.delete('/ngsi-ld/v1/subscriptions/51c0ac9ed714fb3b37d7d5a8', '').reply(204);
|
|
331
331
|
|
|
332
332
|
iotAgentLib.getDevice('Light1', null, 'smartgondor', 'electricity', function (error, device) {
|
|
333
|
-
iotAgentLib.subscribe(device, ['dimming'], null, function (error) {
|
|
333
|
+
iotAgentLib.subscribe(device, ['dimming'], null, 'normalized', function (error) {
|
|
334
334
|
iotAgentLib.unsubscribe(device, '51c0ac9ed714fb3b37d7d5a8', function (error) {
|
|
335
335
|
contextBrokerMock.done();
|
|
336
336
|
done();
|
|
@@ -214,7 +214,7 @@ describe('NGSI-LD - HTTPS support tests', function () {
|
|
|
214
214
|
|
|
215
215
|
it('should send the appropriate request to the Context Broker', function (done) {
|
|
216
216
|
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
217
|
-
iotAgentLib.subscribe(device, ['attr_name'], null, function (error) {
|
|
217
|
+
iotAgentLib.subscribe(device, ['attr_name'], null, 'normalized', function (error) {
|
|
218
218
|
should.not.exist(error);
|
|
219
219
|
|
|
220
220
|
contextBrokerMock.done();
|
|
@@ -89,6 +89,7 @@ describe('NGSI-LD - Startup tests', function () {
|
|
|
89
89
|
process.env.IOTA_FALLBACK_PATH = 'smartgondor';
|
|
90
90
|
process.env.IOTA_LD_SUPPORT_NULL = 'false';
|
|
91
91
|
process.env.IOTA_LD_SUPPORT_DATASET_ID = 'false';
|
|
92
|
+
process.env.IOTA_LD_SUPPORT_DATA_TYPE = 'valueType';
|
|
92
93
|
|
|
93
94
|
nock.cleanAll();
|
|
94
95
|
|
|
@@ -125,6 +126,7 @@ describe('NGSI-LD - Startup tests', function () {
|
|
|
125
126
|
delete process.env.IOTA_FALLBACK_PATH;
|
|
126
127
|
delete process.env.IOTA_LD_SUPPORT_NULL;
|
|
127
128
|
delete process.env.IOTA_LD_SUPPORT_DATASET_ID;
|
|
129
|
+
delete process.env.IOTA_LD_SUPPORT_DATA_TYPE;
|
|
128
130
|
});
|
|
129
131
|
|
|
130
132
|
afterEach(function (done) {
|
|
@@ -155,6 +157,7 @@ describe('NGSI-LD - Startup tests', function () {
|
|
|
155
157
|
config.getConfig().mongodb.port.should.equal('5555');
|
|
156
158
|
config.getConfig().mongodb.db.should.equal('themongodb');
|
|
157
159
|
config.getConfig().mongodb.replicaSet.should.equal('customReplica');
|
|
160
|
+
config.getConfig().server.ldSupport.dataType.should.equal('valueType');
|
|
158
161
|
done();
|
|
159
162
|
});
|
|
160
163
|
});
|
|
@@ -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',
|
|
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
|
+
});
|
|
@@ -94,7 +94,7 @@ describe('NGSI-LD - Subscription tests', function () {
|
|
|
94
94
|
describe('When a client invokes the subscribe() function for device', function () {
|
|
95
95
|
it('should send the appropriate request to the Context Broker', function (done) {
|
|
96
96
|
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
97
|
-
iotAgentLib.subscribe(device, ['attr_name'], null, function (error) {
|
|
97
|
+
iotAgentLib.subscribe(device, ['attr_name'], null, 'normalized', function (error) {
|
|
98
98
|
should.not.exist(error);
|
|
99
99
|
|
|
100
100
|
contextBrokerMock.done();
|
|
@@ -105,7 +105,7 @@ describe('NGSI-LD - Subscription tests', function () {
|
|
|
105
105
|
});
|
|
106
106
|
it('should store the subscription ID in the Device Registry', function (done) {
|
|
107
107
|
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
108
|
-
iotAgentLib.subscribe(device, ['attr_name'], null, function (error) {
|
|
108
|
+
iotAgentLib.subscribe(device, ['attr_name'], null, 'normalized', function (error) {
|
|
109
109
|
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
110
110
|
should.not.exist(error);
|
|
111
111
|
should.exist(device);
|
|
@@ -131,7 +131,7 @@ describe('NGSI-LD - Subscription tests', function () {
|
|
|
131
131
|
|
|
132
132
|
it('should delete the subscription from the CB', function (done) {
|
|
133
133
|
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
134
|
-
iotAgentLib.subscribe(device, ['attr_name'], null, function (error) {
|
|
134
|
+
iotAgentLib.subscribe(device, ['attr_name'], null, 'normalized', function (error) {
|
|
135
135
|
iotAgentLib.unsubscribe(device, '51c0ac9ed714fb3b37d7d5a8', function (error) {
|
|
136
136
|
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
137
137
|
contextBrokerMock.done();
|
|
@@ -143,7 +143,7 @@ describe('NGSI-LD - Subscription tests', function () {
|
|
|
143
143
|
});
|
|
144
144
|
it('should remove the id from the subscriptions array', function (done) {
|
|
145
145
|
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
146
|
-
iotAgentLib.subscribe(device, ['attr_name'], null, function (error) {
|
|
146
|
+
iotAgentLib.subscribe(device, ['attr_name'], null, 'normalized', function (error) {
|
|
147
147
|
iotAgentLib.unsubscribe(device, '51c0ac9ed714fb3b37d7d5a8', function (error) {
|
|
148
148
|
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
149
149
|
should.not.exist(error);
|
|
@@ -169,7 +169,7 @@ describe('NGSI-LD - Subscription tests', function () {
|
|
|
169
169
|
|
|
170
170
|
it('should delete the subscription from the CB', function (done) {
|
|
171
171
|
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
172
|
-
iotAgentLib.subscribe(device, ['attr_name'], null, function (error) {
|
|
172
|
+
iotAgentLib.subscribe(device, ['attr_name'], null, 'normalized', function (error) {
|
|
173
173
|
iotAgentLib.unregister(device.id, null, 'smartgondor', '/gardens', function (error) {
|
|
174
174
|
contextBrokerMock.done();
|
|
175
175
|
done();
|
|
@@ -181,7 +181,7 @@ describe('NGSI-LD - Subscription tests', function () {
|
|
|
181
181
|
describe('When a new notification comes to the IoTAgent', function () {
|
|
182
182
|
beforeEach(function (done) {
|
|
183
183
|
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
184
|
-
iotAgentLib.subscribe(device, ['attr_name'], null, function (error) {
|
|
184
|
+
iotAgentLib.subscribe(device, ['attr_name'], null, 'normalized', function (error) {
|
|
185
185
|
done();
|
|
186
186
|
});
|
|
187
187
|
});
|
|
@@ -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',
|