summaryrefslogtreecommitdiffstats
path: root/tests/teststore.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/teststore.cpp')
-rw-r--r--tests/teststore.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/teststore.cpp b/tests/teststore.cpp
new file mode 100644
index 00000000..a8cd0b2d
--- /dev/null
+++ b/tests/teststore.cpp
@@ -0,0 +1,59 @@
1/*
2 Copyright (c) 2018 Christian Mollekopf <mollekopf@kolabsys.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19#include "teststore.h"
20
21#include <sink/store.h>
22
23#include <QDebug>
24#include <QVariant>
25
26using namespace Kube;
27
28static void iterateOverObjects(const QVariantList &list, std::function<void(const QVariantMap &)> callback)
29{
30 for (const auto &entry : list) {
31 auto object = entry.toMap();
32 callback(object);
33 }
34}
35
36void TestStore::setup(const QVariantMap &map)
37{
38 iterateOverObjects(map.value("resources").toList(), [] (const QVariantMap &object) {
39 auto resource = [&] {
40 if (object["type"] == "dummy") {
41 return Sink::ApplicationDomain::DummyResource::create(object["account"].toByteArray());
42 }
43 if (object["type"] == "mailtransport") {
44 return Sink::ApplicationDomain::MailtransportResource::create(object["account"].toByteArray());
45 }
46 Q_ASSERT(false);
47 return Sink::ApplicationDomain::SinkResource{};
48 }();
49 Sink::Store::create(resource).exec().waitForFinished();
50 });
51
52 iterateOverObjects(map.value("identities").toList(), [] (const QVariantMap &object) {
53 auto identity = Sink::ApplicationDomain::Identity{};
54 identity.setAccount(object["account"].toByteArray());
55 identity.setAddress(object["address"].toString());
56 identity.setName(object["name"].toString());
57 Sink::Store::create(identity).exec().waitForFinished();
58 });
59}