1#!/usr/bin/perl -w 2package Pod::WSDL; 3use Test::More tests => 33; 4BEGIN {use_ok('Pod::WSDL');} 5use lib length $0 > 10 ? substr $0, 0, length($0) - 16 : '.'; 6use strict; 7use warnings; 8use XML::XPath; 9 10eval { 11 new Pod::WSDL(source => 'bla'); 12}; 13 14ok($@ =~ /I need a location/, 'new dies, if it does not get a location'); 15 16eval { 17 new Pod::WSDL(location => 'bla'); 18}; 19 20ok($@ =~ /I need a file or module name or a filehandle, died/, 'new dies, if it does not get a source'); 21 22my $p = new Pod::WSDL(source => 'My::Server', 23 location => 'http://localhost/My/Server', 24 pretty => 1, 25 withDocumentation => 1); 26 27ok($p->writer->{_pretty}, 'Received pretty argument correctly'); 28ok($p->writer->{_withDocumentation}, 'Received withDocumentation argument correctly'); 29ok($p->location eq 'http://localhost/My/Server', 'Received location argument correctly'); 30ok($p->{_source} eq 'My::Server', 'Received source argument correctly'); 31ok($p->{_baseName} eq 'MyServer', 'Generated base name argument correctly'); 32 33$p->location('http://localhost/My/Other/Server'); 34ok($p->location eq 'http://localhost/My/Other/Server', 'Setting location works'); 35 36ok($p->namespaces->{'xmlns:impl'} eq 'http://localhost/My/Server', 'Generated xmlns:impl namespace correctly'); 37ok($p->namespaces->{'xmlns:wsdlsoap'} eq 'http://schemas.xmlsoap.org/wsdl/soap/', 'Generated xmlns:soap namespace correctly'); 38ok($p->namespaces->{'xmlns:wsdl'} eq 'http://schemas.xmlsoap.org/wsdl/', 'Generated xmlns:wsdl namespace correctly'); 39ok($p->namespaces->{'xmlns:soapenc'} eq 'http://schemas.xmlsoap.org/soap/encoding/', 'Generated xmlns:soapenc namespace correctly'); 40ok($p->namespaces->{'xmlns:xsd'} eq 'http://www.w3.org/2001/XMLSchema', 'Generated xmlns:xsd namespace correctly'); 41ok($p->namespaces->{'xmlns:tns1'} eq 'http://localhost/My/Server', 'Generated xmlns:tns1 namespace correctly'); 42 43ok(ref $p->writer->{_outStr} eq 'XML::Writer::_String', 'Initialized outStr for writer correctly.'); 44ok(ref $p->writer->{_writer} eq 'XML::Writer', 'Found an XML::Writer for output'); 45ok(ref $p->generateNS eq 'CODE', 'Initialized generateNS correctly'); 46ok($p->writer->{_indent} == 1, 'Initialized indentation correctly'); 47ok($p->writer->{_lastTag} eq '', 'Initialized lastTag correctly'); 48 49my $loc = $p->location; 50ok($p->WSDL =~ m#<!-- WSDL for $loc created by Pod::WSDL version: $Pod::WSDL::VERSION on .*? -->#, 'Generated comment correctly'); 51 52# arguments of method WSDL() 53$p = new Pod::WSDL(source => 'My::OperationTest', 54 location => 'http://localhost/My/OperationTest', 55 pretty => 1, 56 withDocumentation => 1); 57my $xp = XML::XPath->new(xml => $p->WSDL); 58ok($xp->exists('/wsdl:definitions/wsdl:types/schema/complexType[@name="MyFoo"]/annotation/documentation'), 'Found documentation in schema part (complexType).'); 59ok($xp->exists('/wsdl:definitions/wsdl:types/schema/complexType[@name="MyFoo"]/sequence/element[@name="_bar"]/annotation/documentation'), 'Found documentation in schema part (element).'); 60ok($xp->exists('/wsdl:definitions/wsdl:portType[@name="MyOperationTestHandler"]/wsdl:operation[@name="testGeneral"]/wsdl:documentation'), 'Found documentation in operation part.'); 61 62#print $p->WSDL; 63 64$xp = XML::XPath->new(xml => $p->WSDL(withDocumentation => 0)); 65ok(!$xp->exists('/wsdl:definitions/wsdl:types/schema/complexType[@name="MyFoo"]/annotation/documentation'), 'Switched off documentation -> did not find documentation in schema part (complexType).'); 66ok(!$xp->exists('/wsdl:definitions/wsdl:types/schema/complexType[@name="MyFoo"]/sequence/element[@name="_bar"]/annotation/documentation'), 'Switched off documentation -> did not find documentation in schema part (element).'); 67ok(!$xp->exists('/wsdl:definitions/wsdl:portType[@name="MyOperationTestHandler"]/wsdl:operation[@name="testGeneral"]/wsdl:documentation'), 'Switched off documentation -> did not find documentation in operation part.'); 68 69$xp = XML::XPath->new(xml => $p->WSDL(withDocumentation => 1)); 70ok($xp->exists('/wsdl:definitions/wsdl:types/schema/complexType[@name="MyFoo"]/annotation/documentation'), 'Found documentation in schema part (complexType).'); 71ok($xp->exists('/wsdl:definitions/wsdl:types/schema/complexType[@name="MyFoo"]/sequence/element[@name="_bar"]/annotation/documentation'), 'Found documentation in schema part (element).'); 72ok($xp->exists('/wsdl:definitions/wsdl:portType[@name="MyOperationTestHandler"]/wsdl:operation[@name="testGeneral"]/wsdl:documentation'), 'Found documentation in operation part.'); 73 74$p = new Pod::WSDL(source => 'My::Server', 75 location => 'http://localhost/My/Server', 76 pretty => 1); 77 78my $outputtestFile = $0; 79$outputtestFile =~ s![^/]+$!outputtest001.xml!; 80 81my $outputtest; 82 83{ 84 $/ = undef; 85 open TEST, "$outputtestFile" or die "Could not open $outputtestFile"; 86 $outputtest = <TEST>; 87 close TEST; 88} 89 90 91my $tmp = $p->WSDL; 92$tmp =~ s/<!-- WSDL.*?-->\n//; 93ok($outputtest eq $tmp, "Pretty works."); 94 95$outputtestFile = $0; 96$outputtestFile =~ s![^/]+$!outputtest002.xml!; 97 98my $outputtest2; 99 100{ 101 $/ = undef; 102 open TEST, "$outputtestFile" or die "Could not open $outputtestFile"; 103 $outputtest2 = <TEST>; 104 close TEST; 105} 106 107 108$tmp = $p->WSDL(pretty => 0); 109$tmp =~ s/<!-- WSDL.*?-->\n//; 110#print "--->$tmp<---\n"; 111ok($outputtest2 eq $tmp, "Switch pretty off works."); 112 113$tmp = $p->WSDL(pretty => 1); 114$tmp =~ s/<!-- WSDL.*?-->\n//; 115ok($outputtest eq $tmp, "Switch pretty on works."); 116