#define BOOST_TEST_MODULE mirrorsearchsite #include #include #include #include #include #include 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") { auto a = std::make_shared(1, 1, "file:///some/file/path"), b = std::make_shared(1, 1, "file:///some/other/path"); return {std::move(a), std::move(b)}; } 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(), Ice::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(testCallServiceList) { TestRequest requestGetIndex(this, HttpMethod::GET, "/services"); 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(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();