1 /****************************************************************************
2 ** Copyright (C) 2010-2020 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com.
3 ** All rights reserved.
4 **
5 ** This file is part of the KD Soap library.
6 **
7 ** Licensees holding valid commercial KD Soap licenses may use this file in
8 ** accordance with the KD Soap Commercial License Agreement provided with
9 ** the Software.
10 **
11 **
12 ** This file may be distributed and/or modified under the terms of the
13 ** GNU Lesser General Public License version 2.1 and version 3 as published by the
14 ** Free Software Foundation and appearing in the file LICENSE.LGPL.txt included.
15 **
16 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
17 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 **
19 ** Contact info@kdab.com if any conditions of this licensing are not
20 ** clear to you.
21 **
22 **********************************************************************/
23 
24 #include "KDSoapClientInterface.h"
25 #include "wsdl_BLZService.h"
26 #include "wsdl_BFGlobalService.h"
27 #include "wsdl_OrteLookup.h"
28 #include <QTest>
29 #include <QSignalSpy>
30 #include <QEventLoop>
31 #include <QDebug>
32 
33 class WebCallsWSDL : public QObject
34 {
35     Q_OBJECT
36 public:
37 
38 private slots:
39 
40 #if 0 // 2020-12-02 bad example, it's returning malformed XML!
41     // Soap in RPC mode; using WSDL-generated class
42     // http://www.soapclient.com/soapclient?fn=soapform&template=/clientform.html&soaptemplate=/soapresult.html&soapwsdl=http://soapclient.com/xml/soapresponder.wsdl
43     void testSoapResponder_sync()
44     {
45         EmptySA responder;
46         responder.setSoapVersion(KDSoapClientInterface::SOAP1_2);
47         QString ret = responder.echoString(QLatin1String("abc"));
48         QCOMPARE(ret, QString::fromLatin1("Your input parameters are abc and def"));
49     }
50 
51     void testSoapResponder_async()
52     {
53         EmptySA responder;
54         QSignalSpy spyDone(&responder, SIGNAL(echoStringDone(QString)));
55         QEventLoop eventLoop;
56         connect(&responder, SIGNAL(echoStringDone(QString)), &eventLoop, SLOT(quit()));
57         responder.asyncEchoString(QLatin1String("abc"));
58         eventLoop.exec();
59         QCOMPARE(spyDone.count(), 1);
60         QCOMPARE(spyDone[0][0].toString(), QString::fromLatin1("Your input parameters are abc and def"));
61     }
62 #endif
63 
64     // Soap in Document mode.
65 
66 #if 0 // 2020-02-12: http://www.thomas-bayer.com/axis2/services/BLZService?wsdl is down
67     void testBLZService_wsdl_soap()
68     {
69         BLZService::BLZServiceSOAP11Binding service;
70         TNS__GetBankType getBankType;
71         getBankType.setBlz("20130600"); // found on http://www.thebankcodes.com/blz/bybankname.php
72         TNS__GetBankResponseType response = service.getBank(getBankType);
73         QCOMPARE(response.details().bic(), QString::fromLatin1("BARCDEH1XXX"));
74         QCOMPARE(response.details().bezeichnung(), QString::fromLatin1("Barclaycard Barclays Bank"));
75         QCOMPARE(response.details().ort(), QString::fromLatin1("Hamburg"));
76         QCOMPARE(response.details().plz(), QString::fromLatin1("22702"));
77     }
78 
79     void testParallelAsyncRequests()
80     {
81         BLZService::BLZServiceSOAP11Binding service;
82         const QStringList expectedResults = {"BARCDEH1XXX", "BEBEDEBBXXX", "BEVODEBBXXX"};
83 
84         for (const char* blz : { "10020000", "20130600", "10090000" }) {
85             TNS__GetBankType getBankType;
86             getBankType.setBlz(QString::fromLatin1(blz));
87             service.asyncGetBank(getBankType);
88         }
89         connect(&service, SIGNAL(getBankDone(TNS__GetBankResponseType)),
90                 this, SLOT(slotGetBankDone(TNS__GetBankResponseType)));
91         connect(&service, SIGNAL(getBankError(KDSoapMessage)),
92                 this, SLOT(slotGetBankError(KDSoapMessage)));
93         m_eventLoop.exec();
94 
95         //qDebug() << m_resultsReceived;
96 
97         // Order of the replies is undefined.
98         m_resultsReceived.sort();
99         QCOMPARE(m_resultsReceived, expectedResults);
100     }
101 #endif
102 
testBetFair()103     void testBetFair() // SOAP-14
104     {
105         TYPES__LoginReq loginReq;
106         TYPES__LoginResp loginResp;
107         BFGlobalService globalService;
108         loginReq.setUsername(QLatin1String("user"));
109         loginReq.setPassword(QLatin1String("pass"));
110         loginReq.setProductId(82);
111         loginReq.setIpAddress(QLatin1String("0"));
112         loginReq.setVendorSoftwareId(0);
113 
114         TNS__Login loginParam;
115         loginParam.setRequest(loginReq);
116         TNS__LoginResponse lResp;
117         lResp.setResult(loginResp);
118 
119         // Don't make the call, it errors out (invalid login/pass, but also restricted country)
120         if (false) {
121             lResp = globalService.login(loginParam);
122             qDebug() << globalService.lastError();
123         }
124     }
125 
testOrteLookup()126     void testOrteLookup()
127     {
128         // TODO OrteLookup::OrteLookupSoap12 lookup;
129         OrteLookup::OrteLookupSoap lookup;
130         //lookup.setSoapVersion(KDSoapClientInterface::SOAP1_2);
131         TNS__OrteStartWith args;
132         args.setPrefix(QLatin1String("Berl"));
133         TNS__OrteStartWithResponse resp = lookup.orteStartWith(args);
134         if (!lookup.lastError().isEmpty()) {
135             qWarning("%s", qPrintable(lookup.lastError()));
136         }
137         QCOMPARE(resp.orteStartWithResult(), QString::fromLatin1("Berlin;Berlstedt"));
138     }
139 
140 protected slots:
slotGetBankDone(const TNS__GetBankResponseType & response)141     void slotGetBankDone(const TNS__GetBankResponseType &response)
142     {
143         m_resultsReceived << response.details().bic();
144         if (m_resultsReceived.count() == 3) {
145             m_eventLoop.quit();
146         }
147     }
148 
slotGetBankError(const KDSoapMessage & msg)149     void slotGetBankError(const KDSoapMessage &msg)
150     {
151         m_resultsReceived << msg.faultAsString();
152         if (m_resultsReceived.count() == 3) {
153             m_eventLoop.quit();
154         }
155     }
156 
157 private:
158     QEventLoop m_eventLoop;
159     QStringList m_resultsReceived;
160 };
161 
162 QTEST_MAIN(WebCallsWSDL)
163 
164 #include "webcalls_wsdl.moc"
165 
166