1 |
#!/usr/bin/perl -w |
2 |
|
3 |
use strict; |
4 |
use blib; |
5 |
|
6 |
use Test::More tests => 95; |
7 |
use Test::Exception; |
8 |
use Data::Dumper; |
9 |
|
10 |
BEGIN { use_ok('Search::Estraier') }; |
11 |
|
12 |
my $debug = 0; |
13 |
|
14 |
# name of node for test |
15 |
my $test_node = 'test1'; |
16 |
my $test1_node = 'test2'; |
17 |
|
18 |
ok(my $node = new Search::Estraier::Node( debug => $debug ), 'new'); |
19 |
isa_ok($node, 'Search::Estraier::Node'); |
20 |
|
21 |
ok($node->set_url("http://localhost:1978/node/$test_node"), "set_url $test_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 |
my @res = ( -1, 200 ); |
34 |
|
35 |
my $nodelist; |
36 |
foreach my $url (qw{?action=nodelist http://localhost:1978/master?action=nodelist}) { |
37 |
cmp_ok( |
38 |
$node->shuttle_url( $url, 'text/plain', undef, \$nodelist) |
39 |
,'==', shift @res, 'nodelist'); |
40 |
} |
41 |
|
42 |
my $draft = <<'_END_OF_DRAFT_'; |
43 |
@uri=data001 |
44 |
@title=Material Girl |
45 |
|
46 |
Living in a material world |
47 |
And I am a material girl |
48 |
You know that we are living in a material world |
49 |
And I am a material girl |
50 |
_END_OF_DRAFT_ |
51 |
|
52 |
#diag "draft:\n$draft"; |
53 |
ok(my $doc = new Search::Estraier::Document($draft), 'new doc from draft'); |
54 |
|
55 |
SKIP: { |
56 |
|
57 |
skip "no $test_node node in Hyper Estraier", 81, unless($node->name); |
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 |
for ( 1 .. 5 ) { |
71 |
ok( $node->out_doc_by_uri( 'test' . $_ ), "out_doc_by_uri test$_"); |
72 |
} |
73 |
|
74 |
ok($doc = $node->get_doc( $id ), 'get_doc for edit'); |
75 |
$doc->add_attr('foo', 'bar'); |
76 |
#diag Dumper($doc); |
77 |
ok( $node->edit_doc( $doc ), 'edit_doc'); |
78 |
|
79 |
ok( $node->out_doc( $id ), "out_doc $id"); |
80 |
|
81 |
ok( ! $node->edit_doc( $doc ), "edit removed"); |
82 |
|
83 |
my $max = 3; |
84 |
|
85 |
ok(my $cond = new Search::Estraier::Condition, 'new cond'); |
86 |
ok($cond->set_phrase('girl'), 'cond set_phrase'); |
87 |
ok($cond->set_max($max), "cond set_max $max"); |
88 |
ok($cond->set_order('@uri ASCD'), 'cond set_order'); |
89 |
ok($cond->add_attr('@title STRINC Material'), 'cond add_attr'); |
90 |
|
91 |
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'); |
92 |
|
93 |
ok( my $nrec = $node->search( $cond, 0 ), 'search'); |
94 |
|
95 |
isa_ok( $nrec, 'Search::Estraier::NodeResult' ); |
96 |
|
97 |
cmp_ok($nrec->doc_num, '==', $max, "doc_num = $max"); |
98 |
|
99 |
for ( 6 .. 10 ) { |
100 |
my $uri = 'test' . $_; |
101 |
ok( my $id = $node->uri_to_id( $uri ), "uri_to_id $uri"); |
102 |
ok( $node->get_doc( $id ), "get_doc $id"); |
103 |
ok( $node->get_doc_by_uri( $uri ), "get_doc_by_uri $uri"); |
104 |
cmp_ok( $node->get_doc_attr( $id, '@uri' ), 'eq', $uri, "get_doc_attr $id"); |
105 |
cmp_ok( $node->get_doc_attr_by_uri( $uri, '@uri' ), 'eq', $uri, "get_doc_attr $id"); |
106 |
ok( my $k = $node->etch_doc( $id ), "etch_doc_by_uri $uri"); |
107 |
ok( my $k2 = $node->etch_doc_by_uri( $uri ), "etch_doc_by_uri $uri"); |
108 |
#diag Dumper($k, $k2); |
109 |
ok( eq_hash( $k, $k2 ), "keywords"); |
110 |
} |
111 |
|
112 |
ok($node->_set_info, "refresh _set_info"); |
113 |
|
114 |
my $v; |
115 |
ok($v = $node->name, "name: $v"); |
116 |
ok($v = $node->label, "label: $v"); |
117 |
ok($v = $node->doc_num, "doc_num: $v"); |
118 |
ok($v = $node->word_num, "word_num: $v"); |
119 |
ok($v = $node->size, "size: $v"); |
120 |
|
121 |
ok($node->set_snippet_width( 100, 10, 10 ), "set_snippet_width"); |
122 |
|
123 |
# user doesn't exist |
124 |
ok(! $node->set_user('foobar', 1), 'set_user'); |
125 |
|
126 |
ok(my $node1 = new Search::Estraier::Node( "http://localhost:1978/node/$test1_node" ), "new $test1_node"); |
127 |
ok($node1->set_auth('admin','admin'), "set_auth $test1_node"); |
128 |
|
129 |
SKIP: { |
130 |
skip "no $test1_node in Hyper Estraier, skipping set_link", 2 unless (my $test1_label = $node1->label); |
131 |
|
132 |
ok($node->set_link("http://localhost:1978/node/$test1_node", $test1_label, 42), "set_link $test1_node ($test1_label) 42"); |
133 |
ok($node->set_link("http://localhost:1978/node/$test1_node", $test1_label, 0), "set_link $test1_node ($test1_label) delete"); |
134 |
} |
135 |
|
136 |
} |
137 |
|
138 |
diag "over"; |