diff options
Diffstat (limited to 'tests/interresourcemovetest.cpp')
-rw-r--r-- | tests/interresourcemovetest.cpp | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/tests/interresourcemovetest.cpp b/tests/interresourcemovetest.cpp index 7561c5b..3ac6ad4 100644 --- a/tests/interresourcemovetest.cpp +++ b/tests/interresourcemovetest.cpp | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "log.h" | 28 | #include "log.h" |
29 | #include "test.h" | 29 | #include "test.h" |
30 | #include "testutils.h" | 30 | #include "testutils.h" |
31 | #include <KMime/Message> | ||
31 | 32 | ||
32 | using namespace Sink; | 33 | using namespace Sink; |
33 | using namespace Sink::ApplicationDomain; | 34 | using namespace Sink::ApplicationDomain; |
@@ -41,6 +42,15 @@ class InterResourceMoveTest : public QObject | |||
41 | { | 42 | { |
42 | Q_OBJECT | 43 | Q_OBJECT |
43 | 44 | ||
45 | QByteArray message(const QByteArray &uid, const QString &subject) | ||
46 | { | ||
47 | KMime::Message m; | ||
48 | m.subject(true)->fromUnicodeString(subject, "utf8"); | ||
49 | m.messageID(true)->setIdentifier(uid); | ||
50 | m.assemble(); | ||
51 | return m.encodedContent(); | ||
52 | } | ||
53 | |||
44 | private slots: | 54 | private slots: |
45 | void initTestCase() | 55 | void initTestCase() |
46 | { | 56 | { |
@@ -65,24 +75,25 @@ private slots: | |||
65 | 75 | ||
66 | void testMove() | 76 | void testMove() |
67 | { | 77 | { |
68 | Event event("instance1"); | 78 | QByteArray testuid = "testuid@test.test"; |
69 | event.setProperty("uid", "testuid"); | 79 | QString subject = "summaryValue"; |
70 | QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); | 80 | auto mimeMessage = message(testuid, subject); |
71 | event.setProperty("summary", "summaryValue"); | ||
72 | VERIFYEXEC(Sink::Store::create<Event>(event)); | ||
73 | 81 | ||
82 | Mail mail("instance1"); | ||
83 | mail.setMimeMessage(mimeMessage); | ||
84 | VERIFYEXEC(Sink::Store::create<Mail>(mail)); | ||
74 | 85 | ||
75 | Event createdEvent; | 86 | Mail createdmail; |
76 | // Ensure all local data is processed | 87 | // Ensure all local data is processed |
77 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "instance1")); | 88 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "instance1")); |
78 | { | 89 | { |
79 | auto query = Query().resourceFilter("instance1") ; | 90 | auto query = Query().resourceFilter("instance1") ; |
80 | auto list = Sink::Store::read<Event>(query.filter<Event::Uid>("testuid")); | 91 | auto list = Sink::Store::read<Mail>(query.filter<Mail::MessageId>(testuid)); |
81 | QCOMPARE(list.size(), 1); | 92 | QCOMPARE(list.size(), 1); |
82 | createdEvent = list.first(); | 93 | createdmail = list.first(); |
83 | } | 94 | } |
84 | 95 | ||
85 | VERIFYEXEC(Sink::Store::move<Event>(createdEvent, "instance2")); | 96 | VERIFYEXEC(Sink::Store::move<Mail>(createdmail, "instance2")); |
86 | 97 | ||
87 | //FIXME we can't guarantee that that the create command arrives at instance2 before the flush command, so we'll just wait for a little bit. | 98 | //FIXME we can't guarantee that that the create command arrives at instance2 before the flush command, so we'll just wait for a little bit. |
88 | QTest::qWait(1000); | 99 | QTest::qWait(1000); |
@@ -92,14 +103,18 @@ private slots: | |||
92 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "instance2")); | 103 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "instance2")); |
93 | { | 104 | { |
94 | auto query = Query().resourceFilter("instance2") ; | 105 | auto query = Query().resourceFilter("instance2") ; |
95 | auto list = Sink::Store::read<Event>(query.filter<Event::Uid>("testuid")); | 106 | auto list = Sink::Store::read<Mail>(query.filter<Mail::MessageId>(testuid)); |
96 | QCOMPARE(list.size(), 1); | 107 | QCOMPARE(list.size(), 1); |
108 | const auto mail = list.first(); | ||
109 | QVERIFY(!mail.getMimeMessagePath().isEmpty()); | ||
110 | QCOMPARE(mail.getSubject(), subject); | ||
111 | QCOMPARE(mail.getMimeMessage(), mimeMessage); | ||
97 | } | 112 | } |
98 | 113 | ||
99 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "instance1")); | 114 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "instance1")); |
100 | { | 115 | { |
101 | auto query = Query().resourceFilter("instance1") ; | 116 | auto query = Query().resourceFilter("instance1") ; |
102 | auto list = Sink::Store::read<Event>(query.filter<Event::Uid>("testuid")); | 117 | auto list = Sink::Store::read<Mail>(query.filter<Mail::MessageId>(testuid)); |
103 | QCOMPARE(list.size(), 0); | 118 | QCOMPARE(list.size(), 0); |
104 | } | 119 | } |
105 | } | 120 | } |