diff options
Diffstat (limited to 'site')
-rw-r--r-- | site/custom.cpp | 39 | ||||
-rw-r--r-- | site/test.cpp | 99 |
2 files changed, 67 insertions, 71 deletions
diff --git a/site/custom.cpp b/site/custom.cpp index 5d955a2..00dcb6a 100644 --- a/site/custom.cpp +++ b/site/custom.cpp @@ -7,27 +7,27 @@ namespace MirrorSearch { // Route name: download // path: /download/{filename} class download : public IceSpider::IRouteHandler { - public: - download(const IceSpider::Core * core) : - IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/download/{filename}"), - prx0(core->getProxy<MirrorSearch::Search>()), - _pi_filename(1) - { + public: + download(const IceSpider::Core * core) : + IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/download/{filename}"), + prx0(core->getProxy<MirrorSearch::Search>()), _pi_filename(1) + { + } + + void + execute(IceSpider::IHttpRequest * request) const + { + auto _p_filename(request->getURLParam<::std::string>(_pi_filename)); + auto _responseModel = prx0->feelingLucky(_p_filename, request->getContext()); + if (_responseModel) { + request->responseRedirect(*_responseModel, "Mirror found"s); } + request->response(404, "No mirror found"); + } - void execute(IceSpider::IHttpRequest * request) const - { - auto _p_filename(request->getURLParam<::std::string>(_pi_filename)); - auto _responseModel = prx0->feelingLucky(_p_filename, request->getContext()); - if (_responseModel) { - request->responseRedirect(*_responseModel, "Mirror found"s); - } - request->response(404, "No mirror found"); - } - - private: - const MirrorSearch::SearchPrxPtr prx0; - const unsigned int _pi_filename; + private: + const MirrorSearch::SearchPrxPtr prx0; + const unsigned int _pi_filename; }; } // namespace MirrorSearch @@ -36,4 +36,3 @@ namespace MirrorSearch { FACTORY(MirrorSearch::download, IceSpider::RouteHandlerFactory); // End generated code. - diff --git a/site/test.cpp b/site/test.cpp index 4cd9763..bcff64b 100644 --- a/site/test.cpp +++ b/site/test.cpp @@ -1,68 +1,66 @@ #define BOOST_TEST_MODULE mirrorsearchsite #include <boost/test/unit_test.hpp> -#include <testRequest.h> -#include <core.h> #include <api.h> +#include <core.h> +#include <testRequest.h> -#include <Ice/ObjectAdapter.h> #include <Ice/Initialize.h> +#include <Ice/ObjectAdapter.h> using namespace IceSpider; using namespace MirrorSearch; class TestSerice : public Search { - public: - virtual SearchServices getServices(const ::Ice::Current& = ::Ice::Current()) override - { - return {}; +public: + virtual SearchServices + getServices(const ::Ice::Current & = ::Ice::Current()) override + { + return {}; + } + virtual SearchHits + getMatches(const ::std::string fn, const ::Ice::Current & = ::Ice::Current()) override + { + BOOST_TEST_INFO(fn); + if (fn == "good.txt") { + return {std::make_shared<SearchHit>(1, 1, "file:///some/file/path"), + std::make_shared<SearchHit>(1, 1, "file:///some/other/path")}; } - virtual SearchHits getMatches(const ::std::string fn, const ::Ice::Current& = ::Ice::Current()) override - { - BOOST_TEST_INFO(fn); - if (fn == "good.txt") { - return { - std::make_shared<SearchHit>(1, 1, "file:///some/file/path"), - std::make_shared<SearchHit>(1, 1, "file:///some/other/path") - }; - } - return {}; - } - virtual ::Ice::optional<::std::string> feelingLucky(const ::std::string fn, const ::Ice::Current & c = ::Ice::Current()) override - { - auto ms = getMatches(fn, c); - if (ms.empty()) { - return IceUtil::None; - - } - return ms.front()->url; + return {}; + } + virtual ::Ice::optional<::std::string> + feelingLucky(const ::std::string fn, const ::Ice::Current & c = ::Ice::Current()) override + { + auto ms = getMatches(fn, c); + if (ms.empty()) { + return IceUtil::None; } + return ms.front()->url; + } }; class TestApp : public CoreWithDefaultRouter { - public: - TestApp() : - CoreWithDefaultRouter({ - "--MirrorSearch.Search=Search" - }), - adp(communicator->createObjectAdapterWithEndpoints("test", "default")) - { - adp->activate(); - adp->add(std::make_shared<TestSerice>(), Ice::stringToIdentity("Search")); - } - - ~TestApp() - { - adp->deactivate(); - adp->destroy(); - } - - Ice::ObjectAdapterPtr adp; +public: + TestApp() : + CoreWithDefaultRouter({"--MirrorSearch.Search=Search"}), + adp(communicator->createObjectAdapterWithEndpoints("test", "default")) + { + adp->activate(); + adp->add(std::make_shared<TestSerice>(), Ice::stringToIdentity("Search")); + } + + ~TestApp() + { + adp->deactivate(); + adp->destroy(); + } + + Ice::ObjectAdapterPtr adp; }; BOOST_FIXTURE_TEST_SUITE(ta, TestApp); -BOOST_AUTO_TEST_CASE( testCallIndexNoFile ) +BOOST_AUTO_TEST_CASE(testCallIndexNoFile) { TestRequest requestGetIndex(this, HttpMethod::GET, "/list"); process(&requestGetIndex); @@ -70,7 +68,7 @@ BOOST_AUTO_TEST_CASE( testCallIndexNoFile ) BOOST_CHECK_EQUAL(h["Status"], "404 Not found"); } -BOOST_AUTO_TEST_CASE( testCallServiceList ) +BOOST_AUTO_TEST_CASE(testCallServiceList) { TestRequest requestGetIndex(this, HttpMethod::GET, "/services"); process(&requestGetIndex); @@ -79,7 +77,7 @@ BOOST_AUTO_TEST_CASE( testCallServiceList ) BOOST_CHECK_EQUAL(h["Content-Type"], "application/json"); } -BOOST_AUTO_TEST_CASE( testCallIndex ) +BOOST_AUTO_TEST_CASE(testCallIndex) { TestRequest requestGetIndex(this, HttpMethod::GET, "/list/somefile.txt"); process(&requestGetIndex); @@ -88,7 +86,7 @@ BOOST_AUTO_TEST_CASE( testCallIndex ) BOOST_CHECK_EQUAL(h["Content-Type"], "application/json"); } -BOOST_AUTO_TEST_CASE( testCallDownloadNotFile ) +BOOST_AUTO_TEST_CASE(testCallDownloadNotFile) { TestRequest requestGetIndex(this, HttpMethod::GET, "/download"); process(&requestGetIndex); @@ -96,7 +94,7 @@ BOOST_AUTO_TEST_CASE( testCallDownloadNotFile ) BOOST_CHECK_EQUAL(h["Status"], "404 Not found"); } -BOOST_AUTO_TEST_CASE( testCallDownloadBad ) +BOOST_AUTO_TEST_CASE(testCallDownloadBad) { TestRequest requestGetIndex(this, HttpMethod::GET, "/download/bad.txt"); process(&requestGetIndex); @@ -104,7 +102,7 @@ BOOST_AUTO_TEST_CASE( testCallDownloadBad ) BOOST_CHECK_EQUAL(h["Status"], "404 No mirror found"); } -BOOST_AUTO_TEST_CASE( testCallDownloadGood ) +BOOST_AUTO_TEST_CASE(testCallDownloadGood) { TestRequest requestGetIndex(this, HttpMethod::GET, "/download/good.txt"); process(&requestGetIndex); @@ -114,4 +112,3 @@ BOOST_AUTO_TEST_CASE( testCallDownloadGood ) } BOOST_AUTO_TEST_SUITE_END(); - |