Fix Metaproxy stops logging after check config failed MP-590
[metaproxy-moved-to-github.git] / src / test_router_flexml.cpp
index 95b05ef..d9c2540 100644 (file)
@@ -1,18 +1,31 @@
-/* $Id: test_router_flexml.cpp,v 1.17 2006-06-10 14:29:13 adam Exp $
-   Copyright (c) 2005-2006, Index Data.
+/* This file is part of Metaproxy.
+   Copyright (C) Index Data
 
-   See the LICENSE file for details
- */
+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 this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
 
 #include "config.hpp"
 #include <iostream>
 #include <stdexcept>
 
-#include "filter.hpp"
+#include <metaproxy/filter.hpp>
 #include "router_flexml.hpp"
 #include "factory_static.hpp"
 
 #define BOOST_AUTO_TEST_MAIN
+#define BOOST_TEST_DYN_LINK
 #include <boost/test/auto_unit_test.hpp>
 
 using namespace boost::unit_test;
@@ -25,6 +38,7 @@ public:
     void process(mp::Package & package) const {};
     TFilter() { tfilter_ref++; };
     ~TFilter() { tfilter_ref--; };
+    void configure(const xmlNode* ptr, bool test_only, const char *path) {};
 };
 
 static mp::filter::Base* filter_creator()
@@ -33,12 +47,13 @@ static mp::filter::Base* filter_creator()
 }
 
 // Pass well-formed XML and valid configuration to it (implicit NS)
-BOOST_AUTO_UNIT_TEST( test_router_flexml_1 )
+BOOST_AUTO_TEST_CASE( test_router_flexml_1 )
 {
     try
     {
         std::string xmlconf = "<?xml version=\"1.0\"?>\n"
-            "<yp2 xmlns=\"http://indexdata.dk/yp2/config/1\">\n"
+            "<metaproxy xmlns=\"http://indexdata.com/metaproxy\""
+            " version=\"1.0\">\n"
             "  <start route=\"start\"/>\n"
             "  <filters>\n"
             "    <filter id=\"front_default\" type=\"frontend_net\">\n"
@@ -52,7 +67,7 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_1 )
             "      <message>other</message>\n"
             "    </filter>\n"
             "  </filters>\n"
-            "  <routes>\n"  
+            "  <routes>\n"
             "    <route id=\"start\">\n"
             "      <filter refid=\"front_default\"/>\n"
             "      <filter refid=\"log_cout1\"/>\n"
@@ -62,11 +77,11 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_1 )
             "      </filter>\n"
             "    </route>\n"
             "  </routes>\n"
-            "</yp2>\n";
+            "</metaproxy>\n";
 
         mp::FactoryStatic factory;
         factory.add_creator("tfilter", filter_creator);
-        mp::RouterFleXML rflexml(xmlconf, factory);
+        mp::RouterFleXML rflexml(xmlconf, factory, true);
         BOOST_CHECK_EQUAL(tfilter_ref, 2);
     }
     catch ( std::runtime_error &e) {
@@ -80,20 +95,20 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_1 )
 }
 
 // Pass non-wellformed XML
-BOOST_AUTO_UNIT_TEST( test_router_flexml_2 )
+BOOST_AUTO_TEST_CASE( test_router_flexml_2 )
 {
     bool got_error_as_expected = false;
     try
     {
         std::string xmlconf_invalid = "<?xml version=\"1.0\"?>\n"
-            "<y:yp2 xmlns:y=\"http://indexdata.dk/yp2/config/1\">\n"
+            "<mp:metaproxy xmlns:mp=\"http://indexdata.com/metaproxy\" version=\"1.0\">\n"
             "  <start route=\"start\"/>\n"
             "  <filters>\n"
             "    <filter id=\"front_default\" type=\"frontend_net\">\n"
             "      <port>@:210</port>\n";
-        
+
         mp::FactoryFilter factory;
-        mp::RouterFleXML rflexml(xmlconf_invalid, factory);
+        mp::RouterFleXML rflexml(xmlconf_invalid, factory, true);
     }
     catch ( mp::XMLError &e) {
         std::cout << "XMLError: " << e.what() << "\n";
@@ -109,31 +124,32 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_2 )
 }
 
 // Pass well-formed XML with explicit NS
-BOOST_AUTO_UNIT_TEST( test_router_flexml_3 )
+BOOST_AUTO_TEST_CASE( test_router_flexml_3 )
 {
     try
     {
         std::string xmlconf = "<?xml version=\"1.0\"?>\n"
-            "<y:yp2 xmlns:y=\"http://indexdata.dk/yp2/config/1\">\n"
-            "  <y:start route=\"start\"/>\n"
-            "  <y:filters>\n"
-            "    <y:filter id=\"front_default\" type=\"frontend_net\">\n"
+            "<mp:metaproxy xmlns:mp=\"http://indexdata.com/metaproxy\""
+            "  version=\"1.0\">\n"
+            "  <mp:start route=\"start\"/>\n"
+            "  <mp:filters>\n"
+            "    <mp:filter id=\"front_default\" type=\"frontend_net\">\n"
             "      <port>@:210</port>\n"
-            "    </y:filter>\n"
-            "    <y:filter id=\"log_cout\" type=\"log\">\n"
+            "    </mp:filter>\n"
+            "    <mp:filter id=\"log_cout\" type=\"log\">\n"
             "      <message>my msg</message>\n"
-            "    </y:filter>\n"
-            "  </y:filters>\n"
-            "  <y:routes>\n"  
-            "    <y:route id=\"start\">\n"
-            "      <y:filter refid=\"front_default\"/>\n"
-            "      <y:filter refid=\"log_cout\"/>\n"
-            "    </y:route>\n"
-            "  </y:routes>\n"
-            "</y:yp2>\n";
-       
+            "    </mp:filter>\n"
+            "  </mp:filters>\n"
+            "  <mp:routes>\n"
+            "    <mp:route id=\"start\">\n"
+            "      <mp:filter refid=\"front_default\"/>\n"
+            "      <mp:filter refid=\"log_cout\"/>\n"
+            "    </mp:route>\n"
+            "  </mp:routes>\n"
+            "</mp:metaproxy>\n";
+
         mp::FactoryStatic factory;
-        mp::RouterFleXML rflexml(xmlconf, factory);
+        mp::RouterFleXML rflexml(xmlconf, factory, true);
     }
     catch ( std::runtime_error &e) {
         std::cout << "std::runtime error: " << e.what() << "\n";
@@ -145,29 +161,30 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_3 )
 }
 
 // Pass well-formed XML but bad filter type
-BOOST_AUTO_UNIT_TEST( test_router_flexml_4 )
+BOOST_AUTO_TEST_CASE( test_router_flexml_4 )
 {
     bool got_error_as_expected = false;
     try
     {
         std::string xmlconf = "<?xml version=\"1.0\"?>\n"
-            "<yp2 xmlns=\"http://indexdata.dk/yp2/config/1\">\n"
+            "<metaproxy xmlns=\"http://indexdata.com/metaproxy\""
+            " version=\"1.0\">\n"
             "  <start route=\"start\"/>\n"
             "  <filters>\n"
             "    <filter id=\"front_default\" type=\"notknown\">\n"
             "      <port>@:210</port>\n"
             "    </filter>\n"
             "  </filters>\n"
-            "  <routes>\n"  
+            "  <routes>\n"
             "    <route id=\"start\">\n"
             "      <filter refid=\"front_default\"/>\n"
             "    </route>\n"
             "  </routes>\n"
-            "</yp2>\n";
+            "</metaproxy>\n";
 
         mp::FactoryStatic factory;
         factory.add_creator("tfilter", filter_creator);
-        mp::RouterFleXML rflexml(xmlconf, factory);
+        mp::RouterFleXML rflexml(xmlconf, factory, true);
     }
     catch ( mp::FactoryFilter::NotFound &e) {
         std::cout << "mp::FactoryFilter::NotFound: " << e.what() << "\n";
@@ -183,8 +200,9 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_4 )
 /*
  * Local variables:
  * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
  * indent-tabs-mode: nil
- * c-file-style: "stroustrup"
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab
  */
+