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 "ewsmoveitemrequest.h" 0012 0013 class UtEwsMoveItemRequest : 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 UtEwsMoveItemRequest::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:MoveItem><m:ToFolderId>" 0037 "<t:FolderId Id=\"R70cDGNT1SqOk2pn\" ChangeKey=\"1DjfJ3dT\"/>" 0038 "</m:ToFolderId>" 0039 "<m:ItemIds><t:ItemId Id=\"Xnn2DwwaXQUhbn7U\" ChangeKey=\"rqs77HkG\"/></m:ItemIds>" 0040 "</m:MoveItem></soap:Body></soap:Envelope>\n"; 0041 static const QByteArray response = 0042 "<?xml version=\"1.0\" encoding=\"utf-8\"?>" 0043 "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" 0044 "<s:Header>" 0045 "<h:ServerVersionInfo MajorVersion=\"14\" MinorVersion=\"3\" " 0046 "MajorBuildNumber=\"248\" MinorBuildNumber=\"2\" " 0047 "Version=\"Exchange2007_SP1\" " 0048 "xmlns:h=\"http://schemas.microsoft.com/exchange/services/2006/types\" " 0049 "xmlns=\"http://schemas.microsoft.com/exchange/services/2006/types\" " 0050 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " 0051 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"/>" 0052 "</s:Header>" 0053 "<s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " 0054 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" 0055 "<m:MoveItemResponse " 0056 "xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\" " 0057 "xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">" 0058 "<m:ResponseMessages>" 0059 "<m:MoveItemResponseMessage ResponseClass=\"Success\">" 0060 "<m:ResponseCode>NoError</m:ResponseCode>" 0061 "<m:Items>" 0062 "<t:Message><t:ItemId Id=\"Xnn2DwwaXQUhbn7U\" ChangeKey=\"JoFvRwDP\"/>" 0063 "</t:Message>" 0064 "</m:Items>" 0065 "</m:MoveItemResponseMessage>" 0066 "</m:ResponseMessages>" 0067 "</m:MoveItemResponse>" 0068 "</s:Body>" 0069 "</s:Envelope>"; 0070 0071 FakeTransferJob::addVerifier(this, [this](FakeTransferJob *job, const QByteArray &req) { 0072 verifier(job, req, request, response); 0073 }); 0074 QScopedPointer<EwsMoveItemRequest> req(new EwsMoveItemRequest(mClient, this)); 0075 EwsId::List ids; 0076 ids << EwsId(QStringLiteral("Xnn2DwwaXQUhbn7U"), QStringLiteral("rqs77HkG")); 0077 req->setItemIds(ids); 0078 req->setDestinationFolderId(EwsId(QStringLiteral("R70cDGNT1SqOk2pn"), QStringLiteral("1DjfJ3dT"))); 0079 req->exec(); 0080 0081 QCOMPARE(req->error(), 0); 0082 QCOMPARE(req->responses().size(), 1); 0083 EwsMoveItemRequest::Response resp = req->responses().first(); 0084 QCOMPARE(resp.responseClass(), EwsResponseSuccess); 0085 QCOMPARE(resp.itemId(), EwsId(QStringLiteral("Xnn2DwwaXQUhbn7U"), QStringLiteral("JoFvRwDP"))); 0086 } 0087 0088 void UtEwsMoveItemRequest::twoItems() 0089 { 0090 static const QByteArray request = 0091 "<?xml version=\"1.0\"?>" 0092 "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " 0093 "xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\" " 0094 "xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">" 0095 "<soap:Header><t:RequestServerVersion Version=\"Exchange2007_SP1\"/>" 0096 "</soap:Header><soap:Body><m:MoveItem><m:ToFolderId>" 0097 "<t:FolderId Id=\"R70cDGNT1SqOk2pn\" ChangeKey=\"1DjfJ3dT\"/>" 0098 "</m:ToFolderId>" 0099 "<m:ItemIds>" 0100 "<t:ItemId Id=\"Xnn2DwwaXQUhbn7U\" ChangeKey=\"rqs77HkG\"/>" 0101 "<t:ItemId Id=\"ntTNOncESwiyAXog\" ChangeKey=\"EDHu5rwK\"/>" 0102 "</m:ItemIds>" 0103 "</m:MoveItem></soap:Body></soap:Envelope>\n"; 0104 static const QByteArray response = 0105 "<?xml version=\"1.0\" encoding=\"utf-8\"?>" 0106 "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" 0107 "<s:Header>" 0108 "<h:ServerVersionInfo MajorVersion=\"14\" MinorVersion=\"3\" " 0109 "MajorBuildNumber=\"248\" MinorBuildNumber=\"2\" " 0110 "Version=\"Exchange2007_SP1\" " 0111 "xmlns:h=\"http://schemas.microsoft.com/exchange/services/2006/types\" " 0112 "xmlns=\"http://schemas.microsoft.com/exchange/services/2006/types\" " 0113 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " 0114 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"/>" 0115 "</s:Header>" 0116 "<s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " 0117 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" 0118 "<m:MoveItemResponse " 0119 "xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\" " 0120 "xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">" 0121 "<m:ResponseMessages>" 0122 "<m:MoveItemResponseMessage ResponseClass=\"Success\">" 0123 "<m:ResponseCode>NoError</m:ResponseCode>" 0124 "<m:Items>" 0125 "<t:Message><t:ItemId Id=\"Xnn2DwwaXQUhbn7U\" ChangeKey=\"JoFvRwDP\"/>" 0126 "</t:Message>" 0127 "</m:Items>" 0128 "</m:MoveItemResponseMessage>" 0129 "<m:MoveItemResponseMessage ResponseClass=\"Success\">" 0130 "<m:ResponseCode>NoError</m:ResponseCode>" 0131 "<m:Items>" 0132 "<t:Message><t:ItemId Id=\"ntTNOncESwiyAXog\" ChangeKey=\"4qbAwd3y\"/>" 0133 "</t:Message>" 0134 "</m:Items>" 0135 "</m:MoveItemResponseMessage>" 0136 "</m:ResponseMessages>" 0137 "</m:MoveItemResponse>" 0138 "</s:Body>" 0139 "</s:Envelope>"; 0140 0141 FakeTransferJob::addVerifier(this, [this](FakeTransferJob *job, const QByteArray &req) { 0142 verifier(job, req, request, response); 0143 }); 0144 QScopedPointer<EwsMoveItemRequest> req(new EwsMoveItemRequest(mClient, this)); 0145 static const EwsId::List ids = {EwsId(QStringLiteral("Xnn2DwwaXQUhbn7U"), QStringLiteral("rqs77HkG")), 0146 EwsId(QStringLiteral("ntTNOncESwiyAXog"), QStringLiteral("EDHu5rwK"))}; 0147 req->setItemIds(ids); 0148 req->setDestinationFolderId(EwsId(QStringLiteral("R70cDGNT1SqOk2pn"), QStringLiteral("1DjfJ3dT"))); 0149 req->exec(); 0150 0151 QCOMPARE(req->error(), 0); 0152 QCOMPARE(req->responses().size(), 2); 0153 static const EwsId::List newIds = {EwsId(QStringLiteral("Xnn2DwwaXQUhbn7U"), QStringLiteral("JoFvRwDP")), 0154 EwsId(QStringLiteral("ntTNOncESwiyAXog"), QStringLiteral("4qbAwd3y"))}; 0155 EwsId::List::const_iterator newIdsIt = newIds.begin(); 0156 const auto reqResponses{req->responses()}; 0157 for (const EwsMoveItemRequest::Response &resp : reqResponses) { 0158 QCOMPARE(resp.responseClass(), EwsResponseSuccess); 0159 QCOMPARE(resp.itemId(), *newIdsIt); 0160 ++newIdsIt; 0161 } 0162 } 0163 0164 void UtEwsMoveItemRequest::twoItemsOneFailed() 0165 { 0166 static const QByteArray request = 0167 "<?xml version=\"1.0\"?>" 0168 "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " 0169 "xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\" " 0170 "xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">" 0171 "<soap:Header><t:RequestServerVersion Version=\"Exchange2007_SP1\"/>" 0172 "</soap:Header><soap:Body><m:MoveItem><m:ToFolderId>" 0173 "<t:FolderId Id=\"R70cDGNT1SqOk2pn\" ChangeKey=\"1DjfJ3dT\"/>" 0174 "</m:ToFolderId>" 0175 "<m:ItemIds>" 0176 "<t:ItemId Id=\"Xnn2DwwaXQUhbn7U\" ChangeKey=\"rqs77HkG\"/>" 0177 "<t:ItemId Id=\"ntTNOncESwiyAXog\" ChangeKey=\"EDHu5rwK\"/>" 0178 "</m:ItemIds>" 0179 "</m:MoveItem></soap:Body></soap:Envelope>\n"; 0180 static const QByteArray response = 0181 "<?xml version=\"1.0\" encoding=\"utf-8\"?>" 0182 "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" 0183 "<s:Header>" 0184 "<h:ServerVersionInfo MajorVersion=\"14\" MinorVersion=\"3\" " 0185 "MajorBuildNumber=\"248\" MinorBuildNumber=\"2\" " 0186 "Version=\"Exchange2007_SP1\" " 0187 "xmlns:h=\"http://schemas.microsoft.com/exchange/services/2006/types\" " 0188 "xmlns=\"http://schemas.microsoft.com/exchange/services/2006/types\" " 0189 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " 0190 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"/>" 0191 "</s:Header>" 0192 "<s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " 0193 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" 0194 "<m:MoveItemResponse " 0195 "xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\" " 0196 "xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">" 0197 "<m:ResponseMessages>" 0198 "<m:MoveItemResponseMessage ResponseClass=\"Success\">" 0199 "<m:ResponseCode>NoError</m:ResponseCode>" 0200 "<m:Items>" 0201 "<t:Message><t:ItemId Id=\"Xnn2DwwaXQUhbn7U\" ChangeKey=\"JoFvRwDP\"/>" 0202 "</t:Message>" 0203 "</m:Items>" 0204 "</m:MoveItemResponseMessage>" 0205 "<m:MoveItemResponseMessage ResponseClass=\"Error\">" 0206 "<m:MessageText>The specified object was not found in the store.</m:MessageText>" 0207 "<m:ResponseCode>ErrorItemNotFound</m:ResponseCode>" 0208 "<m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>" 0209 "<m:Items/>" 0210 "</m:MoveItemResponseMessage>" 0211 "</m:ResponseMessages>" 0212 "</m:MoveItemResponse>" 0213 "</s:Body>" 0214 "</s:Envelope>"; 0215 0216 FakeTransferJob::addVerifier(this, [this](FakeTransferJob *job, const QByteArray &req) { 0217 verifier(job, req, request, response); 0218 }); 0219 QScopedPointer<EwsMoveItemRequest> req(new EwsMoveItemRequest(mClient, this)); 0220 static const EwsId::List ids = {EwsId(QStringLiteral("Xnn2DwwaXQUhbn7U"), QStringLiteral("rqs77HkG")), 0221 EwsId(QStringLiteral("ntTNOncESwiyAXog"), QStringLiteral("EDHu5rwK"))}; 0222 req->setItemIds(ids); 0223 req->setDestinationFolderId(EwsId(QStringLiteral("R70cDGNT1SqOk2pn"), QStringLiteral("1DjfJ3dT"))); 0224 req->exec(); 0225 0226 QCOMPARE(req->error(), 0); 0227 QCOMPARE(req->responses().size(), 2); 0228 static const QList<EwsResponseClass> respClasses = {EwsResponseSuccess, EwsResponseError}; 0229 static const EwsId::List newIds = {EwsId(QStringLiteral("Xnn2DwwaXQUhbn7U"), QStringLiteral("JoFvRwDP")), 0230 EwsId(QStringLiteral("ntTNOncESwiyAXog"), QStringLiteral("EDHu5rwK"))}; 0231 EwsId::List::const_iterator newIdsIt = newIds.begin(); 0232 QList<EwsResponseClass>::const_iterator respClassesIt = respClasses.begin(); 0233 unsigned i = 0; 0234 const auto reqResponses{req->responses()}; 0235 for (const EwsMoveItemRequest::Response &resp : reqResponses) { 0236 qDebug() << "Verifying response" << i++; 0237 QCOMPARE(resp.responseClass(), *respClassesIt); 0238 if (resp.isSuccess()) { 0239 QCOMPARE(resp.itemId(), *newIdsIt); 0240 } else { 0241 QCOMPARE(resp.itemId(), EwsId()); 0242 } 0243 ++newIdsIt; 0244 ++respClassesIt; 0245 } 0246 } 0247 0248 void UtEwsMoveItemRequest::twoItemsSecondFailed() 0249 { 0250 static const QByteArray request = 0251 "<?xml version=\"1.0\"?>" 0252 "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " 0253 "xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\" " 0254 "xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">" 0255 "<soap:Header><t:RequestServerVersion Version=\"Exchange2007_SP1\"/>" 0256 "</soap:Header><soap:Body><m:MoveItem><m:ToFolderId>" 0257 "<t:FolderId Id=\"R70cDGNT1SqOk2pn\" ChangeKey=\"1DjfJ3dT\"/>" 0258 "</m:ToFolderId>" 0259 "<m:ItemIds>" 0260 "<t:ItemId Id=\"Xnn2DwwaXQUhbn7U\" ChangeKey=\"rqs77HkG\"/>" 0261 "<t:ItemId Id=\"ntTNOncESwiyAXog\" ChangeKey=\"EDHu5rwK\"/>" 0262 "</m:ItemIds>" 0263 "</m:MoveItem></soap:Body></soap:Envelope>\n"; 0264 static const QByteArray response = 0265 "<?xml version=\"1.0\" encoding=\"utf-8\"?>" 0266 "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" 0267 "<s:Header>" 0268 "<h:ServerVersionInfo MajorVersion=\"14\" MinorVersion=\"3\" " 0269 "MajorBuildNumber=\"248\" MinorBuildNumber=\"2\" " 0270 "Version=\"Exchange2007_SP1\" " 0271 "xmlns:h=\"http://schemas.microsoft.com/exchange/services/2006/types\" " 0272 "xmlns=\"http://schemas.microsoft.com/exchange/services/2006/types\" " 0273 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " 0274 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"/>" 0275 "</s:Header>" 0276 "<s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " 0277 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" 0278 "<m:MoveItemResponse " 0279 "xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\" " 0280 "xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">" 0281 "<m:ResponseMessages>" 0282 "<m:MoveItemResponseMessage ResponseClass=\"Error\">" 0283 "<m:MessageText>The specified object was not found in the store.</m:MessageText>" 0284 "<m:ResponseCode>ErrorItemNotFound</m:ResponseCode>" 0285 "<m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>" 0286 "<m:Items/>" 0287 "</m:MoveItemResponseMessage>" 0288 "<m:MoveItemResponseMessage ResponseClass=\"Success\">" 0289 "<m:ResponseCode>NoError</m:ResponseCode>" 0290 "<m:Items>" 0291 "<t:Message><t:ItemId Id=\"ntTNOncESwiyAXog\" ChangeKey=\"4qbAwd3y\"/>" 0292 "</t:Message>" 0293 "</m:Items>" 0294 "</m:MoveItemResponseMessage>" 0295 "</m:ResponseMessages>" 0296 "</m:MoveItemResponse>" 0297 "</s:Body>" 0298 "</s:Envelope>"; 0299 0300 FakeTransferJob::addVerifier(this, [this](FakeTransferJob *job, const QByteArray &req) { 0301 verifier(job, req, request, response); 0302 }); 0303 QScopedPointer<EwsMoveItemRequest> req(new EwsMoveItemRequest(mClient, this)); 0304 static const EwsId::List ids = {EwsId(QStringLiteral("Xnn2DwwaXQUhbn7U"), QStringLiteral("rqs77HkG")), 0305 EwsId(QStringLiteral("ntTNOncESwiyAXog"), QStringLiteral("EDHu5rwK"))}; 0306 req->setItemIds(ids); 0307 req->setDestinationFolderId(EwsId(QStringLiteral("R70cDGNT1SqOk2pn"), QStringLiteral("1DjfJ3dT"))); 0308 req->exec(); 0309 0310 QCOMPARE(req->error(), 0); 0311 QCOMPARE(req->responses().size(), 2); 0312 static const QList<EwsResponseClass> respClasses = {EwsResponseError, EwsResponseSuccess}; 0313 static const EwsId::List newIds = {EwsId(QStringLiteral("Xnn2DwwaXQUhbn7U"), QStringLiteral("JoFvRwDP")), 0314 EwsId(QStringLiteral("ntTNOncESwiyAXog"), QStringLiteral("4qbAwd3y"))}; 0315 EwsId::List::const_iterator newIdsIt = newIds.begin(); 0316 QList<EwsResponseClass>::const_iterator respClassesIt = respClasses.begin(); 0317 unsigned i = 0; 0318 const auto reqResponses{req->responses()}; 0319 for (const EwsMoveItemRequest::Response &resp : reqResponses) { 0320 qDebug() << "Verifying response" << i++; 0321 QCOMPARE(resp.responseClass(), *respClassesIt); 0322 if (resp.isSuccess()) { 0323 QCOMPARE(resp.itemId(), *newIdsIt); 0324 } else { 0325 QCOMPARE(resp.itemId(), EwsId()); 0326 } 0327 newIdsIt++; 0328 respClassesIt++; 0329 } 0330 } 0331 0332 void UtEwsMoveItemRequest::verifier(FakeTransferJob *job, const QByteArray &req, const QByteArray &expReq, const QByteArray &response) 0333 { 0334 bool fail = true; 0335 auto f = finally([&fail, &job] { 0336 if (fail) { 0337 job->postResponse(""); 0338 } 0339 }); 0340 QCOMPARE(req, expReq); 0341 fail = false; 0342 job->postResponse(response); 0343 } 0344 0345 QTEST_MAIN(UtEwsMoveItemRequest) 0346 0347 #include "ewsmoveitemrequest_ut.moc"