blob: 3ce5f828780a43ee5e4e1d3aa7a07e1168a5e0ce (
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
|
#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;
private slots:
void initTestCase()
{
Test::initTest();
Log::setDebugOutputLevel(Sink::Log::Trace);
auto resource = createResource();
QVERIFY(!resource.identifier().isEmpty());
VERIFYEXEC(Store::create(resource));
mResourceInstanceIdentifier = resource.identifier();
}
void cleanup()
{
// VERIFYEXEC(ResourceControl::shutdown(mResourceInstanceIdentifier));
// removeResourceFromDisk(mResourceInstanceIdentifier);
}
void init()
{
// 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)));
VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Mail>(ResourceControl::Inspection::ExistenceInspection(mail, true)));
auto sentMail = Store::readOne<ApplicationDomain::Mail>(Query::IdentityFilter(mail).request<Mail::Sent>().request<Mail::Subject>());
QVERIFY(sentMail.getSent());
QVERIFY(!sentMail.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"
|