summaryrefslogtreecommitdiffstats
path: root/examples/mailtransportresource/tests
diff options
context:
space:
mode:
Diffstat (limited to 'examples/mailtransportresource/tests')
-rw-r--r--examples/mailtransportresource/tests/CMakeLists.txt11
-rw-r--r--examples/mailtransportresource/tests/mailtransporttest.cpp94
2 files changed, 105 insertions, 0 deletions
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 @@
1set(CMAKE_AUTOMOC ON)
2include_directories(
3 ${CMAKE_CURRENT_BINARY_DIR}
4)
5
6include(SinkTest)
7
8auto_tests (
9 mailtransporttest
10)
11target_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 @@
1#include <QtTest>
2
3#include "tests/testutils.h"
4#include "../mailtransport.h"
5
6#include "common/test.h"
7#include "common/store.h"
8#include "common/resourcecontrol.h"
9#include "common/domain/applicationdomaintype.h"
10#include "common/log.h"
11
12using namespace Sink;
13using namespace Sink::ApplicationDomain;
14
15class MailtransportTest : public QObject
16{
17 Q_OBJECT
18
19 Sink::ApplicationDomain::SinkResource createResource()
20 {
21 auto resource = ApplicationDomain::MailtransportResource::create("account1");
22 resource.setProperty("server", "localhost");
23 // resource.setProperty("port", 993);
24 resource.setProperty("user", "doe");
25 resource.setProperty("password", "doe");
26 resource.setProperty("testmode", true);
27 return resource;
28 }
29
30 void removeResourceFromDisk(const QByteArray &identifier)
31 {
32 // ::MailtransportResource::removeFromDisk(identifier);
33 }
34 QByteArray mResourceInstanceIdentifier;
35
36private slots:
37
38 void initTestCase()
39 {
40 Test::initTest();
41 Log::setDebugOutputLevel(Sink::Log::Trace);
42 // resetTestEnvironment();
43 auto resource = createResource();
44 QVERIFY(!resource.identifier().isEmpty());
45 VERIFYEXEC(Store::create(resource));
46 mResourceInstanceIdentifier = resource.identifier();
47 // mCapabilities = resource.getProperty("capabilities").value<QByteArrayList>();
48 qWarning() << "FOooooooooooooooooooo";
49 }
50
51 void cleanup()
52 {
53 // VERIFYEXEC(ResourceControl::shutdown(mResourceInstanceIdentifier));
54 // removeResourceFromDisk(mResourceInstanceIdentifier);
55 }
56
57 void init()
58 {
59 // qDebug();
60 // qDebug() << "-----------------------------------------";
61 // qDebug();
62 // VERIFYEXEC(ResourceControl::start(mResourceInstanceIdentifier));
63 }
64
65 void testSendMail()
66 {
67 auto message = KMime::Message::Ptr::create();
68 message->subject(true)->fromUnicodeString(QString::fromLatin1("Foobar"), "utf8");
69 message->assemble();
70
71 auto mail = ApplicationDomain::Mail::create(mResourceInstanceIdentifier);
72 mail.setMimeMessage(message->encodedContent());
73
74 VERIFYEXEC(Store::create(mail));
75 VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier));
76 VERIFYEXEC(Store::synchronize(Query::ResourceFilter(mResourceInstanceIdentifier)));
77
78 //TODO verify the mail has been sent
79
80 // auto modifiedMail = Store::readOne<ApplicationDomain::Mail>(Query::IdentityFilter(mail));
81 // VERIFYEXEC(Store::modify(modifiedMail));
82 // VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier));
83 // VERIFYEXEC(ResourceControl::flushReplayQueue(QByteArrayList() << mResourceInstanceIdentifier));
84
85 }
86
87 //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.
88
89};
90
91
92QTEST_MAIN(MailtransportTest)
93
94#include "mailtransporttest.moc"