From f673bda5f37719c5af71f16dcf190236476980c3 Mon Sep 17 00:00:00 2001 From: Benoit Orihuela Date: Fri, 10 Apr 2020 18:38:13 +0200 Subject: [PATCH] feature: support ngsi-ld context broker #82 --- config.js | 8 +- package.json | 2 +- .../deviceProvisioningNoMapping.json | 2 +- .../deviceProvisioningPluginMapping.json | 2 +- .../deviceProvisioningRightMapping.json | 2 +- .../expectedDataUpdatePluginRequest.json | 76 ++++++------ .../expectedDataUpdateRequest.json | 100 +++++++--------- .../expectedProvisioningPluginRequest.json | 77 ++++++------ .../expectedProvisioningRequest.json | 113 +++++++++--------- .../expectedDeviceRegisterRequest.json | 113 +++++++++--------- .../expectedDeviceUpdateDataRequest.json | 100 +++++++--------- test/testConfig.js | 4 +- test/unit/deviceProvisioning-test.js | 7 +- test/unit/ngsi-communication-test.js | 12 +- test/unit/plugin-config-test.js | 8 +- 15 files changed, 297 insertions(+), 329 deletions(-) diff --git a/config.js b/config.js index 3b5b69a..cd7a78d 100644 --- a/config.js +++ b/config.js @@ -58,7 +58,13 @@ config.iota = { /** * Port where the Context Broker is listening. */ - port: '1026' + port: '1026', + + /** + * Version of NGSI + */ + ngsiVersion: 'ld', + jsonLdContext: 'https://schema.lab.fiware.org/ld/context.jsonld' }, /** diff --git a/package.json b/package.json index 8dbfe8f..9801d35 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "command-node": "0.1.1", "request": "2.88.0", "async": "1.5.2", - "iotagent-node-lib": "git://github.com/telefonicaid/iotagent-node-lib.git#master", + "iotagent-node-lib": "git://github.com/telefonicaid/iotagent-node-lib.git#feature/842_ngsi_ld", "express": "4.16.4", "body-parser": "1.18.3", "logops": "2.1.0" diff --git a/test/examples/deviceProvisioning/deviceProvisioningNoMapping.json b/test/examples/deviceProvisioning/deviceProvisioningNoMapping.json index 26df6f3..40ba8c7 100644 --- a/test/examples/deviceProvisioning/deviceProvisioningNoMapping.json +++ b/test/examples/deviceProvisioning/deviceProvisioningNoMapping.json @@ -6,7 +6,7 @@ "service" : "dumbMordor", "service_path": "/deserts", "entity_name": "TheLastLight", - "entity_type": "SIGFOX", + "entity_type": "Device", "timezone": "America/Santiago", "attributes": [], "lazy": [], diff --git a/test/examples/deviceProvisioning/deviceProvisioningPluginMapping.json b/test/examples/deviceProvisioning/deviceProvisioningPluginMapping.json index fe85e9a..ad92cf8 100644 --- a/test/examples/deviceProvisioning/deviceProvisioningPluginMapping.json +++ b/test/examples/deviceProvisioning/deviceProvisioningPluginMapping.json @@ -6,7 +6,7 @@ "service" : "dumbMordor", "service_path": "/deserts", "entity_name": "sigApp3", - "entity_type": "SIGFOX", + "entity_type": "Device", "timezone": "America/Santiago", "attributes": [ { diff --git a/test/examples/deviceProvisioning/deviceProvisioningRightMapping.json b/test/examples/deviceProvisioning/deviceProvisioningRightMapping.json index 6e90df7..e6a027a 100644 --- a/test/examples/deviceProvisioning/deviceProvisioningRightMapping.json +++ b/test/examples/deviceProvisioning/deviceProvisioningRightMapping.json @@ -4,7 +4,7 @@ "device_id": "sigApp2", "protocol": "SIGFOX", "entity_name": "sigApp2", - "entity_type": "SIGFOX", + "entity_type": "Device", "timezone": "America/Santiago", "attributes": [ { diff --git a/test/examples/deviceProvisioning/expectedDataUpdatePluginRequest.json b/test/examples/deviceProvisioning/expectedDataUpdatePluginRequest.json index 5812b30..375fc03 100644 --- a/test/examples/deviceProvisioning/expectedDataUpdatePluginRequest.json +++ b/test/examples/deviceProvisioning/expectedDataUpdatePluginRequest.json @@ -1,42 +1,34 @@ -{ - "contextElements": [ - { - "type": "SIGFOX", - "isPattern": "false", - "id": "sigApp3", - "attributes": [ - { - "name": "time", - "type": "String", - "value": "1430909015" - }, - { - "name": "statin", - "type": "String", - "value": "0A5F" - }, - { - "name": "lng", - "type": "String", - "value": "-4" - }, - { - "name": "lat", - "type": "String", - "value": "41" - }, - { - "name": "campo1", - "type": "Integer", - "value": "valor1" - }, - { - "name": "campo2", - "type": "Integer", - "value": 64 - } - ] - } - ], - "updateAction": "UPDATE" -} +[ + { + "@context": "https://schema.lab.fiware.org/ld/context.jsonld", + "time": { + "type": "Property", + "value": "1430909015" + }, + "statin": { + "type": "Property", + "value": "0A5F" + }, + "lng": { + "type": "Property", + "value": "-4" + }, + "lat": { + "type": "Property", + "value": "41" + }, + "campo1": { + "type": "Property", + "value": { + "@type": "Intangible", + "@value": null + } + }, + "campo2": { + "type": "Property", + "value": 64 + }, + "id": "urn:ngsi-ld:Device:sigApp3", + "type": "Device" + } + ] diff --git a/test/examples/deviceProvisioning/expectedDataUpdateRequest.json b/test/examples/deviceProvisioning/expectedDataUpdateRequest.json index 523bca8..6a7c944 100644 --- a/test/examples/deviceProvisioning/expectedDataUpdateRequest.json +++ b/test/examples/deviceProvisioning/expectedDataUpdateRequest.json @@ -1,57 +1,43 @@ -{ - "contextElements": [ - { - "type": "SIGFOX", - "isPattern": "false", - "id": "sigApp2", - "attributes": [ - { - "name": "time", - "type": "String", - "value": "1430909015" - }, - { - "name": "statin", - "type": "String", - "value": "0A5F" - }, - { - "name": "lng", - "type": "String", - "value": "-4" - }, - { - "name": "lat", - "type": "String", - "value": "41" - }, - { - "name": "theCounter", - "type": "Integer", - "value": 2 - }, - { - "name": "theParam1", - "type": "Integer", - "value": 0 - }, - { - "name": "param2", - "type": "Integer", - "value": 0 - }, - { - "name": "tempDegreesCelsius", - "type": "Integer", - "value": 35 - }, - { - "name": "voltage", - "type": "Integer", - "value": 3183 - } - ] - } - ], - "updateAction": "UPDATE" -} \ No newline at end of file +[ + { + "@context": "https://schema.lab.fiware.org/ld/context.jsonld", + "time": { + "type": "Property", + "value": "1430909015" + }, + "statin": { + "type": "Property", + "value": "0A5F" + }, + "lng": { + "type": "Property", + "value": "-4" + }, + "lat": { + "type": "Property", + "value": "41" + }, + "theCounter": { + "type": "Property", + "value": 2 + }, + "theParam1": { + "type": "Property", + "value": 0 + }, + "param2": { + "type": "Property", + "value": 0 + }, + "tempDegreesCelsius": { + "type": "Property", + "value": 35 + }, + "voltage": { + "type": "Property", + "value": 3183 + }, + "id": "urn:ngsi-ld:Device:sigApp2", + "type": "Device" + } +] diff --git a/test/examples/deviceProvisioning/expectedProvisioningPluginRequest.json b/test/examples/deviceProvisioning/expectedProvisioningPluginRequest.json index cf0326f..475ff0a 100644 --- a/test/examples/deviceProvisioning/expectedProvisioningPluginRequest.json +++ b/test/examples/deviceProvisioning/expectedProvisioningPluginRequest.json @@ -1,42 +1,37 @@ -{ - "contextElements": [ - { - "type": "SIGFOX", - "isPattern": "false", - "id": "sigApp3", - "attributes": [ - { - "name": "time", - "type": "String", - "value": " " - }, - { - "name": "statin", - "type": "String", - "value": " " - }, - { - "name": "lng", - "type": "String", - "value": " " - }, - { - "name": "lat", - "type": "String", - "value": " " - }, - { - "name": "campo1", - "type": "Integer", - "value": " " - }, - { - "name": "campo2", - "type": "Integer", - "value": " " - } - ] +[ + { + "@context": "https://schema.lab.fiware.org/ld/context.jsonld", + "id": "urn:ngsi-ld:Device:sigApp3", + "type": "Device", + "time": { + "type": "Property", + "value": " " + }, + "statin": { + "type": "Property", + "value": " " + }, + "lng": { + "type": "Property", + "value": " " + }, + "lat": { + "type": "Property", + "value": " " + }, + "campo1": { + "type": "Property", + "value": { + "@type": "Intangible", + "@value": null + } + }, + "campo2": { + "type": "Property", + "value": { + "@type": "Intangible", + "@value": null + } } - ], - "updateAction": "APPEND" -} \ No newline at end of file + } + ] diff --git a/test/examples/deviceProvisioning/expectedProvisioningRequest.json b/test/examples/deviceProvisioning/expectedProvisioningRequest.json index b15f268..44d1512 100644 --- a/test/examples/deviceProvisioning/expectedProvisioningRequest.json +++ b/test/examples/deviceProvisioning/expectedProvisioningRequest.json @@ -1,57 +1,58 @@ -{ - "contextElements": [ - { - "type": "SIGFOX", - "isPattern": "false", - "id": "sigApp2", - "attributes": [ - { - "name": "time", - "type": "String", - "value": " " - }, - { - "name": "statin", - "type": "String", - "value": " " - }, - { - "name": "lng", - "type": "String", - "value": " " - }, - { - "name": "lat", - "type": "String", - "value": " " - }, - { - "name": "theCounter", - "type": "Integer", - "value": " " - }, - { - "name": "theParam1", - "type": "Integer", - "value": " " - }, - { - "name": "param2", - "type": "Integer", - "value": " " - }, - { - "name": "tempDegreesCelsius", - "type": "Integer", - "value": " " - }, - { - "name": "voltage", - "type": "Integer", - "value": " " - } - ] +[ + { + "@context": "https://schema.lab.fiware.org/ld/context.jsonld", + "id": "urn:ngsi-ld:Device:sigApp2", + "type": "Device", + "time": { + "type": "Property", + "value": " " + }, + "statin": { + "type": "Property", + "value": " " + }, + "lng": { + "type": "Property", + "value": " " + }, + "lat": { + "type": "Property", + "value": " " + }, + "theCounter": { + "type": "Property", + "value": { + "@type": "Intangible", + "@value": null + } + }, + "theParam1": { + "type": "Property", + "value": { + "@type": "Intangible", + "@value": null + } + }, + "param2": { + "type": "Property", + "value": { + "@type": "Intangible", + "@value": null + } + }, + "tempDegreesCelsius": { + "type": "Property", + "value": { + "@type": "Intangible", + "@value": null + } + }, + "voltage": { + "type": "Property", + "value": { + "@type": "Intangible", + "@value": null + } } - ], - "updateAction": "APPEND" -} \ No newline at end of file + } + ] diff --git a/test/examples/ngsi-communication/expectedDeviceRegisterRequest.json b/test/examples/ngsi-communication/expectedDeviceRegisterRequest.json index c1d285f..3b68dfc 100644 --- a/test/examples/ngsi-communication/expectedDeviceRegisterRequest.json +++ b/test/examples/ngsi-communication/expectedDeviceRegisterRequest.json @@ -1,57 +1,58 @@ -{ - "contextElements": [ - { - "type": "SIGFOX", - "isPattern": "false", - "id": "SIGFOX:sigApp1", - "attributes": [ - { - "name": "time", - "type": "String", - "value": " " - }, - { - "name": "statin", - "type": "String", - "value": " " - }, - { - "name": "lng", - "type": "String", - "value": " " - }, - { - "name": "lat", - "type": "String", - "value": " " - }, - { - "name": "counter", - "type": "Integer", - "value": " " - }, - { - "name": "param1", - "type": "Integer", - "value": " " - }, - { - "name": "param2", - "type": "Integer", - "value": " " - }, - { - "name": "tempDegreesCelsius", - "type": "Integer", - "value": " " - }, - { - "name": "voltage", - "type": "Integer", - "value": " " - } - ] +[ + { + "@context": "https://schema.lab.fiware.org/ld/context.jsonld", + "id": "urn:ngsi-ld:Device:sigApp1", + "type": "Device", + "time": { + "type": "Property", + "value": " " + }, + "statin": { + "type": "Property", + "value": " " + }, + "lng": { + "type": "Property", + "value": " " + }, + "lat": { + "type": "Property", + "value": " " + }, + "counter": { + "type": "Property", + "value": { + "@type": "Intangible", + "@value": null + } + }, + "param1": { + "type": "Property", + "value": { + "@type": "Intangible", + "@value": null + } + }, + "param2": { + "type": "Property", + "value": { + "@type": "Intangible", + "@value": null + } + }, + "tempDegreesCelsius": { + "type": "Property", + "value": { + "@type": "Intangible", + "@value": null + } + }, + "voltage": { + "type": "Property", + "value": { + "@type": "Intangible", + "@value": null + } } - ], - "updateAction": "APPEND" -} \ No newline at end of file + } + ] diff --git a/test/examples/ngsi-communication/expectedDeviceUpdateDataRequest.json b/test/examples/ngsi-communication/expectedDeviceUpdateDataRequest.json index b55604e..b842412 100644 --- a/test/examples/ngsi-communication/expectedDeviceUpdateDataRequest.json +++ b/test/examples/ngsi-communication/expectedDeviceUpdateDataRequest.json @@ -1,57 +1,43 @@ -{ - "contextElements": [ - { - "type": "SIGFOX", - "isPattern": "false", - "id": "SIGFOX:sigApp1", - "attributes": [ - { - "name": "time", - "type": "String", - "value": "1430909015" - }, - { - "name": "statin", - "type": "String", - "value": "0A5F" - }, - { - "name": "lng", - "type": "String", - "value": "-4" - }, - { - "name": "lat", - "type": "String", - "value": "41" - }, - { - "name": "counter", - "type": "Integer", - "value": 2 - }, - { - "name": "param1", - "type": "Integer", - "value": 0 - }, - { - "name": "param2", - "type": "Integer", - "value": 0 - }, - { - "name": "tempDegreesCelsius", - "type": "Integer", - "value": 35 - }, - { - "name": "voltage", - "type": "Integer", - "value": 3183 - } - ] - } - ], - "updateAction": "UPDATE" -} +[ + { + "@context": "https://schema.lab.fiware.org/ld/context.jsonld", + "time": { + "type": "Property", + "value": "1430909015" + }, + "statin": { + "type": "Property", + "value": "0A5F" + }, + "lng": { + "type": "Property", + "value": "-4" + }, + "lat": { + "type": "Property", + "value": "41" + }, + "counter": { + "type": "Property", + "value": 2 + }, + "param1": { + "type": "Property", + "value": 0 + }, + "param2": { + "type": "Property", + "value": 0 + }, + "tempDegreesCelsius": { + "type": "Property", + "value": 35 + }, + "voltage": { + "type": "Property", + "value": 3183 + }, + "id": "urn:ngsi-ld:Device:sigApp1", + "type": "Device" + } + ] diff --git a/test/testConfig.js b/test/testConfig.js index c62389b..99c5867 100644 --- a/test/testConfig.js +++ b/test/testConfig.js @@ -31,7 +31,9 @@ config.iota = { logLevel: 'DEBUG', contextBroker: { host: 'localhost', - port: '10026' + port: '10026', + ngsiVersion: 'ld', + jsonLdContext: 'https://schema.lab.fiware.org/ld/context.jsonld' }, server: { port: 4041 diff --git a/test/unit/deviceProvisioning-test.js b/test/unit/deviceProvisioning-test.js index a60c947..492a72d 100644 --- a/test/unit/deviceProvisioning-test.js +++ b/test/unit/deviceProvisioning-test.js @@ -59,7 +59,6 @@ describe('Device and configuration provisioning', function() { it('should fail with a 400 error', function(done) { request(provisioningOpts, function(error, response, body) { - console.log('BODY: ' + body); should.not.exist(error); response.statusCode.should.equal(400); done(); @@ -91,17 +90,17 @@ describe('Device and configuration provisioning', function() { nock('http://' + config.iota.contextBroker.host + ':' + config.iota.contextBroker.port) .post( - '/v1/updateContext', + '/ngsi-ld/v1/entityOperations/upsert/', utils.readExampleFile('./test/examples/deviceProvisioning/expectedProvisioningRequest.json') ) - .reply(200, {}); + .reply(204); nock('http://' + config.iota.contextBroker.host + ':' + config.iota.contextBroker.port) .post( '/ngsi-ld/v1/entityOperations/upsert/', utils.readExampleFile('./test/examples/deviceProvisioning/expectedDataUpdateRequest.json') ) - .reply(200, {}); + .reply(204); it('should use the provided provisioning', function(done) { request(provisioningOpts, function(error, response, body) { diff --git a/test/unit/ngsi-communication-test.js b/test/unit/ngsi-communication-test.js index 378f281..3986cf0 100644 --- a/test/unit/ngsi-communication-test.js +++ b/test/unit/ngsi-communication-test.js @@ -35,7 +35,7 @@ var iotAgent = require('../../lib/iotagentCore'), utils = require('../tools/utils'), sigfoxDevice = { id: 'sigApp1', - type: 'SIGFOX', + type: 'Device', commands: [], lazy: [], active: [ @@ -84,10 +84,10 @@ describe('Context Broker communication', function() { beforeEach(function(done) { nock('http://' + config.iota.contextBroker.host + ':' + config.iota.contextBroker.port) .post( - '/v1/updateContext', + '/ngsi-ld/v1/entityOperations/upsert/', utils.readExampleFile('./test/examples/ngsi-communication/expectedDeviceRegisterRequest.json') ) - .reply(200, {}); + .reply(204); iotAgent.start(config, function() { async.series( @@ -96,7 +96,7 @@ describe('Context Broker communication', function() { mappings.clean, apply( mappings.add, - 'SIGFOX', + 'Device', 'counter::uint:32 param1::uint:32 param2::uint:8 tempDegreesCelsius::uint:8 voltage::uint:16' ), apply(iotAgentLib.register, sigfoxDevice) @@ -128,10 +128,10 @@ describe('Context Broker communication', function() { nock('http://' + config.iota.contextBroker.host + ':' + config.iota.contextBroker.port) .post( - '/v1/updateContext', + '/ngsi-ld/v1/entityOperations/upsert/', utils.readExampleFile('./test/examples/ngsi-communication/expectedDeviceUpdateDataRequest.json') ) - .reply(200, {}); + .reply(204); it('should answer with a 200 OK', function(done) { request(options, function(error, response, body) { diff --git a/test/unit/plugin-config-test.js b/test/unit/plugin-config-test.js index 6eb12fd..885bf33 100644 --- a/test/unit/plugin-config-test.js +++ b/test/unit/plugin-config-test.js @@ -72,17 +72,17 @@ describe('Plugin configuration test', function() { nock('http://' + config.iota.contextBroker.host + ':' + config.iota.contextBroker.port) .post( - '/v1/updateContext', + '/ngsi-ld/v1/entityOperations/upsert/', utils.readExampleFile('./test/examples/deviceProvisioning/expectedProvisioningPluginRequest.json') ) - .reply(200, {}); + .reply(204); nock('http://' + config.iota.contextBroker.host + ':' + config.iota.contextBroker.port) .post( - '/v1/updateContext', + '/ngsi-ld/v1/entityOperations/upsert/', utils.readExampleFile('./test/examples/deviceProvisioning/expectedDataUpdatePluginRequest.json') ) - .reply(200, {}); + .reply(204); it('should use the plugin to parse the device responses', function(done) { request(provisioningOpts, function(error, response, body) {