1#!/bin/env perl 2 3BEGIN { 4 unless ( grep /blib/, @INC ) { 5 chdir 't' if -d 't'; 6 unshift @INC, '../lib' if -d '../lib'; 7 } 8} 9 10use strict; 11use Test; 12 13BEGIN { 14 use SOAP::Lite; 15 eval { SOAP::Packager::MIME->new->initialize_parser; 1 }; 16 if ($@) { 17 $@ =~ s/ at .+//; 18 print "1..0 # Skip: $@"; 19 exit; 20 } 21} 22 23BEGIN { plan tests => 18 } 24 25my ( $a, $soap, $d, $s, $r, $serialized, $deserialized ); 26 27{ # check attachment deserialization 28 $soap = SOAP::Lite->new(); 29 $soap->init_context(); 30 31 ############################################################################## 32 print "Attachment deserialization (Content-ID) test(s)...\n"; 33 $a = $soap->deserializer->deserialize(<<'EOX'); 34Content-Type: Multipart/Related; boundary=MIME_boundary; type="text/xml"; start="<claim061400a.xml@claiming-it.com>" 35SOAPAction: http://schemas.risky-stuff.com/Auto-Claim 36Content-Description: This is the optional message description. 37 38--MIME_boundary 39Content-Type: text/xml; charset=UTF-8 40Content-Transfer-Encoding: 8bit 41Content-ID: <claim061400a.xml@claiming-it.com> 42 43<?xml version='1.0' ?> 44<soap:Envelope 45 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 46 <soap:Body> 47 <claim:insurance_claim_auto 48 id="insurance_claim_document_id" 49 xmlns:claim="http://schemas.risky-stuff.com/Auto-Claim"> 50 <theSignedForm href="cid:claim061400a.tiff@claiming-it.com" /> 51 <theCrashPhoto href="cid:claim061400a.jpeg@claiming-it.com" /> 52 <somexml href="cid:claim061400a.somexml@claiming-it.com" /> 53 <realxml href="cid:claim061400a.realxml@claiming-it.com" /> 54 <!-- ... more claim details go here... --> 55 </claim:insurance_claim_auto> 56 </soap:Body> 57</soap:Envelope> 58 59--MIME_boundary 60Content-Type: image/tiff 61Content-Transfer-Encoding: base64 62Content-ID: <claim061400a.tiff@claiming-it.com> 63 64AAECAyAgIAQFBg== 65--MIME_boundary 66Content-Type: image/jpeg 67Content-Transfer-Encoding: binary 68Content-ID: <claim061400a.jpeg@claiming-it.com> 69 70...Raw JPEG image.. 71--MIME_boundary 72Content-Type: text/plain 73Content-Transfer-Encoding: binary 74Content-ID: <claim061400a.somexml@claiming-it.com> 75 76<a><b>c</b></a> 77--MIME_boundary 78Content-Type: text/xml 79Content-Transfer-Encoding: binary 80Content-ID: <claim061400a.realxml@claiming-it.com> 81 82<a><b>c</b></a> 83--MIME_boundary-- 84 85EOX 86 87 ok( ref $a ); 88 ok( ref $a 89 && ref $a->valueof('//insurance_claim_auto') 90 && $a->valueof('//insurance_claim_auto')->{theCrashPhoto} =~ /JPEG/ ); 91 ok( ref $a && $a->valueof('//theCrashPhoto') =~ /Raw JPEG image/ ); 92 ok( ref $a && $a->valueof('//theSignedForm') eq "\0\1\2\3 \4\5\6" ); 93 ok( ref $a && $a->valueof('//somexml') =~ m!<a><b>c</b></a>! ); 94 ok( ref $a && $a->valueof('//realxml')->{b} eq 'c' ); 95 96 ############################################################################## 97 print 98"Attachment deserialization (Content-ID and Content-Location) test(s)...\n"; 99 $a = $soap->deserializer->deserialize(<<'EOX'); 100MIME-Version: 1.0 101Content-Type: Multipart/Related; boundary=MIME_boundary; type="text/xml"; start="<http://claiming-it.com/claim061400a.xml>" 102Content-Description: This is the optional message description. 103 104--MIME_boundary 105Content-Type: text/xml; charset=UTF-8 106Content-Transfer-Encoding: 8bit 107Content-ID: <http://claiming-it.com/claim061400a.xml> 108Content-Location: http://claiming-it.com/claim061400a.xml 109 110<?xml version='1.0' ?> 111<soap:Envelope 112 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 113 <soap:Body> 114 <claim:insurance_claim_auto 115 id="insurance_claim_document_id" 116 xmlns:claim="http://schemas.risky-stuff.com/Auto-Claim"> 117 <theSignedForm href="http://claiming-it.com/claim061400a.tiff" /> 118 </claim:insurance_claim_auto> 119 </soap:Body> 120</soap:Envelope> 121 122--MIME_boundary 123Content-Type: image/tiff 124Content-Transfer-Encoding: binary 125Content-ID: <http://claiming-it.com/claim061400a.tiff> 126Content-Location: http://claiming-it.com/claim061400a.tiff 127 128...binary TIFF image... 129--MIME_boundary-- 130 131EOX 132 133 ok( ref $a ); 134 ok( ref $a 135 && ref $a->valueof('//insurance_claim_auto') 136 && $a->valueof('//insurance_claim_auto')->{theSignedForm} =~ /TIFF/ ); 137 ok( ref $a && $a->valueof('//theSignedForm') =~ /binary TIFF image/ ); 138 139 ############################################################################## 140 print "Attachment deserialization (relative Content-Location) test(s)...\n"; 141 142# TODO - this unit test breaks - it does not seem to be picking up a base location 143# from outer Content-Location 144 eval { 145 $a = $soap->deserializer->deserialize(<<'EOX'); }; 146MIME-Version: 1.0 147Content-Type: Multipart/Related; boundary=MIME_boundary; type="text/xml"; start="<http://claiming-it.com/claim061400a.xml>" 148Content-Description: This is the optional message description. 149Content-Location: http://claiming-it.com/ 150 151--MIME_boundary 152Content-Type: text/xml; charset=UTF-8 153Content-Transfer-Encoding: 8bit 154Content-ID: <http://claiming-it.com/claim061400a.xml> 155Content-Location: claim061400a.xml 156 157<?xml version='1.0' ?> 158<soap:Envelope 159 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 160 <soap:Body> 161 <claim:insurance_claim_auto 162 id="insurance_claim_document_id" 163 xmlns:claim="http://schemas.risky-stuff.com/Auto-Claim"> 164 <theSignedForm href="cid:claim061400a.tiff" /> 165 </claim:insurance_claim_auto> 166 </soap:Body> 167</soap:Envelope> 168 169--MIME_boundary 170Content-Type: image/tiff 171Content-Transfer-Encoding: binary 172Content-Id: <claim061400a.tiff> 173Content-Location: claim061400a.tiff 174 175...binary TIFF image... 176--MIME_boundary-- 177 178EOX 179 ok( ref $a ); 180 ok( ref $a 181 && ref $a->valueof('//insurance_claim_auto') 182 && $a->valueof('//insurance_claim_auto')->{theSignedForm} =~ /TIFF/ ); 183 ok( ref $a && $a->valueof('//theSignedForm') =~ /binary TIFF image/ ); 184 185 ############################################################################## 186 print 187 "Attachment deserialization (no default Content-Location) test(s)...\n"; 188 $a = $soap->deserializer->deserialize(<<'EOX'); 189MIME-Version: 1.0 190Content-Type: Multipart/Related; boundary=MIME_boundary; type="text/xml"; start="<b6f4ccrt@15.4.9.92/s445>" 191Content-Description: This is the optional message description. 192 193--MIME_boundary 194Content-Type: text/xml; charset=UTF-8 195Content-Transfer-Encoding: 8bit 196Content-ID: <b6f4ccrt@15.4.9.92/s445> 197Content-Location: claim061400a.xml 198 199<?xml version='1.0' ?> 200<soap:Envelope 201 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 202 <soap:Body> 203 <claim:insurance_claim_auto 204 id="insurance_claim_document_id" 205 xmlns:claim="http://schemas.risky-stuff.com/Auto-Claim"> 206 <theSignedForm href="cid:a34ccrt@15.4.9.92/s445" /> 207 </claim:insurance_claim_auto> 208 </soap:Body> 209</soap:Envelope> 210 211--MIME_boundary 212Content-Type: image/tiff 213Content-Transfer-Encoding: binary 214Content-ID: <a34ccrt@15.4.9.92/s445> 215Content-Location: the_signed_form.tiff 216 217...binary TIFF image... 218--MIME_boundary- 219 220EOX 221 222 # <theSignedForm href="cid:the_signed_form.tiff"/> 223 224 ok( ref $a ); 225 ok( ref $a 226 && ref $a->valueof('//insurance_claim_auto') 227 && $a->valueof('//insurance_claim_auto')->{theSignedForm} =~ /TIFF/ ); 228 ok( ref $a && $a->valueof('//theSignedForm') =~ /binary TIFF image/ ); 229 230 # check attachment of composite element 231 $soap = SOAP::Lite->new(); 232 $soap->init_context(); 233 234 ############################################################################## 235 print "Attachment deserialization (Nested Attachment) test(s)...\n"; 236 $a = $soap->deserializer->deserialize(<<'EOX'); 237Content-Type: Multipart/Related; boundary=MIME_boundary; type="text/xml"; start="<claimstart.xml@claiming-it.com>" 238SOAPAction: http://schemas.risky-stuff.com/Auto-Claim 239Content-Description: This is the optional message description. 240 241--MIME_boundary 242Content-Type: text/xml; charset=UTF-8 243Content-Transfer-Encoding: 8bit 244Content-ID: <claimstart.xml@claiming-it.com> 245 246<?xml version='1.0' ?> 247<soap:Envelope 248 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 249 <soap:Body> 250 <claim:insurance_claim_auto 251 id="insurance_claim_document_id" 252 xmlns:claim="http://schemas.risky-stuff.com/Auto-Claim"> 253 <email href="cid:email.eml@claiming-it.com" /> 254 </claim:insurance_claim_auto> 255 </soap:Body> 256</soap:Envelope> 257 258--MIME_boundary 259Content-Type: message/rfc822 260Content-Transfer-Encoding: binary 261Content-ID: <email.eml@claiming-it.com> 262 263MIME-Version: 1.0 264X-Mailer: MIME::Lite 3.01 (F2.74; T1.24; A1.74; B3.07; Q3.07) 265Date: Thu, 30 Apr 2009 15:59:49 -0400 266To: foo@bar.com 267Subject: multipart message 268Content-Transfer-Encoding: binary 269Content-Type: multipart/related; boundary="_----------=_1241121589160890" 270 271This is a multi-part message in MIME format. 272 273--_----------=_1241121589160890 274Content-Disposition: inline 275Content-Length: 36 276Content-Transfer-Encoding: binary 277Content-Type: text/html 278 279<body>Here's <i>my</i> text</body> 280--_----------=_1241121589160890 281Content-Disposition: inline 282Content-Length: 16 283Content-Transfer-Encoding: binary 284Content-Type: text/plain 285 286 Here's my text 287--_----------=_1241121589160890-- 288 289--MIME_boundary-- 290 291EOX 292 293 ok( ref $a ); 294 ok( ref $a 295 && ref $a->valueof('//insurance_claim_auto') 296 && $a->valueof('//insurance_claim_auto')->{email} =~ 297 m{my(</i>)? text} ); 298 ok( ref $a && $a->valueof('//email') =~ m{my(</i>)? text} ); 299} 300