Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed Nov 6, 2023
1 parent e9a85d3 commit e0ab2df
Show file tree
Hide file tree
Showing 3 changed files with 346 additions and 2 deletions.
74 changes: 73 additions & 1 deletion test/unit/ngsiv2/HTTP_receive_ngsild_measures-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('HTTP: NGSIv2 Measure reception ', function () {
async.series([iotAgentLib.clearAll, iotaJson.stop], done);
});

describe('When a POST single JSON measure with NGSILD format arrives for the HTTP binding and NGSILD is the expected payload type', function () {
describe('When a POST single NGSILD append measure with NGSILD format arrives for the HTTP binding and NGSILD is the expected payload type', function () {
const optionsMeasure = {
url: 'http://localhost:' + config.http.port + '/iot/json/',
method: 'POST',
Expand Down Expand Up @@ -145,4 +145,76 @@ describe('HTTP: NGSIv2 Measure reception ', function () {
});
});
});

describe('When a POST single NGSILD entity measure with NGSILD format arrives for the HTTP binding and NGSILD is the expected payload type', function () {
const optionsMeasure = {
url: 'http://localhost:' + config.http.port + '/iot/json/',
method: 'POST',
json: {
id: 'urn:ngsi-ld:ParkingSpot:santander:daoiz_velarde_1_5:3',
type: 'ParkingSpot',
status: {
type: 'Property',
value: 'free',
observedAt: '2018-09-21T12:00:00Z'
},
category: {
type: 'Property',
value: ['onstreet']
},
refParkingSite: {
type: 'Relationship',
object: 'urn:ngsi-ld:ParkingSite:santander:daoiz_velarde_1_5'
},
name: {
type: 'Property',
value: 'A-13'
},
location: {
type: 'GeoProperty',
value: {
type: 'Point',
coordinates: [-3.80356167695194, 43.46296641666926]
}
},
'@context': [
'https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld',
'https://schema.lab.fiware.org/ld/context'
]
},
headers: {
'fiware-service': 'smartgondor',
'fiware-servicepath': '/gardens'
},
qs: {
i: 'MQTT_2',
k: '1234'
}
};

beforeEach(function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
'/v2/entities?options=upsert',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/ngsildPayloadMeasure.json')
)
.reply(204);
});
it('should return a 200 OK with no error', function (done) {
request(optionsMeasure, function (error, result, body) {
should.not.exist(error);
result.statusCode.should.equal(200);
done();
});
});

it('should send its value to the Context Broker', function (done) {
request(optionsMeasure, function (error, result, body) {
contextBrokerMock.done();
done();
});
});
});
});
226 changes: 225 additions & 1 deletion test/unit/ngsiv2/HTTP_receive_ngsiv2_measures-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('HTTP: NGSIv2 Measure reception ', function () {
async.series([iotAgentLib.clearAll, iotaJson.stop], done);
});

describe('When a POST single NGSIv2 measure format arrives for the HTTP binding and NGSIV2 is the expected payload type', function () {
describe('When a POST single NGSIv2 append measure format arrives for the HTTP binding and NGSIV2 is the expected payload type', function () {
const optionsMeasure = {
url: 'http://localhost:' + config.http.port + '/iot/json/',
method: 'POST',
Expand Down Expand Up @@ -158,4 +158,228 @@ describe('HTTP: NGSIv2 Measure reception ', function () {
});
});
});

describe('When a POST multiple NGSIv2 append measure format arrives for the HTTP binding and NGSIV2 is the expected payload type', function () {
const optionsMeasure = {
url: 'http://localhost:' + config.http.port + '/iot/json/',
method: 'POST',
json: {
actionType: 'APPEND',
entities: [
{
id: 'urn:ngsi-ld:Streetlight:Streetlight-Mylightpoint-2',
type: 'Streetlight',
name: {
type: 'Text',
value: 'MyLightPoint-test1'
},
description: {
type: 'Text',
value: 'testdescription'
},
status: {
type: 'Text',
value: 'connected'
},
dateServiceStarted: {
type: 'DateTime',
value: '2020-06-04T09: 55: 02'
},
locationComment: {
type: 'Text',
value: 'Test1'
},
location: {
type: 'geo:json',
value: {
coordinates: [-87.88429, 41.99499],
type: 'Point'
}
},
address: {
type: 'Text',
value: {
streetAddress: 'MyStreet'
}
},
isRemotelyManaged: {
type: 'Integer',
value: 1
},
installationDate: {
type: 'DateTime',
value: '2022-04-17T02: 30: 04'
}
},
{
id: 'urn:ngsi-ld:Streetlight:Streetlight-Mylightpoint-3',
type: 'Streetlight',
name: {
type: 'Text',
value: 'MyLightPoint-test2'
},
description: {
type: 'Text',
value: 'testdescription'
},
status: {
type: 'Text',
value: 'connected'
},
dateServiceStarted: {
type: 'DateTime',
value: '2022-06-04T09: 55: 02'
},
locationComment: {
type: 'Text',
value: 'Test3'
},
location: {
type: 'geo:json',
value: {
coordinates: [-84.88429, 42.99499],
type: 'Point'
}
},
address: {
type: 'Text',
value: {
streetAddress: 'MyFarStreet'
}
},
isRemotelyManaged: {
type: 'Integer',
value: 3
},
installationDate: {
type: 'DateTime',
value: '2023-04-17T02: 30: 04'
}
}
]
},
headers: {
'fiware-service': 'smartgondor',
'fiware-servicepath': '/gardens'
},
qs: {
i: 'MQTT_2',
k: '1234'
}
};
beforeEach(function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
'/v2/entities?options=upsert',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/ngsiv2PayloadMeasure.json')
)
.reply(204);
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
'/v2/entities?options=upsert',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/ngsiv2PayloadMeasure2.json')
)
.reply(204);
});
it('should return a 200 OK with no error', function (done) {
request(optionsMeasure, function (error, result, body) {
should.not.exist(error);
result.statusCode.should.equal(200);
done();
});
});
it('should send its value to the Context Broker', function (done) {
request(optionsMeasure, function (error, result, body) {
contextBrokerMock.done();
done();
});
});
});

describe('When a POST single NGSIv2 entity measure format arrives for the HTTP binding and NGSIV2 is the expected payload type', function () {
const optionsMeasure = {
url: 'http://localhost:' + config.http.port + '/iot/json/',
method: 'POST',
json: {
id: 'urn:ngsi-ld:Streetlight:Streetlight-Mylightpoint-2',
type: 'Streetlight',
name: {
type: 'Text',
value: 'MyLightPoint-test1'
},
description: {
type: 'Text',
value: 'testdescription'
},
status: {
type: 'Text',
value: 'connected'
},
dateServiceStarted: {
type: 'DateTime',
value: '2020-06-04T09: 55: 02'
},
locationComment: {
type: 'Text',
value: 'Test1'
},
location: {
type: 'geo:json',
value: {
coordinates: [-87.88429, 41.99499],
type: 'Point'
}
},
address: {
type: 'Text',
value: {
streetAddress: 'MyStreet'
}
},
isRemotelyManaged: {
type: 'Integer',
value: 1
},
installationDate: {
type: 'DateTime',
value: '2022-04-17T02: 30: 04'
}
},
headers: {
'fiware-service': 'smartgondor',
'fiware-servicepath': '/gardens'
},
qs: {
i: 'MQTT_2',
k: '1234'
}
};
beforeEach(function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
'/v2/entities?options=upsert',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/ngsiv2PayloadMeasure.json')
)
.reply(204);
});
it('should return a 200 OK with no error', function (done) {
request(optionsMeasure, function (error, result, body) {
should.not.exist(error);
result.statusCode.should.equal(200);
done();
});
});
it('should send its value to the Context Broker', function (done) {
request(optionsMeasure, function (error, result, body) {
contextBrokerMock.done();
done();
});
});
});
});
48 changes: 48 additions & 0 deletions test/unit/ngsiv2/contextRequests/ngsiv2PayloadMeasure2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"id": "Second MQTT Device",
"type": "AnMQTTDevice",
"name": {
"type": "Text",
"value": "MyLightPoint-test2"
},
"description": {
"type": "Text",
"value": "testdescription"
},
"status": {
"type": "Text",
"value": "connected"
},
"dateServiceStarted": {
"type": "DateTime",
"value": "2022-06-04T09: 55: 02"
},
"locationComment": {
"type": "Text",
"value": "Test3"
},
"location": {
"type": "geo:json",
"value": {
"coordinates": [
-84.88429,
42.99499
],
"type": "Point"
}
},
"address": {
"type": "Text",
"value": {
"streetAddress": "MyFarStreet"
}
},
"isRemotelyManaged": {
"type": "Integer",
"value": 3
},
"installationDate": {
"type": "DateTime",
"value": "2023-04-17T02: 30: 04"
}
}

0 comments on commit e0ab2df

Please sign in to comment.