#!/usr/bin/perl -w
use strict;
use warnings;
use Test::More tests => 23;
use Storable;
use lib '../lib';
eval {
require Test::XML;
import Test::XML;
};
use_ok(qw/SOAP::WSDL::Expat::WSDLParser/);
my $filter;
my $parser = SOAP::WSDL::Expat::WSDLParser->new();
$parser->parse_string( xml() );
my $wsdl;
ok( $wsdl = $parser->get_data() , "get object tree");
ok Storable::thaw(Storable::freeze($wsdl));
my $types = $wsdl->first_types();
is $types->get_parent(), $wsdl , 'types parent';
my $serializer_options = {
readable => 1,
autotype => 1,
namespace => { 'tns' => 'urn:myNamespace',
'xsd' => "http://www.w3.org/2001/XMLSchema" },
typelib => $wsdl->first_types(),
indent => "\t",
};
my $xml;
my $type = $types->find_type( 'urn:myNamespace', 'testSimpleType1' );
ok($xml = $type->serialize( 'test', 1 , $serializer_options ),
"serialize simple Type"
);
# print $xml;
SKIP: {
skip_without_test_xml();
is_xml( $xml, '1',
"content compare" );
};
$type = $types->find_type( 'urn:myNamespace', 'testSimpleList' );
ok($xml = $type->serialize( 'testList', [ 1, 2, 3 ] , $serializer_options ),
"serialize simple list type"
);
SKIP: {
skip_without_test_xml();
is_xml( $xml, '1 2 3',
"content compare" );
};
$type = $types->find_element( 'urn:myNamespace', 'TestElement' );
ok($xml = $type->serialize( undef, 1 , $serializer_options ),
"serialize simple element");
SKIP: {
skip_without_test_xml();
is_xml( $xml, '1',
"content compare" );
};
ok( $xml = $types->find_type( 'urn:myNamespace', 'length3')->serialize(
'TestComplex', { size => -13, unit => 'BLA' } ,
$serializer_options
),
"serialize complex type");
SKIP: {
skip_without_test_xml();
is_xml( $xml, q{
-13
BLA
},
"content compare" );
};
ok($xml = $types->find_element( 'urn:myNamespace', 'TestElementComplexType')
->serialize(
undef, { size => -13, unit => 'BLA' } , $serializer_options ),
"serialize element with complex type"
);
SKIP: {
skip_without_test_xml();
is_xml( $xml, q{
-13
BLA
},
"content compare" );
};
ok($xml = $types->find_type( 'urn:myNamespace', 'complex')->serialize(
'complexComplex',
{ 'length' => { size => -13, unit => 'BLA' }, 'int' => 1 },
$serializer_options ),
"serialize complex type with complex content"
);
SKIP: {
skip_without_test_xml();
is_xml( $xml, q{
-13
BLA
1
},
"content compare" );
}
ok($xml = $wsdl->find_message('urn:myNamespace', 'testRequest')
->get_part()->[0]->serialize(
undef,
{ test => { length => { size => -13, unit => 'BLA' } , int => 3 } },
$serializer_options ),
"serialize part"
);
SKIP: {
skip_without_test_xml();
is_xml( $xml, q{
-13
BLA
3
},
"content compare")
};
my $opt = {
typelib => $types,
readable => 1,
autotype => 0,
namespace => { 'urn:myNamespace' => 'tns',
'http://www.w3.org/2001/XMLSchema' => 'xsd',
'http://schemas.xmlsoap.org/wsdl/' => 'wsdl',
},
indent => "",
wsdl => $wsdl,
};
# ok $wsdl->explain($opt) =~ m/#optional/m;
eval { $wsdl->expand('hallo:welt')};
like $@, qr{unbound}, 'Die on attempt to resolve unbound prefix';
my $complex = $types->find_type( 'urn:myNamespace', 'complex');
ok $complex->find_element('', 'length'), 'Find unqualified element in complexType';
ok ! $complex->find_element('urn:myNamespace', 'FOO'), 'Find element in complexType';
eval { $complex->foo() };
like $@, qr{ foo }xms;
eval { SOAP::WSDL::ComplexType->foo() };
like $@, qr{ foo }xms;
sub skip_without_test_xml {
skip("Test::XML not available", 1) if (not $Test::XML::VERSION);
}
sub xml
{
return q{
SimpleType Test
SimpleType Union test
Test-Methode
Test-Methode
Test-Methode
Test-Methode
};
}