Changeset View
Changeset View
Standalone View
Standalone View
tests/entitystoretest.cpp
Show All 12 Lines | 12 | { | |||
---|---|---|---|---|---|
13 | Q_OBJECT | 13 | Q_OBJECT | ||
14 | private: | 14 | private: | ||
15 | QString resourceInstanceIdentifier{"resourceId"}; | 15 | QString resourceInstanceIdentifier{"resourceId"}; | ||
16 | 16 | | |||
17 | private slots: | 17 | private slots: | ||
18 | void initTestCase() | 18 | void initTestCase() | ||
19 | { | 19 | { | ||
20 | Sink::AdaptorFactoryRegistry::instance().registerFactory<Sink::ApplicationDomain::Mail, TestMailAdaptorFactory>("test"); | 20 | Sink::AdaptorFactoryRegistry::instance().registerFactory<Sink::ApplicationDomain::Mail, TestMailAdaptorFactory>("test"); | ||
21 | Sink::AdaptorFactoryRegistry::instance().registerFactory<Sink::ApplicationDomain::Event, TestEventAdaptorFactory>("test"); | ||||
21 | } | 22 | } | ||
22 | 23 | | |||
23 | void cleanup() | 24 | void cleanup() | ||
24 | { | 25 | { | ||
25 | Sink::Storage::DataStore(Sink::storageLocation(), resourceInstanceIdentifier).removeFromDisk(); | 26 | Sink::Storage::DataStore(Sink::storageLocation(), resourceInstanceIdentifier).removeFromDisk(); | ||
26 | } | 27 | } | ||
27 | 28 | | |||
28 | void testCleanup() | 29 | void testCleanup() | ||
29 | { | 30 | { | ||
30 | } | 31 | } | ||
31 | 32 | | |||
33 | void testFullScan() | ||||
34 | { | ||||
35 | using namespace Sink; | ||||
36 | ResourceContext resourceContext{resourceInstanceIdentifier.toUtf8(), "dummy", AdaptorFactoryRegistry::instance().getFactories("test")}; | ||||
37 | Storage::EntityStore store(resourceContext, {}); | ||||
38 | | ||||
39 | auto mail = ApplicationDomain::ApplicationDomainType::createEntity<ApplicationDomain::Mail>("res1"); | ||||
40 | mail.setExtractedMessageId("messageid"); | ||||
41 | mail.setExtractedSubject("boo"); | ||||
42 | | ||||
43 | auto mail2 = ApplicationDomain::ApplicationDomainType::createEntity<ApplicationDomain::Mail>("res1"); | ||||
44 | mail2.setExtractedMessageId("messageid2"); | ||||
45 | mail2.setExtractedSubject("foo"); | ||||
46 | | ||||
47 | auto mail3 = ApplicationDomain::ApplicationDomainType::createEntity<ApplicationDomain::Mail>("res1"); | ||||
48 | mail3.setExtractedMessageId("messageid2"); | ||||
49 | mail3.setExtractedSubject("foo"); | ||||
50 | | ||||
51 | store.startTransaction(Storage::DataStore::ReadWrite); | ||||
52 | store.add("mail", mail, false); | ||||
53 | store.add("mail", mail2, false); | ||||
54 | store.add("mail", mail3, false); | ||||
55 | | ||||
56 | mail.setExtractedSubject("foo"); | ||||
57 | | ||||
58 | store.modify("mail", mail, QByteArrayList{}, false); | ||||
59 | | ||||
60 | { | ||||
61 | const auto ids = store.fullScan("mail"); | ||||
62 | | ||||
63 | QCOMPARE(ids.size(), 3); | ||||
64 | QVERIFY(ids.contains(Sink::Storage::Identifier::fromDisplayByteArray(mail.identifier()))); | ||||
65 | QVERIFY(ids.contains(Sink::Storage::Identifier::fromDisplayByteArray(mail2.identifier()))); | ||||
66 | QVERIFY(ids.contains(Sink::Storage::Identifier::fromDisplayByteArray(mail3.identifier()))); | ||||
67 | } | ||||
68 | | ||||
69 | store.remove("mail", mail3, false); | ||||
70 | store.commitTransaction(); | ||||
71 | | ||||
72 | { | ||||
73 | const auto ids = store.fullScan("mail"); | ||||
74 | | ||||
75 | QCOMPARE(ids.size(), 2); | ||||
76 | QVERIFY(ids.contains(Sink::Storage::Identifier::fromDisplayByteArray(mail.identifier()))); | ||||
77 | QVERIFY(ids.contains(Sink::Storage::Identifier::fromDisplayByteArray(mail2.identifier()))); | ||||
78 | } | ||||
79 | } | ||||
80 | | ||||
81 | void testExistsAndContains() | ||||
82 | { | ||||
83 | | ||||
84 | using namespace Sink; | ||||
85 | ResourceContext resourceContext{resourceInstanceIdentifier.toUtf8(), "dummy", AdaptorFactoryRegistry::instance().getFactories("test")}; | ||||
86 | Storage::EntityStore store(resourceContext, {}); | ||||
87 | | ||||
88 | auto mail = ApplicationDomain::ApplicationDomainType::createEntity<ApplicationDomain::Mail>("res1"); | ||||
89 | mail.setExtractedMessageId("messageid"); | ||||
90 | mail.setExtractedSubject("boo"); | ||||
91 | | ||||
92 | auto mail2 = ApplicationDomain::ApplicationDomainType::createEntity<ApplicationDomain::Mail>("res1"); | ||||
93 | mail2.setExtractedMessageId("messageid2"); | ||||
94 | mail2.setExtractedSubject("foo"); | ||||
95 | | ||||
96 | auto mail3 = ApplicationDomain::ApplicationDomainType::createEntity<ApplicationDomain::Mail>("res1"); | ||||
97 | mail3.setExtractedMessageId("messageid2"); | ||||
98 | mail3.setExtractedSubject("foo"); | ||||
99 | | ||||
100 | auto event = ApplicationDomain::ApplicationDomainType::createEntity<ApplicationDomain::Event>("res1"); | ||||
101 | event.setExtractedUid("messageid2"); | ||||
102 | event.setExtractedSummary("foo"); | ||||
103 | | ||||
104 | store.startTransaction(Storage::DataStore::ReadWrite); | ||||
105 | store.add("mail", mail, false); | ||||
106 | store.add("mail", mail2, false); | ||||
107 | store.add("mail", mail3, false); | ||||
108 | store.add("event", event, false); | ||||
109 | | ||||
110 | mail.setExtractedSubject("foo"); | ||||
111 | | ||||
112 | store.modify("mail", mail, QByteArrayList{}, false); | ||||
113 | store.remove("mail", mail3, false); | ||||
114 | store.commitTransaction(); | ||||
115 | | ||||
116 | QVERIFY(store.contains("mail", mail.identifier())); | ||||
117 | QVERIFY(store.contains("mail", mail2.identifier())); | ||||
118 | QVERIFY(store.contains("mail", mail3.identifier())); | ||||
119 | QVERIFY(store.contains("event", event.identifier())); | ||||
120 | | ||||
121 | QVERIFY(store.exists("mail", mail.identifier())); | ||||
122 | QVERIFY(store.exists("mail", mail2.identifier())); | ||||
123 | QVERIFY(!store.exists("mail", mail3.identifier())); | ||||
124 | QVERIFY(store.exists("event", event.identifier())); | ||||
125 | } | ||||
126 | | ||||
32 | void readAll() | 127 | void readAll() | ||
33 | { | 128 | { | ||
34 | using namespace Sink; | 129 | using namespace Sink; | ||
35 | ResourceContext resourceContext{resourceInstanceIdentifier.toUtf8(), "dummy", AdaptorFactoryRegistry::instance().getFactories("test")}; | 130 | ResourceContext resourceContext{resourceInstanceIdentifier.toUtf8(), "dummy", AdaptorFactoryRegistry::instance().getFactories("test")}; | ||
36 | Storage::EntityStore store(resourceContext, {}); | 131 | Storage::EntityStore store(resourceContext, {}); | ||
37 | 132 | | |||
38 | auto mail = ApplicationDomain::ApplicationDomainType::createEntity<ApplicationDomain::Mail>("res1"); | 133 | auto mail = ApplicationDomain::ApplicationDomainType::createEntity<ApplicationDomain::Mail>("res1"); | ||
39 | mail.setExtractedMessageId("messageid"); | 134 | mail.setExtractedMessageId("messageid"); | ||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |