From ef91fc2c1fef8ed409aa60429afb4867d0dec568 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 10 May 2016 10:03:12 +0200 Subject: Fixed resource property filtering --- common/resourcefacade.cpp | 2 +- tests/CMakeLists.txt | 1 + tests/clientapitest.cpp | 28 ---------------- tests/resourceconfigtest.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 29 deletions(-) create mode 100644 tests/resourceconfigtest.cpp diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index 96e2ac3..526ce6d 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp @@ -119,7 +119,7 @@ static bool matchesFilter(const QHash &filt if (filterProperty == "type") { continue; } - if (filter.value(filterProperty).matches(properties.value(filterProperty))) { + if (!filter.value(filterProperty).matches(properties.value(filterProperty))) { return false; } } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b97596a..c9f7591 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -40,6 +40,7 @@ manual_tests ( auto_tests ( clientapitest + resourceconfigtest storagetest dummyresourcetest domainadaptortest diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index 96982ca..7f9f422 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp @@ -119,34 +119,6 @@ private slots: QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); } - // TODO: This test doesn't belong to this testsuite - void resourceManagement() - { - ResourceConfig::clear(); - Sink::FacadeFactory::instance().registerStaticFacades(); - - Sink::ApplicationDomain::SinkResource res("", "dummyresource.identifier1", 0, QSharedPointer::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(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(query); - QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); - QCOMPARE(model->rowCount(QModelIndex()), 0); - } - } - void testModelSingle() { auto facade = DummyResourceFacade::registerFacade(); diff --git a/tests/resourceconfigtest.cpp b/tests/resourceconfigtest.cpp new file mode 100644 index 0000000..bebff50 --- /dev/null +++ b/tests/resourceconfigtest.cpp @@ -0,0 +1,78 @@ +#include +#include +#include + +#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::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(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(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::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::Query::CapabilityFilter("foo")); + QTRY_COMPARE(model->rowCount(QModelIndex()), 1); + } + + Sink::Store::remove(res).exec().waitForFinished(); + } + +}; + +QTEST_MAIN(ResourceConfigTest) +#include "resourceconfigtest.moc" -- cgit v1.2.3