Added files and initial auth_simple filter
[metaproxy-moved-to-github.git] / src / test_filter_auth_simple.cpp
1 /* $Id: test_filter_auth_simple.cpp,v 1.1 2006-01-12 10:04:34 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_auth_simple.hpp"
12 #include "util.hpp"
13 #include "router_chain.hpp"
14 #include "session.hpp"
15 #include "package.hpp"
16
17 #define BOOST_AUTO_TEST_MAIN
18 #include <boost/test/auto_unit_test.hpp>
19
20 using namespace boost::unit_test;
21
22 class FilterBounceInit: public yp2::filter::Base {
23 public:
24     void process(yp2::Package & package) const {
25         
26         if (package.session().is_closed())
27         {
28             // std::cout << "Got Close.\n";
29         }
30        
31         Z_GDU *gdu = package.request().get();
32         if (gdu)
33         {
34             // std::cout << "Got PDU. Sending init response\n";
35             yp2::odr odr;
36             Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse);
37             
38             apdu->u.initResponse->implementationName = "YP2/YAZ";
39             
40             package.response() = apdu;
41         }
42         package.move();
43     };
44 };
45
46
47 BOOST_AUTO_UNIT_TEST( test_filter_auth_simple_1 )
48 {
49     try 
50     {
51         yp2::filter::AuthSimple lf;
52     }
53     catch ( ... ) {
54         BOOST_CHECK (false);
55     }
56 }
57
58 BOOST_AUTO_UNIT_TEST( test_filter_auth_simple2 )
59 {
60     try 
61     {
62         yp2::RouterChain router;
63         
64         yp2::filter::AuthSimple auth;
65         FilterBounceInit bounce;
66         
67         router.append(auth);
68         router.append(bounce);
69         
70         // Create package with Z39.50 init request in it
71         yp2::Package pack;
72         
73         yp2::odr odr;
74         Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
75         
76         pack.request() = apdu;
77         // Done creating query. 
78         
79         // Put it in router
80         pack.router(router).move(); 
81         
82         // Inspect that we got Z39.50 init response
83         yazpp_1::GDU *gdu = &pack.response();
84         
85         Z_GDU *z_gdu = gdu->get();
86         BOOST_CHECK(z_gdu);
87         if (z_gdu) {
88             BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
89             BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
90         }
91     }
92     catch ( ... ) {
93         BOOST_CHECK (false);
94     }
95 }
96
97 /*
98  * Local variables:
99  * c-basic-offset: 4
100  * indent-tabs-mode: nil
101  * c-file-style: "stroustrup"
102  * End:
103  * vim: shiftwidth=4 tabstop=8 expandtab
104  */