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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
BEGIN {
eval { require MIME::Parser; };
plan(skip_all => "MIME::Parser not installed") if $@;
}
my ($mp, $env, $part, @part_data);
use SOAP::Packager;
$mp = SOAP::Packager::MIME->new;
ok(ref $mp);
# check attachment deserialization
print "Attachment deserialization (Content-ID) test(s)...\n";
$env = $mp->unpackage(<<'EOX');
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:claim061400a.tiff@claiming-it.com"/>
<theCrashPhoto href="cid:claim061400a.jpeg@claiming-it.com"/>
<somexml href="cid:claim061400a.somexml@claiming-it.com"/>
<realxml href="cid:claim061400a.realxml@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: image/jpeg
Content-Transfer-Encoding: binary
Content-ID: <claim061402a.jpeg@claiming-it.com>
...Raw JPEG image..
--MIME_boundary
Content-Type: text/plain
Content-Transfer-Encoding: binary
Content-ID: <claim061403a.somexml@claiming-it.com>
<a><b>c</b></a>
--MIME_boundary
Content-Type: text/xml
Content-Transfer-Encoding: binary
Content-ID: <claim061404a.realxml@claiming-it.com>
<a><b>c</b></a>
--MIME_boundary--
EOX
# test to see how how many parts were found:
ok(@{$mp->parts} == 4);
ok(UNIVERSAL::isa(ref($mp->parts->[0]) => "MIME::Entity"));
# Tests to see if data extraction works - TIFF not checked
#@part_data = $mp->find_part( id => '<claim061402a.jpeg@claiming-it.com>' );
#ok($part_data[0] eq '...Raw JPEG image..');
#@part_data = $mp->find_part( id => '<claim061403a.somexml@claiming-it.com>' );
#ok($part_data[0] eq '<a><b>c</b></a>');
#@part_data = $mp->find_part( id => '<claim061404a.realxml@claiming-it.com>' );
#ok($part_data[0] eq '<a><b>c</b></a>');
# Test: no start parameter specified
# Content-ID: <claim061400a.xml@claiming-it.com>
# Content-Type: text/xml; charset=UTF-8
$env = $mp->unpackage(<<'EOX');
Content-Type: Multipart/Related; boundary=MIME_boundary; type="text/xml"
SOAPAction: http://schemas.risky-stuff.com/Auto-Claim
Content-Description: This is the optional message description.
--MIME_boundary
Content-Transfer-Encoding: 8bit
<?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:claim061400a.tiff@claiming-it.com"/>
<theCrashPhoto href="cid:claim061400a.jpeg@claiming-it.com"/>
<somexml href="cid:claim061400a.somexml@claiming-it.com"/>
<realxml href="cid:claim061400a.realxml@claiming-it.com"/>
<!-- ... more claim details go here... -->
</claim:insurance_claim_auto>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
--MIME_boundary
Content-Type: text/plain
Content-Transfer-Encoding: binary
Content-ID: <claim061403a.somexml@claiming-it.com>
<a><b>c</b></a>
--MIME_boundary--
EOX
# test to see how how many parts were found:
ok(@{$mp->parts} == 1);
# Tests to see if data extraction worked
#@part_data = $mp->find_part( id => '<claim061403a.somexml@claiming-it.com>' );
#ok($part_data[0] eq '<a><b>c</b></a>');
# test to see if start parameter works if it doesn't point to root
$env = $mp->unpackage(<<'EOX');
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/plain
Content-Transfer-Encoding: binary
Content-ID: <claim061403a.somexml@claiming-it.com>
<a><b>c</b></a>
--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:claim061400a.tiff@claiming-it.com"/>
<theCrashPhoto href="cid:claim061400a.jpeg@claiming-it.com"/>
<somexml href="cid:claim061400a.somexml@claiming-it.com"/>
<realxml href="cid:claim061400a.realxml@claiming-it.com"/>
<!-- ... more claim details go here... -->
</claim:insurance_claim_auto>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
--MIME_boundary--
EOX
# test to see how how many parts were found:
ok(@{$mp->parts} == 1);
# Tests to see if data extraction worked
#@part_data = $mp->find_part( id => '<claim061403a.somexml@claiming-it.com>' );
#ok($part_data[0] eq '<a><b>c</b></a>');
done_testing();
1;
|