diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2018-03-06 19:43:22 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2018-03-06 19:43:22 +0000 |
commit | 3131fa0db3000fb5c944e3822361de6fe7bb1b82 (patch) | |
tree | da0cfea27a5d0099eae95a1a1821b71b54afa644 /site/test.cpp | |
parent | Initial commit, WIP (diff) | |
download | mirrorsearch-3131fa0db3000fb5c944e3822361de6fe7bb1b82.tar.bz2 mirrorsearch-3131fa0db3000fb5c944e3822361de6fe7bb1b82.tar.xz mirrorsearch-3131fa0db3000fb5c944e3822361de6fe7bb1b82.zip |
Add basic site setup
Diffstat (limited to 'site/test.cpp')
-rw-r--r-- | site/test.cpp | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/site/test.cpp b/site/test.cpp new file mode 100644 index 0000000..7fcc2ae --- /dev/null +++ b/site/test.cpp @@ -0,0 +1,107 @@ +#define BOOST_TEST_MODULE mirrorsearchsite +#include <boost/test/unit_test.hpp> + +#include <testRequest.h> +#include <core.h> +#include <api.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 {}; + } + virtual SearchHits getMatches(const ::std::string & fn, const ::Ice::Current& = ::Ice::Current()) override + { + BOOST_TEST_INFO(fn); + if (fn == "good.txt") { + return { + new SearchHit(1, 1, "file:///some/file/path"), + new SearchHit(1, 1, "file:///some/other/path") + }; + } + return {}; + } + virtual ::IceUtil::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(new TestSerice(), communicator->stringToIdentity("Search")); + } + + ~TestApp() + { + adp->deactivate(); + adp->destroy(); + } + + Ice::ObjectAdapterPtr adp; +}; + +BOOST_FIXTURE_TEST_SUITE(ta, TestApp); + +BOOST_AUTO_TEST_CASE( testCallIndexNoFile ) +{ + TestRequest requestGetIndex(this, HttpMethod::GET, "/list"); + process(&requestGetIndex); + auto h = requestGetIndex.getResponseHeaders(); + BOOST_CHECK_EQUAL(h["Status"], "404 Not found"); +} + +BOOST_AUTO_TEST_CASE( testCallIndex ) +{ + TestRequest requestGetIndex(this, HttpMethod::GET, "/list/somefile.txt"); + process(&requestGetIndex); + auto h = requestGetIndex.getResponseHeaders(); + BOOST_CHECK_EQUAL(h["Status"], "200 OK"); + BOOST_CHECK_EQUAL(h["Content-Type"], "application/json"); +} + +BOOST_AUTO_TEST_CASE( testCallDownloadNotFile ) +{ + TestRequest requestGetIndex(this, HttpMethod::GET, "/download"); + process(&requestGetIndex); + auto h = requestGetIndex.getResponseHeaders(); + BOOST_CHECK_EQUAL(h["Status"], "404 Not found"); +} + +BOOST_AUTO_TEST_CASE( testCallDownloadBad ) +{ + TestRequest requestGetIndex(this, HttpMethod::GET, "/download/bad.txt"); + process(&requestGetIndex); + auto h = requestGetIndex.getResponseHeaders(); + BOOST_CHECK_EQUAL(h["Status"], "404 No mirror found"); +} + +BOOST_AUTO_TEST_CASE( testCallDownloadGood ) +{ + TestRequest requestGetIndex(this, HttpMethod::GET, "/download/good.txt"); + process(&requestGetIndex); + auto h = requestGetIndex.getResponseHeaders(); + BOOST_CHECK_EQUAL(h["Status"], "303 Mirror found"); + BOOST_CHECK_EQUAL(h["Location"], "file:///some/file/path"); +} + +BOOST_AUTO_TEST_SUITE_END(); + |