1 /* This file is part of Metaproxy.
2 Copyright (C) 2005-2013 Index Data
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
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
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
23 #include "filter_z3950_client.hpp"
24 #include <metaproxy/util.hpp>
26 #include <metaproxy/router_chain.hpp>
27 #include <metaproxy/package.hpp>
29 #define BOOST_AUTO_TEST_MAIN
30 #define BOOST_TEST_DYN_LINK
31 #include <boost/test/auto_unit_test.hpp>
34 #include <yaz/otherinfo.h>
35 #include <yaz/oid_db.h>
37 using namespace boost::unit_test;
38 namespace mp = metaproxy_1;
40 BOOST_AUTO_TEST_CASE( test_filter_z3950_client_1 )
44 mp::filter::Z3950Client zc; // can we construct OK?
51 BOOST_AUTO_TEST_CASE( test_filter_z3950_client_2 )
55 mp::RouterChain router;
57 mp::filter::Z3950Client zc;
61 // Create package with Z39.50 init request in it
65 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
69 pack.request() = apdu;
72 pack.router(router).move();
74 // Inspect that we got Z39.50 init Response - a Z39.50 session MUST
75 // specify a virtual host
76 yazpp_1::GDU *gdu = &pack.response();
78 BOOST_CHECK(pack.session().is_closed());
80 Z_GDU *z_gdu = gdu->get();
83 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
84 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
92 BOOST_AUTO_TEST_CASE( test_filter_z3950_client_3 )
96 mp::RouterChain router;
98 mp::filter::Z3950Client zc;
102 // Create package with Z39.50 present request in it
106 Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
110 pack.request() = apdu;
113 pack.router(router).move();
115 // Inspect that we got Z39.50 close - a Z39.50 session must start
117 yazpp_1::GDU *gdu = &pack.response();
119 BOOST_CHECK(pack.session().is_closed());
121 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_close);
133 BOOST_AUTO_TEST_CASE( test_filter_z3950_client_4 )
137 mp::RouterChain router;
139 mp::filter::Z3950Client zc;
143 // Create package with Z39.50 init request in it
147 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
149 const char *vhost = "localhost:9999";
152 yaz_oi_set_string_oid(&apdu->u.initRequest->otherInfo,
153 odr, yaz_oid_userinfo_proxy, 1, vhost);
157 pack.request() = apdu;
160 pack.router(router).move();
162 if (pack.session().is_closed())
164 // OK, server was not up!
168 // Inspect that we got Z39.50 init response
169 yazpp_1::GDU *gdu = &pack.response();
170 Z_GDU *z_gdu = gdu->get();
173 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
174 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
187 * c-file-style: "Stroustrup"
188 * indent-tabs-mode: nil
190 * vim: shiftwidth=4 tabstop=8 expandtab