diff --git a/serversdkint.pri b/serversdkint.pri index 9272e45..0b72df8 100644 --- a/serversdkint.pri +++ b/serversdkint.pri @@ -25,7 +25,7 @@ win32:CONFIG(release, debug|release): LIBS += -L$$SDKDIR/release/ -lserversdk else:win32:CONFIG(debug, debug|release): LIBS += -L$$SDKDIR/debug/ -lserversdk else:unix: LIBS += -L$$SDKDIR/ -lserversdk -lz - +QT += network INCLUDEPATH += $$PWD/src/ DEPENDPATH += $$PWD/src/serversdk diff --git a/src/serversdk/logger.cpp b/src/serversdk/logger.cpp index 3b18e0e..2db66c8 100644 --- a/src/serversdk/logger.cpp +++ b/src/serversdk/logger.cpp @@ -6,7 +6,7 @@ Q_LOGGING_CATEGORY(sdkcore, "sdk.core"); Q_LOGGING_CATEGORY(sdknetwork, "sdk.network"); -Q_LOGGING_CATEGORY(sdkcompress, "sdk.compress"); +Q_LOGGING_CATEGORY(sdkutils, "sdk.utils"); namespace serversdk { diff --git a/src/serversdk/logger.h b/src/serversdk/logger.h index 989f63f..88868b2 100644 --- a/src/serversdk/logger.h +++ b/src/serversdk/logger.h @@ -10,7 +10,7 @@ Q_DECLARE_LOGGING_CATEGORY(sdkcore) Q_DECLARE_LOGGING_CATEGORY(sdknetwork) -Q_DECLARE_LOGGING_CATEGORY(sdkcompress) +Q_DECLARE_LOGGING_CATEGORY(sdkutils) namespace serversdk { diff --git a/src/serversdk/request.h b/src/serversdk/request.h index 17b0b42..424365c 100644 --- a/src/serversdk/request.h +++ b/src/serversdk/request.h @@ -61,4 +61,6 @@ private: QByteArray mResponseData; }; + } // core + diff --git a/src/serversdk/soaprequest.h b/src/serversdk/soaprequest.h index 2c8617c..a191a6b 100644 --- a/src/serversdk/soaprequest.h +++ b/src/serversdk/soaprequest.h @@ -6,6 +6,7 @@ namespace serversdk { class SoapRequest : public Request { + Q_OBJECT public: SoapRequest(QString action, QString endpoint, QByteArray data); QNetworkRequest networkRequest() const override; diff --git a/src/serversdk/utils.cpp b/src/serversdk/utils.cpp index 9b7650f..89ba25a 100644 --- a/src/serversdk/utils.cpp +++ b/src/serversdk/utils.cpp @@ -68,7 +68,7 @@ QByteArray Utils::decompress(const QByteArray &compressed) float ratio = (float)compressed.count() / (float)result.count(); float compression = ratio * 100.0; - qCInfo(sdkcompress) << "compress data:" << compressed.count() + qCInfo(sdkutils) << "compress data:" << compressed.count() << "uncompressed data:" << result.count() << "compression:" << compression; @@ -97,7 +97,7 @@ QByteArray Utils::sourceData(const QString &subpath) // Get data from file QString filePath = sourcePath(subpath); if (! QFileInfo::exists(filePath)) { - qCWarning(sdkcompress) << "path does not exists:" << filePath; + qCWarning(sdkutils) << "path does not exists:" << filePath; return QByteArray(); } QFile file(filePath); diff --git a/test/auto/auto.pro b/test/auto/auto.pro index 0fe1e4f..043d922 100644 --- a/test/auto/auto.pro +++ b/test/auto/auto.pro @@ -2,5 +2,6 @@ TEMPLATE = subdirs SUBDIRS += \ basic \ + soap \ unittests \ utils diff --git a/test/auto/soap/soap.pro b/test/auto/soap/soap.pro new file mode 100644 index 0000000..cb65479 --- /dev/null +++ b/test/auto/soap/soap.pro @@ -0,0 +1,11 @@ +QT += testlib +QT -= gui + +CONFIG += qt console warn_on depend_includepath testcase +CONFIG -= app_bundle + +TEMPLATE = app + +SOURCES += tst_soaptest.cpp + +include(../../../serversdkint.pri) diff --git a/test/auto/soap/tst_soaptest.cpp b/test/auto/soap/tst_soaptest.cpp new file mode 100644 index 0000000..4300c83 --- /dev/null +++ b/test/auto/soap/tst_soaptest.cpp @@ -0,0 +1,166 @@ +#include +#include + +#include "serversdk/requestmanager.h" +#include "serversdk/utils.h" +#include "serversdk/soaprequest.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"); +} + +void SoapTest::construct() +{ + RequestManager soap; + + QVERIFY(soap.mRequestMap.isEmpty()); + + QFileInfo info(Utils::sourcePath("")); + QCOMPARE(info.fileName(), QStringLiteral("data")); + + QCOMPARE(Utils::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("" \ + "" \ + " " \ + " " \ + " %1" \ + " " \ + "" \ + "").arg("10020200"); + + QByteArray xmlRequest = xml.toUtf8(); + + // SOAP download + RequestManager soap; + auto response = std::make_shared(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 = Utils::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 = Utils::sourceData(xmlRequestFile); + QVERIFY( ! xmlRequest.isEmpty()); + // Response + QByteArray xmlResponse = Utils::sourceData(xmlResponseFile); + QVERIFY( ! xmlResponse.isEmpty()); + + // RequestManagerrequest + auto req = std::make_shared(soapAction, endpoint, xmlRequest); + req->setSoapVersion12(soap12); + + // RequestManagerdownload + RequestManager soap; + soap.processRequest(req); + + QSignalSpy progressSpy(&soap, &RequestManager::progresss); + QSignalSpy finishedSpy(&soap, &RequestManager::downloadFinished); + QVERIFY(finishedSpy.wait(20000)); + QVERIFY(progressSpy.count()); + + //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->data()); + // 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("soapAction"); + QTest::addColumn("endpoint"); + QTest::addColumn("xmlRequestFile"); + QTest::addColumn("xmlResponseFile"); + QTest::addColumn("soap12"); + QTest::addColumn("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" diff --git a/test/data/soap/LatLonListSubgrid-response.xml b/test/data/soap/LatLonListSubgrid-response.xml new file mode 100644 index 0000000..f638363 --- /dev/null +++ b/test/data/soap/LatLonListSubgrid-response.xml @@ -0,0 +1 @@ +<?xml version='1.0'?><dwml version='1.0' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='https://graphical.weather.gov/xml/DWMLgen/schema/DWML.xsd'><latLonList>34.986638,-82.027411 35.120891,-82.011661 35.255084,-81.995872 35.389215,-81.980045 35.523285,-81.964180 34.973669,-81.863528 35.107911,-81.847581 35.242094,-81.831596 35.376216,-81.815571 35.510276,-81.799508 34.960536,-81.699684 35.094768,-81.683540 35.228941,-81.667358 35.363052,-81.651136 35.497102,-81.634876 34.947240,-81.535878 35.081463,-81.519539 35.215625,-81.503160 35.349726,-81.486741 35.483766,-81.470282</latLonList></dwml> \ No newline at end of file diff --git a/test/data/soap/LatLonListSubgrid.xml b/test/data/soap/LatLonListSubgrid.xml new file mode 100644 index 0000000..1bbced9 --- /dev/null +++ b/test/data/soap/LatLonListSubgrid.xml @@ -0,0 +1,12 @@ + + + + +35.00 +-82.00 +35.5 +-81.50 +20.0 + + + \ No newline at end of file diff --git a/test/data/soap/bankapi-1.2-response.xml b/test/data/soap/bankapi-1.2-response.xml new file mode 100644 index 0000000..27ed395 --- /dev/null +++ b/test/data/soap/bankapi-1.2-response.xml @@ -0,0 +1 @@ +BHF-BANKBHFBDEFF100Berlin10117 \ No newline at end of file diff --git a/test/data/soap/bankapi-1.2.sh b/test/data/soap/bankapi-1.2.sh new file mode 100755 index 0000000..b50801d --- /dev/null +++ b/test/data/soap/bankapi-1.2.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# @see https://stackoverflow.com/a/55352633/1917249 + +ACTION_YOU_WANT_TO_CALL="blz:getBank" + +XMLFILENAME=test03-1.2.xml + +URL_OF_THE_SOAP_WEB_SERVICE_ENDPOINT="http://www.thomas-bayer.com/axis2/services/BLZService" + +curl -X POST $URL_OF_THE_SOAP_WEB_SERVICE_ENDPOINT \ + -H 'Content-Type: application/soap+xml;action=$ACTION_YOU_WANT_TO_CALL' \ + -H 'SOAPAction: $ACTION_YOU_WANT_TO_CALL' \ + --data @$XMLFILENAME > test03-1.2-response.xml diff --git a/test/data/soap/bankapi-1.2.xml b/test/data/soap/bankapi-1.2.xml new file mode 100644 index 0000000..2f39f54 --- /dev/null +++ b/test/data/soap/bankapi-1.2.xml @@ -0,0 +1,10 @@ + + + + + 10020200 + + + diff --git a/test/data/soap/bankapi-response.xml b/test/data/soap/bankapi-response.xml new file mode 100644 index 0000000..b00a3e0 --- /dev/null +++ b/test/data/soap/bankapi-response.xml @@ -0,0 +1 @@ +BHF-BANKBHFBDEFF100Berlin10117 \ No newline at end of file diff --git a/test/data/soap/bankapi.sh b/test/data/soap/bankapi.sh new file mode 100755 index 0000000..2ef4bb5 --- /dev/null +++ b/test/data/soap/bankapi.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# @see https://stackoverflow.com/a/55352633/1917249 + +ACTION_YOU_WANT_TO_CALL="blz:getBank" + +XMLFILENAME=test03.xml + +URL_OF_THE_SOAP_WEB_SERVICE_ENDPOINT="http://www.thomas-bayer.com/axis2/services/BLZService" + +curl -X POST $URL_OF_THE_SOAP_WEB_SERVICE_ENDPOINT \ + -H 'Content-Type: text/xml' \ + -H 'SOAPAction: $ACTION_YOU_WANT_TO_CALL' \ + --data @$XMLFILENAME > test03-response.xml diff --git a/test/data/soap/bankapi.xml b/test/data/soap/bankapi.xml new file mode 100644 index 0000000..0fb7677 --- /dev/null +++ b/test/data/soap/bankapi.xml @@ -0,0 +1,10 @@ + + + + + 10020200 + + +