From ed317a9be63c6877702d0871e5fa1bef34ab799f Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 8 Jan 2018 14:32:37 +0100 Subject: Composertest with TestStore --- tests/CMakeLists.txt | 1 + tests/teststore.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++++++----- tests/teststore.h | 2 ++ 3 files changed, 80 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ca394d9e..b5eb2a96 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,4 +7,5 @@ target_link_libraries(kubetestrunner Qt5::QuickTest Qt5::Quick sink + kubeframework ) diff --git a/tests/teststore.cpp b/tests/teststore.cpp index a8cd0b2d..728af885 100644 --- a/tests/teststore.cpp +++ b/tests/teststore.cpp @@ -19,10 +19,15 @@ #include "teststore.h" #include +#include +#include +#include #include #include +#include "framework/src/domain/mime/mailtemplates.h" + using namespace Kube; static void iterateOverObjects(const QVariantList &list, std::function callback) @@ -33,20 +38,62 @@ static void iterateOverObjects(const QVariantList &list, std::function(object["resource"].toByteArray()); + mail.setMimeMessage(msg->encodedContent(true)); + Sink::Store::create(mail).exec().waitForFinished(); +} + void TestStore::setup(const QVariantMap &map) { - iterateOverObjects(map.value("resources").toList(), [] (const QVariantMap &object) { + QByteArrayList resources; + iterateOverObjects(map.value("resources").toList(), [&] (const QVariantMap &object) { + resources << object["id"].toByteArray(); auto resource = [&] { + using namespace Sink::ApplicationDomain; + auto resource = ApplicationDomainType::createEntity("", object["id"].toByteArray()); if (object["type"] == "dummy") { - return Sink::ApplicationDomain::DummyResource::create(object["account"].toByteArray()); - } - if (object["type"] == "mailtransport") { - return Sink::ApplicationDomain::MailtransportResource::create(object["account"].toByteArray()); + resource.setResourceType("sink.dummy"); + } else if (object["type"] == "mailtransport") { + resource.setResourceType("sink.mailtransport"); + } else { + Q_ASSERT(false); } - Q_ASSERT(false); - return Sink::ApplicationDomain::SinkResource{}; + return resource; }(); + resource.setAccount(object["account"].toByteArray()); Sink::Store::create(resource).exec().waitForFinished(); + Sink::SecretStore::instance().insert(resource.identifier(), "secret"); }); iterateOverObjects(map.value("identities").toList(), [] (const QVariantMap &object) { @@ -56,4 +103,27 @@ void TestStore::setup(const QVariantMap &map) identity.setName(object["name"].toString()); Sink::Store::create(identity).exec().waitForFinished(); }); + + iterateOverObjects(map.value("mails").toList(), createMail); + + Sink::ResourceControl::flushMessageQueue(resources).exec().waitForFinished(); +} + +QVariant TestStore::load(const QByteArray &type, const QVariantMap &filter) +{ + using namespace Sink::ApplicationDomain; + if (type == "mail") { + Sink::Query query; + if (filter.contains("resource")) { + query.resourceFilter(filter.value("resource").toByteArray()); + } + auto list = Sink::Store::read(query); + if (!list.isEmpty()) { + return QVariant::fromValue(Mail::Ptr::create(list.first())); + } + return {}; + } + + Q_ASSERT(false); + return {}; } diff --git a/tests/teststore.h b/tests/teststore.h index f0578ca5..e8fce6da 100644 --- a/tests/teststore.h +++ b/tests/teststore.h @@ -19,6 +19,7 @@ #pragma once #include +#include namespace Kube { @@ -26,6 +27,7 @@ class TestStore : public QObject { Q_OBJECT public: Q_INVOKABLE void setup(const QVariantMap &); + Q_INVOKABLE QVariant load(const QByteArray &type, const QVariantMap &); }; } -- cgit v1.2.3