summaryrefslogtreecommitdiff
path: root/site
diff options
context:
space:
mode:
Diffstat (limited to 'site')
-rw-r--r--site/Jamfile.jam73
-rw-r--r--site/custom.cpp38
-rw-r--r--site/search.json13
-rw-r--r--site/test.cpp107
4 files changed, 231 insertions, 0 deletions
diff --git a/site/Jamfile.jam b/site/Jamfile.jam
new file mode 100644
index 0000000..9f9f9fc
--- /dev/null
+++ b/site/Jamfile.jam
@@ -0,0 +1,73 @@
+import icespider ;
+import testing ;
+
+lib icespider-core ;
+lib icespider-common ;
+lib icespider-fcgi ;
+lib icespider-testing ;
+lib adhocutil ;
+lib Ice ;
+lib IceUtil ;
+lib pthread ;
+lib boost_system ;
+lib boost_filesystem ;
+lib slicer ;
+lib slicer-json ;
+lib slicer-db ;
+lib boost_unit_test_framework ;
+lib icespider : :
+ <name>icespider-core
+ : :
+ <include>/usr/include/icespider
+ <include>/usr/include/slicer
+ <include>/usr/include/adhocutil
+ <include>/usr/share/icespider/ice
+ <library>icespider-common
+ <library>adhocutil
+ <library>Ice
+ <library>IceUtil
+ <library>pthread
+ <library>slicer
+ <library>boost_system
+ <allow-ice>yes
+ ;
+
+alias mirrorsearchsite :
+ [ glob *.cpp *.ice *.json : test.cpp ]
+ :
+ <slicer>yes
+ : :
+ <library>../service//mirrorsearch
+ <implicit-dependency>../service//mirrorsearch
+ <library>icespider
+ <library>slicer-json
+ <include>.
+ ;
+
+exe mirrorsearch-cgi :
+ mirrorsearchsite
+ :
+ <slicer>yes
+ <library>icespider-fcgi
+ ;
+
+path-constant me : . ;
+obj test :
+ test.cpp
+ :
+ <define>BOOST_TEST_DYN_LINK
+ <define>ROOT=\"$(me)\"
+ <library>icespider-testing
+ <library>mirrorsearchsite
+ ;
+
+run
+ test
+ mirrorsearchsite
+ : : :
+ <slicer>yes
+ <library>boost_filesystem
+ <library>icespider-testing
+ <library>boost_unit_test_framework
+ : testmirrorsearchsite ;
+
diff --git a/site/custom.cpp b/site/custom.cpp
new file mode 100644
index 0000000..35d0d40
--- /dev/null
+++ b/site/custom.cpp
@@ -0,0 +1,38 @@
+#include "icespider-routes-search.h"
+
+namespace MirrorSearch {
+ // Implementation classes.
+
+ // 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)
+ {
+ }
+
+ 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");
+ }
+ request->response(404, "No mirror found");
+ }
+
+ private:
+ const MirrorSearch::SearchPrx prx0;
+ const unsigned int _pi_filename;
+ };
+
+} // namespace MirrorSearch
+
+// Register route handlers.
+FACTORY(MirrorSearch::download, IceSpider::RouteHandlerFactory);
+
+// End generated code.
+
diff --git a/site/search.json b/site/search.json
new file mode 100644
index 0000000..ca1041d
--- /dev/null
+++ b/site/search.json
@@ -0,0 +1,13 @@
+{
+ "name": "MirrorSearch",
+ "routes": {
+ "list": {
+ "path": "/list/{filename}",
+ "operation": "MirrorSearch.Search.getMatches"
+ }
+ },
+ "slices": [
+ "models.ice",
+ "api.ice"
+ ]
+}
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();
+