3 |
use strict; |
use strict; |
4 |
use blib; |
use blib; |
5 |
|
|
6 |
use Test::More tests => 90; |
use Test::More tests => 106; |
7 |
use Test::Exception; |
use Test::Exception; |
8 |
use Data::Dumper; |
use Data::Dumper; |
9 |
|
|
12 |
my $debug = 0; |
my $debug = 0; |
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'; |
30 |
|
|
31 |
cmp_ok($node->status, '==', -1, 'status'); |
cmp_ok($node->status, '==', -1, 'status'); |
32 |
|
|
33 |
|
SKIP: { |
34 |
|
|
35 |
|
skip "no $test1_node node in Hyper Estraier", 96, unless($node->name); |
36 |
|
|
37 |
my @res = ( -1, 200 ); |
my @res = ( -1, 200 ); |
38 |
|
|
39 |
my $nodelist; |
my $nodelist; |
67 |
my $id; |
my $id; |
68 |
ok($id = $node->uri_to_id( 'data001' ), "uri_to_id = $id"); |
ok($id = $node->uri_to_id( 'data001' ), "uri_to_id = $id"); |
69 |
|
|
70 |
for ( 1 .. 5 ) { |
my $data_max = 5; |
71 |
|
|
72 |
|
for ( 1 .. $data_max ) { |
73 |
ok( $node->out_doc_by_uri( 'test' . $_ ), "out_doc_by_uri test$_"); |
ok( $node->out_doc_by_uri( 'test' . $_ ), "out_doc_by_uri test$_"); |
74 |
} |
} |
75 |
|
|
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'); |
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 $nrec = $node->search( $cond, 0 ), 'search'); |
ok( my $nres = $node->search( $cond, 0 ), 'search'); |
96 |
|
|
97 |
isa_ok( $nrec, 'Search::Estraier::NodeResult' ); |
isa_ok( $nres, 'Search::Estraier::NodeResult' ); |
98 |
|
|
99 |
cmp_ok($nrec->doc_num, '==', $max, "doc_num = $max"); |
cmp_ok($nres->doc_num, '==', $max, "doc_num = $max"); |
100 |
|
|
101 |
|
cmp_ok($nres->hits, '==', $data_max, "hits"); |
102 |
|
|
103 |
for ( 6 .. 10 ) { |
for ( 6 .. 10 ) { |
104 |
my $uri = 'test' . $_; |
my $uri = 'test' . $_; |
105 |
ok( my $id = $node->uri_to_id( $uri ), "uri_to_id $uri"); |
ok( my $id = $node->uri_to_id( $uri ), "uri_to_id($uri) = $id"); |
106 |
ok( $node->get_doc( $id ), "get_doc $id"); |
ok( $node->get_doc( $id ), "get_doc $id"); |
107 |
ok( $node->get_doc_by_uri( $uri ), "get_doc_by_uri $uri"); |
ok( $node->get_doc_by_uri( $uri ), "get_doc_by_uri $uri"); |
108 |
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"); |
113 |
ok( eq_hash( $k, $k2 ), "keywords"); |
ok( eq_hash( $k, $k2 ), "keywords"); |
114 |
} |
} |
115 |
|
|
116 |
|
ok(my $hints = $nres->hints, 'hints'); |
117 |
|
diag Dumper($hints); |
118 |
|
|
119 |
|
ok($node->_set_info, "refresh _set_info"); |
120 |
|
|
121 |
my $v; |
my $v; |
122 |
ok($v = $node->name, "name: $v"); |
ok($v = $node->name, "name: $v"); |
123 |
ok($v = $node->label, "label: $v"); |
ok($v = $node->label, "label: $v"); |
124 |
ok($v = $node->doc_num, "doc_num: $v"); |
ok($v = $node->doc_num, "doc_num: $v"); |
125 |
ok($v = $node->word_num, "word_num: $v"); |
ok(defined($v = $node->word_num), "word_num: $v"); |
126 |
ok($v = $node->size, "size: $v"); |
ok($v = $node->size, "size: $v"); |
127 |
|
|
128 |
ok($node->set_snippet_width( 100, 10, 10 ), "set_snippet_width"); |
ok($node->set_snippet_width( 100, 10, 10 ), "set_snippet_width"); |
130 |
# user doesn't exist |
# user doesn't exist |
131 |
ok(! $node->set_user('foobar', 1), 'set_user'); |
ok(! $node->set_user('foobar', 1), 'set_user'); |
132 |
|
|
133 |
|
ok(my $node2 = new Search::Estraier::Node( "http://localhost:1978/node/$test2_node" ), "new $test2_node"); |
134 |
|
ok($node2->set_auth('admin','admin'), "set_auth $test2_node"); |
135 |
|
|
136 |
|
# croak_on_error |
137 |
|
|
138 |
|
ok($node = new Search::Estraier::Node( url => "http://localhost:1978/non-existant", croak_on_error => 1 ), "new non-existant"); |
139 |
|
throws_ok { $node->name } qr/404/, 'croak on error'; |
140 |
|
|
141 |
|
# croak_on_error |
142 |
|
ok($node = new Search::Estraier::Node( url => "http://localhost:1978/node/$test1_node", croak_on_error => 1 ), "new $test1_node"); |
143 |
|
|
144 |
|
ok(! $node->uri_to_id('foobar'), 'uri_to_id without croak'); |
145 |
|
|
146 |
|
# test users |
147 |
|
|
148 |
|
ok(! $node->admins, 'no admins'); |
149 |
|
ok(! $node->guests, 'no guests'); |
150 |
|
|
151 |
|
SKIP: { |
152 |
|
skip "no $test2_node in Hyper Estraier, skipping set_link", 5 unless (my $test2_label = $node2->label); |
153 |
|
|
154 |
|
my $link_url = "http://localhost:1978/node/$test2_node"; |
155 |
|
|
156 |
|
ok($node->set_link( $link_url, $test2_label, 42), "set_link $test2_node ($test2_label) 42"); |
157 |
|
|
158 |
|
ok(my $links = $node->links, 'links'); |
159 |
|
|
160 |
|
cmp_ok($#{$links}, '==', 0, 'one link'); |
161 |
|
|
162 |
|
like($links->[0], qr/^$link_url/, 'link correct'); |
163 |
|
|
164 |
|
ok($node->set_link("http://localhost:1978/node/$test2_node", $test2_label, 0), "set_link $test2_node ($test2_label) delete"); |
165 |
|
} # SKIP 2 |
166 |
|
|
167 |
|
} # SKIP 1 |
168 |
|
|
169 |
diag "over"; |
diag "over"; |