razorrisk-razor-connectivity 0.14.10

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.
@@ -0,0 +1,652 @@
1
+ #! /usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ # ##########################################################################
5
+ #
6
+ # Copyright (c) 2017 Razor Risk Technologies Pty Limited. All rights reserved.
7
+ #
8
+ # ##########################################################################
9
+
10
+
11
+ # ##########################################################
12
+ # load path
13
+
14
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 4), 'lib')
15
+
16
+
17
+ # ##########################################################
18
+ # diagnostics
19
+
20
+ unless $DEBUG
21
+
22
+ require 'pantheios/globals'
23
+ require 'pantheios/services/null_log_service'
24
+
25
+ ::Pantheios::Globals.INITIAL_SERVICE_CLASSES = [ ::Pantheios::Services::NullLogService ]
26
+ end
27
+
28
+
29
+ # ##########################################################
30
+ # code coverage
31
+
32
+ require 'simplecov'
33
+
34
+
35
+ # ##########################################################
36
+ # requires
37
+
38
+ require 'razor_risk/razor/connectivity/razor_3/header_maker'
39
+
40
+ require 'xqsr3/xml/utilities/compare'
41
+ require 'xqsr3/extensions/test/unit'
42
+
43
+ require 'test/unit'
44
+
45
+
46
+ # ##########################################################
47
+ # tests
48
+
49
+ class Test_HeaderMaker_types_exist < Test::Unit::TestCase
50
+
51
+ def test_has_RazorRisk_module
52
+
53
+ assert Object.const_defined? :RazorRisk
54
+ end
55
+
56
+ def test_has_RazorRisk_Razor_module
57
+
58
+ assert RazorRisk.const_defined? :Razor
59
+ end
60
+
61
+ def test_has_RazorRisk_Razor_Connectivity_module
62
+
63
+ assert RazorRisk::Razor.const_defined? :Connectivity
64
+ end
65
+
66
+ def test_has_RazorRisk_Razor_Connectivity_Razor3_module
67
+
68
+ assert RazorRisk::Razor::Connectivity.const_defined? :Razor3
69
+ end
70
+
71
+ def test_has_HeaderMaker_class
72
+
73
+ assert RazorRisk::Razor::Connectivity::Razor3.const_defined? :HeaderMaker
74
+ end
75
+
76
+ def test_HeaderMaker_is_a_class
77
+
78
+ assert_kind_of ::Class, ::RazorRisk::Razor::Connectivity::Razor3::HeaderMaker
79
+ end
80
+ end
81
+
82
+
83
+ class Test_HeaderMaker_class_methods < Test::Unit::TestCase
84
+
85
+ include ::RazorRisk::Razor::Connectivity::Razor3
86
+
87
+ include ::Xqsr3::XML::Utilities::Compare
88
+
89
+ private
90
+ def default_attributes_
91
+
92
+ <<END_OF_input
93
+ async="false"
94
+ replicate="true"
95
+ END_OF_input
96
+ end
97
+ public
98
+
99
+ def test_request_option_is_deprecated
100
+
101
+ assert_raise_with_message(::ArgumentError, /option.*request.*no longer supported/) { HeaderMaker.prepare_inbound_header 'the-environment', request: nil }
102
+ end
103
+
104
+ def test_unrecognised_options
105
+
106
+ some_invalid_options = [
107
+
108
+ :blah_blah,
109
+ :'blah blah',
110
+ :responseMode,
111
+ ]
112
+
113
+ some_invalid_options.each do |io|
114
+
115
+ assert_raise_with_message(::ArgumentError, /option.*#{io}.*not recognised/) { HeaderMaker.prepare_inbound_header 'the-environment', **{ io => nil } }
116
+ end
117
+ end
118
+
119
+ def test_prepare_inbound_header_with_riskQ_as_String_1
120
+
121
+ body = nil
122
+
123
+ input_text = <<END_OF_input
124
+ <?xml version="1.0" encoding="utf-8"?>
125
+ <riskQ
126
+ #{default_attributes_}
127
+ caller="the-caller"
128
+ environment="the-environment"
129
+ request="theRequest"
130
+ responseMode="binary"
131
+ server="the-server"
132
+ doDiffs="true"
133
+ />
134
+ END_OF_input
135
+
136
+ options = {}
137
+ options.merge! return_type: :string, request_type: :riskQ
138
+ options.merge! no_caller_pid: true
139
+ options.merge! no_caller_thread: true
140
+ options.merge! caller: 'the-caller', request_name: 'theRequest', response_mode: :binary, server: 'the-server'
141
+ options.merge! body: body
142
+
143
+ expected = Nokogiri.XML input_text
144
+
145
+
146
+ actual = HeaderMaker.prepare_inbound_header 'the-environment', **options
147
+
148
+ assert_kind_of ::String, actual
149
+
150
+ r = xml_compare expected, actual, normalise_whitespace: true
151
+
152
+ assert r.same?, "#{r.details}"
153
+
154
+
155
+
156
+ maker = HeaderMaker.new 'the-environment', **options
157
+ actual = maker.prepare_inbound_header
158
+
159
+ assert_kind_of ::String, actual
160
+
161
+ r = xml_compare expected, actual, normalise_whitespace: true
162
+
163
+ assert r.same?, "#{r.details}"
164
+ end
165
+
166
+ def test_prepare_inbound_header_with_riskQ_as_String_with_body_1
167
+
168
+ body = "<something>or-other</something>"
169
+
170
+ input_text = <<END_OF_input
171
+ <?xml version="1.0" encoding="utf-8"?>
172
+ <riskQ
173
+ #{default_attributes_}
174
+ caller="the-caller"
175
+ environment="the-environment"
176
+ request="theRequest"
177
+ responseMode="binary"
178
+ server="the-server"
179
+ doDiffs="true"
180
+ >
181
+ <body>
182
+ <something>or-other</something>
183
+ </body>
184
+ </riskQ>
185
+ END_OF_input
186
+
187
+ options = {}
188
+ options.merge! return_type: :string, request_type: :riskQ
189
+ options.merge! no_caller_pid: true
190
+ options.merge! no_caller_thread: true
191
+ options.merge! caller: 'the-caller', request_name: 'theRequest', response_mode: :binary, server: 'the-server'
192
+ options.merge! body: body
193
+
194
+ expected = Nokogiri.XML input_text
195
+
196
+ actual = HeaderMaker.prepare_inbound_header 'the-environment', **options
197
+
198
+ assert_kind_of ::String, actual
199
+
200
+ r = xml_compare expected, actual, normalise_whitespace: true
201
+
202
+ assert r.same?, "#{r.details}"
203
+ end
204
+
205
+ def test_prepare_inbound_header_with_riskQ_as_String_with_body_as_Element
206
+
207
+ body = "<body><something>or-other</something></body>"
208
+
209
+ input_text = <<END_OF_input
210
+ <?xml version="1.0" encoding="utf-8"?>
211
+ <riskQ
212
+ #{default_attributes_}
213
+ caller="the-caller"
214
+ environment="the-environment"
215
+ request="theRequest"
216
+ responseMode="binary"
217
+ server="the-server"
218
+ doDiffs="true"
219
+ >
220
+ <body>
221
+ <something>or-other</something>
222
+ </body>
223
+ </riskQ>
224
+ END_OF_input
225
+
226
+ body = ::Nokogiri.XML(body).children.first
227
+
228
+ options = {}
229
+ options.merge! return_type: :string, request_type: :riskQ
230
+ options.merge! no_caller_pid: true
231
+ options.merge! no_caller_thread: true
232
+ options.merge! caller: 'the-caller', request_name: 'theRequest', response_mode: :binary, server: 'the-server'
233
+ options.merge! body: body
234
+
235
+ expected = Nokogiri.XML input_text
236
+
237
+ actual = HeaderMaker.prepare_inbound_header 'the-environment', **options
238
+
239
+ assert_kind_of ::String, actual
240
+
241
+ r = xml_compare expected, actual, normalise_whitespace: true
242
+
243
+ assert r.same?, "#{r.details}"
244
+ end
245
+
246
+ def test_prepare_inbound_header_with_riskQ_as_XML_1
247
+
248
+ body = nil
249
+
250
+ input_text = <<END_OF_input
251
+ <?xml version="1.0" encoding="utf-8"?>
252
+ <riskQ
253
+ #{default_attributes_}
254
+ caller="the-caller"
255
+ environment="the-environment"
256
+ request="theRequest"
257
+ responseMode="binary"
258
+ server="the-server"
259
+ doDiffs="true"
260
+ />
261
+ END_OF_input
262
+
263
+ options = {}
264
+ options.merge! return_type: :xml, request_type: :riskQ
265
+ options.merge! no_caller_pid: true
266
+ options.merge! no_caller_thread: true
267
+ options.merge! caller: 'the-caller', request_name: 'theRequest', response_mode: :binary, server: 'the-server'
268
+ options.merge! body: body
269
+
270
+ expected = Nokogiri.XML input_text
271
+
272
+ actual = HeaderMaker.prepare_inbound_header 'the-environment', **options
273
+
274
+ assert_kind_of ::Nokogiri::XML::Node, actual
275
+
276
+ r = xml_compare expected, actual, normalise_whitespace: true
277
+
278
+ assert r.same?, "#{r.details}"
279
+ end
280
+
281
+ def test_prepare_inbound_header_with_riskQ_as_StringArray_1
282
+
283
+ body = nil
284
+
285
+ input_text = <<END_OF_input
286
+ <?xml version="1.0" encoding="utf-8"?>
287
+ <riskQ
288
+ #{default_attributes_}
289
+ caller="the-caller"
290
+ environment="the-environment"
291
+ request="theRequest"
292
+ responseMode="binary"
293
+ server="the-server"
294
+ doDiffs="true"
295
+ />
296
+ END_OF_input
297
+
298
+ options = {}
299
+ options.merge! return_type: :string_array, request_type: :riskQ
300
+ options.merge! no_caller_pid: true
301
+ options.merge! no_caller_thread: true
302
+ options.merge! caller: 'the-caller', request_name: 'theRequest', response_mode: :binary, server: 'the-server'
303
+ options.merge! body: body
304
+
305
+ expected = Nokogiri.XML input_text
306
+
307
+ actual = HeaderMaker.prepare_inbound_header 'the-environment', **options
308
+
309
+ assert_kind_of ::Array, actual
310
+ actual_xml_s = "#{actual[0]}#{actual[-1]}"
311
+
312
+ r = xml_compare expected, actual_xml_s, normalise_whitespace: true, validate_params: true
313
+
314
+ assert r.same?, "#{r.details}"
315
+ end
316
+
317
+ def test_prepare_inbound_header_with_razorInbound_as_String_1
318
+
319
+ body = nil
320
+
321
+ input_text = <<END_OF_input
322
+ <?xml version="1.0" encoding="utf-8"?>
323
+ <razorInbound
324
+ #{default_attributes_}
325
+ caller="the-other-caller"
326
+ callerPid="#{Process.pid}"
327
+ environment="the-other-environment"
328
+ request="theOtherRequest"
329
+ responseMode="xml"
330
+ server="the-other-server"
331
+ doDiffs="true"
332
+ />
333
+ END_OF_input
334
+
335
+ options = {}
336
+ options.merge! return_type: :string, request_type: :razorInbound
337
+ options.merge! no_caller_thread: true
338
+ options.merge! caller: 'the-other-caller', request_name: 'theOtherRequest', response_mode: :xml, server: 'the-other-server'
339
+ options.merge! body: body
340
+
341
+ expected = Nokogiri.XML input_text
342
+
343
+ actual = HeaderMaker.prepare_inbound_header 'the-other-environment', **options
344
+
345
+ assert_kind_of ::String, actual
346
+
347
+ r = xml_compare expected, actual, normalise_whitespace: true
348
+
349
+ assert r.same?, "#{r.details}"
350
+ end
351
+
352
+
353
+ # actual samples
354
+
355
+ def test_do_risk_point_trees_first_request_1
356
+
357
+ body = <<END_OF_body
358
+ <riskPointTreeRequest>
359
+ <keyPath>
360
+ <keyElement nodeOffset="1">Customer</keyElement>
361
+ <keyElement nodeOffset="2">ID</keyElement>
362
+ </keyPath>
363
+ <lookupValue>CusA1</lookupValue>
364
+ <relationship>Parent</relationship>
365
+ </riskPointTreeRequest>
366
+ END_OF_body
367
+
368
+ input_text = <<END_OF_input
369
+ <?xml version="1.0" encoding="utf-8"?>
370
+ <riskQ
371
+ #{default_attributes_}
372
+ caller="do_risk_point_trees"
373
+ callerPid="#{Process.pid}"
374
+ environment="rz01"
375
+ request="selectRiskPointTree"
376
+ responseMode="xml"
377
+ server="PortfolioExposureServer"
378
+ doDiffs="true"
379
+ >
380
+ <body>
381
+ <riskPointTreeRequest>
382
+ <keyPath>
383
+ <keyElement nodeOffset="1">Customer</keyElement>
384
+ <keyElement nodeOffset="2">ID</keyElement>
385
+ </keyPath>
386
+ <lookupValue>CusA1</lookupValue>
387
+ <relationship>Parent</relationship>
388
+ </riskPointTreeRequest>
389
+ </body>
390
+ </riskQ>
391
+ END_OF_input
392
+
393
+ options = {}
394
+ options.merge! return_type: :string, request_type: :riskQ
395
+ options.merge! no_caller_thread: true
396
+ options.merge! caller: 'do_risk_point_trees'
397
+ options.merge! request_name: 'selectRiskPointTree', response_mode: :xml, server: 'PortfolioExposureServer'
398
+ options.merge! body: body
399
+
400
+ expected = Nokogiri.XML input_text
401
+
402
+ actual = HeaderMaker.prepare_inbound_header 'rz01', **options
403
+
404
+ assert_kind_of ::String, actual
405
+
406
+ r = xml_compare expected, actual, normalise_whitespace: true
407
+
408
+ assert r.same?, "#{r.details}"
409
+ end
410
+
411
+ def test_body_with_simple_content
412
+
413
+ body = <<END_OF_body
414
+ <nothing/>
415
+ END_OF_body
416
+
417
+ input_text = <<END_OF_input
418
+ <?xml version="1.0" encoding="utf-8"?>
419
+ <riskQ
420
+ #{default_attributes_}
421
+ caller="do_risk_point_trees"
422
+ callerPid="#{Process.pid}"
423
+ environment="rz01"
424
+ request="selectRiskPointTree"
425
+ responseMode="xml"
426
+ server="PortfolioExposureServer"
427
+ doDiffs="true"
428
+ >
429
+ <body>
430
+ <nothing/>
431
+ </body>
432
+ </riskQ>
433
+ END_OF_input
434
+
435
+ options = {}
436
+ options.merge! return_type: :string, request_type: :riskQ
437
+ options.merge! no_caller_thread: true
438
+ options.merge! caller: 'do_risk_point_trees'
439
+ options.merge! request_name: 'selectRiskPointTree', response_mode: :xml, server: 'PortfolioExposureServer'
440
+ options.merge! body: body
441
+
442
+ expected = Nokogiri.XML input_text
443
+
444
+ actual = HeaderMaker.prepare_inbound_header 'rz01', **options
445
+
446
+ assert_kind_of ::String, actual
447
+
448
+ r = xml_compare expected, actual, normalise_whitespace: true
449
+
450
+ assert r.same?, "#{r.details}"
451
+ end
452
+
453
+ def test_body_with_simple_content_and_some_body_attributes
454
+
455
+ body = <<END_OF_body
456
+ <nothing/>
457
+ END_OF_body
458
+
459
+ input_text = <<END_OF_input
460
+ <?xml version="1.0" encoding="utf-8"?>
461
+ <riskQ
462
+ #{default_attributes_}
463
+ caller="do_risk_point_trees"
464
+ callerPid="#{Process.pid}"
465
+ environment="rz01"
466
+ request="selectRiskPointTree"
467
+ responseMode="xml"
468
+ server="PortfolioExposureServer"
469
+ doDiffs="true"
470
+ >
471
+ <body coloured="false" hidden="true">
472
+ <nothing/>
473
+ </body>
474
+ </riskQ>
475
+ END_OF_input
476
+
477
+ options = {}
478
+ options.merge! return_type: :string, request_type: :riskQ
479
+ options.merge! no_caller_thread: true
480
+ options.merge! caller: 'do_risk_point_trees'
481
+ options.merge! request_name: 'selectRiskPointTree', response_mode: :xml, server: 'PortfolioExposureServer'
482
+ options.merge! body: body
483
+ options.merge! body_attributes: { hidden: true, coloured: false }
484
+
485
+ expected = Nokogiri.XML input_text
486
+
487
+ actual = HeaderMaker.prepare_inbound_header 'rz01', **options
488
+
489
+ assert_kind_of ::String, actual
490
+
491
+ r = xml_compare expected, actual, normalise_whitespace: true
492
+
493
+ assert r.same?, "#{r.details}"
494
+ end
495
+
496
+ def test_body_with_empty_content
497
+
498
+ body = ''
499
+
500
+ input_text = <<END_OF_input
501
+ <?xml version="1.0" encoding="utf-8"?>
502
+ <riskQ
503
+ #{default_attributes_}
504
+ caller="do_risk_point_trees"
505
+ callerPid="#{Process.pid}"
506
+ environment="rz01"
507
+ request="selectRiskPointTree"
508
+ responseMode="xml"
509
+ server="PortfolioExposureServer"
510
+ doDiffs="true"
511
+ >
512
+ <body />
513
+ </riskQ>
514
+ END_OF_input
515
+
516
+ options = {}
517
+ options.merge! return_type: :string, request_type: :riskQ
518
+ options.merge! no_caller_thread: true
519
+ options.merge! caller: 'do_risk_point_trees'
520
+ options.merge! request_name: 'selectRiskPointTree', response_mode: :xml, server: 'PortfolioExposureServer'
521
+ options.merge! body: body
522
+
523
+ expected = Nokogiri.XML input_text
524
+
525
+ actual = HeaderMaker.prepare_inbound_header 'rz01', **options
526
+
527
+ assert_kind_of ::String, actual
528
+
529
+ r = xml_compare expected, actual, normalise_whitespace: true
530
+
531
+ assert r.same?, "#{r.details}"
532
+ end
533
+
534
+ def test_body_with_empty_content_with_body_attributes
535
+
536
+ body = ''
537
+
538
+ input_text = <<END_OF_input
539
+ <?xml version="1.0" encoding="utf-8"?>
540
+ <riskQ
541
+ #{default_attributes_}
542
+ caller="do_risk_point_trees"
543
+ callerPid="#{Process.pid}"
544
+ environment="rz01"
545
+ request="selectRiskPointTree"
546
+ responseMode="xml"
547
+ server="PortfolioExposureServer"
548
+ doDiffs="true"
549
+ >
550
+ <body coloured="false" hidden="true" />
551
+ </riskQ>
552
+ END_OF_input
553
+
554
+ options = {}
555
+ options.merge! return_type: :string, request_type: :riskQ
556
+ options.merge! no_caller_thread: true
557
+ options.merge! caller: 'do_risk_point_trees'
558
+ options.merge! request_name: 'selectRiskPointTree', response_mode: :xml, server: 'PortfolioExposureServer'
559
+ options.merge! body: body
560
+ options.merge! body_attributes: { hidden: true, coloured: false }
561
+
562
+ expected = Nokogiri.XML input_text
563
+
564
+ actual = HeaderMaker.prepare_inbound_header 'rz01', **options
565
+
566
+ assert_kind_of ::String, actual
567
+
568
+ r = xml_compare expected, actual, normalise_whitespace: true
569
+
570
+ assert r.same?, "#{r.details}"
571
+ end
572
+
573
+ def test_nil_body
574
+
575
+ body = nil
576
+
577
+ input_text = <<END_OF_input
578
+ <?xml version="1.0" encoding="utf-8"?>
579
+ <riskQ
580
+ #{default_attributes_}
581
+ caller="do_risk_point_trees"
582
+ callerPid="#{Process.pid}"
583
+ environment="rz01"
584
+ request="selectRiskPointTree"
585
+ responseMode="xml"
586
+ server="PortfolioExposureServer"
587
+ doDiffs="true"
588
+ >
589
+ </riskQ>
590
+ END_OF_input
591
+
592
+ options = {}
593
+ options.merge! return_type: :string, request_type: :riskQ
594
+ options.merge! no_caller_thread: true
595
+ options.merge! caller: 'do_risk_point_trees'
596
+ options.merge! request_name: 'selectRiskPointTree', response_mode: :xml, server: 'PortfolioExposureServer'
597
+ options.merge! body: body
598
+
599
+ expected = Nokogiri.XML input_text
600
+
601
+ actual = HeaderMaker.prepare_inbound_header 'rz01', **options
602
+
603
+ assert_kind_of ::String, actual
604
+
605
+ r = xml_compare expected, actual, normalise_whitespace: true
606
+
607
+ assert r.same?, "#{r.details}"
608
+ end
609
+
610
+ def test_nil_body_with_body_attributes
611
+
612
+ body = nil
613
+
614
+ input_text = <<END_OF_input
615
+ <?xml version="1.0" encoding="utf-8"?>
616
+ <riskQ
617
+ #{default_attributes_}
618
+ caller="do_risk_point_trees"
619
+ callerPid="#{Process.pid}"
620
+ environment="rz01"
621
+ request="selectRiskPointTree"
622
+ responseMode="xml"
623
+ server="PortfolioExposureServer"
624
+ doDiffs="true"
625
+ >
626
+ <body coloured="false" hidden="true" />
627
+ </riskQ>
628
+ END_OF_input
629
+
630
+ options = {}
631
+ options.merge! return_type: :string, request_type: :riskQ
632
+ options.merge! no_caller_thread: true
633
+ options.merge! caller: 'do_risk_point_trees'
634
+ options.merge! request_name: 'selectRiskPointTree', response_mode: :xml, server: 'PortfolioExposureServer'
635
+ options.merge! body: body
636
+ options.merge! body_attributes: { hidden: true, coloured: false }
637
+
638
+ expected = Nokogiri.XML input_text
639
+
640
+ actual = HeaderMaker.prepare_inbound_header 'rz01', **options
641
+
642
+ assert_kind_of ::String, actual
643
+
644
+ r = xml_compare expected, actual, normalise_whitespace: true
645
+
646
+ assert r.same?, "#{r.details}"
647
+ end
648
+ end
649
+
650
+ # ############################## end of file ############################# #
651
+
652
+