diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-08 14:32:37 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-08 16:26:38 +0100 |
commit | ed317a9be63c6877702d0871e5fa1bef34ab799f (patch) | |
tree | 1ed15ea9dae1a48285674f06365d404af8c9b5c0 /tests/teststore.cpp | |
parent | 3ac6cf5ffae2247719730f328d1363c498e4ee83 (diff) | |
download | kube-ed317a9be63c6877702d0871e5fa1bef34ab799f.tar.gz kube-ed317a9be63c6877702d0871e5fa1bef34ab799f.zip |
Composertest with TestStore
Diffstat (limited to 'tests/teststore.cpp')
-rw-r--r-- | tests/teststore.cpp | 84 |
1 files changed, 77 insertions, 7 deletions
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 | |||
26 | using namespace Kube; | 31 | using namespace Kube; |
27 | 32 | ||
28 | static void iterateOverObjects(const QVariantList &list, std::function<void(const QVariantMap &)> callback) | 33 | static 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 | ||
41 | static 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 | |||
50 | static 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 | |||
36 | void TestStore::setup(const QVariantMap &map) | 77 | void 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 | |||
112 | QVariant 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 | } |