X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ftest_filter_rewrite.cpp;h=e3802a7531ca597a4054471778271654aac0d033;hb=2bde9b746dfd661553c28a129a667363cc7a1581;hp=67d77409996ea03cb34195b9df485b05990a1292;hpb=3a51c4a584225b0e77d17600acb527337f5ac8ce;p=metaproxy-moved-to-github.git diff --git a/src/test_filter_rewrite.cpp b/src/test_filter_rewrite.cpp index 67d7740..e3802a7 100644 --- a/src/test_filter_rewrite.cpp +++ b/src/test_filter_rewrite.cpp @@ -23,12 +23,14 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "filter_http_client.hpp" #include "filter_http_rewrite.hpp" #include -#include "router_chain.hpp" +#include #include #include #include +#include + #define BOOST_AUTO_TEST_MAIN #define BOOST_TEST_DYN_LINK @@ -36,77 +38,314 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA using namespace boost::unit_test; namespace mp = metaproxy_1; +/* + * The global testconfig is commented out, as it won't even compile + * on old Centos5 machines +struct TestConfig { + TestConfig() + { + std::cout << "global setup\n"; + yaz_log_init_level(YLOG_ALL); + } + ~TestConfig() + { + std::cout << "global teardown\n"; + } +}; +BOOST_GLOBAL_FIXTURE( TestConfig ); +*/ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 ) { try { + std::cout << "Running non-xml config test case" << std::endl; + mp::RouterChain router; mp::filter::HttpRewrite fhr; + + std::string xmlconf = + "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n" + ; + + std::cout << xmlconf; + + // reading and parsing XML conf + xmlDocPtr doc = xmlParseMemory(xmlconf.c_str(), xmlconf.size()); + BOOST_CHECK(doc); + xmlNode *root_element = xmlDocGetRootElement(doc); + fhr.configure(root_element, true, ""); + xmlFreeDoc(doc); + + router.append(fhr); + + // create an http request + mp::Package pack; + + mp::odr odr; + Z_GDU *gdu_req = z_get_HTTP_Request_uri(odr, + "http://proxyhost/proxypath/targetsite/page1.html", 0, 1); + + pack.request() = gdu_req; + + //create the http response + + const char *resp_buf = + "HTTP/1.1 200 OK\r\n" + "Content-Length: 441\r\n" + "Content-Type: text/html\r\n" + "Link: ; rel=absolute\r\n" + "Link: ; rel=relative\r\n" + "\r\n" + "Hello proxy!" + "" + "" + "" + "" + "

Welcome to our website. It doesn't make it easy to get pro" + "xified" + "" + " An absolute link" + "" + "" + "" + "" + "

Welcome to our website. It doesn't make it easy to get pro" + "xified" + "" + " An absolute link" + "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n" + ; + + std::cout << xmlconf; + + // reading and parsing XML conf + xmlDocPtr doc = xmlParseMemory(xmlconf.c_str(), xmlconf.size()); + BOOST_CHECK(doc); + xmlNode *root_element = xmlDocGetRootElement(doc); + fhr.configure(root_element, true, ""); + xmlFreeDoc(doc); router.append(fhr); - router.append(hc); // create an http request mp::Package pack; mp::odr odr; Z_GDU *gdu_req = z_get_HTTP_Request_uri(odr, - "http://proxyhost/proxypath/localhost:80/~jakub/targetsite.php", 0, 1); + "http://proxyhost/proxypath/targetsite/page1.html", 0, 1); pack.request() = gdu_req; + //create the http response + + const char *resp_buf = + "HTTP/1.1 200 OK\r\n" + "Content-Length: 50\r\n" + "Content-Type: text/html\r\n" + "Link: ; rel=absolute\r\n" + "Link: ; rel=relative\r\n" + "\r\n" + "Hello proxy!" + "" + "" + "" + "" + "

Welcome to our website. It doesn't make it easy to get pro" + "xified" + "" + " An absolute link" + "" + "" + "" + "" + "

Welcome to our website. It doesn't make it easy to get pro" + "xified" + "" + " An absolute link" + "