diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-02-16 20:14:49 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-02-16 20:14:49 +0100 |
commit | 5374dcfd39d9a0ee5b493e93419018b734781c4a (patch) | |
tree | d3eb1c44b1fdabcf8f6df31bef6dd52749e71cb0 | |
parent | 6e700175cdaed0971c646fd1d2d814e0ec4d73ba (diff) | |
download | sink-5374dcfd39d9a0ee5b493e93419018b734781c4a.tar.gz sink-5374dcfd39d9a0ee5b493e93419018b734781c4a.zip |
Fixed multimodifications
-rw-r--r-- | common/store.cpp | 2 | ||||
-rw-r--r-- | tests/clientapitest.cpp | 42 |
2 files changed, 43 insertions, 1 deletions
diff --git a/common/store.cpp b/common/store.cpp index 6dd4fb3..9550d3e 100644 --- a/common/store.cpp +++ b/common/store.cpp | |||
@@ -198,7 +198,7 @@ KAsync::Job<void> Store::modify(const Query &query, const DomainType &domainObje | |||
198 | for (const auto &p : domainObject.changedProperties()) { | 198 | for (const auto &p : domainObject.changedProperties()) { |
199 | copy.setProperty(p, domainObject.getProperty(p)); | 199 | copy.setProperty(p, domainObject.getProperty(p)); |
200 | } | 200 | } |
201 | return modify(*entity); | 201 | return modify(copy); |
202 | }); | 202 | }); |
203 | } | 203 | } |
204 | 204 | ||
diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index fb1bdeb..ea72ae0 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp | |||
@@ -34,10 +34,14 @@ public: | |||
34 | ~TestDummyResourceFacade(){}; | 34 | ~TestDummyResourceFacade(){}; |
35 | KAsync::Job<void> create(const T &domainObject) Q_DECL_OVERRIDE | 35 | KAsync::Job<void> create(const T &domainObject) Q_DECL_OVERRIDE |
36 | { | 36 | { |
37 | SinkLogCtx(Sink::Log::Context{"test"}) << "Create: " << domainObject; | ||
38 | creations << domainObject; | ||
37 | return KAsync::null<void>(); | 39 | return KAsync::null<void>(); |
38 | }; | 40 | }; |
39 | KAsync::Job<void> modify(const T &domainObject) Q_DECL_OVERRIDE | 41 | KAsync::Job<void> modify(const T &domainObject) Q_DECL_OVERRIDE |
40 | { | 42 | { |
43 | SinkLogCtx(Sink::Log::Context{"test"}) << "Modify: " << domainObject; | ||
44 | modifications << domainObject; | ||
41 | return KAsync::null<void>(); | 45 | return KAsync::null<void>(); |
42 | }; | 46 | }; |
43 | KAsync::Job<void> move(const T &domainObject, const QByteArray &) Q_DECL_OVERRIDE | 47 | KAsync::Job<void> move(const T &domainObject, const QByteArray &) Q_DECL_OVERRIDE |
@@ -50,6 +54,8 @@ public: | |||
50 | }; | 54 | }; |
51 | KAsync::Job<void> remove(const T &domainObject) Q_DECL_OVERRIDE | 55 | KAsync::Job<void> remove(const T &domainObject) Q_DECL_OVERRIDE |
52 | { | 56 | { |
57 | SinkLogCtx(Sink::Log::Context{"test"}) << "Remove: " << domainObject; | ||
58 | removals << domainObject; | ||
53 | return KAsync::null<void>(); | 59 | return KAsync::null<void>(); |
54 | }; | 60 | }; |
55 | QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename T::Ptr>::Ptr> load(const Sink::Query &query, const Sink::Log::Context &ctx) Q_DECL_OVERRIDE | 61 | QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename T::Ptr>::Ptr> load(const Sink::Query &query, const Sink::Log::Context &ctx) Q_DECL_OVERRIDE |
@@ -102,6 +108,9 @@ public: | |||
102 | Sink::ResultProviderInterface<typename T::Ptr> *mResultProvider; | 108 | Sink::ResultProviderInterface<typename T::Ptr> *mResultProvider; |
103 | bool runAsync = false; | 109 | bool runAsync = false; |
104 | int offset = 0; | 110 | int offset = 0; |
111 | QList<T> creations; | ||
112 | QList<T> modifications; | ||
113 | QList<T> removals; | ||
105 | }; | 114 | }; |
106 | 115 | ||
107 | 116 | ||
@@ -333,6 +342,39 @@ private slots: | |||
333 | QVERIFY(!model->canFetchMore(QModelIndex())); | 342 | QVERIFY(!model->canFetchMore(QModelIndex())); |
334 | } | 343 | } |
335 | 344 | ||
345 | void testCreateModifyDelete() | ||
346 | { | ||
347 | auto facade = TestDummyResourceFacade<Sink::ApplicationDomain::Event>::registerFacade(); | ||
348 | ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); | ||
349 | |||
350 | auto event = Sink::ApplicationDomain::Event::createEntity<Sink::ApplicationDomain::Event>("dummyresource.instance1"); | ||
351 | Sink::Store::create(event).exec().waitForFinished(); | ||
352 | QCOMPARE(facade->creations.size(), 1); | ||
353 | Sink::Store::modify(event).exec().waitForFinished(); | ||
354 | QCOMPARE(facade->modifications.size(), 1); | ||
355 | Sink::Store::remove(event).exec().waitForFinished(); | ||
356 | QCOMPARE(facade->removals.size(), 1); | ||
357 | |||
358 | } | ||
359 | void testMultiModify() | ||
360 | { | ||
361 | auto facade = TestDummyResourceFacade<Sink::ApplicationDomain::Event>::registerFacade(); | ||
362 | facade->results << QSharedPointer<Sink::ApplicationDomain::Event>::create("dummyresource.instance1", "id1", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | ||
363 | facade->results << QSharedPointer<Sink::ApplicationDomain::Event>::create("dummyresource.instance1", "id2", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | ||
364 | ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); | ||
365 | |||
366 | Sink::Query query; | ||
367 | query.resourceFilter("dummyresource.instance1"); | ||
368 | |||
369 | auto event = Sink::ApplicationDomain::Event::createEntity<Sink::ApplicationDomain::Event>("dummyresource.instance1"); | ||
370 | event.setUid("modifiedUid"); | ||
371 | Sink::Store::modify(query, event).exec().waitForFinished(); | ||
372 | QCOMPARE(facade->modifications.size(), 2); | ||
373 | for (const auto &m : facade->modifications) { | ||
374 | QCOMPARE(m.getUid(), QString("modifiedUid")); | ||
375 | } | ||
376 | } | ||
377 | |||
336 | void testModelStress() | 378 | void testModelStress() |
337 | { | 379 | { |
338 | auto facade = TestDummyResourceFacade<Sink::ApplicationDomain::Folder>::registerFacade(); | 380 | auto facade = TestDummyResourceFacade<Sink::ApplicationDomain::Folder>::registerFacade(); |