Changeset View
Changeset View
Standalone View
Standalone View
tests/teststore.cpp
Show All 15 Lines | 1 | /* | |||
---|---|---|---|---|---|
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | 16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301, USA. | 17 | 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
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> | 22 | #include <sink/resourcecontrol.h> | ||
23 | #include <sink/secretstore.h> | 23 | #include <sink/secretstore.h> | ||
24 | | ||||
24 | #include <kmime/kmime_message.h> | 25 | #include <kmime/kmime_message.h> | ||
25 | 26 | | |||
27 | #include <KCalCore/Event> | ||||
28 | #include <KCalCore/ICalFormat> | ||||
29 | | ||||
26 | #include <QDebug> | 30 | #include <QDebug> | ||
31 | #include <QUuid> | ||||
27 | #include <QVariant> | 32 | #include <QVariant> | ||
28 | 33 | | |||
29 | #include "framework/src/domain/mime/mailtemplates.h" | 34 | #include "framework/src/domain/mime/mailtemplates.h" | ||
30 | 35 | | |||
31 | using namespace Kube; | 36 | using namespace Kube; | ||
32 | 37 | | |||
33 | static void iterateOverObjects(const QVariantList &list, std::function<void(const QVariantMap &)> callback) | 38 | static void iterateOverObjects(const QVariantList &list, std::function<void(const QVariantMap &)> callback) | ||
34 | { | 39 | { | ||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Line(s) | 120 | { | |||
119 | folder.setSpecialPurpose(toByteArrayList(object["specialpurpose"].toList())); | 124 | folder.setSpecialPurpose(toByteArrayList(object["specialpurpose"].toList())); | ||
120 | Sink::Store::create(folder).exec().waitForFinished(); | 125 | Sink::Store::create(folder).exec().waitForFinished(); | ||
121 | 126 | | |||
122 | iterateOverObjects(object.value("mails").toList(), [=](const QVariantMap &object) { | 127 | iterateOverObjects(object.value("mails").toList(), [=](const QVariantMap &object) { | ||
123 | createMail(object, folder.identifier()); | 128 | createMail(object, folder.identifier()); | ||
124 | }); | 129 | }); | ||
125 | } | 130 | } | ||
126 | 131 | | |||
132 | static void createEvent(const QVariantMap &object, const QByteArray &calendarId = {}) | ||||
133 | { | ||||
134 | using Sink::ApplicationDomain::ApplicationDomainType; | ||||
135 | using Sink::ApplicationDomain::Event; | ||||
136 | | ||||
137 | auto sinkEvent = ApplicationDomainType::createEntity<Event>(object["resource"].toByteArray()); | ||||
138 | | ||||
139 | auto calcoreEvent = QSharedPointer<KCalCore::Event>::create(); | ||||
140 | | ||||
141 | QString uid; | ||||
142 | if (object.contains("uid")) { | ||||
143 | uid = object["uid"].toString(); | ||||
cmollekopf: Setting properties twice should not be necessary. Set the ical property only, and make sure… | |||||
144 | } else { | ||||
145 | uid = QUuid::createUuid().toString(); | ||||
146 | } | ||||
147 | calcoreEvent->setUid(uid); | ||||
148 | | ||||
149 | auto summary = object["summary"].toString(); | ||||
150 | calcoreEvent->setSummary(summary); | ||||
151 | | ||||
152 | if (object.contains("description")) { | ||||
153 | auto description = object["description"].toString(); | ||||
154 | calcoreEvent->setDescription(description); | ||||
155 | } | ||||
156 | | ||||
157 | auto startTime = object["starts"].toDateTime(); | ||||
158 | auto endTime = object["ends"].toDateTime(); | ||||
159 | | ||||
160 | calcoreEvent->setDtStart(startTime); | ||||
161 | calcoreEvent->setDtEnd(endTime); | ||||
162 | | ||||
163 | auto ical = KCalCore::ICalFormat().toICalString(calcoreEvent); | ||||
164 | sinkEvent.setIcal(ical.toUtf8()); | ||||
165 | | ||||
166 | sinkEvent.setCalendar(calendarId); | ||||
167 | | ||||
168 | Sink::Store::create(sinkEvent).exec().waitForFinished(); | ||||
169 | } | ||||
170 | | ||||
171 | static void createCalendar(const QVariantMap &object) | ||||
172 | { | ||||
173 | using Sink::ApplicationDomain::Calendar; | ||||
174 | using Sink::ApplicationDomain::ApplicationDomainType; | ||||
175 | | ||||
176 | auto calendar = ApplicationDomainType::createEntity<Calendar>(object["resource"].toByteArray()); | ||||
177 | calendar.setName(object["name"].toString()); | ||||
178 | Sink::Store::create(calendar).exec().waitForFinished(); | ||||
179 | | ||||
180 | auto calendarId = calendar.identifier(); | ||||
181 | iterateOverObjects(object.value("events").toList(), | ||||
182 | [calendarId](const QVariantMap &object) { createEvent(object, calendarId); }); | ||||
183 | } | ||||
184 | | ||||
127 | void TestStore::setup(const QVariantMap &map) | 185 | void TestStore::setup(const QVariantMap &map) | ||
128 | { | 186 | { | ||
129 | using namespace Sink::ApplicationDomain; | 187 | using namespace Sink::ApplicationDomain; | ||
130 | iterateOverObjects(map.value("accounts").toList(), [&] (const QVariantMap &object) { | 188 | iterateOverObjects(map.value("accounts").toList(), [&] (const QVariantMap &object) { | ||
131 | auto account = ApplicationDomainType::createEntity<SinkAccount>("", object["id"].toByteArray()); | 189 | auto account = ApplicationDomainType::createEntity<SinkAccount>("", object["id"].toByteArray()); | ||
132 | account.setName(object["name"].toString()); | 190 | account.setName(object["name"].toString()); | ||
133 | Sink::Store::create(account).exec().waitForFinished(); | 191 | Sink::Store::create(account).exec().waitForFinished(); | ||
134 | }); | 192 | }); | ||
135 | QByteArrayList resources; | 193 | QByteArrayList resources; | ||
136 | iterateOverObjects(map.value("resources").toList(), [&] (const QVariantMap &object) { | 194 | iterateOverObjects(map.value("resources").toList(), [&] (const QVariantMap &object) { | ||
137 | resources << object["id"].toByteArray(); | 195 | resources << object["id"].toByteArray(); | ||
138 | auto resource = [&] { | 196 | auto resource = [&] { | ||
139 | using namespace Sink::ApplicationDomain; | 197 | using namespace Sink::ApplicationDomain; | ||
140 | auto resource = ApplicationDomainType::createEntity<SinkResource>("", object["id"].toByteArray()); | 198 | auto resource = ApplicationDomainType::createEntity<SinkResource>("", object["id"].toByteArray()); | ||
141 | if (object["type"] == "dummy") { | 199 | if (object["type"] == "dummy") { | ||
142 | resource.setResourceType("sink.dummy"); | 200 | resource.setResourceType("sink.dummy"); | ||
143 | } else if (object["type"] == "mailtransport") { | 201 | } else if (object["type"] == "mailtransport") { | ||
144 | resource.setResourceType("sink.mailtransport"); | 202 | resource.setResourceType("sink.mailtransport"); | ||
145 | resource.setProperty("testmode", true); | 203 | resource.setProperty("testmode", true); | ||
204 | } else if (object["type"] == "caldav") { | ||||
205 | resource.setResourceType("sink.caldav"); | ||||
206 | resource.setProperty("testmode", true); | ||||
146 | } else { | 207 | } else { | ||
147 | Q_ASSERT(false); | 208 | Q_ASSERT(false); | ||
148 | } | 209 | } | ||
149 | return resource; | 210 | return resource; | ||
150 | }(); | 211 | }(); | ||
151 | resource.setAccount(object["account"].toByteArray()); | 212 | resource.setAccount(object["account"].toByteArray()); | ||
152 | Sink::Store::create(resource).exec().waitForFinished(); | 213 | Sink::Store::create(resource).exec().waitForFinished(); | ||
153 | Sink::SecretStore::instance().insert(resource.identifier(), "secret"); | 214 | Sink::SecretStore::instance().insert(resource.identifier(), "secret"); | ||
154 | }); | 215 | }); | ||
155 | 216 | | |||
156 | iterateOverObjects(map.value("identities").toList(), [] (const QVariantMap &object) { | 217 | iterateOverObjects(map.value("identities").toList(), [] (const QVariantMap &object) { | ||
157 | auto identity = Sink::ApplicationDomain::Identity{}; | 218 | auto identity = Sink::ApplicationDomain::Identity{}; | ||
158 | identity.setAccount(object["account"].toByteArray()); | 219 | identity.setAccount(object["account"].toByteArray()); | ||
159 | identity.setAddress(object["address"].toString()); | 220 | identity.setAddress(object["address"].toString()); | ||
160 | identity.setName(object["name"].toString()); | 221 | identity.setName(object["name"].toString()); | ||
161 | Sink::Store::create(identity).exec().waitForFinished(); | 222 | Sink::Store::create(identity).exec().waitForFinished(); | ||
162 | }); | 223 | }); | ||
163 | 224 | | |||
164 | iterateOverObjects(map.value("folders").toList(), createFolder); | 225 | iterateOverObjects(map.value("folders").toList(), createFolder); | ||
165 | iterateOverObjects(map.value("mails").toList(), [] (const QVariantMap &map) { | 226 | iterateOverObjects(map.value("mails").toList(), [] (const QVariantMap &map) { | ||
166 | createMail(map); | 227 | createMail(map); | ||
167 | }); | 228 | }); | ||
168 | 229 | | |||
230 | iterateOverObjects(map.value("calendars").toList(), createCalendar); | ||||
231 | | ||||
169 | Sink::ResourceControl::flushMessageQueue(resources).exec().waitForFinished(); | 232 | Sink::ResourceControl::flushMessageQueue(resources).exec().waitForFinished(); | ||
170 | } | 233 | } | ||
171 | 234 | | |||
172 | QVariant TestStore::load(const QByteArray &type, const QVariantMap &filter) | 235 | QVariant TestStore::load(const QByteArray &type, const QVariantMap &filter) | ||
173 | { | 236 | { | ||
174 | using namespace Sink::ApplicationDomain; | 237 | using namespace Sink::ApplicationDomain; | ||
175 | const auto list = loadList(type, filter); | 238 | const auto list = loadList(type, filter); | ||
176 | if (!list.isEmpty()) { | 239 | if (!list.isEmpty()) { | ||
▲ Show 20 Lines • Show All 67 Lines • Show Last 20 Lines |
Setting properties twice should not be necessary. Set the ical property only, and make sure that you extract the other properties in an extractor in the resource (Just like it's done for mail).
This also means all event properties should be marked as extracted properties instead.