summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-09-27 16:13:47 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-09-27 16:13:47 +0200
commit529db49c496f4f668cec3f7c59d2d0ec78c50c9a (patch)
treeb7622a54b4063f4dc735a8b4061525148377b6c9 /tests
parent577c2c344079c1a87d3d93be5f957e5f2d935bff (diff)
downloadsink-529db49c496f4f668cec3f7c59d2d0ec78c50c9a.tar.gz
sink-529db49c496f4f668cec3f7c59d2d0ec78c50c9a.zip
Don't hardcode the type property.
Diffstat (limited to 'tests')
-rw-r--r--tests/accountstest.cpp22
-rw-r--r--tests/resourceconfigtest.cpp39
2 files changed, 32 insertions, 29 deletions
diff --git a/tests/accountstest.cpp b/tests/accountstest.cpp
index e0a99c2..260602c 100644
--- a/tests/accountstest.cpp
+++ b/tests/accountstest.cpp
@@ -22,8 +22,8 @@ private slots:
22 22
23 void init() 23 void init()
24 { 24 {
25 ConfigStore("accounts").clear(); 25 ConfigStore("accounts", "type").clear();
26 ConfigStore("resources").clear(); 26 ConfigStore("resources", Sink::ApplicationDomain::SinkResource::ResourceType::name).clear();
27 } 27 }
28 28
29 void testLoad() 29 void testLoad()
@@ -34,17 +34,17 @@ private slots:
34 QString accountName("name"); 34 QString accountName("name");
35 QString accountIcon("icon"); 35 QString accountIcon("icon");
36 auto account = ApplicationDomainType::createEntity<SinkAccount>(); 36 auto account = ApplicationDomainType::createEntity<SinkAccount>();
37 account.setProperty("type", "maildir"); 37 account.setAccountType("maildir");
38 account.setProperty("name", accountName); 38 account.setName(accountName);
39 account.setProperty("icon", accountIcon); 39 account.setIcon(accountIcon);
40 Store::create(account).exec().waitForFinished(); 40 Store::create(account).exec().waitForFinished();
41 41
42 Store::fetchAll<SinkAccount>(Query()).syncThen<void, QList<SinkAccount::Ptr>>([&](const QList<SinkAccount::Ptr> &accounts) { 42 Store::fetchAll<SinkAccount>(Query()).syncThen<void, QList<SinkAccount::Ptr>>([&](const QList<SinkAccount::Ptr> &accounts) {
43 QCOMPARE(accounts.size(), 1); 43 QCOMPARE(accounts.size(), 1);
44 auto account = accounts.first(); 44 auto account = accounts.first();
45 QCOMPARE(account->getProperty("type").toString(), QString("maildir")); 45 QCOMPARE(account->getAccountType(), QString("maildir"));
46 QCOMPARE(account->getProperty("name").toString(), accountName); 46 QCOMPARE(account->getName(), accountName);
47 QCOMPARE(account->getProperty("icon").toString(), accountIcon); 47 QCOMPARE(account->getIcon(), accountIcon);
48 }) 48 })
49 .exec().waitForFinished(); 49 .exec().waitForFinished();
50 50
@@ -52,8 +52,8 @@ private slots:
52 QString smtpUsername("smtpUsername"); 52 QString smtpUsername("smtpUsername");
53 QString smtpPassword("smtpPassword"); 53 QString smtpPassword("smtpPassword");
54 auto resource = ApplicationDomainType::createEntity<SinkResource>(); 54 auto resource = ApplicationDomainType::createEntity<SinkResource>();
55 resource.setProperty("type", "sink.mailtransport"); 55 resource.setResourceType("sink.mailtransport");
56 resource.setProperty("account", account.identifier()); 56 resource.setAccount(account);
57 resource.setProperty("server", smtpServer); 57 resource.setProperty("server", smtpServer);
58 resource.setProperty("username", smtpUsername); 58 resource.setProperty("username", smtpUsername);
59 resource.setProperty("password", smtpPassword); 59 resource.setProperty("password", smtpPassword);
@@ -63,7 +63,7 @@ private slots:
63 Store::fetchAll<SinkResource>(Query()).syncThen<void, QList<SinkResource::Ptr>>([&](const QList<SinkResource::Ptr> &resources) { 63 Store::fetchAll<SinkResource>(Query()).syncThen<void, QList<SinkResource::Ptr>>([&](const QList<SinkResource::Ptr> &resources) {
64 QCOMPARE(resources.size(), 1); 64 QCOMPARE(resources.size(), 1);
65 auto resource = resources.first(); 65 auto resource = resources.first();
66 QCOMPARE(resource->getProperty("type").toString(), QString("sink.mailtransport")); 66 QCOMPARE(resource->getResourceType(), QByteArray("sink.mailtransport"));
67 QCOMPARE(resource->getProperty("server").toString(), smtpServer); 67 QCOMPARE(resource->getProperty("server").toString(), smtpServer);
68 }) 68 })
69 .exec().waitForFinished(); 69 .exec().waitForFinished();
diff --git a/tests/resourceconfigtest.cpp b/tests/resourceconfigtest.cpp
index 70a37f0..c06b0fb 100644
--- a/tests/resourceconfigtest.cpp
+++ b/tests/resourceconfigtest.cpp
@@ -11,6 +11,9 @@
11#include "test.h" 11#include "test.h"
12#include "testutils.h" 12#include "testutils.h"
13 13
14using namespace Sink;
15using namespace Sink::ApplicationDomain;
16
14/** 17/**
15 * Test of the resource configuration. 18 * Test of the resource configuration.
16 */ 19 */
@@ -31,43 +34,43 @@ private slots:
31 ResourceConfig::clear(); 34 ResourceConfig::clear();
32 Sink::FacadeFactory::instance().registerStaticFacades(); 35 Sink::FacadeFactory::instance().registerStaticFacades();
33 36
34 Sink::ApplicationDomain::SinkResource res("", "dummyresource.identifier1", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); 37 SinkResource res("", "dummyresource.identifier1", 0, QSharedPointer<MemoryBufferAdaptor>::create());
35 res.setProperty("identifier", "dummyresource.identifier1"); 38 res.setProperty("identifier", "dummyresource.identifier1");
36 res.setProperty("type", "dummyresource"); 39 res.setProperty(SinkResource::ResourceType::name, "dummyresource");
37 40
38 Sink::Store::create(res).exec().waitForFinished(); 41 Sink::Store::create(res).exec().waitForFinished();
39 { 42 {
40 Sink::Query query; 43 Sink::Query query;
41 query.filter("type", Sink::Query::Comparator("dummyresource")); 44 query.filter<SinkResource::ResourceType>("dummyresource");
42 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::SinkResource>(query); 45 auto model = Sink::Store::loadModel<SinkResource>(query);
43 QTRY_COMPARE(model->rowCount(QModelIndex()), 1); 46 QTRY_COMPARE(model->rowCount(QModelIndex()), 1);
44 } 47 }
45 48
46 Sink::Store::remove(res).exec().waitForFinished(); 49 Sink::Store::remove(res).exec().waitForFinished();
47 { 50 {
48 Sink::Query query; 51 Sink::Query query;
49 query.filter("type", Sink::Query::Comparator("dummyresource")); 52 query.filter<SinkResource::ResourceType>("dummyresource");
50 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::SinkResource>(query); 53 auto model = Sink::Store::loadModel<SinkResource>(query);
51 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 54 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
52 QCOMPARE(model->rowCount(QModelIndex()), 0); 55 QCOMPARE(model->rowCount(QModelIndex()), 0);
53 } 56 }
54 } 57 }
55 58
56 void testLoadResourceByCapabiity() 59 void testLoadResourceByCapability()
57 { 60 {
58 ResourceConfig::clear(); 61 ResourceConfig::clear();
59 Sink::FacadeFactory::instance().registerStaticFacades(); 62 Sink::FacadeFactory::instance().registerStaticFacades();
60 63
61 Sink::ApplicationDomain::SinkResource res("", "dummyresource.identifier1", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); 64 SinkResource res("", "dummyresource.identifier1", 0, QSharedPointer<MemoryBufferAdaptor>::create());
62 res.setProperty("identifier", "dummyresource.identifier1"); 65 res.setProperty("identifier", "dummyresource.identifier1");
63 res.setProperty("type", "dummyresource"); 66 res.setResourceType("dummyresource");
64 res.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << "foo")); 67 res.setCapabilities(QByteArrayList() << "foo");
65 68
66 Sink::Store::create(res).exec().waitForFinished(); 69 Sink::Store::create(res).exec().waitForFinished();
67 { 70 {
68 Sink::Query query; 71 Sink::Query query;
69 query.filter("type", Sink::Query::Comparator("dummyresource")); 72 query.filter<SinkResource::ResourceType>("dummyresource");
70 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::SinkResource>(Sink::Query::CapabilityFilter("foo")); 73 auto model = Sink::Store::loadModel<SinkResource>(Query().containsFilter<SinkResource::Capabilities>("foo"));
71 QTRY_COMPARE(model->rowCount(QModelIndex()), 1); 74 QTRY_COMPARE(model->rowCount(QModelIndex()), 1);
72 } 75 }
73 76
@@ -79,20 +82,20 @@ private slots:
79 ResourceConfig::clear(); 82 ResourceConfig::clear();
80 Sink::FacadeFactory::instance().registerStaticFacades(); 83 Sink::FacadeFactory::instance().registerStaticFacades();
81 84
82 auto res = Sink::ApplicationDomain::DummyResource::create(""); 85 auto res = DummyResource::create("");
83 VERIFYEXEC(Sink::Store::create(res)); 86 VERIFYEXEC(Sink::Store::create(res));
84 { 87 {
85 Sink::Query query; 88 Sink::Query query;
86 query.liveQuery = true; 89 query.liveQuery = true;
87 query.request<Sink::ApplicationDomain::SinkResource::Status>(); 90 query.request<SinkResource::Status>();
88 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::SinkResource>(query); 91 auto model = Sink::Store::loadModel<SinkResource>(query);
89 QTRY_COMPARE(model->rowCount(QModelIndex()), 1); 92 QTRY_COMPARE(model->rowCount(QModelIndex()), 1);
90 auto resource = model->data(model->index(0, 0, QModelIndex()), Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::SinkResource::Ptr>(); 93 auto resource = model->data(model->index(0, 0, QModelIndex()), Sink::Store::DomainObjectRole).value<SinkResource::Ptr>();
91 QCOMPARE(resource->getStatus(), static_cast<int>(Sink::ApplicationDomain::OfflineStatus)); 94 QCOMPARE(resource->getStatus(), static_cast<int>(OfflineStatus));
92 95
93 //Synchronize to connect 96 //Synchronize to connect
94 VERIFYEXEC(Sink::Store::synchronize(query)); 97 VERIFYEXEC(Sink::Store::synchronize(query));
95 QTRY_COMPARE(model->data(model->index(0, 0, QModelIndex()), Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::SinkResource::Ptr>()->getStatus(), static_cast<int>(Sink::ApplicationDomain::ConnectedStatus)); 98 QTRY_COMPARE(model->data(model->index(0, 0, QModelIndex()), Sink::Store::DomainObjectRole).value<SinkResource::Ptr>()->getStatus(), static_cast<int>(ConnectedStatus));
96 } 99 }
97 100
98 VERIFYEXEC(Sink::Store::remove(res)); 101 VERIFYEXEC(Sink::Store::remove(res));