3
# This was actually a part of the test suite - but because it starts
4
# an external process it was safer not to use it as a test (the process
5
# could be left running if an error occurs).
7
# It is an example of a TCP-based SOAP exchange.
11
eval { require SOAP::Lite;
14
die("must have SOAP::Lite installed to run this script");
17
use vars qw($NUMTESTS);
22
# to handle systems with no installed Test module
23
# we include the t dir (where a copy of Test.pm is located)
25
eval { require Test; };
39
# --- launch a testing SOAP server
40
my ($pid, $port, $max_port);
42
$max_port = $port + 100;
47
my $biblio = new Bio::Biblio (-location => "tcp://localhost:$port",
48
-namespace => 'soap_server');
50
ok ($biblio->get_count, '43');
51
ok ($biblio->get_by_id ('X'), 'X');
52
ok ($biblio->find ('a,b','c,d')->get_collection_id, 'a,b,c,d');
53
ok ($biblio->find (['x', 'y'], ['u', 'v'])->get_collection_id, 'x,y,u,v');
55
ok ( eval { join (',', @{ $biblio->find ('AAA')->get_all_ids }) }, 'AAA'); print STDERR $@ if $@;
57
ok ( eval { join (',', @{ $biblio->find ('XXX')->get_all }) }, 'XXX'); print STDERR $@ if $@;
59
ok ( eval { $biblio->find (46)->has_next }, 1); print STDERR $@ if $@;
61
ok ( eval { $biblio->find ('BBB')->get_next }, 'BBB'); print STDERR $@ if $@;
63
ok ( eval { join (',', @{ $biblio->find ('CCC')->get_more (3) }) }, 'CCC,CCC,CCC'); print STDERR $@ if $@;
65
ok ( eval { $biblio->find (46)->exists }, 0); print STDERR $@ if $@;
68
# clean-up the running server
69
kill 9, $pid if defined $pid;
70
print " SOAP server $pid killed\n";
72
} elsif (defined $pid) {
73
# child here - a testing SOAP server
77
use SOAP::Transport::TCP;
79
while ($port < $max_port) {
81
$daemon = SOAP::Transport::TCP::Server
82
-> new (LocalAddr => 'localhost', LocalPort => $port, Listen => 5, Reuse => 1)
83
-> dispatch_to('soap_server');
88
print " Contact to SOAP server at ", join(':', $daemon->sockhost, $daemon->sockport), " (server PID: $$)\n";
91
sub getBibRefCount { shift; return 43; }
92
sub getById { shift; return shift; }
94
my ($self, $keywords, $attrs) = @_;
95
return join (',', (@{ $keywords }, @{ $attrs })) if $attrs;
96
return join (',', @{ $keywords });
98
sub getAllIDs { shift; return [ shift ] }
99
sub getAllBibRefs { shift; return [ shift ] }
100
sub hasNext { return SOAP::Data->type (boolean => 'true'); }
101
sub getNext { shift; return [ '1', shift]; }
103
my ($self, $id, $how_many) = @_;
105
push (@result, $id) for (1..$how_many);
108
sub exists { return SOAP::Data->type (boolean => '0'); }
115
print STDERR "Testing SOAP services FAILED: $!.\n";