File indexing completed on 2024-11-24 04:43:51
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 "ewsdeleteitemrequest.h" 0012 0013 class UtEwsDeleteItemRequest : public QObject 0014 { 0015 Q_OBJECT 0016 private Q_SLOTS: 0017 void singleItem(); 0018 void twoItems(); 0019 void twoItemsOneFailed(); 0020 void twoItemsSecondFailed(); 0021 0022 private: 0023 void verifier(FakeTransferJob *job, const QByteArray &req, const QByteArray &expReq, const QByteArray &resp); 0024 0025 EwsClient mClient; 0026 }; 0027 0028 void UtEwsDeleteItemRequest::singleItem() 0029 { 0030 static const QByteArray request = 0031 "<?xml version=\"1.0\"?>" 0032 "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " 0033 "xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\" " 0034 "xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">" 0035 "<soap:Header><t:RequestServerVersion Version=\"Exchange2007_SP1\"/>" 0036 "</soap:Header><soap:Body><m:DeleteItem DeleteType=\"SoftDelete\">" 0037 "<m:ItemIds><t:ItemId Id=\"+IRgnMJ8x+J6MQAZ\" ChangeKey=\"1iQt/At9\"/></m:ItemIds>" 0038 "</m:DeleteItem></soap:Body></soap:Envelope>\n"; 0039 static const QByteArray response = 0040 "<?xml version=\"1.0\" encoding=\"utf-8\"?>" 0041 "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" 0042 "<s:Header>" 0043 "<h:ServerVersionInfo MajorVersion=\"14\" MinorVersion=\"3\" " 0044 "MajorBuildNumber=\"248\" MinorBuildNumber=\"2\" " 0045 "Version=\"Exchange2007_SP1\" " 0046 "xmlns:h=\"http://schemas.microsoft.com/exchange/services/2006/types\" " 0047 "xmlns=\"http://schemas.microsoft.com/exchange/services/2006/types\" " 0048 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " 0049 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"/>" 0050 "</s:Header>" 0051 "<s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " 0052 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" 0053 "<m:DeleteItemResponse " 0054 "xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\" " 0055 "xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">" 0056 "<m:ResponseMessages>" 0057 "<m:DeleteItemResponseMessage ResponseClass=\"Success\">" 0058 "<m:ResponseCode>NoError</m:ResponseCode>" 0059 "</m:DeleteItemResponseMessage>" 0060 "</m:ResponseMessages>" 0061 "</m:DeleteItemResponse>" 0062 "</s:Body>" 0063 "</s:Envelope>"; 0064 0065 FakeTransferJob::addVerifier(this, [this](FakeTransferJob *job, const QByteArray &req) { 0066 verifier(job, req, request, response); 0067 }); 0068 QScopedPointer<EwsDeleteItemRequest> req(new EwsDeleteItemRequest(mClient, this)); 0069 EwsId::List ids; 0070 ids << EwsId(QStringLiteral("+IRgnMJ8x+J6MQAZ"), QStringLiteral("1iQt/At9")); 0071 req->setItemIds(ids); 0072 req->exec(); 0073 0074 QCOMPARE(req->error(), 0); 0075 QCOMPARE(req->responses().size(), 1); 0076 EwsDeleteItemRequest::Response resp = req->responses().first(); 0077 QCOMPARE(resp.responseClass(), EwsResponseSuccess); 0078 } 0079 0080 void UtEwsDeleteItemRequest::twoItems() 0081 { 0082 static const QByteArray request = 0083 "<?xml version=\"1.0\"?>" 0084 "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " 0085 "xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\" " 0086 "xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">" 0087 "<soap:Header><t:RequestServerVersion Version=\"Exchange2007_SP1\"/>" 0088 "</soap:Header><soap:Body><m:DeleteItem DeleteType=\"SoftDelete\">" 0089 "<m:ItemIds>" 0090 "<t:ItemId Id=\"9LB1MiL3cOYUjmYy\" ChangeKey=\"TBjl3rnU\"/>" 0091 "<t:ItemId Id=\"rZ0sc7Gfn9+XHVgv\" ChangeKey=\"pHTEe9nY\"/>" 0092 "</m:ItemIds>" 0093 "</m:DeleteItem></soap:Body></soap:Envelope>\n"; 0094 static const QByteArray response = 0095 "<?xml version=\"1.0\" encoding=\"utf-8\"?>" 0096 "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" 0097 "<s:Header>" 0098 "<h:ServerVersionInfo MajorVersion=\"14\" MinorVersion=\"3\" " 0099 "MajorBuildNumber=\"248\" MinorBuildNumber=\"2\" " 0100 "Version=\"Exchange2007_SP1\" " 0101 "xmlns:h=\"http://schemas.microsoft.com/exchange/services/2006/types\" " 0102 "xmlns=\"http://schemas.microsoft.com/exchange/services/2006/types\" " 0103 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " 0104 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"/>" 0105 "</s:Header>" 0106 "<s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " 0107 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" 0108 "<m:DeleteItemResponse " 0109 "xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\" " 0110 "xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">" 0111 "<m:ResponseMessages>" 0112 "<m:DeleteItemResponseMessage ResponseClass=\"Success\">" 0113 "<m:ResponseCode>NoError</m:ResponseCode>" 0114 "</m:DeleteItemResponseMessage>" 0115 "<m:DeleteItemResponseMessage ResponseClass=\"Success\">" 0116 "<m:ResponseCode>NoError</m:ResponseCode>" 0117 "</m:DeleteItemResponseMessage>" 0118 "</m:ResponseMessages>" 0119 "</m:DeleteItemResponse>" 0120 "</s:Body>" 0121 "</s:Envelope>"; 0122 0123 FakeTransferJob::addVerifier(this, [this](FakeTransferJob *job, const QByteArray &req) { 0124 verifier(job, req, request, response); 0125 }); 0126 QScopedPointer<EwsDeleteItemRequest> req(new EwsDeleteItemRequest(mClient, this)); 0127 static const EwsId::List ids = {EwsId(QStringLiteral("9LB1MiL3cOYUjmYy"), QStringLiteral("TBjl3rnU")), 0128 EwsId(QStringLiteral("rZ0sc7Gfn9+XHVgv"), QStringLiteral("pHTEe9nY"))}; 0129 req->setItemIds(ids); 0130 req->exec(); 0131 0132 QCOMPARE(req->error(), 0); 0133 QCOMPARE(req->responses().size(), 2); 0134 const auto responses{req->responses()}; 0135 for (const EwsDeleteItemRequest::Response &resp : responses) { 0136 QCOMPARE(resp.responseClass(), EwsResponseSuccess); 0137 } 0138 } 0139 0140 void UtEwsDeleteItemRequest::twoItemsOneFailed() 0141 { 0142 static const QByteArray request = 0143 "<?xml version=\"1.0\"?>" 0144 "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " 0145 "xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\" " 0146 "xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">" 0147 "<soap:Header><t:RequestServerVersion Version=\"Exchange2007_SP1\"/>" 0148 "</soap:Header><soap:Body><m:DeleteItem DeleteType=\"SoftDelete\">" 0149 "<m:ItemIds>" 0150 "<t:ItemId Id=\"9LB1MiL3cOYUjmYy\" ChangeKey=\"TBjl3rnU\"/>" 0151 "<t:ItemId Id=\"rZ0sc7Gfn9+XHVgv\" ChangeKey=\"pHTEe9nY\"/>" 0152 "</m:ItemIds>" 0153 "</m:DeleteItem></soap:Body></soap:Envelope>\n"; 0154 static const QByteArray response = 0155 "<?xml version=\"1.0\" encoding=\"utf-8\"?>" 0156 "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" 0157 "<s:Header>" 0158 "<h:ServerVersionInfo MajorVersion=\"14\" MinorVersion=\"3\" " 0159 "MajorBuildNumber=\"248\" MinorBuildNumber=\"2\" " 0160 "Version=\"Exchange2007_SP1\" " 0161 "xmlns:h=\"http://schemas.microsoft.com/exchange/services/2006/types\" " 0162 "xmlns=\"http://schemas.microsoft.com/exchange/services/2006/types\" " 0163 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " 0164 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"/>" 0165 "</s:Header>" 0166 "<s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " 0167 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" 0168 "<m:DeleteItemResponse " 0169 "xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\" " 0170 "xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">" 0171 "<m:ResponseMessages>" 0172 "<m:DeleteItemResponseMessage ResponseClass=\"Error\">" 0173 "<m:MessageText>The specified object was not found in the store.</m:MessageText>" 0174 "<m:ResponseCode>ErrorItemNotFound</m:ResponseCode>" 0175 "<m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>" 0176 "</m:DeleteItemResponseMessage>" 0177 "<m:DeleteItemResponseMessage ResponseClass=\"Success\">" 0178 "<m:ResponseCode>NoError</m:ResponseCode>" 0179 "</m:DeleteItemResponseMessage>" 0180 "</m:ResponseMessages>" 0181 "</m:DeleteItemResponse>" 0182 "</s:Body>" 0183 "</s:Envelope>"; 0184 0185 FakeTransferJob::addVerifier(this, [this](FakeTransferJob *job, const QByteArray &req) { 0186 verifier(job, req, request, response); 0187 }); 0188 QScopedPointer<EwsDeleteItemRequest> req(new EwsDeleteItemRequest(mClient, this)); 0189 static const EwsId::List ids = {EwsId(QStringLiteral("9LB1MiL3cOYUjmYy"), QStringLiteral("TBjl3rnU")), 0190 EwsId(QStringLiteral("rZ0sc7Gfn9+XHVgv"), QStringLiteral("pHTEe9nY"))}; 0191 req->setItemIds(ids); 0192 req->exec(); 0193 0194 QCOMPARE(req->error(), 0); 0195 QCOMPARE(req->responses().size(), 2); 0196 static const QList<EwsResponseClass> respClasses = {EwsResponseError, EwsResponseSuccess}; 0197 QList<EwsResponseClass>::const_iterator respClassesIt = respClasses.begin(); 0198 unsigned i = 0; 0199 const auto responses{req->responses()}; 0200 for (const EwsDeleteItemRequest::Response &resp : responses) { 0201 qDebug() << "Verifying response" << i++; 0202 QCOMPARE(resp.responseClass(), *respClassesIt); 0203 respClassesIt++; 0204 } 0205 } 0206 0207 void UtEwsDeleteItemRequest::twoItemsSecondFailed() 0208 { 0209 static const QByteArray request = 0210 "<?xml version=\"1.0\"?>" 0211 "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " 0212 "xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\" " 0213 "xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">" 0214 "<soap:Header><t:RequestServerVersion Version=\"Exchange2007_SP1\"/>" 0215 "</soap:Header><soap:Body><m:DeleteItem DeleteType=\"SoftDelete\">" 0216 "<m:ItemIds>" 0217 "<t:ItemId Id=\"9LB1MiL3cOYUjmYy\" ChangeKey=\"TBjl3rnU\"/>" 0218 "<t:ItemId Id=\"rZ0sc7Gfn9+XHVgv\" ChangeKey=\"pHTEe9nY\"/>" 0219 "</m:ItemIds>" 0220 "</m:DeleteItem></soap:Body></soap:Envelope>\n"; 0221 static const QByteArray response = 0222 "<?xml version=\"1.0\" encoding=\"utf-8\"?>" 0223 "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" 0224 "<s:Header>" 0225 "<h:ServerVersionInfo MajorVersion=\"14\" MinorVersion=\"3\" " 0226 "MajorBuildNumber=\"248\" MinorBuildNumber=\"2\" " 0227 "Version=\"Exchange2007_SP1\" " 0228 "xmlns:h=\"http://schemas.microsoft.com/exchange/services/2006/types\" " 0229 "xmlns=\"http://schemas.microsoft.com/exchange/services/2006/types\" " 0230 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " 0231 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"/>" 0232 "</s:Header>" 0233 "<s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " 0234 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" 0235 "<m:DeleteItemResponse " 0236 "xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\" " 0237 "xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">" 0238 "<m:ResponseMessages>" 0239 "<m:DeleteItemResponseMessage ResponseClass=\"Error\">" 0240 "<m:MessageText>The specified object was not found in the store.</m:MessageText>" 0241 "<m:ResponseCode>ErrorItemNotFound</m:ResponseCode>" 0242 "<m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>" 0243 "</m:DeleteItemResponseMessage>" 0244 "<m:DeleteItemResponseMessage ResponseClass=\"Success\">" 0245 "<m:ResponseCode>NoError</m:ResponseCode>" 0246 "</m:DeleteItemResponseMessage>" 0247 "</m:ResponseMessages>" 0248 "</m:DeleteItemResponse>" 0249 "</s:Body>" 0250 "</s:Envelope>"; 0251 0252 FakeTransferJob::addVerifier(this, [this](FakeTransferJob *job, const QByteArray &req) { 0253 verifier(job, req, request, response); 0254 }); 0255 QScopedPointer<EwsDeleteItemRequest> req(new EwsDeleteItemRequest(mClient, this)); 0256 static const EwsId::List ids = {EwsId(QStringLiteral("9LB1MiL3cOYUjmYy"), QStringLiteral("TBjl3rnU")), 0257 EwsId(QStringLiteral("rZ0sc7Gfn9+XHVgv"), QStringLiteral("pHTEe9nY"))}; 0258 req->setItemIds(ids); 0259 req->exec(); 0260 0261 QCOMPARE(req->error(), 0); 0262 QCOMPARE(req->responses().size(), 2); 0263 static const QList<EwsResponseClass> respClasses = {EwsResponseError, EwsResponseSuccess}; 0264 QList<EwsResponseClass>::const_iterator respClassesIt = respClasses.begin(); 0265 unsigned i = 0; 0266 const auto responses{req->responses()}; 0267 for (const EwsDeleteItemRequest::Response &resp : responses) { 0268 qDebug() << "Verifying response" << i++; 0269 QCOMPARE(resp.responseClass(), *respClassesIt); 0270 respClassesIt++; 0271 } 0272 } 0273 0274 void UtEwsDeleteItemRequest::verifier(FakeTransferJob *job, const QByteArray &req, const QByteArray &expReq, const QByteArray &response) 0275 { 0276 bool fail = true; 0277 auto f = finally([&fail, &job] { 0278 if (fail) { 0279 job->postResponse(""); 0280 } 0281 }); 0282 QCOMPARE(req, expReq); 0283 fail = false; 0284 job->postResponse(response); 0285 } 0286 0287 QTEST_MAIN(UtEwsDeleteItemRequest) 0288 0289 #include "ewsdeleteitemrequest_ut.moc"