Skip to content

Commit 339895c

Browse files
authored
Merge pull request #822 from telefonicaid/task/add_test_multimeasure_with_timeinstant
Task/add test cases about multimeasure with timeinstant mapped attribute
2 parents ae0eef5 + 285df88 commit 339895c

File tree

6 files changed

+376
-4
lines changed

6 files changed

+376
-4
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"devices": [
3+
{
4+
"attributes": [
5+
{
6+
"type": "percent",
7+
"name": "humidity",
8+
"object_id": "h"
9+
}
10+
],
11+
"entity_type": "sensor",
12+
"protocol": "IoTA-JSON",
13+
"entity_name": "e0130101",
14+
"device_id": "dev0130101",
15+
"explicitAttrs": false,
16+
"timestamp": true
17+
}
18+
]
19+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"devices": [
3+
{
4+
"attributes": [
5+
{
6+
"type": "datetime",
7+
"name": "TimeInstant",
8+
"object_id": "myTimeInstant"
9+
},
10+
{
11+
"type": "percent",
12+
"name": "humidity",
13+
"object_id": "h"
14+
}
15+
],
16+
"entity_type": "sensor",
17+
"protocol": "IoTA-JSON",
18+
"entity_name": "e0130101",
19+
"device_id": "dev0130101",
20+
"explicitAttrs": false,
21+
"timestamp": true
22+
}
23+
]
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"devices": [
3+
{
4+
"attributes": [
5+
{
6+
"type": "datetime",
7+
"name": "TimeInstant",
8+
"object_id": "TimeInstant"
9+
},
10+
{
11+
"type": "percent",
12+
"name": "humidity",
13+
"object_id": "h"
14+
}
15+
],
16+
"entity_type": "sensor",
17+
"protocol": "IoTA-JSON",
18+
"entity_name": "e0130101",
19+
"device_id": "dev0130101",
20+
"explicitAttrs": false,
21+
"timestamp": true
22+
}
23+
]
24+
}

test/unit/ngsiv2/HTTP_reveice_measures-test2.js

Lines changed: 273 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ describe('HTTP: Measure reception ', function () {
171171
});
172172
});
173173

174-
describe('When a POST multimeasure arrives with a TimeInstant attribute in the body', function () {
174+
describe('When a POST multimeasure arrives with a the same TimeInstant attribute in the body', function () {
175175
const optionsMeasure = {
176176
url: 'http://localhost:' + config.http.port + '/iot/json',
177177
method: 'POST',
@@ -248,14 +248,283 @@ describe('HTTP: Measure reception ', function () {
248248
});
249249
});
250250

251+
describe('When a POST multimeasure arrives with different TimeInstant attribute in the body', function () {
252+
const optionsMeasure = {
253+
url: 'http://localhost:' + config.http.port + '/iot/json',
254+
method: 'POST',
255+
json: [
256+
{
257+
h: '111222',
258+
TimeInstant: '2020-02-22T22:22:22Z'
259+
},
260+
{
261+
h: '111333',
262+
TimeInstant: '2023-03-23T23:33:33Z'
263+
},
264+
{
265+
h: '111111'
266+
}
267+
],
268+
headers: {
269+
'fiware-service': 'smartgondor',
270+
'fiware-servicepath': '/gardens'
271+
},
272+
qs: {
273+
i: 'dev0130101',
274+
k: '1234'
275+
}
276+
};
277+
const provisionOptions = {
278+
url: 'http://localhost:' + config.iota.server.port + '/iot/devices',
279+
method: 'POST',
280+
json: utils.readExampleFile('./test/deviceProvisioning/provisionDeviceTimeinstant3.json'),
281+
headers: {
282+
'fiware-service': 'smartgondor',
283+
'fiware-servicepath': '/gardens'
284+
}
285+
};
286+
287+
beforeEach(function (done) {
288+
nock.cleanAll();
289+
// This mock does not check the payload since the aim of the test is not to verify
290+
// device provisioning functionality. Appropriate verification is done in tests under
291+
// provisioning folder of iotagent-node-lib
292+
contextBrokerMock = nock('http://192.168.1.1:1026');
293+
294+
contextBrokerMock
295+
.matchHeader('fiware-service', 'smartgondor')
296+
.matchHeader('fiware-servicepath', '/gardens')
297+
.post(
298+
'/v2/entities?options=upsert',
299+
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures1b.json')
300+
)
301+
.reply(204);
302+
303+
contextBrokerMock
304+
.matchHeader('fiware-service', 'smartgondor')
305+
.matchHeader('fiware-servicepath', '/gardens')
306+
.post(
307+
'/v2/entities?options=upsert',
308+
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures2b.json')
309+
)
310+
.reply(204);
311+
312+
contextBrokerMock
313+
.matchHeader('fiware-service', 'smartgondor')
314+
.matchHeader('fiware-servicepath', '/gardens')
315+
.post(
316+
'/v2/entities?options=upsert'
317+
// FIXME: Mock about h atttribute + current timestamp
318+
//utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures.json')
319+
)
320+
.reply(204);
321+
322+
iotaJson.stop(function () {
323+
iotaJson.start(config, function () {
324+
request(provisionOptions, function (error, response, body) {
325+
done();
326+
});
327+
});
328+
});
329+
});
330+
331+
afterEach(function () {});
332+
333+
it('should send its value to the Context Broker', function (done) {
334+
request(optionsMeasure, function (error, result, body) {
335+
contextBrokerMock.done();
336+
done();
337+
});
338+
});
339+
});
340+
341+
describe('When a POST multimeasure arrives with different TimeInstant mapped attribute in the body', function () {
342+
const optionsMeasure = {
343+
url: 'http://localhost:' + config.http.port + '/iot/json',
344+
method: 'POST',
345+
json: [
346+
{
347+
h: '111222',
348+
myTimeInstant: '2020-02-22T22:22:22Z'
349+
},
350+
{
351+
h: '111333',
352+
myTimeInstant: '2023-03-23T23:33:33Z'
353+
},
354+
{
355+
h: '111111'
356+
}
357+
],
358+
headers: {
359+
'fiware-service': 'smartgondor',
360+
'fiware-servicepath': '/gardens'
361+
},
362+
qs: {
363+
i: 'dev0130101',
364+
k: '1234'
365+
}
366+
};
367+
const provisionOptions = {
368+
url: 'http://localhost:' + config.iota.server.port + '/iot/devices',
369+
method: 'POST',
370+
json: utils.readExampleFile('./test/deviceProvisioning/provisionDeviceTimeinstant4.json'),
371+
headers: {
372+
'fiware-service': 'smartgondor',
373+
'fiware-servicepath': '/gardens'
374+
}
375+
};
376+
377+
beforeEach(function (done) {
378+
nock.cleanAll();
379+
// This mock does not check the payload since the aim of the test is not to verify
380+
// device provisioning functionality. Appropriate verification is done in tests under
381+
// provisioning folder of iotagent-node-lib
382+
contextBrokerMock = nock('http://192.168.1.1:1026');
383+
384+
contextBrokerMock
385+
.matchHeader('fiware-service', 'smartgondor')
386+
.matchHeader('fiware-servicepath', '/gardens')
387+
.post(
388+
'/v2/entities?options=upsert',
389+
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures1b.json')
390+
)
391+
.reply(204);
392+
393+
contextBrokerMock
394+
.matchHeader('fiware-service', 'smartgondor')
395+
.matchHeader('fiware-servicepath', '/gardens')
396+
.post(
397+
'/v2/entities?options=upsert',
398+
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures2b.json')
399+
)
400+
.reply(204);
401+
402+
contextBrokerMock
403+
.matchHeader('fiware-service', 'smartgondor')
404+
.matchHeader('fiware-servicepath', '/gardens')
405+
.post(
406+
'/v2/entities?options=upsert'
407+
// FIXME: Mock about h atttribute + current timestamp
408+
//utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures.json')
409+
)
410+
.reply(204);
411+
412+
iotaJson.stop(function () {
413+
iotaJson.start(config, function () {
414+
request(provisionOptions, function (error, response, body) {
415+
done();
416+
});
417+
});
418+
});
419+
});
420+
421+
afterEach(function () {});
422+
423+
it('should send its value to the Context Broker', function (done) {
424+
request(optionsMeasure, function (error, result, body) {
425+
contextBrokerMock.done();
426+
done();
427+
});
428+
});
429+
});
430+
431+
describe('When a POST multimeasure arrives with different TimeInstant mapped timestamp attribute in the body', function () {
432+
const optionsMeasure = {
433+
url: 'http://localhost:' + config.http.port + '/iot/json',
434+
method: 'POST',
435+
json: [
436+
{
437+
h: '111222',
438+
TimeInstant: '2020-02-22T22:22:22Z'
439+
},
440+
{
441+
h: '111333',
442+
TimeInstant: '2023-03-23T23:33:33Z'
443+
},
444+
{
445+
h: '111111'
446+
}
447+
],
448+
headers: {
449+
'fiware-service': 'smartgondor',
450+
'fiware-servicepath': '/gardens'
451+
},
452+
qs: {
453+
i: 'dev0130101',
454+
k: '1234'
455+
}
456+
};
457+
const provisionOptions = {
458+
url: 'http://localhost:' + config.iota.server.port + '/iot/devices',
459+
method: 'POST',
460+
json: utils.readExampleFile('./test/deviceProvisioning/provisionDeviceTimeinstant5.json'),
461+
headers: {
462+
'fiware-service': 'smartgondor',
463+
'fiware-servicepath': '/gardens'
464+
}
465+
};
466+
467+
beforeEach(function (done) {
468+
nock.cleanAll();
469+
// This mock does not check the payload since the aim of the test is not to verify
470+
// device provisioning functionality. Appropriate verification is done in tests under
471+
// provisioning folder of iotagent-node-lib
472+
contextBrokerMock = nock('http://192.168.1.1:1026');
473+
474+
contextBrokerMock
475+
.matchHeader('fiware-service', 'smartgondor')
476+
.matchHeader('fiware-servicepath', '/gardens')
477+
.post(
478+
'/v2/entities?options=upsert',
479+
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures1b.json')
480+
)
481+
.reply(204);
482+
483+
contextBrokerMock
484+
.matchHeader('fiware-service', 'smartgondor')
485+
.matchHeader('fiware-servicepath', '/gardens')
486+
.post(
487+
'/v2/entities?options=upsert',
488+
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures2b.json')
489+
)
490+
.reply(204);
491+
492+
contextBrokerMock
493+
.matchHeader('fiware-service', 'smartgondor')
494+
.matchHeader('fiware-servicepath', '/gardens')
495+
.post(
496+
'/v2/entities?options=upsert'
497+
// FIXME: Mock about h atttribute + current timestamp
498+
//utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures.json')
499+
)
500+
.reply(204);
501+
502+
iotaJson.stop(function () {
503+
iotaJson.start(config, function () {
504+
request(provisionOptions, function (error, response, body) {
505+
done();
506+
});
507+
});
508+
});
509+
});
510+
511+
afterEach(function () {});
512+
513+
it('should send its value to the Context Broker', function (done) {
514+
request(optionsMeasure, function (error, result, body) {
515+
contextBrokerMock.done();
516+
done();
517+
});
518+
});
519+
});
520+
251521
describe('When a POST multimeasure arrives with a TimeInstant query parameter in the body', function () {
252522
const optionsMeasure = {
253523
url: 'http://localhost:' + config.http.port + '/iot/json',
254524
method: 'POST',
255525
json: [
256526
{
257527
h: '111222'
258-
259528
},
260529
{
261530
h: '111333'
@@ -267,8 +536,8 @@ describe('HTTP: Measure reception ', function () {
267536
},
268537
qs: {
269538
i: 'dev0130101',
270-
k: '1234' ,
271-
t:'2020-02-22T22:22:22Z'
539+
k: '1234',
540+
t: '2020-02-22T22:22:22Z'
272541
}
273542
};
274543
const provisionOptions = {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"id":"e0130101",
3+
"type":"sensor",
4+
"humidity":{
5+
"type": "percent",
6+
"value": "111222",
7+
"metadata": {
8+
"TimeInstant": {
9+
"type": "DateTime",
10+
"value": "2020-02-22T22:22:22Z"
11+
}
12+
}
13+
},
14+
"TimeInstant":{
15+
"type": "DateTime",
16+
"value": "2020-02-22T22:22:22Z"
17+
}
18+
}

0 commit comments

Comments
 (0)