Changeset View
Changeset View
Standalone View
Standalone View
tests/units/akonadi/akonadiprojectrepositorytest.cpp
Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Line(s) | 78 | { | |||
---|---|---|---|---|---|
80 | 80 | | |||
81 | // A project and its corresponding item already existing in storage | 81 | // A project and its corresponding item already existing in storage | ||
82 | Akonadi::Item item(42); | 82 | Akonadi::Item item(42); | ||
83 | Domain::Project::Ptr project(new Domain::Project); | 83 | Domain::Project::Ptr project(new Domain::Project); | ||
84 | 84 | | |||
85 | // A mock modify job | 85 | // A mock modify job | ||
86 | auto itemModifyJob = new FakeJob(this); | 86 | auto itemModifyJob = new FakeJob(this); | ||
87 | 87 | | |||
88 | // Storage mock returning the create job | | |||
89 | Utils::MockObject<Akonadi::StorageInterface> storageMock; | 88 | Utils::MockObject<Akonadi::StorageInterface> storageMock; | ||
90 | storageMock(&Akonadi::StorageInterface::updateItem).when(item, nullptr) | 89 | Utils::MockObject<Akonadi::SerializerInterface> serializerMock; | ||
90 | QScopedPointer<Akonadi::ProjectRepository> repository(new Akonadi::ProjectRepository(storageMock.getInstance(), | ||||
91 | serializerMock.getInstance())); | ||||
92 | | ||||
93 | // Storage mock returning the create job | ||||
94 | storageMock(&Akonadi::StorageInterface::updateItem).when(item, repository.get()) | ||||
91 | .thenReturn(itemModifyJob); | 95 | .thenReturn(itemModifyJob); | ||
92 | 96 | | |||
93 | // Serializer mock returning the item for the project | 97 | // Serializer mock returning the item for the project | ||
94 | Utils::MockObject<Akonadi::SerializerInterface> serializerMock; | | |||
95 | serializerMock(&Akonadi::SerializerInterface::createItemFromProject).when(project).thenReturn(item); | 98 | serializerMock(&Akonadi::SerializerInterface::createItemFromProject).when(project).thenReturn(item); | ||
96 | 99 | | |||
97 | // WHEN | 100 | // WHEN | ||
98 | QScopedPointer<Akonadi::ProjectRepository> repository(new Akonadi::ProjectRepository(storageMock.getInstance(), | | |||
99 | serializerMock.getInstance())); | | |||
100 | repository->update(project)->exec(); | 101 | repository->update(project)->exec(); | ||
101 | 102 | | |||
102 | // THEN | 103 | // THEN | ||
103 | QVERIFY(serializerMock(&Akonadi::SerializerInterface::createItemFromProject).when(project).exactly(1)); | 104 | QVERIFY(serializerMock(&Akonadi::SerializerInterface::createItemFromProject).when(project).exactly(1)); | ||
104 | QVERIFY(storageMock(&Akonadi::StorageInterface::updateItem).when(item, nullptr).exactly(1)); | 105 | QVERIFY(storageMock(&Akonadi::StorageInterface::updateItem).when(item, repository.get()).exactly(1)); | ||
105 | } | 106 | } | ||
106 | 107 | | |||
107 | void shouldRemoveExistingProject() | 108 | void shouldRemoveExistingProject() | ||
108 | { | 109 | { | ||
109 | // GIVEN | 110 | // GIVEN | ||
110 | 111 | | |||
111 | // A project and its corresponding item already existing in storage | 112 | // A project and its corresponding item already existing in storage | ||
112 | Akonadi::Item item(42); | 113 | Akonadi::Item item(42); | ||
▲ Show 20 Lines • Show All 133 Lines • ▼ Show 20 Line(s) | 246 | if (parentItem.parentCollection().id() != childItem.parentCollection().id()) { | |||
246 | storageMock(&Akonadi::StorageInterface::fetchItems).when(childItem.parentCollection(), repository.get()) | 247 | storageMock(&Akonadi::StorageInterface::fetchItems).when(childItem.parentCollection(), repository.get()) | ||
247 | .thenReturn(itemFetchJob3); | 248 | .thenReturn(itemFetchJob3); | ||
248 | storageMock(&Akonadi::StorageInterface::createTransaction).when().thenReturn(transactionJob); | 249 | storageMock(&Akonadi::StorageInterface::createTransaction).when().thenReturn(transactionJob); | ||
249 | storageMock(&Akonadi::StorageInterface::updateItem).when(childItem, transactionJob) | 250 | storageMock(&Akonadi::StorageInterface::updateItem).when(childItem, transactionJob) | ||
250 | .thenReturn(itemModifyJob); | 251 | .thenReturn(itemModifyJob); | ||
251 | storageMock(&Akonadi::StorageInterface::moveItems).when(movedList, parentItem.parentCollection(), transactionJob) | 252 | storageMock(&Akonadi::StorageInterface::moveItems).when(movedList, parentItem.parentCollection(), transactionJob) | ||
252 | .thenReturn(itemsMoveJob); | 253 | .thenReturn(itemsMoveJob); | ||
253 | } else { | 254 | } else { | ||
254 | storageMock(&Akonadi::StorageInterface::updateItem).when(childItem, nullptr) | 255 | storageMock(&Akonadi::StorageInterface::updateItem).when(childItem, repository.get()) | ||
255 | .thenReturn(itemModifyJob); | 256 | .thenReturn(itemModifyJob); | ||
256 | } | 257 | } | ||
257 | 258 | | |||
258 | // Serializer mock returning the item for the task | 259 | // Serializer mock returning the item for the task | ||
259 | serializerMock(&Akonadi::SerializerInterface::createItemFromTask).when(child).thenReturn(childItem); | 260 | serializerMock(&Akonadi::SerializerInterface::createItemFromTask).when(child).thenReturn(childItem); | ||
260 | serializerMock(&Akonadi::SerializerInterface::createItemFromProject).when(parent).thenReturn(parentItem); | 261 | serializerMock(&Akonadi::SerializerInterface::createItemFromProject).when(parent).thenReturn(parentItem); | ||
261 | serializerMock(&Akonadi::SerializerInterface::updateItemProject).when(childItem, parent).thenReturn(); | 262 | serializerMock(&Akonadi::SerializerInterface::updateItemProject).when(childItem, parent).thenReturn(); | ||
262 | if (execParentJob) | 263 | if (execParentJob) | ||
Show All 12 Lines | 273 | if (execJob) { | |||
275 | QVERIFY(storageMock(&Akonadi::StorageInterface::fetchItem).when(parentItem, repository.get()).exactly(1)); | 276 | QVERIFY(storageMock(&Akonadi::StorageInterface::fetchItem).when(parentItem, repository.get()).exactly(1)); | ||
276 | if (execParentJob) { | 277 | if (execParentJob) { | ||
277 | if (parentItem.parentCollection().id() != childItem.parentCollection().id()) { | 278 | if (parentItem.parentCollection().id() != childItem.parentCollection().id()) { | ||
278 | QVERIFY(storageMock(&Akonadi::StorageInterface::fetchItems).when(childItem.parentCollection(), repository.get()).exactly(1)); | 279 | QVERIFY(storageMock(&Akonadi::StorageInterface::fetchItems).when(childItem.parentCollection(), repository.get()).exactly(1)); | ||
279 | QVERIFY(storageMock(&Akonadi::StorageInterface::createTransaction).when().thenReturn(transactionJob).exactly(1)); | 280 | QVERIFY(storageMock(&Akonadi::StorageInterface::createTransaction).when().thenReturn(transactionJob).exactly(1)); | ||
280 | QVERIFY(storageMock(&Akonadi::StorageInterface::updateItem).when(childItem, transactionJob).exactly(1)); | 281 | QVERIFY(storageMock(&Akonadi::StorageInterface::updateItem).when(childItem, transactionJob).exactly(1)); | ||
281 | QVERIFY(storageMock(&Akonadi::StorageInterface::moveItems).when(movedList, parentItem.parentCollection(), transactionJob).exactly(1)); | 282 | QVERIFY(storageMock(&Akonadi::StorageInterface::moveItems).when(movedList, parentItem.parentCollection(), transactionJob).exactly(1)); | ||
282 | } else { | 283 | } else { | ||
283 | QVERIFY(storageMock(&Akonadi::StorageInterface::updateItem).when(childItem, nullptr).exactly(1)); | 284 | QVERIFY(storageMock(&Akonadi::StorageInterface::updateItem).when(childItem, repository.get()).exactly(1)); | ||
284 | } | 285 | } | ||
285 | } | 286 | } | ||
286 | } | 287 | } | ||
287 | } | 288 | } | ||
288 | 289 | | |||
289 | void shouldDissociateATaskFromItsProject_data() | 290 | void shouldDissociateATaskFromItsProject_data() | ||
290 | { | 291 | { | ||
291 | QTest::addColumn<Domain::Task::Ptr>("child"); | 292 | QTest::addColumn<Domain::Task::Ptr>("child"); | ||
Show All 29 Lines | 315 | { | |||
321 | auto itemModifyJob = new FakeJob(this); | 322 | auto itemModifyJob = new FakeJob(this); | ||
322 | 323 | | |||
323 | Utils::MockObject<Akonadi::StorageInterface> storageMock; | 324 | Utils::MockObject<Akonadi::StorageInterface> storageMock; | ||
324 | Utils::MockObject<Akonadi::SerializerInterface> serializerMock; | 325 | Utils::MockObject<Akonadi::SerializerInterface> serializerMock; | ||
325 | QScopedPointer<Akonadi::ProjectRepository> repository(new Akonadi::ProjectRepository(storageMock.getInstance(), | 326 | QScopedPointer<Akonadi::ProjectRepository> repository(new Akonadi::ProjectRepository(storageMock.getInstance(), | ||
326 | serializerMock.getInstance())); | 327 | serializerMock.getInstance())); | ||
327 | 328 | | |||
328 | // Storage mock returning the delete job | 329 | // Storage mock returning the delete job | ||
329 | storageMock(&Akonadi::StorageInterface::updateItem).when(childItem, nullptr) | 330 | storageMock(&Akonadi::StorageInterface::updateItem).when(childItem, repository.get()) | ||
330 | .thenReturn(itemModifyJob); | 331 | .thenReturn(itemModifyJob); | ||
331 | storageMock(&Akonadi::StorageInterface::fetchItem).when(childItem, repository.get()) | 332 | storageMock(&Akonadi::StorageInterface::fetchItem).when(childItem, repository.get()) | ||
332 | .thenReturn(itemFetchJob); | 333 | .thenReturn(itemFetchJob); | ||
333 | 334 | | |||
334 | // Serializer mock returning the item for the task | 335 | // Serializer mock returning the item for the task | ||
335 | serializerMock(&Akonadi::SerializerInterface::createItemFromTask).when(child).thenReturn(childItem); | 336 | serializerMock(&Akonadi::SerializerInterface::createItemFromTask).when(child).thenReturn(childItem); | ||
336 | serializerMock(&Akonadi::SerializerInterface::removeItemParent).when(childItem).thenReturn(); | 337 | serializerMock(&Akonadi::SerializerInterface::removeItemParent).when(childItem).thenReturn(); | ||
337 | 338 | | |||
338 | // WHEN | 339 | // WHEN | ||
339 | repository->dissociate(child)->exec(); | 340 | repository->dissociate(child)->exec(); | ||
340 | 341 | | |||
341 | // THEN | 342 | // THEN | ||
342 | QVERIFY(serializerMock(&Akonadi::SerializerInterface::createItemFromTask).when(child).exactly(1)); | 343 | QVERIFY(serializerMock(&Akonadi::SerializerInterface::createItemFromTask).when(child).exactly(1)); | ||
343 | 344 | | |||
344 | QVERIFY(storageMock(&Akonadi::StorageInterface::fetchItem).when(childItem, repository.get()).exactly(1)); | 345 | QVERIFY(storageMock(&Akonadi::StorageInterface::fetchItem).when(childItem, repository.get()).exactly(1)); | ||
345 | if (!fetchJobFailed) { | 346 | if (!fetchJobFailed) { | ||
346 | QVERIFY(serializerMock(&Akonadi::SerializerInterface::removeItemParent).when(childItem).exactly(1));; | 347 | QVERIFY(serializerMock(&Akonadi::SerializerInterface::removeItemParent).when(childItem).exactly(1));; | ||
347 | QVERIFY(storageMock(&Akonadi::StorageInterface::updateItem).when(childItem, nullptr).exactly(1)); | 348 | QVERIFY(storageMock(&Akonadi::StorageInterface::updateItem).when(childItem, repository.get()).exactly(1)); | ||
348 | } | 349 | } | ||
349 | 350 | | |||
350 | // Give a chance to job to delete themselves | 351 | // Give a chance to job to delete themselves | ||
351 | // in case of an error (since they use deleteLater() internally) | 352 | // in case of an error (since they use deleteLater() internally) | ||
352 | QTest::qWait(10); | 353 | QTest::qWait(10); | ||
353 | } | 354 | } | ||
354 | }; | 355 | }; | ||
355 | 356 | | |||
356 | ZANSHIN_TEST_MAIN(AkonadiProjectRepositoryTest) | 357 | ZANSHIN_TEST_MAIN(AkonadiProjectRepositoryTest) | ||
357 | 358 | | |||
358 | #include "akonadiprojectrepositorytest.moc" | 359 | #include "akonadiprojectrepositorytest.moc" |