diff options
Diffstat (limited to 'tests/interresourcemovetest.cpp')
-rw-r--r-- | tests/interresourcemovetest.cpp | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/tests/interresourcemovetest.cpp b/tests/interresourcemovetest.cpp new file mode 100644 index 0000000..7561c5b --- /dev/null +++ b/tests/interresourcemovetest.cpp | |||
@@ -0,0 +1,151 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2016 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) version 3, or any | ||
8 | * later version accepted by the membership of KDE e.V. (or its | ||
9 | * successor approved by the membership of KDE e.V.), which shall | ||
10 | * act as a proxy defined in Section 6 of version 3 of the license. | ||
11 | * | ||
12 | * This library is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * Lesser General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU Lesser General Public | ||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | ||
20 | #include <QtTest> | ||
21 | |||
22 | #include <QString> | ||
23 | |||
24 | #include "dummyresource/resourcefactory.h" | ||
25 | #include "store.h" | ||
26 | #include "resourceconfig.h" | ||
27 | #include "resourcecontrol.h" | ||
28 | #include "log.h" | ||
29 | #include "test.h" | ||
30 | #include "testutils.h" | ||
31 | |||
32 | using namespace Sink; | ||
33 | using namespace Sink::ApplicationDomain; | ||
34 | |||
35 | /** | ||
36 | * Test of complete system using the dummy resource. | ||
37 | * | ||
38 | * This test requires the dummy resource installed. | ||
39 | */ | ||
40 | class InterResourceMoveTest : public QObject | ||
41 | { | ||
42 | Q_OBJECT | ||
43 | |||
44 | private slots: | ||
45 | void initTestCase() | ||
46 | { | ||
47 | Sink::Test::initTest(); | ||
48 | auto factory = Sink::ResourceFactory::load("sink.dummy"); | ||
49 | QVERIFY(factory); | ||
50 | ::DummyResource::removeFromDisk("instance1"); | ||
51 | ::DummyResource::removeFromDisk("instance2"); | ||
52 | ResourceConfig::addResource("instance1", "sink.dummy"); | ||
53 | ResourceConfig::addResource("instance2", "sink.dummy"); | ||
54 | } | ||
55 | |||
56 | void init() | ||
57 | { | ||
58 | } | ||
59 | |||
60 | void cleanup() | ||
61 | { | ||
62 | VERIFYEXEC(Sink::Store::removeDataFromDisk(QByteArray("instance1"))); | ||
63 | VERIFYEXEC(Sink::Store::removeDataFromDisk(QByteArray("instance2"))); | ||
64 | } | ||
65 | |||
66 | void testMove() | ||
67 | { | ||
68 | Event event("instance1"); | ||
69 | event.setProperty("uid", "testuid"); | ||
70 | QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); | ||
71 | event.setProperty("summary", "summaryValue"); | ||
72 | VERIFYEXEC(Sink::Store::create<Event>(event)); | ||
73 | |||
74 | |||
75 | Event createdEvent; | ||
76 | // Ensure all local data is processed | ||
77 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "instance1")); | ||
78 | { | ||
79 | auto query = Query().resourceFilter("instance1") ; | ||
80 | auto list = Sink::Store::read<Event>(query.filter<Event::Uid>("testuid")); | ||
81 | QCOMPARE(list.size(), 1); | ||
82 | createdEvent = list.first(); | ||
83 | } | ||
84 | |||
85 | VERIFYEXEC(Sink::Store::move<Event>(createdEvent, "instance2")); | ||
86 | |||
87 | //FIXME we can't guarantee that that the create command arrives at instance2 before the flush command, so we'll just wait for a little bit. | ||
88 | QTest::qWait(1000); | ||
89 | //Ensure the move has been processed | ||
90 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "instance1")); | ||
91 | //Ensure the create in the target resource has been processed | ||
92 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "instance2")); | ||
93 | { | ||
94 | auto query = Query().resourceFilter("instance2") ; | ||
95 | auto list = Sink::Store::read<Event>(query.filter<Event::Uid>("testuid")); | ||
96 | QCOMPARE(list.size(), 1); | ||
97 | } | ||
98 | |||
99 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "instance1")); | ||
100 | { | ||
101 | auto query = Query().resourceFilter("instance1") ; | ||
102 | auto list = Sink::Store::read<Event>(query.filter<Event::Uid>("testuid")); | ||
103 | QCOMPARE(list.size(), 0); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | void testCopy() | ||
108 | { | ||
109 | Event event("instance1"); | ||
110 | event.setProperty("uid", "testuid"); | ||
111 | QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); | ||
112 | event.setProperty("summary", "summaryValue"); | ||
113 | VERIFYEXEC(Sink::Store::create<Event>(event)); | ||
114 | |||
115 | |||
116 | Event createdEvent; | ||
117 | // Ensure all local data is processed | ||
118 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "instance1")); | ||
119 | { | ||
120 | auto query = Query().resourceFilter("instance1") ; | ||
121 | auto list = Sink::Store::read<Event>(query.filter<Event::Uid>("testuid")); | ||
122 | QCOMPARE(list.size(), 1); | ||
123 | createdEvent = list.first(); | ||
124 | } | ||
125 | |||
126 | VERIFYEXEC(Sink::Store::copy<Event>(createdEvent, "instance2")); | ||
127 | |||
128 | //FIXME we can't guarantee that that the create command arrives at instance2 before the flush command, so we'll just wait for a little bit. | ||
129 | QTest::qWait(100); | ||
130 | //Ensure the copy has been processed | ||
131 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "instance1")); | ||
132 | //Ensure the create in the target resource has been processed | ||
133 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "instance2")); | ||
134 | { | ||
135 | auto query = Query().resourceFilter("instance2") ; | ||
136 | auto list = Sink::Store::read<Event>(query.filter<Event::Uid>("testuid")); | ||
137 | QCOMPARE(list.size(), 1); | ||
138 | } | ||
139 | |||
140 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "instance1")); | ||
141 | { | ||
142 | auto query = Query().resourceFilter("instance1") ; | ||
143 | auto list = Sink::Store::read<Event>(query.filter<Event::Uid>("testuid")); | ||
144 | QCOMPARE(list.size(), 1); | ||
145 | } | ||
146 | } | ||
147 | |||
148 | }; | ||
149 | |||
150 | QTEST_MAIN(InterResourceMoveTest) | ||
151 | #include "interresourcemovetest.moc" | ||