blob: 23a61b807ae9adc8505bf57f728d066742d03f89 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
#include <QtTest>
#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;
}
QByteArray mResourceInstanceIdentifier;
QByteArray mStorageResource;
private slots:
void initTestCase()
{
Test::initTest();
auto resource = createResource();
QVERIFY(!resource.identifier().isEmpty());
VERIFYEXEC(Store::create(resource));
mResourceInstanceIdentifier = resource.identifier();
auto dummyResource = ApplicationDomain::DummyResource::create("account1");
VERIFYEXEC(Store::create(dummyResource));
mStorageResource = dummyResource.identifier();
QVERIFY(!mStorageResource.isEmpty());
}
void cleanup()
{
VERIFYEXEC(ResourceControl::shutdown(mResourceInstanceIdentifier));
}
void init()
{
VERIFYEXEC(ResourceControl::start(mResourceInstanceIdentifier));
}
void testSendMail()
{
auto message = KMime::Message::Ptr::create();
message->messageID(true)->generate("foo.com");
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));
//FIXME the email is sent already because changereplay kicks of automatically
//Ensure the mail is queryable in the outbox
// auto mailInOutbox = Store::readOne<ApplicationDomain::Mail>(Query().resourceFilter(mResourceInstanceIdentifier).filter<Mail::Sent>(false).request<Mail::Subject>().request<Mail::Folder>().request<Mail::MimeMessage>().request<Mail::Sent>());
// QVERIFY(!mailInOutbox.identifier().isEmpty());
//Ensure the mail is sent and moved to the sent mail folder on sync
VERIFYEXEC(Store::synchronize(Query().resourceFilter(mResourceInstanceIdentifier)));
QTest::qWait(100);
VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mStorageResource));
auto mailInSentMailFolder = Store::readOne<ApplicationDomain::Mail>(Query().resourceFilter(mStorageResource).filter<Mail::Sent>(true).request<Mail::Subject>().request<Mail::Folder>().request<Mail::MimeMessage>().request<Mail::Sent>());
//Check that the mail has been moved to the sent mail folder
QVERIFY(mailInSentMailFolder.getSent());
QVERIFY(!mailInSentMailFolder.getSubject().isEmpty());
}
//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"
|