1 /* $Id: test_router_flexml.cpp,v 1.20 2007-05-09 21:23:09 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 #include <boost/test/auto_unit_test.hpp>
33 using namespace boost::unit_test;
35 namespace mp = metaproxy_1;
37 static int tfilter_ref = 0;
38 class TFilter: public mp::filter::Base {
40 void process(mp::Package & package) const {};
41 TFilter() { tfilter_ref++; };
42 ~TFilter() { tfilter_ref--; };
45 static mp::filter::Base* filter_creator()
50 // Pass well-formed XML and valid configuration to it (implicit NS)
51 BOOST_AUTO_UNIT_TEST( test_router_flexml_1 )
55 std::string xmlconf = "<?xml version=\"1.0\"?>\n"
56 "<metaproxy xmlns=\"http://indexdata.com/metaproxy\""
58 " <start route=\"start\"/>\n"
60 " <filter id=\"front_default\" type=\"frontend_net\">\n"
61 " <port>@:210</port>\n"
63 " <filter id=\"log_cout1\" type=\"log\">\n"
64 " <message>my msg</message>\n"
66 " <filter id=\"tfilter_id\" type=\"tfilter\"/>\n"
67 " <filter id=\"log_cout2\" type=\"log\">\n"
68 " <message>other</message>\n"
72 " <route id=\"start\">\n"
73 " <filter refid=\"front_default\"/>\n"
74 " <filter refid=\"log_cout1\"/>\n"
75 " <filter type=\"tfilter\">\n"
77 " <filter type=\"z3950_client\">\n"
83 mp::FactoryStatic factory;
84 factory.add_creator("tfilter", filter_creator);
85 mp::RouterFleXML rflexml(xmlconf, factory);
86 BOOST_CHECK_EQUAL(tfilter_ref, 2);
88 catch ( std::runtime_error &e) {
89 std::cout << "std::runtime error: " << e.what() << "\n";
95 BOOST_CHECK_EQUAL(tfilter_ref, 0);
98 // Pass non-wellformed XML
99 BOOST_AUTO_UNIT_TEST( test_router_flexml_2 )
101 bool got_error_as_expected = false;
104 std::string xmlconf_invalid = "<?xml version=\"1.0\"?>\n"
105 "<mp:metaproxy xmlns:mp=\"http://indexdata.com/metaproxy\" version=\"1.0\">\n"
106 " <start route=\"start\"/>\n"
108 " <filter id=\"front_default\" type=\"frontend_net\">\n"
109 " <port>@:210</port>\n";
111 mp::FactoryFilter factory;
112 mp::RouterFleXML rflexml(xmlconf_invalid, factory);
114 catch ( mp::XMLError &e) {
115 std::cout << "XMLError: " << e.what() << "\n";
116 got_error_as_expected = true;
118 catch ( std::runtime_error &e) {
119 std::cout << "std::runtime error: " << e.what() << "\n";
124 BOOST_CHECK(got_error_as_expected);
127 // Pass well-formed XML with explicit NS
128 BOOST_AUTO_UNIT_TEST( test_router_flexml_3 )
132 std::string xmlconf = "<?xml version=\"1.0\"?>\n"
133 "<mp:metaproxy xmlns:mp=\"http://indexdata.com/metaproxy\""
134 " version=\"1.0\">\n"
135 " <mp:start route=\"start\"/>\n"
137 " <mp:filter id=\"front_default\" type=\"frontend_net\">\n"
138 " <port>@:210</port>\n"
140 " <mp:filter id=\"log_cout\" type=\"log\">\n"
141 " <message>my msg</message>\n"
145 " <mp:route id=\"start\">\n"
146 " <mp:filter refid=\"front_default\"/>\n"
147 " <mp:filter refid=\"log_cout\"/>\n"
152 mp::FactoryStatic factory;
153 mp::RouterFleXML rflexml(xmlconf, factory);
155 catch ( std::runtime_error &e) {
156 std::cout << "std::runtime error: " << e.what() << "\n";
164 // Pass well-formed XML but bad filter type
165 BOOST_AUTO_UNIT_TEST( test_router_flexml_4 )
167 bool got_error_as_expected = false;
170 std::string xmlconf = "<?xml version=\"1.0\"?>\n"
171 "<metaproxy xmlns=\"http://indexdata.com/metaproxy\""
172 " version=\"1.0\">\n"
173 " <start route=\"start\"/>\n"
175 " <filter id=\"front_default\" type=\"notknown\">\n"
176 " <port>@:210</port>\n"
180 " <route id=\"start\">\n"
181 " <filter refid=\"front_default\"/>\n"
186 mp::FactoryStatic factory;
187 factory.add_creator("tfilter", filter_creator);
188 mp::RouterFleXML rflexml(xmlconf, factory);
190 catch ( mp::FactoryFilter::NotFound &e) {
191 std::cout << "mp::FactoryFilter::NotFound: " << e.what() << "\n";
192 got_error_as_expected = true;
194 catch ( std::runtime_error &e) {
195 std::cout << "std::runtime error: " << e.what() << "\n";
197 BOOST_CHECK(got_error_as_expected);
204 * indent-tabs-mode: nil
205 * c-file-style: "stroustrup"
207 * vim: shiftwidth=4 tabstop=8 expandtab