LitleOnline 8.16.0 → 8.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/CHANGELOG +7 -0
  2. data/DESCRIPTION +1 -1
  3. data/README.md +2 -2
  4. data/Rakefile +6 -3
  5. data/bin/Setup.rb +14 -0
  6. data/bin/sample_batch_driver.rb +122 -0
  7. data/lib/LitleBatchRequest.rb +466 -0
  8. data/lib/LitleListeners.rb +142 -0
  9. data/lib/LitleOnline.rb +4 -0
  10. data/lib/LitleOnlineRequest.rb +25 -144
  11. data/lib/LitleRequest.rb +513 -0
  12. data/lib/LitleTransaction.rb +295 -0
  13. data/lib/XMLFields.rb +114 -4
  14. data/test/certification/certTest_batchAll.rb +337 -0
  15. data/test/certification/ts_all.rb +2 -0
  16. data/test/functional/test_batch.rb +164 -0
  17. data/test/functional/test_credit.rb +0 -18
  18. data/test/functional/test_litle_requests.rb +355 -0
  19. data/test/functional/test_updateCardValidationNumOnToken.rb +1 -1
  20. data/test/functional/test_xmlfields.rb +0 -19
  21. data/test/functional/ts_all.rb +2 -0
  22. data/test/unit/test_LitleAUBatch.rb +217 -0
  23. data/test/unit/test_LitleBatchRequest.rb +599 -0
  24. data/test/unit/test_LitleOnlineRequest.rb +9 -57
  25. data/test/unit/test_LitleRequest.rb +320 -0
  26. data/test/unit/test_LitleTransaction.rb +398 -0
  27. data/test/unit/test_auth.rb +25 -2
  28. data/test/unit/test_authReversal.rb +28 -5
  29. data/test/unit/test_capture.rb +24 -1
  30. data/test/unit/test_captureGivenAuth.rb +23 -1
  31. data/test/unit/test_credit.rb +92 -19
  32. data/test/unit/test_echeckCredit.rb +1 -1
  33. data/test/unit/test_echeckRedeposit.rb +1 -1
  34. data/test/unit/test_echeckSale.rb +1 -1
  35. data/test/unit/test_echeckVerification.rb +1 -1
  36. data/test/unit/test_echeckVoid.rb +1 -1
  37. data/test/unit/test_forceCapture.rb +24 -1
  38. data/test/unit/test_sale.rb +25 -2
  39. data/test/unit/test_token.rb +1 -1
  40. data/test/unit/test_updateCardValidationNumOnToken.rb +1 -1
  41. data/test/unit/test_xmlfields.rb +1 -1
  42. data/test/unit/ts_unit.rb +4 -0
  43. metadata +59 -14
@@ -60,24 +60,6 @@ module LitleOnline
60
60
  assert_equal('Valid Format', response.message)
61
61
  end
62
62
 
63
- def test_illegal_order_id
64
- hash = {
65
- 'merchantId' => '101',
66
- 'version'=>'8.8',
67
- 'reportGroup'=>'Planets',
68
- 'orderId'=>'12344',
69
- 'litleTxnId' => '12345456',
70
- 'amount'=>'106',
71
- 'orderSource'=>'ecomerce',
72
- 'card'=>{
73
- 'type'=>'VI',
74
- 'number' =>'4100000000000001',
75
- 'expDate' =>'1210'
76
- }}
77
- response= LitleOnlineRequest.new.credit(hash)
78
- assert(response.message =~ /Error validating xml data against the schema/)
79
- end
80
-
81
63
  def test_fields_out_of_order
82
64
  hash = {
83
65
  'merchantId' => '101',
@@ -0,0 +1,355 @@
1
+ =begin
2
+ Copyright (c) 2012 Litle & Co.
3
+
4
+ Permission is hereby granted, free of charge, to any person
5
+ obtaining a copy of this software and associated documentation
6
+ files (the "Software"), to deal in the Software without
7
+ restriction, including without limitation the rights to use,
8
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the
10
+ Software is furnished to do so, subject to the following
11
+ conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
+ OTHER DEALINGS IN THE SOFTWARE.
24
+ =end
25
+ require 'lib/LitleOnline'
26
+ require 'test/unit'
27
+ require 'fileutils'
28
+
29
+ module LitleOnline
30
+ class TestLitleRequest < Test::Unit::TestCase
31
+
32
+ def setup
33
+ dir = '/tmp/litle-sdk-for-ruby-test'
34
+ FileUtils.rm_rf dir
35
+ Dir.mkdir dir
36
+ end
37
+
38
+ def test_request_creation
39
+ dir = '/tmp'
40
+
41
+ request = LitleRequest.new()
42
+ request.create_new_litle_request(dir + '/litle-sdk-for-ruby-test')
43
+
44
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
45
+ entries.sort!
46
+
47
+ assert_equal entries.size, 4
48
+ assert_not_nil entries[2] =~ /request_\d+\z/
49
+ assert_not_nil entries[3] =~ /request_\d+_batches\z/
50
+ end
51
+
52
+ def test_commit_batch_with_path
53
+ dir = '/tmp'
54
+
55
+ batch = LitleBatchRequest.new
56
+ batch.create_new_batch(dir + '/litle-sdk-for-ruby-test')
57
+ batch.close_batch
58
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
59
+
60
+ assert_equal entries.length, 3
61
+ entries.sort!
62
+ assert_not_nil entries[2] =~ /batch_\d+.closed-0\z/
63
+
64
+ request = LitleRequest.new
65
+ request.create_new_litle_request(dir+ '/litle-sdk-for-ruby-test')
66
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
67
+ entries.sort!
68
+ assert_not_nil entries[2] =~ /batch_\d+.closed-0\z/
69
+ assert_not_nil entries[3] =~ /request_\d+\z/
70
+ assert_not_nil entries[4] =~ /request_\d+_batches\z/
71
+
72
+ request.commit_batch(batch.get_batch_name)
73
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
74
+ entries.sort!
75
+ assert_equal entries.length, 4
76
+ assert_not_nil entries[2] =~ /request_\d+\z/
77
+ assert_not_nil entries[3] =~ /request_\d+_batches\z/
78
+ end
79
+
80
+ def test_commit_batch_with_batch
81
+ dir = '/tmp'
82
+
83
+ batch = LitleBatchRequest.new
84
+ batch.create_new_batch(dir + '/litle-sdk-for-ruby-test')
85
+ batch.close_batch
86
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
87
+
88
+ assert_equal entries.length, 3
89
+ entries.sort!
90
+ assert_not_nil entries[2] =~ /batch_\d+.closed-0\z/
91
+
92
+ request = LitleRequest.new
93
+ request.create_new_litle_request(dir+ '/litle-sdk-for-ruby-test')
94
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
95
+ entries.sort!
96
+ assert_equal entries.length, 5
97
+ assert_not_nil entries[2] =~ /batch_\d+.closed-0\z/
98
+ assert_not_nil entries[3] =~ /request_\d+\z/
99
+ assert_not_nil entries[4] =~ /request_\d+_batches\z/
100
+
101
+ request.commit_batch(batch)
102
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
103
+ entries.sort!
104
+ assert_equal entries.length, 4
105
+ assert_not_nil entries[2] =~ /request_\d+\z/
106
+ assert_not_nil entries[3] =~ /request_\d+_batches\z/
107
+ end
108
+
109
+ def test_commit_batch_with_batch_and_au
110
+ dir = '/tmp'
111
+
112
+ batch = LitleBatchRequest.new
113
+ batch.create_new_batch(dir + '/litle-sdk-for-ruby-test')
114
+ accountUpdateHash = {
115
+ 'reportGroup'=>'Planets',
116
+ 'id'=>'12345',
117
+ 'customerId'=>'0987',
118
+ 'card'=>{
119
+ 'type'=>'VI',
120
+ 'number' =>'4100000000000001',
121
+ 'expDate' =>'1210'
122
+ }}
123
+ batch.account_update(accountUpdateHash)
124
+ batch.close_batch
125
+
126
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
127
+
128
+ assert_equal entries.length, 4
129
+ entries.sort!
130
+ assert_not_nil entries[2] =~ /batch_\d+.closed-0\z/
131
+ assert_not_nil entries[3] =~ /batch_\d+.closed-1\z/
132
+
133
+ request = LitleRequest.new
134
+ request.create_new_litle_request(dir+ '/litle-sdk-for-ruby-test')
135
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
136
+ entries.sort!
137
+ assert_equal entries.length, 6
138
+ assert_not_nil entries[2] =~ /batch_\d+.closed-0\z/
139
+ assert_not_nil entries[3] =~ /batch_\d+.closed-1\z/
140
+ assert_not_nil entries[4] =~ /request_\d+\z/
141
+ assert_not_nil entries[5] =~ /request_\d+_batches\z/
142
+
143
+ request.commit_batch(batch)
144
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
145
+ entries.sort!
146
+ assert_equal entries.length, 4
147
+ assert_not_nil entries[2] =~ /request_\d+\z/
148
+ assert_not_nil entries[3] =~ /request_\d+_batches\z/
149
+ end
150
+
151
+ def test_finish_request
152
+ dir = '/tmp'
153
+
154
+ request = LitleRequest.new()
155
+ request.create_new_litle_request(dir + '/litle-sdk-for-ruby-test')
156
+
157
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
158
+ entries.sort!
159
+
160
+ assert_equal entries.size, 4
161
+ assert_not_nil entries[2] =~ /request_\d+\z/
162
+ assert_not_nil entries[3] =~ /request_\d+_batches\z/
163
+
164
+ request.finish_request
165
+
166
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
167
+ entries.sort!
168
+
169
+ assert_equal entries.size, 3
170
+ assert_not_nil entries[2] =~ /request_\d+.complete\z/
171
+ end
172
+
173
+ def test_add_rfr
174
+ @config_hash = Configuration.new.config
175
+
176
+ dir = '/tmp'
177
+ temp = dir + '/litle-sdk-for-ruby-test/'
178
+
179
+ request = LitleRequest.new()
180
+ request.add_rfr_request({'litleSessionId' => '137813712'}, temp)
181
+
182
+ entries = Dir.entries(temp)
183
+ entries.sort!
184
+
185
+ assert_equal entries.size, 3
186
+ assert_not_nil entries[2] =~ /request_\d+.complete\z/
187
+ end
188
+
189
+ def test_send_to_litle
190
+ @config_hash = Configuration.new.config
191
+
192
+ dir = '/tmp'
193
+
194
+ request = LitleRequest.new()
195
+ request.create_new_litle_request(dir + '/litle-sdk-for-ruby-test')
196
+ request.finish_request
197
+ request.send_to_litle
198
+
199
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
200
+ entries.sort!
201
+
202
+ assert_equal entries.size, 3
203
+ assert_not_nil entries[2] =~ /request_\d+.complete.sent\z/
204
+
205
+ uploaded_file = entries[2]
206
+
207
+ options = {}
208
+ username = get_config(:sftp_username, options)
209
+ password = get_config(:sftp_password, options)
210
+ url = get_config(:sftp_url, options)
211
+
212
+ Net::SFTP.start(url, username, :password => password) do |sftp|
213
+ # clear out the sFTP outbound dir prior to checking for new files, avoids leaving files on the server
214
+ # if files are left behind we are not counting then towards the expected total
215
+ ents = []
216
+ handle = sftp.opendir!('/inbound/')
217
+ files_on_srv = sftp.readdir!(handle)
218
+ files_on_srv.each {|file|
219
+ ents.push(file.name)
220
+ }
221
+ assert_equal ents.size, 3
222
+ ents.sort!
223
+ assert_equal ents[2], uploaded_file.gsub('sent', 'asc')
224
+ sftp.remove('/inbound/' + ents[2])
225
+ end
226
+ end
227
+
228
+ def test_send_to_litle_stream
229
+ @config_hash = Configuration.new.config
230
+
231
+ dir = '/tmp'
232
+
233
+ request = LitleRequest.new()
234
+ request.create_new_litle_request(dir + '/litle-sdk-for-ruby-test')
235
+ request.finish_request
236
+ request.send_to_litle_stream
237
+
238
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
239
+ entries.sort!
240
+
241
+ assert_equal entries.size, 4
242
+ assert_not_nil entries[2] =~ /request_\d+.complete.sent\z/
243
+ File.delete(dir + '/litle-sdk-for-ruby-test/' + entries[2])
244
+
245
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test/responses')
246
+ entries.sort!
247
+
248
+ assert_equal entries.size, 3
249
+ assert_not_nil entries[2] =~ /response_\d+.complete.asc.received\z/
250
+ end
251
+
252
+ def test_full_flow
253
+ saleHash = {
254
+ 'reportGroup'=>'Planets',
255
+ 'id' => '006',
256
+ 'orderId'=>'12344',
257
+ 'amount'=>'6000',
258
+ 'orderSource'=>'ecommerce',
259
+ 'card'=>{
260
+ 'type'=>'VI',
261
+ 'number' =>'4100000000000001',
262
+ 'expDate' =>'1210'
263
+ }}
264
+
265
+ dir = '/tmp'
266
+
267
+ request = LitleRequest.new()
268
+ request.create_new_litle_request(dir + '/litle-sdk-for-ruby-test')
269
+
270
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
271
+ entries.sort!
272
+
273
+ assert_equal entries.size, 4
274
+ assert_not_nil entries[2] =~ /request_\d+\z/
275
+ assert_not_nil entries[3] =~ /request_\d+_batches\z/
276
+
277
+ #create five batches, each with 10 sales
278
+ 5.times{
279
+ batch = LitleBatchRequest.new
280
+ batch.create_new_batch(dir + '/litle-sdk-for-ruby-test')
281
+
282
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
283
+
284
+ assert_equal entries.length, 6
285
+ entries.sort!
286
+ assert_not_nil entries[2] =~ /batch_\d+\z/
287
+ assert_not_nil entries[3] =~ /batch_\d+_txns\z/
288
+ assert_not_nil entries[4] =~ /request_\d+\z/
289
+ assert_not_nil entries[5] =~ /request_\d+_batches\z/
290
+ #add the same sale ten times
291
+ 10.times{
292
+ #batch.account_update(accountUpdateHash)
293
+ batch.sale(saleHash)
294
+ }
295
+
296
+ #close the batch, indicating we plan to add no more transactions
297
+ batch.close_batch()
298
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
299
+
300
+ assert_equal entries.length, 5
301
+ entries.sort!
302
+ assert_not_nil entries[2] =~ /batch_\d+.closed-\d+\z/
303
+ assert_not_nil entries[3] =~ /request_\d+\z/
304
+ assert_not_nil entries[4] =~ /request_\d+_batches\z/
305
+
306
+ #add the batch to the LitleRequest
307
+ request.commit_batch(batch)
308
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
309
+ assert_equal entries.length, 4
310
+ entries.sort!
311
+ assert_not_nil entries[2] =~ /request_\d+\z/
312
+ assert_not_nil entries[3] =~ /request_\d+_batches\z/
313
+ }
314
+ #finish the Litle Request, indicating we plan to add no more batches
315
+ request.finish_request
316
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
317
+ assert_equal entries.length, 3
318
+ entries.sort!
319
+ assert_not_nil entries[2] =~ /request_\d+.complete\z/
320
+
321
+ #send the batch files at the given directory over sFTP
322
+ request.send_to_litle
323
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
324
+ assert_equal entries.length, 3
325
+ entries.sort!
326
+ assert_not_nil entries[2] =~ /request_\d+.complete.sent\z/
327
+ #grab the expected number of responses from the sFTP server and save them to the given path
328
+ request.get_responses_from_server()
329
+ #process the responses from the server with a listener which applies the given block
330
+ request.process_responses({:transaction_listener => LitleOnline::DefaultLitleListener.new do |transaction| end})
331
+
332
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
333
+ assert_equal entries.length, 4
334
+ entries.sort!
335
+ assert_not_nil entries[2] =~ /request_\d+.complete.sent\z/
336
+ File.delete(dir + '/litle-sdk-for-ruby-test/' + entries[2])
337
+
338
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test/' + entries[3])
339
+ entries.sort!
340
+ assert_equal entries.length, 3
341
+ assert_not_nil entries[2] =~ /response_\d+.complete.asc.received.processed\z/
342
+
343
+ end
344
+
345
+ def get_config(field, options)
346
+ if options[field.to_s] == nil and options[field] == nil then
347
+ return @config_hash[field.to_s]
348
+ elsif options[field.to_s] != nil then
349
+ return options[field.to_s]
350
+ else
351
+ return options[field]
352
+ end
353
+ end
354
+ end
355
+ end
@@ -34,7 +34,7 @@ module LitleOnline
34
34
  'reportGroup'=>'Planets',
35
35
  'orderId'=>'12344',
36
36
  'litleToken'=>'1233456789103801',
37
- 'cardValidationNum'=>'123'
37
+ 'cardValidationNum'=>'123'
38
38
  }
39
39
  response= LitleOnlineRequest.new.update_card_validation_num_on_token(hash)
40
40
  assert_equal('Valid Format', response.message)
@@ -341,25 +341,6 @@ module LitleOnline
341
341
  assert_equal('Valid Format', response.message)
342
342
  end
343
343
 
344
- def test_cardbothtypeandtrack
345
- hash = {
346
- 'merchantId' => '101',
347
- 'version'=>'8.8',
348
- 'reportGroup'=>'Planets',
349
- 'litleTxnId'=>'123456',
350
- 'orderId'=>'12344',
351
- 'amount'=>'106',
352
- 'orderSource'=>'ecommerce',
353
- 'card'=>{
354
- 'type'=>'VI',
355
- 'track'=>'1234',
356
- 'number' =>'4100000000000001',
357
- 'expDate' =>'1210'
358
- }}
359
- response= LitleOnlineRequest.new.credit(hash)
360
- assert(response.message =~ /Error validating xml data against the schema/)
361
- end
362
-
363
344
  def test_line_item_data
364
345
  hash = {
365
346
  'merchantId' => '101',
@@ -41,3 +41,5 @@ require_relative 'test_echeckCredit'
41
41
  require_relative 'test_echeckVerification'
42
42
  require_relative 'test_echeckVoid'
43
43
  require_relative 'test_updateCardValidationNumOnToken'
44
+ require_relative 'test_litle_requests'
45
+ require_relative 'test_batch'
@@ -0,0 +1,217 @@
1
+ =begin
2
+ Copyright (c) 2011 Litle & Co.
3
+
4
+ Permission is hereby granted, free of charge, to any person
5
+ obtaining a copy of this software and associated documentation
6
+ files (the "Software"), to deal in the Software without
7
+ restriction, including without limitation the rights to use,
8
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the
10
+ Software is furnished to do so, subject to the following
11
+ conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
+ OTHER DEALINGS IN THE SOFTWARE.
24
+ =end
25
+ require 'lib/LitleOnline'
26
+ require 'lib/LitleBatchRequest'
27
+ require 'test/unit'
28
+ require 'mocha/setup'
29
+
30
+ module LitleOnline
31
+
32
+ class TestLitleAUBatch < Test::Unit::TestCase
33
+ def test_create_new_batch
34
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
35
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').twice
36
+ Dir.expects(:mkdir).with('/usr/local/Batches/').once
37
+ File.expects(:directory?).returns(false).once
38
+
39
+ batch = LitleAUBatch.new
40
+ batch.create_new_batch('/usr/local/Batches/')
41
+ end
42
+
43
+ def test_account_update
44
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
45
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
46
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
47
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
48
+ File.expects(:directory?).returns(true).once
49
+
50
+ accountUpdateHash = {
51
+ 'reportGroup'=>'Planets',
52
+ 'id'=>'12345',
53
+ 'customerId'=>'0987',
54
+ 'card'=>{
55
+ 'type'=>'VI',
56
+ 'number' =>'4100000000000001',
57
+ 'expDate' =>'1210'
58
+ }}
59
+
60
+ batch = LitleAUBatch.new
61
+ batch.create_new_batch('D:\Batches\\')
62
+ batch.account_update(accountUpdateHash)
63
+
64
+ counts = batch.get_counts_and_amounts
65
+ assert_equal 1, counts[:numAccountUpdates]
66
+ assert_equal 1, counts[:total]
67
+ end
68
+
69
+ def test_close_batch
70
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
71
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
72
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').once
73
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.closed.*/), 'w').once
74
+ File.expects(:rename).once
75
+ File.expects(:delete).once
76
+ File.expects(:directory?).returns(true).once
77
+
78
+ batch = LitleAUBatch.new
79
+ batch.create_new_batch('D:\Batches\\')
80
+
81
+ batch.close_batch()
82
+ end
83
+
84
+ def test_open_existing_batch
85
+ open = sequence('open')
86
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).times(2).in_sequence(open)
87
+
88
+ File.expects(:file?).returns(false).once.in_sequence(open)
89
+ File.expects(:directory?).returns(true).in_sequence(open)
90
+ File.expects(:file?).returns(false).in_sequence(open)
91
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').in_sequence(open)
92
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(open)
93
+ File.expects(:file?).returns(true).in_sequence(open)
94
+
95
+
96
+
97
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'rb').returns({:numAccountUpdates => 0}).once.in_sequence(open)
98
+ File.expects(:rename).once.in_sequence(open)
99
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.closed.*/), 'w').once.in_sequence(open)
100
+ File.expects(:delete).with(regexp_matches(/.*batch_.*\d_txns.*/)).once.in_sequence(open)
101
+ batch1 = LitleAUBatch.new
102
+ batch2 = LitleAUBatch.new
103
+ batch1.create_new_batch('/usr/local/Batches/')
104
+
105
+ batch2.open_existing_batch(batch1.get_batch_name)
106
+ batch2.close_batch()
107
+ end
108
+
109
+ def test_build_batch_header
110
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
111
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
112
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').once
113
+ File.expects(:rename).once
114
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'w').once
115
+ File.expects(:delete).once
116
+ File.expects(:directory?).returns(true).once
117
+
118
+ batch = LitleAUBatch.new
119
+ batch.get_counts_and_amounts.expects(:[]).returns(hash = Hash.new).at_least(5)
120
+
121
+ batch.create_new_batch('/usr/local/batches')
122
+ batch.close_batch()
123
+ end
124
+
125
+ def test_create_new_batch_missing_separator
126
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
127
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
128
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').once
129
+
130
+ batch = LitleAUBatch.new
131
+ batch.create_new_batch('/usr/local')
132
+
133
+ assert batch.get_batch_name.include?('/usr/local/')
134
+ end
135
+
136
+ def test_create_new_batch_name_collision
137
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
138
+
139
+ fileExists = sequence('fileExists')
140
+ File.expects(:file?).with(regexp_matches(/.*\/usr\/local\//)).returns(false).in_sequence(fileExists)
141
+ File.expects(:file?).with(regexp_matches(/.*batch_.*\d.*/)).returns(true).in_sequence(fileExists)
142
+ File.expects(:file?).with(regexp_matches(/.*\/usr\/local\//)).returns(false).in_sequence(fileExists)
143
+ File.expects(:file?).with(regexp_matches(/.*batch_.*\d.*/)).returns(false).in_sequence(fileExists)
144
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').in_sequence(fileExists)
145
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(fileExists)
146
+
147
+
148
+ batch = LitleAUBatch.new
149
+ batch.create_new_batch('/usr/local/')
150
+ end
151
+
152
+ def test_create_new_batch_when_full
153
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
154
+
155
+ batch = LitleAUBatch.new
156
+ addTxn = sequence('addTxn')
157
+
158
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').in_sequence(addTxn)
159
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(addTxn)
160
+ batch.create_new_batch('/usr/local')
161
+
162
+ batch.get_counts_and_amounts.expects(:[]).with(:numAccountUpdates).returns(499999).in_sequence(addTxn)
163
+ batch.get_counts_and_amounts.expects(:[]).with(:total).returns(30000).in_sequence(addTxn)
164
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(addTxn)
165
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').in_sequence(addTxn)
166
+ batch.get_counts_and_amounts.expects(:[]).with(:total).returns(100000).in_sequence(addTxn)
167
+ batch.expects(:close_batch).once.in_sequence(addTxn)
168
+ batch.expects(:initialize).once.in_sequence(addTxn)
169
+ batch.expects(:create_new_batch).once.in_sequence(addTxn)
170
+
171
+ accountUpdateHash = {
172
+ 'reportGroup'=>'Planets',
173
+ 'id'=>'12345',
174
+ 'customerId'=>'0987',
175
+ 'card'=>{
176
+ 'type'=>'VI',
177
+ 'number' =>'4100000000000001',
178
+ 'expDate' =>'1210'
179
+ }}
180
+
181
+ batch.account_update(accountUpdateHash)
182
+ end
183
+
184
+ def test_complete_batch
185
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
186
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').at_most(7)
187
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').at_most(5)
188
+ File.expects(:rename).once
189
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.closed.*/), 'w').once
190
+ File.expects(:delete).with(regexp_matches(/.*batch_.*\d_txns.*/)).once
191
+ Dir.expects(:mkdir).with('/usr/local/Batches/').once
192
+ File.expects(:directory?).returns(false).once
193
+
194
+ batch = LitleAUBatch.new
195
+ batch.create_new_batch('/usr/local/Batches/')
196
+
197
+ accountUpdateHash = {
198
+ 'reportGroup'=>'Planets',
199
+ 'id'=>'12345',
200
+ 'customerId'=>'0987',
201
+ 'card'=>{
202
+ 'type'=>'VI',
203
+ 'number' =>'4100000000000001',
204
+ 'expDate' =>'1210'
205
+ }}
206
+
207
+ 5.times(){ batch.account_update(accountUpdateHash ) }
208
+
209
+ #pid, size = `ps ax -o pid,rss | grep -E "^[[:space:]]*#{$$}"`.strip.split.map(&:to_i)
210
+ #puts "PID: " + pid.to_s + " size: " + size.to_s
211
+ batch.close_batch()
212
+ counts = batch.get_counts_and_amounts
213
+
214
+ assert_equal 5, counts[:numAccountUpdates]
215
+ end
216
+ end
217
+ end