/[Search-Estraier]/trunk/t/5_Node.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/t/5_Node.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 56 by dpavlin, Fri Jan 6 20:45:48 2006 UTC revision 134 by dpavlin, Tue May 9 12:21:26 2006 UTC
# Line 3  Line 3 
3  use strict;  use strict;
4  use blib;  use blib;
5    
6  use Test::More tests => 90;  use Test::More tests => 118;
7  use Test::Exception;  use Test::Exception;
8  use Data::Dumper;  use Data::Dumper;
9    
10  BEGIN { use_ok('Search::Estraier') };  BEGIN { use_ok('Search::Estraier') };
11    
12  my $debug = 0;  my $debug = 1;
13    
14  # name of node for test  # name of node for test
15  my $test_node = 'Search-Estraier';  my $test1_node = 'test1';
16    my $test2_node = 'test2';
17    
18  ok(my $node = new Search::Estraier::Node($debug), 'new');  ok(my $node = new Search::Estraier::Node( debug => $debug ), 'new');
19  isa_ok($node, 'Search::Estraier::Node');  isa_ok($node, 'Search::Estraier::Node');
20    
21  ok($node->set_url('http://localhost:1978/node/searchestraier'), 'set_url');  ok($node->set_url("http://localhost:1978/node/$test1_node"), "set_url $test1_node");
22    
23  ok($node->set_proxy('', 8080), 'set_proxy');  ok($node->set_proxy('', 8080), 'set_proxy');
24  throws_ok {$node->set_proxy('proxy.example.com', 'foo') } qr/port/, 'set_proxy port NaN';  throws_ok {$node->set_proxy('proxy.example.com', 'foo') } qr/port/, 'set_proxy port NaN';
# Line 29  ok($node->set_auth('admin','admin'), 'se Line 30  ok($node->set_auth('admin','admin'), 'se
30    
31  cmp_ok($node->status, '==', -1, 'status');  cmp_ok($node->status, '==', -1, 'status');
32    
33    # test master functionality
34    
35    ok($node->master( action => 'sync' ), 'sync');
36    
37    
38    SKIP: {
39    
40    skip "no $test1_node node in Hyper Estraier", 108, unless($node->name);
41    
42  my @res = ( -1, 200 );  my @res = ( -1, 200 );
43    
44  my $nodelist;  my $nodelist;
# Line 62  for ( 1 .. 10 ) { Line 72  for ( 1 .. 10 ) {
72  my $id;  my $id;
73  ok($id = $node->uri_to_id( 'data001' ), "uri_to_id = $id");  ok($id = $node->uri_to_id( 'data001' ), "uri_to_id = $id");
74    
75  for ( 1 .. 5 ) {  my $data_max = 5;
76    
77    for ( 1 .. $data_max ) {
78          ok( $node->out_doc_by_uri( 'test' . $_ ), "out_doc_by_uri test$_");          ok( $node->out_doc_by_uri( 'test' . $_ ), "out_doc_by_uri test$_");
79  }  }
80    
# Line 85  ok($cond->add_attr('@title STRINC Materi Line 97  ok($cond->add_attr('@title STRINC Materi
97    
98  cmp_ok($node->cond_to_query( $cond ), 'eq' , 'phrase=girl&attr1=%40title%20STRINC%20Material&order=%40uri%20ASCD&max='.$max.'&wwidth=480&hwidth=96&awidth=96', 'cond_to_query');  cmp_ok($node->cond_to_query( $cond ), 'eq' , 'phrase=girl&attr1=%40title%20STRINC%20Material&order=%40uri%20ASCD&max='.$max.'&wwidth=480&hwidth=96&awidth=96', 'cond_to_query');
99    
100  ok( my $nrec = $node->search( $cond, 0 ), 'search');  ok( my $nres = $node->search( $cond, 0 ), 'search');
101    
102    isa_ok( $nres, 'Search::Estraier::NodeResult' );
103    
104    cmp_ok($nres->doc_num, '==', $max, "doc_num = $max");
105    
106  isa_ok( $nrec, 'Search::Estraier::NodeResult' );  cmp_ok($nres->hits, '==', $data_max, "hits");
107    
108  cmp_ok($nrec->doc_num, '==', $max, "doc_num = $max");  for my $i ( 0 .. ($nres->hits - 1) ) {
109            my $uri = 'test' . ($i + $data_max + 1);
110    
111  for ( 6 .. 10 ) {          if ($i < $nres->doc_num) {
112          my $uri = 'test' . $_;                  ok( my $rdoc = $nres->get_doc( $i ), "get_doc $i");
113          ok( my $id = $node->uri_to_id( $uri ), "uri_to_id $uri");  
114                    cmp_ok( $rdoc->attr('@uri'), 'eq', $uri, "\@uri = $uri");
115                    ok( my $k = $rdoc->keywords( $id ), "rdoc keywords");
116            }
117    
118            ok( my $id = $node->uri_to_id( $uri ), "uri_to_id($uri) = $id");
119          ok( $node->get_doc( $id ), "get_doc $id");          ok( $node->get_doc( $id ), "get_doc $id");
120          ok( $node->get_doc_by_uri( $uri ), "get_doc_by_uri $uri");          ok( $node->get_doc_by_uri( $uri ), "get_doc_by_uri $uri");
121          cmp_ok( $node->get_doc_attr( $id, '@uri' ), 'eq', $uri, "get_doc_attr $id");          cmp_ok( $node->get_doc_attr( $id, '@uri' ), 'eq', $uri, "get_doc_attr $id");
122          cmp_ok( $node->get_doc_attr_by_uri( $uri, '@uri' ), 'eq', $uri, "get_doc_attr $id");          cmp_ok( $node->get_doc_attr_by_uri( $uri, '@uri' ), 'eq', $uri, "get_doc_attr $id");
123          ok( my $k = $node->etch_doc( $id ), "etch_doc_by_uri $uri");          ok( my $k1 = $node->etch_doc( $id ), "etch_doc_by_uri $uri");
124          ok( my $k2 = $node->etch_doc_by_uri( $uri ), "etch_doc_by_uri $uri");          ok( my $k2 = $node->etch_doc_by_uri( $uri ), "etch_doc_by_uri $uri");
125          #diag Dumper($k, $k2);          #diag Dumper($k, $k2);
126          ok( eq_hash( $k, $k2 ), "keywords");          ok( eq_hash( $k1, $k2 ), "keywords");
127  }  }
128    
129    ok(my $hints = $nres->hints, 'hints');
130    diag Dumper($hints);
131    
132    ok($node->_set_info, "refresh _set_info");
133    
134  my $v;  my $v;
135  ok($v = $node->name, "name: $v");  ok($v = $node->name, "name: $v");
136  ok($v = $node->label, "label: $v");  ok($v = $node->label, "label: $v");
137  ok($v = $node->doc_num, "doc_num: $v");  ok($v = $node->doc_num, "doc_num: $v");
138  ok($v = $node->word_num, "word_num: $v");  ok(defined($v = $node->word_num), "word_num: $v");
139  ok($v = $node->size, "size: $v");  ok($v = $node->size, "size: $v");
140    
141  ok($node->set_snippet_width( 100, 10, 10 ), "set_snippet_width");  ok($node->set_snippet_width( 100, 10, 10 ), "set_snippet_width");
# Line 116  ok($node->set_snippet_width( 100, 10, 10 Line 143  ok($node->set_snippet_width( 100, 10, 10
143  # user doesn't exist  # user doesn't exist
144  ok(! $node->set_user('foobar', 1), 'set_user');  ok(! $node->set_user('foobar', 1), 'set_user');
145    
146    ok(my $node2 = new Search::Estraier::Node( "http://localhost:1978/node/$test2_node" ), "new $test2_node");
147    ok($node2->set_auth('admin','admin'), "set_auth $test2_node");
148    
149    # croak_on_error
150    
151    ok($node = new Search::Estraier::Node( url => "http://localhost:1978/non-existant", croak_on_error => 1 ), "new non-existant");
152    throws_ok { $node->name } qr/404/, 'croak on error';
153    
154    # croak_on_error
155    ok($node = new Search::Estraier::Node( url => "http://localhost:1978/node/$test1_node", croak_on_error => 1 ), "new $test1_node");
156    
157    ok(! $node->uri_to_id('foobar'), 'uri_to_id without croak');
158    
159    # test users
160    
161    ok(! $node->admins, 'no admins');
162    ok(! $node->guests, 'no guests');
163    
164    # test search without results
165    
166    ok($cond = new Search::Estraier::Condition, 'new cond');
167    ok($cond->set_phrase('this_is_phrase_which_does_not_exits'), 'cond set_phrase');
168    
169    ok($nres = $node->search( $cond, 0 ), 'search');
170    
171    SKIP: {
172            skip "no $test2_node in Hyper Estraier, skipping set_link", 5 unless (my $test2_label = $node2->label);
173    
174            my $link_url = "http://localhost:1978/node/$test2_node";
175    
176            ok($node->set_link( $link_url, $test2_label, 42), "set_link $test2_node ($test2_label) 42");
177    
178            ok(my $links = $node->links, 'links');
179    
180            cmp_ok($#{$links}, '==', 0, 'one link');
181    
182            like($links->[0], qr/^$link_url/, 'link correct');
183    
184            ok($node->set_link("http://localhost:1978/node/$test2_node", $test2_label, 0), "set_link $test2_node ($test2_label) delete");
185    }       # SKIP 2
186    
187    }       # SKIP 1
188    
189  diag "over";  diag "over";

Legend:
Removed from v.56  
changed lines
  Added in v.134

  ViewVC Help
Powered by ViewVC 1.1.26