server-sdk/test/auto/request/tst_soaptest.cpp
Filip Bucek aff09b92da disabled soap test ( service unavailable )
* renamed files in script based on their names
2020-02-18 14:44:01 +01:00

220 lines
7.2 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 geocode_soap();
/*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::geocode_soap()
{
const QString soapAction = "https://geoservices.tamu.edu/GeocodeAddressNonParsed";
const QString host = "https://geoservices.tamu.edu";
const QString endpoint = "/Services/Geocode/WebService/GeocoderService_V04_01.asmx";
const QString url = host + endpoint;
QString xml = QString(R"(<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GeocodeAddressNonParsed xmlns="https://geoservices.tamu.edu/">
<streetAddress>string</streetAddress>
<city>string</city>
<state>string</state>
<zip>string</zip>
<apiKey>string</apiKey>
<version>double</version>
<shouldCalculateCensus>boolean</shouldCalculateCensus>
<censusYear>Unknown or NineteenNinety or TwoThousand or TwoThousandTen or AllAvailable</censusYear>
<shouldReturnReferenceGeometry>boolean</shouldReturnReferenceGeometry>
<shouldNotStoreTransactionDetails>boolean</shouldNotStoreTransactionDetails>
</GeocodeAddressNonParsed>
</soap12:Body>
</soap12:Envelope>)");
QByteArray xmlRequest = xml.toUtf8();
// SOAP download
RequestManager soap;
auto response = std::make_shared<SoapRequest>(soapAction, url, 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());
QCOMPARE(response.use_count(), 1L ); // this context + Soap
QCOMPARE(response->responseData(), xmlResponse);
}
void SoapTest::public_soap_xml()
{
QString soapAction = "blz:getBank";
QString url = "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, url, 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
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"