iotagent-node-lib 4.4.0 → 4.6.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/README.md +67 -272
- package/config.js +2 -1
- package/doc/README.md +1 -1
- package/doc/admin.md +19 -22
- package/doc/api.md +621 -155
- package/doc/deprecated.md +4 -0
- package/doc/devel/architecture.md +5 -135
- package/doc/devel/development.md +224 -12
- package/doc/getting-started.md +114 -53
- package/doc/requirements.txt +1 -1
- package/doc/roadmap.md +5 -5
- package/docker/Mosquitto/Dockerfile +2 -2
- package/docker/Mosquitto/README.md +14 -11
- package/lib/commonConfig.js +7 -1
- package/lib/constants.js +3 -0
- package/lib/fiware-iotagent-lib.js +12 -15
- package/lib/jexlTranformsMap.js +3 -1
- package/lib/model/dbConn.js +1 -4
- package/lib/services/common/alarmManagement.js +3 -0
- package/lib/services/devices/deviceRegistryMemory.js +1 -1
- package/lib/services/devices/deviceRegistryMongoDB.js +2 -2
- package/lib/services/devices/deviceService.js +4 -3
- package/lib/services/devices/devices-NGSI-LD.js +5 -5
- package/lib/services/devices/devices-NGSI-mixed.js +3 -3
- package/lib/services/devices/devices-NGSI-v2.js +5 -5
- package/lib/services/groups/groupService.js +1 -1
- package/lib/services/ngsi/entities-NGSI-LD.js +321 -571
- package/lib/services/ngsi/entities-NGSI-v2.js +348 -281
- package/lib/services/ngsi/ngsiService.js +3 -1
- package/lib/services/ngsi/subscription-NGSI-LD.js +2 -2
- package/lib/services/ngsi/subscription-NGSI-v2.js +2 -2
- package/lib/services/northBound/deviceGroupAdministrationServer.js +42 -6
- package/lib/services/northBound/deviceProvisioningServer.js +5 -5
- package/lib/services/northBound/northboundServer.js +4 -2
- package/lib/services/stats/statsRegistry.js +128 -101
- package/lib/templates/createDevice.json +0 -24
- package/lib/templates/createDeviceLax.json +0 -23
- package/lib/templates/deviceGroup.json +1 -25
- package/lib/templates/updateDevice.json +0 -24
- package/lib/templates/updateDeviceLax.json +0 -23
- package/package.json +2 -2
- package/scripts/legacy_expression_tool/README.md +0 -1
- package/test/functional/README.md +75 -47
- package/test/functional/functional-tests-runner.js +9 -4
- package/test/functional/functional-tests.js +4 -4
- package/test/functional/testCases.js +1251 -257
- package/test/functional/testUtils.js +53 -20
- package/test/unit/examples/deviceProvisioningRequests/provisionFullDevice.json +1 -13
- package/test/unit/examples/deviceProvisioningRequests/updateProvisionDeviceWithApikey.json +4 -0
- package/test/unit/examples/groupProvisioningRequests/multipleConfigGroupsCreation.json +44 -0
- package/test/unit/examples/groupProvisioningRequests/provisionDuplicateConfigGroup.json +35 -0
- package/test/unit/examples/groupProvisioningRequests/provisionFullConfigGroup.json +36 -0
- package/test/unit/examples/groupProvisioningRequests/provisionFullConfigGroupAlternate.json +36 -0
- package/test/unit/general/deviceService-test.js +102 -0
- package/test/unit/general/statistics-service_test.js +1 -74
- package/test/unit/mongodb/mongodb-configGroup-registry-test.js +452 -0
- package/test/unit/mongodb/mongodb-connectionoptions-test.js +2 -3
- package/test/unit/mongodb/mongodb-group-registry-test.js +34 -33
- package/test/unit/mongodb/mongodb-service-registry-test.js +477 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin1a.json +4 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin2.json +22 -22
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin29.json +4 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin32.json +14 -15
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin1.json +23 -23
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin15.json +0 -5
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin4.json +11 -16
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin5.json +23 -28
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin6.json +8 -13
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin7.json +0 -5
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin8.json +24 -29
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +12 -17
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextStaticLinkedAttributes.json +12 -10
- package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +0 -102
- package/test/unit/ngsi-ld/plugins/multientity-plugin_test.js +4 -5
- package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +5 -5
- package/test/unit/ngsi-ld/provisioning/listProvisionedDevices-test.js +0 -4
- package/test/unit/ngsiv2/general/deviceService-test.js +94 -1
- package/test/unit/ngsiv2/general/iotam-autoregistration-test.js +195 -0
- package/test/unit/ngsiv2/provisioning/device-group-api-test.js +259 -0
- package/test/unit/ngsiv2/provisioning/device-provisioning-configGroup-api_test.js +1189 -0
- package/test/unit/ngsiv2/provisioning/device-update-registration_test.js +6 -6
- package/test/unit/ngsiv2/provisioning/listProvisionedDevices-test.js +0 -4
- package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +35 -0
- package/test/unit/statsRegistry/openmetrics-test.js +167 -0
- package/lib/templates/queryContext.json +0 -25
- package/test/unit/examples/deviceProvisioningRequests/provisionBidirectionalDevice.json +0 -35
- package/test/unit/examples/deviceProvisioningRequests/provisionDeviceBidirectionalGroup.json +0 -17
- package/test/unit/examples/groupProvisioningRequests/bidirectionalGroup.json +0 -31
- package/test/unit/general/statistics-persistence_test.js +0 -121
- package/test/unit/ngsi-ld/examples/contextRequests/createBidirectionalDevice.json +0 -17
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextProcessTimestamp.json +0 -12
- package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotification.json +0 -13
- package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotificationWithDatasetId.json +0 -21
- package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotificationWithMetadata.json +0 -17
- package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json +0 -23
- package/test/unit/ngsi-ld/plugins/timestamp-processing-plugin_test.js +0 -132
- package/test/unit/ngsiv2/examples/contextRequests/createBidirectionalDevice.json +0 -8
- package/test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalNotification.json +0 -13
- package/test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalNotificationWithMetadata.json +0 -19
- package/test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json +0 -24
|
@@ -197,7 +197,7 @@ describe('NGSI-v2 - IoT Agent Device Update Registration', function () {
|
|
|
197
197
|
});
|
|
198
198
|
|
|
199
199
|
it('should register as ContextProvider of its lazy attributes', function (done) {
|
|
200
|
-
iotAgentLib.updateRegister(deviceUpdated, false, function (error) {
|
|
200
|
+
iotAgentLib.updateRegister(deviceUpdated, device1, false, function (error) {
|
|
201
201
|
should.not.exist(error);
|
|
202
202
|
contextBrokerMock.done();
|
|
203
203
|
done();
|
|
@@ -205,7 +205,7 @@ describe('NGSI-v2 - IoT Agent Device Update Registration', function () {
|
|
|
205
205
|
});
|
|
206
206
|
|
|
207
207
|
it('should store the new values in the registry', function (done) {
|
|
208
|
-
iotAgentLib.updateRegister(deviceUpdated, false, function (error, data) {
|
|
208
|
+
iotAgentLib.updateRegister(deviceUpdated, device1, false, function (error, data) {
|
|
209
209
|
iotAgentLib.getDevice(deviceUpdated.id, null, 'smartgondor', 'gardens', function (error, deviceResult) {
|
|
210
210
|
should.not.exist(error);
|
|
211
211
|
should.exist(deviceResult);
|
|
@@ -253,7 +253,7 @@ describe('NGSI-v2 - IoT Agent Device Update Registration', function () {
|
|
|
253
253
|
});
|
|
254
254
|
|
|
255
255
|
it('should register as ContextProvider of its commands and create the additional attributes', function (done) {
|
|
256
|
-
iotAgentLib.updateRegister(deviceCommandUpdated, false, function (error) {
|
|
256
|
+
iotAgentLib.updateRegister(deviceCommandUpdated, device1, false, function (error) {
|
|
257
257
|
should.not.exist(error);
|
|
258
258
|
contextBrokerMock.done();
|
|
259
259
|
done();
|
|
@@ -261,7 +261,7 @@ describe('NGSI-v2 - IoT Agent Device Update Registration', function () {
|
|
|
261
261
|
});
|
|
262
262
|
|
|
263
263
|
it('should store the new values in the registry', function (done) {
|
|
264
|
-
iotAgentLib.updateRegister(deviceCommandUpdated, false, function (error, data) {
|
|
264
|
+
iotAgentLib.updateRegister(deviceCommandUpdated, device1, false, function (error, data) {
|
|
265
265
|
iotAgentLib.getDevice(
|
|
266
266
|
deviceCommandUpdated.id,
|
|
267
267
|
null,
|
|
@@ -282,7 +282,7 @@ describe('NGSI-v2 - IoT Agent Device Update Registration', function () {
|
|
|
282
282
|
|
|
283
283
|
describe('When a update action is executed in a non registered device', function () {
|
|
284
284
|
it('should return a DEVICE_NOT_FOUND error', function (done) {
|
|
285
|
-
iotAgentLib.updateRegister(unknownDevice, false, function (error) {
|
|
285
|
+
iotAgentLib.updateRegister(unknownDevice, device1, false, function (error) {
|
|
286
286
|
should.exist(error);
|
|
287
287
|
error.name.should.equal('DEVICE_NOT_FOUND');
|
|
288
288
|
done();
|
|
@@ -304,7 +304,7 @@ describe('NGSI-v2 - IoT Agent Device Update Registration', function () {
|
|
|
304
304
|
});
|
|
305
305
|
|
|
306
306
|
it('should return a REGISTRATION_ERROR error in the update action', function (done) {
|
|
307
|
-
iotAgentLib.updateRegister(deviceUpdated, false, function (error) {
|
|
307
|
+
iotAgentLib.updateRegister(deviceUpdated, device1, false, function (error) {
|
|
308
308
|
should.exist(error);
|
|
309
309
|
error.name.should.equal('UNREGISTRATION_ERROR');
|
|
310
310
|
done();
|
|
@@ -183,11 +183,9 @@ describe('NGSI-v2 - Device provisioning API: List provisioned devices', function
|
|
|
183
183
|
should.exist(body.devices[2].attributes[0].entity_name);
|
|
184
184
|
should.exist(body.devices[2].attributes[0].entity_type);
|
|
185
185
|
should.exist(body.devices[2].attributes[1].expression);
|
|
186
|
-
should.exist(body.devices[2].attributes[2].reverse);
|
|
187
186
|
body.devices[2].attributes[0].entity_name.should.equal('Higro2000');
|
|
188
187
|
body.devices[2].attributes[0].entity_type.should.equal('Higrometer');
|
|
189
188
|
body.devices[2].attributes[1].expression.should.equal('${@humidity * 20}');
|
|
190
|
-
body.devices[2].attributes[2].reverse.length.should.equal(2);
|
|
191
189
|
done();
|
|
192
190
|
});
|
|
193
191
|
});
|
|
@@ -242,11 +240,9 @@ describe('NGSI-v2 - Device provisioning API: List provisioned devices', function
|
|
|
242
240
|
should.exist(body.attributes[0].entity_name);
|
|
243
241
|
should.exist(body.attributes[0].entity_type);
|
|
244
242
|
should.exist(body.attributes[1].expression);
|
|
245
|
-
should.exist(body.attributes[2].reverse);
|
|
246
243
|
body.attributes[0].entity_name.should.equal('Higro2000');
|
|
247
244
|
body.attributes[0].entity_type.should.equal('Higrometer');
|
|
248
245
|
body.attributes[1].expression.should.equal('${@humidity * 20}');
|
|
249
|
-
body.attributes[2].reverse.length.should.equal(2);
|
|
250
246
|
done();
|
|
251
247
|
});
|
|
252
248
|
});
|
|
@@ -289,6 +289,41 @@ describe('NGSI-v2 - Device provisioning API: Update provisioned devices', functi
|
|
|
289
289
|
});
|
|
290
290
|
});
|
|
291
291
|
});
|
|
292
|
+
describe('When an update request arrives with a new Apikey', function () {
|
|
293
|
+
const optionsUpdate = {
|
|
294
|
+
url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices/Light1',
|
|
295
|
+
method: 'PUT',
|
|
296
|
+
headers: {
|
|
297
|
+
'fiware-service': 'smartgondor',
|
|
298
|
+
'fiware-servicepath': '/gardens'
|
|
299
|
+
},
|
|
300
|
+
json: utils.readExampleFile(
|
|
301
|
+
'./test/unit/examples/deviceProvisioningRequests/updateProvisionDeviceWithApikey.json'
|
|
302
|
+
)
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
beforeEach(function () {
|
|
306
|
+
contextBrokerMock
|
|
307
|
+
.matchHeader('fiware-service', 'smartgondor')
|
|
308
|
+
.matchHeader('fiware-servicepath', '/gardens')
|
|
309
|
+
.delete('/v2/registrations/6319a7f5254b05844116584d', '')
|
|
310
|
+
.reply(204);
|
|
311
|
+
|
|
312
|
+
contextBrokerMock
|
|
313
|
+
.matchHeader('fiware-service', 'smartgondor')
|
|
314
|
+
.matchHeader('fiware-servicepath', '/gardens')
|
|
315
|
+
.post('/v2/registrations')
|
|
316
|
+
.reply(201, null, { Location: '/v2/registrations/4419a7f5254b058441165849' });
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it('should raise a 204 error', function (done) {
|
|
320
|
+
request(optionsUpdate, function (error, response, body) {
|
|
321
|
+
should.not.exist(error);
|
|
322
|
+
response.statusCode.should.equal(204);
|
|
323
|
+
done();
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
});
|
|
292
327
|
describe('When a wrong update request payload arrives', function () {
|
|
293
328
|
const optionsUpdate = {
|
|
294
329
|
url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices/Light1',
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 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::daniel.moranjimenez@telefonica.com
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/* eslint-disable no-unused-vars */
|
|
25
|
+
|
|
26
|
+
const statsRegistry = require('../../../lib/services/stats/statsRegistry');
|
|
27
|
+
const should = require('should');
|
|
28
|
+
|
|
29
|
+
describe('statsRegistry - openmetrics endpoint', function () {
|
|
30
|
+
|
|
31
|
+
const testCases = [
|
|
32
|
+
{
|
|
33
|
+
description: 'Should accept standard openmetrics 0.0.1 header',
|
|
34
|
+
accept: 'application/openmetrics-text; version=0.0.1; charset=utf-8',
|
|
35
|
+
contentType: {
|
|
36
|
+
mediaType: 'application/openmetrics-text',
|
|
37
|
+
version: '0.0.1',
|
|
38
|
+
charset: 'utf-8'
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
description: 'Should accept standard openmetrics 1.0.0 header',
|
|
43
|
+
accept: 'application/openmetrics-text; version=1.0.0; charset=utf-8',
|
|
44
|
+
contentType: {
|
|
45
|
+
mediaType: 'application/openmetrics-text',
|
|
46
|
+
version: '1.0.0',
|
|
47
|
+
charset: 'utf-8'
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
description: 'Should accept openmetrics with no version',
|
|
52
|
+
accept: 'application/openmetrics-text',
|
|
53
|
+
contentType: {
|
|
54
|
+
mediaType: 'application/openmetrics-text',
|
|
55
|
+
version: '1.0.0',
|
|
56
|
+
charset: 'utf-8'
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
description: 'Should accept text/plain header with version',
|
|
61
|
+
accept: 'text/plain; version=0.0.4',
|
|
62
|
+
contentType: {
|
|
63
|
+
mediaType: 'text/plain',
|
|
64
|
+
version: '0.0.4',
|
|
65
|
+
charset: 'utf-8'
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
description: 'Should accept wildcard header',
|
|
70
|
+
accept: '*/*',
|
|
71
|
+
contentType: {
|
|
72
|
+
mediaType: 'text/plain',
|
|
73
|
+
version: '0.0.4',
|
|
74
|
+
charset: 'utf-8'
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
description: 'Should accept both openmetrics and text/plain, prefer openmetrics',
|
|
79
|
+
accept: 'application/openmetrics-text; version=0.0.1; charset=utf-8,text/plain;version=0.0.4',
|
|
80
|
+
contentType: {
|
|
81
|
+
mediaType: 'application/openmetrics-text',
|
|
82
|
+
version: '0.0.1',
|
|
83
|
+
charset: 'utf-8'
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
description: 'Should accept both text/plain and openmetrics, prefer openmetrics',
|
|
88
|
+
accept: 'text/plain,application/openmetrics-text; version=0.0.1; charset=utf-8',
|
|
89
|
+
contentType: {
|
|
90
|
+
mediaType: 'application/openmetrics-text',
|
|
91
|
+
version: '0.0.1',
|
|
92
|
+
charset: 'utf-8'
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
description: 'Should accept both openmetrics and text/plain, prefer text if preference set',
|
|
97
|
+
accept: 'application/openmetrics-text; version=0.0.1; charset=utf-8;q=0.5,text/plain;q=0.7',
|
|
98
|
+
contentType: {
|
|
99
|
+
mediaType: 'text/plain',
|
|
100
|
+
version: '0.0.4',
|
|
101
|
+
charset: 'utf-8'
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
description: 'Should match version to content-type',
|
|
106
|
+
accept: 'application/openmetrics-text; version=0.0.1; charset=utf-8, text/plain;version=1.0.0',
|
|
107
|
+
contentType: {
|
|
108
|
+
mediaType: 'application/openmetrics-text',
|
|
109
|
+
version: '0.0.1',
|
|
110
|
+
charset: 'utf-8'
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
description: 'Should set default q to 1.0',
|
|
115
|
+
accept: 'application/openmetrics-text; version=0.0.1; q=0.5,text/plain;version=0.0.4',
|
|
116
|
+
contentType: {
|
|
117
|
+
mediaType: 'text/plain',
|
|
118
|
+
version: '0.0.4',
|
|
119
|
+
charset: 'utf-8'
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
description: 'Should accept mixture of content-types and q',
|
|
124
|
+
accept: 'application/openmetrics-text; version=0.0.1,text/plain;version=0.0.4;q=0.5,*/*;q=0.1',
|
|
125
|
+
contentType: {
|
|
126
|
+
mediaType: 'application/openmetrics-text',
|
|
127
|
+
version: '0.0.1',
|
|
128
|
+
charset: 'utf-8'
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
description: 'Should reject Invalid charset',
|
|
133
|
+
accept: '*/*; charset=utf-16',
|
|
134
|
+
contentType: null
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
description: 'Should reject Invalid openmetrics version',
|
|
138
|
+
accept: 'application/openmetrics-text; version=0.0.5',
|
|
139
|
+
contentType: null
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
description: 'Should reject Invalid text/plain',
|
|
143
|
+
accept: 'text/plain; version=0.0.2',
|
|
144
|
+
contentType: null
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
|
|
148
|
+
for (const testCase of testCases) {
|
|
149
|
+
describe(testCase.description, function () {
|
|
150
|
+
const result = statsRegistry.matchContentType(testCase.accept);
|
|
151
|
+
if (testCase.contentType) {
|
|
152
|
+
it('should match', function (done) {
|
|
153
|
+
should.exist(result);
|
|
154
|
+
result.mediaType.should.equal(testCase.contentType.mediaType);
|
|
155
|
+
result.version.should.equal(testCase.contentType.version);
|
|
156
|
+
result.charset.should.equal(testCase.contentType.charset);
|
|
157
|
+
done();
|
|
158
|
+
});
|
|
159
|
+
} else {
|
|
160
|
+
it('should not match', function (done) {
|
|
161
|
+
should.not.exist(result);
|
|
162
|
+
done();
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"properties": {
|
|
3
|
-
"entities": {
|
|
4
|
-
"description": "The objects the request is applied to.",
|
|
5
|
-
"type": "array",
|
|
6
|
-
"items": {
|
|
7
|
-
"type": "object",
|
|
8
|
-
"properties": {
|
|
9
|
-
"type": {
|
|
10
|
-
"type": "string",
|
|
11
|
-
"required": true
|
|
12
|
-
},
|
|
13
|
-
"isPattern": {
|
|
14
|
-
"type": "string"
|
|
15
|
-
},
|
|
16
|
-
"id": {
|
|
17
|
-
"type": "string",
|
|
18
|
-
"required": true
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
"required": true
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"devices": [
|
|
3
|
-
{
|
|
4
|
-
"device_id": "Light1",
|
|
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":"location",
|
|
14
|
-
"type":"geo:point",
|
|
15
|
-
"expression": "latitude,longitude",
|
|
16
|
-
"reverse": [
|
|
17
|
-
{
|
|
18
|
-
"object_id":"latitude",
|
|
19
|
-
"type": "Number",
|
|
20
|
-
"expression": "location | split(', ')[1] | parsefloat()"
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
"object_id":"longitude",
|
|
24
|
-
"type": "Number",
|
|
25
|
-
"expression": "location | split(', ')[0] | parsefloat()"
|
|
26
|
-
}
|
|
27
|
-
]
|
|
28
|
-
}
|
|
29
|
-
],
|
|
30
|
-
"lazy": [],
|
|
31
|
-
"static_attributes": [],
|
|
32
|
-
"commands": []
|
|
33
|
-
}
|
|
34
|
-
]
|
|
35
|
-
}
|
package/test/unit/examples/deviceProvisioningRequests/provisionDeviceBidirectionalGroup.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"devices": [
|
|
3
|
-
{
|
|
4
|
-
"device_id": "Light1",
|
|
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
|
-
"lazy": [],
|
|
13
|
-
"static_attributes": [],
|
|
14
|
-
"commands": []
|
|
15
|
-
}
|
|
16
|
-
]
|
|
17
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"services": [
|
|
3
|
-
{
|
|
4
|
-
"resource": "/deviceTest",
|
|
5
|
-
"apikey": "801230BJKL23Y9090DSFL123HJK09H324HV8732",
|
|
6
|
-
"entity_type": "TheLightType",
|
|
7
|
-
"commands": [],
|
|
8
|
-
"lazy": [],
|
|
9
|
-
"attributes": [
|
|
10
|
-
{
|
|
11
|
-
"name":"location",
|
|
12
|
-
"type":"geo:point",
|
|
13
|
-
"expression": "${latitude}, ${longitude}",
|
|
14
|
-
"reverse": [
|
|
15
|
-
{
|
|
16
|
-
"object_id":"latitude",
|
|
17
|
-
"type": "Number",
|
|
18
|
-
"expression": "location | split(', ')[1] | parsefloat()"
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"object_id":"longitude",
|
|
22
|
-
"type": "Number",
|
|
23
|
-
"expression": "location | split(', ')[0] | parsefloat()"
|
|
24
|
-
}
|
|
25
|
-
]
|
|
26
|
-
}
|
|
27
|
-
],
|
|
28
|
-
"static_attributes": []
|
|
29
|
-
}
|
|
30
|
-
]
|
|
31
|
-
}
|
|
@@ -1,121 +0,0 @@
|
|
|
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, 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
|
-
|
|
24
|
-
/* eslint-disable no-unused-vars */
|
|
25
|
-
|
|
26
|
-
const statsService = require('../../../lib/services/stats/statsRegistry');
|
|
27
|
-
const commonConfig = require('../../../lib/commonConfig');
|
|
28
|
-
const iotAgentLib = require('../../../lib/fiware-iotagent-lib');
|
|
29
|
-
const should = require('should');
|
|
30
|
-
const async = require('async');
|
|
31
|
-
const mongoUtils = require('../mongodb/mongoDBUtils');
|
|
32
|
-
const iotAgentConfig = {
|
|
33
|
-
logLevel: 'FATAL',
|
|
34
|
-
contextBroker: {
|
|
35
|
-
host: '192.168.1.1',
|
|
36
|
-
port: '1026'
|
|
37
|
-
},
|
|
38
|
-
server: {
|
|
39
|
-
port: 4041,
|
|
40
|
-
host: 'localhost',
|
|
41
|
-
baseRoot: '/'
|
|
42
|
-
},
|
|
43
|
-
stats: {
|
|
44
|
-
interval: 50,
|
|
45
|
-
persistence: true
|
|
46
|
-
},
|
|
47
|
-
mongodb: {
|
|
48
|
-
host: 'localhost',
|
|
49
|
-
port: '27017',
|
|
50
|
-
db: 'iotagent'
|
|
51
|
-
},
|
|
52
|
-
types: {},
|
|
53
|
-
service: 'smartgondor',
|
|
54
|
-
subservice: 'gardens',
|
|
55
|
-
providerUrl: 'http://smartgondor.com',
|
|
56
|
-
deviceRegistrationDuration: 'P1M'
|
|
57
|
-
};
|
|
58
|
-
let iotAgentDb;
|
|
59
|
-
let oldConfig;
|
|
60
|
-
|
|
61
|
-
describe('Statistics persistence service', function () {
|
|
62
|
-
function insertDummy(n, callback) {
|
|
63
|
-
iotAgentDb.collection('tests').insertOne({ test: 'test' }, function () {
|
|
64
|
-
callback();
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
beforeEach(function (done) {
|
|
69
|
-
oldConfig = commonConfig.getConfig();
|
|
70
|
-
|
|
71
|
-
iotAgentLib.activate(iotAgentConfig, function (error) {
|
|
72
|
-
statsService.globalLoad({}, function () {
|
|
73
|
-
iotAgentDb = require('../../../lib/model/dbConn').db;
|
|
74
|
-
|
|
75
|
-
async.times(10, insertDummy, function () {
|
|
76
|
-
done();
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
afterEach(function (done) {
|
|
83
|
-
iotAgentLib.deactivate(function (error) {
|
|
84
|
-
commonConfig.setConfig(oldConfig);
|
|
85
|
-
statsService.globalLoad({}, function () {
|
|
86
|
-
mongoUtils.cleanDbs(done);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
describe('When a periodic persitence action is set', function () {
|
|
92
|
-
beforeEach(function (done) {
|
|
93
|
-
statsService.globalLoad(
|
|
94
|
-
{
|
|
95
|
-
stat1: 10
|
|
96
|
-
},
|
|
97
|
-
function () {
|
|
98
|
-
statsService.add('stat1', 5, done);
|
|
99
|
-
}
|
|
100
|
-
);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('should store all the records in the database', function (done) {
|
|
104
|
-
statsService.addTimerAction(statsService.mongodbPersistence, function () {
|
|
105
|
-
setTimeout(function () {
|
|
106
|
-
statsService.clearTimers(function () {
|
|
107
|
-
iotAgentDb
|
|
108
|
-
.collection('kpis')
|
|
109
|
-
.find({})
|
|
110
|
-
.toArray(function (err, docs) {
|
|
111
|
-
should.not.exist(err);
|
|
112
|
-
should.exist(docs);
|
|
113
|
-
docs.length.should.be.above(2);
|
|
114
|
-
done();
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
}, 200);
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"@context": "http://context.json-ld",
|
|
4
|
-
"id": "urn:ngsi-ld:TheLightType:TheFirstLight",
|
|
5
|
-
"location": {
|
|
6
|
-
"type": "GeoProperty",
|
|
7
|
-
"value": {
|
|
8
|
-
"coordinates": [
|
|
9
|
-
0,
|
|
10
|
-
0
|
|
11
|
-
],
|
|
12
|
-
"type": "Point"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
"type": "TheLightType"
|
|
16
|
-
}
|
|
17
|
-
]
|
package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotificationWithDatasetId.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
}
|
package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"@context": "http://context.json-ld",
|
|
3
|
-
"type": "Subscription",
|
|
4
|
-
"entities": [
|
|
5
|
-
{
|
|
6
|
-
"id": "TheFirstLight",
|
|
7
|
-
"type": "TheLightType"
|
|
8
|
-
}
|
|
9
|
-
],
|
|
10
|
-
"watchedAttributes": [
|
|
11
|
-
"location"
|
|
12
|
-
],
|
|
13
|
-
"notification": {
|
|
14
|
-
"endpoint": {
|
|
15
|
-
"uri": "http://smartgondor.com/notify",
|
|
16
|
-
"accept": "application/json"
|
|
17
|
-
},
|
|
18
|
-
"attributes": [
|
|
19
|
-
"location"
|
|
20
|
-
],
|
|
21
|
-
"format": "normalized"
|
|
22
|
-
}
|
|
23
|
-
}
|