/[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 79 - (hide annotations)
Mon Jan 16 21:47:21 2006 UTC (17 years, 10 months ago) by dpavlin
File MIME type: application/x-troff
File size: 4327 byte(s)
test fix
1 dpavlin 28 #!/usr/bin/perl -w
2    
3     use strict;
4     use blib;
5    
6 dpavlin 78 use Test::More tests => 97;
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 78 skip "no $test1_node node in Hyper Estraier", 87, 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 43 for ( 1 .. 5 ) {
71     ok( $node->out_doc_by_uri( 'test' . $_ ), "out_doc_by_uri test$_");
72 dpavlin 41 }
73 dpavlin 42
74 dpavlin 50 ok($doc = $node->get_doc( $id ), 'get_doc for edit');
75 dpavlin 42 $doc->add_attr('foo', 'bar');
76 dpavlin 50 #diag Dumper($doc);
77 dpavlin 42 ok( $node->edit_doc( $doc ), 'edit_doc');
78 dpavlin 43
79 dpavlin 50 ok( $node->out_doc( $id ), "out_doc $id");
80    
81     ok( ! $node->edit_doc( $doc ), "edit removed");
82    
83 dpavlin 53 my $max = 3;
84    
85 dpavlin 51 ok(my $cond = new Search::Estraier::Condition, 'new cond');
86     ok($cond->set_phrase('girl'), 'cond set_phrase');
87 dpavlin 53 ok($cond->set_max($max), "cond set_max $max");
88 dpavlin 51 ok($cond->set_order('@uri ASCD'), 'cond set_order');
89     ok($cond->add_attr('@title STRINC Material'), 'cond add_attr');
90    
91 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');
92 dpavlin 51
93     ok( my $nrec = $node->search( $cond, 0 ), 'search');
94    
95     isa_ok( $nrec, 'Search::Estraier::NodeResult' );
96    
97 dpavlin 53 cmp_ok($nrec->doc_num, '==', $max, "doc_num = $max");
98    
99 dpavlin 43 for ( 6 .. 10 ) {
100 dpavlin 44 my $uri = 'test' . $_;
101 dpavlin 46 ok( my $id = $node->uri_to_id( $uri ), "uri_to_id $uri");
102     ok( $node->get_doc( $id ), "get_doc $id");
103 dpavlin 44 ok( $node->get_doc_by_uri( $uri ), "get_doc_by_uri $uri");
104 dpavlin 49 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 dpavlin 43 }
111 dpavlin 48
112 dpavlin 72 ok($node->_set_info, "refresh _set_info");
113    
114 dpavlin 48 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 dpavlin 55 ok($node->set_snippet_width( 100, 10, 10 ), "set_snippet_width");
122    
123 dpavlin 56 # user doesn't exist
124     ok(! $node->set_user('foobar', 1), 'set_user');
125    
126 dpavlin 78 ok(my $node1 = new Search::Estraier::Node( "http://localhost:1978/node/$test2_node" ), "new $test2_node");
127     ok($node1->set_auth('admin','admin'), "set_auth $test2_node");
128 dpavlin 57
129 dpavlin 78 # croak_on_error
130    
131     ok(my $node2 = new Search::Estraier::Node( url => "http://localhost:1978/non-existant", croak_on_error => 1 ), "new non-existant");
132 dpavlin 79 throws_ok { $node2->name } qr/404/, 'croak on error';
133 dpavlin 78
134 dpavlin 72 SKIP: {
135 dpavlin 78 skip "no $test2_node in Hyper Estraier, skipping set_link", 2 unless (my $test1_label = $node1->label);
136 dpavlin 72
137 dpavlin 78 ok($node->set_link("http://localhost:1978/node/$test2_node", $test1_label, 42), "set_link $test2_node ($test1_label) 42");
138     ok($node->set_link("http://localhost:1978/node/$test2_node", $test1_label, 0), "set_link $test2_node ($test1_label) delete");
139 dpavlin 73 } # SKIP 2
140 dpavlin 72
141 dpavlin 73 } # SKIP 1
142 dpavlin 72
143 dpavlin 55 diag "over";

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26