[r418]: trunk / t / SOAP / Lite / Deserializer.t Maximize Restore History

Download this file

Deserializer.t    123 lines (104 with data), 4.6 kB

  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
use strict;
use warnings;
use Test::More tests => 17; #qw(no_plan);
use Scalar::Util qw(refaddr);
use_ok qw(SOAP::Lite::Deserializer);
# test object creation and calling new as object method
ok my $deserializer = SOAP::Lite::Deserializer->new(), 'instantiate object';
is refaddr $deserializer, refaddr $deserializer->new(), 'return self if new called as object method';
# test is_xml (all variants)
ok $deserializer->is_xml('<Foo></Foo>'), '<Foo></Foo> is_xml';
ok $deserializer->is_xml('Fromme Sch端ler'), 'Fromme Sch端ler is_xml';
ok $deserializer->is_xml('My Header:'), 'My Header: is_xml';
ok ! $deserializer->is_xml('From martin'), 'From martin ! is_xml';
ok ! $deserializer->is_xml('X-Header: Foo'), 'X-Header: Foo ! is_xml';
# call typecast and check whether it returns undef
ok ! defined $deserializer->typecast(), 'typecast is undef';
# call baselocation with all variants of URIs, and without/with
# $deserializer->base();
baselocation: {
my %uri = (
'http://example.org/somewhere/over/the/rainbow' => 'http://example.org/somewhere/over/the/rainbow',
'rainbow' => 'thismessage:/rainbow',
q{} => q{},
);
for my $key ( keys %uri) {
is $deserializer->baselocation($key), $uri{$key}, "$key baselocation";
}
$deserializer->base('foo:');
is $deserializer->baselocation('rainbow'), 'foo:/rainbow', "rainbow baselocation (with base set)";
}
# deserialize messages without errors
ok my $som = $deserializer->deserialize( soap_message() ), 'deserialize SOAP message';
# MIME message
MIME: {
# setup context
my $soap = SOAP::Lite->new();
$deserializer->context($soap);
ok my $som = $deserializer->deserialize( mime_message() ), 'deserialize MIME message';
$som->match('//theSignedForm');
}
# deserialize messages with errors
eval {
my $som = $deserializer->deserialize( unresolved_attr_prefix() );
};
like $@, qr{\AUnresolved \s prefix \s'xsi'}x, 'error on unresolved attribute prefix';
eval {
my $som = $deserializer->deserialize( unresolved_attr_value() );
};
like $@, qr{\A Unresolved \s prefix \s 'foo' \s for \s attribute \s value \s 'foo:value'}x
, 'error on unresolved attribute value prefix';
sub soap_message {
q{<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" >
<SOAP-ENV:Body ><EnqueueMessage xmlns="http://www.example.org/MessageGateway2/"><MMessage>
<MRecipientURI>mailto:test@example.com</MRecipientURI>
<MMessageContent>TestContent for Message</MMessageContent>
</MMessage></EnqueueMessage></SOAP-ENV:Body></SOAP-ENV:Envelope>};
}
sub unresolved_attr_prefix {
q{<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" >
<SOAP-ENV:Body ><EnqueueMessage xmlns="http://www.example.org/MessageGateway2/"><MMessage>
<MRecipientURI xsi:type="foo:value">mailto:test@example.com</MRecipientURI>
</MMessage></EnqueueMessage></SOAP-ENV:Body></SOAP-ENV:Envelope>};
}
sub unresolved_attr_value {
q{<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" >
<SOAP-ENV:Body ><EnqueueMessage xmlns="http://www.example.org/MessageGateway2/"><MMessage>
<MRecipientURI xml:type="foo:value">mailto:test@example.com</MRecipientURI>
</MMessage></EnqueueMessage></SOAP-ENV:Body></SOAP-ENV:Envelope>};
}
sub mime_message {
q{Content-Type: Multipart/Related; boundary=MIME_boundary; type="text/xml"; start="<claim061400a.xml@claiming-it.com>"
SOAPAction: http://schemas.risky-stuff.com/Auto-Claim
Content-Description: This is the optional message description.
--MIME_boundary
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: <claim061400a.xml@claiming-it.com>
<?xml version='1.0' ?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<claim:insurance_claim_auto id="insurance_claim_document_id"
xmlns:claim="http://schemas.risky-stuff.com/Auto-Claim">
<theSignedForm href="cid:claim061401a.tiff@claiming-it.com"/>
<somexml href="cid:claim061403a.somexml@claiming-it.com"/>
<!-- ... more claim details go here... -->
</claim:insurance_claim_auto>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
--MIME_boundary
Content-Type: image/tiff
Content-Transfer-Encoding: base64
Content-ID: <claim061401a.tiff@claiming-it.com>
AAECAyAgIAQFBg==
--MIME_boundary
Content-Type: text/plain
Content-Transfer-Encoding: binary
Content-ID: <claim061403a.somexml@claiming-it.com>
<a><b>c</b></a>
--MIME_boundary--};
}