iotagent-node-lib 4.5.0 → 4.7.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 +0 -1
- package/Changelog +12 -0
- package/README.md +67 -272
- package/config.js +3 -1
- package/doc/README.md +1 -1
- package/doc/admin.md +40 -18
- package/doc/api.md +532 -136
- 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 +21 -2
- package/lib/constants.js +3 -0
- package/lib/fiware-iotagent-lib.js +12 -15
- package/lib/jexlTranformsMap.js +3 -1
- package/lib/model/Command.js +2 -2
- package/lib/model/Device.js +7 -3
- package/lib/model/Group.js +5 -3
- package/lib/model/dbConn.js +53 -115
- package/lib/services/commands/commandRegistryMongoDB.js +115 -75
- package/lib/services/common/alarmManagement.js +3 -0
- package/lib/services/common/iotManagerService.js +3 -1
- package/lib/services/devices/deviceRegistryMemory.js +36 -0
- package/lib/services/devices/deviceRegistryMongoDB.js +160 -87
- package/lib/services/devices/deviceService.js +33 -3
- package/lib/services/devices/devices-NGSI-v2.js +6 -1
- package/lib/services/groups/groupRegistryMongoDB.js +120 -83
- 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 +51 -3
- package/lib/services/ngsi/ngsiService.js +34 -1
- package/lib/services/northBound/deviceGroupAdministrationServer.js +42 -6
- package/lib/services/northBound/deviceProvisioningServer.js +12 -4
- 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 +12 -24
- package/lib/templates/updateDeviceLax.json +12 -23
- package/package.json +5 -5
- package/scripts/legacy_expression_tool/README.md +0 -1
- package/test/functional/README.md +22 -17
- package/test/functional/config-test.js +3 -2
- 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/functional/testUtils.js +2 -2
- 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/examples/groupProvisioningRequests/provisionFullGroup.json +1 -0
- package/test/unit/general/config-multi-core-test.js +1 -2
- package/test/unit/general/contextBrokerKeystoneSecurityAccess-test.js +5 -4
- package/test/unit/general/deviceService-test.js +106 -3
- package/test/unit/general/statistics-service_test.js +1 -74
- package/test/unit/memoryRegistry/deviceRegistryMemory_test.js +6 -5
- package/test/unit/mongodb/mongodb-configGroup-registry-test.js +452 -0
- package/test/unit/mongodb/mongodb-connectionoptions-test.js +9 -42
- 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 +1 -104
- package/test/unit/ngsi-ld/general/config-jsonld-contexts-test.js +1 -2
- 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/ngsi-mixed/provisioning/ngsi-versioning-test.js +8 -5
- package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +42 -41
- package/test/unit/ngsiv2/general/contextBrokerOAuthSecurityAccess-test.js +11 -10
- package/test/unit/ngsiv2/general/deviceService-test.js +98 -4
- package/test/unit/ngsiv2/general/https-support-test.js +1 -1
- package/test/unit/ngsiv2/general/iotam-autoregistration-test.js +195 -0
- package/test/unit/ngsiv2/lazyAndCommands/active-devices-attribute-update-test.js +4 -3
- package/test/unit/ngsiv2/lazyAndCommands/command-test.js +6 -5
- package/test/unit/ngsiv2/lazyAndCommands/lazy-devices-test.js +17 -16
- package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +10 -18
- package/test/unit/ngsiv2/ngsiService/active-devices-test.js +21 -20
- package/test/unit/ngsiv2/ngsiService/staticAttributes-test.js +8 -7
- package/test/unit/ngsiv2/plugins/alias-plugin_test.js +12 -11
- package/test/unit/ngsiv2/plugins/custom-plugin_test.js +3 -2
- package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +28 -27
- package/test/unit/ngsiv2/provisioning/device-group-api-test.js +265 -4
- package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +12 -11
- package/test/unit/ngsiv2/provisioning/device-provisioning-configGroup-api_test.js +1190 -0
- package/test/unit/ngsiv2/provisioning/device-registration_test.js +5 -4
- package/test/unit/ngsiv2/provisioning/listProvisionedDevices-test.js +6 -9
- package/test/unit/ngsiv2/provisioning/provisionDeviceMultientity-test.js +1 -1
- package/test/unit/ngsiv2/provisioning/removeProvisionedDevice-test.js +5 -4
- package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +8 -7
- 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
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"groups": [
|
|
3
|
+
{
|
|
4
|
+
"resource": "/deviceTest",
|
|
5
|
+
"apikey": "801230BJKL23Y9090DSFL123HJK09H324HV8732",
|
|
6
|
+
"entity_type": "Light",
|
|
7
|
+
"trust": "8970A9078A803H3BL98PINEQRW8342HBAMS",
|
|
8
|
+
"cbHost": "http://unexistentHost:1026",
|
|
9
|
+
"commands": [
|
|
10
|
+
{
|
|
11
|
+
"name": "wheel1",
|
|
12
|
+
"type": "Wheel"
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"lazy": [
|
|
16
|
+
{
|
|
17
|
+
"name": "luminescence",
|
|
18
|
+
"type": "Lumens"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"attributes": [
|
|
22
|
+
{
|
|
23
|
+
"name": "status",
|
|
24
|
+
"type": "Boolean"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"resource": "/deviceTest",
|
|
30
|
+
"apikey": "23HJK3Y9090DSFL173209HV8801232",
|
|
31
|
+
"entity_type": "Termometer",
|
|
32
|
+
"trust": "BL9803H3QRW8342HBAMS8A8",
|
|
33
|
+
"cbHost": "http://unexistentHost:1026",
|
|
34
|
+
"commands": [
|
|
35
|
+
{
|
|
36
|
+
"name": "temperature",
|
|
37
|
+
"type": "degrees"
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
"lazy": [],
|
|
41
|
+
"attributes": []
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"groups": [
|
|
3
|
+
{
|
|
4
|
+
"resource": "/deviceDuplicateGroup",
|
|
5
|
+
"apikey": "JK09H3L12K09H3L123HJK0732L123HJK38K09H3",
|
|
6
|
+
"entity_type": "CommandMachinery",
|
|
7
|
+
"trust": "8970A9078A803H3BL98PINEQRW8342HBAMS",
|
|
8
|
+
"commands": [
|
|
9
|
+
{
|
|
10
|
+
"name": "wheel1",
|
|
11
|
+
"type": "Wheel"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"lazy": [
|
|
15
|
+
{
|
|
16
|
+
"name": "luminescence",
|
|
17
|
+
"type": "Lumens"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"attributes": [
|
|
21
|
+
{
|
|
22
|
+
"name": "status",
|
|
23
|
+
"type": "Boolean"
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
"static_attributes": [
|
|
27
|
+
{
|
|
28
|
+
"name": "bootstrapServer",
|
|
29
|
+
"type": "Address",
|
|
30
|
+
"value": "127.0.0.1"
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"groups": [
|
|
3
|
+
{
|
|
4
|
+
"resource": "/deviceTest",
|
|
5
|
+
"apikey": "801230BJKL23Y9090DSFL123HJK09H324HV8732",
|
|
6
|
+
"entity_type": "SensorMachine",
|
|
7
|
+
"trust": "8970A9078A803H3BL98PINEQRW8342HBAMS",
|
|
8
|
+
"cbHost": "http://unexistentHost:1026",
|
|
9
|
+
"commands": [
|
|
10
|
+
{
|
|
11
|
+
"name": "wheel1",
|
|
12
|
+
"type": "Wheel"
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"lazy": [
|
|
16
|
+
{
|
|
17
|
+
"name": "luminescence",
|
|
18
|
+
"type": "Lumens"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"attributes": [
|
|
22
|
+
{
|
|
23
|
+
"name": "status",
|
|
24
|
+
"type": "Boolean"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"static_attributes": [
|
|
28
|
+
{
|
|
29
|
+
"name": "bootstrapServer",
|
|
30
|
+
"type": "Address",
|
|
31
|
+
"value": "127.0.0.1"
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"groups": [
|
|
3
|
+
{
|
|
4
|
+
"resource": "/deviceTest",
|
|
5
|
+
"apikey": "754KL23Y9090DSFL123HSFL12380KL23Y2",
|
|
6
|
+
"entity_type": "AnotherMachine",
|
|
7
|
+
"trust": "8970A9078A803H3BL98PINEQRW8342HBAMS",
|
|
8
|
+
"cbHost": "http://unexistentHost:1026",
|
|
9
|
+
"commands": [
|
|
10
|
+
{
|
|
11
|
+
"name": "wheel1",
|
|
12
|
+
"type": "Wheel"
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"lazy": [
|
|
16
|
+
{
|
|
17
|
+
"name": "luminescence",
|
|
18
|
+
"type": "Lumens"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"attributes": [
|
|
22
|
+
{
|
|
23
|
+
"name": "status",
|
|
24
|
+
"type": "Boolean"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"static_attributes": [
|
|
28
|
+
{
|
|
29
|
+
"name": "bootstrapServer",
|
|
30
|
+
"type": "Address",
|
|
31
|
+
"value": "127.0.0.1"
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|
|
@@ -85,7 +85,8 @@ const iotAgentConfig = {
|
|
|
85
85
|
service: 'smartgondor',
|
|
86
86
|
subservice: 'gardens',
|
|
87
87
|
providerUrl: 'http://smartgondor.com',
|
|
88
|
-
deviceRegistrationDuration: 'P1M'
|
|
88
|
+
deviceRegistrationDuration: 'P1M',
|
|
89
|
+
useCBflowControl: true
|
|
89
90
|
};
|
|
90
91
|
|
|
91
92
|
describe('NGSI-v2 - Secured access to the Context Broker with Keystone', function () {
|
|
@@ -128,7 +129,7 @@ describe('NGSI-v2 - Secured access to the Context Broker with Keystone', functio
|
|
|
128
129
|
.matchHeader('fiware-service', 'smartgondor')
|
|
129
130
|
.matchHeader('fiware-servicepath', 'electricity')
|
|
130
131
|
.matchHeader('X-Auth-Token', '12345679ABCDEF')
|
|
131
|
-
.post('/v2/entities?options=upsert')
|
|
132
|
+
.post('/v2/entities?options=upsert,flowControl')
|
|
132
133
|
.reply(204);
|
|
133
134
|
iotAgentLib.activate(iotAgentConfig, done);
|
|
134
135
|
});
|
|
@@ -165,7 +166,7 @@ describe('NGSI-v2 - Secured access to the Context Broker with Keystone', functio
|
|
|
165
166
|
.matchHeader('fiware-service', 'smartgondor')
|
|
166
167
|
.matchHeader('fiware-servicepath', 'electricity')
|
|
167
168
|
.matchHeader('X-Auth-Token', '12345679ABCDEF')
|
|
168
|
-
.post('/v2/entities?options=upsert')
|
|
169
|
+
.post('/v2/entities?options=upsert,flowControl')
|
|
169
170
|
.reply(403, { name: 'ACCESS_FORBIDDEN' });
|
|
170
171
|
|
|
171
172
|
iotAgentLib.activate(iotAgentConfig, done);
|
|
@@ -197,7 +198,7 @@ describe('NGSI-v2 - Secured access to the Context Broker with Keystone', functio
|
|
|
197
198
|
.matchHeader('fiware-service', 'smartgondor')
|
|
198
199
|
.matchHeader('fiware-servicepath', 'electricity')
|
|
199
200
|
.matchHeader('X-Auth-Token', '12345679ABCDEF')
|
|
200
|
-
.post('/v2/entities?options=upsert');
|
|
201
|
+
.post('/v2/entities?options=upsert,flowControl');
|
|
201
202
|
|
|
202
203
|
iotAgentLib.activate(iotAgentConfig, done);
|
|
203
204
|
});
|
|
@@ -123,7 +123,8 @@ const iotAgentConfig = {
|
|
|
123
123
|
service: 'smartgondor',
|
|
124
124
|
subservice: 'gardens',
|
|
125
125
|
providerUrl: 'http://smartgondor.com',
|
|
126
|
-
deviceRegistrationDuration: 'P1M'
|
|
126
|
+
deviceRegistrationDuration: 'P1M',
|
|
127
|
+
useCBflowControl: true
|
|
127
128
|
};
|
|
128
129
|
const groupCreation = {
|
|
129
130
|
url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/services',
|
|
@@ -153,6 +154,36 @@ const groupCreation = {
|
|
|
153
154
|
'fiware-servicepath': '/testingPath'
|
|
154
155
|
}
|
|
155
156
|
};
|
|
157
|
+
|
|
158
|
+
const configGroupCreation = {
|
|
159
|
+
url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/groups',
|
|
160
|
+
method: 'POST',
|
|
161
|
+
json: {
|
|
162
|
+
groups: [
|
|
163
|
+
{
|
|
164
|
+
resource: '',
|
|
165
|
+
apikey: '801230BJKL23Y9090DSFL123HJK09H324HV8732',
|
|
166
|
+
entity_type: 'TheLightType',
|
|
167
|
+
trust: '8970A9078A803H3BL98PINEQRW8342HBAMS',
|
|
168
|
+
cbHost: 'http://192.168.1.1:1026',
|
|
169
|
+
commands: [],
|
|
170
|
+
lazy: [],
|
|
171
|
+
attributes: [
|
|
172
|
+
{
|
|
173
|
+
name: 'status',
|
|
174
|
+
type: 'Boolean'
|
|
175
|
+
}
|
|
176
|
+
],
|
|
177
|
+
static_attributes: []
|
|
178
|
+
}
|
|
179
|
+
]
|
|
180
|
+
},
|
|
181
|
+
headers: {
|
|
182
|
+
'fiware-service': 'testservice',
|
|
183
|
+
'fiware-servicepath': '/testingPath'
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
156
187
|
const deviceCreation = {
|
|
157
188
|
url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices',
|
|
158
189
|
method: 'POST',
|
|
@@ -180,6 +211,7 @@ describe('NGSI-v2 - Device Service: utils', function () {
|
|
|
180
211
|
async.series([iotAgentLib.clearAll, iotAgentLib.deactivate], done);
|
|
181
212
|
});
|
|
182
213
|
|
|
214
|
+
// #FIXME1649: this test will be removed if at the end /iot/services API (now Deprecated) is removed
|
|
183
215
|
describe('When an existing device tries to be retrieved with retrieveOrCreate()', function () {
|
|
184
216
|
beforeEach(function (done) {
|
|
185
217
|
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
@@ -191,7 +223,7 @@ describe('NGSI-v2 - Device Service: utils', function () {
|
|
|
191
223
|
contextBrokerMock
|
|
192
224
|
.matchHeader('fiware-service', 'testservice')
|
|
193
225
|
.matchHeader('fiware-servicepath', '/testingPath')
|
|
194
|
-
.post('/v2/entities?options=upsert')
|
|
226
|
+
.post('/v2/entities?options=upsert,flowControl')
|
|
195
227
|
.reply(204);
|
|
196
228
|
|
|
197
229
|
async.series(
|
|
@@ -213,6 +245,41 @@ describe('NGSI-v2 - Device Service: utils', function () {
|
|
|
213
245
|
});
|
|
214
246
|
});
|
|
215
247
|
|
|
248
|
+
describe('When an existing device tries to be retrieved with retrieveOrCreate()', function () {
|
|
249
|
+
beforeEach(function (done) {
|
|
250
|
+
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
251
|
+
.matchHeader('fiware-service', 'testservice')
|
|
252
|
+
.matchHeader('fiware-servicepath', '/testingPath')
|
|
253
|
+
.post('/v2/registrations')
|
|
254
|
+
.reply(201, null, { Location: '/v2/registrations/6319a7f5254b05844116584d' });
|
|
255
|
+
|
|
256
|
+
contextBrokerMock
|
|
257
|
+
.matchHeader('fiware-service', 'testservice')
|
|
258
|
+
.matchHeader('fiware-servicepath', '/testingPath')
|
|
259
|
+
.post('/v2/entities?options=upsert,flowControl')
|
|
260
|
+
.reply(204);
|
|
261
|
+
|
|
262
|
+
async.series(
|
|
263
|
+
[request.bind(request, configGroupCreation), request.bind(request, deviceCreation)],
|
|
264
|
+
function (error, results) {
|
|
265
|
+
done();
|
|
266
|
+
}
|
|
267
|
+
);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('should return the existing device', function (done) {
|
|
271
|
+
iotAgentLib.retrieveDevice('Light1', '801230BJKL23Y9090DSFL123HJK09H324HV8732', function (error, device) {
|
|
272
|
+
should.not.exist(error);
|
|
273
|
+
should.exist(device);
|
|
274
|
+
|
|
275
|
+
device.id.should.equal('Light1');
|
|
276
|
+
done();
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
// #FIXME1649: this test will be removed if at the end /iot/services API (now Deprecated) is removed
|
|
282
|
+
|
|
216
283
|
describe('When an unexisting device tries to be retrieved for an existing APIKey', function () {
|
|
217
284
|
beforeEach(function (done) {
|
|
218
285
|
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
@@ -224,7 +291,7 @@ describe('NGSI-v2 - Device Service: utils', function () {
|
|
|
224
291
|
contextBrokerMock
|
|
225
292
|
.matchHeader('fiware-service', 'testservice')
|
|
226
293
|
.matchHeader('fiware-servicepath', '/testingPath')
|
|
227
|
-
.post('/v2/entities?options=upsert')
|
|
294
|
+
.post('/v2/entities?options=upsert,flowControl')
|
|
228
295
|
.reply(204);
|
|
229
296
|
|
|
230
297
|
async.series([request.bind(request, groupCreation)], function (error, results) {
|
|
@@ -249,6 +316,42 @@ describe('NGSI-v2 - Device Service: utils', function () {
|
|
|
249
316
|
});
|
|
250
317
|
});
|
|
251
318
|
|
|
319
|
+
describe('When an unexisting device tries to be retrieved for an existing APIKey', function () {
|
|
320
|
+
beforeEach(function (done) {
|
|
321
|
+
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
322
|
+
.matchHeader('fiware-service', 'testservice')
|
|
323
|
+
.matchHeader('fiware-servicepath', '/testingPath')
|
|
324
|
+
.post('/v2/registrations')
|
|
325
|
+
.reply(201, null, { Location: '/v2/registrations/6319a7f5254b05844116584d' });
|
|
326
|
+
|
|
327
|
+
contextBrokerMock
|
|
328
|
+
.matchHeader('fiware-service', 'testservice')
|
|
329
|
+
.matchHeader('fiware-servicepath', '/testingPath')
|
|
330
|
+
.post('/v2/entities?options=upsert,flowControl')
|
|
331
|
+
.reply(204);
|
|
332
|
+
|
|
333
|
+
async.series([request.bind(request, configGroupCreation)], function (error, results) {
|
|
334
|
+
done();
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it('should register the device and return it', function (done) {
|
|
339
|
+
iotAgentLib.retrieveDevice(
|
|
340
|
+
'UNEXISTENT_DEV',
|
|
341
|
+
'801230BJKL23Y9090DSFL123HJK09H324HV8732',
|
|
342
|
+
function (error, device) {
|
|
343
|
+
should.not.exist(error);
|
|
344
|
+
should.exist(device);
|
|
345
|
+
|
|
346
|
+
device.id.should.equal('UNEXISTENT_DEV');
|
|
347
|
+
should.exist(device.protocol);
|
|
348
|
+
device.protocol.should.equal('MQTT_UL');
|
|
349
|
+
done();
|
|
350
|
+
}
|
|
351
|
+
);
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
|
|
252
355
|
describe('When an unexisting device tries to be retrieved for an unexisting APIKey', function () {
|
|
253
356
|
it('should raise an error', function (done) {
|
|
254
357
|
iotAgentLib.retrieveDevice(
|
|
@@ -35,9 +35,6 @@ const iotAgentConfig = {
|
|
|
35
35
|
host: 'localhost',
|
|
36
36
|
baseRoot: '/'
|
|
37
37
|
},
|
|
38
|
-
stats: {
|
|
39
|
-
interval: 100
|
|
40
|
-
},
|
|
41
38
|
types: {},
|
|
42
39
|
service: 'smartgondor',
|
|
43
40
|
subservice: 'gardens',
|
|
@@ -51,9 +48,7 @@ describe('Statistics service', function () {
|
|
|
51
48
|
oldConfig = commonConfig.getConfig();
|
|
52
49
|
commonConfig.setConfig(iotAgentConfig);
|
|
53
50
|
|
|
54
|
-
statsService.globalLoad({},
|
|
55
|
-
statsService.clearTimers(done);
|
|
56
|
-
});
|
|
51
|
+
statsService.globalLoad({}, done);
|
|
57
52
|
});
|
|
58
53
|
|
|
59
54
|
afterEach(function (done) {
|
|
@@ -74,16 +69,6 @@ describe('Statistics service', function () {
|
|
|
74
69
|
);
|
|
75
70
|
});
|
|
76
71
|
|
|
77
|
-
it('should appear the modified value in the getCurrent() statistics', function (done) {
|
|
78
|
-
statsService.add(statName, statValue, function () {
|
|
79
|
-
statsService.getCurrent(statName, function (error, value) {
|
|
80
|
-
should.not.exist(error);
|
|
81
|
-
should.exist(value);
|
|
82
|
-
value.should.equal(statValue);
|
|
83
|
-
done();
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
72
|
it('should add the value to the global values', function (done) {
|
|
88
73
|
statsService.add(statName, statValue, function () {
|
|
89
74
|
statsService.getGlobal(statName, function (error, value) {
|
|
@@ -119,62 +104,4 @@ describe('Statistics service', function () {
|
|
|
119
104
|
});
|
|
120
105
|
});
|
|
121
106
|
});
|
|
122
|
-
describe('When the current statistics are reset', function () {
|
|
123
|
-
beforeEach(function (done) {
|
|
124
|
-
statsService.add('statA', 42, function () {
|
|
125
|
-
statsService.add('statB', 52, done);
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('should return a value of zero for any of the individual statistics', function (done) {
|
|
130
|
-
statsService.resetCurrent(function (error) {
|
|
131
|
-
should.not.exist(error);
|
|
132
|
-
|
|
133
|
-
statsService.getAllCurrent(function (error, data) {
|
|
134
|
-
should.exist(data);
|
|
135
|
-
should.exist(data.statA);
|
|
136
|
-
should.exist(data.statB);
|
|
137
|
-
data.statA.should.equal(0);
|
|
138
|
-
data.statB.should.equal(0);
|
|
139
|
-
done();
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
describe('When a new periodic stats action is set', function () {
|
|
145
|
-
let valueCurrent = 0;
|
|
146
|
-
let valueGlobal = 0;
|
|
147
|
-
let times = 0;
|
|
148
|
-
|
|
149
|
-
beforeEach(function (done) {
|
|
150
|
-
statsService.globalLoad(
|
|
151
|
-
{
|
|
152
|
-
stat1: 10
|
|
153
|
-
},
|
|
154
|
-
function () {
|
|
155
|
-
statsService.add('stat1', 5, done);
|
|
156
|
-
}
|
|
157
|
-
);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
function mockedAction(current, global, callback) {
|
|
161
|
-
valueCurrent = current.stat1;
|
|
162
|
-
valueGlobal = global.stat1;
|
|
163
|
-
times++;
|
|
164
|
-
callback();
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
it('should be triggered with the periodicity stated in the config.stats.interval parameter', function (done) {
|
|
168
|
-
statsService.addTimerAction(mockedAction, function () {
|
|
169
|
-
setTimeout(function () {
|
|
170
|
-
statsService.clearTimers(function () {
|
|
171
|
-
valueCurrent.should.equal(5);
|
|
172
|
-
valueGlobal.should.equal(15);
|
|
173
|
-
times.should.equal(4);
|
|
174
|
-
done();
|
|
175
|
-
});
|
|
176
|
-
}, 480);
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
107
|
});
|
|
@@ -48,7 +48,8 @@ const iotAgentConfig = {
|
|
|
48
48
|
service: 'smartgondor',
|
|
49
49
|
subservice: 'gardens',
|
|
50
50
|
providerUrl: 'http://smartgondor.com',
|
|
51
|
-
deviceRegistrationDuration: 'P1M'
|
|
51
|
+
deviceRegistrationDuration: 'P1M',
|
|
52
|
+
useCBflowControl: true
|
|
52
53
|
};
|
|
53
54
|
let contextBrokerMock;
|
|
54
55
|
|
|
@@ -64,7 +65,7 @@ describe('NGSI-v2 - In memory device registry', function () {
|
|
|
64
65
|
describe('When a the registry is queried for a device using an arbitrary attribute', function () {
|
|
65
66
|
beforeEach(function (done) {
|
|
66
67
|
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
67
|
-
.post('/v2/entities?options=upsert')
|
|
68
|
+
.post('/v2/entities?options=upsert,flowControl')
|
|
68
69
|
.times(10)
|
|
69
70
|
.matchHeader('fiware-service', 'smartgondor')
|
|
70
71
|
.matchHeader('fiware-servicepath', 'gardens')
|
|
@@ -116,7 +117,7 @@ describe('NGSI-v2 - In memory device registry', function () {
|
|
|
116
117
|
describe('When a the registry is queried for devices in multiple services', function () {
|
|
117
118
|
beforeEach(function (done) {
|
|
118
119
|
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
119
|
-
.post('/v2/entities?options=upsert')
|
|
120
|
+
.post('/v2/entities?options=upsert,flowControl')
|
|
120
121
|
.times(10)
|
|
121
122
|
.reply(204);
|
|
122
123
|
|
|
@@ -159,7 +160,7 @@ describe('NGSI-v2 - In memory device registry', function () {
|
|
|
159
160
|
describe('When a the registry is queried for devices in a particular service', function () {
|
|
160
161
|
beforeEach(function (done) {
|
|
161
162
|
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
162
|
-
.post('/v2/entities?options=upsert')
|
|
163
|
+
.post('/v2/entities?options=upsert,flowControl')
|
|
163
164
|
.times(10)
|
|
164
165
|
.reply(204);
|
|
165
166
|
|
|
@@ -202,7 +203,7 @@ describe('NGSI-v2 - In memory device registry', function () {
|
|
|
202
203
|
describe('When a the registry is queried for device in a particular name and type', function () {
|
|
203
204
|
beforeEach(function (done) {
|
|
204
205
|
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
205
|
-
.post('/v2/entities?options=upsert')
|
|
206
|
+
.post('/v2/entities?options=upsert,flowControl')
|
|
206
207
|
.times(10)
|
|
207
208
|
.reply(204);
|
|
208
209
|
|