-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a9336f
commit 2da7b1f
Showing
3 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Copyright 2016 Telefonica Investigación y Desarrollo, S.A.U | ||
* | ||
* This file is part of iotagent-json | ||
* | ||
* iotagent-ul is free software: you can redistribute it and/or | ||
* modify it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the License, | ||
* or (at your option) any later version. | ||
* | ||
* iotagent-ul is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public | ||
* License along with iotagent-json. | ||
* If not, seehttp://www.gnu.org/licenses/. | ||
* | ||
* For those usages not covered by the GNU Affero General Public License | ||
* please contact with::[contacto@tid.es] | ||
* | ||
*/ | ||
|
||
/* eslint-disable no-unused-vars */ | ||
|
||
const iotagentMqtt = require('../../../'); | ||
const config = require('./config-test.js'); | ||
const nock = require('nock'); | ||
const should = require('should'); | ||
const iotAgentLib = require('iotagent-node-lib'); | ||
const async = require('async'); | ||
const utils = require('../../utils'); | ||
const request = utils.request; | ||
let mockedClientServer; | ||
let contextBrokerMock; | ||
|
||
describe('HTTP binding - Update command provisioned with a new apikey', function () { | ||
const provisionOptions = { | ||
url: 'http://localhost:' + config.iota.server.port + '/iot/devices', | ||
method: 'POST', | ||
json: utils.readExampleFile('./test/unit/ngsiv2/deviceProvisioning/provisionDeviceHTTP4.json'), | ||
headers: { | ||
'fiware-service': 'smartgondor', | ||
'fiware-servicepath': '/gardens' | ||
} | ||
}; | ||
beforeEach(function (done) { | ||
config.iota.logLevel = 'FATAL'; | ||
nock.cleanAll(); | ||
|
||
iotagentMqtt.start(config, function () { | ||
request(provisionOptions, function (error, response, body) { | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should have provisioned with APIKEY1', function (done) { | ||
const options = { | ||
url: 'http://localhost:' + config.iota.server.port + '/iot/devices/MQTT_4', | ||
headers: { | ||
'fiware-service': 'smartgondor', | ||
'fiware-servicepath': '/gardens' | ||
}, | ||
method: 'GET' | ||
}; | ||
request(options, function (error, response, body) { | ||
const parsedBody = JSON.parse(body); | ||
parsedBody.apikey.should.equal('APIKEY1'); | ||
done(); | ||
}); | ||
}); | ||
|
||
afterEach(function (done) { | ||
nock.cleanAll(); | ||
async.series([iotAgentLib.clearAll, iotagentMqtt.stop], done); | ||
}); | ||
|
||
describe('When a request to update a provision device arrives', function () { | ||
const optionsUpdate = { | ||
url: 'http://localhost:' + config.iota.server.port + '/iot/devices/MQTT_4', | ||
method: 'PUT', | ||
headers: { | ||
'fiware-service': 'smartgondor', | ||
'fiware-servicepath': '/gardens' | ||
}, | ||
json: utils.readExampleFile('./test/unit/ngsiv2/deviceProvisioning/updateProvisionDevice4.json') | ||
}; | ||
|
||
it('should return a 200 OK and no errors', function (done) { | ||
request(optionsUpdate, function (error, response, body) { | ||
should.not.exist(error); | ||
response.statusCode.should.equal(204); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should have updated device apikey', function (done) { | ||
request(optionsUpdate, function (error, response, body) { | ||
const options = { | ||
url: 'http://localhost:' + config.iota.server.port + '/iot/devices/MQTT_4', | ||
headers: { | ||
'fiware-service': 'smartgondor', | ||
'fiware-servicepath': '/gardens' | ||
}, | ||
method: 'GET' | ||
}; | ||
|
||
request(options, function (error, response, body) { | ||
/* jshint camelcase:false */ | ||
const parsedBody = JSON.parse(body); | ||
parsedBody.apikey.should.equal('APIKEY2'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
47 changes: 47 additions & 0 deletions
47
test/unit/ngsiv2/deviceProvisioning/provisionDeviceHTTP4.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"devices": [ | ||
{ | ||
"device_id": "MQTT_4", | ||
"protocol": "GENERIC_PROTO", | ||
"apikey": "APIKEY1", | ||
"entity_name": "Second MQTT Device", | ||
"timezone": "America/Santiago", | ||
"entity_type": "AnMQTTDevice", | ||
"attributes": [ | ||
{ | ||
"name": "temperature", | ||
"type": "celsius" | ||
}, | ||
{ | ||
"name": "humidity", | ||
"type": "degrees" | ||
}, | ||
{ | ||
"name": "luminosity", | ||
"type": "Integer" | ||
|
||
}, | ||
{ | ||
"name": "pollution", | ||
"type": "Float" | ||
}, | ||
{ | ||
"name": "configuration", | ||
"type": "Object" | ||
}, | ||
{ | ||
"name": "tags", | ||
"type": "Array" | ||
}, | ||
{ | ||
"name": "enabled", | ||
"type": "Boolean" | ||
}, | ||
{ | ||
"name": "alive", | ||
"type": "Null" | ||
} | ||
] | ||
} | ||
] | ||
} |
3 changes: 3 additions & 0 deletions
3
test/unit/ngsiv2/deviceProvisioning/updateProvisionDevice4.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"apikey": "APIKEY2" | ||
} |