diff --git a/config.js b/config.js index c88fbea..7ba7fe1 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 dfce960..33ef607 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 14a7fc5..7724a2f 100644 --- a/test/testConfig.js +++ b/test/testConfig.js @@ -31,7 +31,9 @@ config.iota = { logLevel: 'FATAL', 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 c901c85..f70d4cd 100644 --- a/test/unit/deviceProvisioning-test.js +++ b/test/unit/deviceProvisioning-test.js @@ -61,7 +61,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(); @@ -93,17 +92,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 8995a51..a0cd7ff 100644 --- a/test/unit/ngsi-communication-test.js +++ b/test/unit/ngsi-communication-test.js @@ -36,7 +36,7 @@ const nock = require('nock'); const utils = require('../tools/utils'); const sigfoxDevice = { id: 'sigApp1', - type: 'SIGFOX', + type: 'Device', commands: [], lazy: [], active: [ @@ -85,10 +85,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( @@ -97,7 +97,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) @@ -129,10 +129,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 9e1b23e..6e24ebe 100644 --- a/test/unit/plugin-config-test.js +++ b/test/unit/plugin-config-test.js @@ -73,17 +73,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) {