diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-24 23:56:18 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-24 23:56:18 +0200 |
commit | 917e5776fb65c5b9bef680b84ef8769d19088294 (patch) | |
tree | c99bae6f433fe5310563318317370645b4641ccb /tests/maildirresourcetest.cpp | |
parent | b4be5caff7691b5a4325938dc10abc02432af26e (diff) | |
download | sink-917e5776fb65c5b9bef680b84ef8769d19088294.tar.gz sink-917e5776fb65c5b9bef680b84ef8769d19088294.zip |
Removed everything from maildirresourcetest that is covered in mailtest
Diffstat (limited to 'tests/maildirresourcetest.cpp')
-rw-r--r-- | tests/maildirresourcetest.cpp | 276 |
1 files changed, 0 insertions, 276 deletions
diff --git a/tests/maildirresourcetest.cpp b/tests/maildirresourcetest.cpp index 17d297d..46d2a28 100644 --- a/tests/maildirresourcetest.cpp +++ b/tests/maildirresourcetest.cpp | |||
@@ -293,282 +293,6 @@ private slots: | |||
293 | QTRY_VERIFY(!QFileInfo(targetPath).exists()); | 293 | QTRY_VERIFY(!QFileInfo(targetPath).exists()); |
294 | } | 294 | } |
295 | 295 | ||
296 | void testCreateMail() | ||
297 | { | ||
298 | Sink::Query query; | ||
299 | query.resources << "org.kde.maildir.instance1"; | ||
300 | |||
301 | // Ensure all local data is processed | ||
302 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
303 | |||
304 | auto message = KMime::Message::Ptr::create(); | ||
305 | message->subject(true)->fromUnicodeString(QString::fromLatin1("Foobar"), "utf8"); | ||
306 | message->assemble(); | ||
307 | |||
308 | auto mail = Sink::ApplicationDomain::ApplicationDomainType::createEntity<Sink::ApplicationDomain::Mail>("org.kde.maildir.instance1"); | ||
309 | mail.setBlobProperty("mimeMessage", message->encodedContent()); | ||
310 | //FIXME generate accessors | ||
311 | // mail.setMimeMessage(message->encodedContent()); | ||
312 | |||
313 | Sink::Store::create(mail).exec().waitForFinished(); | ||
314 | |||
315 | // Ensure all local data is processed | ||
316 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
317 | |||
318 | //Ensure extracted properties are up to date. | ||
319 | auto future = Sink::Store::fetchOne<ApplicationDomain::Mail>(Query::IdentityFilter(mail.identifier()) + Query::RequestedProperties(QByteArrayList() << "subject")) | ||
320 | .then<void, ApplicationDomain::Mail>([](const ApplicationDomain::Mail &mail) { | ||
321 | QCOMPARE(mail.getProperty("subject").toString(), QString::fromLatin1("Foobar")); | ||
322 | }).exec(); | ||
323 | future.waitForFinished(); | ||
324 | |||
325 | auto targetPath = tempDir.path() + "/maildir1/cur"; | ||
326 | QDir dir(targetPath); | ||
327 | dir.setFilter(QDir::Files); | ||
328 | QTRY_COMPARE(dir.count(), static_cast<unsigned int>(2)); | ||
329 | QFile file(targetPath + "/" + dir.entryList().last()); | ||
330 | QVERIFY(file.open(QIODevice::ReadOnly)); | ||
331 | KMime::Message m; | ||
332 | m.setContent(file.readAll()); | ||
333 | m.parse(); | ||
334 | QCOMPARE(m.subject(true)->asUnicodeString(), QString::fromLatin1("Foobar")); | ||
335 | } | ||
336 | |||
337 | void testCreateMailInFolder() | ||
338 | { | ||
339 | auto query = Sink::Query::ResourceFilter("org.kde.maildir.instance1"); | ||
340 | |||
341 | // Ensure all local data is processed | ||
342 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
343 | |||
344 | //TODO | ||
345 | //create folder | ||
346 | //create mail in folder | ||
347 | //ensure mail is in folder | ||
348 | // | ||
349 | auto folder = Sink::ApplicationDomain::ApplicationDomainType::createEntity<Sink::ApplicationDomain::Folder>("org.kde.maildir.instance1"); | ||
350 | folder.setProperty("name", "newfolder"); | ||
351 | |||
352 | Sink::Store::create(folder).exec().waitForFinished(); | ||
353 | |||
354 | auto message = KMime::Message::Ptr::create(); | ||
355 | message->subject(true)->fromUnicodeString(QString::fromLatin1("Foobar"), "utf8"); | ||
356 | message->assemble(); | ||
357 | |||
358 | auto mail = Sink::ApplicationDomain::ApplicationDomainType::createEntity<Sink::ApplicationDomain::Mail>("org.kde.maildir.instance1"); | ||
359 | mail.setBlobProperty("mimeMessage", message->encodedContent()); | ||
360 | mail.setProperty("folder", folder); | ||
361 | |||
362 | Sink::Store::create(mail).exec().waitForFinished(); | ||
363 | // .then() | ||
364 | // .exec().waitForFinished(); | ||
365 | // | ||
366 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
367 | |||
368 | auto future = Sink::Store::fetchOne<ApplicationDomain::Mail>(Query::IdentityFilter(mail.identifier()) + Query::RequestedProperties(QByteArrayList() << "mimeMessage" << "folder")) | ||
369 | .then<void, ApplicationDomain::Mail>([folder](const ApplicationDomain::Mail &mail) { | ||
370 | // qDebug() << "Retrieved draft: " << mail.getProperty("folder") << mail.identifier() << mail.getProperty("mimeMessage").toString(); | ||
371 | QCOMPARE(mail.getProperty("folder").toByteArray(), folder.identifier()); | ||
372 | }).exec(); | ||
373 | future.waitForFinished(); | ||
374 | if (future.errorCode()) { | ||
375 | qWarning() << future.errorCode() << future.errorMessage(); | ||
376 | } | ||
377 | QVERIFY(!future.errorCode()); | ||
378 | auto future2 = ResourceControl::inspect<ApplicationDomain::Mail>(ResourceControl::Inspection::ExistenceInspection(mail, false)).exec(); | ||
379 | future2.waitForFinished(); | ||
380 | QVERIFY(!future2.errorCode()); | ||
381 | |||
382 | auto targetPath = tempDir.path() + "/maildir1/newfolder/cur"; | ||
383 | QDir dir(targetPath); | ||
384 | dir.setFilter(QDir::Files); | ||
385 | QCOMPARE(dir.count(), static_cast<unsigned int>(1)); | ||
386 | } | ||
387 | |||
388 | void testRemoveMail() | ||
389 | { | ||
390 | using namespace Sink; | ||
391 | using namespace Sink::ApplicationDomain; | ||
392 | |||
393 | auto query = Query::ResourceFilter("org.kde.maildir.instance1"); | ||
394 | Store::synchronize(query).exec().waitForFinished(); | ||
395 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
396 | |||
397 | auto result = Store::fetchOne<Folder>( | ||
398 | Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name")) | ||
399 | .then<void, KAsync::Job<void>, Folder>([query](const Folder &folder) { | ||
400 | return Store::fetchAll<Mail>(Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" | ||
401 | << "subject")) | ||
402 | .then<void, KAsync::Job<void>, QList<Mail::Ptr>>([query](const QList<Mail::Ptr> &mails) { | ||
403 | ASYNCCOMPARE(mails.size(), 1); | ||
404 | auto mail = mails.first(); | ||
405 | |||
406 | return Store::remove(*mail) | ||
407 | .then(ResourceControl::flushReplayQueue(query.resources)) // The change needs to be replayed already | ||
408 | .then(ResourceControl::inspect<Mail>(ResourceControl::Inspection::ExistenceInspection(*mail, false))); | ||
409 | }); | ||
410 | }) | ||
411 | .exec(); | ||
412 | result.waitForFinished(); | ||
413 | QVERIFY(!result.errorCode()); | ||
414 | } | ||
415 | |||
416 | void testMarkMailAsRead() | ||
417 | { | ||
418 | using namespace Sink; | ||
419 | using namespace Sink::ApplicationDomain; | ||
420 | |||
421 | auto query = Query::ResourceFilter("org.kde.maildir.instance1"); | ||
422 | Store::synchronize(query).exec().waitForFinished(); | ||
423 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
424 | |||
425 | Folder f; | ||
426 | |||
427 | auto result = Store::fetchOne<Folder>( | ||
428 | Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name")) | ||
429 | .then<void, KAsync::Job<void>, Folder>([query, &f](const Folder &folder) { | ||
430 | f = folder; | ||
431 | return Store::fetchAll<Mail>(Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("folder", folder) + | ||
432 | Query::RequestedProperties(QByteArrayList() << "folder" | ||
433 | << "subject")) | ||
434 | .then<void, KAsync::Job<void>, QList<Mail::Ptr>>([query](const QList<Mail::Ptr> &mails) { | ||
435 | ASYNCCOMPARE(mails.size(), 1); | ||
436 | auto mail = mails.first(); | ||
437 | mail->setProperty("unread", true); | ||
438 | return Store::modify(*mail) | ||
439 | .then<void>(ResourceControl::flushReplayQueue(query.resources)) // The change needs to be replayed already | ||
440 | .then(ResourceControl::inspect<Mail>(ResourceControl::Inspection::PropertyInspection(*mail, "unread", true))) | ||
441 | .then(ResourceControl::inspect<Mail>(ResourceControl::Inspection::PropertyInspection(*mail, "subject", mail->getProperty("subject")))); | ||
442 | }); | ||
443 | }) | ||
444 | .exec(); | ||
445 | result.waitForFinished(); | ||
446 | QVERIFY(!result.errorCode()); | ||
447 | |||
448 | // Verify that we can still query for all relevant information | ||
449 | auto result2 = Store::fetchAll<Mail>( | ||
450 | Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("folder", f) + Query::RequestedProperties(QByteArrayList() << "folder" | ||
451 | << "subject" | ||
452 | << "mimeMessage" | ||
453 | << "unread")) | ||
454 | .then<void, KAsync::Job<void>, QList<Mail::Ptr>>([](const QList<Mail::Ptr> &mails) { | ||
455 | ASYNCCOMPARE(mails.size(), 1); | ||
456 | auto mail = mails.first(); | ||
457 | ASYNCVERIFY(!mail->getProperty("subject").toString().isEmpty()); | ||
458 | ASYNCCOMPARE(mail->getProperty("unread").toBool(), true); | ||
459 | ASYNCVERIFY(QFileInfo(mail->getProperty("mimeMessage").toString()).exists()); | ||
460 | return KAsync::null<void>(); | ||
461 | }) | ||
462 | .exec(); | ||
463 | result2.waitForFinished(); | ||
464 | QVERIFY(!result2.errorCode()); | ||
465 | } | ||
466 | |||
467 | void testEditMail() | ||
468 | { | ||
469 | using namespace Sink; | ||
470 | using namespace Sink::ApplicationDomain; | ||
471 | |||
472 | auto query = Query::ResourceFilter("org.kde.maildir.instance1"); | ||
473 | Store::synchronize(query).exec().waitForFinished(); | ||
474 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
475 | |||
476 | Folder f; | ||
477 | |||
478 | auto result = Store::fetchOne<Folder>( | ||
479 | Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name")) | ||
480 | .then<void, KAsync::Job<void>, Folder>([query, &f](const Folder &folder) { | ||
481 | f = folder; | ||
482 | return Store::fetchAll<Mail>(Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("folder", folder) + | ||
483 | Query::RequestedProperties(QByteArrayList() << "folder" | ||
484 | << "subject" << "mimeMessage")) | ||
485 | .then<void, KAsync::Job<void>, QList<Mail::Ptr>>([query](const QList<Mail::Ptr> &mails) { | ||
486 | ASYNCCOMPARE(mails.size(), 1); | ||
487 | auto mail = mails.first(); | ||
488 | auto message = KMime::Message::Ptr::create(); | ||
489 | message->subject(true)->fromUnicodeString("Test1", "utf8"); | ||
490 | message->assemble(); | ||
491 | mail->setMimeMessage(message->encodedContent()); | ||
492 | return Store::modify(*mail); | ||
493 | }); | ||
494 | }) | ||
495 | .exec(); | ||
496 | result.waitForFinished(); | ||
497 | QVERIFY(!result.errorCode()); | ||
498 | |||
499 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
500 | |||
501 | // Verify that we can still query for all relevant information | ||
502 | auto result2 = Store::fetchAll<Mail>( | ||
503 | Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("folder", f) + Query::RequestedProperties(QByteArrayList() << "folder" | ||
504 | << "subject" | ||
505 | << "mimeMessage" | ||
506 | << "unread")) | ||
507 | .then<void, KAsync::Job<void>, QList<Mail::Ptr>>([](const QList<Mail::Ptr> &mails) { | ||
508 | ASYNCCOMPARE(mails.size(), 1); | ||
509 | auto mail = mails.first(); | ||
510 | ASYNCCOMPARE(mail->getProperty("subject").toString(), QString("Test1")); | ||
511 | ASYNCVERIFY(QFileInfo(mail->getMimeMessagePath()).exists()); | ||
512 | return KAsync::null<void>(); | ||
513 | }) | ||
514 | .exec(); | ||
515 | result2.waitForFinished(); | ||
516 | QVERIFY(!result2.errorCode()); | ||
517 | |||
518 | //Ensure we didn't leave a stale message behind | ||
519 | auto targetPath = tempDir.path() + "/maildir1/cur"; | ||
520 | QDir dir(targetPath); | ||
521 | dir.setFilter(QDir::Files); | ||
522 | QTRY_COMPARE(dir.count(), static_cast<unsigned int>(1)); | ||
523 | } | ||
524 | |||
525 | void testCreateDraft() | ||
526 | { | ||
527 | Sink::Query query; | ||
528 | query.resources << "org.kde.maildir.instance1"; | ||
529 | |||
530 | Sink::Store::synchronize(query).exec().waitForFinished(); | ||
531 | // Ensure all local data is processed | ||
532 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
533 | |||
534 | auto message = KMime::Message::Ptr::create(); | ||
535 | message->subject(true)->fromUnicodeString(QString::fromLatin1("Foobar"), "utf8"); | ||
536 | message->assemble(); | ||
537 | |||
538 | auto mail = Sink::ApplicationDomain::ApplicationDomainType::createEntity<Sink::ApplicationDomain::Mail>("org.kde.maildir.instance1"); | ||
539 | // Sink::ApplicationDomain::Mail::create("org.kde.maildir.instance1"); | ||
540 | mail.setBlobProperty("mimeMessage", message->encodedContent()); | ||
541 | mail.setProperty("draft", true); | ||
542 | |||
543 | Sink::Store::create(mail).exec().waitForFinished(); | ||
544 | |||
545 | // Ensure all local data is processed | ||
546 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
547 | |||
548 | QByteArray folderIdentifier; | ||
549 | auto future = Sink::Store::fetchOne<ApplicationDomain::Mail>(Query::IdentityFilter(mail.identifier()) + Query::RequestedProperties(QByteArrayList() << "mimeMessage" << "folder")) | ||
550 | .then<void, ApplicationDomain::Mail>([&](const ApplicationDomain::Mail &mail) { | ||
551 | folderIdentifier = mail.getProperty("folder").toByteArray(); | ||
552 | QVERIFY(!folderIdentifier.isEmpty()); | ||
553 | }).exec(); | ||
554 | future.waitForFinished(); | ||
555 | if (future.errorCode()) { | ||
556 | qWarning() << future.errorCode() << future.errorMessage(); | ||
557 | } | ||
558 | QVERIFY(!future.errorCode()); | ||
559 | |||
560 | //Ensure we can also query by folder | ||
561 | Sink::Store::fetchAll<ApplicationDomain::Mail>(Query::PropertyFilter("folder", folderIdentifier)) | ||
562 | .then<void, QList<ApplicationDomain::Mail::Ptr> >([&](const QList<ApplicationDomain::Mail::Ptr> &mails) { | ||
563 | bool found = false; | ||
564 | for (const auto m : mails) { | ||
565 | if (m->identifier() == mail.identifier()) { | ||
566 | found = true; | ||
567 | } | ||
568 | } | ||
569 | QVERIFY(found); | ||
570 | }).exec().waitForFinished(); | ||
571 | } | ||
572 | }; | 296 | }; |
573 | 297 | ||
574 | QTEST_MAIN(MaildirResourceTest) | 298 | QTEST_MAIN(MaildirResourceTest) |