From f90ca753a4b723dbf72996bbd1261dc786c7cce6 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 31 May 2016 11:24:59 +0200 Subject: Replace the imapresourcetest with the generic mailsynctest --- examples/imapresource/tests/CMakeLists.txt | 4 +- examples/imapresource/tests/imapmailsynctest.cpp | 84 +++++++ examples/imapresource/tests/imapresourcetest.cpp | 276 ----------------------- 3 files changed, 86 insertions(+), 278 deletions(-) create mode 100644 examples/imapresource/tests/imapmailsynctest.cpp delete mode 100644 examples/imapresource/tests/imapresourcetest.cpp (limited to 'examples') diff --git a/examples/imapresource/tests/CMakeLists.txt b/examples/imapresource/tests/CMakeLists.txt index 0604b91..29ae918 100644 --- a/examples/imapresource/tests/CMakeLists.txt +++ b/examples/imapresource/tests/CMakeLists.txt @@ -6,12 +6,12 @@ include_directories( include(SinkTest) auto_tests ( - imapresourcetest imapserverproxytest imapmailtest + imapmailsynctest ) -target_link_libraries(imapresourcetest sink_resource_imap) target_link_libraries(imapserverproxytest sink_resource_imap) target_link_libraries(imapmailtest sink_resource_imap) +target_link_libraries(imapmailsynctest sink_resource_imap) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/resetmailbox.sh DESTINATION bin PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ) diff --git a/examples/imapresource/tests/imapmailsynctest.cpp b/examples/imapresource/tests/imapmailsynctest.cpp new file mode 100644 index 0000000..c73c840 --- /dev/null +++ b/examples/imapresource/tests/imapmailsynctest.cpp @@ -0,0 +1,84 @@ +#include + +#include +#include "../imapresource.h" +#include "../imapserverproxy.h" + +#include "common/test.h" +#include "common/domain/applicationdomaintype.h" + +using namespace Sink; +using namespace Sink::ApplicationDomain; + +/** + * Test of complete system using the imap resource. + * + * This test requires the imap resource installed. + */ +class ImapMailSyncTest : public Sink::MailSyncTest +{ + Q_OBJECT + +protected: + void resetTestEnvironment() Q_DECL_OVERRIDE + { + system("resetmailbox.sh"); + } + + Sink::ApplicationDomain::SinkResource createResource() Q_DECL_OVERRIDE + { + auto resource = ApplicationDomain::ImapResource::create("account1"); + resource.setProperty("server", "localhost"); + resource.setProperty("port", 993); + resource.setProperty("user", "doe"); + resource.setProperty("password", "doe"); + return resource; + } + + Sink::ApplicationDomain::SinkResource createFaultyResource() Q_DECL_OVERRIDE + { + auto resource = ApplicationDomain::ImapResource::create("account1"); + resource.setProperty("server", "foobar"); + resource.setProperty("port", 993); + resource.setProperty("user", "doe"); + resource.setProperty("password", "doe"); + return resource; + } + + void removeResourceFromDisk(const QByteArray &identifier) Q_DECL_OVERRIDE + { + ::ImapResource::removeFromDisk(identifier); + } + + void createFolder(const QStringList &folderPath) Q_DECL_OVERRIDE + { + Imap::ImapServerProxy imap("localhost", 993); + VERIFYEXEC(imap.login("doe", "doe")); + VERIFYEXEC(imap.create("INBOX." + folderPath.join('.'))); + } + + void removeFolder(const QStringList &folderPath) Q_DECL_OVERRIDE + { + Imap::ImapServerProxy imap("localhost", 993); + VERIFYEXEC(imap.login("doe", "doe")); + VERIFYEXEC(imap.remove("INBOX." + folderPath.join('.'))); + } + + void createMessage(const QStringList &folderPath, const QByteArray &message) Q_DECL_OVERRIDE + { + Imap::ImapServerProxy imap("localhost", 993); + VERIFYEXEC(imap.login("doe", "doe")); + VERIFYEXEC(imap.append("INBOX." + folderPath.join('.'), message)); + } + + void removeMessage(const QStringList &folderPath, const QByteArray &messages) Q_DECL_OVERRIDE + { + Imap::ImapServerProxy imap("localhost", 993); + VERIFYEXEC(imap.login("doe", "doe")); + VERIFYEXEC(imap.remove("INBOX." + folderPath.join('.'), "2:*")); + } +}; + +QTEST_MAIN(ImapMailSyncTest) + +#include "imapmailsynctest.moc" diff --git a/examples/imapresource/tests/imapresourcetest.cpp b/examples/imapresource/tests/imapresourcetest.cpp deleted file mode 100644 index fa3caa7..0000000 --- a/examples/imapresource/tests/imapresourcetest.cpp +++ /dev/null @@ -1,276 +0,0 @@ -#include - -#include -#include - -// #include "imapresource/imapresource.h" -#include "store.h" -#include "resourcecontrol.h" -#include "commands.h" -#include "entitybuffer.h" -#include "resourceconfig.h" -#include "modelresult.h" -#include "pipeline.h" -#include "log.h" -#include "test.h" -#include "../imapresource.h" -#include "../imapserverproxy.h" - -#define ASYNCCOMPARE(actual, expected) \ -do {\ - if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\ - return KAsync::error(1, "Comparison failed.");\ -} while (0) - -#define ASYNCVERIFY(statement) \ -do {\ - if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\ - return KAsync::error(1, "Verify failed.");\ -} while (0) - -#define VERIFYEXEC(statement) \ -do {\ - auto result = statement.exec(); \ - result.waitForFinished(); \ - if (!QTest::qVerify(!result.errorCode(), #statement, "", __FILE__, __LINE__))\ - return;\ -} while (0) - -using namespace Sink; -using namespace Sink::ApplicationDomain; - -/** - * Test of complete system using the imap resource. - * - * This test requires the imap resource installed. - */ -class ImapResourceTest : public QObject -{ - Q_OBJECT - - QTemporaryDir tempDir; - QString targetPath; -private slots: - void initTestCase() - { - Sink::Test::initTest(); - Sink::Log::setDebugOutputLevel(Sink::Log::Trace); - ::ImapResource::removeFromDisk("org.kde.imap.instance1"); - system("resetmailbox.sh"); - // auto resource = ApplicationDomain::ImapResource::create("account1"); - Sink::ApplicationDomain::SinkResource resource; - resource.setProperty("identifier", "org.kde.imap.instance1"); - resource.setProperty("type", "org.kde.imap"); - resource.setProperty("server", "localhost"); - resource.setProperty("user", "doe"); - resource.setProperty("password", "doe"); - resource.setProperty("port", 993); - Sink::Store::create(resource).exec().waitForFinished(); - } - - void cleanup() - { - Sink::ResourceControl::shutdown(QByteArray("org.kde.imap.instance1")).exec().waitForFinished(); - ::ImapResource::removeFromDisk("org.kde.imap.instance1"); - } - - void init() - { - qDebug(); - qDebug() << "-----------------------------------------"; - qDebug(); - Sink::ResourceControl::start(QByteArray("org.kde.imap.instance1")).exec().waitForFinished(); - } - - void testListFolders() - { - Sink::Query query; - query.resources << "org.kde.imap.instance1"; - query.request(); - - // Ensure all local data is processed - VERIFYEXEC(Store::synchronize(query)); - ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - - auto job = Store::fetchAll(query).then>([](const QList &folders) { - QCOMPARE(folders.size(), 2); - QStringList names; - for (const auto &folder : folders) { - names << folder->getName(); - } - QVERIFY(names.contains("INBOX")); - QVERIFY(names.contains("test")); - }); - VERIFYEXEC(job); - } - - void testListFolderHierarchy() - { - Sink::Query query; - query.resources << "org.kde.imap.instance1"; - query.request().request(); - - Imap::ImapServerProxy imap("localhost", 993); - VERIFYEXEC(imap.login("doe", "doe")); - VERIFYEXEC(imap.create("INBOX.test.sub")); - - // Ensure all local data is processed - VERIFYEXEC(Store::synchronize(query)); - ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - - auto job = Store::fetchAll(query).then>([](const QList &folders) { - QCOMPARE(folders.size(), 3); - QHash map; - for (const auto &folder : folders) { - map.insert(folder->getName(), folder); - } - QCOMPARE(map.value("sub")->getParent(), map.value("test")->identifier()); - }); - VERIFYEXEC(job); - } - - void testListNewFolders() - { - Sink::Query query; - query.resources << "org.kde.imap.instance1"; - query.request(); - - Imap::ImapServerProxy imap("localhost", 993); - VERIFYEXEC(imap.login("doe", "doe")); - VERIFYEXEC(imap.create("INBOX.test.sub1")); - - // Ensure all local data is processed - VERIFYEXEC(Store::synchronize(query)); - ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - - auto job = Store::fetchAll(query).then>([](const QList &folders) { - QStringList names; - for (const auto &folder : folders) { - names << folder->getName(); - } - QVERIFY(names.contains("sub1")); - }); - VERIFYEXEC(job); - } - - void testListRemovedFolders() - { - Sink::Query query; - query.resources << "org.kde.imap.instance1"; - query.request(); - - VERIFYEXEC(Store::synchronize(query)); - ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - - Imap::ImapServerProxy imap("localhost", 993); - VERIFYEXEC(imap.login("doe", "doe")); - VERIFYEXEC(imap.remove("INBOX.test.sub1")); - - // Ensure all local data is processed - VERIFYEXEC(Store::synchronize(query)); - ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - - auto job = Store::fetchAll(query).then>([](const QList &folders) { - QStringList names; - for (const auto &folder : folders) { - names << folder->getName(); - } - QVERIFY(!names.contains("sub1")); - }); - VERIFYEXEC(job); - } - - void testListMails() - { - Sink::Query query; - query.resources << "org.kde.imap.instance1"; - query.request().request(); - - // Ensure all local data is processed - VERIFYEXEC(Store::synchronize(query)); - ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - - auto job = Store::fetchAll(query).then>([](const QList &mails) { - QCOMPARE(mails.size(), 1); - QVERIFY(mails.first()->getSubject().startsWith(QString("[Nepomuk] Jenkins build is still unstable"))); - const auto data = mails.first()->getMimeMessage(); - QVERIFY(!data.isEmpty()); - - KMime::Message m; - m.setContent(data); - m.parse(); - QCOMPARE(mails.first()->getSubject(), m.subject(true)->asUnicodeString()); - }); - VERIFYEXEC(job); - } - - void testFetchNewMessages() - { - Sink::Query query; - query.resources << "org.kde.imap.instance1"; - query.request().request(); - - // Ensure all local data is processed - VERIFYEXEC(Store::synchronize(query)); - ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - - Imap::ImapServerProxy imap("localhost", 993); - VERIFYEXEC(imap.login("doe", "doe")); - - auto msg = KMime::Message::Ptr::create(); - msg->subject(true)->fromUnicodeString("Foobar", "utf8"); - msg->assemble(); - - VERIFYEXEC(imap.append("INBOX.test", msg->encodedContent(true))); - - Store::synchronize(query).exec().waitForFinished(); - ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - - auto job = Store::fetchAll(query).then>([](const QList &mails) { - QCOMPARE(mails.size(), 2); - }); - VERIFYEXEC(job); - } - - void testFetchRemovedMessages() - { - Sink::Query query; - query.resources << "org.kde.imap.instance1"; - query.request().request(); - - // Ensure all local data is processed - VERIFYEXEC(Store::synchronize(query)); - ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - - Imap::ImapServerProxy imap("localhost", 993); - VERIFYEXEC(imap.login("doe", "doe")); - - VERIFYEXEC(imap.remove("INBOX.test", "2:*")); - - Store::synchronize(query).exec().waitForFinished(); - ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - - auto job = Store::fetchAll(query).then>([](const QList &mails) { - QCOMPARE(mails.size(), 1); - }); - VERIFYEXEC(job); - } - - void testFailingSync() - { - auto resource = ApplicationDomain::ImapResource::create("account1"); - resource.setProperty("server", "foobar"); - resource.setProperty("port", 993); - Sink::Store::create(resource).exec().waitForFinished(); - Sink::Query query; - query.resources << resource.identifier(); - - // Ensure sync fails if resource is misconfigured - auto future = Store::synchronize(query).exec(); - future.waitForFinished(); - QVERIFY(future.errorCode()); - } -}; - -QTEST_MAIN(ImapResourceTest) -#include "imapresourcetest.moc" -- cgit v1.2.3