File indexing completed on 2024-11-17 04:44:00

0001 /*
0002     Copyright (c) 2017 Sandro Knauß <sknauss@kde.org>
0003     Copyright (c) 2018 Rémi Nicole <minijackson@riseup.net>
0004 
0005     This program is free software; you can redistribute it and/or modify
0006     it under the terms of the GNU General Public License as published by
0007     the Free Software Foundation; either version 2 of the License, or
0008     (at your option) any later version.
0009 
0010     This program is distributed in the hope that it will be useful,
0011     but WITHOUT ANY WARRANTY; without even the implied warranty of
0012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0013     GNU General Public License for more details.
0014 
0015     You should have received a copy of the GNU General Public License
0016     along with this program; if not, write to the Free Software
0017     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #include "davcollectioncreatejobtest.h"
0021 
0022 #include <KDAV2/DavCollectionCreateJob>
0023 #include <KDAV2/DavCollectionDeleteJob>
0024 
0025 #include <QColor>
0026 #include <QTest>
0027 
0028 void DavCollectionCreateJobTest::initTestCase()
0029 {
0030     QString addressbookUuid = QUuid::createUuid().toString();
0031     addressbookUrl = "https://apps.kolabnow.com/addressbooks/test1%40kolab.org/" + addressbookUuid;
0032     addressbookUrl.setUserName("test1@kolab.org");
0033     addressbookUrl.setPassword("Welcome2KolabSystems");
0034 
0035     QString calendarUuid = QUuid::createUuid().toString();
0036     calendarUrl = "https://apps.kolabnow.com/calendars/test1%40kolab.org/" + calendarUuid;
0037     calendarUrl.setUserName("test1@kolab.org");
0038     calendarUrl.setPassword("Welcome2KolabSystems");
0039 }
0040 
0041 void DavCollectionCreateJobTest::runNormalCollectionTest()
0042 {
0043 }
0044 
0045 void DavCollectionCreateJobTest::runAddressbookTest()
0046 {
0047     KDAV2::DavUrl testCollectionUrl(addressbookUrl, KDAV2::CardDav);
0048     KDAV2::DavCollection testCollection;
0049 
0050     testCollection.setDisplayName("Test AddressBook Collection");
0051     testCollection.setUrl(testCollectionUrl);
0052 
0053     auto collectionCreateJob = new KDAV2::DavCollectionCreateJob(testCollection);
0054     collectionCreateJob->exec();
0055 
0056     QCOMPARE(collectionCreateJob->error(), 0);
0057 
0058     KDAV2::DavCollection resultCollection = collectionCreateJob->collection();
0059 
0060     QVERIFY(!resultCollection.CTag().isEmpty());
0061     QCOMPARE(resultCollection.displayName(), QLatin1String("Test AddressBook Collection"));
0062 
0063     delete collectionCreateJob;
0064 }
0065 
0066 void DavCollectionCreateJobTest::runCalendarTest()
0067 {
0068     KDAV2::DavUrl testCollectionUrl(calendarUrl, KDAV2::CalDav);
0069     KDAV2::DavCollection testCollection;
0070 
0071     testCollection.setDisplayName("Test Calendar Collection");
0072     testCollection.setUrl(testCollectionUrl);
0073     testCollection.setContentTypes(KDAV2::DavCollection::Events | KDAV2::DavCollection::Todos);
0074     testCollection.setColor("#123456");
0075 
0076     auto collectionCreateJob = new KDAV2::DavCollectionCreateJob(testCollection);
0077     collectionCreateJob->exec();
0078 
0079     QCOMPARE(collectionCreateJob->error(), 0);
0080 
0081     KDAV2::DavCollection resultCollection = collectionCreateJob->collection();
0082 
0083     QVERIFY(!resultCollection.CTag().isEmpty());
0084     QCOMPARE(resultCollection.displayName(), QLatin1String("Test Calendar Collection"));
0085     QCOMPARE(resultCollection.color().name(), QLatin1String("#123456"));
0086     QVERIFY(resultCollection.contentTypes().testFlag(KDAV2::DavCollection::Events));
0087     QVERIFY(resultCollection.contentTypes().testFlag(KDAV2::DavCollection::Todos));
0088 
0089     delete collectionCreateJob;
0090 }
0091 
0092 void DavCollectionCreateJobTest::cleanupTestCase()
0093 {
0094     {
0095         KDAV2::DavUrl testCollectionUrl(addressbookUrl, KDAV2::CardDav);
0096 
0097         auto collectionDeleteJob = new KDAV2::DavCollectionDeleteJob(testCollectionUrl);
0098         collectionDeleteJob->exec();
0099         QCOMPARE(collectionDeleteJob->error(), 0);
0100 
0101         delete collectionDeleteJob;
0102     }
0103 
0104     {
0105         KDAV2::DavUrl testCollectionUrl(calendarUrl, KDAV2::CalDav);
0106 
0107         auto collectionDeleteJob = new KDAV2::DavCollectionDeleteJob(testCollectionUrl);
0108         collectionDeleteJob->exec();
0109         QCOMPARE(collectionDeleteJob->error(), 0);
0110 
0111         delete collectionDeleteJob;
0112     }
0113 }
0114 
0115 QTEST_GUILESS_MAIN(DavCollectionCreateJobTest)