From 3f4011bcbf4ccf55edb8ea618fbf9b50f9e7bec9 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 17 Jun 2016 09:09:33 +0200 Subject: Initial version of the mailtransport resource --- .../mailtransportresource/tests/CMakeLists.txt | 11 +++ .../tests/mailtransporttest.cpp | 94 ++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 examples/mailtransportresource/tests/CMakeLists.txt create mode 100644 examples/mailtransportresource/tests/mailtransporttest.cpp (limited to 'examples/mailtransportresource/tests') diff --git a/examples/mailtransportresource/tests/CMakeLists.txt b/examples/mailtransportresource/tests/CMakeLists.txt new file mode 100644 index 0000000..458b462 --- /dev/null +++ b/examples/mailtransportresource/tests/CMakeLists.txt @@ -0,0 +1,11 @@ +set(CMAKE_AUTOMOC ON) +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} +) + +include(SinkTest) + +auto_tests ( + mailtransporttest +) +target_link_libraries(mailtransporttest sink_resource_mailtransport) diff --git a/examples/mailtransportresource/tests/mailtransporttest.cpp b/examples/mailtransportresource/tests/mailtransporttest.cpp new file mode 100644 index 0000000..564b4cb --- /dev/null +++ b/examples/mailtransportresource/tests/mailtransporttest.cpp @@ -0,0 +1,94 @@ +#include + +#include "tests/testutils.h" +#include "../mailtransport.h" + +#include "common/test.h" +#include "common/store.h" +#include "common/resourcecontrol.h" +#include "common/domain/applicationdomaintype.h" +#include "common/log.h" + +using namespace Sink; +using namespace Sink::ApplicationDomain; + +class MailtransportTest : public QObject +{ + Q_OBJECT + + Sink::ApplicationDomain::SinkResource createResource() + { + auto resource = ApplicationDomain::MailtransportResource::create("account1"); + resource.setProperty("server", "localhost"); + // resource.setProperty("port", 993); + resource.setProperty("user", "doe"); + resource.setProperty("password", "doe"); + resource.setProperty("testmode", true); + return resource; + } + + void removeResourceFromDisk(const QByteArray &identifier) + { + // ::MailtransportResource::removeFromDisk(identifier); + } + QByteArray mResourceInstanceIdentifier; + +private slots: + + void initTestCase() + { + Test::initTest(); + Log::setDebugOutputLevel(Sink::Log::Trace); + // resetTestEnvironment(); + auto resource = createResource(); + QVERIFY(!resource.identifier().isEmpty()); + VERIFYEXEC(Store::create(resource)); + mResourceInstanceIdentifier = resource.identifier(); + // mCapabilities = resource.getProperty("capabilities").value(); + qWarning() << "FOooooooooooooooooooo"; + } + + void cleanup() + { + // VERIFYEXEC(ResourceControl::shutdown(mResourceInstanceIdentifier)); + // removeResourceFromDisk(mResourceInstanceIdentifier); + } + + void init() + { + // qDebug(); + // qDebug() << "-----------------------------------------"; + // qDebug(); + // VERIFYEXEC(ResourceControl::start(mResourceInstanceIdentifier)); + } + + void testSendMail() + { + auto message = KMime::Message::Ptr::create(); + message->subject(true)->fromUnicodeString(QString::fromLatin1("Foobar"), "utf8"); + message->assemble(); + + auto mail = ApplicationDomain::Mail::create(mResourceInstanceIdentifier); + mail.setMimeMessage(message->encodedContent()); + + VERIFYEXEC(Store::create(mail)); + VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); + VERIFYEXEC(Store::synchronize(Query::ResourceFilter(mResourceInstanceIdentifier))); + + //TODO verify the mail has been sent + + // auto modifiedMail = Store::readOne(Query::IdentityFilter(mail)); + // VERIFYEXEC(Store::modify(modifiedMail)); + // VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); + // VERIFYEXEC(ResourceControl::flushReplayQueue(QByteArrayList() << mResourceInstanceIdentifier)); + + } + + //TODO test mail that fails to be sent. add a special header to the mail and have the resource fail sending. Ensure we can modify the mail to fix sending of the message. + +}; + + +QTEST_MAIN(MailtransportTest) + +#include "mailtransporttest.moc" -- cgit v1.2.3