diff options
author | Rémi Nicole <nicole@kolabsystems.com> | 2018-03-27 18:26:11 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-03-27 18:26:15 +0200 |
commit | 761328989492db9bd603c2d7f1134d20e485d2f6 (patch) | |
tree | 0e3b4517dd2000fb1cc2738bbb22a3e54dfffb6f /examples/caldavresource/tests/caldavtest.cpp | |
parent | 80afd7070f2d8e57cab2fe55fef611623fdb75f0 (diff) | |
download | sink-761328989492db9bd603c2d7f1134d20e485d2f6.tar.gz sink-761328989492db9bd603c2d7f1134d20e485d2f6.zip |
Add CalDAV support
Summary:
Notes:
- Add a `webdavcommon` folder for WebDAV generic resource code
- Move `davresource` to `carddaveresource` and make it use the WebDAV code
- For now it tests the CalDAV resource directly on KolabNow (to be changed)
- Only synchronization, not adding / changing / removing WebDAV collections or items (to be implemented)
- Only events are currently supported (todo, freebusy, etc. are to be implemented but should be straightforward)
Fixes T8224
Reviewers: cmollekopf
Tags: #sink
Maniphest Tasks: T8224
Differential Revision: https://phabricator.kde.org/D11741
Diffstat (limited to 'examples/caldavresource/tests/caldavtest.cpp')
-rw-r--r-- | examples/caldavresource/tests/caldavtest.cpp | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/examples/caldavresource/tests/caldavtest.cpp b/examples/caldavresource/tests/caldavtest.cpp new file mode 100644 index 0000000..f999590 --- /dev/null +++ b/examples/caldavresource/tests/caldavtest.cpp | |||
@@ -0,0 +1,93 @@ | |||
1 | #include <QtTest> | ||
2 | |||
3 | #include "../caldavresource.h" | ||
4 | |||
5 | #include "common/resourcecontrol.h" | ||
6 | #include "common/secretstore.h" | ||
7 | #include "common/store.h" | ||
8 | #include "common/test.h" | ||
9 | #include "tests/testutils.h" | ||
10 | |||
11 | using Sink::ApplicationDomain::Calendar; | ||
12 | using Sink::ApplicationDomain::DummyResource; | ||
13 | using Sink::ApplicationDomain::Event; | ||
14 | using Sink::ApplicationDomain::SinkResource; | ||
15 | |||
16 | class CalDavTest : public QObject | ||
17 | { | ||
18 | Q_OBJECT | ||
19 | |||
20 | SinkResource createResource() | ||
21 | { | ||
22 | auto resource = Sink::ApplicationDomain::CalDavResource::create("account1"); | ||
23 | resource.setProperty("server", "http://localhost/dav/calendars/users/doe"); | ||
24 | resource.setProperty("username", "doe"); | ||
25 | Sink::SecretStore::instance().insert(resource.identifier(), "doe"); | ||
26 | resource.setProperty("testmode", true); | ||
27 | return resource; | ||
28 | } | ||
29 | |||
30 | |||
31 | QByteArray mResourceInstanceIdentifier; | ||
32 | QByteArray mStorageResource; | ||
33 | |||
34 | private slots: | ||
35 | |||
36 | void initTestCase() | ||
37 | { | ||
38 | Sink::Test::initTest(); | ||
39 | auto resource = createResource(); | ||
40 | QVERIFY(!resource.identifier().isEmpty()); | ||
41 | VERIFYEXEC(Sink::Store::create(resource)); | ||
42 | mResourceInstanceIdentifier = resource.identifier(); | ||
43 | |||
44 | auto dummyResource = DummyResource::create("account1"); | ||
45 | VERIFYEXEC(Sink::Store::create(dummyResource)); | ||
46 | mStorageResource = dummyResource.identifier(); | ||
47 | QVERIFY(!mStorageResource.isEmpty()); | ||
48 | } | ||
49 | |||
50 | void cleanup() | ||
51 | { | ||
52 | VERIFYEXEC(Sink::Store::removeDataFromDisk(mResourceInstanceIdentifier)); | ||
53 | VERIFYEXEC(Sink::Store::removeDataFromDisk(mStorageResource)); | ||
54 | } | ||
55 | |||
56 | void init() | ||
57 | { | ||
58 | VERIFYEXEC(Sink::ResourceControl::start(mResourceInstanceIdentifier)); | ||
59 | } | ||
60 | |||
61 | void testSyncCal() | ||
62 | { | ||
63 | VERIFYEXEC(Sink::Store::synchronize(Sink::Query().resourceFilter(mResourceInstanceIdentifier))); | ||
64 | // Check in the logs that it doesn't synchronize events again because same CTag | ||
65 | VERIFYEXEC(Sink::Store::synchronize(Sink::Query().resourceFilter(mResourceInstanceIdentifier))); | ||
66 | } | ||
67 | |||
68 | void testSyncCalEmpty() | ||
69 | { | ||
70 | VERIFYEXEC(Sink::Store::synchronize(Sink::Query().resourceFilter(mResourceInstanceIdentifier))); | ||
71 | |||
72 | auto eventJob = | ||
73 | Sink::Store::fetchAll<Event>(Sink::Query().request<Event::Uid>()).then([](const QList<Event::Ptr> &events) { | ||
74 | QCOMPARE(events.size(), 14); | ||
75 | }); | ||
76 | VERIFYEXEC(eventJob); | ||
77 | |||
78 | auto calendarJob = | ||
79 | Sink::Store::fetchAll<Calendar>(Sink::Query().request<Calendar::Name>()).then([](const QList<Calendar::Ptr> &calendars) { | ||
80 | QCOMPARE(calendars.size(), 2); | ||
81 | for (const auto &calendar : calendars) { | ||
82 | QVERIFY(calendar->getName() == "Calendar" || calendar->getName() == "Tasks"); | ||
83 | } | ||
84 | }); | ||
85 | VERIFYEXEC(calendarJob); | ||
86 | |||
87 | SinkLog() << "Finished"; | ||
88 | } | ||
89 | }; | ||
90 | |||
91 | QTEST_MAIN(CalDavTest) | ||
92 | |||
93 | #include "caldavtest.moc" | ||