41554de2374cb0bfeeaca254b29653a3cbca1f47
[metaproxy-moved-to-github.git] / src / test_filter_record_transform.cpp
1 /* This file is part of Metaproxy.
2    Copyright (C) 2005-2008 Index Data
3
4 Metaproxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19 #include "config.hpp"
20 #include "filter_record_transform.hpp"
21 //#include "util.hpp"
22 //#include "sru_util.hpp"
23 #include "router_chain.hpp"
24 #include "session.hpp"
25 #include "package.hpp"
26
27 //#include <iostream>
28 //#include <stdexcept>
29
30 #define BOOST_AUTO_TEST_MAIN
31 #define BOOST_TEST_DYN_LINK
32 #include <boost/test/auto_unit_test.hpp>
33
34 #include <iostream>
35
36
37 using namespace boost::unit_test;
38
39 namespace mp = metaproxy_1;
40 //using namespace mp::util;
41
42
43
44 BOOST_AUTO_TEST_CASE( test_filter_record_transform_1 )
45 {
46     try 
47     {
48         mp::filter::RecordTransform f_rec_trans;
49     }
50     catch ( ... ) {
51         BOOST_CHECK (false);
52     }
53 }
54
55 BOOST_AUTO_TEST_CASE( test_filter_record_transform_2 )
56 {
57     try 
58     {
59         mp::RouterChain router;
60         
61         mp::filter::RecordTransform f_rec_trans;
62         
63         router.append(f_rec_trans);
64
65         //check_sru_to_z3950_init(router);
66         //check_sru_to_z3950_search(router, 
67         //                           "@attrset Bib-1 @attr 1=4 the", 
68         //                           "@attrset Bib-1 @attr 1=4 the");
69
70     }
71     catch ( ... ) {
72         BOOST_CHECK (false);
73     }
74 }
75
76
77 BOOST_AUTO_TEST_CASE( test_filter_record_transform_3 )
78 {
79     
80
81     try 
82     {
83         mp::RouterChain router;
84         
85
86         std::string xmlconf = 
87             "<?xml version='1.0'?>\n"
88             "<filter xmlns='http://indexdata.com/metaproxy'\n"
89             "        id='rec_trans_1' type='record_transform'>\n"
90             "<retrievalinfo>"
91             "<retrieval" 
92             " syntax=\"usmarc\""
93             " name=\"marcxml\">"
94             "<backend syntax=\"usmarc\""
95             " name=\"marcxml\""
96             "/>"
97             "</retrieval>"
98             "</retrievalinfo>"
99             "</filter>\n"
100             ;
101          
102         //std::cout << xmlconf  << std::endl;
103
104         // reading and parsing XML conf
105         xmlDocPtr doc = xmlParseMemory(xmlconf.c_str(), xmlconf.size());
106         BOOST_CHECK(doc);
107         xmlNode *root_element = xmlDocGetRootElement(doc);
108
109         // creating and configuring filter
110         mp::filter::RecordTransform f_rec_trans;
111         f_rec_trans.configure(root_element, true);
112         
113         // remeber to free XML DOM
114         xmlFreeDoc(doc);
115         
116         // add only filter to router
117         router.append(f_rec_trans);
118
119         // start testing
120         //check_sru_to_z3950_init(router);
121         //check_sru_to_z3950_search(router, 
122         //                           "@attrset Bib-1 @attr 1=4 the", 
123         //                           "@attrset Bib-1 @attr 1=4 the");
124
125     }
126
127     catch (std::exception &e) {
128         std::cout << e.what() << "\n";
129         BOOST_CHECK (false);
130     }
131
132     catch ( ... ) {
133         BOOST_CHECK (false);
134     }
135 }
136
137 /*
138  * Local variables:
139  * c-basic-offset: 4
140  * indent-tabs-mode: nil
141  * c-file-style: "stroustrup"
142  * End:
143  * vim: shiftwidth=4 tabstop=8 expandtab
144  */