File: XSD_custom_resolver.t

package info (click to toggle)
libsoap-wsdl-perl 3.004-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,600 kB
  • sloc: perl: 8,433; xml: 1,769; java: 19; makefile: 15
file content (131 lines) | stat: -rw-r--r-- 4,047 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package TestResolver;
use strict; use warnings;
use Class::Std::Fast;

use base qw(SOAP::WSDL::Generator::PrefixResolver);

sub resolve_prefix {
    my ($self, $type, $namespace, $node) = @_;
    my $name = defined($node) ? $node->get_name() : ();
    if (($type eq 'interface') && $name =~m{\.}x) {
        return "MySpacialPrufax::";
    }
    if ($type eq 'type') {
        return 'MySpatialTaipeeProfix::'
            if $namespace ne 'http://www.w3.org/2001/XMLSchema'
    }
    return $self->SUPER::resolve_prefix($type, $namespace, $node);
}


package main;
use Test::More tests => 14;
use File::Basename qw(dirname);
use File::Spec;
use File::Path;

my $path = File::Spec->rel2abs( dirname __FILE__ );

use_ok qw(SOAP::WSDL::Generator::Template::XSD);

use SOAP::WSDL::Expat::WSDLParser;

my $parser = SOAP::WSDL::Expat::WSDLParser->new();

my $definitions = $parser->parse_file(
     "$path/../../../acceptance/wsdl/generator_test_dot_names.wsdl"
    #"$path/../../../acceptance/wsdl/elementAtomicComplexType.xml"
);

my $generator = SOAP::WSDL::Generator::Template::XSD->new({
    definitions => $definitions,
    type_prefix => 'Foo',
    element_prefix => 'Foo',
    typemap_prefix => 'Foo',
    OUTPUT_PATH => "$path/testlib",
    prefix_resolver_class => 'TestResolver',
    silent => 1,
});

my $code = "";
$generator->set_output(\$code);
$generator->generate_typelib();
{
    eval $code;
    ok !$@;
    print $@ if $@;
}
# print $code;


$generator->set_type_prefix('MySpatialTaipeeProfix');
$generator->set_element_prefix('MyElements');
$generator->set_typemap_prefix('MyTypemaps');
$generator->set_interface_prefix('MyInterfaces');

$generator->set_output(undef);
$generator->generate();
#$generator->generate_typelib();
#$generator->generate_typemap();

if (eval { require Test::Warn; }) {
   Test::Warn::warning_like( sub { $generator->generate_interface() },
    qr{\A Multiple \s parts \s detected \s in \s message \s testMultiPartWarning}xms);
}
else {
    $generator->generate_interface();
    SKIP: { skip 'Cannot test warnings without Test::Warn', 1 };
}

$generator->generate_server();

eval "use lib '$path/testlib'";

use_ok qw(MySpacialPrufax::My::SOAP::testService::testPort);
use_ok qw(MyServer::My::SOAP::testService::testPort);
use_ok qw(MySpatialTaipeeProfix::testComplexTypeRestriction);
use_ok qw(MySpatialTaipeeProfix::testComplexTypeAll);
SKIP: {
    eval { require Test::Pod::Content; }
        or skip 'Cannot test pod content without Test::Pod::Content', 6;
    Test::Pod::Content::pod_section_like(
        'MySpacialPrufax::My::SOAP::testService::testPort',
        'NAME',
        qr{^MySpacialPrufax::My::SOAP::testService::testPort \s - \s}xms,
        'Pod NAME section');
    Test::Pod::Content::pod_section_like(
        'MySpacialPrufax::My::SOAP::testService::testPort',
        'SYNOPSIS',
        qr{use \s MySpacialPrufax::My::SOAP::testService::testPort}xms,
        'Pod SYNOPSIS section');
    Test::Pod::Content::pod_section_like(
        'MySpacialPrufax::My::SOAP::testService::testPort',
        'SYNOPSIS',
        qr{\s MySpacialPrufax::My::SOAP::testService::testPort->new\(}xms,
        'Pod SYNOPSIS section');

    Test::Pod::Content::pod_section_like(
        'MyServer::My::SOAP::testService::testPort',
        'NAME',
        qr{^MyServer::My::SOAP::testService::testPort \s - \s}xms,
        'Pod NAME section');
    Test::Pod::Content::pod_section_like(
        'MyServer::My::SOAP::testService::testPort',
        'SYNOPSIS',
        qr{use \s MyServer::My::SOAP::testService::testPort}xms,
        'Pod SYNOPSIS section');
    Test::Pod::Content::pod_section_like(
        'MyServer::My::SOAP::testService::testPort',
        'SYNOPSIS',
        qr{\s MyServer::My::SOAP::testService::testPort->new\(}xms,
        'Pod SYNOPSIS section');
}

my $obj = MySpatialTaipeeProfix::testComplexTypeAll->new({
	Test_1 => 'Test1',
	Test_2 => 'Test2',
});

like $obj->serialize(), qr{<Test-1>Test1</Test-1>}xm, 'serialize altered name with original name';

rmtree "$path/testlib";