a try at mocking of inputs in WebPAC::Input::Test
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 4 Feb 2007 12:42:43 +0000 (12:42 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 4 Feb 2007 12:42:43 +0000 (12:42 +0000)
git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@796 07558da8-63fa-0310-ba24-9fe276d99e06

lib/WebPAC/Input/Test.pm [new file with mode: 0644]
t/2-input.t

diff --git a/lib/WebPAC/Input/Test.pm b/lib/WebPAC/Input/Test.pm
new file mode 100644 (file)
index 0000000..afddbef
--- /dev/null
@@ -0,0 +1,133 @@
+package WebPAC::Input::Test;
+
+use warnings;
+use strict;
+
+use WebPAC::Input;
+use base qw/WebPAC::Common/;
+
+=head1 NAME
+
+WebPAC::Input::Test - Mock test records for WebPAC
+
+=head1 VERSION
+
+Version 0.01
+
+=cut
+
+our $VERSION = '0.01';
+
+=head1 SYNOPSIS
+
+Setup test record
+
+ $WebPAC::Input::Test::rec = {
+       '200' => [ {
+               'a' => 'foo',
+               'b' => 'bar',
+               }, {
+               'a' => 'baz',
+               } ],
+       '900' => [
+               'foobar',
+               ],
+  };
+
+Setup optional size
+
+  $WebPAC::Input::Test::Size = 42;
+
+=head1 FUNCTIONS
+
+=head2 new
+
+  my $isis = new WebPAC::Input::Test(
+       path => '/path/to/LIBRI'
+       filter => sub {
+               my ($l,$field_nr) = @_;
+               # do something with $l which is line of input file
+               return $l;
+       },
+  }
+
+=cut
+
+sub new {
+       my $class = shift;
+       my $self = {@_};
+       bless($self, $class);
+
+       my $arg = {@_};
+
+       $self->_get_logger()->info("mocking Test database with args = ", dump($arg));
+
+       $self ? return $self : return undef;
+}
+
+=head2 fetch_rec
+
+Return record with ID C<$mfn> from database
+
+  my $rec = $isis->fetch_rec( $mfn );
+
+Second argument, C<filter_coderef> is ignored.
+
+=cut
+
+my $rec;
+
+sub fetch_rec {
+       my $self = shift;
+
+       my ($mfn, $filter_coderef) = @_;
+
+       $self->_get_logger()->info("mfn = $mfn");
+
+       return $rec;
+}
+
+=head2 dump_ascii
+
+Return dump of record ID C<$mfn> from database
+
+  my $rec = $isis->dump_ascii( $mfn );
+
+=cut
+
+sub dump_ascii {
+       my $self = shift;
+
+       return dump( $rec );
+}
+
+=head2 size
+
+Return number of records in database
+
+  my $size = $isis->size;
+
+=cut
+
+my $size = 1;
+
+sub size {
+       my $self = shift;
+       $self->_get_logger()->info("size = $size");
+       return $size;
+}
+
+=head1 AUTHOR
+
+Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2007 Dobrica Pavlinusic, All Rights Reserved.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut
+
+1; # End of WebPAC::Input::Test
index 96bfb7f..cb26b19 100755 (executable)
@@ -11,6 +11,7 @@ use Data::Dump qw/dump/;
 BEGIN {
 use_ok( 'WebPAC::Input::ISIS' );
 use_ok( 'WebPAC::Input::MARC' );
+use_ok( 'WebPAC::Input::Test' );
 }
 
 my $debug = shift @ARGV;
@@ -119,10 +120,25 @@ test_after_open($input);
 test_fetch($input, $input->size);
 
 # test modify_record
-$module = 'WebPAC::Input::ISIS';
-ok($input = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1 ), "new $module");
+$module = 'WebPAC::Input::Test';
+ok($input = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1, debug => $debug ), "new $module");
 
 ok($input->open( path => "$abs_path/modify_isis/LIBRI", ), "open modify_isis (plain)");
+
+$WebPAC::Input::Test::rec = {
+       '200' => [ {
+               'a' => 'foo',
+               'b' => 'bar',
+               }, {
+               'a' => 'baz',
+               } ],
+       '900' => [
+               'foobar',
+               ],
+};
+
+ok($input->size, 'size');
+
 ok(my $rec_p = $input->fetch, 'fetch');
 
 # modify_records