1 /* $Id: test_filter_virt_db.cpp,v 1.17 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 "filter_virt_db.hpp"
28 #include "filter_backend_test.hpp"
29 #include "filter_log.hpp"
31 #include "router_chain.hpp"
32 #include "session.hpp"
33 #include "package.hpp"
35 #define BOOST_AUTO_TEST_MAIN
36 #include <boost/test/auto_unit_test.hpp>
39 #include <yaz/pquery.h>
40 #include <yaz/otherinfo.h>
41 using namespace boost::unit_test;
43 namespace mp = metaproxy_1;
45 BOOST_AUTO_UNIT_TEST( test_filter_virt_db_1 )
49 mp::filter::VirtualDB vdb;
56 BOOST_AUTO_UNIT_TEST( test_filter_virt_db_2 )
60 mp::RouterChain router;
62 mp::filter::VirtualDB vdb;
66 // Create package with Z39.50 init request in it
67 // Since there is not vhost given, the virt will make its
68 // own init response (regardless of backend)
72 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
76 pack.request() = apdu;
79 pack.router(router).move();
81 // Inspect that we got Z39.50 init Response OK.
82 yazpp_1::GDU *gdu = &pack.response();
84 BOOST_CHECK(!pack.session().is_closed());
86 Z_GDU *z_gdu = gdu->get();
89 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
90 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
99 static void init(mp::Package &pack, mp::Router &router)
101 // Create package with Z39.50 init request in it
103 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
109 pack.request() = apdu;
112 pack.router(router).move();
114 // Inspect that we got Z39.50 init response
115 yazpp_1::GDU *gdu = &pack.response();
117 BOOST_CHECK(!pack.session().is_closed());
119 Z_GDU *z_gdu = gdu->get();
123 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
124 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
127 static void search(mp::Package &pack, mp::Router &router,
128 const std::string &query, const char *db,
131 // Create package with Z39.50 search request in it
134 Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchRequest);
136 mp::util::pqf(odr, apdu, query);
138 apdu->u.searchRequest->resultSetName = odr_strdup(odr, setname);
140 apdu->u.searchRequest->num_databaseNames = 1;
141 apdu->u.searchRequest->databaseNames = (char**)
142 odr_malloc(odr, sizeof(char *));
143 apdu->u.searchRequest->databaseNames[0] = odr_strdup(odr, db);
149 pack.request() = apdu;
151 Z_GDU *gdu_test = pack.request().get();
152 BOOST_CHECK(gdu_test);
155 pack.router(router).move();
157 // Inspect that we got Z39.50 search response
158 yazpp_1::GDU *gdu = &pack.response();
160 BOOST_CHECK(!pack.session().is_closed());
162 Z_GDU *z_gdu = gdu->get();
166 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
167 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_searchResponse);
170 static void present(mp::Package &pack, mp::Router &router,
171 int start, int number,
174 // Create package with Z39.50 present request in it
177 Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
179 apdu->u.presentRequest->resultSetId = odr_strdup(odr, setname);
180 *apdu->u.presentRequest->resultSetStartPoint = start;
181 *apdu->u.presentRequest->numberOfRecordsRequested = number;
187 pack.request() = apdu;
189 Z_GDU *gdu_test = pack.request().get();
190 BOOST_CHECK(gdu_test);
193 pack.router(router).move();
195 // Inspect that we got Z39.50 present response
196 yazpp_1::GDU *gdu = &pack.response();
198 BOOST_CHECK(!pack.session().is_closed());
200 Z_GDU *z_gdu = gdu->get();
204 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
205 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_presentResponse);
208 BOOST_AUTO_UNIT_TEST( test_filter_virt_db_3 )
212 mp::RouterChain router;
214 mp::filter::Log filter_log1("FRONT");
216 router.append(filter_log1);
219 mp::filter::VirtualDB vdb;
221 vdb.add_map_db2target("Default", "localhost:210", "");
222 mp::filter::Log filter_log2("BACK");
224 router.append(filter_log2);
226 mp::filter::BackendTest btest;
227 router.append(btest);
229 mp::Session session1;
233 mp::Package pack(session1, origin1);
237 // search for database for which there is no map
238 mp::Package pack(session1, origin1);
239 search(pack, router, "computer", "bad_database", "default");
242 // search for database for which there a map
243 mp::Package pack(session1, origin1);
244 search(pack, router, "other", "Default", "default");
247 // present from last search
248 mp::Package pack(session1, origin1);
249 present(pack, router, 1, 2, "default");
261 * indent-tabs-mode: nil
262 * c-file-style: "stroustrup"
264 * vim: shiftwidth=4 tabstop=8 expandtab