The configure method takes test_only flag so we can avoid
[metaproxy-moved-to-github.git] / src / test_filter_query_rewrite.cpp
index d0fcb7c..06f8c0e 100644 (file)
@@ -1,7 +1,22 @@
-/* $Id: test_filter_query_rewrite.cpp,v 1.6 2006-01-23 08:13:11 mike Exp $
-   Copyright (c) 2005, Index Data.
+/* $Id: test_filter_query_rewrite.cpp,v 1.15 2008-02-20 15:07:53 adam Exp $
+   Copyright (c) 2005-2007, Index Data.
 
-%LICENSE%
+This file is part of Metaproxy.
+
+Metaproxy is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Metaproxy; see the file LICENSE.  If not, write to the
+Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.
  */
 
 #include "config.hpp"
 #include "package.hpp"
 
 #define BOOST_AUTO_TEST_MAIN
+#define BOOST_TEST_DYN_LINK
 #include <boost/test/auto_unit_test.hpp>
 
 using namespace boost::unit_test;
-using namespace yp2::util;
 
-class FilterBounceZ3950: public yp2::filter::Base {
+namespace mp = metaproxy_1;
+using namespace mp::util;
+
+class FilterBounceZ3950: public mp::filter::Base {
 public:
-    void process(yp2::Package & package) const {
+    void process(mp::Package & package) const {
         
         if (package.session().is_closed())
         {
@@ -61,14 +79,14 @@ public:
     };
 };
 
-void check_query_rewrite_init(yp2::RouterChain &router)
+void check_query_rewrite_init(mp::RouterChain &router)
 {
     //std::cout << "QUERY REWRITE INIT\n";
 
     // Create package with Z39.50 init request in it
-    yp2::Package pack;
+    mp::Package pack;
         
-    yp2::odr odr;
+    mp::odr odr;
     Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
     
     pack.request() = apdu;
@@ -91,7 +109,7 @@ void check_query_rewrite_init(yp2::RouterChain &router)
     }
 }
 
-void check_query_rewrite_search(yp2::RouterChain &router, 
+void check_query_rewrite_search(mp::RouterChain &router, 
                                 std::string query_in,
                                 std::string query_expect)
 {
@@ -99,13 +117,13 @@ void check_query_rewrite_search(yp2::RouterChain &router,
     //          << query_in << " " << query_expect << "\n";
     
     // Create package with Z39.50 search request in it
-    yp2::Package pack;
+    mp::Package pack;
         
-    yp2::odr odr;
+    mp::odr odr;
     Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchRequest);
 
     // create package PQF query here    
-    yp2::util::pqf(odr, apdu, query_in);
+    mp::util::pqf(odr, apdu, query_in);
 
     // create package PDF database info (needed!)
     apdu->u.searchRequest->num_databaseNames = 1;
@@ -139,24 +157,24 @@ void check_query_rewrite_search(yp2::RouterChain &router,
 }
 
 
-BOOST_AUTO_UNIT_TEST( test_filter_query_rewrite_1 )
+BOOST_AUTO_TEST_CASE( test_filter_query_rewrite_1 )
 {
     try 
     {
-        yp2::filter::QueryRewrite f_query_rewrite;
+        mp::filter::QueryRewrite f_query_rewrite;
     }
     catch ( ... ) {
         BOOST_CHECK (false);
     }
 }
 
-BOOST_AUTO_UNIT_TEST( test_filter_query_rewrite2 )
+BOOST_AUTO_TEST_CASE( test_filter_query_rewrite2 )
 {
     try 
     {
-        yp2::RouterChain router;
+        mp::RouterChain router;
         
-        yp2::filter::QueryRewrite f_query_rewrite;
+        mp::filter::QueryRewrite f_query_rewrite;
         //FilterBounceZ3950 f_bounce_z3950;
         
         router.append(f_query_rewrite);
@@ -174,43 +192,19 @@ BOOST_AUTO_UNIT_TEST( test_filter_query_rewrite2 )
 }
 
 
-BOOST_AUTO_UNIT_TEST( test_filter_query_rewrite3 )
+BOOST_AUTO_TEST_CASE( test_filter_query_rewrite3 )
 {
     
 
     try 
     {
-        yp2::RouterChain router;
+        mp::RouterChain router;
         
 
         std::string xmlconf = 
             "<?xml version='1.0'?>\n"
-            "<filter xmlns='http://indexdata.dk/yp2/config/1'\n"
+            "<filter xmlns='http://indexdata.com/metaproxy'\n"
             "        id='qrw1' type='query_rewrite'>\n"
-            "  <regex action='all'>\n"
-            "    <expression>@attrset XYZ</expression>\n"
-            "    <format>@attrset Bib-1</format>\n"
-            "  </regex>\n"
-            "  <regex action='search'>\n"
-            "    <expression>@attr 1=4</expression>\n"
-            "    <format>@attr 1=4 @attr 4=2</format>\n"
-            "  </regex>\n"
-            "  <regex action='search'>\n"
-            "    <expression>fish</expression>\n"
-            "    <format>cat</format>\n"
-            "  </regex>\n"
-            "  <regex action='scan'>\n"
-            "    <expression>@attr 1=4</expression>\n"
-            "    <format>@attr 1=5 @attr 4=1</format>\n"
-            "  </regex>\n"
-            "  <regex action='scan' stop='1'>\n"
-            "    <expression>fish</expression>\n"
-            "    <format>mouse</format>\n"
-            "  </regex>\n"
-            "  <regex action='finally'>\n"
-            "    <expression>^</expression>\n"
-            "    <format>@and @attr1=9999 vdb</format>\n"
-            "  </regex>\n"
             "</filter>\n"
             ;
          
@@ -222,8 +216,8 @@ BOOST_AUTO_UNIT_TEST( test_filter_query_rewrite3 )
         xmlNode *root_element = xmlDocGetRootElement(doc);
 
         // creating and configuring filter
-        yp2::filter::QueryRewrite f_query_rewrite;
-        f_query_rewrite.configure(root_element);
+        mp::filter::QueryRewrite f_query_rewrite;
+        f_query_rewrite.configure(root_element, true);
         
         // remeber to free XML DOM
         xmlFreeDoc(doc);