diff options
Diffstat (limited to 'tests/dummyresourcetest.cpp')
-rw-r--r-- | tests/dummyresourcetest.cpp | 96 |
1 files changed, 49 insertions, 47 deletions
diff --git a/tests/dummyresourcetest.cpp b/tests/dummyresourcetest.cpp index 687a33b..a7a492c 100644 --- a/tests/dummyresourcetest.cpp +++ b/tests/dummyresourcetest.cpp | |||
@@ -14,6 +14,7 @@ | |||
14 | #include "test.h" | 14 | #include "test.h" |
15 | 15 | ||
16 | using namespace Sink; | 16 | using namespace Sink; |
17 | using namespace Sink::ApplicationDomain; | ||
17 | 18 | ||
18 | /** | 19 | /** |
19 | * Test of complete system using the dummy resource. | 20 | * Test of complete system using the dummy resource. |
@@ -32,7 +33,7 @@ private slots: | |||
32 | Sink::Test::initTest(); | 33 | Sink::Test::initTest(); |
33 | auto factory = Sink::ResourceFactory::load("sink.dummy"); | 34 | auto factory = Sink::ResourceFactory::load("sink.dummy"); |
34 | QVERIFY(factory); | 35 | QVERIFY(factory); |
35 | DummyResource::removeFromDisk("sink.dummy.instance1"); | 36 | ::DummyResource::removeFromDisk("sink.dummy.instance1"); |
36 | ResourceConfig::addResource("sink.dummy.instance1", "sink.dummy"); | 37 | ResourceConfig::addResource("sink.dummy.instance1", "sink.dummy"); |
37 | } | 38 | } |
38 | 39 | ||
@@ -52,49 +53,49 @@ private slots: | |||
52 | 53 | ||
53 | void testProperty() | 54 | void testProperty() |
54 | { | 55 | { |
55 | Sink::ApplicationDomain::Event event; | 56 | Event event; |
56 | event.setProperty("uid", "testuid"); | 57 | event.setProperty("uid", "testuid"); |
57 | QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); | 58 | QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); |
58 | } | 59 | } |
59 | 60 | ||
60 | void testWriteToFacadeAndQueryByUid() | 61 | void testWriteToFacadeAndQueryByUid() |
61 | { | 62 | { |
62 | Sink::ApplicationDomain::Event event("sink.dummy.instance1"); | 63 | Event event("sink.dummy.instance1"); |
63 | event.setProperty("uid", "testuid"); | 64 | event.setProperty("uid", "testuid"); |
64 | QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); | 65 | QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); |
65 | event.setProperty("summary", "summaryValue"); | 66 | event.setProperty("summary", "summaryValue"); |
66 | Sink::Store::create<Sink::ApplicationDomain::Event>(event).exec().waitForFinished(); | 67 | Sink::Store::create<Event>(event).exec().waitForFinished(); |
67 | 68 | ||
68 | const auto query = Query::ResourceFilter("sink.dummy.instance1") ; | 69 | auto query = Query::ResourceFilter("sink.dummy.instance1") ; |
69 | 70 | ||
70 | // Ensure all local data is processed | 71 | // Ensure all local data is processed |
71 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | 72 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); |
72 | 73 | ||
73 | auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Event>(query + Query::PropertyFilter("uid", "testuid")); | 74 | auto model = Sink::Store::loadModel<Event>(query.filter<Event::Uid>("testuid")); |
74 | QTRY_COMPARE(model->rowCount(QModelIndex()), 1); | 75 | QTRY_COMPARE(model->rowCount(QModelIndex()), 1); |
75 | auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Event::Ptr>(); | 76 | auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Event::Ptr>(); |
76 | QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); | 77 | QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); |
77 | } | 78 | } |
78 | 79 | ||
79 | void testWriteToFacadeAndQueryByUid2() | 80 | void testWriteToFacadeAndQueryByUid2() |
80 | { | 81 | { |
81 | Sink::ApplicationDomain::Event event("sink.dummy.instance1"); | 82 | Event event("sink.dummy.instance1"); |
82 | event.setProperty("summary", "summaryValue"); | 83 | event.setProperty("summary", "summaryValue"); |
83 | 84 | ||
84 | event.setProperty("uid", "testuid"); | 85 | event.setProperty("uid", "testuid"); |
85 | Sink::Store::create<Sink::ApplicationDomain::Event>(event).exec().waitForFinished(); | 86 | Sink::Store::create<Event>(event).exec().waitForFinished(); |
86 | 87 | ||
87 | event.setProperty("uid", "testuid2"); | 88 | event.setProperty("uid", "testuid2"); |
88 | Sink::Store::create<Sink::ApplicationDomain::Event>(event).exec().waitForFinished(); | 89 | Sink::Store::create<Event>(event).exec().waitForFinished(); |
89 | 90 | ||
90 | const auto query = Query::ResourceFilter("sink.dummy.instance1") ; | 91 | auto query = Query::ResourceFilter("sink.dummy.instance1") ; |
91 | 92 | ||
92 | // Ensure all local data is processed | 93 | // Ensure all local data is processed |
93 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | 94 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); |
94 | 95 | ||
95 | auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Event>(query + Query::PropertyFilter("uid", "testuid")); | 96 | auto model = Sink::Store::loadModel<Event>(query.filter<Event::Uid>("testuid")); |
96 | QTRY_COMPARE(model->rowCount(QModelIndex()), 1); | 97 | QTRY_COMPARE(model->rowCount(QModelIndex()), 1); |
97 | auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Event::Ptr>(); | 98 | auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Event::Ptr>(); |
98 | 99 | ||
99 | qDebug() << value->getProperty("uid").toByteArray(); | 100 | qDebug() << value->getProperty("uid").toByteArray(); |
100 | QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); | 101 | QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); |
@@ -102,24 +103,24 @@ private slots: | |||
102 | 103 | ||
103 | void testWriteToFacadeAndQueryBySummary() | 104 | void testWriteToFacadeAndQueryBySummary() |
104 | { | 105 | { |
105 | Sink::ApplicationDomain::Event event("sink.dummy.instance1"); | 106 | Event event("sink.dummy.instance1"); |
106 | 107 | ||
107 | event.setProperty("uid", "testuid"); | 108 | event.setProperty("uid", "testuid"); |
108 | event.setProperty("summary", "summaryValue1"); | 109 | event.setProperty("summary", "summaryValue1"); |
109 | Sink::Store::create<Sink::ApplicationDomain::Event>(event).exec().waitForFinished(); | 110 | Sink::Store::create<Event>(event).exec().waitForFinished(); |
110 | 111 | ||
111 | event.setProperty("uid", "testuid2"); | 112 | event.setProperty("uid", "testuid2"); |
112 | event.setProperty("summary", "summaryValue2"); | 113 | event.setProperty("summary", "summaryValue2"); |
113 | Sink::Store::create<Sink::ApplicationDomain::Event>(event).exec().waitForFinished(); | 114 | Sink::Store::create<Event>(event).exec().waitForFinished(); |
114 | 115 | ||
115 | const auto query = Query::ResourceFilter("sink.dummy.instance1") ; | 116 | auto query = Query::ResourceFilter("sink.dummy.instance1") ; |
116 | 117 | ||
117 | // Ensure all local data is processed | 118 | // Ensure all local data is processed |
118 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | 119 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); |
119 | 120 | ||
120 | auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Event>(query + Query::PropertyFilter("summary", "summaryValue2")); | 121 | auto model = Sink::Store::loadModel<Event>(query.filter<Event::Summary>("summaryValue2")); |
121 | QTRY_COMPARE(model->rowCount(QModelIndex()), 1); | 122 | QTRY_COMPARE(model->rowCount(QModelIndex()), 1); |
122 | auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Event::Ptr>(); | 123 | auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Event::Ptr>(); |
123 | 124 | ||
124 | qDebug() << value->getProperty("uid").toByteArray(); | 125 | qDebug() << value->getProperty("uid").toByteArray(); |
125 | QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid2")); | 126 | QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid2")); |
@@ -128,7 +129,7 @@ private slots: | |||
128 | void testResourceSync() | 129 | void testResourceSync() |
129 | { | 130 | { |
130 | auto pipeline = QSharedPointer<Sink::Pipeline>::create("sink.dummy.instance1"); | 131 | auto pipeline = QSharedPointer<Sink::Pipeline>::create("sink.dummy.instance1"); |
131 | DummyResource resource("sink.dummy.instance1", pipeline); | 132 | ::DummyResource resource("sink.dummy.instance1", pipeline); |
132 | auto job = resource.synchronizeWithSource(); | 133 | auto job = resource.synchronizeWithSource(); |
133 | // TODO pass in optional timeout? | 134 | // TODO pass in optional timeout? |
134 | auto future = job.exec(); | 135 | auto future = job.exec(); |
@@ -148,9 +149,9 @@ private slots: | |||
148 | Sink::Store::synchronize(query).exec().waitForFinished(); | 149 | Sink::Store::synchronize(query).exec().waitForFinished(); |
149 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | 150 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); |
150 | 151 | ||
151 | auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Event>(query); | 152 | auto model = Sink::Store::loadModel<Event>(query); |
152 | QTRY_VERIFY(model->rowCount(QModelIndex()) >= 1); | 153 | QTRY_VERIFY(model->rowCount(QModelIndex()) >= 1); |
153 | auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Event::Ptr>(); | 154 | auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Event::Ptr>(); |
154 | 155 | ||
155 | QVERIFY(!value->getProperty("summary").toString().isEmpty()); | 156 | QVERIFY(!value->getProperty("summary").toString().isEmpty()); |
156 | qDebug() << value->getProperty("summary").toString(); | 157 | qDebug() << value->getProperty("summary").toString(); |
@@ -158,39 +159,40 @@ private slots: | |||
158 | 159 | ||
159 | void testSyncAndFacadeMail() | 160 | void testSyncAndFacadeMail() |
160 | { | 161 | { |
161 | const auto query = Query::ResourceFilter("sink.dummy.instance1"); | 162 | auto query = Query::ResourceFilter("sink.dummy.instance1"); |
163 | query.request<Mail::Subject>(); | ||
162 | 164 | ||
163 | // Ensure all local data is processed | 165 | // Ensure all local data is processed |
164 | Sink::Store::synchronize(query).exec().waitForFinished(); | 166 | Sink::Store::synchronize(query).exec().waitForFinished(); |
165 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | 167 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); |
166 | 168 | ||
167 | auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); | 169 | auto model = Sink::Store::loadModel<Mail>(query); |
168 | QTRY_VERIFY(model->rowCount(QModelIndex()) >= 1); | 170 | QTRY_VERIFY(model->rowCount(QModelIndex()) >= 1); |
169 | auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Mail::Ptr>(); | 171 | auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Mail::Ptr>(); |
170 | 172 | ||
171 | QVERIFY(!value->getProperty("subject").toString().isEmpty()); | 173 | qWarning() << value->getSubject() << value->identifier(); |
172 | qDebug() << value->getProperty("subject").toString(); | 174 | QVERIFY(!value->getSubject().isEmpty()); |
173 | } | 175 | } |
174 | 176 | ||
175 | void testWriteModifyDelete() | 177 | void testWriteModifyDelete() |
176 | { | 178 | { |
177 | Sink::ApplicationDomain::Event event("sink.dummy.instance1"); | 179 | Event event("sink.dummy.instance1"); |
178 | event.setProperty("uid", "testuid"); | 180 | event.setProperty("uid", "testuid"); |
179 | QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); | 181 | QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); |
180 | event.setProperty("summary", "summaryValue"); | 182 | event.setProperty("summary", "summaryValue"); |
181 | Sink::Store::create<Sink::ApplicationDomain::Event>(event).exec().waitForFinished(); | 183 | Sink::Store::create<Event>(event).exec().waitForFinished(); |
182 | 184 | ||
183 | const auto query = Query::ResourceFilter("sink.dummy.instance1") + Query::PropertyFilter("uid", "testuid"); | 185 | auto query = Query::ResourceFilter("sink.dummy.instance1").filter<Event::Uid>("testuid"); |
184 | 186 | ||
185 | // Ensure all local data is processed | 187 | // Ensure all local data is processed |
186 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | 188 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); |
187 | 189 | ||
188 | // Test create | 190 | // Test create |
189 | Sink::ApplicationDomain::Event event2; | 191 | Event event2; |
190 | { | 192 | { |
191 | auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Event>(query); | 193 | auto model = Sink::Store::loadModel<Event>(query); |
192 | QTRY_COMPARE(model->rowCount(QModelIndex()), 1); | 194 | QTRY_COMPARE(model->rowCount(QModelIndex()), 1); |
193 | auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Event::Ptr>(); | 195 | auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Event::Ptr>(); |
194 | 196 | ||
195 | QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); | 197 | QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); |
196 | QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue")); | 198 | QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue")); |
@@ -199,29 +201,29 @@ private slots: | |||
199 | 201 | ||
200 | event2.setProperty("uid", "testuid"); | 202 | event2.setProperty("uid", "testuid"); |
201 | event2.setProperty("summary", "summaryValue2"); | 203 | event2.setProperty("summary", "summaryValue2"); |
202 | Sink::Store::modify<Sink::ApplicationDomain::Event>(event2).exec().waitForFinished(); | 204 | Sink::Store::modify<Event>(event2).exec().waitForFinished(); |
203 | 205 | ||
204 | // Ensure all local data is processed | 206 | // Ensure all local data is processed |
205 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | 207 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); |
206 | 208 | ||
207 | // Test modify | 209 | // Test modify |
208 | { | 210 | { |
209 | auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Event>(query); | 211 | auto model = Sink::Store::loadModel<Event>(query); |
210 | QTRY_COMPARE(model->rowCount(QModelIndex()), 1); | 212 | QTRY_COMPARE(model->rowCount(QModelIndex()), 1); |
211 | auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Event::Ptr>(); | 213 | auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Event::Ptr>(); |
212 | 214 | ||
213 | QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); | 215 | QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); |
214 | QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue2")); | 216 | QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue2")); |
215 | } | 217 | } |
216 | 218 | ||
217 | Sink::Store::remove<Sink::ApplicationDomain::Event>(event2).exec().waitForFinished(); | 219 | Sink::Store::remove<Event>(event2).exec().waitForFinished(); |
218 | 220 | ||
219 | // Ensure all local data is processed | 221 | // Ensure all local data is processed |
220 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | 222 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); |
221 | 223 | ||
222 | // Test remove | 224 | // Test remove |
223 | { | 225 | { |
224 | auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Event>(query); | 226 | auto model = Sink::Store::loadModel<Event>(query); |
225 | QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); | 227 | QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); |
226 | QTRY_COMPARE(model->rowCount(QModelIndex()), 0); | 228 | QTRY_COMPARE(model->rowCount(QModelIndex()), 0); |
227 | } | 229 | } |
@@ -231,22 +233,22 @@ private slots: | |||
231 | { | 233 | { |
232 | auto query = Query::ResourceFilter("sink.dummy.instance1"); | 234 | auto query = Query::ResourceFilter("sink.dummy.instance1"); |
233 | query.liveQuery = true; | 235 | query.liveQuery = true; |
234 | query += Query::PropertyFilter("uid", "testuid"); | 236 | query.filter<Event::Uid>("testuid"); |
235 | 237 | ||
236 | auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Event>(query); | 238 | auto model = Sink::Store::loadModel<Event>(query); |
237 | QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); | 239 | QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); |
238 | 240 | ||
239 | Sink::ApplicationDomain::Event event("sink.dummy.instance1"); | 241 | Event event("sink.dummy.instance1"); |
240 | event.setProperty("uid", "testuid"); | 242 | event.setProperty("uid", "testuid"); |
241 | QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); | 243 | QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); |
242 | event.setProperty("summary", "summaryValue"); | 244 | event.setProperty("summary", "summaryValue"); |
243 | Sink::Store::create<Sink::ApplicationDomain::Event>(event).exec().waitForFinished(); | 245 | Sink::Store::create<Event>(event).exec().waitForFinished(); |
244 | 246 | ||
245 | // Test create | 247 | // Test create |
246 | Sink::ApplicationDomain::Event event2; | 248 | Event event2; |
247 | { | 249 | { |
248 | QTRY_COMPARE(model->rowCount(QModelIndex()), 1); | 250 | QTRY_COMPARE(model->rowCount(QModelIndex()), 1); |
249 | auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Event::Ptr>(); | 251 | auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Event::Ptr>(); |
250 | QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); | 252 | QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); |
251 | QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue")); | 253 | QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue")); |
252 | event2 = *value; | 254 | event2 = *value; |
@@ -254,18 +256,18 @@ private slots: | |||
254 | 256 | ||
255 | event2.setProperty("uid", "testuid"); | 257 | event2.setProperty("uid", "testuid"); |
256 | event2.setProperty("summary", "summaryValue2"); | 258 | event2.setProperty("summary", "summaryValue2"); |
257 | Sink::Store::modify<Sink::ApplicationDomain::Event>(event2).exec().waitForFinished(); | 259 | Sink::Store::modify<Event>(event2).exec().waitForFinished(); |
258 | 260 | ||
259 | // Test modify | 261 | // Test modify |
260 | { | 262 | { |
261 | // TODO wait for a change signal | 263 | // TODO wait for a change signal |
262 | QTRY_COMPARE(model->rowCount(QModelIndex()), 1); | 264 | QTRY_COMPARE(model->rowCount(QModelIndex()), 1); |
263 | auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Event::Ptr>(); | 265 | auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Event::Ptr>(); |
264 | QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); | 266 | QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); |
265 | QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue2")); | 267 | QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue2")); |
266 | } | 268 | } |
267 | 269 | ||
268 | Sink::Store::remove<Sink::ApplicationDomain::Event>(event2).exec().waitForFinished(); | 270 | Sink::Store::remove<Event>(event2).exec().waitForFinished(); |
269 | 271 | ||
270 | // Test remove | 272 | // Test remove |
271 | { | 273 | { |