mirror of
https://gitlab.com/spaceti-app/integrations/common/server-sdk.git
synced 2026-07-13 00:00:48 +02:00
172 lines
4.9 KiB
C++
172 lines
4.9 KiB
C++
#include <QtTest>
|
|
#include <QProcess>
|
|
|
|
#include "serversdk/requestmanager.h"
|
|
#include "serversdk/utils.h"
|
|
#include "serversdk/soaprequest.h"
|
|
|
|
#include "test.h"
|
|
|
|
namespace serversdk {
|
|
|
|
class SoapTest : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
SoapTest();
|
|
|
|
private:
|
|
Q_SLOT void construct();
|
|
|
|
Q_SLOT void public_soap_xml();
|
|
|
|
Q_SLOT void public_soap_test();
|
|
Q_SLOT void public_soap_test_data();
|
|
};
|
|
|
|
SoapTest::SoapTest()
|
|
{
|
|
qRegisterMetaType<std::shared_ptr<Request>>("std::shared_ptr<Request>");
|
|
}
|
|
|
|
void SoapTest::construct()
|
|
{
|
|
RequestManager soap;
|
|
|
|
QVERIFY(soap.mRequestMap.isEmpty());
|
|
|
|
QFileInfo info(Test::sourcePath(""));
|
|
QCOMPARE(info.fileName(), QStringLiteral("data"));
|
|
|
|
QCOMPARE(Test::sourceData("soap/LatLonListSubgrid-response.xml").count(), 1298);
|
|
//QCOMPARE(Utils::sourceData("test/cmd/LatLonListSubgrid-response.xml").count(), 1298);
|
|
}
|
|
|
|
void SoapTest::public_soap_xml()
|
|
{
|
|
QString soapAction = "blz:getBank";
|
|
QString endpoint = "http://www.thomas-bayer.com/axis2/services/BLZService";
|
|
QString xml = QString("<soapenv:Envelope "
|
|
"xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" "
|
|
"xmlns:blz=\"http://thomas-bayer.com/blz/\">"
|
|
"<soapenv:Header/>"
|
|
" <soapenv:Body>"
|
|
" <blz:getBank>"
|
|
" <blz:blz>%1</blz:blz>"
|
|
" </blz:getBank>"
|
|
"</soapenv:Body>"
|
|
"</soapenv:Envelope>").arg("10020200");
|
|
|
|
QByteArray xmlRequest = xml.toUtf8();
|
|
|
|
// SOAP download
|
|
RequestManager soap;
|
|
auto response = std::make_shared<SoapRequest>(soapAction, endpoint, xmlRequest);
|
|
QCOMPARE(response.use_count(), 1L );
|
|
soap.processRequest(response);
|
|
QVERIFY(soap.mRequestMap.count() == 1);
|
|
QSignalSpy spyFinished(&soap, &RequestManager::downloadFinished);
|
|
|
|
QVERIFY(spyFinished.wait());
|
|
//QCOMPARE(response.use_count(), 2L ); // this context + Soap
|
|
spyFinished.clear();
|
|
QCOMPARE(response.use_count(), 1L ); // this context + Soap
|
|
|
|
// Response
|
|
QByteArray xmlResponse = Test::sourceData("soap/bankapi-response.xml");
|
|
QVERIFY( ! xmlResponse.isEmpty());
|
|
|
|
// QFile fileWrite(cmdDir() + "/tst_soap-response.xml");
|
|
// QVERIFY(fileWrite.open(QIODevice::WriteOnly));
|
|
// fileWrite.write(soap.data());
|
|
// fileWrite.close();
|
|
|
|
QCOMPARE(response.use_count(), 1L ); // this context + Soap
|
|
QCOMPARE(response->responseData(), xmlResponse);
|
|
}
|
|
|
|
|
|
|
|
void SoapTest::public_soap_test()
|
|
{
|
|
QFETCH(QString, soapAction);
|
|
QFETCH(QString, endpoint);
|
|
QFETCH(QString, xmlRequestFile);
|
|
QFETCH(QString, xmlResponseFile);
|
|
QFETCH(bool, soap12);
|
|
|
|
// Request
|
|
QByteArray xmlRequest = Test::sourceData(xmlRequestFile);
|
|
QVERIFY( ! xmlRequest.isEmpty());
|
|
// Response
|
|
QByteArray xmlResponse = Test::sourceData(xmlResponseFile);
|
|
QVERIFY( ! xmlResponse.isEmpty());
|
|
|
|
// RequestManagerrequest
|
|
auto req = std::make_shared<SoapRequest>(soapAction, endpoint, xmlRequest);
|
|
req->setSoapVersion12(soap12);
|
|
|
|
// RequestManagerdownload
|
|
RequestManager soap;
|
|
soap.processRequest(req);
|
|
QCOMPARE(req->status(), 0); // when not processed yet, status is 0
|
|
|
|
QSignalSpy progressSpy(&soap, &RequestManager::progresss);
|
|
QSignalSpy finishedSpy(&soap, &RequestManager::downloadFinished);
|
|
QVERIFY(finishedSpy.wait(20000));
|
|
QVERIFY(progressSpy.count());
|
|
|
|
QCOMPARE(req->status(), 200);
|
|
|
|
//Uncoment to write .xml response to cmd folder
|
|
// QFile fileWrite(Utils::sourcePath("test/cmd/tst_soap-response.xml"));
|
|
// QVERIFY(fileWrite.open(QIODevice::WriteOnly));
|
|
// fileWrite.write(req->responseData());
|
|
// fileWrite.close();
|
|
QProcess process;
|
|
process.start("hostname");
|
|
process.waitForFinished(-1); // will wait forever until finished
|
|
|
|
QString stdout = process.readAllStandardOutput();
|
|
|
|
QCOMPARE(req->responseData(), xmlResponse);
|
|
}
|
|
|
|
|
|
void SoapTest::public_soap_test_data()
|
|
{
|
|
QTest::addColumn<QString>("soapAction");
|
|
QTest::addColumn<QString>("endpoint");
|
|
QTest::addColumn<QString>("xmlRequestFile");
|
|
QTest::addColumn<QString>("xmlResponseFile");
|
|
QTest::addColumn<bool>("soap12");
|
|
QTest::addColumn<bool>("soap12");
|
|
|
|
// QTest::newRow("weather service")
|
|
// << "LatLonListSubgrid"
|
|
// << "https://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php"
|
|
// << "soap/LatLonListSubgrid.xml"
|
|
// << "soap/LatLonListSubgrid-response.xml"
|
|
// << false;
|
|
|
|
QTest::newRow("bank service")
|
|
<< "blz:getBank"
|
|
<< "http://www.thomas-bayer.com/axis2/services/BLZService"
|
|
<< "soap/bankapi.xml"
|
|
<< "soap/bankapi-response.xml"
|
|
<< false;
|
|
|
|
QTest::newRow("bank service SOAP 1.2")
|
|
<< "blz:getBank"
|
|
<< "http://www.thomas-bayer.com/axis2/services/BLZService"
|
|
<< "soap/bankapi-1.2.xml"
|
|
<< "soap/bankapi-1.2-response.xml"
|
|
<< true; // SOAP 1.2
|
|
}
|
|
|
|
}
|
|
|
|
QTEST_MAIN(serversdk::SoapTest)
|
|
|
|
#include "tst_soaptest.moc"
|