1 /* $Id: test_router_flexml.cpp,v 1.22 2008-02-20 15:07:53 adam Exp $
2 Copyright (c) 2005-2007, Index Data.
4 This file is part of Metaproxy.
6 Metaproxy is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with Metaproxy; see the file LICENSE. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 #include "router_flexml.hpp"
28 #include "factory_static.hpp"
30 #define BOOST_AUTO_TEST_MAIN
31 #define BOOST_TEST_DYN_LINK
32 #include <boost/test/auto_unit_test.hpp>
34 using namespace boost::unit_test;
36 namespace mp = metaproxy_1;
38 static int tfilter_ref = 0;
39 class TFilter: public mp::filter::Base {
41 void process(mp::Package & package) const {};
42 TFilter() { tfilter_ref++; };
43 ~TFilter() { tfilter_ref--; };
46 static mp::filter::Base* filter_creator()
51 // Pass well-formed XML and valid configuration to it (implicit NS)
52 BOOST_AUTO_TEST_CASE( test_router_flexml_1 )
56 std::string xmlconf = "<?xml version=\"1.0\"?>\n"
57 "<metaproxy xmlns=\"http://indexdata.com/metaproxy\""
59 " <start route=\"start\"/>\n"
61 " <filter id=\"front_default\" type=\"frontend_net\">\n"
62 " <port>@:210</port>\n"
64 " <filter id=\"log_cout1\" type=\"log\">\n"
65 " <message>my msg</message>\n"
67 " <filter id=\"tfilter_id\" type=\"tfilter\"/>\n"
68 " <filter id=\"log_cout2\" type=\"log\">\n"
69 " <message>other</message>\n"
73 " <route id=\"start\">\n"
74 " <filter refid=\"front_default\"/>\n"
75 " <filter refid=\"log_cout1\"/>\n"
76 " <filter type=\"tfilter\">\n"
78 " <filter type=\"z3950_client\">\n"
84 mp::FactoryStatic factory;
85 factory.add_creator("tfilter", filter_creator);
86 mp::RouterFleXML rflexml(xmlconf, factory, true);
87 BOOST_CHECK_EQUAL(tfilter_ref, 2);
89 catch ( std::runtime_error &e) {
90 std::cout << "std::runtime error: " << e.what() << "\n";
96 BOOST_CHECK_EQUAL(tfilter_ref, 0);
99 // Pass non-wellformed XML
100 BOOST_AUTO_TEST_CASE( test_router_flexml_2 )
102 bool got_error_as_expected = false;
105 std::string xmlconf_invalid = "<?xml version=\"1.0\"?>\n"
106 "<mp:metaproxy xmlns:mp=\"http://indexdata.com/metaproxy\" version=\"1.0\">\n"
107 " <start route=\"start\"/>\n"
109 " <filter id=\"front_default\" type=\"frontend_net\">\n"
110 " <port>@:210</port>\n";
112 mp::FactoryFilter factory;
113 mp::RouterFleXML rflexml(xmlconf_invalid, factory, true);
115 catch ( mp::XMLError &e) {
116 std::cout << "XMLError: " << e.what() << "\n";
117 got_error_as_expected = true;
119 catch ( std::runtime_error &e) {
120 std::cout << "std::runtime error: " << e.what() << "\n";
125 BOOST_CHECK(got_error_as_expected);
128 // Pass well-formed XML with explicit NS
129 BOOST_AUTO_TEST_CASE( test_router_flexml_3 )
133 std::string xmlconf = "<?xml version=\"1.0\"?>\n"
134 "<mp:metaproxy xmlns:mp=\"http://indexdata.com/metaproxy\""
135 " version=\"1.0\">\n"
136 " <mp:start route=\"start\"/>\n"
138 " <mp:filter id=\"front_default\" type=\"frontend_net\">\n"
139 " <port>@:210</port>\n"
141 " <mp:filter id=\"log_cout\" type=\"log\">\n"
142 " <message>my msg</message>\n"
146 " <mp:route id=\"start\">\n"
147 " <mp:filter refid=\"front_default\"/>\n"
148 " <mp:filter refid=\"log_cout\"/>\n"
153 mp::FactoryStatic factory;
154 mp::RouterFleXML rflexml(xmlconf, factory, true);
156 catch ( std::runtime_error &e) {
157 std::cout << "std::runtime error: " << e.what() << "\n";
165 // Pass well-formed XML but bad filter type
166 BOOST_AUTO_TEST_CASE( test_router_flexml_4 )
168 bool got_error_as_expected = false;
171 std::string xmlconf = "<?xml version=\"1.0\"?>\n"
172 "<metaproxy xmlns=\"http://indexdata.com/metaproxy\""
173 " version=\"1.0\">\n"
174 " <start route=\"start\"/>\n"
176 " <filter id=\"front_default\" type=\"notknown\">\n"
177 " <port>@:210</port>\n"
181 " <route id=\"start\">\n"
182 " <filter refid=\"front_default\"/>\n"
187 mp::FactoryStatic factory;
188 factory.add_creator("tfilter", filter_creator);
189 mp::RouterFleXML rflexml(xmlconf, factory, true);
191 catch ( mp::FactoryFilter::NotFound &e) {
192 std::cout << "mp::FactoryFilter::NotFound: " << e.what() << "\n";
193 got_error_as_expected = true;
195 catch ( std::runtime_error &e) {
196 std::cout << "std::runtime error: " << e.what() << "\n";
198 BOOST_CHECK(got_error_as_expected);
205 * indent-tabs-mode: nil
206 * c-file-style: "stroustrup"
208 * vim: shiftwidth=4 tabstop=8 expandtab