diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-09-24 15:32:47 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-09-24 15:41:07 +0100 |
commit | 177cf1b6922919627cb96b9f8e6e3dc4238346dc (patch) | |
tree | 55bfabd536129230f5dd8e2b2ba89601537fb4af | |
parent | Remove unused util functions (diff) | |
download | gentoobrowse-api-177cf1b6922919627cb96b9f8e6e3dc4238346dc.tar.bz2 gentoobrowse-api-177cf1b6922919627cb96b9f8e6e3dc4238346dc.tar.xz gentoobrowse-api-177cf1b6922919627cb96b9f8e6e3dc4238346dc.zip |
Throw and transport ICE exceptions when things aren't found
-rw-r--r-- | gentoobrowse-api/api/Jamfile.jam | 8 | ||||
-rw-r--r-- | gentoobrowse-api/api/portage.ice | 13 | ||||
-rw-r--r-- | gentoobrowse-api/service/portageimpl.cpp | 4 | ||||
-rw-r--r-- | gentoobrowse-api/service/portageimpl.h | 2 | ||||
-rw-r--r-- | gentoobrowse-api/unittests/testPortage.cpp | 28 |
5 files changed, 39 insertions, 16 deletions
diff --git a/gentoobrowse-api/api/Jamfile.jam b/gentoobrowse-api/api/Jamfile.jam index 1f6b931..6cd2480 100644 --- a/gentoobrowse-api/api/Jamfile.jam +++ b/gentoobrowse-api/api/Jamfile.jam @@ -1,12 +1,20 @@ +lib slicer-db : : : : + <include>/usr/include/slicer/db + <include>/usr/include/slicer/slicer + ; + lib gentoobrowse-api : [ glob *.cpp *.ice ] : <library>..//adhocutil <library>..//dbppcore <library>../domain//gentoobrowse-domain + <include>/usr/share/slicer/ice + <library>slicer-db <implicit-dependency>../domain//gentoobrowse-domain : : <include>. + <library>slicer-db <library>../domain//gentoobrowse-domain <implicit-dependency>../domain//gentoobrowse-domain ; diff --git a/gentoobrowse-api/api/portage.ice b/gentoobrowse-api/api/portage.ice index 56d066b..584aee5 100644 --- a/gentoobrowse-api/api/portage.ice +++ b/gentoobrowse-api/api/portage.ice @@ -1,17 +1,18 @@ #include <portage-models.ice> #include <extended-models.ice> +#include <sqlExceptions.ice> module Gentoo { interface Portage { - idempotent Category getCategory(int id); - idempotent Category findCategory(string name); + idempotent Category getCategory(int id) throws Slicer::NoRowsReturned; + idempotent Category findCategory(string name) throws Slicer::NoRowsReturned; idempotent Categories getAllCategories(); idempotent Categories getCategoriesInSuper(string super); idempotent OverviewCategoriesBySuper getAllOverviewCategories(); idempotent OverviewCategories getOverviewCategoriesInSuper(string super); - idempotent Package getPackage(int id); - idempotent optional(0) Package findPackage(string category, string package); + idempotent Package getPackage(int id) throws Slicer::NoRowsReturned; + idempotent Package findPackage(string category, string package) throws Slicer::NoRowsReturned; idempotent Packages getAllPackages(); idempotent Packages getPackagesInCategory(int id); idempotent SearchResultPackages getPackagesSearch(string query); @@ -23,11 +24,11 @@ module Gentoo { idempotent Categories getCategoriesWithRecentAdditions(int syncs); idempotent Packages getTopTrackedPackages(int n); - idempotent Bug getBug(int id); + idempotent Bug getBug(int id) throws Slicer::NoRowsReturned; idempotent Bugs getPackageBugs(int packageId); idempotent SearchResultBugs getBugsSearch(string query); - idempotent NewsItem getNewsItem(string newsid); + idempotent NewsItem getNewsItem(string newsid) throws Slicer::NoRowsReturned; idempotent News getNewsSearch(string query); idempotent News getNewsRecent(int items); }; diff --git a/gentoobrowse-api/service/portageimpl.cpp b/gentoobrowse-api/service/portageimpl.cpp index cf03f23..2147307 100644 --- a/gentoobrowse-api/service/portageimpl.cpp +++ b/gentoobrowse-api/service/portageimpl.cpp @@ -79,10 +79,10 @@ Portage::getPackage(Ice::Int id, const Ice::Current &) return fetchCache<Gentoo::PackagePtr>(sql::portage::getPackage, 30, id); } -IceUtil::Optional<Gentoo::PackagePtr> +Gentoo::PackagePtr Portage::findPackage(const std::string & cat, const std::string & pkg, const Ice::Current &) { - return fetchCache<IceUtil::Optional<Gentoo::PackagePtr>>(sql::portage::findPackage, 30, cat, pkg); + return fetchCache<Gentoo::PackagePtr>(sql::portage::findPackage, 30, cat, pkg); } Gentoo::Packages diff --git a/gentoobrowse-api/service/portageimpl.h b/gentoobrowse-api/service/portageimpl.h index 273fbed..17c30af 100644 --- a/gentoobrowse-api/service/portageimpl.h +++ b/gentoobrowse-api/service/portageimpl.h @@ -19,7 +19,7 @@ class DLL_PUBLIC Portage : public Gentoo::Portage, IceTray::AbstractCachingDatab Gentoo::OverviewCategories getOverviewCategoriesInSuper(const std::string &, const Ice::Current &) override; Gentoo::PackagePtr getPackage(Ice::Int id, const Ice::Current &) override; - IceUtil::Optional<Gentoo::PackagePtr> findPackage(const std::string &, const std::string &, const Ice::Current &) override; + Gentoo::PackagePtr findPackage(const std::string &, const std::string &, const Ice::Current &) override; Gentoo::Packages getPackagesInCategory(Ice::Int id, const Ice::Current &) override; Gentoo::Packages getAllPackages(const Ice::Current &) override; Gentoo::SearchResultPackages getPackagesSearch(const std::string & query, const Ice::Current &) override; diff --git a/gentoobrowse-api/unittests/testPortage.cpp b/gentoobrowse-api/unittests/testPortage.cpp index 14fe16b..9cdbd1f 100644 --- a/gentoobrowse-api/unittests/testPortage.cpp +++ b/gentoobrowse-api/unittests/testPortage.cpp @@ -9,7 +9,7 @@ BOOST_FIXTURE_TEST_SUITE(tp, TestClient) BOOST_AUTO_TEST_CASE( getCategoryMissing ) { - BOOST_REQUIRE_THROW(p->getCategory(0), std::exception); + BOOST_REQUIRE_THROW(p->getCategory(0), Slicer::NoRowsReturned); } BOOST_AUTO_TEST_CASE( getCategory ) @@ -22,6 +22,11 @@ BOOST_AUTO_TEST_CASE( getCategory ) BOOST_REQUIRE_EQUAL(169, cat->summary->length()); } +BOOST_AUTO_TEST_CASE( findCategoryMissing ) +{ + BOOST_REQUIRE_THROW(p->findCategory("missing"), Slicer::NoRowsReturned); +} + BOOST_AUTO_TEST_CASE( findCategory ) { auto cat = p->findCategory("app-backup"); @@ -103,7 +108,7 @@ BOOST_AUTO_TEST_CASE( getOverviewCategoriesInSuper ) BOOST_AUTO_TEST_CASE( getPackageMissing ) { - BOOST_REQUIRE_THROW(p->getPackage(0), std::exception); + BOOST_REQUIRE_THROW(p->getPackage(0), Slicer::NoRowsReturned); } BOOST_AUTO_TEST_CASE( getPackage ) @@ -120,17 +125,16 @@ BOOST_AUTO_TEST_CASE( getPackage ) BOOST_REQUIRE_EQUAL("Default assignee for orphaned packages", pkg->maintainername); } -BOOST_AUTO_TEST_CASE( findPackage ) +BOOST_AUTO_TEST_CASE( findPackageMissing ) { - auto cat = p->findPackage("not", "here"); - BOOST_REQUIRE(!cat); + BOOST_REQUIRE_THROW(p->findPackage("not", "here"), Slicer::NoRowsReturned); } -BOOST_AUTO_TEST_CASE( findPackageMissing ) +BOOST_AUTO_TEST_CASE( findPackage ) { auto pkg = p->findPackage("dev-vcs", "archway"); BOOST_REQUIRE(pkg); - BOOST_REQUIRE_EQUAL(53258, (*pkg)->packageid); + BOOST_REQUIRE_EQUAL(53258, pkg->packageid); } BOOST_AUTO_TEST_CASE( getAllPackages ) @@ -232,6 +236,11 @@ BOOST_AUTO_TEST_CASE( getRecentAdditions ) BOOST_REQUIRE_EQUAL("GPL-2", es.front()->license); } +BOOST_AUTO_TEST_CASE( getBugMissing ) +{ + BOOST_REQUIRE_THROW(p->getBug(10), Slicer::NoRowsReturned); +} + BOOST_AUTO_TEST_CASE( getBug ) { auto b = p->getBug(567064); @@ -262,6 +271,11 @@ BOOST_AUTO_TEST_CASE( getBugsSearch ) BOOST_REQUIRE_EQUAL(567682, bs[2]->bugid); } +BOOST_AUTO_TEST_CASE( getNewsItemMissing ) +{ + BOOST_REQUIRE_THROW(p->getNewsItem("2015-02-02-use-libav"), Slicer::NoRowsReturned); +} + BOOST_AUTO_TEST_CASE( getNewsItem ) { auto n = p->getNewsItem("2015-02-01-use-libav"); |