xmlconv 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. data/.gemtest +0 -0
  2. data/History.txt +6 -0
  3. data/LICENSE +339 -0
  4. data/README.txt +29 -0
  5. data/Rakefile +37 -0
  6. data/bin/admin +68 -0
  7. data/bin/xmlconvd +38 -0
  8. data/data/grammar/i2.grammar +73 -0
  9. data/lib/xmlconv/config.rb +61 -0
  10. data/lib/xmlconv/custom/lookandfeel.rb +50 -0
  11. data/lib/xmlconv/i2/address.rb +35 -0
  12. data/lib/xmlconv/i2/date.rb +41 -0
  13. data/lib/xmlconv/i2/document.rb +27 -0
  14. data/lib/xmlconv/i2/header.rb +32 -0
  15. data/lib/xmlconv/i2/order.rb +61 -0
  16. data/lib/xmlconv/i2/parser.rb +23 -0
  17. data/lib/xmlconv/i2/position.rb +45 -0
  18. data/lib/xmlconv/i2/record.rb +11 -0
  19. data/lib/xmlconv/model/address.rb +20 -0
  20. data/lib/xmlconv/model/agreement.rb +10 -0
  21. data/lib/xmlconv/model/bdd.rb +37 -0
  22. data/lib/xmlconv/model/bsr.rb +16 -0
  23. data/lib/xmlconv/model/delivery.rb +15 -0
  24. data/lib/xmlconv/model/delivery_item.rb +24 -0
  25. data/lib/xmlconv/model/document.rb +25 -0
  26. data/lib/xmlconv/model/freetext_container.rb +26 -0
  27. data/lib/xmlconv/model/id_container.rb +22 -0
  28. data/lib/xmlconv/model/invoice.rb +18 -0
  29. data/lib/xmlconv/model/invoice_item.rb +11 -0
  30. data/lib/xmlconv/model/item.rb +19 -0
  31. data/lib/xmlconv/model/item_container.rb +15 -0
  32. data/lib/xmlconv/model/name.rb +27 -0
  33. data/lib/xmlconv/model/part_info.rb +10 -0
  34. data/lib/xmlconv/model/part_info_container.rb +15 -0
  35. data/lib/xmlconv/model/party.rb +20 -0
  36. data/lib/xmlconv/model/party_container.rb +20 -0
  37. data/lib/xmlconv/model/price.rb +10 -0
  38. data/lib/xmlconv/model/price_container.rb +18 -0
  39. data/lib/xmlconv/model/transaction.rb +28 -0
  40. data/lib/xmlconv/state/global.rb +28 -0
  41. data/lib/xmlconv/state/global_predefine.rb +11 -0
  42. data/lib/xmlconv/state/login.rb +39 -0
  43. data/lib/xmlconv/state/transaction.rb +13 -0
  44. data/lib/xmlconv/state/transactions.rb +130 -0
  45. data/lib/xmlconv/util/application.rb +142 -0
  46. data/lib/xmlconv/util/autoload.rb +35 -0
  47. data/lib/xmlconv/util/destination.rb +249 -0
  48. data/lib/xmlconv/util/invoicer.rb +71 -0
  49. data/lib/xmlconv/util/known_user.rb +16 -0
  50. data/lib/xmlconv/util/mail.rb +31 -0
  51. data/lib/xmlconv/util/polling_manager.rb +198 -0
  52. data/lib/xmlconv/util/session.rb +23 -0
  53. data/lib/xmlconv/util/transaction.rb +133 -0
  54. data/lib/xmlconv/util/validator.rb +20 -0
  55. data/lib/xmlconv/view/foot.rb +27 -0
  56. data/lib/xmlconv/view/head.rb +13 -0
  57. data/lib/xmlconv/view/login.rb +36 -0
  58. data/lib/xmlconv/view/navigation.rb +30 -0
  59. data/lib/xmlconv/view/navigationlink.rb +21 -0
  60. data/lib/xmlconv/view/pager.rb +73 -0
  61. data/lib/xmlconv/view/preformatted.rb +54 -0
  62. data/lib/xmlconv/view/template.rb +17 -0
  63. data/lib/xmlconv/view/transaction.rb +42 -0
  64. data/lib/xmlconv/view/transactions.rb +90 -0
  65. data/lib/xmlconv.rb +3 -0
  66. data/test/config.rb +12 -0
  67. data/test/mock.rb +149 -0
  68. data/test/suite.rb +16 -0
  69. data/test/test_i2/address.rb +88 -0
  70. data/test/test_i2/date.rb +50 -0
  71. data/test/test_i2/document.rb +62 -0
  72. data/test/test_i2/header.rb +39 -0
  73. data/test/test_i2/order.rb +94 -0
  74. data/test/test_i2/parser.rb +312 -0
  75. data/test/test_i2/position.rb +65 -0
  76. data/test/test_model/address.rb +35 -0
  77. data/test/test_model/agreement.rb +22 -0
  78. data/test/test_model/bdd.rb +55 -0
  79. data/test/test_model/bsr.rb +38 -0
  80. data/test/test_model/delivery.rb +79 -0
  81. data/test/test_model/delivery_item.rb +52 -0
  82. data/test/test_model/freetext_container.rb +45 -0
  83. data/test/test_model/invoice.rb +65 -0
  84. data/test/test_model/invoice_item.rb +41 -0
  85. data/test/test_model/name.rb +57 -0
  86. data/test/test_model/part_info.rb +24 -0
  87. data/test/test_model/party.rb +96 -0
  88. data/test/test_model/price.rb +24 -0
  89. data/test/test_util/application.rb +168 -0
  90. data/test/test_util/destination.rb +415 -0
  91. data/test/test_util/invoicer.rb +42 -0
  92. data/test/test_util/polling_manager.rb +299 -0
  93. data/test/test_util/transaction.rb +130 -0
  94. metadata +178 -0
@@ -0,0 +1,415 @@
1
+ #!/usr/bin/env ruby
2
+ # TestDestination -- xmlconv2 -- 08.06.2004 -- hwyss@ywesee.com
3
+
4
+ $: << File.dirname(__FILE__)
5
+ $: << File.expand_path('..', File.dirname(__FILE__))
6
+ $: << File.expand_path('../../lib', File.dirname(__FILE__))
7
+
8
+ require 'test/unit'
9
+ require 'xmlconv/util/destination'
10
+ require 'flexmock'
11
+ require 'xmlconv/config'
12
+
13
+ module XmlConv
14
+ module Util
15
+ class TestDestination < Test::Unit::TestCase
16
+ include FlexMock::TestCase
17
+ def setup
18
+ @destination = Destination.new
19
+ super
20
+ end
21
+ def test_attr_accessors
22
+ assert_respond_to(@destination, :path)
23
+ assert_respond_to(@destination, :path=)
24
+ end
25
+ def test_attr_readers
26
+ assert_respond_to(@destination, :uri)
27
+ assert_respond_to(@destination, :status)
28
+ assert_respond_to(@destination, :update_status)
29
+ end
30
+ def test_deliver__destination
31
+ delivery = flexmock('Delivery')
32
+ assert_raises(RuntimeError) {
33
+ @destination.deliver(delivery)
34
+ }
35
+ end
36
+ def test_forget_credentials
37
+ assert_respond_to(@destination, :forget_credentials!)
38
+ end
39
+ def test_book
40
+ assert_instance_of(DestinationDir, Destination.book('/'))
41
+ assert_instance_of(DestinationHttp,
42
+ Destination.book('http://www.example.com'))
43
+ assert_instance_of(DestinationFtp,
44
+ Destination.book('ftp://www.example.com'))
45
+ end
46
+ end
47
+ class TestDestinationDir < Test::Unit::TestCase
48
+ include FlexMock::TestCase
49
+ def setup
50
+ @destination = DestinationDir.new
51
+ @target_dir = File.expand_path('data/destination',
52
+ File.dirname(__FILE__))
53
+ super
54
+ end
55
+ def teardown
56
+ if(File.exist?(@target_dir))
57
+ FileUtils.rm_r(@target_dir)
58
+ end
59
+ super
60
+ end
61
+ def test_attr_readers
62
+ assert_respond_to(@destination, :filename)
63
+ end
64
+ def test_deliver__dir
65
+ storage = flexmock('Storage')
66
+ storage.should_receive(:transaction).and_return { |block|
67
+ block.call
68
+ }
69
+ ODBA.storage = storage
70
+ cache = flexmock('Cache')
71
+ ODBA.cache = cache
72
+ cache.should_receive(:store).and_return { |obj|
73
+ assert_equal(@destination, obj)
74
+ }
75
+ delivery = flexmock('Delivery')
76
+ delivery.should_receive(:filename).and_return { 'test_file.dat' }
77
+ if(File.exist?(@target_dir))
78
+ FileUtils.rm_r(@target_dir)
79
+ end
80
+ @destination.path = @target_dir
81
+ @destination.deliver(delivery)
82
+ target_file = File.expand_path('test_file.dat', @target_dir)
83
+ assert(File.exist?(@target_dir), "Target Directory was not created")
84
+ assert(File.exist?(target_file), "Target File was not written")
85
+ assert_equal(delivery.to_s, File.read(target_file))
86
+ assert_equal('test_file.dat', @destination.filename)
87
+ assert_equal(:pending_pickup, @destination.status)
88
+ ensure
89
+ ODBA.storage = nil
90
+ ODBA.cache = nil
91
+ end
92
+ def test_uri
93
+ @destination.path = '/foo/bar/baz'
94
+ assert_instance_of(URI::Generic, @destination.uri)
95
+ assert_equal("file:/foo/bar/baz", @destination.uri.to_s)
96
+ @destination.instance_variable_set('@filename', 'test_file.dat')
97
+ assert_equal("file:/foo/bar/baz/test_file.dat", @destination.uri.to_s)
98
+ end
99
+ def test_status
100
+ storage = flexmock('Storage')
101
+ storage.should_receive(:transaction).and_return { |block|
102
+ block.call
103
+ }
104
+ ODBA.storage = storage
105
+ cache = flexmock('Cache')
106
+ ODBA.cache = cache
107
+ cache.should_receive(:store).and_return { |obj|
108
+ assert_equal(@destination, obj)
109
+ }
110
+ assert_equal(:open, @destination.status)
111
+ @destination.update_status
112
+ assert_equal(:open, @destination.status)
113
+ @destination.instance_variable_set('@status', :pending_pickup)
114
+ @destination.instance_variable_set('@filename', 'no_such.file')
115
+ assert_equal(:pending_pickup, @destination.status)
116
+ @destination.update_status
117
+ assert_equal(:picked_up, @destination.status)
118
+ @destination.update_status
119
+ assert_equal(:picked_up, @destination.status)
120
+ ensure
121
+ ODBA.storage = nil
122
+ ODBA.cache = nil
123
+ end
124
+ def test_status_comparable
125
+ assert_equal(0, @destination.status_comparable)
126
+ @destination.instance_variable_set('@status', :pending_pickup)
127
+ assert_equal(10, @destination.status_comparable)
128
+ @destination.instance_variable_set('@status', :picked_up)
129
+ assert_equal(20, @destination.status_comparable)
130
+ end
131
+ end
132
+ class TestRemoteDestination < Test::Unit::TestCase
133
+ include FlexMock::TestCase
134
+ def setup
135
+ @destination = RemoteDestination.new
136
+ super
137
+ end
138
+ def test_attr_accessors
139
+ assert_respond_to(@destination, :path)
140
+ assert_respond_to(@destination, :path=)
141
+ assert_respond_to(@destination, :uri)
142
+ assert_respond_to(@destination, :uri=)
143
+ assert_respond_to(@destination, :host)
144
+ assert_respond_to(@destination, :host=)
145
+ end
146
+ end
147
+ class TestDestinationHttp < Test::Unit::TestCase
148
+ include FlexMock::TestCase
149
+ def setup
150
+ @destination = DestinationHttp.new
151
+ @destination.transport = @transport = flexmock('DestinationHttp::HTTP_CLASS')
152
+ super
153
+ end
154
+ def test_path_writer
155
+ assert_equal('http:/', @destination.uri.to_s)
156
+ @destination.path = '/foo/bar'
157
+ assert_equal('http:/foo/bar', @destination.uri.to_s)
158
+ end
159
+ def test_host_writer
160
+ assert_equal('http:/', @destination.uri.to_s)
161
+ @destination.host = 'www.example.org'
162
+ assert_equal('http://www.example.org/', @destination.uri.to_s)
163
+ end
164
+ def test_uri_writer
165
+ uri = URI.parse('http://www.example.org/foo/bar')
166
+ assert_instance_of(URI::HTTP, @destination.uri)
167
+ assert_equal('http:/', @destination.uri.to_s)
168
+ @destination.uri = uri
169
+ assert_instance_of(URI::HTTP, @destination.uri)
170
+ assert_equal('http://www.example.org/foo/bar', @destination.uri.to_s)
171
+ @destination.uri = 'http://www.example.com/foo/bar'
172
+ assert_instance_of(URI::HTTP, @destination.uri)
173
+ assert_equal('http://www.example.com/foo/bar', @destination.uri.to_s)
174
+ end
175
+ def test_deliver__http
176
+ @destination.uri = 'http://testaccount:password@xmlconv.ywesee.com:12345/test.rbx'
177
+ http_session = flexmock('HttpSession')
178
+ delivery = flexmock('Delivery')
179
+ response = flexmock('Response')
180
+ response.should_receive(:message).and_return { 'Status' }
181
+ delivery.should_receive(:to_s).and_return { 'The Delivery' }
182
+ http_session.should_receive(:request).and_return { |post_request, body|
183
+ assert_instance_of(Net::HTTP::Post, post_request)
184
+ header = post_request.instance_variable_get('@header')
185
+ assert_equal(['text/xml'], header['content-type'])
186
+ assert(header.include?('authorization'), "Authorization-Headers not sent")
187
+ assert_equal('The Delivery', body)
188
+ response
189
+ }
190
+ @transport.should_receive(:start).and_return { |host, port, block|
191
+ assert_equal('xmlconv.ywesee.com', host)
192
+ assert_equal(12345, port)
193
+ block.call(http_session)
194
+ }
195
+ @destination.deliver(delivery)
196
+ assert_equal(:http_status, @destination.status)
197
+ # When the delivery is delivered, forget username and Password
198
+ uri = @destination.uri
199
+ assert_nil(uri.user)
200
+ assert_nil(uri.password)
201
+ assert_equal('http://xmlconv.ywesee.com:12345/test.rbx', uri.to_s)
202
+ end
203
+ end
204
+ class TestDestinationFtp < Test::Unit::TestCase
205
+ include FlexMock::TestCase
206
+ def setup
207
+ @destination = DestinationFtp.new
208
+ @destination.transport = @transport = flexmock('DestinationFtp::FTP_CLASS')
209
+ super
210
+ end
211
+ def test_path_writer
212
+ assert_equal('ftp:/', @destination.uri.to_s)
213
+ @destination.path = '/foo/bar'
214
+ assert_equal('ftp:/foo/bar', @destination.uri.to_s)
215
+ end
216
+ def test_host_writer
217
+ assert_equal('ftp:/', @destination.uri.to_s)
218
+ @destination.host = 'www.example.org'
219
+ assert_equal('ftp://www.example.org/', @destination.uri.to_s)
220
+ end
221
+ def test_uri_writer
222
+ uri = URI.parse('ftp://www.example.org/foo/bar')
223
+ assert_instance_of(URI::FTP, @destination.uri)
224
+ assert_equal('ftp:/', @destination.uri.to_s)
225
+ @destination.uri = uri
226
+ assert_instance_of(URI::FTP, @destination.uri)
227
+ assert_equal('ftp://www.example.org/foo/bar', @destination.uri.to_s)
228
+ @destination.uri = 'ftp://www.example.com/foo/bar'
229
+ assert_instance_of(URI::FTP, @destination.uri)
230
+ assert_equal('ftp://www.example.com/foo/bar', @destination.uri.to_s)
231
+ end
232
+ def test_deliver__ftp
233
+ @destination.uri = 'ftp://testaccount:password@xmlconv.ywesee.com/foo/bar/'
234
+ ftp_session = flexmock('FtpSession')
235
+ delivery = flexmock('Delivery')
236
+ delivery.should_receive(:to_s).and_return { 'The Delivery' }
237
+ delivery.should_receive(:filename).and_return { 'test.dat' }
238
+ ftp_session.should_receive(:chdir).and_return { |path|
239
+ assert_equal('/foo/bar/', path)
240
+ }
241
+ ftp_session.should_receive(:puttextfile).and_return { |local, remote|
242
+ assert_equal("The Delivery\n", File.read(local))
243
+ assert_equal('test.dat', remote)
244
+ }
245
+ @transport.should_receive(:open).and_return { |host, user, password, block|
246
+ assert_equal('xmlconv.ywesee.com', host)
247
+ assert_equal('testaccount', user)
248
+ assert_equal('password', password)
249
+ block.call(ftp_session)
250
+ }
251
+ @destination.deliver(delivery)
252
+ assert_equal(:ftp_ok, @destination.status)
253
+ # When the delivery is delivered, forget username and Password
254
+ uri = @destination.uri
255
+ assert_nil(uri.user)
256
+ assert_nil(uri.password)
257
+ assert_equal('ftp://xmlconv.ywesee.com:21/foo/bar/', uri.to_s)
258
+ end
259
+ def test_deliver__many
260
+ @destination.uri = 'ftp://testaccount:password@xmlconv.ywesee.com/foo/bar/'
261
+ ftp_session = flexmock('FtpSession')
262
+ delivery = flexmock('Delivery')
263
+ delivery.should_receive(:to_s).and_return { 'The Delivery' }
264
+ delivery.should_receive(:filename).and_return { 'test.dat' }
265
+ delivery.should_receive(:to_s).and_return { 'The Delivery' }
266
+ delivery.should_receive(:filename).and_return { 'test.dat' }
267
+ ftp_session.should_receive(:chdir).and_return { |path|
268
+ assert_equal('/foo/bar/', path)
269
+ }
270
+ expecteds = %w{000_test.dat 001_test.dat}
271
+ ftp_session.should_receive(:puttextfile).times(2)\
272
+ .and_return { |local, remote|
273
+ assert_equal("The Delivery\n", File.read(local))
274
+ assert_equal(expecteds.shift, remote)
275
+ }
276
+ @transport.should_receive(:open).and_return { |host, user, password, block|
277
+ assert_equal('xmlconv.ywesee.com', host)
278
+ assert_equal('testaccount', user)
279
+ assert_equal('password', password)
280
+ block.call(ftp_session)
281
+ }
282
+ @destination.deliver([delivery, delivery])
283
+ assert_equal(:ftp_ok, @destination.status)
284
+ # When the delivery is delivered, forget username and Password
285
+ uri = @destination.uri
286
+ assert_nil(uri.user)
287
+ assert_nil(uri.password)
288
+ assert_equal('ftp://xmlconv.ywesee.com:21/foo/bar/', uri.to_s)
289
+ end
290
+ def test_deliver_tmp
291
+ path = 'ftp://testaccount:password@xmlconv.ywesee.com/foo/bar/'
292
+ tmp = '/foo/tmp'
293
+ @destination = Destination.book(path, tmp)
294
+ @destination.transport = @transport = flexmock('DestinationHttp::FTP_CLASS')
295
+ ftp_session = flexmock('FtpSession')
296
+ delivery = flexmock('Delivery')
297
+ delivery.should_receive(:to_s).and_return { 'The Delivery' }
298
+ delivery.should_receive(:filename).and_return { 'test.dat' }
299
+ ftp_session.should_receive(:chdir).and_return { |path|
300
+ assert_equal('/foo/bar/', path)
301
+ }
302
+ ftp_session.should_receive(:puttextfile).and_return { |local, remote|
303
+ assert_equal("The Delivery\n", File.read(local))
304
+ assert_equal('/foo/tmp/test.dat', remote)
305
+ }
306
+ ftp_session.should_receive(:rename).with('/foo/tmp/test.dat', 'test.dat').times(1)
307
+ @transport.should_receive(:open).and_return { |host, user, password, block|
308
+ assert_equal('xmlconv.ywesee.com', host)
309
+ assert_equal('testaccount', user)
310
+ assert_equal('password', password)
311
+ block.call(ftp_session)
312
+ }
313
+ @destination.deliver(delivery)
314
+ assert_equal(:ftp_ok, @destination.status)
315
+ # When the delivery is delivered, forget username and Password
316
+ uri = @destination.uri
317
+ assert_nil(uri.user)
318
+ assert_nil(uri.password)
319
+ assert_equal('ftp://xmlconv.ywesee.com:21/foo/bar/', uri.to_s)
320
+ end
321
+ end
322
+ class TestDestinationSftp < Test::Unit::TestCase
323
+ include FlexMock::TestCase
324
+ def setup
325
+ @destination = DestinationSftp.new
326
+ @destination.transport = @transport = flexmock('DestinationSftp::SFTP_CLASS')
327
+ super
328
+ end
329
+ def test_path_writer
330
+ assert_equal('sftp:/', @destination.uri.to_s)
331
+ @destination.path = '/foo/bar'
332
+ assert_equal('sftp:/foo/bar', @destination.uri.to_s)
333
+ end
334
+ def test_host_writer
335
+ assert_equal('sftp:/', @destination.uri.to_s)
336
+ @destination.host = 'www.example.org'
337
+ assert_equal('sftp://www.example.org/', @destination.uri.to_s)
338
+ end
339
+ def test_uri_writer
340
+ uri = URI.parse('sftp://www.example.org/foo/bar')
341
+ assert_instance_of(URI::Generic, @destination.uri)
342
+ assert_equal('sftp:/', @destination.uri.to_s)
343
+ @destination.uri = uri
344
+ assert_instance_of(URI::Generic, @destination.uri)
345
+ assert_equal('sftp://www.example.org/foo/bar', @destination.uri.to_s)
346
+ @destination.uri = 'sftp://www.example.com/foo/bar'
347
+ assert_instance_of(URI::Generic, @destination.uri)
348
+ assert_equal('sftp://www.example.com/foo/bar', @destination.uri.to_s)
349
+ end
350
+ def test_deliver__sftp
351
+ @destination.uri = 'sftp://testaccount@xmlconv.ywesee.com/foo/bar/'
352
+ file_operations = flexmock 'SftpFileOperations'
353
+ sftp_session = flexmock('SftpSession')
354
+ sftp_session.should_receive(:file).and_return file_operations
355
+ delivery = flexmock('Delivery')
356
+ delivery.should_receive(:to_s).and_return { 'The Delivery' }
357
+ delivery.should_receive(:filename).and_return { 'test.dat' }
358
+ file_handle = StringIO.new('')
359
+ @transport.should_receive(:start).and_return { |host, user, opts, block|
360
+ assert_equal('xmlconv.ywesee.com', host)
361
+ assert_equal('testaccount', user)
362
+ assert_equal([], opts[:keys])
363
+ assert_instance_of(String, opts[:user_known_hosts_file])
364
+ block.call(sftp_session)
365
+ }
366
+ file_operations.should_receive(:open).and_return do |path, mode, block|
367
+ assert_equal '/foo/bar/test.dat', path
368
+ assert_equal 'w', mode
369
+ block.call file_handle
370
+ end
371
+ @destination.deliver(delivery)
372
+ assert_equal(:sftp_ok, @destination.status)
373
+ file_handle.rewind
374
+ assert_equal "The Delivery\n", file_handle.read
375
+ # When the delivery is delivered, forget username and Password
376
+ uri = @destination.uri
377
+ assert_nil(uri.user)
378
+ assert_nil(uri.password)
379
+ assert_equal('sftp://xmlconv.ywesee.com/foo/bar/', uri.to_s)
380
+ end
381
+ def test_deliver__many
382
+ @destination.uri = 'sftp://testaccount@xmlconv.ywesee.com/foo/bar/'
383
+ file_operations = flexmock 'SftpFileOperations'
384
+ sftp_session = flexmock('SftpSession')
385
+ sftp_session.should_receive(:file).and_return file_operations
386
+ delivery = flexmock('Delivery')
387
+ delivery.should_receive(:to_s).and_return { 'The Delivery' }
388
+ delivery.should_receive(:filename).and_return { 'test.dat' }
389
+ file_handle = StringIO.new('')
390
+ @transport.should_receive(:start).and_return { |host, user, opts, block|
391
+ assert_equal('xmlconv.ywesee.com', host)
392
+ assert_equal('testaccount', user)
393
+ assert_equal([], opts[:keys])
394
+ assert_instance_of(String, opts[:user_known_hosts_file])
395
+ block.call(sftp_session)
396
+ }
397
+ expecteds = %w{/foo/bar/test.dat /foo/bar/test.dat}
398
+ file_operations.should_receive(:open).and_return do |path, mode, block|
399
+ assert_equal(expecteds.shift, path)
400
+ assert_equal 'w', mode
401
+ block.call file_handle
402
+ end
403
+ @destination.deliver([delivery, delivery])
404
+ assert_equal(:sftp_ok, @destination.status)
405
+ file_handle.rewind
406
+ assert_equal "The Delivery\n" * 2, file_handle.read
407
+ # When the delivery is delivered, forget username and Password
408
+ uri = @destination.uri
409
+ assert_nil(uri.user)
410
+ assert_nil(uri.password)
411
+ assert_equal('sftp://xmlconv.ywesee.com/foo/bar/', uri.to_s)
412
+ end
413
+ end
414
+ end
415
+ end
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+ # Util::TestInvoicer -- xmlconv2 -- 03.08.2006 -- hwyss@ywesee.com
3
+
4
+ $: << File.dirname(__FILE__)
5
+ $: << File.expand_path('../../lib', File.dirname(__FILE__))
6
+
7
+ require 'test/unit'
8
+ require 'xmlconv/util/invoicer'
9
+ require 'flexmock'
10
+
11
+ module XmlConv
12
+ module Util
13
+ class TestInvoicer < Test::Unit::TestCase
14
+ def setup
15
+ @invoicer = Invoicer
16
+ end
17
+ def test_group_by_partner
18
+ trans1 = FlexMock.new
19
+ trans1.should_receive(:partner)\
20
+ .times(1).and_return { 'Group1' }
21
+ trans1.should_receive(:model)\
22
+ .times(1).and_return { 'Model1' }
23
+ trans2 = FlexMock.new
24
+ trans2.should_receive(:partner)\
25
+ .times(1).and_return { 'Group2' }
26
+ trans2.should_receive(:model)\
27
+ .times(1).and_return { 'Model2' }
28
+ trans3 = FlexMock.new
29
+ trans3.should_receive(:partner)\
30
+ .times(1).and_return { 'Group1' }
31
+ trans3.should_receive(:model)\
32
+ .times(1).and_return { 'Model3' }
33
+ transactions = [trans1, trans2, trans3]
34
+ expected = {
35
+ 'Group1' => ['Model1', 'Model3'],
36
+ 'Group2' => ['Model2']
37
+ }
38
+ assert_equal(expected, @invoicer.group_by_partner(transactions))
39
+ end
40
+ end
41
+ end
42
+ end