iotagent-node-lib 4.4.0 → 4.5.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/config.js +2 -1
- package/doc/admin.md +16 -7
- package/doc/api.md +183 -52
- package/doc/requirements.txt +1 -1
- package/lib/commonConfig.js +7 -1
- 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/ngsi/entities-NGSI-LD.js +1 -1
- package/lib/services/ngsi/entities-NGSI-v2.js +313 -281
- package/lib/services/ngsi/subscription-NGSI-LD.js +2 -2
- package/lib/services/ngsi/subscription-NGSI-v2.js +2 -2
- package/lib/services/northBound/deviceProvisioningServer.js +5 -4
- package/lib/services/northBound/northboundServer.js +2 -2
- package/package.json +1 -1
- package/test/functional/README.md +60 -37
- package/test/functional/testCases.js +1017 -264
- package/test/functional/testUtils.js +53 -20
- package/test/unit/examples/deviceProvisioningRequests/updateProvisionDeviceWithApikey.json +4 -0
- package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +5 -5
- package/test/unit/ngsiv2/provisioning/device-update-registration_test.js +6 -6
- package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +35 -0
|
@@ -98,28 +98,61 @@ function sendMeasureIotaLib(measure, provision) {
|
|
|
98
98
|
* @param {Object} json
|
|
99
99
|
* @returns {Array} measures
|
|
100
100
|
*/
|
|
101
|
-
function jsonToIotaMeasures(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
101
|
+
function jsonToIotaMeasures(originJson) {
|
|
102
|
+
// FIXME: maybe this could be refactored to use less code
|
|
103
|
+
if (originJson && originJson[0]) {
|
|
104
|
+
// multimeasure case
|
|
105
|
+
let finalMeasures = [];
|
|
106
|
+
|
|
107
|
+
for (let json of originJson) {
|
|
108
|
+
let measures = [];
|
|
109
|
+
for (let key in json) {
|
|
110
|
+
/* eslint-disable-next-line no-prototype-builtins */
|
|
111
|
+
if (json.hasOwnProperty(key)) {
|
|
112
|
+
let measure = {
|
|
113
|
+
name: key,
|
|
114
|
+
value: json[key]
|
|
115
|
+
};
|
|
116
|
+
// A bit of Magic. If the key is TimeInstant, we set the type to DateTime.
|
|
117
|
+
// When sending the data through iot
|
|
118
|
+
if (key === 'TimeInstant') {
|
|
119
|
+
measure.type = 'DateTime';
|
|
120
|
+
} else {
|
|
121
|
+
// Although the type is not meaningfull and we could have picked any string for this,
|
|
122
|
+
// we have aligned with DEFAULT_ATTRIBUTE_TYPE constant in IOTA-JSON and IOTA-UL repositories
|
|
123
|
+
measure.type = 'Text';
|
|
124
|
+
}
|
|
125
|
+
measures.push(measure);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
finalMeasures.push(measures);
|
|
129
|
+
}
|
|
130
|
+
return finalMeasures;
|
|
131
|
+
} else {
|
|
132
|
+
let json = originJson;
|
|
133
|
+
|
|
134
|
+
let measures = [];
|
|
135
|
+
for (let key in json) {
|
|
136
|
+
/* eslint-disable-next-line no-prototype-builtins */
|
|
137
|
+
if (json.hasOwnProperty(key)) {
|
|
138
|
+
let measure = {
|
|
139
|
+
name: key,
|
|
140
|
+
value: json[key]
|
|
141
|
+
};
|
|
142
|
+
// A bit of Magic. If the key is TimeInstant, we set the type to DateTime.
|
|
143
|
+
// When sending the data through iot
|
|
144
|
+
if (key === 'TimeInstant') {
|
|
145
|
+
measure.type = 'DateTime';
|
|
146
|
+
} else {
|
|
147
|
+
// Although the type is not meaningfull and we could have picked any string for this,
|
|
148
|
+
// we have aligned with DEFAULT_ATTRIBUTE_TYPE constant in IOTA-JSON and IOTA-UL repositories
|
|
149
|
+
measure.type = 'Text';
|
|
150
|
+
}
|
|
151
|
+
measures.push(measure);
|
|
118
152
|
}
|
|
119
|
-
measures.push(measure);
|
|
120
153
|
}
|
|
154
|
+
return measures;
|
|
121
155
|
}
|
|
122
|
-
return measures;
|
|
123
156
|
}
|
|
124
157
|
|
|
125
158
|
/**
|
|
@@ -170,7 +203,7 @@ async function testCase(measure, expectation, provision, env, config, type, tran
|
|
|
170
203
|
let receivedContext = [];
|
|
171
204
|
let cbMockRoute = '';
|
|
172
205
|
// Set the correct route depending if the test is multientity or not
|
|
173
|
-
if (type === 'multientity') {
|
|
206
|
+
if (type === 'multientity' || type === 'multimeasure') {
|
|
174
207
|
cbMockRoute = '/v2/op/update';
|
|
175
208
|
} else {
|
|
176
209
|
cbMockRoute = '/v2/entities?options=upsert';
|
|
@@ -186,14 +186,14 @@ describe('NGSI-LD - IoT Agent Device Update Registration', function () {
|
|
|
186
186
|
});
|
|
187
187
|
|
|
188
188
|
it('should register as ContextProvider of its lazy attributes', function (done) {
|
|
189
|
-
iotAgentLib.updateRegister(deviceUpdated, false, function (error) {
|
|
189
|
+
iotAgentLib.updateRegister(deviceUpdated, device1, false, function (error) {
|
|
190
190
|
should.not.exist(error);
|
|
191
191
|
contextBrokerMock.done();
|
|
192
192
|
done();
|
|
193
193
|
});
|
|
194
194
|
});
|
|
195
195
|
it('should store the new values in the registry', function (done) {
|
|
196
|
-
iotAgentLib.updateRegister(deviceUpdated, false, function (error, data) {
|
|
196
|
+
iotAgentLib.updateRegister(deviceUpdated, device1, false, function (error, data) {
|
|
197
197
|
iotAgentLib.getDevice(deviceUpdated.id, null, 'smartgondor', 'gardens', function (error, deviceResult) {
|
|
198
198
|
should.not.exist(error);
|
|
199
199
|
should.exist(deviceResult);
|
|
@@ -236,7 +236,7 @@ describe('NGSI-LD - IoT Agent Device Update Registration', function () {
|
|
|
236
236
|
// });
|
|
237
237
|
// });
|
|
238
238
|
it('should store the new values in the registry', function (done) {
|
|
239
|
-
iotAgentLib.updateRegister(deviceCommandUpdated, false, function (error, data) {
|
|
239
|
+
iotAgentLib.updateRegister(deviceCommandUpdated, device1, false, function (error, data) {
|
|
240
240
|
iotAgentLib.getDevice(
|
|
241
241
|
deviceCommandUpdated.id,
|
|
242
242
|
null,
|
|
@@ -257,7 +257,7 @@ describe('NGSI-LD - IoT Agent Device Update Registration', function () {
|
|
|
257
257
|
|
|
258
258
|
describe('When a update action is executed in a non registered device', function () {
|
|
259
259
|
it('should return a DEVICE_NOT_FOUND error', function (done) {
|
|
260
|
-
iotAgentLib.updateRegister(unknownDevice, false, function (error) {
|
|
260
|
+
iotAgentLib.updateRegister(unknownDevice, device1, false, function (error) {
|
|
261
261
|
should.exist(error);
|
|
262
262
|
error.name.should.equal('DEVICE_NOT_FOUND');
|
|
263
263
|
done();
|
|
@@ -273,7 +273,7 @@ describe('NGSI-LD - IoT Agent Device Update Registration', function () {
|
|
|
273
273
|
});
|
|
274
274
|
|
|
275
275
|
it('should return a REGISTRATION_ERROR error in the update action', function (done) {
|
|
276
|
-
iotAgentLib.updateRegister(deviceUpdated, false, function (error) {
|
|
276
|
+
iotAgentLib.updateRegister(deviceUpdated, device1, false, function (error) {
|
|
277
277
|
should.exist(error);
|
|
278
278
|
//error.name.should.equal('UNREGISTRATION_ERROR');
|
|
279
279
|
done();
|
|
@@ -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();
|
|
@@ -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',
|