File indexing completed on 2024-05-12 05:15:04

0001 /*
0002     Copyright (c) 2017 Sandro Knauß <sknauss@kde.org>
0003 
0004     This program is free software; you can redistribute it and/or modify
0005     it under the terms of the GNU General Public License as published by
0006     the Free Software Foundation; either version 2 of the License, or
0007     (at your option) any later version.
0008 
0009     This program is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0012     GNU General Public License for more details.
0013 
0014     You should have received a copy of the GNU General Public License
0015     along with this program; if not, write to the Free Software
0016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0017 */
0018 
0019 #include "davitemfetchjobtest.h"
0020 #include "fakeserver.h"
0021 
0022 #include <KDAV2/DavItemFetchJob>
0023 
0024 #include <QTest>
0025 
0026 void DavItemFetchJobTest::runSuccessfullTest()
0027 {
0028     FakeServer fakeServer;
0029     QUrl url(QStringLiteral("http://localhost/item"));
0030     url.setPort(fakeServer.port());
0031     KDAV2::DavUrl davUrl(url, KDAV2::CardDav);
0032 
0033     KDAV2::DavItem item(davUrl, QString(), QByteArray(), QString());
0034 
0035     auto job = new KDAV2::DavItemFetchJob(item);
0036 
0037     fakeServer.addScenarioFromFile(QLatin1String(AUTOTEST_DATA_DIR)+QStringLiteral("/dataitemfetchjob.txt"));
0038     fakeServer.startAndWait();
0039     job->exec();
0040     fakeServer.quit();
0041 
0042     QVERIFY(fakeServer.isAllScenarioDone());
0043     QCOMPARE(job->error(), 0);
0044 
0045     QCOMPARE(item.data(), QByteArray());
0046     QCOMPARE(item.etag(), QString());
0047     QCOMPARE(item.contentType(), QString());
0048 
0049     item = job->item();
0050     QByteArray data("BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Kolab//iRony DAV Server 0.3.1//Sabre//Sabre VObject 2.1.7//EN\r\nUID:12345678-1234-1234-1234-123456789abc\r\nFN:John2 Doe\r\nN:Doe;John2;;;\r\nEMAIL;TYPE=INTERNET;TYPE=HOME:john2.doe@example.com\r\nREV;VALUE=DATE-TIME:20170104T182647Z\r\nEND:VCARD\r\n");
0051     QCOMPARE(item.data(), data);
0052     QCOMPARE(item.etag(), QStringLiteral("7a33141f192d904d-47"));
0053     QCOMPARE(item.contentType(), QStringLiteral("text/x-vcard"));
0054 
0055 }
0056 
0057 QTEST_GUILESS_MAIN(DavItemFetchJobTest)