From 85a0eee50a48cccb54c8563a1f8caf821ba4ab2f Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Tue, 21 May 2024 16:38:38 +0200 Subject: [PATCH] update httpBinding test --- .../ngsiv2/contextRequests/multimeasure.json | 21 + .../ngsiv2/contextRequests/multimeasure2.json | 29 + .../ngsiv2/contextRequests/multimeasure3.json | 499 ++++++++++++++++++ test/unit/ngsiv2/httpBindings-test.js | 54 +- 4 files changed, 555 insertions(+), 48 deletions(-) create mode 100644 test/unit/ngsiv2/contextRequests/multimeasure.json create mode 100644 test/unit/ngsiv2/contextRequests/multimeasure2.json create mode 100644 test/unit/ngsiv2/contextRequests/multimeasure3.json diff --git a/test/unit/ngsiv2/contextRequests/multimeasure.json b/test/unit/ngsiv2/contextRequests/multimeasure.json new file mode 100644 index 00000000..3802eafb --- /dev/null +++ b/test/unit/ngsiv2/contextRequests/multimeasure.json @@ -0,0 +1,21 @@ +{ + "actionType": "append", + "entities": [ + { + "id": "Second UL Device", + "type": "AnMQTTDevice", + "temperature": { + "type": "celsius", + "value": 23 + } + }, + { + "id": "Second UL Device", + "type": "AnMQTTDevice", + "humidity": { + "type": "degrees", + "value": 98 + } + } + ] +} diff --git a/test/unit/ngsiv2/contextRequests/multimeasure2.json b/test/unit/ngsiv2/contextRequests/multimeasure2.json new file mode 100644 index 00000000..55c8bb70 --- /dev/null +++ b/test/unit/ngsiv2/contextRequests/multimeasure2.json @@ -0,0 +1,29 @@ +{ + "actionType": "append", + "entities": [ + { + "id": "Second UL Device", + "type": "AnMQTTDevice", + "temperature": { + "type": "celsius", + "value": 23 + }, + "humidity": { + "type": "degrees", + "value": 98 + } + }, + { + "id": "Second UL Device", + "type": "AnMQTTDevice", + "temperature": { + "type": "celsius", + "value": 16 + }, + "humidity": { + "type": "degrees", + "value": 34 + } + } + ] +} diff --git a/test/unit/ngsiv2/contextRequests/multimeasure3.json b/test/unit/ngsiv2/contextRequests/multimeasure3.json new file mode 100644 index 00000000..2667a40b --- /dev/null +++ b/test/unit/ngsiv2/contextRequests/multimeasure3.json @@ -0,0 +1,499 @@ +{ + "actionType": "append", + "entities": [ + { + "id": "urn:x-iot:smartsantander:u7jcfa:fixed:t311", + "type": "repeater:illuminance", + "att_name": { + "type": "string", + "value": "value", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "coords": { + "type": "string", + "value": "WGS84", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "temperature:ambient": { + "type": "float", + "value": 24.4, + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + }, + { + "id": "urn:x-iot:smartsantander:u7jcfa:fixed:t311", + "type": "repeater:illuminance", + "att_name": { + "type": "string", + "value": "value", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "coords": { + "type": "string", + "value": "WGS84", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "hum": { + "type": "Text", + "value": 58, + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + }, + { + "id": "urn:x-iot:smartsantander:u7jcfa:fixed:t311", + "type": "repeater:illuminance", + "att_name": { + "type": "string", + "value": "value", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "coords": { + "type": "string", + "value": "WGS84", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "aco": { + "type": "Text", + "value": 0.1, + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + }, + { + "id": "urn:x-iot:smartsantander:u7jcfa:fixed:t311", + "type": "repeater:illuminance", + "att_name": { + "type": "string", + "value": "value", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "coords": { + "type": "string", + "value": "WGS84", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "apa": { + "type": "Text", + "value": 0.38, + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + }, + { + "id": "urn:x-iot:smartsantander:u7jcfa:fixed:t311", + "type": "repeater:illuminance", + "att_name": { + "type": "string", + "value": "value", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "coords": { + "type": "string", + "value": "WGS84", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "ao3": { + "type": "Text", + "value": 121, + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + }, + { + "id": "urn:x-iot:smartsantander:u7jcfa:fixed:t311", + "type": "repeater:illuminance", + "att_name": { + "type": "string", + "value": "value", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "coords": { + "type": "string", + "value": "WGS84", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "no2": { + "type": "Text", + "value": 115, + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + }, + { + "id": "urn:x-iot:smartsantander:u7jcfa:fixed:t311", + "type": "repeater:illuminance", + "att_name": { + "type": "string", + "value": "value", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "coords": { + "type": "string", + "value": "WGS84", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "pla": { + "type": "Text", + "value": 43.4551, + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + }, + { + "id": "urn:x-iot:smartsantander:u7jcfa:fixed:t311", + "type": "repeater:illuminance", + "att_name": { + "type": "string", + "value": "value", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "coords": { + "type": "string", + "value": "WGS84", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "plo": { + "type": "Text", + "value": -3.83381, + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + }, + { + "id": "urn:x-iot:smartsantander:u7jcfa:fixed:t311", + "type": "repeater:illuminance", + "att_name": { + "type": "string", + "value": "value", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "coords": { + "type": "string", + "value": "WGS84", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "poa": { + "type": "Text", + "value": 28, + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + }, + { + "id": "urn:x-iot:smartsantander:u7jcfa:fixed:t311", + "type": "repeater:illuminance", + "att_name": { + "type": "string", + "value": "value", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "coords": { + "type": "string", + "value": "WGS84", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "spi": { + "type": "Text", + "value": 0, + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + }, + { + "id": "urn:x-iot:smartsantander:u7jcfa:fixed:t311", + "type": "repeater:illuminance", + "att_name": { + "type": "string", + "value": "value", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "coords": { + "type": "string", + "value": "WGS84", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "dia": { + "type": "Text", + "value": 0, + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + }, + { + "id": "urn:x-iot:smartsantander:u7jcfa:fixed:t311", + "type": "repeater:illuminance", + "att_name": { + "type": "string", + "value": "value", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "coords": { + "type": "string", + "value": "WGS84", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "mit": { + "type": "Text", + "value": 1492, + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + }, + { + "id": "urn:x-iot:smartsantander:u7jcfa:fixed:t311", + "type": "repeater:illuminance", + "att_name": { + "type": "string", + "value": "value", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "coords": { + "type": "string", + "value": "WGS84", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "pos": { + "type": "Text", + "value": "43.4630608,-3.8345434", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + }, + "TimeInstant": { + "type": "DateTime", + "value": "2024-05-21T16:33:16.657+02:00" + } + } + ] +} diff --git a/test/unit/ngsiv2/httpBindings-test.js b/test/unit/ngsiv2/httpBindings-test.js index 6bdc3b79..056dd7a3 100644 --- a/test/unit/ngsiv2/httpBindings-test.js +++ b/test/unit/ngsiv2/httpBindings-test.js @@ -391,19 +391,7 @@ describe('HTTP Transport binding: measures', function () { contextBrokerMock .matchHeader('fiware-service', 'smartgondor') .matchHeader('fiware-servicepath', '/gardens') - .post( - '/v2/entities?options=upsert', - utils.readExampleFile('./test/unit/ngsiv2/contextRequests/singleMeasure.json') - ) - .reply(204); - - contextBrokerMock - .matchHeader('fiware-service', 'smartgondor') - .matchHeader('fiware-servicepath', '/gardens') - .post( - '/v2/entities?options=upsert', - utils.readExampleFile('./test/unit/ngsiv2/contextRequests/secondSingleMeasure.json') - ) + .post('/v2/op/update', utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multimeasure.json')) .reply(204); }); @@ -440,19 +428,7 @@ describe('HTTP Transport binding: measures', function () { contextBrokerMock .matchHeader('fiware-service', 'smartgondor') .matchHeader('fiware-servicepath', '/gardens') - .post( - '/v2/entities?options=upsert', - utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasure.json') - ) - .reply(204); - - contextBrokerMock - .matchHeader('fiware-service', 'smartgondor') - .matchHeader('fiware-servicepath', '/gardens') - .post( - '/v2/entities?options=upsert', - utils.readExampleFile('./test/unit/ngsiv2/contextRequests/secondMultipleMeasure.json') - ) + .post('/v2/op/update', utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multimeasure2.json')) .reply(204); }); @@ -650,28 +626,10 @@ describe('HTTP Transport binding: measures', function () { contextBrokerMock .matchHeader('fiware-service', 'smartgondor') .matchHeader('fiware-servicepath', '/gardens') - // Note: The expected body payload is not set explicitly since this mock will be used to - // intercept requests from the IOTA to the CB for each one of the different observations. - // Therefore, instead of introducing 13 different mocks, we have decided to have a single one - // and just check the structure of the payload programmatically. - .post('/v2/entities?options=upsert', function (body) { - let i = 0; - let attributes = 0; - - for (const attribute in body) { - // checks that all attributes has metadata - if (body.hasOwnProperty(attribute)) { - attributes++; - for (const metadata in body[attribute].metadata) { - if (body[attribute].metadata.hasOwnProperty(metadata)) { - i++; - } - } - } - } - return i === attributes - 1 - 2; - }) - .times(13) + .post( + '/v2/op/update' + //utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multimeasure3.json') + ) .reply(204); config.iota.timestamp = true; // forces to add timestamp att and metadata with timeinstant to all attributes