Changeset View
Changeset View
Standalone View
Standalone View
tests/units/akonadi/akonadiprojectrepositorytest.cpp
Show First 20 Lines • Show All 145 Lines • ▼ Show 20 Line(s) | 137 | { | |||
---|---|---|---|---|---|
146 | QTest::addColumn<bool>("execParentJob"); | 146 | QTest::addColumn<bool>("execParentJob"); | ||
147 | QTest::addColumn<Akonadi::Item::List>("list"); | 147 | QTest::addColumn<Akonadi::Item::List>("list"); | ||
148 | 148 | | |||
149 | Akonadi::Collection col(40); | 149 | Akonadi::Collection col(40); | ||
150 | 150 | | |||
151 | Akonadi::Item childItem(42); | 151 | Akonadi::Item childItem(42); | ||
152 | childItem.setParentCollection(col); | 152 | childItem.setParentCollection(col); | ||
153 | Domain::Artifact::Ptr childTask(new Domain::Task); | 153 | Domain::Artifact::Ptr childTask(new Domain::Task); | ||
154 | Domain::Artifact::Ptr childNote(new Domain::Note); | | |||
155 | 154 | | |||
156 | Akonadi::Item parentItem(41); | 155 | Akonadi::Item parentItem(41); | ||
157 | parentItem.setParentCollection(col); | 156 | parentItem.setParentCollection(col); | ||
158 | auto parent = Domain::Project::Ptr::create(); | 157 | auto parent = Domain::Project::Ptr::create(); | ||
159 | 158 | | |||
160 | auto itemFetchJob1 = new Testlib::AkonadiFakeItemFetchJob(this); | 159 | auto itemFetchJob1 = new Testlib::AkonadiFakeItemFetchJob(this); | ||
161 | itemFetchJob1->setItems(Akonadi::Item::List() << childItem); | 160 | itemFetchJob1->setItems(Akonadi::Item::List() << childItem); | ||
162 | auto itemFetchJob2 = new Testlib::AkonadiFakeItemFetchJob(this); | 161 | auto itemFetchJob2 = new Testlib::AkonadiFakeItemFetchJob(this); | ||
163 | itemFetchJob2->setItems(Akonadi::Item::List() << parentItem); | 162 | itemFetchJob2->setItems(Akonadi::Item::List() << parentItem); | ||
164 | auto itemFetchJob3 = new Testlib::AkonadiFakeItemFetchJob(this); | 163 | auto itemFetchJob3 = new Testlib::AkonadiFakeItemFetchJob(this); | ||
165 | 164 | | |||
166 | Akonadi::Item::List list; | 165 | Akonadi::Item::List list; | ||
167 | 166 | | |||
168 | QTest::newRow("nominal case (task)") << childItem << parentItem << childTask << parent << itemFetchJob1 << itemFetchJob2 << itemFetchJob3 << true << true << list; | 167 | QTest::newRow("nominal case (task)") << childItem << parentItem << childTask << parent << itemFetchJob1 << itemFetchJob2 << itemFetchJob3 << true << true << list; | ||
169 | 168 | | |||
170 | itemFetchJob1 = new Testlib::AkonadiFakeItemFetchJob(this); | 169 | itemFetchJob1 = new Testlib::AkonadiFakeItemFetchJob(this); | ||
171 | itemFetchJob1->setItems(Akonadi::Item::List() << childItem); | | |||
172 | itemFetchJob2 = new Testlib::AkonadiFakeItemFetchJob(this); | | |||
173 | itemFetchJob2->setItems(Akonadi::Item::List() << parentItem); | | |||
174 | itemFetchJob3 = new Testlib::AkonadiFakeItemFetchJob(this); | | |||
175 | QTest::newRow("nominal case (note)") << childItem << parentItem << childNote << parent << itemFetchJob1 << itemFetchJob2 << itemFetchJob3 << true << true << list; | | |||
176 | | ||||
177 | itemFetchJob1 = new Testlib::AkonadiFakeItemFetchJob(this); | | |||
178 | itemFetchJob1->setExpectedError(KJob::KilledJobError); | 170 | itemFetchJob1->setExpectedError(KJob::KilledJobError); | ||
179 | QTest::newRow("child job error with empty list") << childItem << parentItem << childTask << parent << itemFetchJob1 << itemFetchJob2 << itemFetchJob3 << false << false << list; | 171 | QTest::newRow("child job error with empty list") << childItem << parentItem << childTask << parent << itemFetchJob1 << itemFetchJob2 << itemFetchJob3 << false << false << list; | ||
180 | 172 | | |||
181 | itemFetchJob1 = new Testlib::AkonadiFakeItemFetchJob(this); | 173 | itemFetchJob1 = new Testlib::AkonadiFakeItemFetchJob(this); | ||
182 | itemFetchJob1->setExpectedError(KJob::KilledJobError); | 174 | itemFetchJob1->setExpectedError(KJob::KilledJobError); | ||
183 | itemFetchJob1->setItems(Akonadi::Item::List() << childItem); | 175 | itemFetchJob1->setItems(Akonadi::Item::List() << childItem); | ||
184 | QTest::newRow("child job error with item (task)") << childItem << parentItem << childTask << parent << itemFetchJob1 << itemFetchJob2 << itemFetchJob3 << false << false << list; | 176 | QTest::newRow("child job error with item (task)") << childItem << parentItem << childTask << parent << itemFetchJob1 << itemFetchJob2 << itemFetchJob3 << false << false << list; | ||
185 | 177 | | |||
186 | itemFetchJob1 = new Testlib::AkonadiFakeItemFetchJob(this); | 178 | itemFetchJob1 = new Testlib::AkonadiFakeItemFetchJob(this); | ||
187 | itemFetchJob1->setExpectedError(KJob::KilledJobError); | | |||
188 | itemFetchJob1->setItems(Akonadi::Item::List() << childItem); | | |||
189 | QTest::newRow("child job error with item (note)") << childItem << parentItem << childNote << parent << itemFetchJob1 << itemFetchJob2 << itemFetchJob3 << false << false << list; | | |||
190 | | ||||
191 | itemFetchJob1 = new Testlib::AkonadiFakeItemFetchJob(this); | | |||
192 | itemFetchJob1->setItems(Akonadi::Item::List() << childItem); | 179 | itemFetchJob1->setItems(Akonadi::Item::List() << childItem); | ||
193 | itemFetchJob2 = new Testlib::AkonadiFakeItemFetchJob(this); | 180 | itemFetchJob2 = new Testlib::AkonadiFakeItemFetchJob(this); | ||
194 | itemFetchJob2->setExpectedError(KJob::KilledJobError); | 181 | itemFetchJob2->setExpectedError(KJob::KilledJobError); | ||
195 | QTest::newRow("parent job error with empty list (task)") << childItem << parentItem << childTask << parent << itemFetchJob1 << itemFetchJob2 << itemFetchJob3 << true << false << list; | 182 | QTest::newRow("parent job error with empty list (task)") << childItem << parentItem << childTask << parent << itemFetchJob1 << itemFetchJob2 << itemFetchJob3 << true << false << list; | ||
196 | 183 | | |||
197 | itemFetchJob1 = new Testlib::AkonadiFakeItemFetchJob(this); | 184 | itemFetchJob1 = new Testlib::AkonadiFakeItemFetchJob(this); | ||
198 | itemFetchJob1->setItems(Akonadi::Item::List() << childItem); | 185 | itemFetchJob1->setItems(Akonadi::Item::List() << childItem); | ||
199 | itemFetchJob2 = new Testlib::AkonadiFakeItemFetchJob(this); | 186 | itemFetchJob2 = new Testlib::AkonadiFakeItemFetchJob(this); | ||
200 | itemFetchJob2->setExpectedError(KJob::KilledJobError); | 187 | itemFetchJob2->setExpectedError(KJob::KilledJobError); | ||
201 | QTest::newRow("parent job error with empty list (note)") << childItem << parentItem << childNote << parent << itemFetchJob1 << itemFetchJob2 << itemFetchJob3 << true << false << list; | | |||
202 | | ||||
203 | itemFetchJob1 = new Testlib::AkonadiFakeItemFetchJob(this); | | |||
204 | itemFetchJob1->setItems(Akonadi::Item::List() << childItem); | | |||
205 | itemFetchJob2 = new Testlib::AkonadiFakeItemFetchJob(this); | | |||
206 | itemFetchJob2->setExpectedError(KJob::KilledJobError); | | |||
207 | itemFetchJob2->setItems(Akonadi::Item::List() << parentItem); | 188 | itemFetchJob2->setItems(Akonadi::Item::List() << parentItem); | ||
208 | QTest::newRow("parent job error with item (task)") << childItem << parentItem << childTask << parent << itemFetchJob1 << itemFetchJob2 << itemFetchJob3 << true << false << list; | 189 | QTest::newRow("parent job error with item (task)") << childItem << parentItem << childTask << parent << itemFetchJob1 << itemFetchJob2 << itemFetchJob3 << true << false << list; | ||
209 | 190 | | |||
210 | itemFetchJob1 = new Testlib::AkonadiFakeItemFetchJob(this); | 191 | itemFetchJob1 = new Testlib::AkonadiFakeItemFetchJob(this); | ||
211 | itemFetchJob1->setItems(Akonadi::Item::List() << childItem); | 192 | itemFetchJob1->setItems(Akonadi::Item::List() << childItem); | ||
212 | itemFetchJob2 = new Testlib::AkonadiFakeItemFetchJob(this); | 193 | itemFetchJob2 = new Testlib::AkonadiFakeItemFetchJob(this); | ||
213 | itemFetchJob2->setExpectedError(KJob::KilledJobError); | | |||
214 | itemFetchJob2->setItems(Akonadi::Item::List() << parentItem); | | |||
215 | QTest::newRow("parent job error with item (note)") << childItem << parentItem << childNote << parent << itemFetchJob1 << itemFetchJob2 << itemFetchJob3 << true << false << list; | | |||
216 | | ||||
217 | itemFetchJob1 = new Testlib::AkonadiFakeItemFetchJob(this); | | |||
218 | itemFetchJob1->setItems(Akonadi::Item::List() << childItem); | | |||
219 | itemFetchJob2 = new Testlib::AkonadiFakeItemFetchJob(this); | | |||
220 | Akonadi::Collection col2(39); | 194 | Akonadi::Collection col2(39); | ||
221 | Akonadi::Item parentItem2(41); | 195 | Akonadi::Item parentItem2(41); | ||
222 | parentItem2.setParentCollection(col2); | 196 | parentItem2.setParentCollection(col2); | ||
223 | itemFetchJob2->setItems(Akonadi::Item::List() << parentItem2); | 197 | itemFetchJob2->setItems(Akonadi::Item::List() << parentItem2); | ||
224 | itemFetchJob3 = new Testlib::AkonadiFakeItemFetchJob(this); | 198 | itemFetchJob3 = new Testlib::AkonadiFakeItemFetchJob(this); | ||
225 | QTest::newRow("update and move item (task)") << childItem << parentItem2 << childTask << parent << itemFetchJob1 << itemFetchJob2 << itemFetchJob3 << true << true << list; | 199 | QTest::newRow("update and move item (task)") << childItem << parentItem2 << childTask << parent << itemFetchJob1 << itemFetchJob2 << itemFetchJob3 << true << true << list; | ||
226 | 200 | | |||
227 | itemFetchJob1 = new Testlib::AkonadiFakeItemFetchJob(this); | 201 | itemFetchJob1 = new Testlib::AkonadiFakeItemFetchJob(this); | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 214 | { | |||
276 | } else { | 250 | } else { | ||
277 | storageMock(&Akonadi::StorageInterface::updateItem).when(childItem, Q_NULLPTR) | 251 | storageMock(&Akonadi::StorageInterface::updateItem).when(childItem, Q_NULLPTR) | ||
278 | .thenReturn(itemModifyJob); | 252 | .thenReturn(itemModifyJob); | ||
279 | } | 253 | } | ||
280 | 254 | | |||
281 | // Serializer mock returning the item for the task | 255 | // Serializer mock returning the item for the task | ||
282 | Utils::MockObject<Akonadi::SerializerInterface> serializerMock; | 256 | Utils::MockObject<Akonadi::SerializerInterface> serializerMock; | ||
283 | serializerMock(&Akonadi::SerializerInterface::createItemFromTask).when(child.objectCast<Domain::Task>()).thenReturn(childItem); | 257 | serializerMock(&Akonadi::SerializerInterface::createItemFromTask).when(child.objectCast<Domain::Task>()).thenReturn(childItem); | ||
284 | serializerMock(&Akonadi::SerializerInterface::createItemFromNote).when(child.objectCast<Domain::Note>()).thenReturn(childItem); | | |||
285 | serializerMock(&Akonadi::SerializerInterface::createItemFromProject).when(parent).thenReturn(parentItem); | 258 | serializerMock(&Akonadi::SerializerInterface::createItemFromProject).when(parent).thenReturn(parentItem); | ||
286 | serializerMock(&Akonadi::SerializerInterface::updateItemProject).when(childItem, parent).thenReturn(); | 259 | serializerMock(&Akonadi::SerializerInterface::updateItemProject).when(childItem, parent).thenReturn(); | ||
287 | if (execParentJob) | 260 | if (execParentJob) | ||
288 | serializerMock(&Akonadi::SerializerInterface::filterDescendantItems).when(list, childItem).thenReturn(list); | 261 | serializerMock(&Akonadi::SerializerInterface::filterDescendantItems).when(list, childItem).thenReturn(list); | ||
289 | 262 | | |||
290 | // WHEN | 263 | // WHEN | ||
291 | QScopedPointer<Akonadi::ProjectRepository> repository(new Akonadi::ProjectRepository(storageMock.getInstance(), | 264 | QScopedPointer<Akonadi::ProjectRepository> repository(new Akonadi::ProjectRepository(storageMock.getInstance(), | ||
292 | serializerMock.getInstance())); | 265 | serializerMock.getInstance())); | ||
Show All 24 Lines | |||||
317 | void shouldDissociateAnArtifactFromItsProject_data() | 290 | void shouldDissociateAnArtifactFromItsProject_data() | ||
318 | { | 291 | { | ||
319 | QTest::addColumn<Domain::Artifact::Ptr>("child"); | 292 | QTest::addColumn<Domain::Artifact::Ptr>("child"); | ||
320 | QTest::addColumn<Akonadi::Item>("childItem"); | 293 | QTest::addColumn<Akonadi::Item>("childItem"); | ||
321 | QTest::addColumn<Testlib::AkonadiFakeItemFetchJob*>("itemFetchJob"); | 294 | QTest::addColumn<Testlib::AkonadiFakeItemFetchJob*>("itemFetchJob"); | ||
322 | QTest::addColumn<bool>("fetchJobFailed"); | 295 | QTest::addColumn<bool>("fetchJobFailed"); | ||
323 | 296 | | |||
324 | Domain::Artifact::Ptr taskChild(new Domain::Task); | 297 | Domain::Artifact::Ptr taskChild(new Domain::Task); | ||
325 | Domain::Artifact::Ptr noteChild(new Domain::Note); | | |||
326 | Akonadi::Item childItem(42); | 298 | Akonadi::Item childItem(42); | ||
327 | 299 | | |||
328 | auto itemFetchJob = new Testlib::AkonadiFakeItemFetchJob(this); | 300 | auto itemFetchJob = new Testlib::AkonadiFakeItemFetchJob(this); | ||
329 | itemFetchJob->setItems(Akonadi::Item::List() << childItem); | 301 | itemFetchJob->setItems(Akonadi::Item::List() << childItem); | ||
330 | QTest::newRow("task nominal case") << taskChild << childItem << itemFetchJob << false; | 302 | QTest::newRow("task nominal case") << taskChild << childItem << itemFetchJob << false; | ||
331 | 303 | | |||
332 | itemFetchJob = new Testlib::AkonadiFakeItemFetchJob(this); | 304 | itemFetchJob = new Testlib::AkonadiFakeItemFetchJob(this); | ||
333 | itemFetchJob->setExpectedError(KJob::KilledJobError); | 305 | itemFetchJob->setExpectedError(KJob::KilledJobError); | ||
334 | QTest::newRow("task job error with empty list") << taskChild << childItem << itemFetchJob << true; | 306 | QTest::newRow("task job error with empty list") << taskChild << childItem << itemFetchJob << true; | ||
335 | 307 | | |||
336 | itemFetchJob = new Testlib::AkonadiFakeItemFetchJob(this); | 308 | itemFetchJob = new Testlib::AkonadiFakeItemFetchJob(this); | ||
337 | itemFetchJob->setExpectedError(KJob::KilledJobError); | 309 | itemFetchJob->setExpectedError(KJob::KilledJobError); | ||
338 | itemFetchJob->setItems(Akonadi::Item::List() << childItem); | 310 | itemFetchJob->setItems(Akonadi::Item::List() << childItem); | ||
339 | QTest::newRow("task job error with item") << taskChild << childItem << itemFetchJob << true; | 311 | QTest::newRow("task job error with item") << taskChild << childItem << itemFetchJob << true; | ||
340 | | ||||
341 | itemFetchJob = new Testlib::AkonadiFakeItemFetchJob(this); | | |||
342 | itemFetchJob->setItems(Akonadi::Item::List() << childItem); | | |||
343 | QTest::newRow("note nominal case") << noteChild << childItem << itemFetchJob << false; | | |||
344 | | ||||
345 | itemFetchJob = new Testlib::AkonadiFakeItemFetchJob(this); | | |||
346 | itemFetchJob->setExpectedError(KJob::KilledJobError); | | |||
347 | QTest::newRow("note job error with empty list") << noteChild << childItem << itemFetchJob << true; | | |||
348 | | ||||
349 | itemFetchJob = new Testlib::AkonadiFakeItemFetchJob(this); | | |||
350 | itemFetchJob->setExpectedError(KJob::KilledJobError); | | |||
351 | itemFetchJob->setItems(Akonadi::Item::List() << childItem); | | |||
352 | QTest::newRow("note job error with item") << noteChild << childItem << itemFetchJob << true; | | |||
353 | } | 312 | } | ||
354 | 313 | | |||
355 | void shouldDissociateAnArtifactFromItsProject() | 314 | void shouldDissociateAnArtifactFromItsProject() | ||
356 | { | 315 | { | ||
357 | // GIVEN | 316 | // GIVEN | ||
358 | QFETCH(Domain::Artifact::Ptr, child); | 317 | QFETCH(Domain::Artifact::Ptr, child); | ||
359 | QFETCH(Akonadi::Item, childItem); | 318 | QFETCH(Akonadi::Item, childItem); | ||
360 | QFETCH(Testlib::AkonadiFakeItemFetchJob*, itemFetchJob); | 319 | QFETCH(Testlib::AkonadiFakeItemFetchJob*, itemFetchJob); | ||
361 | QFETCH(bool, fetchJobFailed); | 320 | QFETCH(bool, fetchJobFailed); | ||
362 | 321 | | |||
363 | auto itemModifyJob = new FakeJob(this); | 322 | auto itemModifyJob = new FakeJob(this); | ||
364 | 323 | | |||
365 | // Storage mock returning the delete job | 324 | // Storage mock returning the delete job | ||
366 | Utils::MockObject<Akonadi::StorageInterface> storageMock; | 325 | Utils::MockObject<Akonadi::StorageInterface> storageMock; | ||
367 | storageMock(&Akonadi::StorageInterface::updateItem).when(childItem, Q_NULLPTR) | 326 | storageMock(&Akonadi::StorageInterface::updateItem).when(childItem, Q_NULLPTR) | ||
368 | .thenReturn(itemModifyJob); | 327 | .thenReturn(itemModifyJob); | ||
369 | storageMock(&Akonadi::StorageInterface::fetchItem).when(childItem) | 328 | storageMock(&Akonadi::StorageInterface::fetchItem).when(childItem) | ||
370 | .thenReturn(itemFetchJob); | 329 | .thenReturn(itemFetchJob); | ||
371 | 330 | | |||
372 | // Serializer mock returning the item for the task | 331 | // Serializer mock returning the item for the task | ||
373 | Utils::MockObject<Akonadi::SerializerInterface> serializerMock; | 332 | Utils::MockObject<Akonadi::SerializerInterface> serializerMock; | ||
374 | if (child.objectCast<Domain::Task>()) | | |||
375 | serializerMock(&Akonadi::SerializerInterface::createItemFromTask).when(child.objectCast<Domain::Task>()).thenReturn(childItem); | 333 | serializerMock(&Akonadi::SerializerInterface::createItemFromTask).when(child.objectCast<Domain::Task>()).thenReturn(childItem); | ||
376 | else | | |||
377 | serializerMock(&Akonadi::SerializerInterface::createItemFromNote).when(child.objectCast<Domain::Note>()).thenReturn(childItem); | | |||
378 | serializerMock(&Akonadi::SerializerInterface::removeItemParent).when(childItem).thenReturn(); | 334 | serializerMock(&Akonadi::SerializerInterface::removeItemParent).when(childItem).thenReturn(); | ||
379 | 335 | | |||
380 | // WHEN | 336 | // WHEN | ||
381 | QScopedPointer<Akonadi::ProjectRepository> repository(new Akonadi::ProjectRepository(storageMock.getInstance(), | 337 | QScopedPointer<Akonadi::ProjectRepository> repository(new Akonadi::ProjectRepository(storageMock.getInstance(), | ||
382 | serializerMock.getInstance())); | 338 | serializerMock.getInstance())); | ||
383 | repository->dissociate(child)->exec(); | 339 | repository->dissociate(child)->exec(); | ||
384 | 340 | | |||
385 | // THEN | 341 | // THEN | ||
386 | if (child.objectCast<Domain::Task>()) | | |||
387 | QVERIFY(serializerMock(&Akonadi::SerializerInterface::createItemFromTask).when(child.objectCast<Domain::Task>()).exactly(1)); | 342 | QVERIFY(serializerMock(&Akonadi::SerializerInterface::createItemFromTask).when(child.objectCast<Domain::Task>()).exactly(1)); | ||
388 | else | | |||
389 | QVERIFY(serializerMock(&Akonadi::SerializerInterface::createItemFromNote).when(child.objectCast<Domain::Note>()).exactly(1)); | | |||
390 | 343 | | |||
391 | QVERIFY(storageMock(&Akonadi::StorageInterface::fetchItem).when(childItem).exactly(1)); | 344 | QVERIFY(storageMock(&Akonadi::StorageInterface::fetchItem).when(childItem).exactly(1)); | ||
392 | if (!fetchJobFailed) { | 345 | if (!fetchJobFailed) { | ||
393 | QVERIFY(serializerMock(&Akonadi::SerializerInterface::removeItemParent).when(childItem).exactly(1));; | 346 | QVERIFY(serializerMock(&Akonadi::SerializerInterface::removeItemParent).when(childItem).exactly(1));; | ||
394 | QVERIFY(storageMock(&Akonadi::StorageInterface::updateItem).when(childItem, Q_NULLPTR).exactly(1)); | 347 | QVERIFY(storageMock(&Akonadi::StorageInterface::updateItem).when(childItem, Q_NULLPTR).exactly(1)); | ||
395 | } | 348 | } | ||
396 | 349 | | |||
397 | // Give a chance to job to delete themselves | 350 | // Give a chance to job to delete themselves | ||
398 | // in case of an error (since they use deleteLater() internally) | 351 | // in case of an error (since they use deleteLater() internally) | ||
399 | QTest::qWait(10); | 352 | QTest::qWait(10); | ||
400 | } | 353 | } | ||
401 | }; | 354 | }; | ||
402 | 355 | | |||
403 | ZANSHIN_TEST_MAIN(AkonadiProjectRepositoryTest) | 356 | ZANSHIN_TEST_MAIN(AkonadiProjectRepositoryTest) | ||
404 | 357 | | |||
405 | #include "akonadiprojectrepositorytest.moc" | 358 | #include "akonadiprojectrepositorytest.moc" |