File indexing completed on 2024-11-24 04:43:52

0001 /*
0002     SPDX-FileCopyrightText: 2015-2017 Krzysztof Nowicki <krissn@op.pl>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include <QTest>
0008 
0009 #include "fakehttppost.h"
0010 
0011 #include "ewsunsubscriberequest.h"
0012 
0013 class UtEwsUnsibscribeRequest : public QObject
0014 {
0015     Q_OBJECT
0016 private Q_SLOTS:
0017     void simple();
0018 
0019 private:
0020     void verifier(FakeTransferJob *job, const QByteArray &req, const QByteArray &expReq, const QByteArray &resp);
0021 
0022     EwsClient mClient;
0023 };
0024 
0025 void UtEwsUnsibscribeRequest::simple()
0026 {
0027     static const QByteArray request =
0028         "<?xml version=\"1.0\"?>"
0029         "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" "
0030         "xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\" "
0031         "xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">"
0032         "<soap:Header><t:RequestServerVersion Version=\"Exchange2007_SP1\"/></soap:Header>"
0033         "<soap:Body>"
0034         "<m:Unsubscribe>"
0035         "<m:SubscriptionId>dwzVKTlwXxBZtQRMucP5Mg==</m:SubscriptionId>"
0036         "</m:Unsubscribe></soap:Body></soap:Envelope>\n";
0037     static const QByteArray response =
0038         "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
0039         "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">"
0040         "<s:Header><h:ServerVersionInfo xmlns:h=\"http://schemas.microsoft.com/exchange/services/2006/types\" "
0041         "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
0042         "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
0043         "MajorVersion=\"15\" MinorVersion=\"1\" MajorBuildNumber=\"409\" "
0044         "MinorBuildNumber=\"24\" Version=\"V2016_01_06\"/>"
0045         "</s:Header>"
0046         "<s:Body>"
0047         "<m:UnsubscribeResponse xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\" "
0048         "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
0049         "xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">"
0050         "<m:ResponseMessages>"
0051         "<m:UnsubscribeResponseMessage ResponseClass=\"Success\">"
0052         "<m:ResponseCode>NoError</m:ResponseCode>"
0053         "</m:UnsubscribeResponseMessage>"
0054         "</m:ResponseMessages>"
0055         "</m:UnsubscribeResponse>"
0056         "</s:Body></s:Envelope>";
0057 
0058     FakeTransferJob::addVerifier(this, [this](FakeTransferJob *job, const QByteArray &req) {
0059         verifier(job, req, request, response);
0060     });
0061     QScopedPointer<EwsUnsubscribeRequest> req(new EwsUnsubscribeRequest(mClient, this));
0062     req->setSubscriptionId(QStringLiteral("dwzVKTlwXxBZtQRMucP5Mg=="));
0063 
0064     req->exec();
0065 
0066     QCOMPARE(req->error(), 0);
0067 }
0068 
0069 void UtEwsUnsibscribeRequest::verifier(FakeTransferJob *job, const QByteArray &req, const QByteArray &expReq, const QByteArray &response)
0070 {
0071     bool fail = true;
0072     auto f = finally([&fail, &job] {
0073         if (fail) {
0074             job->postResponse("");
0075         }
0076     });
0077     QCOMPARE(req, expReq);
0078     fail = false;
0079     job->postResponse(response);
0080 }
0081 
0082 QTEST_MAIN(UtEwsUnsibscribeRequest)
0083 
0084 #include "ewsunsubscriberequest_ut.moc"