@@ -197,6 +197,78 @@ def new_operation(operation_name, wsdl, globals)
197
197
end
198
198
end
199
199
200
+ describe "attachments" do
201
+ context "soap_version 1" do
202
+ it "sends requests with content-type text/xml" do
203
+ globals . endpoint @server . url ( :multipart )
204
+ operation = new_operation ( :example , no_wsdl , globals )
205
+ req = operation . request do
206
+ attachments [
207
+ { filename : 'x1.xml' , content : '<xml>abc</xml>' } ,
208
+ { filename : 'x2.xml' , content : '<xml>cde</xml>' } ,
209
+ ]
210
+ end
211
+ expect ( req . headers [ "Content-Type" ] ) . to start_with "multipart/related; type=\" text/xml\" ; "
212
+ end
213
+ end
214
+ context "soap_version 2" do
215
+ it "sends requests with content-type application/soap+xml" do
216
+ globals . endpoint @server . url ( :multipart )
217
+ globals . soap_version 2
218
+ operation = new_operation ( :example , no_wsdl , globals )
219
+ req = operation . request do
220
+ attachments [
221
+ { filename : 'x1.xml' , content : '<xml>abc</xml>' } ,
222
+ { filename : 'x2.xml' , content : '<xml>cde</xml>' } ,
223
+ ]
224
+ end
225
+ expect ( req . headers [ "Content-Type" ] ) . to start_with "multipart/related; type=\" application/soap+xml\" ; "
226
+ end
227
+ end
228
+ context "MTOM" do
229
+ it "sends request with content-type header application/xop+xml" do
230
+ globals . endpoint @server . url ( :multipart )
231
+ operation = new_operation ( :example , no_wsdl , globals )
232
+ req = operation . request do
233
+ mtom true
234
+ attachments [
235
+ { filename : 'x1.xml' , content : '<xml>abc</xml>' } ,
236
+ { filename : 'x2.xml' , content : '<xml>cde</xml>' } ,
237
+ ]
238
+ end
239
+ expect ( req . headers [ "Content-Type" ] ) . to start_with "multipart/related; type=\" application/xop+xml\" ; start-info=\" text/xml\" ; start=\" <soap-request-body@soap>\" ; boundary=\" --==_mimepart_"
240
+ end
241
+
242
+ it "sends attachments with Content-Transfer-Encoding: binary" do
243
+ globals . endpoint @server . url ( :multipart )
244
+ operation = new_operation ( :example , no_wsdl , globals )
245
+ req = operation . request do
246
+ mtom true
247
+ attachments [
248
+ { filename : 'x1.xml' , content : '<xml>abc</xml>' } ,
249
+ { filename : 'x2.xml' , content : '<xml>cde</xml>' } ,
250
+ ]
251
+ end
252
+ expect ( req . body . to_s ) . to include ( "filename=x1.xml\r \n Content-Transfer-Encoding: binary" )
253
+ end
254
+
255
+ it "successfully makes request" do
256
+ globals . endpoint @server . url ( :multipart )
257
+ operation = new_operation ( :example , no_wsdl , globals )
258
+ response = operation . call do
259
+ mtom true
260
+ attachments [
261
+ { filename : 'x1.xml' , content : '<xml>abc</xml>' } ,
262
+ { filename : 'x2.xml' , content : '<xml>cde</xml>' } ,
263
+ ]
264
+ end
265
+
266
+ expect ( response . multipart? ) . to be true
267
+ expect ( response . attachments . first . content_id ) . to include ( 'attachment1' )
268
+ end
269
+ end
270
+ end
271
+
200
272
def inspect_request ( response )
201
273
hash = JSON . parse ( response . http . body )
202
274
OpenStruct . new ( hash )
0 commit comments