diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-31 11:24:59 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-31 11:24:59 +0200 |
commit | f90ca753a4b723dbf72996bbd1261dc786c7cce6 (patch) | |
tree | 13916b2f69e728af3883e63e23f71a464ef3573b /examples/imapresource/tests | |
parent | 08c368700c57fc1214aab34a24c921756b3200f0 (diff) | |
download | sink-f90ca753a4b723dbf72996bbd1261dc786c7cce6.tar.gz sink-f90ca753a4b723dbf72996bbd1261dc786c7cce6.zip |
Replace the imapresourcetest with the generic mailsynctest
Diffstat (limited to 'examples/imapresource/tests')
-rw-r--r-- | examples/imapresource/tests/CMakeLists.txt | 4 | ||||
-rw-r--r-- | examples/imapresource/tests/imapmailsynctest.cpp | 84 | ||||
-rw-r--r-- | examples/imapresource/tests/imapresourcetest.cpp | 276 |
3 files changed, 86 insertions, 278 deletions
diff --git a/examples/imapresource/tests/CMakeLists.txt b/examples/imapresource/tests/CMakeLists.txt index 0604b91..29ae918 100644 --- a/examples/imapresource/tests/CMakeLists.txt +++ b/examples/imapresource/tests/CMakeLists.txt | |||
@@ -6,12 +6,12 @@ include_directories( | |||
6 | include(SinkTest) | 6 | include(SinkTest) |
7 | 7 | ||
8 | auto_tests ( | 8 | auto_tests ( |
9 | imapresourcetest | ||
10 | imapserverproxytest | 9 | imapserverproxytest |
11 | imapmailtest | 10 | imapmailtest |
11 | imapmailsynctest | ||
12 | ) | 12 | ) |
13 | target_link_libraries(imapresourcetest sink_resource_imap) | ||
14 | target_link_libraries(imapserverproxytest sink_resource_imap) | 13 | target_link_libraries(imapserverproxytest sink_resource_imap) |
15 | target_link_libraries(imapmailtest sink_resource_imap) | 14 | target_link_libraries(imapmailtest sink_resource_imap) |
15 | target_link_libraries(imapmailsynctest sink_resource_imap) | ||
16 | 16 | ||
17 | install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/resetmailbox.sh DESTINATION bin PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ) | 17 | install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/resetmailbox.sh DESTINATION bin PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ) |
diff --git a/examples/imapresource/tests/imapmailsynctest.cpp b/examples/imapresource/tests/imapmailsynctest.cpp new file mode 100644 index 0000000..c73c840 --- /dev/null +++ b/examples/imapresource/tests/imapmailsynctest.cpp | |||
@@ -0,0 +1,84 @@ | |||
1 | #include <QtTest> | ||
2 | |||
3 | #include <tests/mailsynctest.h> | ||
4 | #include "../imapresource.h" | ||
5 | #include "../imapserverproxy.h" | ||
6 | |||
7 | #include "common/test.h" | ||
8 | #include "common/domain/applicationdomaintype.h" | ||
9 | |||
10 | using namespace Sink; | ||
11 | using namespace Sink::ApplicationDomain; | ||
12 | |||
13 | /** | ||
14 | * Test of complete system using the imap resource. | ||
15 | * | ||
16 | * This test requires the imap resource installed. | ||
17 | */ | ||
18 | class ImapMailSyncTest : public Sink::MailSyncTest | ||
19 | { | ||
20 | Q_OBJECT | ||
21 | |||
22 | protected: | ||
23 | void resetTestEnvironment() Q_DECL_OVERRIDE | ||
24 | { | ||
25 | system("resetmailbox.sh"); | ||
26 | } | ||
27 | |||
28 | Sink::ApplicationDomain::SinkResource createResource() Q_DECL_OVERRIDE | ||
29 | { | ||
30 | auto resource = ApplicationDomain::ImapResource::create("account1"); | ||
31 | resource.setProperty("server", "localhost"); | ||
32 | resource.setProperty("port", 993); | ||
33 | resource.setProperty("user", "doe"); | ||
34 | resource.setProperty("password", "doe"); | ||
35 | return resource; | ||
36 | } | ||
37 | |||
38 | Sink::ApplicationDomain::SinkResource createFaultyResource() Q_DECL_OVERRIDE | ||
39 | { | ||
40 | auto resource = ApplicationDomain::ImapResource::create("account1"); | ||
41 | resource.setProperty("server", "foobar"); | ||
42 | resource.setProperty("port", 993); | ||
43 | resource.setProperty("user", "doe"); | ||
44 | resource.setProperty("password", "doe"); | ||
45 | return resource; | ||
46 | } | ||
47 | |||
48 | void removeResourceFromDisk(const QByteArray &identifier) Q_DECL_OVERRIDE | ||
49 | { | ||
50 | ::ImapResource::removeFromDisk(identifier); | ||
51 | } | ||
52 | |||
53 | void createFolder(const QStringList &folderPath) Q_DECL_OVERRIDE | ||
54 | { | ||
55 | Imap::ImapServerProxy imap("localhost", 993); | ||
56 | VERIFYEXEC(imap.login("doe", "doe")); | ||
57 | VERIFYEXEC(imap.create("INBOX." + folderPath.join('.'))); | ||
58 | } | ||
59 | |||
60 | void removeFolder(const QStringList &folderPath) Q_DECL_OVERRIDE | ||
61 | { | ||
62 | Imap::ImapServerProxy imap("localhost", 993); | ||
63 | VERIFYEXEC(imap.login("doe", "doe")); | ||
64 | VERIFYEXEC(imap.remove("INBOX." + folderPath.join('.'))); | ||
65 | } | ||
66 | |||
67 | void createMessage(const QStringList &folderPath, const QByteArray &message) Q_DECL_OVERRIDE | ||
68 | { | ||
69 | Imap::ImapServerProxy imap("localhost", 993); | ||
70 | VERIFYEXEC(imap.login("doe", "doe")); | ||
71 | VERIFYEXEC(imap.append("INBOX." + folderPath.join('.'), message)); | ||
72 | } | ||
73 | |||
74 | void removeMessage(const QStringList &folderPath, const QByteArray &messages) Q_DECL_OVERRIDE | ||
75 | { | ||
76 | Imap::ImapServerProxy imap("localhost", 993); | ||
77 | VERIFYEXEC(imap.login("doe", "doe")); | ||
78 | VERIFYEXEC(imap.remove("INBOX." + folderPath.join('.'), "2:*")); | ||
79 | } | ||
80 | }; | ||
81 | |||
82 | QTEST_MAIN(ImapMailSyncTest) | ||
83 | |||
84 | #include "imapmailsynctest.moc" | ||
diff --git a/examples/imapresource/tests/imapresourcetest.cpp b/examples/imapresource/tests/imapresourcetest.cpp deleted file mode 100644 index fa3caa7..0000000 --- a/examples/imapresource/tests/imapresourcetest.cpp +++ /dev/null | |||
@@ -1,276 +0,0 @@ | |||
1 | #include <QtTest> | ||
2 | |||
3 | #include <QString> | ||
4 | #include <KMime/Message> | ||
5 | |||
6 | // #include "imapresource/imapresource.h" | ||
7 | #include "store.h" | ||
8 | #include "resourcecontrol.h" | ||
9 | #include "commands.h" | ||
10 | #include "entitybuffer.h" | ||
11 | #include "resourceconfig.h" | ||
12 | #include "modelresult.h" | ||
13 | #include "pipeline.h" | ||
14 | #include "log.h" | ||
15 | #include "test.h" | ||
16 | #include "../imapresource.h" | ||
17 | #include "../imapserverproxy.h" | ||
18 | |||
19 | #define ASYNCCOMPARE(actual, expected) \ | ||
20 | do {\ | ||
21 | if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\ | ||
22 | return KAsync::error<void>(1, "Comparison failed.");\ | ||
23 | } while (0) | ||
24 | |||
25 | #define ASYNCVERIFY(statement) \ | ||
26 | do {\ | ||
27 | if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\ | ||
28 | return KAsync::error<void>(1, "Verify failed.");\ | ||
29 | } while (0) | ||
30 | |||
31 | #define VERIFYEXEC(statement) \ | ||
32 | do {\ | ||
33 | auto result = statement.exec(); \ | ||
34 | result.waitForFinished(); \ | ||
35 | if (!QTest::qVerify(!result.errorCode(), #statement, "", __FILE__, __LINE__))\ | ||
36 | return;\ | ||
37 | } while (0) | ||
38 | |||
39 | using namespace Sink; | ||
40 | using namespace Sink::ApplicationDomain; | ||
41 | |||
42 | /** | ||
43 | * Test of complete system using the imap resource. | ||
44 | * | ||
45 | * This test requires the imap resource installed. | ||
46 | */ | ||
47 | class ImapResourceTest : public QObject | ||
48 | { | ||
49 | Q_OBJECT | ||
50 | |||
51 | QTemporaryDir tempDir; | ||
52 | QString targetPath; | ||
53 | private slots: | ||
54 | void initTestCase() | ||
55 | { | ||
56 | Sink::Test::initTest(); | ||
57 | Sink::Log::setDebugOutputLevel(Sink::Log::Trace); | ||
58 | ::ImapResource::removeFromDisk("org.kde.imap.instance1"); | ||
59 | system("resetmailbox.sh"); | ||
60 | // auto resource = ApplicationDomain::ImapResource::create("account1"); | ||
61 | Sink::ApplicationDomain::SinkResource resource; | ||
62 | resource.setProperty("identifier", "org.kde.imap.instance1"); | ||
63 | resource.setProperty("type", "org.kde.imap"); | ||
64 | resource.setProperty("server", "localhost"); | ||
65 | resource.setProperty("user", "doe"); | ||
66 | resource.setProperty("password", "doe"); | ||
67 | resource.setProperty("port", 993); | ||
68 | Sink::Store::create(resource).exec().waitForFinished(); | ||
69 | } | ||
70 | |||
71 | void cleanup() | ||
72 | { | ||
73 | Sink::ResourceControl::shutdown(QByteArray("org.kde.imap.instance1")).exec().waitForFinished(); | ||
74 | ::ImapResource::removeFromDisk("org.kde.imap.instance1"); | ||
75 | } | ||
76 | |||
77 | void init() | ||
78 | { | ||
79 | qDebug(); | ||
80 | qDebug() << "-----------------------------------------"; | ||
81 | qDebug(); | ||
82 | Sink::ResourceControl::start(QByteArray("org.kde.imap.instance1")).exec().waitForFinished(); | ||
83 | } | ||
84 | |||
85 | void testListFolders() | ||
86 | { | ||
87 | Sink::Query query; | ||
88 | query.resources << "org.kde.imap.instance1"; | ||
89 | query.request<Folder::Name>(); | ||
90 | |||
91 | // Ensure all local data is processed | ||
92 | VERIFYEXEC(Store::synchronize(query)); | ||
93 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
94 | |||
95 | auto job = Store::fetchAll<Folder>(query).then<void, QList<Folder::Ptr>>([](const QList<Folder::Ptr> &folders) { | ||
96 | QCOMPARE(folders.size(), 2); | ||
97 | QStringList names; | ||
98 | for (const auto &folder : folders) { | ||
99 | names << folder->getName(); | ||
100 | } | ||
101 | QVERIFY(names.contains("INBOX")); | ||
102 | QVERIFY(names.contains("test")); | ||
103 | }); | ||
104 | VERIFYEXEC(job); | ||
105 | } | ||
106 | |||
107 | void testListFolderHierarchy() | ||
108 | { | ||
109 | Sink::Query query; | ||
110 | query.resources << "org.kde.imap.instance1"; | ||
111 | query.request<Folder::Name>().request<Folder::Parent>(); | ||
112 | |||
113 | Imap::ImapServerProxy imap("localhost", 993); | ||
114 | VERIFYEXEC(imap.login("doe", "doe")); | ||
115 | VERIFYEXEC(imap.create("INBOX.test.sub")); | ||
116 | |||
117 | // Ensure all local data is processed | ||
118 | VERIFYEXEC(Store::synchronize(query)); | ||
119 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
120 | |||
121 | auto job = Store::fetchAll<Folder>(query).then<void, QList<Folder::Ptr>>([](const QList<Folder::Ptr> &folders) { | ||
122 | QCOMPARE(folders.size(), 3); | ||
123 | QHash<QString, Folder::Ptr> map; | ||
124 | for (const auto &folder : folders) { | ||
125 | map.insert(folder->getName(), folder); | ||
126 | } | ||
127 | QCOMPARE(map.value("sub")->getParent(), map.value("test")->identifier()); | ||
128 | }); | ||
129 | VERIFYEXEC(job); | ||
130 | } | ||
131 | |||
132 | void testListNewFolders() | ||
133 | { | ||
134 | Sink::Query query; | ||
135 | query.resources << "org.kde.imap.instance1"; | ||
136 | query.request<Folder::Name>(); | ||
137 | |||
138 | Imap::ImapServerProxy imap("localhost", 993); | ||
139 | VERIFYEXEC(imap.login("doe", "doe")); | ||
140 | VERIFYEXEC(imap.create("INBOX.test.sub1")); | ||
141 | |||
142 | // Ensure all local data is processed | ||
143 | VERIFYEXEC(Store::synchronize(query)); | ||
144 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
145 | |||
146 | auto job = Store::fetchAll<Folder>(query).then<void, QList<Folder::Ptr>>([](const QList<Folder::Ptr> &folders) { | ||
147 | QStringList names; | ||
148 | for (const auto &folder : folders) { | ||
149 | names << folder->getName(); | ||
150 | } | ||
151 | QVERIFY(names.contains("sub1")); | ||
152 | }); | ||
153 | VERIFYEXEC(job); | ||
154 | } | ||
155 | |||
156 | void testListRemovedFolders() | ||
157 | { | ||
158 | Sink::Query query; | ||
159 | query.resources << "org.kde.imap.instance1"; | ||
160 | query.request<Folder::Name>(); | ||
161 | |||
162 | VERIFYEXEC(Store::synchronize(query)); | ||
163 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
164 | |||
165 | Imap::ImapServerProxy imap("localhost", 993); | ||
166 | VERIFYEXEC(imap.login("doe", "doe")); | ||
167 | VERIFYEXEC(imap.remove("INBOX.test.sub1")); | ||
168 | |||
169 | // Ensure all local data is processed | ||
170 | VERIFYEXEC(Store::synchronize(query)); | ||
171 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
172 | |||
173 | auto job = Store::fetchAll<Folder>(query).then<void, QList<Folder::Ptr>>([](const QList<Folder::Ptr> &folders) { | ||
174 | QStringList names; | ||
175 | for (const auto &folder : folders) { | ||
176 | names << folder->getName(); | ||
177 | } | ||
178 | QVERIFY(!names.contains("sub1")); | ||
179 | }); | ||
180 | VERIFYEXEC(job); | ||
181 | } | ||
182 | |||
183 | void testListMails() | ||
184 | { | ||
185 | Sink::Query query; | ||
186 | query.resources << "org.kde.imap.instance1"; | ||
187 | query.request<Mail::Subject>().request<Mail::MimeMessage>(); | ||
188 | |||
189 | // Ensure all local data is processed | ||
190 | VERIFYEXEC(Store::synchronize(query)); | ||
191 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
192 | |||
193 | auto job = Store::fetchAll<Mail>(query).then<void, QList<Mail::Ptr>>([](const QList<Mail::Ptr> &mails) { | ||
194 | QCOMPARE(mails.size(), 1); | ||
195 | QVERIFY(mails.first()->getSubject().startsWith(QString("[Nepomuk] Jenkins build is still unstable"))); | ||
196 | const auto data = mails.first()->getMimeMessage(); | ||
197 | QVERIFY(!data.isEmpty()); | ||
198 | |||
199 | KMime::Message m; | ||
200 | m.setContent(data); | ||
201 | m.parse(); | ||
202 | QCOMPARE(mails.first()->getSubject(), m.subject(true)->asUnicodeString()); | ||
203 | }); | ||
204 | VERIFYEXEC(job); | ||
205 | } | ||
206 | |||
207 | void testFetchNewMessages() | ||
208 | { | ||
209 | Sink::Query query; | ||
210 | query.resources << "org.kde.imap.instance1"; | ||
211 | query.request<Mail::Subject>().request<Mail::MimeMessage>(); | ||
212 | |||
213 | // Ensure all local data is processed | ||
214 | VERIFYEXEC(Store::synchronize(query)); | ||
215 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
216 | |||
217 | Imap::ImapServerProxy imap("localhost", 993); | ||
218 | VERIFYEXEC(imap.login("doe", "doe")); | ||
219 | |||
220 | auto msg = KMime::Message::Ptr::create(); | ||
221 | msg->subject(true)->fromUnicodeString("Foobar", "utf8"); | ||
222 | msg->assemble(); | ||
223 | |||
224 | VERIFYEXEC(imap.append("INBOX.test", msg->encodedContent(true))); | ||
225 | |||
226 | Store::synchronize(query).exec().waitForFinished(); | ||
227 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
228 | |||
229 | auto job = Store::fetchAll<Mail>(query).then<void, QList<Mail::Ptr>>([](const QList<Mail::Ptr> &mails) { | ||
230 | QCOMPARE(mails.size(), 2); | ||
231 | }); | ||
232 | VERIFYEXEC(job); | ||
233 | } | ||
234 | |||
235 | void testFetchRemovedMessages() | ||
236 | { | ||
237 | Sink::Query query; | ||
238 | query.resources << "org.kde.imap.instance1"; | ||
239 | query.request<Mail::Subject>().request<Mail::MimeMessage>(); | ||
240 | |||
241 | // Ensure all local data is processed | ||
242 | VERIFYEXEC(Store::synchronize(query)); | ||
243 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
244 | |||
245 | Imap::ImapServerProxy imap("localhost", 993); | ||
246 | VERIFYEXEC(imap.login("doe", "doe")); | ||
247 | |||
248 | VERIFYEXEC(imap.remove("INBOX.test", "2:*")); | ||
249 | |||
250 | Store::synchronize(query).exec().waitForFinished(); | ||
251 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
252 | |||
253 | auto job = Store::fetchAll<Mail>(query).then<void, QList<Mail::Ptr>>([](const QList<Mail::Ptr> &mails) { | ||
254 | QCOMPARE(mails.size(), 1); | ||
255 | }); | ||
256 | VERIFYEXEC(job); | ||
257 | } | ||
258 | |||
259 | void testFailingSync() | ||
260 | { | ||
261 | auto resource = ApplicationDomain::ImapResource::create("account1"); | ||
262 | resource.setProperty("server", "foobar"); | ||
263 | resource.setProperty("port", 993); | ||
264 | Sink::Store::create(resource).exec().waitForFinished(); | ||
265 | Sink::Query query; | ||
266 | query.resources << resource.identifier(); | ||
267 | |||
268 | // Ensure sync fails if resource is misconfigured | ||
269 | auto future = Store::synchronize(query).exec(); | ||
270 | future.waitForFinished(); | ||
271 | QVERIFY(future.errorCode()); | ||
272 | } | ||
273 | }; | ||
274 | |||
275 | QTEST_MAIN(ImapResourceTest) | ||
276 | #include "imapresourcetest.moc" | ||