1#!/bin/env perl 
2
3BEGIN {
4    unless(grep /blib/, @INC) {
5        chdir 't' if -d 't';
6        unshift @INC, '../lib' if -d '../lib';
7    }
8}
9
10use strict;
11use Test;
12
13use SOAP::Lite
14    on_fault => sub {
15        my $soap = shift;
16        my $res = shift;
17        ref $res
18            ? warn(join " ", "SOAP FAULT:", $res->faultstring, "\n") 
19            : warn(join " ", "TRANSPORT ERROR:", $soap->transport->status, "\n");
20        return new SOAP::SOM;
21    };
22
23$SOAP::Constants::DO_NOT_USE_CHARSET = 1;
24
25my($a, $s, $r, $serialized, $deserialized);
26
27# ------------------------------------------------------
28use SOAP::Test;
29
30$s = SOAP::Lite->uri('http://something/somewhere')->proxy('http://services.xmethods.net/soap/servlet/rpcrouter')->on_fault(sub{});
31eval { 
32    $s->transport->timeout($SOAP::Test::TIMEOUT = $SOAP::Test::TIMEOUT)
33};
34$r = $s->test_connection;
35
36unless (defined $r && defined $r->envelope) {
37    print "1..0 # Skip: ", $s->transport->status, "\n"; 
38    exit;
39}
40# ------------------------------------------------------
41
42plan tests => 21;
43
44{
45# Public test server with Frontier implementation (http://soap.weblogs.com/)
46    print "Frontier server test(s)...\n";
47    $s = SOAP::Lite 
48        -> uri('/examples')
49        -> on_action(sub { sprintf '"%s"', @_ })
50        -> proxy('http://superhonker.userland.com/', timeout => $SOAP::Test::TIMEOUT);
51
52    ok($s->getCurrentTime()->result); 
53    ok($s->getStateName(SOAP::Data->name(statenum => 1))->result eq 'Alabama'); 
54
55    print "SOAP::Lite server test(s)...\n";
56    $s = SOAP::Lite 
57        -> uri('http://www.soaplite.com/My/Examples')
58        -> proxy('http://services.soaplite.com/examples.cgi', timeout => $SOAP::Test::TIMEOUT);
59  ok($s->getStateNames(1,4,6,13)->result =~ /^Alabama\s+Arkansas\s+Colorado\s+Illinois\s*$/); 
60
61  $r = $s->getStateList([1,2,3,4])->result;
62  ok(ref $r && $r->[0] eq 'Alabama'); 
63
64  $r = $s->getStateStruct(SOAP::Data->type(ordered_hash => [item1 => 1, item2 => 4]))->result;
65  ok(ref $r && $r->{item2} eq 'Arkansas'); 
66
67# Public test server with COM implementation (http://www.zaks.demon.co.uk/com/4s4c/)
68  print "COM server test(s)...\n";
69  $s = SOAP::Lite 
70    -> uri('http://simon.fell.com/calc')
71    -> proxy('http://soap.4s4c.com/ssss4c/soap.asp', timeout => $SOAP::Test::TIMEOUT)
72  ;
73beta
74    $r = $s->doubler(name SOAP::Data nums => [10,20,30,50,100])->result;
75    ok(ref $r && $r->[1] == 40);
76
77    # Real server with ASP implementation (http://www.soap-wrc.com/webservices/)
78    print "ASP server test(s)...\n";
79    $s = SOAP::Lite 
80        -> uri('www.soap-wrc.com')
81        -> proxy('http://www.soap-wrc.com/webservices/soapv11.asp', timeout => $SOAP::Test::TIMEOUT)
82        -> on_fault(sub{ref$_[1]?return$_[1]:return});
83
84    import SOAP::Data 'name'; # no import by default
85
86    $r = $s->addResource(
87        name(Login => 'login'),
88        name(Password => 'password'),
89        name(Caption => 'caption'),
90        name(Description => 'description'),
91        name(URL => 'http://yahoo.com'),
92    );
93    ok(ref $r && $r->faultcode eq 'SOAP-ENV:Client');
94    # Password should be wrong. Put yours if you have it. 
95    # Remember: this is the real server
96
97if (0) { # doesn't seem to be working on 2001/01/31
98    print "DevelopMentor's Perl server test(s)...\n";
99    ok((SOAP::Lite
100        -> uri('urn:soap-perl-test')                
101        -> proxy('http://soapl.develop.com/soap?class=SPTest', timeout => $SOAP::Test::TIMEOUT)
102        -> add(SOAP::Data->name(a => 3), SOAP::Data->name(b => 4))
103        -> result or 0) == 7);beta
104}
105
106# Public server with Microsoft implementation (http://search.microsoft.com/search/MSComSearchService.asmx)
107  print "Microsoft's server test(s)...\n";
108  ok((SOAP::Lite 
109    -> uri('http://tempuri.org/')
110    -> proxy('http://search.microsoft.com/search/MSComSearchService.asmx', timeout => $SOAP::Test::TIMEOUT)
111    -> on_action(sub{join'',@_})
112    -> GetVocabulary(SOAP::Data->name(Query => 'something_very_unusual')->uri('http://tempuri.org/'))
113    -> valueof('//Found') || '') eq 'false');
114
115  $r = SOAP::Lite 
116    -> uri('http://tempuri.org/')
117    -> proxy('http://search.microsoft.com/search/MSComSearchService.asmx', timeout => $SOAP::Test::TIMEOUT)
118    -> on_action(sub{join'',@_})
119    -> GetBestBets(SOAP::Data->name(Query => 'data')->uri('http://tempuri.org/'))
120    -> result;
121  ok(ref $r && $r->{VocabularyLastcache} =~ /T/);
122
123# Public server with 4s4c implementation (http://www.pocketsoap.com/4s4c/)
124  print "4s4c (aka Simon's SOAP Server Services For COM) server test(s)...\n";
125  $s = SOAP::Lite 
126    -> uri('http://www.pocketsoap.com/whois')
127    -> proxy('http://soap.4s4c.com/whois/soap.asp', timeout => $SOAP::Test::TIMEOUT)
128    -> whois(SOAP::Data->name('name' => 'yahoo'));
129  $r = $s->result || '';
130  ok($r =~ /YAHOO/);
131
132# Public server with MS SOAP implementation (http://www.itfinity.net/soap/guid/details.html)
133  print "MS SOAP (on itfinity.net) server test(s)...\n";
134  ok((SOAP::Lite 
135        -> uri('http://www.itfinity.net/soap/guid/guid.xsd')
136        -> proxy('http://www.itfinity.net/soap/guid/default.asp', timeout => $SOAP::Test::TIMEOUT)
137        -> NextGUID
138        -> result or '') =~ /.{8}-.{4}-.{4}-.{4}-.{12}/);
139
140# Public server with Apache implementation (http://www.lemurlabs.com/projects/soap/itime/index.jsp)
141  print "Apache SOAP (on lemurlabs.com) server test(s)...\n";
142  ok((SOAP::Lite 
143        -> uri('urn:lemurlabs-ITimeService')
144        -> proxy('http://www.lemurlabs.com/rpcrouter', timeout => $SOAP::Test::TIMEOUT)
145        -> getInternetTime
146        -> result or '') =~ /\d/);
147
148  ok(@{SOAP::Lite 
149    -> uri('urn:lemurlabs-Fortune')
150    -> proxy('http://www.lemurlabs.com/rpcrouter', timeout => $SOAP::Test::TIMEOUT)
151    -> getDictionaryNameList #getAnyFortune
152    -> result or []} > 1);
153
154  $r = (SOAP::Lite 
155    -> uri('urn:lemurlabs-Fortune')
156    -> proxy('http://www.lemurlabs.com/rpcrouter', timeout => $SOAP::Test::TIMEOUT)
157    -> getFortuneByDictionary('work')
158    -> result) || '';
159
160  ok($r && ref($r = SOAP::Deserializer->deserialize($r)) && ($r = $r->valueof('//fortune') || ''));
161  print $r ? "Your fortune cookie:\n$r\n" : "No fortune cookies for you today\n\n";
162
163if (0) { # seems to be down as of 2001/04/18
164# Public server with Lucin implementation (http://www.lucin.com/lu003/sal.htm)
165  print "Lucin SOAP (lucin.com) server test(s)...\n";
166  $r = (SOAP::Lite
167    -> proxy('http://srv.lucin.net/bin/SOAP002.asp', timeout => $SOAP::Test::TIMEOUT)
168    -> uri('http://schema.soapranch.com/salACC/CAddress.xml')
169    -> Ping(SOAP::Data->new(name => 'ApplicID', type => 'xsd:long', value => 1001))
170    -> result) || '';
171
172  ok($r && $r =~ /^OKO/);
173}
174
175# Public server with SOAP::Lite/ApacheSOAP implementations (http://www.xmethods.net/)
176  print "XMethods (SOAP::Lite/ApacheSOAP) server test(s)...\n";
177  print "All connections are keep-alive\n";
178  $s = SOAP::Lite                             
179    -> uri('urn:xmethods-BNPriceCheck')                
180    -> proxy('http://services.xmethods.net/soap/servlet/rpcrouter', timeout => $SOAP::Test::TIMEOUT);
181
182  my $isbn = '0672319225';
183  $r = ($s->getPrice(SOAP::Data->type(string => $isbn))->result) || 0;
184  print "Price for ISBN$isbn is \$$r\n";
185  ok($r > 20 && $r < 60);
186
187  $s = SOAP::Lite                             
188    -> uri('urn:xmethods-CurrencyExchange')                
189    -> proxy('http://services.xmethods.net/soap', timeout => $SOAP::Test::TIMEOUT);
190
191  $r = ($s->getRate(SOAP::Data->name(country1 => 'England'), 
192                    SOAP::Data->name(country2 => 'Japan'))
193          ->result) || 0;
194  print "Currency rate for England/Japan is $r\n";
195  ok($r > 1);
196
197  $s = SOAP::Lite                             
198    -> uri('urn:xmethods-delayed-quotes')                
199    -> proxy('http://services.xmethods.net/soap', timeout => $SOAP::Test::TIMEOUT);
200
201  $r = ($s->getQuote('MSFT')->result) || 0;
202  print "Quote for MSFT symbol is $r\n";
203  ok($r > 1);
204
205if (0) { # should work, but server wasn't ready as of 2001/04/18
206  $s = SOAP::Lite                             
207    -> uri('urn:xmethods-delayed-quotes')                
208    -> proxy('https://services.xmethods.net/soap', timeout => $SOAP::Test::TIMEOUT);
209
210  $r = ($s->getQuote('MSFT')->result) || 0;
211  print "Quote for MSFT symbol from secure server is $r\n";
212  ok($r > 1);
213}
214
215  ok((SOAP::Lite
216        -> uri('urn:xmethods-DomainChecker')                
217        -> proxy('http://services.xmethods.net/soap', timeout => $SOAP::Test::TIMEOUT)
218        -> checkDomain('yahoo.com')
219        -> result or '') eq 'unavailable');
220
221  ok((SOAP::Lite
222        -> uri('urn:xmethods-CATraffic')                
223        -> proxy('http://services.xmethods.net/soap/servlet/rpcrouter', timeout => $SOAP::Test::TIMEOUT)
224        -> getTraffic(type SOAP::Data string => 101)
225        -> result or '') =~ /reported/);
226
227  ok((SOAP::Lite
228        -> uri('urn:xmethods-Temperature')                
229        -> proxy('http://services.xmethods.net/soap/servlet/rpcrouter', timeout => $SOAP::Test::TIMEOUT)
230        -> getTemp(type SOAP::Data string => 64151)
231        -> result or '') =~ /\./);
232
233if (0) { # Tony brought it down as of 2001/06/11
234  ok((SOAP::Lite
235        -> uri('urn:xmethodsSoapPing')                
236        -> proxy('http://services.xmethods.net/perl/soaplite.cgi', timeout => $SOAP::Test::TIMEOUT)
237        -> pingHost(name SOAP::Data hostname => 'www.yahoo.com')
238        -> result or 0) == 1);
239
240  skip 'xmethods is unavailable', 1;
241  print "BabelFish translator server test(s)...\n";
242  ok((SOAP::Lite                             
243        -> uri('urn:xmethodsBabelFish')                
244        -> proxy('http://services.xmethods.net/perl/soaplite.cgi', timeout => $SOAP::Test::TIMEOUT)
245        -> BabelFish(SOAP::Data->name(translationmode => 'en_it'), 
246                     SOAP::Data->name(sourcedata => 'I want to work'))
247        -> result or '') =~ /^Desidero lavorare$/);
248}
249}
250
251if (0) { # Kafka response has xsi:type="string" response which is invalid
252  print "Kafka (http://www.vbxml.com/soapworkshop/utilities/kafka/) server test(s)...\n";
253  ok((SOAP::Lite
254        -> service('http://www.vbxml.com/soapworkshop/services/id/id.xml')
255        -> GetSecretIdentity('Superman') or '') eq 'Clark Kent');
256}
257