From 5830d7e0d1d35494823f5fa61a4871b8d9df1c9d Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 27 Sep 2016 16:15:44 +0200 Subject: Use the Query::filter api. --- tests/clientapitest.cpp | 2 +- tests/dummyresourcetest.cpp | 96 +++++++++++++++++----------------- tests/mailquerybenchmark.cpp | 31 ++++++----- tests/mailtest.cpp | 39 +++++++------- tests/mailthreadtest.cpp | 56 +++++++------------- tests/querytest.cpp | 119 ++++++++++++++++++++++--------------------- 6 files changed, 168 insertions(+), 175 deletions(-) (limited to 'tests') diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index b5405cf..44eb845 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp @@ -61,7 +61,7 @@ public: } SinkTrace() << "-------------------------."; for (const auto &res : results) { - qDebug() << "Parent filter " << query.propertyFilter.value("parent").value.toByteArray() << res->identifier() << res->getProperty("parent").toByteArray(); + qDebug() << "Parent filter " << query.getFilter("parent").value.toByteArray() << res->identifier() << res->getProperty("parent").toByteArray(); auto parentProperty = res->getProperty("parent").toByteArray(); if ((!parent && parentProperty.isEmpty()) || (parent && parentProperty == parent->identifier()) || query.parentProperty.isEmpty()) { qDebug() << "Found a hit" << res->identifier(); diff --git a/tests/dummyresourcetest.cpp b/tests/dummyresourcetest.cpp index 687a33b..a7a492c 100644 --- a/tests/dummyresourcetest.cpp +++ b/tests/dummyresourcetest.cpp @@ -14,6 +14,7 @@ #include "test.h" using namespace Sink; +using namespace Sink::ApplicationDomain; /** * Test of complete system using the dummy resource. @@ -32,7 +33,7 @@ private slots: Sink::Test::initTest(); auto factory = Sink::ResourceFactory::load("sink.dummy"); QVERIFY(factory); - DummyResource::removeFromDisk("sink.dummy.instance1"); + ::DummyResource::removeFromDisk("sink.dummy.instance1"); ResourceConfig::addResource("sink.dummy.instance1", "sink.dummy"); } @@ -52,49 +53,49 @@ private slots: void testProperty() { - Sink::ApplicationDomain::Event event; + Event event; event.setProperty("uid", "testuid"); QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); } void testWriteToFacadeAndQueryByUid() { - Sink::ApplicationDomain::Event event("sink.dummy.instance1"); + Event event("sink.dummy.instance1"); event.setProperty("uid", "testuid"); QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); event.setProperty("summary", "summaryValue"); - Sink::Store::create(event).exec().waitForFinished(); + Sink::Store::create(event).exec().waitForFinished(); - const auto query = Query::ResourceFilter("sink.dummy.instance1") ; + auto query = Query::ResourceFilter("sink.dummy.instance1") ; // Ensure all local data is processed Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - auto model = Sink::Store::loadModel(query + Query::PropertyFilter("uid", "testuid")); + auto model = Sink::Store::loadModel(query.filter("testuid")); QTRY_COMPARE(model->rowCount(QModelIndex()), 1); - auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); } void testWriteToFacadeAndQueryByUid2() { - Sink::ApplicationDomain::Event event("sink.dummy.instance1"); + Event event("sink.dummy.instance1"); event.setProperty("summary", "summaryValue"); event.setProperty("uid", "testuid"); - Sink::Store::create(event).exec().waitForFinished(); + Sink::Store::create(event).exec().waitForFinished(); event.setProperty("uid", "testuid2"); - Sink::Store::create(event).exec().waitForFinished(); + Sink::Store::create(event).exec().waitForFinished(); - const auto query = Query::ResourceFilter("sink.dummy.instance1") ; + auto query = Query::ResourceFilter("sink.dummy.instance1") ; // Ensure all local data is processed Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - auto model = Sink::Store::loadModel(query + Query::PropertyFilter("uid", "testuid")); + auto model = Sink::Store::loadModel(query.filter("testuid")); QTRY_COMPARE(model->rowCount(QModelIndex()), 1); - auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); qDebug() << value->getProperty("uid").toByteArray(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); @@ -102,24 +103,24 @@ private slots: void testWriteToFacadeAndQueryBySummary() { - Sink::ApplicationDomain::Event event("sink.dummy.instance1"); + Event event("sink.dummy.instance1"); event.setProperty("uid", "testuid"); event.setProperty("summary", "summaryValue1"); - Sink::Store::create(event).exec().waitForFinished(); + Sink::Store::create(event).exec().waitForFinished(); event.setProperty("uid", "testuid2"); event.setProperty("summary", "summaryValue2"); - Sink::Store::create(event).exec().waitForFinished(); + Sink::Store::create(event).exec().waitForFinished(); - const auto query = Query::ResourceFilter("sink.dummy.instance1") ; + auto query = Query::ResourceFilter("sink.dummy.instance1") ; // Ensure all local data is processed Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - auto model = Sink::Store::loadModel(query + Query::PropertyFilter("summary", "summaryValue2")); + auto model = Sink::Store::loadModel(query.filter("summaryValue2")); QTRY_COMPARE(model->rowCount(QModelIndex()), 1); - auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); qDebug() << value->getProperty("uid").toByteArray(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid2")); @@ -128,7 +129,7 @@ private slots: void testResourceSync() { auto pipeline = QSharedPointer::create("sink.dummy.instance1"); - DummyResource resource("sink.dummy.instance1", pipeline); + ::DummyResource resource("sink.dummy.instance1", pipeline); auto job = resource.synchronizeWithSource(); // TODO pass in optional timeout? auto future = job.exec(); @@ -148,9 +149,9 @@ private slots: Sink::Store::synchronize(query).exec().waitForFinished(); Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - auto model = Sink::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->rowCount(QModelIndex()) >= 1); - auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); QVERIFY(!value->getProperty("summary").toString().isEmpty()); qDebug() << value->getProperty("summary").toString(); @@ -158,39 +159,40 @@ private slots: void testSyncAndFacadeMail() { - const auto query = Query::ResourceFilter("sink.dummy.instance1"); + auto query = Query::ResourceFilter("sink.dummy.instance1"); + query.request(); // Ensure all local data is processed Sink::Store::synchronize(query).exec().waitForFinished(); Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - auto model = Sink::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->rowCount(QModelIndex()) >= 1); - auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); - QVERIFY(!value->getProperty("subject").toString().isEmpty()); - qDebug() << value->getProperty("subject").toString(); + qWarning() << value->getSubject() << value->identifier(); + QVERIFY(!value->getSubject().isEmpty()); } void testWriteModifyDelete() { - Sink::ApplicationDomain::Event event("sink.dummy.instance1"); + Event event("sink.dummy.instance1"); event.setProperty("uid", "testuid"); QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); event.setProperty("summary", "summaryValue"); - Sink::Store::create(event).exec().waitForFinished(); + Sink::Store::create(event).exec().waitForFinished(); - const auto query = Query::ResourceFilter("sink.dummy.instance1") + Query::PropertyFilter("uid", "testuid"); + auto query = Query::ResourceFilter("sink.dummy.instance1").filter("testuid"); // Ensure all local data is processed Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); // Test create - Sink::ApplicationDomain::Event event2; + Event event2; { - auto model = Sink::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_COMPARE(model->rowCount(QModelIndex()), 1); - auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue")); @@ -199,29 +201,29 @@ private slots: event2.setProperty("uid", "testuid"); event2.setProperty("summary", "summaryValue2"); - Sink::Store::modify(event2).exec().waitForFinished(); + Sink::Store::modify(event2).exec().waitForFinished(); // Ensure all local data is processed Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); // Test modify { - auto model = Sink::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_COMPARE(model->rowCount(QModelIndex()), 1); - auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue2")); } - Sink::Store::remove(event2).exec().waitForFinished(); + Sink::Store::remove(event2).exec().waitForFinished(); // Ensure all local data is processed Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); // Test remove { - auto model = Sink::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QTRY_COMPARE(model->rowCount(QModelIndex()), 0); } @@ -231,22 +233,22 @@ private slots: { auto query = Query::ResourceFilter("sink.dummy.instance1"); query.liveQuery = true; - query += Query::PropertyFilter("uid", "testuid"); + query.filter("testuid"); - auto model = Sink::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); - Sink::ApplicationDomain::Event event("sink.dummy.instance1"); + Event event("sink.dummy.instance1"); event.setProperty("uid", "testuid"); QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); event.setProperty("summary", "summaryValue"); - Sink::Store::create(event).exec().waitForFinished(); + Sink::Store::create(event).exec().waitForFinished(); // Test create - Sink::ApplicationDomain::Event event2; + Event event2; { QTRY_COMPARE(model->rowCount(QModelIndex()), 1); - auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue")); event2 = *value; @@ -254,18 +256,18 @@ private slots: event2.setProperty("uid", "testuid"); event2.setProperty("summary", "summaryValue2"); - Sink::Store::modify(event2).exec().waitForFinished(); + Sink::Store::modify(event2).exec().waitForFinished(); // Test modify { // TODO wait for a change signal QTRY_COMPARE(model->rowCount(QModelIndex()), 1); - auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue2")); } - Sink::Store::remove(event2).exec().waitForFinished(); + Sink::Store::remove(event2).exec().waitForFinished(); // Test remove { diff --git a/tests/mailquerybenchmark.cpp b/tests/mailquerybenchmark.cpp index 450955f..1d96819 100644 --- a/tests/mailquerybenchmark.cpp +++ b/tests/mailquerybenchmark.cpp @@ -45,6 +45,9 @@ #include "createentity_generated.h" #include "getrssusage.h" +using namespace Sink; +using namespace Sink::ApplicationDomain; + /** * Benchmark mail query performance. */ @@ -62,7 +65,7 @@ class MailQueryBenchmark : public QObject auto pipeline = QSharedPointer::create(resourceIdentifier); pipeline->setResourceType("test"); - auto indexer = QSharedPointer>::create(); + auto indexer = QSharedPointer>::create(); pipeline->setPreprocessors("mail", QVector() << indexer.data()); @@ -71,13 +74,13 @@ class MailQueryBenchmark : public QObject pipeline->startTransaction(); const auto date = QDateTime::currentDateTimeUtc(); for (int i = 0; i < count; i++) { - auto domainObject = Sink::ApplicationDomain::Mail::Ptr::create(); + auto domainObject = Mail::Ptr::create(); domainObject->setProperty("uid", "uid"); domainObject->setProperty("subject", QString("subject%1").arg(i)); domainObject->setProperty("date", date.addSecs(count)); domainObject->setProperty("folder", "folder1"); // domainObject->setProperty("attachment", attachment); - const auto command = createCommand(*domainObject, *domainTypeAdaptorFactory); + const auto command = createCommand(*domainObject, *domainTypeAdaptorFactory); pipeline->newEntity(command.data(), command.size()); } pipeline->commit(); @@ -92,18 +95,18 @@ class MailQueryBenchmark : public QObject QTime time; time.start(); - auto resultSet = QSharedPointer>::create(); + auto resultSet = QSharedPointer>::create(); auto resourceAccess = QSharedPointer::create(); TestMailResourceFacade facade(resourceIdentifier, resourceAccess); auto ret = facade.load(query); ret.first.exec().waitForFinished(); auto emitter = ret.second; - QList list; - emitter->onAdded([&list](const Sink::ApplicationDomain::Mail::Ptr &mail) { list << mail; }); + QList list; + emitter->onAdded([&list](const Mail::Ptr &mail) { list << mail; }); bool done = false; - emitter->onInitialResultSetComplete([&done](const Sink::ApplicationDomain::Mail::Ptr &mail) { done = true; }); - emitter->fetch(Sink::ApplicationDomain::Mail::Ptr()); + emitter->onInitialResultSetComplete([&done](const Mail::Ptr &mail) { done = true; }); + emitter->fetch(Mail::Ptr()); QTRY_VERIFY(done); QCOMPARE(list.size(), query.limit); @@ -149,18 +152,18 @@ private slots: void init() { resourceIdentifier = "sink.test.instance1"; - Sink::AdaptorFactoryRegistry::instance().registerFactory("test"); + Sink::AdaptorFactoryRegistry::instance().registerFactory("test"); } void test50k() { Sink::Query query; query.liveQuery = false; - query.requestedProperties << "uid" - << "subject" - << "date"; - query.sortProperty = "date"; - query += Sink::Query::PropertyFilter("folder", "folder1"); + query.request() + .request() + .request(); + query.sort(); + query.filter("folder1"); query.limit = 1000; populateDatabase(50000); diff --git a/tests/mailtest.cpp b/tests/mailtest.cpp index 925fb70..ed145d4 100644 --- a/tests/mailtest.cpp +++ b/tests/mailtest.cpp @@ -39,12 +39,13 @@ void MailTest::initTestCase() QVERIFY(isBackendAvailable()); resetTestEnvironment(); auto resource = createResource(); + QVERIFY(!resource.getResourceType().isEmpty()); QVERIFY(!resource.identifier().isEmpty()); VERIFYEXEC(Store::create(resource)); mResourceInstanceIdentifier = resource.identifier(); - mCapabilities = resource.getProperty("capabilities").value(); + mCapabilities = resource.getCapabilities(); } void MailTest::cleanup() @@ -82,7 +83,7 @@ void MailTest::testCreateModifyDeleteFolder() VERIFYEXEC(Store::create(folder)); VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); { - auto job = Store::fetchAll(Query::RequestedProperties(QByteArrayList() << Folder::Name::name << Folder::Icon::name)) + auto job = Store::fetchAll(Query().request().request()) .syncThen>([=](const QList &folders) { QCOMPARE(folders.size(), baseCount + 1); QHash foldersByName; @@ -108,7 +109,7 @@ void MailTest::testCreateModifyDeleteFolder() VERIFYEXEC(Store::modify(folder)); VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); { - auto job = Store::fetchAll(Query::RequestedProperties(QByteArrayList() << Folder::Name::name << Folder::Icon::name)) + auto job = Store::fetchAll(Query().request().request()) .syncThen>([=](const QList &folders) { QCOMPARE(folders.size(), baseCount + 1); QHash foldersByName; @@ -129,7 +130,7 @@ void MailTest::testCreateModifyDeleteFolder() VERIFYEXEC(Store::remove(folder)); VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); { - auto job = Store::fetchAll(Query::RequestedProperties(QByteArrayList() << Folder::Name::name << Folder::Icon::name)) + auto job = Store::fetchAll(Query().request().request()) .syncThen>([=](const QList &folders) { QCOMPARE(folders.size(), baseCount); }); @@ -159,7 +160,7 @@ void MailTest::testCreateModifyDeleteMail() VERIFYEXEC(Store::create(mail)); VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); { - auto job = Store::fetchAll(Query::RequestedProperties(QByteArrayList() << Mail::Folder::name << Mail::Subject::name << Mail::MimeMessage::name)) + auto job = Store::fetchAll(Query().request().request().request()) .syncThen>([=](const QList &mails) { QCOMPARE(mails.size(), 1); auto mail = *mails.first(); @@ -188,7 +189,7 @@ void MailTest::testCreateModifyDeleteMail() VERIFYEXEC(Store::modify(mail)); VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); { - auto job = Store::fetchAll(Query::RequestedProperties(QByteArrayList() << Mail::Folder::name << Mail::Subject::name << Mail::MimeMessage::name)) + auto job = Store::fetchAll(Query().request().request().request()) .syncThen>([=](const QList &mails) { QCOMPARE(mails.size(), 1); auto mail = *mails.first(); @@ -210,7 +211,7 @@ void MailTest::testCreateModifyDeleteMail() VERIFYEXEC(Store::remove(mail)); VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); { - auto job = Store::fetchAll(Query::RequestedProperties(QByteArrayList() << Mail::Folder::name << Mail::Subject::name)) + auto job = Store::fetchAll(Query().request().request()) .syncThen>([=](const QList &mails) { QCOMPARE(mails.size(), 0); }); @@ -246,7 +247,7 @@ void MailTest::testMoveMail() Mail modifiedMail; { - auto job = Store::fetchAll(Query::RequestedProperties(QByteArrayList() << Mail::Folder::name << Mail::Subject::name << Mail::MimeMessage::name)) + auto job = Store::fetchAll(Query().request().request().request()) .syncThen>([=, &modifiedMail](const QList &mails) { QCOMPARE(mails.size(), 1); auto mail = *mails.first(); @@ -265,7 +266,7 @@ void MailTest::testMoveMail() VERIFYEXEC(Store::modify(modifiedMail)); VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); { - auto job = Store::fetchAll(Query::RequestedProperties(QByteArrayList() << Mail::Folder::name << Mail::Subject::name << Mail::MimeMessage::name)) + auto job = Store::fetchAll(Query().request().request().request()) .syncThen>([=](const QList &mails) { QCOMPARE(mails.size(), 1); auto mail = *mails.first(); @@ -296,9 +297,11 @@ void MailTest::testMarkMailAsRead() VERIFYEXEC(Store::create(mail)); VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); - auto job = Store::fetchAll(Query::ResourceFilter(mResourceInstanceIdentifier) + - Query::RequestedProperties(QByteArrayList() << Mail::Folder::name - << Mail::Subject::name)) + auto job = Store::fetchAll(Query() + .filter(SinkResource(mResourceInstanceIdentifier)) + .request() + .request() + ) .then>([this](const QList &mails) { ASYNCCOMPARE(mails.size(), 1); auto mail = mails.first(); @@ -311,11 +314,13 @@ void MailTest::testMarkMailAsRead() VERIFYEXEC(job); // Verify that we can still query for all relevant information - auto job2 = Store::fetchAll( - Query::ResourceFilter(mResourceInstanceIdentifier) + Query::RequestedProperties(QByteArrayList() << Mail::Folder::name - << Mail::Subject::name - << Mail::MimeMessage::name - << Mail::Unread::name)) + auto job2 = Store::fetchAll(Query() + .filter(SinkResource(mResourceInstanceIdentifier)) + .request() + .request() + .request() + .request() + ) .then>([](const QList &mails) { ASYNCCOMPARE(mails.size(), 1); auto mail = mails.first(); diff --git a/tests/mailthreadtest.cpp b/tests/mailthreadtest.cpp index e9fe499..6ba54df 100644 --- a/tests/mailthreadtest.cpp +++ b/tests/mailthreadtest.cpp @@ -75,11 +75,9 @@ void MailThreadTest::testListThreadLeader() VERIFYEXEC(Store::synchronize(query)); ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - auto job = Store::fetchAll(query).syncThen>([](const QList &mails) { - QCOMPARE(mails.size(), 1); - QVERIFY(mails.first()->getSubject().startsWith(QString("ThreadLeader"))); - }); - VERIFYEXEC(job); + auto mails = Store::read(query); + QCOMPARE(mails.size(), 1); + QVERIFY(mails.first().getSubject().startsWith(QString("ThreadLeader"))); } /* @@ -126,25 +124,19 @@ void MailThreadTest::testIndexInMixedOrder() } VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); - Sink::Query query; + auto query = Sink::Query::threadLeaders(folder); query.filter(SinkResource(mResourceInstanceIdentifier)); query.request().request().request().request(); - query.filter(folder); - query.sort(); - query.reduce(Query::Reduce::Selector::max()); Mail threadLeader; //Ensure we find the thread leader { - auto job = Store::fetchAll(query) - .syncThen>([=, &threadLeader](const QList &mails) { - QCOMPARE(mails.size(), 1); - auto mail = *mails.first(); - threadLeader = mail; - QCOMPARE(mail.getSubject(), QString::fromLatin1("Re: Re: 1")); - }); - VERIFYEXEC(job); + auto mails = Store::read(query); + QCOMPARE(mails.size(), 1); + auto mail = mails.first(); + threadLeader = mail; + QCOMPARE(mail.getSubject(), QString::fromLatin1("Re: Re: 1")); } { @@ -157,13 +149,10 @@ void MailThreadTest::testIndexInMixedOrder() //Ensure we find the thread leader still { - auto job = Store::fetchAll(query) - .syncThen>([=](const QList &mails) { - QCOMPARE(mails.size(), 1); - auto mail = *mails.first(); - QCOMPARE(mail.getSubject(), QString::fromLatin1("Re: Re: 1")); - }); - VERIFYEXEC(job); + auto mails = Store::read(query); + QCOMPARE(mails.size(), 1); + auto mail = mails.first(); + QCOMPARE(mail.getSubject(), QString::fromLatin1("Re: Re: 1")); } { @@ -176,20 +165,13 @@ void MailThreadTest::testIndexInMixedOrder() //Ensure the thread is complete { - Sink::Query query; - query.filter(SinkResource(mResourceInstanceIdentifier)); - query.ids << threadLeader.identifier(); + auto query = Sink::Query::completeThread(threadLeader); query.request().request().request().request(); - query.sort(); - query.bloom(); - - auto job = Store::fetchAll(query) - .syncThen>([=](const QList &mails) { - QCOMPARE(mails.size(), 3); - auto mail = *mails.first(); - QCOMPARE(mail.getSubject(), QString::fromLatin1("Re: Re: 1")); - }); - VERIFYEXEC(job); + + auto mails = Store::read(query); + QCOMPARE(mails.size(), 3); + auto mail = mails.first(); + QCOMPARE(mail.getSubject(), QString::fromLatin1("Re: Re: 1")); } /* VERIFYEXEC(Store::remove(mail)); */ diff --git a/tests/querytest.cpp b/tests/querytest.cpp index ab2a7e5..be1e0f6 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp @@ -12,6 +12,7 @@ #include "test.h" #include "testutils.h" +using namespace Sink; using namespace Sink::ApplicationDomain; /** @@ -52,7 +53,7 @@ private slots: query.liveQuery = true; // We fetch before the data is available and rely on the live query mechanism to deliver the actual data - auto model = Sink::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(), 0); } @@ -62,8 +63,8 @@ private slots: { // Setup { - Sink::ApplicationDomain::Mail mail("sink.dummy.instance1"); - Sink::Store::create(mail).exec().waitForFinished(); + Mail mail("sink.dummy.instance1"); + Sink::Store::create(mail).exec().waitForFinished(); } // Test @@ -72,7 +73,7 @@ private slots: query.liveQuery = true; // We fetch before the data is available and rely on the live query mechanism to deliver the actual data - auto model = Sink::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_COMPARE(model->rowCount(), 1); } @@ -80,8 +81,8 @@ private slots: { // Setup { - Sink::ApplicationDomain::Mail mail("sink.dummy.instance1"); - Sink::Store::create(mail).exec().waitForFinished(); + Mail mail("sink.dummy.instance1"); + Sink::Store::create(mail).exec().waitForFinished(); } // Test @@ -93,7 +94,7 @@ private slots: Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); // We fetch after the data is available and don't rely on the live query mechanism to deliver the actual data - auto model = Sink::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(), 1); @@ -125,7 +126,7 @@ private slots: auto model = Sink::Store::loadModel(query); QTRY_COMPARE(model->rowCount(), 1); - auto mail = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); + auto mail = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); { mail->setFolder("folder2"); Sink::Store::modify(*mail).exec().waitForFinished(); @@ -144,9 +145,9 @@ private slots: QByteArray id; // Setup { - Sink::ApplicationDomain::Mail mail("sink.dummy.instance1"); - Sink::Store::create(mail).exec().waitForFinished(); - Sink::Store::create(mail).exec().waitForFinished(); + Mail mail("sink.dummy.instance1"); + Sink::Store::create(mail).exec().waitForFinished(); + Sink::Store::create(mail).exec().waitForFinished(); Sink::Query query; query.resources << "sink.dummy.instance1"; @@ -155,17 +156,17 @@ private slots: Sink::Store::synchronize(query).exec().waitForFinished(); // We fetch before the data is available and rely on the live query mechanism to deliver the actual data - auto model = Sink::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QVERIFY(model->rowCount() >= 1); - id = model->index(0, 0).data(Sink::Store::DomainObjectRole).value()->identifier(); + id = model->index(0, 0).data(Sink::Store::DomainObjectRole).value()->identifier(); } // Test Sink::Query query; query.resources << "sink.dummy.instance1"; query.ids << id; - auto model = Sink::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(), 1); } @@ -174,8 +175,8 @@ private slots: { // Setup { - Sink::ApplicationDomain::Folder folder("sink.dummy.instance1"); - Sink::Store::create(folder).exec().waitForFinished(); + Folder folder("sink.dummy.instance1"); + Sink::Store::create(folder).exec().waitForFinished(); } // Test @@ -184,9 +185,9 @@ private slots: query.liveQuery = true; // We fetch before the data is available and rely on the live query mechanism to deliver the actual data - auto model = Sink::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_COMPARE(model->rowCount(), 1); - auto folderEntity = model->index(0, 0).data(Sink::Store::DomainObjectRole).value(); + auto folderEntity = model->index(0, 0).data(Sink::Store::DomainObjectRole).value(); QVERIFY(!folderEntity->identifier().isEmpty()); } @@ -194,8 +195,8 @@ private slots: { // Setup { - Sink::ApplicationDomain::Folder folder("sink.dummy.instance1"); - Sink::Store::create(folder).exec().waitForFinished(); + Folder folder("sink.dummy.instance1"); + Sink::Store::create(folder).exec().waitForFinished(); Sink::Query query; query.resources << "sink.dummy.instance1"; @@ -203,16 +204,16 @@ private slots: // Ensure all local data is processed Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - auto model = Sink::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(), 1); - auto folderEntity = model->index(0, 0).data(Sink::Store::DomainObjectRole).value(); + auto folderEntity = model->index(0, 0).data(Sink::Store::DomainObjectRole).value(); QVERIFY(!folderEntity->identifier().isEmpty()); - Sink::ApplicationDomain::Folder subfolder("sink.dummy.instance1"); + Folder subfolder("sink.dummy.instance1"); subfolder.setProperty("parent", folderEntity->identifier()); - Sink::Store::create(subfolder).exec().waitForFinished(); + Sink::Store::create(subfolder).exec().waitForFinished(); } // Test @@ -224,7 +225,7 @@ private slots: Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); // We fetch after the data is available and don't rely on the live query mechanism to deliver the actual data - auto model = Sink::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(), 1); model->fetchMore(model->index(0, 0)); @@ -236,30 +237,30 @@ private slots: { // Setup { - Sink::ApplicationDomain::Mail mail("sink.dummy.instance1"); + Mail mail("sink.dummy.instance1"); mail.setProperty("uid", "test1"); mail.setProperty("sender", "doe@example.org"); - Sink::Store::create(mail).exec().waitForFinished(); + Sink::Store::create(mail).exec().waitForFinished(); } { - Sink::ApplicationDomain::Mail mail("sink.dummy.instance1"); + Mail mail("sink.dummy.instance1"); mail.setProperty("uid", "test2"); mail.setProperty("sender", "doe@example.org"); - Sink::Store::create(mail).exec().waitForFinished(); + Sink::Store::create(mail).exec().waitForFinished(); } // Test Sink::Query query; query.resources << "sink.dummy.instance1"; query.liveQuery = false; - query += Sink::Query::PropertyFilter("uid", "test1"); + query.filter("test1"); // Ensure all local data is processed Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); // We fetch before the data is available and rely on the live query mechanism to deliver the actual data - auto model = Sink::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(), 1); } @@ -267,10 +268,10 @@ private slots: void testMailByFolder() { // Setup - Sink::ApplicationDomain::Folder::Ptr folderEntity; + Folder::Ptr folderEntity; { - Sink::ApplicationDomain::Folder folder("sink.dummy.instance1"); - Sink::Store::create(folder).exec().waitForFinished(); + Folder folder("sink.dummy.instance1"); + Sink::Store::create(folder).exec().waitForFinished(); Sink::Query query; query.resources << "sink.dummy.instance1"; @@ -278,29 +279,29 @@ private slots: // Ensure all local data is processed Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - auto model = Sink::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(), 1); - folderEntity = model->index(0, 0).data(Sink::Store::DomainObjectRole).value(); + folderEntity = model->index(0, 0).data(Sink::Store::DomainObjectRole).value(); QVERIFY(!folderEntity->identifier().isEmpty()); - Sink::ApplicationDomain::Mail mail("sink.dummy.instance1"); + Mail mail("sink.dummy.instance1"); mail.setProperty("uid", "test1"); mail.setProperty("folder", folderEntity->identifier()); - Sink::Store::create(mail).exec().waitForFinished(); + Sink::Store::create(mail).exec().waitForFinished(); } // Test Sink::Query query; query.resources << "sink.dummy.instance1"; - query += Sink::Query::PropertyFilter("folder", *folderEntity); + query.filter(*folderEntity); // Ensure all local data is processed Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); // We fetch before the data is available and rely on the live query mechanism to deliver the actual data - auto model = Sink::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(), 1); } @@ -363,10 +364,10 @@ private slots: void testMailByFolderSortedByDate() { // Setup - Sink::ApplicationDomain::Folder::Ptr folderEntity; + Folder::Ptr folderEntity; { - Sink::ApplicationDomain::Folder folder("sink.dummy.instance1"); - Sink::Store::create(folder).exec().waitForFinished(); + Folder folder("sink.dummy.instance1"); + Sink::Store::create(folder).exec().waitForFinished(); Sink::Query query; query.resources << "sink.dummy.instance1"; @@ -374,71 +375,71 @@ private slots: // Ensure all local data is processed Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - auto model = Sink::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(), 1); - folderEntity = model->index(0, 0).data(Sink::Store::DomainObjectRole).value(); + folderEntity = model->index(0, 0).data(Sink::Store::DomainObjectRole).value(); QVERIFY(!folderEntity->identifier().isEmpty()); const auto date = QDateTime(QDate(2015, 7, 7), QTime(12, 0)); { - Sink::ApplicationDomain::Mail mail("sink.dummy.instance1"); + Mail mail("sink.dummy.instance1"); mail.setProperty("uid", "testSecond"); mail.setProperty("folder", folderEntity->identifier()); mail.setProperty("date", date.addDays(-1)); - Sink::Store::create(mail).exec().waitForFinished(); + Sink::Store::create(mail).exec().waitForFinished(); } { - Sink::ApplicationDomain::Mail mail("sink.dummy.instance1"); + Mail mail("sink.dummy.instance1"); mail.setProperty("uid", "testLatest"); mail.setProperty("folder", folderEntity->identifier()); mail.setProperty("date", date); - Sink::Store::create(mail).exec().waitForFinished(); + Sink::Store::create(mail).exec().waitForFinished(); } { - Sink::ApplicationDomain::Mail mail("sink.dummy.instance1"); + Mail mail("sink.dummy.instance1"); mail.setProperty("uid", "testLast"); mail.setProperty("folder", folderEntity->identifier()); mail.setProperty("date", date.addDays(-2)); - Sink::Store::create(mail).exec().waitForFinished(); + Sink::Store::create(mail).exec().waitForFinished(); } } // Test Sink::Query query; query.resources << "sink.dummy.instance1"; - query += Sink::Query::PropertyFilter("folder", *folderEntity); - query.sortProperty = "date"; + query.filter(*folderEntity); + query.sort(); query.limit = 1; query.liveQuery = false; // Ensure all local data is processed Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - auto model = Sink::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); // The model is not sorted, but the limited set is sorted, so we can only test for the latest result. QCOMPARE(model->rowCount(), 1); - QCOMPARE(model->index(0, 0).data(Sink::Store::DomainObjectRole).value()->getProperty("uid").toByteArray(), QByteArray("testLatest")); + QCOMPARE(model->index(0, 0).data(Sink::Store::DomainObjectRole).value()->getProperty("uid").toByteArray(), QByteArray("testLatest")); model->fetchMore(QModelIndex()); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(), 2); // We can't make any assumptions about the order of the indexes - // QCOMPARE(model->index(1, 0).data(Sink::Store::DomainObjectRole).value()->getProperty("uid").toByteArray(), QByteArray("testSecond")); + // QCOMPARE(model->index(1, 0).data(Sink::Store::DomainObjectRole).value()->getProperty("uid").toByteArray(), QByteArray("testSecond")); } void testReactToNewResource() { Sink::Query query; query.liveQuery = true; - auto model = Sink::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_COMPARE(model->rowCount(QModelIndex()), 0); - auto res = Sink::ApplicationDomain::DummyResource::create(""); + auto res = DummyResource::create(""); VERIFYEXEC(Sink::Store::create(res)); - auto folder = Sink::ApplicationDomain::Folder::create(res.identifier()); + auto folder = Folder::create(res.identifier()); VERIFYEXEC(Sink::Store::create(folder)); QTRY_COMPARE(model->rowCount(QModelIndex()), 1); -- cgit v1.2.3