diff options
-rw-r--r-- | common/domain/applicationdomaintype.h | 9 | ||||
-rw-r--r-- | tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/accountstest.cpp | 64 |
3 files changed, 74 insertions, 0 deletions
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index 9650a21..5ecd9eb 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <QVariant> | 24 | #include <QVariant> |
25 | #include <QByteArray> | 25 | #include <QByteArray> |
26 | #include <QDebug> | 26 | #include <QDebug> |
27 | #include <QUuid> | ||
27 | #include "bufferadaptor.h" | 28 | #include "bufferadaptor.h" |
28 | 29 | ||
29 | namespace Sink { | 30 | namespace Sink { |
@@ -55,6 +56,14 @@ public: | |||
55 | return QSharedPointer<DomainType>::create(domainType.mResourceInstanceIdentifier, QByteArray(domainType.mIdentifier.constData(), domainType.mIdentifier.size()), domainType.mRevision, memoryAdaptor); | 56 | return QSharedPointer<DomainType>::create(domainType.mResourceInstanceIdentifier, QByteArray(domainType.mIdentifier.constData(), domainType.mIdentifier.size()), domainType.mRevision, memoryAdaptor); |
56 | } | 57 | } |
57 | 58 | ||
59 | template <class DomainType> | ||
60 | static DomainType createEntity() | ||
61 | { | ||
62 | DomainType object; | ||
63 | object.mIdentifier = QUuid::createUuid().toByteArray(); | ||
64 | return object; | ||
65 | } | ||
66 | |||
58 | virtual ~ApplicationDomainType(); | 67 | virtual ~ApplicationDomainType(); |
59 | 68 | ||
60 | bool hasProperty(const QByteArray &key) const; | 69 | bool hasProperty(const QByteArray &key) const; |
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8045f59..b25e7bc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt | |||
@@ -54,6 +54,7 @@ auto_tests ( | |||
54 | dummyresourcewritebenchmark | 54 | dummyresourcewritebenchmark |
55 | modelinteractivitytest | 55 | modelinteractivitytest |
56 | inspectiontest | 56 | inspectiontest |
57 | accountstest | ||
57 | ) | 58 | ) |
58 | target_link_libraries(dummyresourcetest sink_resource_dummy) | 59 | target_link_libraries(dummyresourcetest sink_resource_dummy) |
59 | target_link_libraries(dummyresourcebenchmark sink_resource_dummy) | 60 | target_link_libraries(dummyresourcebenchmark sink_resource_dummy) |
diff --git a/tests/accountstest.cpp b/tests/accountstest.cpp new file mode 100644 index 0000000..0ae10ec --- /dev/null +++ b/tests/accountstest.cpp | |||
@@ -0,0 +1,64 @@ | |||
1 | #include <QTest> | ||
2 | #include <QDebug> | ||
3 | #include <QSignalSpy> | ||
4 | #include <functional> | ||
5 | |||
6 | #include <test.h> | ||
7 | #include <store.h> | ||
8 | |||
9 | class AccountsTest : public QObject | ||
10 | { | ||
11 | Q_OBJECT | ||
12 | private slots: | ||
13 | |||
14 | void initTestCase() | ||
15 | { | ||
16 | Sink::Test::initTest(); | ||
17 | } | ||
18 | |||
19 | void testLoad() | ||
20 | { | ||
21 | using namespace Sink; | ||
22 | using namespace Sink::ApplicationDomain; | ||
23 | |||
24 | QString accountName("name"); | ||
25 | QString accountIcon("icon"); | ||
26 | auto account = ApplicationDomainType::createEntity<SinkAccount>(); | ||
27 | account.setProperty("type", "maildir"); | ||
28 | account.setProperty("name", accountName); | ||
29 | account.setProperty("icon", accountIcon); | ||
30 | Store::create(account).exec().waitForFinished(); | ||
31 | |||
32 | Store::fetchAll<SinkAccount>(Query()).then<void, QList<SinkAccount>>([](const QList<SinkAccount> &accounts) { | ||
33 | QCOMPARE(accounts.size(), 1); | ||
34 | }) | ||
35 | .exec().waitForFinished(); | ||
36 | |||
37 | QString smtpServer("smtpServer"); | ||
38 | QString smtpUsername("smtpUsername"); | ||
39 | QString smtpPassword("smtpPassword"); | ||
40 | auto resource = ApplicationDomainType::createEntity<SinkResource>(); | ||
41 | resource.setProperty("type", "org.kde.mailtransport"); | ||
42 | resource.setProperty("account", account.identifier()); | ||
43 | resource.setProperty("server", smtpServer); | ||
44 | resource.setProperty("username", smtpUsername); | ||
45 | resource.setProperty("password", smtpPassword); | ||
46 | Store::create(resource).exec().waitForFinished(); | ||
47 | |||
48 | |||
49 | Store::fetchAll<SinkResource>(Query()).then<void, QList<SinkResource>>([](const QList<SinkResource> &resources) { | ||
50 | QCOMPARE(resources.size(), 1); | ||
51 | }) | ||
52 | .exec().waitForFinished(); | ||
53 | |||
54 | Store::remove(resource).exec().waitForFinished(); | ||
55 | |||
56 | Store::fetchAll<SinkResource>(Query()).then<void, QList<SinkResource>>([](const QList<SinkResource> &resources) { | ||
57 | QCOMPARE(resources.size(), 0); | ||
58 | }) | ||
59 | .exec().waitForFinished(); | ||
60 | } | ||
61 | }; | ||
62 | |||
63 | QTEST_GUILESS_MAIN(AccountsTest) | ||
64 | #include "accountstest.moc" | ||