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 ? warn(join "\n", "--- SOAP FAULT ---", $res->faultcode, $res->faultstring, '') 
18             : warn(join "\n", "--- TRANSPORT ERROR ---", $soap->transport->status, '');
19    return new SOAP::SOM;
20  }
21;
22
23my($a, $s, $r, $serialized, $deserialized);
24
25# ------------------------------------------------------
26use SOAP::Test;
27
28$s = SOAP::Lite->uri('http://something/somewhere')->proxy('http://services.xmethods.net/soap/servlet/rpcrouter')->on_fault(sub{});
29eval { $s->transport->timeout($SOAP::Test::TIMEOUT = $SOAP::Test::TIMEOUT) };
30$r = $s->test_connection;
31
32unless (defined $r && defined $r->envelope) {
33  print "1..0 # Skip: ", $s->transport->status, "\n"; 
34  exit;
35}
36# ------------------------------------------------------
37
38plan tests => 12;
39
40{
41# Service description (WSDL) (http://www.xmethods.net/)
42  print "Service description (WSDL) test(s)...\n";
43  $s = SOAP::Lite
44    -> service('http://services.xmethods.net/soap/urn:xmethods-delayed-quotes.wsdl');
45
46  ok($s->getQuote('MSFT') > 1);
47
48  ok(SOAP::Lite
49    -> service('http://services.xmethods.net/soap/urn:xmethods-delayed-quotes.wsdl')
50    -> getQuote('MSFT') > 1);
51
52  # WSDL with <import> element and multiple ports (non-SOAP bindings)
53  ok(SOAP::Lite
54    -> service('http://www.xmethods.net/sd/StockQuoteImport.wsdl')
55    -> getQuote('MSFT') > 1);
56
57  my $schema = SOAP::Schema
58    -> schema('http://services.xmethods.net/soap/urn:xmethods-delayed-quotes.wsdl')
59    -> parse('net.xmethods.services.stockquote.StockQuoteService');
60
61  foreach (keys %{$schema->services}) {
62    eval { $schema->stub($_) } or die;
63  }
64
65  # SOAP::Schema converts
66  # net.xmethods.services.stockquote.StockQuoteService
67  # into
68  # net_xmethods_services_stockquote_StockQuoteService
69
70  print "Service description static stub test(s)...\n";
71  ok(net_xmethods_services_stockquote_StockQuoteService->getQuote('MSFT') > 1);
72
73  ok(defined net_xmethods_services_stockquote_StockQuoteService->self);
74
75  ok(net_xmethods_services_stockquote_StockQuoteService->self->call);
76
77  print "Service description static stub with import test(s)...\n";
78  net_xmethods_services_stockquote_StockQuoteService->import(':all');
79
80  ok(getQuote('MSFT') > 1);
81
82  ok(defined net_xmethods_services_stockquote_StockQuoteService->self);
83
84  ok(net_xmethods_services_stockquote_StockQuoteService->self->call);
85
86  # ok, now we'll test for passing SOAP::Data and SOAP::Headers as a parameters
87
88  my @params;
89  {
90    package TestStockQuoteService; 
91    @TestStockQuoteService::ISA = 'net_xmethods_services_stockquote_StockQuoteService';
92    sub call { shift; @params = @_; new SOAP::SOM }
93  }
94
95  my @testparams = (SOAP::Data->name(param1 => 'MSFT'), 
96                    SOAP::Data->name('param2'),
97                    SOAP::Header->name(header1 => 'value'));
98  TestStockQuoteService->new->getQuote(@testparams);
99
100  ok($params[1]->value->name eq 'param1');
101  ok($params[2]->name eq 'param2');
102  ok(ref $params[3] eq 'SOAP::Header' && $params[3]->name eq 'header1');
103}
104