summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/teststore.cpp84
-rw-r--r--tests/teststore.h2
3 files changed, 80 insertions, 7 deletions
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
7 Qt5::QuickTest 7 Qt5::QuickTest
8 Qt5::Quick 8 Qt5::Quick
9 sink 9 sink
10 kubeframework
10) 11)
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 @@
19#include "teststore.h" 19#include "teststore.h"
20 20
21#include <sink/store.h> 21#include <sink/store.h>
22#include <sink/resourcecontrol.h>
23#include <sink/secretstore.h>
24#include <kmime/kmime_message.h>
22 25
23#include <QDebug> 26#include <QDebug>
24#include <QVariant> 27#include <QVariant>
25 28
29#include "framework/src/domain/mime/mailtemplates.h"
30
26using namespace Kube; 31using namespace Kube;
27 32
28static void iterateOverObjects(const QVariantList &list, std::function<void(const QVariantMap &)> callback) 33static void iterateOverObjects(const QVariantList &list, std::function<void(const QVariantMap &)> callback)
@@ -33,20 +38,62 @@ static void iterateOverObjects(const QVariantList &list, std::function<void(cons
33 } 38 }
34} 39}
35 40
41static QStringList toStringList(const QVariantList &list)
42{
43 QStringList s;
44 for (const auto &e : list) {
45 s << e.toString();
46 }
47 return s;
48}
49
50static void createMail(const QVariantMap &object)
51{
52 using namespace Sink::ApplicationDomain;
53
54 auto toAddresses = toStringList(object["to"].toList());
55 auto ccAddresses = toStringList(object["cc"].toList());
56 auto bccAddresses = toStringList(object["bcc"].toList());
57
58 KMime::Types::Mailbox mb;
59 mb.fromUnicodeString("identity@example.org");
60 auto msg = MailTemplates::createMessage({},
61 toAddresses,
62 ccAddresses,
63 bccAddresses,
64 mb,
65 object["subject"].toString(),
66 object["body"].toString(),
67 {},
68 {},
69 {},
70 {});
71
72 auto mail = ApplicationDomainType::createEntity<Mail>(object["resource"].toByteArray());
73 mail.setMimeMessage(msg->encodedContent(true));
74 Sink::Store::create<Mail>(mail).exec().waitForFinished();
75}
76
36void TestStore::setup(const QVariantMap &map) 77void TestStore::setup(const QVariantMap &map)
37{ 78{
38 iterateOverObjects(map.value("resources").toList(), [] (const QVariantMap &object) { 79 QByteArrayList resources;
80 iterateOverObjects(map.value("resources").toList(), [&] (const QVariantMap &object) {
81 resources << object["id"].toByteArray();
39 auto resource = [&] { 82 auto resource = [&] {
83 using namespace Sink::ApplicationDomain;
84 auto resource = ApplicationDomainType::createEntity<SinkResource>("", object["id"].toByteArray());
40 if (object["type"] == "dummy") { 85 if (object["type"] == "dummy") {
41 return Sink::ApplicationDomain::DummyResource::create(object["account"].toByteArray()); 86 resource.setResourceType("sink.dummy");
42 } 87 } else if (object["type"] == "mailtransport") {
43 if (object["type"] == "mailtransport") { 88 resource.setResourceType("sink.mailtransport");
44 return Sink::ApplicationDomain::MailtransportResource::create(object["account"].toByteArray()); 89 } else {
90 Q_ASSERT(false);
45 } 91 }
46 Q_ASSERT(false); 92 return resource;
47 return Sink::ApplicationDomain::SinkResource{};
48 }(); 93 }();
94 resource.setAccount(object["account"].toByteArray());
49 Sink::Store::create(resource).exec().waitForFinished(); 95 Sink::Store::create(resource).exec().waitForFinished();
96 Sink::SecretStore::instance().insert(resource.identifier(), "secret");
50 }); 97 });
51 98
52 iterateOverObjects(map.value("identities").toList(), [] (const QVariantMap &object) { 99 iterateOverObjects(map.value("identities").toList(), [] (const QVariantMap &object) {
@@ -56,4 +103,27 @@ void TestStore::setup(const QVariantMap &map)
56 identity.setName(object["name"].toString()); 103 identity.setName(object["name"].toString());
57 Sink::Store::create(identity).exec().waitForFinished(); 104 Sink::Store::create(identity).exec().waitForFinished();
58 }); 105 });
106
107 iterateOverObjects(map.value("mails").toList(), createMail);
108
109 Sink::ResourceControl::flushMessageQueue(resources).exec().waitForFinished();
110}
111
112QVariant TestStore::load(const QByteArray &type, const QVariantMap &filter)
113{
114 using namespace Sink::ApplicationDomain;
115 if (type == "mail") {
116 Sink::Query query;
117 if (filter.contains("resource")) {
118 query.resourceFilter(filter.value("resource").toByteArray());
119 }
120 auto list = Sink::Store::read<Mail>(query);
121 if (!list.isEmpty()) {
122 return QVariant::fromValue(Mail::Ptr::create(list.first()));
123 }
124 return {};
125 }
126
127 Q_ASSERT(false);
128 return {};
59} 129}
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 @@
19#pragma once 19#pragma once
20 20
21#include <QObject> 21#include <QObject>
22#include <QVariant>
22 23
23namespace Kube { 24namespace Kube {
24 25
@@ -26,6 +27,7 @@ class TestStore : public QObject {
26 Q_OBJECT 27 Q_OBJECT
27public: 28public:
28 Q_INVOKABLE void setup(const QVariantMap &); 29 Q_INVOKABLE void setup(const QVariantMap &);
30 Q_INVOKABLE QVariant load(const QByteArray &type, const QVariantMap &);
29}; 31};
30 32
31} 33}