Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed Oct 19, 2023
1 parent 6799942 commit 9bdc1a2
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
61 changes: 61 additions & 0 deletions test/unit/ngsiv2/HTTP_receive_measures-test3.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,65 @@ describe('HTTP: Measure reception ', function () {
});
});
});

describe('When a POST single SOAP/XML measure arrives for the HTTP binding', function () {
var soapReq =
'<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"> ' +
'<soapenv:Header xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"/> ' +
'<soapenv:Body ' +
'xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"> ' +
'<ns21:notificationEventRequest ' +
'xmlns:ns21="http://myurl.com"> ' +
'<ns21:Param1>ABC12345</ns21:Param1> ' +
'<ns21:Param2/> ' +
'<ns21:Date>28/09/2023 11:48:15 +0000</ns21:Date> ' +
'<ns21:NestedAttr> ' +
'<ns21:SubAttr>This is a description</ns21:SubAttr> ' +
'</ns21:NestedAttr> ' +
'<ns21:Status>Assigned</ns21:Status> ' +
'<ns21:OriginSystem/> ' +
'</ns21:notificationEventRequest> ' +
'</soapenv:Body> ' +
'</soap:Envelope>';
const optionsMeasure = {
url: 'http://localhost:' + config.http.port + '/iot/json/attrs/data',
method: 'POST',
json: false,
body: soapReq,
headers: {
'fiware-service': 'smartgondor',
'fiware-servicepath': '/gardens',
'content-type': 'application/soap+xml'
},
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/singleMeasureSoapXml.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();
});
});
});
});
57 changes: 57 additions & 0 deletions test/unit/ngsiv2/contextRequests/singleMeasureSoapXml.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"id": "Second MQTT Device",
"type": "AnMQTTDevice",
"data": {
"type": "None",
"value": {
"soap:Envelope": {
"$": {
"xmlns:soap": "http://www.w3.org/2003/05/soap-envelope"
},
"soapenv:Header": [
{
"$": {
"xmlns:soapenv": "http://www.w3.org/2003/05/soap-envelope"
}
}
],
"soapenv:Body": [
{
"$": {
"xmlns:soapenv": "http://www.w3.org/2003/05/soap-envelope"
},
"ns21:notificationEventRequest": [
{
"$": {
"xmlns:ns21": "http://myurl.com"
},
"ns21:Param1": [
"ABC12345"
],
"ns21:Param2": [
""
],
"ns21:Date": [
"28/09/2023 11:48:15 +0000"
],
"ns21:NestedAttr": [
{
"ns21:SubAttr": [
"This is a description"
]
}
],
"ns21:Status": [
"Assigned"
],
"ns21:OriginSystem": [
""
]
}
]
}
]
}
}
}
}

0 comments on commit 9bdc1a2

Please sign in to comment.