Skip to content

Commit

Permalink
Merge pull request #822 from telefonicaid/task/add_test_multimeasure_…
Browse files Browse the repository at this point in the history
…with_timeinstant

Task/add test cases about multimeasure with timeinstant mapped attribute
  • Loading branch information
fgalan authored Apr 18, 2024
2 parents ae0eef5 + 285df88 commit 339895c
Show file tree
Hide file tree
Showing 6 changed files with 376 additions and 4 deletions.
19 changes: 19 additions & 0 deletions test/deviceProvisioning/provisionDeviceTimeinstant3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"devices": [
{
"attributes": [
{
"type": "percent",
"name": "humidity",
"object_id": "h"
}
],
"entity_type": "sensor",
"protocol": "IoTA-JSON",
"entity_name": "e0130101",
"device_id": "dev0130101",
"explicitAttrs": false,
"timestamp": true
}
]
}
24 changes: 24 additions & 0 deletions test/deviceProvisioning/provisionDeviceTimeinstant4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"devices": [
{
"attributes": [
{
"type": "datetime",
"name": "TimeInstant",
"object_id": "myTimeInstant"
},
{
"type": "percent",
"name": "humidity",
"object_id": "h"
}
],
"entity_type": "sensor",
"protocol": "IoTA-JSON",
"entity_name": "e0130101",
"device_id": "dev0130101",
"explicitAttrs": false,
"timestamp": true
}
]
}
24 changes: 24 additions & 0 deletions test/deviceProvisioning/provisionDeviceTimeinstant5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"devices": [
{
"attributes": [
{
"type": "datetime",
"name": "TimeInstant",
"object_id": "TimeInstant"
},
{
"type": "percent",
"name": "humidity",
"object_id": "h"
}
],
"entity_type": "sensor",
"protocol": "IoTA-JSON",
"entity_name": "e0130101",
"device_id": "dev0130101",
"explicitAttrs": false,
"timestamp": true
}
]
}
277 changes: 273 additions & 4 deletions test/unit/ngsiv2/HTTP_reveice_measures-test2.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe('HTTP: Measure reception ', function () {
});
});

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

describe('When a POST multimeasure arrives with different TimeInstant attribute in the body', function () {
const optionsMeasure = {
url: 'http://localhost:' + config.http.port + '/iot/json',
method: 'POST',
json: [
{
h: '111222',
TimeInstant: '2020-02-22T22:22:22Z'
},
{
h: '111333',
TimeInstant: '2023-03-23T23:33:33Z'
},
{
h: '111111'
}
],
headers: {
'fiware-service': 'smartgondor',
'fiware-servicepath': '/gardens'
},
qs: {
i: 'dev0130101',
k: '1234'
}
};
const provisionOptions = {
url: 'http://localhost:' + config.iota.server.port + '/iot/devices',
method: 'POST',
json: utils.readExampleFile('./test/deviceProvisioning/provisionDeviceTimeinstant3.json'),
headers: {
'fiware-service': 'smartgondor',
'fiware-servicepath': '/gardens'
}
};

beforeEach(function (done) {
nock.cleanAll();
// This mock does not check the payload since the aim of the test is not to verify
// device provisioning functionality. Appropriate verification is done in tests under
// provisioning folder of iotagent-node-lib
contextBrokerMock = nock('http://192.168.1.1:1026');

contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
'/v2/entities?options=upsert',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures1b.json')
)
.reply(204);

contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
'/v2/entities?options=upsert',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures2b.json')
)
.reply(204);

contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
'/v2/entities?options=upsert'
// FIXME: Mock about h atttribute + current timestamp
//utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures.json')
)
.reply(204);

iotaJson.stop(function () {
iotaJson.start(config, function () {
request(provisionOptions, function (error, response, body) {
done();
});
});
});
});

afterEach(function () {});

it('should send its value to the Context Broker', function (done) {
request(optionsMeasure, function (error, result, body) {
contextBrokerMock.done();
done();
});
});
});

describe('When a POST multimeasure arrives with different TimeInstant mapped attribute in the body', function () {
const optionsMeasure = {
url: 'http://localhost:' + config.http.port + '/iot/json',
method: 'POST',
json: [
{
h: '111222',
myTimeInstant: '2020-02-22T22:22:22Z'
},
{
h: '111333',
myTimeInstant: '2023-03-23T23:33:33Z'
},
{
h: '111111'
}
],
headers: {
'fiware-service': 'smartgondor',
'fiware-servicepath': '/gardens'
},
qs: {
i: 'dev0130101',
k: '1234'
}
};
const provisionOptions = {
url: 'http://localhost:' + config.iota.server.port + '/iot/devices',
method: 'POST',
json: utils.readExampleFile('./test/deviceProvisioning/provisionDeviceTimeinstant4.json'),
headers: {
'fiware-service': 'smartgondor',
'fiware-servicepath': '/gardens'
}
};

beforeEach(function (done) {
nock.cleanAll();
// This mock does not check the payload since the aim of the test is not to verify
// device provisioning functionality. Appropriate verification is done in tests under
// provisioning folder of iotagent-node-lib
contextBrokerMock = nock('http://192.168.1.1:1026');

contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
'/v2/entities?options=upsert',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures1b.json')
)
.reply(204);

contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
'/v2/entities?options=upsert',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures2b.json')
)
.reply(204);

contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
'/v2/entities?options=upsert'
// FIXME: Mock about h atttribute + current timestamp
//utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures.json')
)
.reply(204);

iotaJson.stop(function () {
iotaJson.start(config, function () {
request(provisionOptions, function (error, response, body) {
done();
});
});
});
});

afterEach(function () {});

it('should send its value to the Context Broker', function (done) {
request(optionsMeasure, function (error, result, body) {
contextBrokerMock.done();
done();
});
});
});

describe('When a POST multimeasure arrives with different TimeInstant mapped timestamp attribute in the body', function () {
const optionsMeasure = {
url: 'http://localhost:' + config.http.port + '/iot/json',
method: 'POST',
json: [
{
h: '111222',
TimeInstant: '2020-02-22T22:22:22Z'
},
{
h: '111333',
TimeInstant: '2023-03-23T23:33:33Z'
},
{
h: '111111'
}
],
headers: {
'fiware-service': 'smartgondor',
'fiware-servicepath': '/gardens'
},
qs: {
i: 'dev0130101',
k: '1234'
}
};
const provisionOptions = {
url: 'http://localhost:' + config.iota.server.port + '/iot/devices',
method: 'POST',
json: utils.readExampleFile('./test/deviceProvisioning/provisionDeviceTimeinstant5.json'),
headers: {
'fiware-service': 'smartgondor',
'fiware-servicepath': '/gardens'
}
};

beforeEach(function (done) {
nock.cleanAll();
// This mock does not check the payload since the aim of the test is not to verify
// device provisioning functionality. Appropriate verification is done in tests under
// provisioning folder of iotagent-node-lib
contextBrokerMock = nock('http://192.168.1.1:1026');

contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
'/v2/entities?options=upsert',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures1b.json')
)
.reply(204);

contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
'/v2/entities?options=upsert',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures2b.json')
)
.reply(204);

contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
'/v2/entities?options=upsert'
// FIXME: Mock about h atttribute + current timestamp
//utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures.json')
)
.reply(204);

iotaJson.stop(function () {
iotaJson.start(config, function () {
request(provisionOptions, function (error, response, body) {
done();
});
});
});
});

afterEach(function () {});

it('should send its value to the Context Broker', function (done) {
request(optionsMeasure, function (error, result, body) {
contextBrokerMock.done();
done();
});
});
});

describe('When a POST multimeasure arrives with a TimeInstant query parameter in the body', function () {
const optionsMeasure = {
url: 'http://localhost:' + config.http.port + '/iot/json',
method: 'POST',
json: [
{
h: '111222'

},
{
h: '111333'
Expand All @@ -267,8 +536,8 @@ describe('HTTP: Measure reception ', function () {
},
qs: {
i: 'dev0130101',
k: '1234' ,
t:'2020-02-22T22:22:22Z'
k: '1234',
t: '2020-02-22T22:22:22Z'
}
};
const provisionOptions = {
Expand Down
18 changes: 18 additions & 0 deletions test/unit/ngsiv2/contextRequests/timeInstantMeasures1b.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"id":"e0130101",
"type":"sensor",
"humidity":{
"type": "percent",
"value": "111222",
"metadata": {
"TimeInstant": {
"type": "DateTime",
"value": "2020-02-22T22:22:22Z"
}
}
},
"TimeInstant":{
"type": "DateTime",
"value": "2020-02-22T22:22:22Z"
}
}
Loading

0 comments on commit 339895c

Please sign in to comment.