/[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

Annotation of /trunk/t/5_Node.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 109 - (hide annotations)
Mon Feb 20 21:21:04 2006 UTC (17 years, 3 months ago) by dpavlin
File MIME type: application/x-troff
File size: 4926 byte(s)
fix test if no test2 exists
1 dpavlin 28 #!/usr/bin/perl -w
2    
3     use strict;
4     use blib;
5    
6 dpavlin 107 use Test::More tests => 106;
7 dpavlin 28 use Test::Exception;
8     use Data::Dumper;
9    
10     BEGIN { use_ok('Search::Estraier') };
11    
12 dpavlin 46 my $debug = 0;
13 dpavlin 40
14 dpavlin 35 # name of node for test
15 dpavlin 78 my $test1_node = 'test1';
16     my $test2_node = 'test2';
17 dpavlin 35
18 dpavlin 57 ok(my $node = new Search::Estraier::Node( debug => $debug ), 'new');
19 dpavlin 28 isa_ok($node, 'Search::Estraier::Node');
20    
21 dpavlin 78 ok($node->set_url("http://localhost:1978/node/$test1_node"), "set_url $test1_node");
22 dpavlin 29
23 dpavlin 38 ok($node->set_proxy('', 8080), 'set_proxy');
24 dpavlin 30 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 dpavlin 31
29 dpavlin 39 ok($node->set_auth('admin','admin'), 'set_auth');
30 dpavlin 32
31     cmp_ok($node->status, '==', -1, 'status');
32 dpavlin 35
33 dpavlin 73 SKIP: {
34    
35 dpavlin 107 skip "no $test1_node node in Hyper Estraier", 97, unless($node->name);
36 dpavlin 73
37 dpavlin 38 my @res = ( -1, 200 );
38    
39 dpavlin 35 my $nodelist;
40 dpavlin 39 foreach my $url (qw{?action=nodelist http://localhost:1978/master?action=nodelist}) {
41 dpavlin 37 cmp_ok(
42     $node->shuttle_url( $url, 'text/plain', undef, \$nodelist)
43 dpavlin 38 ,'==', shift @res, 'nodelist');
44 dpavlin 37 }
45 dpavlin 35
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 dpavlin 40 #diag "draft:\n$draft";
57     ok(my $doc = new Search::Estraier::Document($draft), 'new doc from draft');
58    
59 dpavlin 46 ok( $node->put_doc($doc), "put_doc data001");
60    
61 dpavlin 41 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 dpavlin 50 my $id;
68     ok($id = $node->uri_to_id( 'data001' ), "uri_to_id = $id");
69 dpavlin 41
70 dpavlin 100 my $data_max = 5;
71    
72     for ( 1 .. $data_max ) {
73 dpavlin 43 ok( $node->out_doc_by_uri( 'test' . $_ ), "out_doc_by_uri test$_");
74 dpavlin 41 }
75 dpavlin 42
76 dpavlin 50 ok($doc = $node->get_doc( $id ), 'get_doc for edit');
77 dpavlin 42 $doc->add_attr('foo', 'bar');
78 dpavlin 50 #diag Dumper($doc);
79 dpavlin 42 ok( $node->edit_doc( $doc ), 'edit_doc');
80 dpavlin 43
81 dpavlin 50 ok( $node->out_doc( $id ), "out_doc $id");
82    
83     ok( ! $node->edit_doc( $doc ), "edit removed");
84    
85 dpavlin 53 my $max = 3;
86    
87 dpavlin 51 ok(my $cond = new Search::Estraier::Condition, 'new cond');
88     ok($cond->set_phrase('girl'), 'cond set_phrase');
89 dpavlin 53 ok($cond->set_max($max), "cond set_max $max");
90 dpavlin 51 ok($cond->set_order('@uri ASCD'), 'cond set_order');
91     ok($cond->add_attr('@title STRINC Material'), 'cond add_attr');
92    
93 dpavlin 53 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 dpavlin 51
95 dpavlin 91 ok( my $nres = $node->search( $cond, 0 ), 'search');
96 dpavlin 51
97 dpavlin 91 isa_ok( $nres, 'Search::Estraier::NodeResult' );
98 dpavlin 51
99 dpavlin 91 cmp_ok($nres->doc_num, '==', $max, "doc_num = $max");
100 dpavlin 53
101 dpavlin 100 cmp_ok($nres->hits, '==', $data_max, "hits");
102    
103 dpavlin 43 for ( 6 .. 10 ) {
104 dpavlin 44 my $uri = 'test' . $_;
105 dpavlin 103 ok( my $id = $node->uri_to_id( $uri ), "uri_to_id($uri) = $id");
106 dpavlin 46 ok( $node->get_doc( $id ), "get_doc $id");
107 dpavlin 44 ok( $node->get_doc_by_uri( $uri ), "get_doc_by_uri $uri");
108 dpavlin 49 cmp_ok( $node->get_doc_attr( $id, '@uri' ), 'eq', $uri, "get_doc_attr $id");
109     cmp_ok( $node->get_doc_attr_by_uri( $uri, '@uri' ), 'eq', $uri, "get_doc_attr $id");
110     ok( my $k = $node->etch_doc( $id ), "etch_doc_by_uri $uri");
111     ok( my $k2 = $node->etch_doc_by_uri( $uri ), "etch_doc_by_uri $uri");
112     #diag Dumper($k, $k2);
113     ok( eq_hash( $k, $k2 ), "keywords");
114 dpavlin 43 }
115 dpavlin 48
116 dpavlin 91 ok(my $hints = $nres->hints, 'hints');
117     diag Dumper($hints);
118    
119 dpavlin 72 ok($node->_set_info, "refresh _set_info");
120    
121 dpavlin 48 my $v;
122     ok($v = $node->name, "name: $v");
123     ok($v = $node->label, "label: $v");
124     ok($v = $node->doc_num, "doc_num: $v");
125     ok($v = $node->word_num, "word_num: $v");
126     ok($v = $node->size, "size: $v");
127    
128 dpavlin 55 ok($node->set_snippet_width( 100, 10, 10 ), "set_snippet_width");
129    
130 dpavlin 56 # user doesn't exist
131     ok(! $node->set_user('foobar', 1), 'set_user');
132    
133 dpavlin 94 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 dpavlin 57
136 dpavlin 78 # croak_on_error
137    
138 dpavlin 94 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 dpavlin 78
141 dpavlin 103 # croak_on_error
142 dpavlin 106 ok($node = new Search::Estraier::Node( url => "http://localhost:1978/node/$test1_node", croak_on_error => 1 ), "new $test1_node");
143 dpavlin 94
144 dpavlin 103 ok(! $node->uri_to_id('foobar'), 'uri_to_id without croak');
145    
146 dpavlin 107 # test users
147    
148     ok(! $node->admins, 'no admins');
149     ok(! $node->guests, 'no guests');
150    
151 dpavlin 72 SKIP: {
152 dpavlin 109 skip "no $test2_node in Hyper Estraier, skipping set_link", 5 unless (my $test2_label = $node2->label);
153 dpavlin 72
154 dpavlin 107 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 dpavlin 94 ok($node->set_link("http://localhost:1978/node/$test2_node", $test2_label, 0), "set_link $test2_node ($test2_label) delete");
165 dpavlin 73 } # SKIP 2
166 dpavlin 72
167 dpavlin 73 } # SKIP 1
168 dpavlin 72
169 dpavlin 55 diag "over";

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26