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

Contents of /trunk/t/5_Node.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 56 - (show annotations)
Fri Jan 6 20:45:48 2006 UTC (17 years, 5 months ago) by dpavlin
File MIME type: application/x-troff
File size: 3400 byte(s)
added set_user
1 #!/usr/bin/perl -w
2
3 use strict;
4 use blib;
5
6 use Test::More tests => 90;
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 = 'Search-Estraier';
16
17 ok(my $node = new Search::Estraier::Node($debug), 'new');
18 isa_ok($node, 'Search::Estraier::Node');
19
20 ok($node->set_url('http://localhost:1978/node/searchestraier'), 'set_url');
21
22 ok($node->set_proxy('', 8080), 'set_proxy');
23 throws_ok {$node->set_proxy('proxy.example.com', 'foo') } qr/port/, 'set_proxy port NaN';
24
25 ok($node->set_timeout(42), 'set_timeout');
26 throws_ok {$node->set_timeout('foo') } qr/timeout/, 'set_timeout NaN';
27
28 ok($node->set_auth('admin','admin'), 'set_auth');
29
30 cmp_ok($node->status, '==', -1, 'status');
31
32 my @res = ( -1, 200 );
33
34 my $nodelist;
35 foreach my $url (qw{?action=nodelist http://localhost:1978/master?action=nodelist}) {
36 cmp_ok(
37 $node->shuttle_url( $url, 'text/plain', undef, \$nodelist)
38 ,'==', shift @res, 'nodelist');
39 }
40
41 my $draft = <<'_END_OF_DRAFT_';
42 @uri=data001
43 @title=Material Girl
44
45 Living in a material world
46 And I am a material girl
47 You know that we are living in a material world
48 And I am a material girl
49 _END_OF_DRAFT_
50
51 #diag "draft:\n$draft";
52 ok(my $doc = new Search::Estraier::Document($draft), 'new doc from draft');
53
54 ok( $node->put_doc($doc), "put_doc data001");
55
56 for ( 1 .. 10 ) {
57 $doc->add_attr('@uri', 'test' . $_);
58 ok( $node->put_doc($doc), "put_doc test$_");
59 #diag $doc->dump_draft;
60 }
61
62 my $id;
63 ok($id = $node->uri_to_id( 'data001' ), "uri_to_id = $id");
64
65 for ( 1 .. 5 ) {
66 ok( $node->out_doc_by_uri( 'test' . $_ ), "out_doc_by_uri test$_");
67 }
68
69 ok($doc = $node->get_doc( $id ), 'get_doc for edit');
70 $doc->add_attr('foo', 'bar');
71 #diag Dumper($doc);
72 ok( $node->edit_doc( $doc ), 'edit_doc');
73
74 ok( $node->out_doc( $id ), "out_doc $id");
75
76 ok( ! $node->edit_doc( $doc ), "edit removed");
77
78 my $max = 3;
79
80 ok(my $cond = new Search::Estraier::Condition, 'new cond');
81 ok($cond->set_phrase('girl'), 'cond set_phrase');
82 ok($cond->set_max($max), "cond set_max $max");
83 ok($cond->set_order('@uri ASCD'), 'cond set_order');
84 ok($cond->add_attr('@title STRINC Material'), 'cond add_attr');
85
86 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');
87
88 ok( my $nrec = $node->search( $cond, 0 ), 'search');
89
90 isa_ok( $nrec, 'Search::Estraier::NodeResult' );
91
92 cmp_ok($nrec->doc_num, '==', $max, "doc_num = $max");
93
94 for ( 6 .. 10 ) {
95 my $uri = 'test' . $_;
96 ok( my $id = $node->uri_to_id( $uri ), "uri_to_id $uri");
97 ok( $node->get_doc( $id ), "get_doc $id");
98 ok( $node->get_doc_by_uri( $uri ), "get_doc_by_uri $uri");
99 cmp_ok( $node->get_doc_attr( $id, '@uri' ), 'eq', $uri, "get_doc_attr $id");
100 cmp_ok( $node->get_doc_attr_by_uri( $uri, '@uri' ), 'eq', $uri, "get_doc_attr $id");
101 ok( my $k = $node->etch_doc( $id ), "etch_doc_by_uri $uri");
102 ok( my $k2 = $node->etch_doc_by_uri( $uri ), "etch_doc_by_uri $uri");
103 #diag Dumper($k, $k2);
104 ok( eq_hash( $k, $k2 ), "keywords");
105 }
106
107 my $v;
108 ok($v = $node->name, "name: $v");
109 ok($v = $node->label, "label: $v");
110 ok($v = $node->doc_num, "doc_num: $v");
111 ok($v = $node->word_num, "word_num: $v");
112 ok($v = $node->size, "size: $v");
113
114 ok($node->set_snippet_width( 100, 10, 10 ), "set_snippet_width");
115
116 # user doesn't exist
117 ok(! $node->set_user('foobar', 1), 'set_user');
118
119 diag "over";

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26