1 /* $Id: test_filter_virt_db.cpp,v 1.18 2007-11-02 17:47:41 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 #define BOOST_TEST_DYN_LINK
37 #include <boost/test/auto_unit_test.hpp>
40 #include <yaz/pquery.h>
41 #include <yaz/otherinfo.h>
42 using namespace boost::unit_test;
44 namespace mp = metaproxy_1;
46 BOOST_AUTO_TEST_CASE( test_filter_virt_db_1 )
50 mp::filter::VirtualDB vdb;
57 BOOST_AUTO_TEST_CASE( test_filter_virt_db_2 )
61 mp::RouterChain router;
63 mp::filter::VirtualDB vdb;
67 // Create package with Z39.50 init request in it
68 // Since there is not vhost given, the virt will make its
69 // own init response (regardless of backend)
73 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
77 pack.request() = apdu;
80 pack.router(router).move();
82 // Inspect that we got Z39.50 init Response OK.
83 yazpp_1::GDU *gdu = &pack.response();
85 BOOST_CHECK(!pack.session().is_closed());
87 Z_GDU *z_gdu = gdu->get();
90 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
91 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
100 static void init(mp::Package &pack, mp::Router &router)
102 // Create package with Z39.50 init request in it
104 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
110 pack.request() = apdu;
113 pack.router(router).move();
115 // Inspect that we got Z39.50 init response
116 yazpp_1::GDU *gdu = &pack.response();
118 BOOST_CHECK(!pack.session().is_closed());
120 Z_GDU *z_gdu = gdu->get();
124 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
125 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
128 static void search(mp::Package &pack, mp::Router &router,
129 const std::string &query, const char *db,
132 // Create package with Z39.50 search request in it
135 Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchRequest);
137 mp::util::pqf(odr, apdu, query);
139 apdu->u.searchRequest->resultSetName = odr_strdup(odr, setname);
141 apdu->u.searchRequest->num_databaseNames = 1;
142 apdu->u.searchRequest->databaseNames = (char**)
143 odr_malloc(odr, sizeof(char *));
144 apdu->u.searchRequest->databaseNames[0] = odr_strdup(odr, db);
150 pack.request() = apdu;
152 Z_GDU *gdu_test = pack.request().get();
153 BOOST_CHECK(gdu_test);
156 pack.router(router).move();
158 // Inspect that we got Z39.50 search response
159 yazpp_1::GDU *gdu = &pack.response();
161 BOOST_CHECK(!pack.session().is_closed());
163 Z_GDU *z_gdu = gdu->get();
167 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
168 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_searchResponse);
171 static void present(mp::Package &pack, mp::Router &router,
172 int start, int number,
175 // Create package with Z39.50 present request in it
178 Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
180 apdu->u.presentRequest->resultSetId = odr_strdup(odr, setname);
181 *apdu->u.presentRequest->resultSetStartPoint = start;
182 *apdu->u.presentRequest->numberOfRecordsRequested = number;
188 pack.request() = apdu;
190 Z_GDU *gdu_test = pack.request().get();
191 BOOST_CHECK(gdu_test);
194 pack.router(router).move();
196 // Inspect that we got Z39.50 present response
197 yazpp_1::GDU *gdu = &pack.response();
199 BOOST_CHECK(!pack.session().is_closed());
201 Z_GDU *z_gdu = gdu->get();
205 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
206 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_presentResponse);
209 BOOST_AUTO_TEST_CASE( test_filter_virt_db_3 )
213 mp::RouterChain router;
215 mp::filter::Log filter_log1("FRONT");
217 router.append(filter_log1);
220 mp::filter::VirtualDB vdb;
222 vdb.add_map_db2target("Default", "localhost:210", "");
223 mp::filter::Log filter_log2("BACK");
225 router.append(filter_log2);
227 mp::filter::BackendTest btest;
228 router.append(btest);
230 mp::Session session1;
234 mp::Package pack(session1, origin1);
238 // search for database for which there is no map
239 mp::Package pack(session1, origin1);
240 search(pack, router, "computer", "bad_database", "default");
243 // search for database for which there a map
244 mp::Package pack(session1, origin1);
245 search(pack, router, "other", "Default", "default");
248 // present from last search
249 mp::Package pack(session1, origin1);
250 present(pack, router, 1, 2, "default");
262 * indent-tabs-mode: nil
263 * c-file-style: "stroustrup"
265 * vim: shiftwidth=4 tabstop=8 expandtab