e6ee8fc0d8443f4794eccda91f1ef32cc38ad2a8
[metaproxy-moved-to-github.git] / src / test_router_flexml.cpp
1 /* $Id: test_router_flexml.cpp,v 1.8 2006-01-04 11:19:04 adam Exp $
2    Copyright (c) 2005, Index Data.
3
4 %LICENSE%
5  */
6
7 #include "config.hpp"
8 #include <iostream>
9 #include <stdexcept>
10
11 #include "filter.hpp"
12 #include "router_flexml.hpp"
13 #include "filter_factory.hpp"
14
15 #define BOOST_AUTO_TEST_MAIN
16 #include <boost/test/auto_unit_test.hpp>
17
18 using namespace boost::unit_test;
19
20 class TFilter: public yp2::filter::Base {
21 public:
22     void process(yp2::Package & package) const {};
23 };
24     
25
26 BOOST_AUTO_UNIT_TEST( test_router_flexml_1 )
27 {
28     try
29     {
30         std::string xmlconf = "<?xml version=\"1.0\"?>\n"
31             "<yp2 xmlns=\"http://indexdata.dk/yp2/config/1\">\n"
32             "  <start route=\"start\"/>\n"
33             "  <filters>\n"
34             "    <filter id=\"front_default\" type=\"frontend_net\">\n"
35             "      <port>210</port>\n"
36             "    </filter>\n"
37             "    <filter id=\"log_cout\" type=\"log\">\n"
38             "      <logfile>mylog.log</logfile>\n"
39             "    </filter>\n"
40             "  </filters>\n"
41             "  <routes>\n"  
42             "    <route id=\"start\">\n"
43             "      <filter refid=\"front_default\"/>\n"
44             "      <filter refid=\"log_cout\"/>\n"
45             "    </route>\n"
46             "  </routes>\n"
47             "</yp2>\n";
48         yp2::RouterFleXML rflexml(xmlconf);
49     }
50     catch ( yp2::RouterFleXML::XMLError &e) {
51         std::cout << "XMLError: " << e.what() << "\n";
52         BOOST_CHECK (false);
53     }
54     catch ( yp2::FilterFactoryException &e) {
55         std::cout << "FilterFactoryException: " << e.what() << "\n";
56         BOOST_CHECK (false);
57     }
58     catch ( ... ) {
59         BOOST_CHECK (false);
60     }
61 }
62
63 BOOST_AUTO_UNIT_TEST( test_router_flexml_2 )
64 {
65     bool got_xml_error = false;
66     try
67     {
68         std::string xmlconf_invalid = "<?xml version=\"1.0\"?>\n"
69             "<y:yp2 xmlns:y=\"http://indexdata.dk/yp2/config/1\">\n"
70             "  <start route=\"start\"/>\n"
71             "  <filters>\n"
72             "    <filter id=\"front_default\" type=\"frontend_net\">\n"
73             "      <port>210</port>\n";
74         
75         yp2::RouterFleXML rflexml(xmlconf_invalid);
76     }
77     catch ( yp2::RouterFleXML::XMLError &e) {
78         got_xml_error = true;
79     }
80     catch ( ... ) {
81         ;
82     }
83     BOOST_CHECK(got_xml_error);
84 }
85
86 BOOST_AUTO_UNIT_TEST( test_router_flexml_3 )
87 {
88     try
89     {
90         std::string xmlconf = "<?xml version=\"1.0\"?>\n"
91             "<y:yp2 xmlns:y=\"http://indexdata.dk/yp2/config/1\">\n"
92             "  <y:start route=\"start\"/>\n"
93             "  <y:filters>\n"
94             "    <y:filter id=\"front_default\" type=\"frontend_net\">\n"
95             "      <port>210</port>\n"
96             "    </y:filter>\n"
97             "    <y:filter id=\"log_cout\" type=\"log\">\n"
98             "      <logfile>mylog.log</logfile>\n"
99             "    </y:filter>\n"
100             "  </y:filters>\n"
101             "  <y:routes>\n"  
102             "    <y:route id=\"start\">\n"
103             "      <y:filter refid=\"front_default\"/>\n"
104             "      <y:filter refid=\"log_cout\"/>\n"
105             "    </y:route>\n"
106             "  </y:routes>\n"
107             "</y:yp2>\n";
108        
109         yp2::RouterFleXML rflexml(xmlconf);
110     }
111     catch ( ... ) {
112         BOOST_CHECK (false);
113     }
114 }
115
116
117 /*
118  * Local variables:
119  * c-basic-offset: 4
120  * indent-tabs-mode: nil
121  * c-file-style: "stroustrup"
122  * End:
123  * vim: shiftwidth=4 tabstop=8 expandtab
124  */