From dd240d06dc35c50239dec91dcf043f8d4c990953 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 15 Mar 2016 16:51:55 +0100 Subject: Fixed and tested maildirsettings. --- accounts/maildir/maildirsettings.cpp | 49 ++++++++++++++++++++------------- accounts/maildir/tests/settingstest.cpp | 42 ++++++++++++++++++++++------ 2 files changed, 64 insertions(+), 27 deletions(-) diff --git a/accounts/maildir/maildirsettings.cpp b/accounts/maildir/maildirsettings.cpp index c8b892d7..1d48fc24 100644 --- a/accounts/maildir/maildirsettings.cpp +++ b/accounts/maildir/maildirsettings.cpp @@ -105,7 +105,10 @@ void MaildirSettings::save() if (!mIdentifier.isEmpty()) { Sink::ApplicationDomain::SinkResource resource(mIdentifier); resource.setProperty("path", mPath); - Sink::Store::modify(resource).exec(); + Sink::Store::modify(resource).then([](){}, [](int errorCode, const QString &errorMessage) { + qWarning() << "Error while modifying resource: " << errorMessage; + }) + .exec(); } else { const auto resourceIdentifier = "org.kde.maildir." + QUuid::createUuid().toByteArray(); mIdentifier = resourceIdentifier; @@ -114,31 +117,39 @@ void MaildirSettings::save() resource.setProperty("path", property("path")); resource.setProperty("identifier", resourceIdentifier); resource.setProperty("type", "org.kde.maildir"); - Sink::Store::create(resource).exec(); - Q_ASSERT(!mAccountIdentifier.isEmpty()); - Kube::Account account(mAccountIdentifier); - account.setProperty("maildirResource", resourceIdentifier); - account.save(); - //TODO deal with errors while creating + Sink::Store::create(resource).then([this, resourceIdentifier]() { + Q_ASSERT(!mAccountIdentifier.isEmpty()); + Kube::Account account(mAccountIdentifier); + account.setProperty("maildirResource", resourceIdentifier); + account.save(); + }, + [](int errorCode, const QString &errorMessage) { + qWarning() << "Error while creating resource: " << errorMessage; + }) + .exec(); } } void MaildirSettings::remove() { - if (!mIdentifier.isEmpty()) { + if (mIdentifier.isEmpty()) { qWarning() << "We're missing an identifier"; } else { - Sink::ApplicationDomain::SinkResource resource(mIdentifier); - Sink::Store::remove(resource).exec(); - Kube::Account account(mAccountIdentifier); - account.remove(); - - Kube::Settings settings("accounts"); - auto accounts = settings.property("accounts").toStringList(); - accounts.removeAll(mAccountIdentifier); - settings.setProperty("accounts", accounts); - settings.save(); - //TODO deal with errors while removing + Sink::ApplicationDomain::SinkResource resource("", mIdentifier, 0, QSharedPointer::create()); + Sink::Store::remove(resource).then([this]() { + Kube::Account account(mAccountIdentifier); + account.remove(); + + Kube::Settings settings("accounts"); + auto accounts = settings.property("accounts").toStringList(); + accounts.removeAll(mAccountIdentifier); + settings.setProperty("accounts", accounts); + settings.save(); + }, + [](int errorCode, const QString &errorMessage) { + qWarning() << "Error while removing resource: " << errorMessage; + }) + .exec(); } } diff --git a/accounts/maildir/tests/settingstest.cpp b/accounts/maildir/tests/settingstest.cpp index d9983028..af1a35b4 100644 --- a/accounts/maildir/tests/settingstest.cpp +++ b/accounts/maildir/tests/settingstest.cpp @@ -1,6 +1,11 @@ -#include +#include #include +#include #include +#include +#include +#include +#include #include "maildirsettings.h" @@ -11,9 +16,7 @@ private slots: void initTestCase() { - // Sink::FacadeFactory::instance().resetFactory(); - // ResourceConfig::clear(); - // Sink::Log::setDebugOutputLevel(Sink::Log::Trace); + Sink::Test::initTest(); } void testLoad() @@ -26,10 +29,33 @@ private slots: settings.setPath(maildirPath); settings.save(); - //TODO ensure the maildir resource has been created - //TODO ensure the path has been setup correctly - //Ensure we can read the configuration correctly - //Ensure we can remove the account again + Sink::Store::fetchAll(Sink::Query()).then>([](const QList &resources) { + QCOMPARE(resources.size(), 1); + }) + .exec().waitForFinished(); + + //Ensure we can read back all the information using the accountid + { + MaildirSettings readSettings; + QSignalSpy spy(&readSettings, &MaildirSettings::pathChanged); + readSettings.setAccountIdentifier(accountId); + QTRY_VERIFY(spy.count()); + QVERIFY(!readSettings.identifier().isEmpty()); + QCOMPARE(readSettings.path().toString(), maildirPath); + } + + { + MaildirSettings settings; + QSignalSpy spy(&settings, &MaildirSettings::pathChanged); + settings.setAccountIdentifier(accountId); + QTRY_VERIFY(spy.count()); + settings.remove(); + } + + Sink::Store::fetchAll(Sink::Query()).then>([](const QList &resources) { + QCOMPARE(resources.size(), 0); + }) + .exec().waitForFinished(); } }; -- cgit v1.2.3