1#!/usr/bin/perl -w
2package Pod::WSDL;
3use Test::More tests => 23;
4BEGIN {use_ok('Pod::WSDL');}
5use lib length $0 > 14 ? substr $0, 0, length($0) - 20 : '.';
6use strict;
7use warnings;
8use XML::XPath;
9
10my $p = new Pod::WSDL(source => 'My::OperationTest',
11	               location => 'http://localhost/My/OperationTest',
12	               pretty => 1,
13	               withDocumentation => 1);
14
15my $xmlOutput = $p->WSDL;
16my $xp = XML::XPath->new(xml => $xmlOutput);
17
18# test general structure
19ok($xp->exists('/wsdl:definitions/wsdl:message[@name = "testGeneralRequest"]'), 'Found message element "testGeneralRequest" in xml output.');
20ok($xp->exists('/wsdl:definitions/wsdl:message[@name = "testGeneralRequest"]/wsdl:part[@name = "in" and @type = "xsd:string"]'), 'Found part element "in" for message "testGeneralRequest" in xml output.');
21
22ok($xp->exists('/wsdl:definitions/wsdl:message[@name = "testGeneralResponse"]'), 'Found message element "testGeneralResponse" in xml output.');
23ok($xp->exists('/wsdl:definitions/wsdl:message[@name = "testGeneralResponse"]/wsdl:part[@name = "testGeneralReturn" and @type = "xsd:string"]'), 'Found part element "testGeneralReturn" for message "testGeneralResponse" in xml output.');
24
25ok($xp->exists('/wsdl:definitions/wsdl:portType[@name = "MyOperationTestHandler"]'), 'Found portType element "MyOperationTestHandler" in xml output.');
26ok($xp->exists('/wsdl:definitions/wsdl:portType[@name = "MyOperationTestHandler"]/wsdl:operation[@name = "testGeneral" and @parameterOrder = "in"]'), 'Found operation element "testGeneral" in portType in xml output.');
27ok($xp->exists('/wsdl:definitions/wsdl:portType[@name = "MyOperationTestHandler"]/wsdl:operation[@name = "testGeneral" and @parameterOrder = "in"]/wsdl:documentation[text() = "bla bla"]'), 'Found documentation for operation element "testGeneral".');
28ok($xp->exists('/wsdl:definitions/wsdl:portType[@name = "MyOperationTestHandler"]/wsdl:operation[@name = "testGeneral" and @parameterOrder = "in"]/wsdl:input[@message = "impl:testGeneralRequest" and @name="testGeneralRequest"]'), 'Found input message for operation element "testGeneral".');
29ok($xp->exists('/wsdl:definitions/wsdl:portType[@name = "MyOperationTestHandler"]/wsdl:operation[@name = "testGeneral" and @parameterOrder = "in"]/wsdl:output[@message = "impl:testGeneralResponse" and @name="testGeneralResponse"]'), 'Found output message for operation element "testGeneral".');
30
31# test parameters: _IN, _OUT, _INOUT
32ok($xp->exists('/wsdl:definitions/wsdl:message[@name = "testInOutRequest"]/wsdl:part[@name = "in" and @type = "xsd:string"]'), 'Found part element "in" in xml output.');
33ok($xp->exists('/wsdl:definitions/wsdl:message[@name = "testInOutRequest"]/wsdl:part[@name = "out" and @type = "xsd:string"]'), 'Found part element "out" in xml output.');
34ok($xp->exists('/wsdl:definitions/wsdl:message[@name = "testInOutRequest"]/wsdl:part[@name = "inout" and @type = "xsd:string"]'), 'Found part element "inout" in xml output.');
35
36# test faults
37ok($xp->exists('/wsdl:definitions/wsdl:message[@name = "MyFoo"]'), 'Found message element "MyFoo" in xml output.');
38ok($xp->exists('/wsdl:definitions/wsdl:message[@name = "MyFoo"]/wsdl:part[@name = "fault" and @type = "tns1:MyFoo"]'), 'Found part element "fault" for message "MyFoo" in xml output.');
39ok($xp->exists('/wsdl:definitions/wsdl:portType[@name = "MyOperationTestHandler"]/wsdl:operation[@name = "testGeneral" and @parameterOrder = "in"]/wsdl:fault[@message = "impl:MyFoo" and @name="MyFoo"]'), 'Found fault message for operation element "testGeneral".');
40
41# test arrays
42ok($xp->exists('/wsdl:definitions/wsdl:message[@name = "testArrayRequest"]/wsdl:part[@name = "in" and @type = "tns1:ArrayOfString"]'), 'Found correct part element "in" for message "testArrayRequest" in xml output.');
43ok($xp->exists('/wsdl:definitions/wsdl:message[@name = "testArrayResponse"]/wsdl:part[@name = "testArrayReturn" and @type = "tns1:ArrayOfString"]'), 'Found correct part element "testArrayReturn" for message "testArrayResponse" in xml output.');
44
45# test empty message
46ok($xp->exists('/wsdl:definitions/wsdl:message[@name = "testOnewayRequest"]'), 'Found message element with name "testOnewayRequest" for message "testOneway" in xml output.');
47
48# test oneway message
49ok($xp->exists('/wsdl:definitions/wsdl:message[@name = "empty"]'), 'Found message element with name "empty" for message "testEmpty" in xml output.');
50ok($xp->exists('/wsdl:definitions/wsdl:portType[@name = "MyOperationTestHandler"]/wsdl:operation[@name = "testOneway" and @parameterOrder = "in"]/wsdl:input[@message = "impl:testOnewayRequest" and @name="testOnewayRequest"]'), 'Found input message for operation element "testOneway".');
51ok(!$xp->exists('/wsdl:definitions/wsdl:portType[@name = "MyOperationTestHandler"]/wsdl:operation[@name = "testOneway" and @parameterOrder = "in"]/wsdl:output'), 'Did not find output message (which is correct) for operation element "testOneway".');
52
53
54# test method without wsdl pod
55ok(!$xp->exists('/wsdl:definitions/wsdl:message[@name = "testWithoutPodRequest"]') && !$xp->exists('/wsdl:definitions/wsdl:message[@name = "testWithoutPodResponse"]'), 'Non pod messages not found xml output.');
56
57print $xmlOutput;