/[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 29 by dpavlin, Thu Jan 5 15:30:35 2006 UTC revision 130 by dpavlin, Mon May 8 20:47:48 2006 UTC
# Line 3  Line 3 
3  use strict;  use strict;
4  use blib;  use blib;
5    
6  use Test::More tests => 5;  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  ok(my $node = new Search::Estraier::Node, 'new');  my $debug = 0;
13    
14    # name of node for test
15    my $test1_node = 'test1';
16    my $test2_node = 'test2';
17    
18    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/'), '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');
24    throws_ok {$node->set_proxy('proxy.example.com', 'foo') } qr/port/, 'set_proxy port NaN';
25    
26    ok($node->set_timeout(42), 'set_timeout');
27    throws_ok {$node->set_timeout('foo') } qr/timeout/, 'set_timeout NaN';
28    
29    ok($node->set_auth('admin','admin'), 'set_auth');
30    
31    cmp_ok($node->status, '==', -1, 'status');
32    
33    SKIP: {
34    
35    skip "no $test1_node node in Hyper Estraier", 108, unless($node->name);
36    
37    my @res = ( -1, 200 );
38    
39    my $nodelist;
40    foreach my $url (qw{?action=nodelist http://localhost:1978/master?action=nodelist}) {
41            cmp_ok(
42                    $node->shuttle_url( $url, 'text/plain', undef, \$nodelist)
43            ,'==', shift @res, 'nodelist');
44    }
45    
46    my $draft = <<'_END_OF_DRAFT_';
47    @uri=data001
48    @title=Material Girl
49    
50    Living in a material world
51    And I am a material girl
52    You know that we are living in a material world
53    And I am a material girl
54    _END_OF_DRAFT_
55    
56    #diag "draft:\n$draft";
57    ok(my $doc = new Search::Estraier::Document($draft), 'new doc from draft');
58    
59    ok( $node->put_doc($doc), "put_doc data001");
60    
61    for ( 1 .. 10 ) {
62            $doc->add_attr('@uri', 'test' . $_);
63            ok( $node->put_doc($doc), "put_doc test$_");
64            #diag $doc->dump_draft;
65    }
66    
67    my $id;
68    ok($id = $node->uri_to_id( 'data001' ), "uri_to_id = $id");
69    
70    my $data_max = 5;
71    
72    for ( 1 .. $data_max ) {
73            ok( $node->out_doc_by_uri( 'test' . $_ ), "out_doc_by_uri test$_");
74    }
75    
76    ok($doc = $node->get_doc( $id ), 'get_doc for edit');
77    $doc->add_attr('foo', 'bar');
78    #diag Dumper($doc);
79    ok( $node->edit_doc( $doc ), 'edit_doc');
80    
81    ok( $node->out_doc( $id ), "out_doc $id");
82    
83    ok( ! $node->edit_doc( $doc ), "edit removed");
84    
85    my $max = 3;
86    
87    ok(my $cond = new Search::Estraier::Condition, 'new cond');
88    ok($cond->set_phrase('girl'), 'cond set_phrase');
89    ok($cond->set_max($max), "cond set_max $max");
90    ok($cond->set_order('@uri ASCD'), 'cond set_order');
91    ok($cond->add_attr('@title STRINC Material'), 'cond add_attr');
92    
93    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');
94    
95    ok( my $nres = $node->search( $cond, 0 ), 'search');
96    
97    isa_ok( $nres, 'Search::Estraier::NodeResult' );
98    
99    cmp_ok($nres->doc_num, '==', $max, "doc_num = $max");
100    
101    cmp_ok($nres->hits, '==', $data_max, "hits");
102    
103    for my $i ( 0 .. ($nres->hits - 1) ) {
104            my $uri = 'test' . ($i + $data_max + 1);
105    
106            if ($i < $nres->doc_num) {
107                    ok( my $rdoc = $nres->get_doc( $i ), "get_doc $i");
108    
109                    cmp_ok( $rdoc->attr('@uri'), 'eq', $uri, "\@uri = $uri");
110                    ok( my $k = $rdoc->keywords( $id ), "rdoc keywords");
111            }
112    
113            ok( my $id = $node->uri_to_id( $uri ), "uri_to_id($uri) = $id");
114            ok( $node->get_doc( $id ), "get_doc $id");
115            ok( $node->get_doc_by_uri( $uri ), "get_doc_by_uri $uri");
116            cmp_ok( $node->get_doc_attr( $id, '@uri' ), 'eq', $uri, "get_doc_attr $id");
117            cmp_ok( $node->get_doc_attr_by_uri( $uri, '@uri' ), 'eq', $uri, "get_doc_attr $id");
118            ok( my $k1 = $node->etch_doc( $id ), "etch_doc_by_uri $uri");
119            ok( my $k2 = $node->etch_doc_by_uri( $uri ), "etch_doc_by_uri $uri");
120            #diag Dumper($k, $k2);
121            ok( eq_hash( $k1, $k2 ), "keywords");
122    }
123    
124    ok(my $hints = $nres->hints, 'hints');
125    diag Dumper($hints);
126    
127    ok($node->_set_info, "refresh _set_info");
128    
129    my $v;
130    ok($v = $node->name, "name: $v");
131    ok($v = $node->label, "label: $v");
132    ok($v = $node->doc_num, "doc_num: $v");
133    ok(defined($v = $node->word_num), "word_num: $v");
134    ok($v = $node->size, "size: $v");
135    
136    ok($node->set_snippet_width( 100, 10, 10 ), "set_snippet_width");
137    
138    # user doesn't exist
139    ok(! $node->set_user('foobar', 1), 'set_user');
140    
141    ok(my $node2 = new Search::Estraier::Node( "http://localhost:1978/node/$test2_node" ), "new $test2_node");
142    ok($node2->set_auth('admin','admin'), "set_auth $test2_node");
143    
144    # croak_on_error
145    
146    ok($node = new Search::Estraier::Node( url => "http://localhost:1978/non-existant", croak_on_error => 1 ), "new non-existant");
147    throws_ok { $node->name } qr/404/, 'croak on error';
148    
149    # croak_on_error
150    ok($node = new Search::Estraier::Node( url => "http://localhost:1978/node/$test1_node", croak_on_error => 1 ), "new $test1_node");
151    
152    ok(! $node->uri_to_id('foobar'), 'uri_to_id without croak');
153    
154    # test users
155    
156    ok(! $node->admins, 'no admins');
157    ok(! $node->guests, 'no guests');
158    
159    # test search without results
160    
161    ok($cond = new Search::Estraier::Condition, 'new cond');
162    ok($cond->set_phrase('this_is_phrase_which_does_not_exits'), 'cond set_phrase');
163    
164    ok($nres = $node->search( $cond, 0 ), 'search');
165    
166    SKIP: {
167            skip "no $test2_node in Hyper Estraier, skipping set_link", 5 unless (my $test2_label = $node2->label);
168    
169            my $link_url = "http://localhost:1978/node/$test2_node";
170    
171            ok($node->set_link( $link_url, $test2_label, 42), "set_link $test2_node ($test2_label) 42");
172    
173            ok(my $links = $node->links, 'links');
174    
175            cmp_ok($#{$links}, '==', 0, 'one link');
176    
177            like($links->[0], qr/^$link_url/, 'link correct');
178    
179            ok($node->set_link("http://localhost:1978/node/$test2_node", $test2_label, 0), "set_link $test2_node ($test2_label) delete");
180    }       # SKIP 2
181    
182    }       # SKIP 1
183    
184  ok($node->set_proxy('proxy.example.com', 8080), 'set_proxy');  diag "over";

Legend:
Removed from v.29  
changed lines
  Added in v.130

  ViewVC Help
Powered by ViewVC 1.1.26