summaryrefslogtreecommitdiffstats
path: root/tests/maildirresourcetest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/maildirresourcetest.cpp')
-rw-r--r--tests/maildirresourcetest.cpp157
1 files changed, 96 insertions, 61 deletions
diff --git a/tests/maildirresourcetest.cpp b/tests/maildirresourcetest.cpp
index 6ad6ca6..28a1d44 100644
--- a/tests/maildirresourcetest.cpp
+++ b/tests/maildirresourcetest.cpp
@@ -3,7 +3,8 @@
3#include <QString> 3#include <QString>
4 4
5#include "maildirresource/maildirresource.h" 5#include "maildirresource/maildirresource.h"
6#include "clientapi.h" 6#include "store.h"
7#include "resourcecontrol.h"
7#include "commands.h" 8#include "commands.h"
8#include "entitybuffer.h" 9#include "entitybuffer.h"
9#include "resourceconfig.h" 10#include "resourceconfig.h"
@@ -68,7 +69,7 @@ private Q_SLOTS:
68 69
69 void cleanup() 70 void cleanup()
70 { 71 {
71 Sink::Store::shutdown(QByteArray("org.kde.maildir.instance1")).exec().waitForFinished(); 72 Sink::ResourceControl::shutdown(QByteArray("org.kde.maildir.instance1")).exec().waitForFinished();
72 MaildirResource::removeFromDisk("org.kde.maildir.instance1"); 73 MaildirResource::removeFromDisk("org.kde.maildir.instance1");
73 QDir dir(targetPath); 74 QDir dir(targetPath);
74 dir.removeRecursively(); 75 dir.removeRecursively();
@@ -80,7 +81,7 @@ private Q_SLOTS:
80 qDebug() << "-----------------------------------------"; 81 qDebug() << "-----------------------------------------";
81 qDebug(); 82 qDebug();
82 copyRecursively(TESTDATAPATH "/maildir1", targetPath); 83 copyRecursively(TESTDATAPATH "/maildir1", targetPath);
83 Sink::Store::start(QByteArray("org.kde.maildir.instance1")).exec().waitForFinished(); 84 Sink::ResourceControl::start(QByteArray("org.kde.maildir.instance1")).exec().waitForFinished();
84 } 85 }
85 86
86 void testListFolders() 87 void testListFolders()
@@ -90,7 +91,7 @@ private Q_SLOTS:
90 91
91 //Ensure all local data is processed 92 //Ensure all local data is processed
92 Sink::Store::synchronize(query).exec().waitForFinished(); 93 Sink::Store::synchronize(query).exec().waitForFinished();
93 Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); 94 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
94 95
95 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query); 96 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query);
96 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 97 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
@@ -105,7 +106,7 @@ private Q_SLOTS:
105 106
106 //Ensure all local data is processed 107 //Ensure all local data is processed
107 Sink::Store::synchronize(query).exec().waitForFinished(); 108 Sink::Store::synchronize(query).exec().waitForFinished();
108 Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); 109 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
109 110
110 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query); 111 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query);
111 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 112 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
@@ -123,7 +124,7 @@ private Q_SLOTS:
123 //Ensure all local data is processed 124 //Ensure all local data is processed
124 auto query = Query::ResourceFilter("org.kde.maildir.instance1"); 125 auto query = Query::ResourceFilter("org.kde.maildir.instance1");
125 Store::synchronize(query).exec().waitForFinished(); 126 Store::synchronize(query).exec().waitForFinished();
126 Store::flushMessageQueue(query.resources).exec().waitForFinished(); 127 ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
127 auto result = Store::fetchOne<Folder>( 128 auto result = Store::fetchOne<Folder>(
128 Query::ResourceFilter("org.kde.maildir.instance1") + Query::RequestedProperties(QByteArrayList() << "name") 129 Query::ResourceFilter("org.kde.maildir.instance1") + Query::RequestedProperties(QByteArrayList() << "name")
129 ) 130 )
@@ -149,7 +150,7 @@ private Q_SLOTS:
149 150
150 //Ensure all local data is processed 151 //Ensure all local data is processed
151 Sink::Store::synchronize(query).exec().waitForFinished(); 152 Sink::Store::synchronize(query).exec().waitForFinished();
152 Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); 153 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
153 154
154 auto mailModel = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); 155 auto mailModel = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query);
155 QTRY_VERIFY(mailModel->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 156 QTRY_VERIFY(mailModel->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
@@ -158,6 +159,9 @@ private Q_SLOTS:
158 QVERIFY(!mail->getProperty("subject").toString().isEmpty()); 159 QVERIFY(!mail->getProperty("subject").toString().isEmpty());
159 QVERIFY(!mail->getProperty("mimeMessage").toString().isEmpty()); 160 QVERIFY(!mail->getProperty("mimeMessage").toString().isEmpty());
160 QVERIFY(mail->getProperty("date").toDateTime().isValid()); 161 QVERIFY(mail->getProperty("date").toDateTime().isValid());
162
163 QFileInfo info(mail->getProperty("mimeMessage").toString());
164 QVERIFY(info.exists());
161 } 165 }
162 166
163 167
@@ -169,7 +173,7 @@ private Q_SLOTS:
169 173
170 //Ensure all local data is processed 174 //Ensure all local data is processed
171 Sink::Store::synchronize(query).exec().waitForFinished(); 175 Sink::Store::synchronize(query).exec().waitForFinished();
172 Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); 176 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
173 177
174 auto targetPath = tempDir.path() + "/maildir1/"; 178 auto targetPath = tempDir.path() + "/maildir1/";
175 QDir dir(targetPath); 179 QDir dir(targetPath);
@@ -177,7 +181,7 @@ private Q_SLOTS:
177 181
178 //Ensure all local data is processed 182 //Ensure all local data is processed
179 Sink::Store::synchronize(query).exec().waitForFinished(); 183 Sink::Store::synchronize(query).exec().waitForFinished();
180 Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); 184 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
181 185
182 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query); 186 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query);
183 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 187 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
@@ -193,11 +197,11 @@ private Q_SLOTS:
193 197
194 //Ensure all local data is processed 198 //Ensure all local data is processed
195 Sink::Store::synchronize(query).exec().waitForFinished(); 199 Sink::Store::synchronize(query).exec().waitForFinished();
196 Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); 200 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
197 201
198 //Ensure all local data is processed 202 //Ensure all local data is processed
199 Sink::Store::synchronize(query).exec().waitForFinished(); 203 Sink::Store::synchronize(query).exec().waitForFinished();
200 Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); 204 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
201 205
202 auto mailModel = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); 206 auto mailModel = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query);
203 QTRY_VERIFY(mailModel->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 207 QTRY_VERIFY(mailModel->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
@@ -212,7 +216,7 @@ private Q_SLOTS:
212 216
213 //Ensure all local data is processed 217 //Ensure all local data is processed
214 Sink::Store::synchronize(query).exec().waitForFinished(); 218 Sink::Store::synchronize(query).exec().waitForFinished();
215 Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); 219 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
216 220
217 auto targetPath = tempDir.path() + "/maildir1/cur/1365777830.R28.localhost.localdomain:2,S"; 221 auto targetPath = tempDir.path() + "/maildir1/cur/1365777830.R28.localhost.localdomain:2,S";
218 QFile file(targetPath); 222 QFile file(targetPath);
@@ -220,7 +224,7 @@ private Q_SLOTS:
220 224
221 //Ensure all local data is processed 225 //Ensure all local data is processed
222 Sink::Store::synchronize(query).exec().waitForFinished(); 226 Sink::Store::synchronize(query).exec().waitForFinished();
223 Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); 227 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
224 228
225 auto mailModel = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); 229 auto mailModel = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query);
226 QTRY_VERIFY(mailModel->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 230 QTRY_VERIFY(mailModel->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
@@ -233,7 +237,7 @@ private Q_SLOTS:
233 query.resources << "org.kde.maildir.instance1"; 237 query.resources << "org.kde.maildir.instance1";
234 238
235 //Ensure all local data is processed 239 //Ensure all local data is processed
236 Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); 240 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
237 241
238 Sink::ApplicationDomain::Folder folder("org.kde.maildir.instance1"); 242 Sink::ApplicationDomain::Folder folder("org.kde.maildir.instance1");
239 folder.setProperty("name", "testCreateFolder"); 243 folder.setProperty("name", "testCreateFolder");
@@ -241,7 +245,7 @@ private Q_SLOTS:
241 Sink::Store::create(folder).exec().waitForFinished(); 245 Sink::Store::create(folder).exec().waitForFinished();
242 246
243 //Ensure all local data is processed 247 //Ensure all local data is processed
244 Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); 248 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
245 249
246 auto targetPath = tempDir.path() + "/maildir1/testCreateFolder"; 250 auto targetPath = tempDir.path() + "/maildir1/testCreateFolder";
247 QFileInfo file(targetPath); 251 QFileInfo file(targetPath);
@@ -259,7 +263,7 @@ private Q_SLOTS:
259 Sink::ApplicationDomain::Folder folder("org.kde.maildir.instance1"); 263 Sink::ApplicationDomain::Folder folder("org.kde.maildir.instance1");
260 folder.setProperty("name", "testCreateFolder"); 264 folder.setProperty("name", "testCreateFolder");
261 Sink::Store::create(folder).exec().waitForFinished(); 265 Sink::Store::create(folder).exec().waitForFinished();
262 Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); 266 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
263 QTRY_VERIFY(QFileInfo(targetPath).exists()); 267 QTRY_VERIFY(QFileInfo(targetPath).exists());
264 268
265 Sink::Query folderQuery; 269 Sink::Query folderQuery;
@@ -271,7 +275,7 @@ private Q_SLOTS:
271 auto createdFolder = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Folder::Ptr>(); 275 auto createdFolder = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Folder::Ptr>();
272 276
273 Sink::Store::remove(*createdFolder).exec().waitForFinished(); 277 Sink::Store::remove(*createdFolder).exec().waitForFinished();
274 Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); 278 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
275 QTRY_VERIFY(!QFileInfo(targetPath).exists()); 279 QTRY_VERIFY(!QFileInfo(targetPath).exists());
276 } 280 }
277 281
@@ -281,15 +285,16 @@ private Q_SLOTS:
281 query.resources << "org.kde.maildir.instance1"; 285 query.resources << "org.kde.maildir.instance1";
282 286
283 //Ensure all local data is processed 287 //Ensure all local data is processed
284 Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); 288 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
285 289
286 Sink::ApplicationDomain::Mail mail("org.kde.maildir.instance1"); 290 Sink::ApplicationDomain::Mail mail("org.kde.maildir.instance1");
287 mail.setProperty("name", "testCreateMail"); 291 mail.setProperty("name", "testCreateMail");
292 //FIXME instead of properties, ensure the mimeMessage property is used and the file is moved as expected
288 293
289 Sink::Store::create(mail).exec().waitForFinished(); 294 Sink::Store::create(mail).exec().waitForFinished();
290 295
291 //Ensure all local data is processed 296 //Ensure all local data is processed
292 Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); 297 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
293 298
294 auto targetPath = tempDir.path() + "/maildir1/new"; 299 auto targetPath = tempDir.path() + "/maildir1/new";
295 QDir dir(targetPath); 300 QDir dir(targetPath);
@@ -304,29 +309,28 @@ private Q_SLOTS:
304 309
305 auto query = Query::ResourceFilter("org.kde.maildir.instance1"); 310 auto query = Query::ResourceFilter("org.kde.maildir.instance1");
306 Store::synchronize(query).exec().waitForFinished(); 311 Store::synchronize(query).exec().waitForFinished();
307 Store::flushMessageQueue(query.resources).exec().waitForFinished(); 312 ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
308 313
309 auto result = Store::fetchOne<Folder>( 314 auto result = Store::fetchOne<Folder>(
310 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name") 315 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name")
316 )
317 .then<void, KAsync::Job<void>, Folder>([query](const Folder &folder) {
318 return Store::fetchAll<Mail>(
319 Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject")
311 ) 320 )
312 .then<void, KAsync::Job<void>, Folder>([query](const Folder &folder) { 321 .then<void, KAsync::Job<void>, QList<Mail::Ptr> >([query](const QList<Mail::Ptr> &mails) {
313 return Store::fetchAll<Mail>( 322 //Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE
314 Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject") 323 if (mails.size() != 1) {
315 ) 324 return KAsync::error<void>(1, "Wrong number of mails.");
316 .then<void, KAsync::Job<void>, QList<Mail::Ptr> >([query](const QList<Mail::Ptr> &mails) { 325 }
317 //Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE 326 auto mail = mails.first();
318 if (mails.size() != 1) { 327
319 return KAsync::error<void>(1, "Wrong number of mails."); 328 return Store::remove(*mail)
320 } 329 .then(ResourceControl::flushReplayQueue(query.resources)) //The change needs to be replayed already
321 auto mail = mails.first(); 330 .then(ResourceControl::inspect<Mail>(ResourceControl::Inspection::ExistenceInspection(*mail, false)));
322 331 });
323 return Store::remove(*mail) 332 })
324 .then(Store::flushReplayQueue(query.resources)) //The change needs to be replayed already 333 .exec();
325 .then(Resources::inspect<Mail>(Resources::Inspection::ExistenceInspection(*mail, false)));
326 })
327 .then<void>([](){});
328 })
329 .exec();
330 result.waitForFinished(); 334 result.waitForFinished();
331 QVERIFY(!result.errorCode()); 335 QVERIFY(!result.errorCode());
332 } 336 }
@@ -338,33 +342,64 @@ private Q_SLOTS:
338 342
339 auto query = Query::ResourceFilter("org.kde.maildir.instance1"); 343 auto query = Query::ResourceFilter("org.kde.maildir.instance1");
340 Store::synchronize(query).exec().waitForFinished(); 344 Store::synchronize(query).exec().waitForFinished();
341 Store::flushMessageQueue(query.resources).exec().waitForFinished(); 345 ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
346
347 Folder f;
342 348
343 auto result = Store::fetchOne<Folder>( 349 auto result = Store::fetchOne<Folder>(
344 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name") 350 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name")
351 )
352 .then<void, KAsync::Job<void>, Folder>([query, &f](const Folder &folder) {
353 f = folder;
354 return Store::fetchAll<Mail>(
355 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject")
345 ) 356 )
346 .then<void, KAsync::Job<void>, Folder>([query](const Folder &folder) { 357 .then<void, KAsync::Job<void>, QList<Mail::Ptr> >([query](const QList<Mail::Ptr> &mails) {
347 Trace() << "Found a folder" << folder.identifier(); 358 //Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE
348 return Store::fetchAll<Mail>( 359 if (mails.size() != 1) {
349 Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject") 360 return KAsync::error<void>(1, "Wrong number of mails.");
350 ) 361 }
351 .then<void, KAsync::Job<void>, QList<Mail::Ptr> >([query](const QList<Mail::Ptr> &mails) { 362 auto mail = mails.first();
352 //Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE 363 mail->setProperty("unread", true);
353 if (mails.size() != 1) { 364 return Store::modify(*mail)
354 return KAsync::error<void>(1, "Wrong number of mails."); 365 .then<void>(ResourceControl::flushReplayQueue(query.resources)) //The change needs to be replayed already
355 } 366 .then(ResourceControl::inspect<Mail>(ResourceControl::Inspection::PropertyInspection(*mail, "unread", true)))
356 auto mail = mails.first(); 367 .then(ResourceControl::inspect<Mail>(ResourceControl::Inspection::PropertyInspection(*mail, "subject", mail->getProperty("subject"))));
357 mail->setProperty("unread", true); 368 });
358 auto inspectionCommand = Resources::Inspection::PropertyInspection(*mail, "unread", true); 369 })
359 return Store::modify(*mail) 370 .exec();
360 .then<void>(Store::flushReplayQueue(query.resources)) //The change needs to be replayed already
361 .then(Resources::inspect<Mail>(inspectionCommand));
362 })
363 .then<void>([](){});
364 })
365 .exec();
366 result.waitForFinished(); 371 result.waitForFinished();
367 QVERIFY(!result.errorCode()); 372 QVERIFY(!result.errorCode());
373
374 //Verify that we can still query for all relevant information
375 auto result2 = Store::fetchAll<Mail>(
376 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("folder", f) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject" << "mimeMessage" << "unread")
377 )
378 .then<void, KAsync::Job<void>, QList<Mail::Ptr> >([](const QList<Mail::Ptr> &mails) {
379 //Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE
380 if (mails.size() != 1) {
381 qWarning() << "Wrong number of mails";
382 return KAsync::error<void>(1, "Wrong number of mails.");
383 }
384 auto mail = mails.first();
385 if (mail->getProperty("subject").toString().isEmpty()) {
386 qWarning() << "Wrong subject";
387 return KAsync::error<void>(1, "Wrong subject.");
388 }
389 if (mail->getProperty("unread").toBool() != true) {
390 qWarning() << "Not unread";
391 return KAsync::error<void>(1, "Not unread.");
392 }
393 QFileInfo info(mail->getProperty("mimeMessage").toString());
394 if (!info.exists()) {
395 qWarning() << "Wrong subject";
396 return KAsync::error<void>(1, "Can't find mime message.");
397 }
398 return KAsync::null<void>();
399 })
400 .exec();
401 result2.waitForFinished();
402 QVERIFY(!result2.errorCode());
368 } 403 }
369 404
370}; 405};