iotagent-node-lib 4.5.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/doc/README.md +1 -1
- package/doc/admin.md +3 -15
- package/doc/api.md +469 -134
- 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/roadmap.md +5 -5
- package/docker/Mosquitto/Dockerfile +2 -2
- package/docker/Mosquitto/README.md +14 -11
- 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/groups/groupService.js +1 -1
- package/lib/services/ngsi/entities-NGSI-LD.js +320 -570
- package/lib/services/ngsi/entities-NGSI-v2.js +36 -1
- package/lib/services/ngsi/ngsiService.js +3 -1
- package/lib/services/northBound/deviceGroupAdministrationServer.js +42 -6
- package/lib/services/northBound/deviceProvisioningServer.js +0 -1
- package/lib/services/northBound/northboundServer.js +2 -0
- 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 +22 -17
- package/test/functional/functional-tests-runner.js +9 -4
- package/test/functional/functional-tests.js +4 -4
- package/test/functional/testCases.js +245 -4
- package/test/unit/examples/deviceProvisioningRequests/provisionFullDevice.json +1 -13
- 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/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/listProvisionedDevices-test.js +0 -4
- 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
|
@@ -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
|
});
|
|
@@ -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
|
-
}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 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
|
-
* Modified by: Jason Fox - FIWARE Foundation
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
const iotAgentLib = require('../../../../lib/fiware-iotagent-lib');
|
|
27
|
-
const utils = require('../../../tools/utils');
|
|
28
|
-
const should = require('should');
|
|
29
|
-
const logger = require('logops');
|
|
30
|
-
const nock = require('nock');
|
|
31
|
-
const moment = require('moment');
|
|
32
|
-
let contextBrokerMock;
|
|
33
|
-
const iotAgentConfig = {
|
|
34
|
-
contextBroker: {
|
|
35
|
-
host: '192.168.1.1',
|
|
36
|
-
port: '1026',
|
|
37
|
-
ngsiVersion: 'ld',
|
|
38
|
-
jsonLdContext: 'http://context.json-ld'
|
|
39
|
-
},
|
|
40
|
-
server: {
|
|
41
|
-
port: 4041,
|
|
42
|
-
host: 'localhost'
|
|
43
|
-
},
|
|
44
|
-
types: {
|
|
45
|
-
Light: {
|
|
46
|
-
commands: [],
|
|
47
|
-
type: 'Light',
|
|
48
|
-
lazy: [
|
|
49
|
-
{
|
|
50
|
-
name: 'temperature',
|
|
51
|
-
type: 'centigrades'
|
|
52
|
-
}
|
|
53
|
-
],
|
|
54
|
-
active: [
|
|
55
|
-
{
|
|
56
|
-
name: 'pressure',
|
|
57
|
-
type: 'Hgmm'
|
|
58
|
-
}
|
|
59
|
-
]
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
service: 'smartgondor',
|
|
63
|
-
subservice: 'gardens',
|
|
64
|
-
providerUrl: 'http://smartgondor.com'
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
describe('NGSI-LD - Timestamp processing plugin', function () {
|
|
68
|
-
beforeEach(function (done) {
|
|
69
|
-
logger.setLevel('FATAL');
|
|
70
|
-
|
|
71
|
-
iotAgentLib.activate(iotAgentConfig, function () {
|
|
72
|
-
iotAgentLib.clearAll(function () {
|
|
73
|
-
done();
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
afterEach(function (done) {
|
|
79
|
-
iotAgentLib.clearAll(function () {
|
|
80
|
-
iotAgentLib.deactivate(done);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
describe('When an update comes with a timestamp through the plugin', function () {
|
|
84
|
-
const values = [
|
|
85
|
-
{
|
|
86
|
-
name: 'state',
|
|
87
|
-
type: 'Boolean',
|
|
88
|
-
value: true
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
name: 'TimeInstant',
|
|
92
|
-
type: 'DateTime',
|
|
93
|
-
value: '2016-05-30T16:25:22.304Z'
|
|
94
|
-
}
|
|
95
|
-
];
|
|
96
|
-
|
|
97
|
-
beforeEach(function () {
|
|
98
|
-
nock.cleanAll();
|
|
99
|
-
|
|
100
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
101
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
102
|
-
.post('/ngsi-ld/v1/entityOperations/upsert/?options=update', function (body) {
|
|
103
|
-
const expectedBody = utils.readExampleFile(
|
|
104
|
-
'./test/unit/ngsi-ld/examples/contextRequests/updateContextProcessTimestamp.json'
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
// Note that TimeInstant fields are not included in the json used by this mock as they are dynamic
|
|
108
|
-
// fields. The following code just checks that TimeInstant fields are present.
|
|
109
|
-
if (!body[0].state.observedAt) {
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const timeInstantAtt = body[0].state.observedAt;
|
|
114
|
-
if (moment(timeInstantAtt, 'YYYY-MM-DDTHH:mm:ss.SSSZ').isValid) {
|
|
115
|
-
delete body[0].state.observedAt;
|
|
116
|
-
delete expectedBody[0].state.observedAt;
|
|
117
|
-
return JSON.stringify(body) === JSON.stringify(expectedBody);
|
|
118
|
-
}
|
|
119
|
-
return false;
|
|
120
|
-
})
|
|
121
|
-
.reply(204);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('should return an entity with all its timestamps expanded to have separators', function (done) {
|
|
125
|
-
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
126
|
-
should.not.exist(error);
|
|
127
|
-
contextBrokerMock.done();
|
|
128
|
-
done();
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
});
|