1 /* $Id: test_router_flexml.cpp,v 1.19 2007-01-25 14:05:54 adam Exp $
2 Copyright (c) 2005-2007, Index Data.
4 See the LICENSE file for details
12 #include "router_flexml.hpp"
13 #include "factory_static.hpp"
15 #define BOOST_AUTO_TEST_MAIN
16 #include <boost/test/auto_unit_test.hpp>
18 using namespace boost::unit_test;
20 namespace mp = metaproxy_1;
22 static int tfilter_ref = 0;
23 class TFilter: public mp::filter::Base {
25 void process(mp::Package & package) const {};
26 TFilter() { tfilter_ref++; };
27 ~TFilter() { tfilter_ref--; };
30 static mp::filter::Base* filter_creator()
35 // Pass well-formed XML and valid configuration to it (implicit NS)
36 BOOST_AUTO_UNIT_TEST( test_router_flexml_1 )
40 std::string xmlconf = "<?xml version=\"1.0\"?>\n"
41 "<metaproxy xmlns=\"http://indexdata.com/metaproxy\""
43 " <start route=\"start\"/>\n"
45 " <filter id=\"front_default\" type=\"frontend_net\">\n"
46 " <port>@:210</port>\n"
48 " <filter id=\"log_cout1\" type=\"log\">\n"
49 " <message>my msg</message>\n"
51 " <filter id=\"tfilter_id\" type=\"tfilter\"/>\n"
52 " <filter id=\"log_cout2\" type=\"log\">\n"
53 " <message>other</message>\n"
57 " <route id=\"start\">\n"
58 " <filter refid=\"front_default\"/>\n"
59 " <filter refid=\"log_cout1\"/>\n"
60 " <filter type=\"tfilter\">\n"
62 " <filter type=\"z3950_client\">\n"
68 mp::FactoryStatic factory;
69 factory.add_creator("tfilter", filter_creator);
70 mp::RouterFleXML rflexml(xmlconf, factory);
71 BOOST_CHECK_EQUAL(tfilter_ref, 2);
73 catch ( std::runtime_error &e) {
74 std::cout << "std::runtime error: " << e.what() << "\n";
80 BOOST_CHECK_EQUAL(tfilter_ref, 0);
83 // Pass non-wellformed XML
84 BOOST_AUTO_UNIT_TEST( test_router_flexml_2 )
86 bool got_error_as_expected = false;
89 std::string xmlconf_invalid = "<?xml version=\"1.0\"?>\n"
90 "<mp:metaproxy xmlns:mp=\"http://indexdata.com/metaproxy\" version=\"1.0\">\n"
91 " <start route=\"start\"/>\n"
93 " <filter id=\"front_default\" type=\"frontend_net\">\n"
94 " <port>@:210</port>\n";
96 mp::FactoryFilter factory;
97 mp::RouterFleXML rflexml(xmlconf_invalid, factory);
99 catch ( mp::XMLError &e) {
100 std::cout << "XMLError: " << e.what() << "\n";
101 got_error_as_expected = true;
103 catch ( std::runtime_error &e) {
104 std::cout << "std::runtime error: " << e.what() << "\n";
109 BOOST_CHECK(got_error_as_expected);
112 // Pass well-formed XML with explicit NS
113 BOOST_AUTO_UNIT_TEST( test_router_flexml_3 )
117 std::string xmlconf = "<?xml version=\"1.0\"?>\n"
118 "<mp:metaproxy xmlns:mp=\"http://indexdata.com/metaproxy\""
119 " version=\"1.0\">\n"
120 " <mp:start route=\"start\"/>\n"
122 " <mp:filter id=\"front_default\" type=\"frontend_net\">\n"
123 " <port>@:210</port>\n"
125 " <mp:filter id=\"log_cout\" type=\"log\">\n"
126 " <message>my msg</message>\n"
130 " <mp:route id=\"start\">\n"
131 " <mp:filter refid=\"front_default\"/>\n"
132 " <mp:filter refid=\"log_cout\"/>\n"
137 mp::FactoryStatic factory;
138 mp::RouterFleXML rflexml(xmlconf, factory);
140 catch ( std::runtime_error &e) {
141 std::cout << "std::runtime error: " << e.what() << "\n";
149 // Pass well-formed XML but bad filter type
150 BOOST_AUTO_UNIT_TEST( test_router_flexml_4 )
152 bool got_error_as_expected = false;
155 std::string xmlconf = "<?xml version=\"1.0\"?>\n"
156 "<metaproxy xmlns=\"http://indexdata.com/metaproxy\""
157 " version=\"1.0\">\n"
158 " <start route=\"start\"/>\n"
160 " <filter id=\"front_default\" type=\"notknown\">\n"
161 " <port>@:210</port>\n"
165 " <route id=\"start\">\n"
166 " <filter refid=\"front_default\"/>\n"
171 mp::FactoryStatic factory;
172 factory.add_creator("tfilter", filter_creator);
173 mp::RouterFleXML rflexml(xmlconf, factory);
175 catch ( mp::FactoryFilter::NotFound &e) {
176 std::cout << "mp::FactoryFilter::NotFound: " << e.what() << "\n";
177 got_error_as_expected = true;
179 catch ( std::runtime_error &e) {
180 std::cout << "std::runtime error: " << e.what() << "\n";
182 BOOST_CHECK(got_error_as_expected);
189 * indent-tabs-mode: nil
190 * c-file-style: "stroustrup"
192 * vim: shiftwidth=4 tabstop=8 expandtab