Bugzilla – Attachment 83958 Details for
Bug 13937
Add an Elasticsearch-compatible Z39.50/SRU daemon
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 13937: Add tests for search and retrieval
Bug-13937-Add-tests-for-search-and-retrieval.patch (text/plain), 9.11 KB, created by
Ere Maijala
on 2019-01-15 11:56:36 UTC
(
hide
)
Description:
Bug 13937: Add tests for search and retrieval
Filename:
MIME Type:
Creator:
Ere Maijala
Created:
2019-01-15 11:56:36 UTC
Size:
9.11 KB
patch
obsolete
>From 332ce29739fd4e75097652d3b82b1500b9e5a38d Mon Sep 17 00:00:00 2001 >From: Ere Maijala <ere.maijala@helsinki.fi> >Date: Tue, 27 Nov 2018 13:40:44 +0200 >Subject: [PATCH] Bug 13937: Add tests for search and retrieval > >Sponsored-by: National Library of Finland >--- > .../Koha/Z3950Responder/GenericSession.t | 129 +++++++++++++++++ > .../Koha/Z3950Responder/ZebraSession.t | 133 ++++++++++++++++++ > 2 files changed, 262 insertions(+) > create mode 100644 t/db_dependent/Koha/Z3950Responder/GenericSession.t > create mode 100644 t/db_dependent/Koha/Z3950Responder/ZebraSession.t > >diff --git a/t/db_dependent/Koha/Z3950Responder/GenericSession.t b/t/db_dependent/Koha/Z3950Responder/GenericSession.t >new file mode 100644 >index 0000000000..164f53e059 >--- /dev/null >+++ b/t/db_dependent/Koha/Z3950Responder/GenericSession.t >@@ -0,0 +1,129 @@ >+#!/usr/bin/perl >+ >+use Modern::Perl; >+ >+use Test::More tests => 3; >+use t::lib::Mocks qw(mock_preference); >+ >+use YAML; >+use ZOOM; >+ >+BEGIN { >+ use_ok('Koha::Z3950Responder'); >+ use_ok('Koha::Z3950Responder::GenericSession'); >+} >+ >+our $child; >+ >+subtest 'test_search' => sub { >+ >+ plan tests => 9; >+ >+ t::lib::Mocks::mock_preference('SearchEngine', 'Elasticsearch'); >+ >+ my $marc_record_1 = MARC::Record->new(); >+ $marc_record_1->leader(' cam 22 a 4500'); >+ $marc_record_1->append_fields( >+ MARC::Field->new('001', '123'), >+ MARC::Field->new('020', '', '', a => '1-56619-909-3'), >+ MARC::Field->new('100', '', '', a => 'Author 1'), >+ MARC::Field->new('110', '', '', a => 'Corp Author'), >+ MARC::Field->new('210', '', '', a => 'Title 1'), >+ MARC::Field->new('245', '', '', a => 'Title:', b => 'first record'), >+ MARC::Field->new('999', '', '', c => '1234567'), >+ ); >+ >+ my $marc_record_2 = MARC::Record->new(); >+ $marc_record_2->leader(' cam 22 a 4500'); >+ $marc_record_2->append_fields( >+ MARC::Field->new('001', '234'), >+ MARC::Field->new('020', '', '', a => '1-56619-909-3'), >+ MARC::Field->new('100', '', '', a => 'Author 2'), >+ MARC::Field->new('110', '', '', a => 'Corp Author'), >+ MARC::Field->new('210', '', '', a => 'Title 2'), >+ MARC::Field->new('245', '', '', a => 'Title:', b => 'second record'), >+ MARC::Field->new('999', '', '', c => '1234567'), >+ ); >+ >+ my $yaml = new Test::MockModule('YAML'); >+ $yaml->mock('LoadFile', sub { >+ return { >+ biblios => { >+ use => { >+ 1 => 'author', >+ 4 => 'title' >+ } >+ } >+ }; >+ }); >+ >+ my $builder = new Test::MockModule('Koha::SearchEngine::Elasticsearch::QueryBuilder'); >+ $builder->mock('build_query_compat', sub { >+ my ( $self, $operators, $operands ) = @_; >+ >+ return (undef, $operands->[0]); >+ }); >+ >+ my $search = new Test::MockModule('Koha::SearchEngine::Elasticsearch::Search'); >+ $search->mock('simple_search_compat', sub { >+ my ( $self, $query ) = @_; >+ >+ return (1, undef, 0) unless $query eq '((author:(author)) AND (title:(title)))'; >+ >+ my @records = ($marc_record_1, $marc_record_2); >+ return (undef, \@records, 2); >+ }); >+ >+ $child = fork(); >+ if ($child == 0) { >+ my @yaz_options = ( '@:42111' ); >+ my $z = Koha::Z3950Responder->new( { >+ config_dir => '', >+ yaz_options => [ @yaz_options ] >+ }); >+ $z->start(); >+ exit; >+ } >+ sleep(1); >+ >+ my $o = new ZOOM::Options(); >+ $o->option(preferredRecordSyntax => 'xml'); >+ $o->option(elementSetName => 'marcxml'); >+ $o->option(databaseName => 'biblios'); >+ >+ my $Zconn = ZOOM::Connection->create($o); >+ ok($Zconn, 'ZOOM connection created'); >+ >+ $Zconn->connect('127.0.0.1:42111', 0); >+ is($Zconn->errcode(), 0, 'Connection is successful: ' . $Zconn->errmsg()); >+ >+ my $rs = $Zconn->search_pqf('@and @attr 1=1 author @attr 1=4 title'); >+ is($Zconn->errcode(), 0, 'Search is successful: ' . $Zconn->errmsg()); >+ >+ is($rs->size(), 2, 'Two results returned'); >+ >+ my $returned1 = MARC::Record->new_from_xml($rs->record(0)->raw()); >+ ok ($returned1, 'Record 1 returned as MARCXML'); >+ is($returned1->as_xml, $marc_record_1->as_xml, 'Record 1 returned properly'); >+ >+ my $returned2= MARC::Record->new_from_xml($rs->record(1)->raw()); >+ ok ($returned2, 'Record 2 returned as MARCXML'); >+ is($returned2->as_xml, $marc_record_2->as_xml, 'Record 2 returned properly'); >+ >+ is($rs->record(2), undef, 'Record 3 does not exist'); >+ >+ cleanup(); >+}; >+ >+sub cleanup { >+ if ($child) { >+ kill 9, $child; >+ $child = undef; >+ } >+} >+ >+# Fall back to make sure that the Zebra process >+# and files get cleaned up >+END { >+ cleanup(); >+} >diff --git a/t/db_dependent/Koha/Z3950Responder/ZebraSession.t b/t/db_dependent/Koha/Z3950Responder/ZebraSession.t >new file mode 100644 >index 0000000000..d61fcc0ee3 >--- /dev/null >+++ b/t/db_dependent/Koha/Z3950Responder/ZebraSession.t >@@ -0,0 +1,133 @@ >+#!/usr/bin/perl >+ >+use Modern::Perl; >+ >+use Test::More tests => 3; >+use Test::MockObject; >+use t::lib::Mocks qw(mock_preference); >+ >+use YAML; >+use ZOOM; >+ >+BEGIN { >+ use_ok('Koha::Z3950Responder'); >+ use_ok('Koha::Z3950Responder::ZebraSession'); >+} >+ >+our $child; >+ >+subtest 'test_search' => sub { >+ >+ plan tests => 9; >+ >+ t::lib::Mocks::mock_preference('SearchEngine', 'Zebra'); >+ >+ my $marc_record_1 = MARC::Record->new(); >+ $marc_record_1->leader(' cam 22 a 4500'); >+ $marc_record_1->append_fields( >+ MARC::Field->new('001', '123'), >+ MARC::Field->new('020', '', '', a => '1-56619-909-3'), >+ MARC::Field->new('100', '', '', a => 'Author 1'), >+ MARC::Field->new('110', '', '', a => 'Corp Author'), >+ MARC::Field->new('210', '', '', a => 'Title 1'), >+ MARC::Field->new('245', '', '', a => 'Title:', b => 'first record'), >+ MARC::Field->new('999', '', '', c => '1234567'), >+ ); >+ >+ my $marc_record_2 = MARC::Record->new(); >+ $marc_record_2->leader(' cam 22 a 4500'); >+ $marc_record_2->append_fields( >+ MARC::Field->new('001', '234'), >+ MARC::Field->new('020', '', '', a => '1-56619-909-3'), >+ MARC::Field->new('100', '', '', a => 'Author 2'), >+ MARC::Field->new('110', '', '', a => 'Corp Author'), >+ MARC::Field->new('210', '', '', a => 'Title 2'), >+ MARC::Field->new('245', '', '', a => 'Title:', b => 'second record'), >+ MARC::Field->new('999', '', '', c => '1234567'), >+ ); >+ >+ my $context = new Test::MockModule('C4::Context'); >+ $context->mock('Zconn', sub { >+ my $Zconn = new Test::MockObject(); >+ $Zconn->mock('connect', sub {}); >+ $Zconn->mock('err_code', sub { >+ return 0; >+ }); >+ $Zconn->mock('search_pqf', sub { >+ my $results = new Test::MockObject(); >+ $results->mock('size', sub { >+ return 2; >+ }); >+ $results->mock('record_immediate', sub { >+ my ($self, $index) = @_; >+ >+ my $record; >+ if ($index == 0) { >+ $record = $marc_record_1; >+ } elsif ($index == 1) { >+ $record = $marc_record_2; >+ } >+ my $Zrecord = new Test::MockObject(); >+ $Zrecord->mock('raw', sub { >+ return $record->as_xml(); >+ }); >+ return $Zrecord; >+ }); >+ $results->mock('records', sub {}); >+ $results->mock('destroy', sub {}); >+ }); >+ }); >+ >+ $child = fork(); >+ if ($child == 0) { >+ my @yaz_options = ( '@:42111' ); >+ my $z = Koha::Z3950Responder->new( { >+ config_dir => '', >+ yaz_options => [ @yaz_options ] >+ }); >+ $z->start(); >+ exit; >+ } >+ sleep(1); >+ >+ my $o = new ZOOM::Options(); >+ $o->option(preferredRecordSyntax => 'xml'); >+ $o->option(elementSetName => 'marcxml'); >+ $o->option(databaseName => 'biblios'); >+ >+ my $Zconn = ZOOM::Connection->create($o); >+ ok($Zconn, 'ZOOM connection created'); >+ >+ $Zconn->connect('127.0.0.1:42111', 0); >+ is($Zconn->errcode(), 0, 'Connection is successful: ' . $Zconn->errmsg()); >+ >+ my $rs = $Zconn->search_pqf('@and @attr 1=1 author @attr 1=4 title'); >+ is($Zconn->errcode(), 0, 'Search is successful: ' . $Zconn->errmsg()); >+ >+ is($rs->size(), 2, 'Two results returned'); >+ >+ my $returned1 = MARC::Record->new_from_xml($rs->record(0)->raw()); >+ ok ($returned1, 'Record 1 returned as MARCXML'); >+ is($returned1->as_xml, $marc_record_1->as_xml, 'Record 1 returned properly'); >+ >+ my $returned2= MARC::Record->new_from_xml($rs->record(1)->raw()); >+ ok ($returned2, 'Record 2 returned as MARCXML'); >+ is($returned2->as_xml, $marc_record_2->as_xml, 'Record 2 returned properly'); >+ >+ is($rs->record(2), undef, 'Record 3 does not exist'); >+ >+ cleanup(); >+}; >+ >+sub cleanup { >+ if ($child) { >+ kill 9, $child; >+ $child = undef; >+ } >+} >+ >+# Fall back to make sure that the Zebra process >+# and files get cleaned up >+END { >+ cleanup(); >+} >-- >2.17.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 13937
:
46369
|
47417
|
47418
|
47419
|
53503
|
58122
|
58125
|
58126
|
59443
|
59444
|
60735
|
60736
|
60737
|
60738
|
66943
|
66944
|
66945
|
66946
|
69139
|
82562
|
82563
|
82564
|
82565
|
82566
|
82567
|
82589
|
82590
|
82591
|
82592
|
82593
|
82594
|
82595
|
82660
|
82661
|
82662
|
82663
|
82664
|
82665
|
82666
|
82667
|
83780
|
83781
|
83782
|
83783
|
83784
|
83785
|
83786
|
83787
|
83788
|
83789
|
83951
|
83952
|
83953
|
83954
|
83955
|
83956
|
83957
|
83958
|
83959
|
84050
|
84051
|
84052
|
84053
|
84054
|
84055
|
84056
|
84057
|
84058
|
84059
|
84062
|
84063
|
84064
|
84065
|
84066
|
84067
|
84068
|
84069
|
84072
|
84073
|
85112
|
86353
|
86354
|
86355
|
86356
|
86357
|
86358
|
86359
|
86360
|
86361
|
86362
|
86363
|
86364
|
88907
|
88908
|
88909
|
88910
|
88911
|
88912
|
88913
|
88914
|
88915
|
88916
|
88917
|
88918
|
91728
|
91729
|
91730
|
91731
|
91732
|
91733
|
91734
|
91735
|
91736
|
91737
|
91738
|
91739
|
91740
|
93913
|
94097
|
94109
|
94110
|
94209
|
94616
|
94647