summaryrefslogtreecommitdiffstats
path: root/tests/resourceconfigtest.cpp
blob: bebff506e8eb407bbe0b6155a6e3ed058f183941 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <QtTest>
#include <QDebug>
#include <functional>

#include "store.h"
#include "facade.h"
#include "resourceconfig.h"
#include "modelresult.h"
#include "resultprovider.h"
#include "facadefactory.h"

/**
 * Test of the resource configuration.
 */
class ResourceConfigTest : public QObject
{
    Q_OBJECT
private slots:

    void initTestCase()
    {
        Sink::FacadeFactory::instance().resetFactory();
        ResourceConfig::clear();
        Sink::Log::setDebugOutputLevel(Sink::Log::Trace);
    }

    void resourceManagement()
    {
        ResourceConfig::clear();
        Sink::FacadeFactory::instance().registerStaticFacades();

        Sink::ApplicationDomain::SinkResource res("", "dummyresource.identifier1", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
        res.setProperty("identifier", "dummyresource.identifier1");
        res.setProperty("type", "dummyresource");

        Sink::Store::create(res).exec().waitForFinished();
        {
            Sink::Query query;
            query.propertyFilter.insert("type", Sink::Query::Comparator("dummyresource"));
            auto model = Sink::Store::loadModel<Sink::ApplicationDomain::SinkResource>(query);
            QTRY_COMPARE(model->rowCount(QModelIndex()), 1);
        }

        Sink::Store::remove(res).exec().waitForFinished();
        {
            Sink::Query query;
            query.propertyFilter.insert("type", Sink::Query::Comparator("dummyresource"));
            auto model = Sink::Store::loadModel<Sink::ApplicationDomain::SinkResource>(query);
            QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
            QCOMPARE(model->rowCount(QModelIndex()), 0);
        }
    }

    void testLoadResourceByCapabiity()
    {
        ResourceConfig::clear();
        Sink::FacadeFactory::instance().registerStaticFacades();

        Sink::ApplicationDomain::SinkResource res("", "dummyresource.identifier1", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
        res.setProperty("identifier", "dummyresource.identifier1");
        res.setProperty("type", "dummyresource");
        res.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << "foo"));

        Sink::Store::create(res).exec().waitForFinished();
        {
            Sink::Query query;
            query.propertyFilter.insert("type", Sink::Query::Comparator("dummyresource"));
            auto model = Sink::Store::loadModel<Sink::ApplicationDomain::SinkResource>(Sink::Query::CapabilityFilter("foo"));
            QTRY_COMPARE(model->rowCount(QModelIndex()), 1);
        }

        Sink::Store::remove(res).exec().waitForFinished();
    }

};

QTEST_MAIN(ResourceConfigTest)
#include "resourceconfigtest.moc"