archerfinley-google4r-checkout-1.0.5 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/CHANGES +93 -0
  2. data/LICENSE +22 -0
  3. data/README +58 -0
  4. data/Rakefile +13 -0
  5. data/VERSION +1 -0
  6. data/google4r-checkout-1.0.5-1.0.5.gem +0 -0
  7. data/google4r-checkout-1.0.5.gemspec +174 -0
  8. data/lib/google4r/checkout.rb +34 -0
  9. data/lib/google4r/checkout/commands.rb +567 -0
  10. data/lib/google4r/checkout/frontend.rb +210 -0
  11. data/lib/google4r/checkout/merchant_calculation.rb +321 -0
  12. data/lib/google4r/checkout/notifications.rb +708 -0
  13. data/lib/google4r/checkout/shared.rb +1086 -0
  14. data/lib/google4r/checkout/utils.rb +94 -0
  15. data/lib/google4r/checkout/xml_generation.rb +880 -0
  16. data/test/integration/checkout_command_test.rb +174 -0
  17. data/test/unit/add_merchant_order_number_command_test.rb +70 -0
  18. data/test/unit/add_tracking_data_command_test.rb +75 -0
  19. data/test/unit/address_test.rb +131 -0
  20. data/test/unit/anonymous_address_test.rb +75 -0
  21. data/test/unit/archive_order_command_test.rb +66 -0
  22. data/test/unit/area_test.rb +44 -0
  23. data/test/unit/authorization_amount_notification_test.rb +69 -0
  24. data/test/unit/authorize_order_command_test.rb +66 -0
  25. data/test/unit/backorder_items_command_test.rb +83 -0
  26. data/test/unit/callback_handler_test.rb +83 -0
  27. data/test/unit/cancel_items_command_test.rb +89 -0
  28. data/test/unit/cancel_order_command_test.rb +83 -0
  29. data/test/unit/carrier_calculated_shipping_test.rb +57 -0
  30. data/test/unit/charge_amount_notification_test.rb +64 -0
  31. data/test/unit/charge_order_command_test.rb +77 -0
  32. data/test/unit/chargeback_amount_notification_test.rb +65 -0
  33. data/test/unit/checkout_command_test.rb +125 -0
  34. data/test/unit/checkout_command_xml_generator_test.rb +218 -0
  35. data/test/unit/command_test.rb +116 -0
  36. data/test/unit/deliver_order_command_test.rb +70 -0
  37. data/test/unit/delivery_method_test.rb +42 -0
  38. data/test/unit/digital_content_test.rb +105 -0
  39. data/test/unit/flat_rate_shipping_test.rb +132 -0
  40. data/test/unit/frontend_test.rb +144 -0
  41. data/test/unit/item_info_test.rb +69 -0
  42. data/test/unit/item_test.rb +171 -0
  43. data/test/unit/marketing_preferences_test.rb +65 -0
  44. data/test/unit/merchant_calculated_shipping_test.rb +172 -0
  45. data/test/unit/merchant_calculation_callback_test.rb +137 -0
  46. data/test/unit/merchant_calculation_result_test.rb +78 -0
  47. data/test/unit/merchant_calculation_results_test.rb +178 -0
  48. data/test/unit/merchant_code_result_test.rb +51 -0
  49. data/test/unit/merchant_code_test.rb +122 -0
  50. data/test/unit/new_order_notification_test.rb +115 -0
  51. data/test/unit/notification_acknowledgement_test.rb +67 -0
  52. data/test/unit/notification_handler_test.rb +113 -0
  53. data/test/unit/order_adjustment_test.rb +119 -0
  54. data/test/unit/order_report_command_test.rb +111 -0
  55. data/test/unit/order_state_change_notification_test.rb +158 -0
  56. data/test/unit/pickup_shipping_test.rb +70 -0
  57. data/test/unit/postal_area_test.rb +71 -0
  58. data/test/unit/private_data_parser_test.rb +68 -0
  59. data/test/unit/refund_amount_notification_test.rb +65 -0
  60. data/test/unit/refund_order_command_test.rb +86 -0
  61. data/test/unit/reset_items_shipping_information_command_test.rb +83 -0
  62. data/test/unit/return_items_command_test.rb +83 -0
  63. data/test/unit/risk_information_notification_test.rb +98 -0
  64. data/test/unit/send_buyer_message_command_test.rb +73 -0
  65. data/test/unit/ship_items_command_test.rb +101 -0
  66. data/test/unit/shipping_adjustment_test.rb +100 -0
  67. data/test/unit/shopping_cart_test.rb +146 -0
  68. data/test/unit/tax_rule_test.rb +70 -0
  69. data/test/unit/tax_table_test.rb +82 -0
  70. data/test/unit/tracking_data_test.rb +54 -0
  71. data/test/unit/unarchive_order_command_test.rb +66 -0
  72. data/test/unit/us_country_area_test.rb +76 -0
  73. data/test/unit/us_state_area_test.rb +70 -0
  74. data/test/unit/us_zip_area_test.rb +66 -0
  75. data/test/unit/world_area_test.rb +48 -0
  76. data/var/cacert.pem +7815 -0
  77. metadata +189 -0
@@ -0,0 +1,75 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/anonymous_address_test.rb
4
+ # Author: Tony Chan <api dot htchan at gmail dot com>
5
+ # Copyright: (c) 2007 by Tony Chan
6
+ # License: MIT License as follows:
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining
9
+ # a copy of this software and associated documentation files (the
10
+ # "Software"), to deal in the Software without restriction, including
11
+ # without limitation the rights to use, copy, modify, merge, publish,
12
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
13
+ # persons to whom the Software is furnished to do so, subject to the
14
+ # following conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be included
17
+ # in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
25
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ #++
27
+
28
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
29
+
30
+ require 'google4r/checkout'
31
+
32
+ require 'test/frontend_configuration'
33
+
34
+ # Test for the class Address.
35
+ class Google4R::Checkout::AnonymousAddressTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+
40
+ @xml_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
41
+ <anonymous-address id="739030698069958">
42
+ <country-code>US</country-code>
43
+ <city>Mountain View</city>
44
+ <region>CA</region>
45
+ <postal-code>94043</postal-code>
46
+ </anonymous-address>}
47
+
48
+ end
49
+
50
+ def test_responds_correctly
51
+ address = Address.new
52
+
53
+ [ :address_id, :address_id=,
54
+ :country_code, :country_code=,
55
+ :city, :city=, :region, :region=,
56
+ :postal_code, :postal_code=
57
+ ].each do |symbol|
58
+ assert_respond_to address, symbol
59
+ end
60
+ end
61
+
62
+ def test_creating_anonymous_address
63
+
64
+ document = REXML::Document.new(@xml_str)
65
+
66
+ anonymous_address = AnonymousAddress.create_from_element(document.elements['/anonymous-address'])
67
+
68
+ assert_equal '739030698069958', anonymous_address.address_id
69
+ assert_equal 'US', anonymous_address.country_code
70
+ assert_equal 'Mountain View', anonymous_address.city
71
+ assert_equal 'CA', anonymous_address.region
72
+ assert_equal '94043', anonymous_address.postal_code
73
+
74
+ end
75
+ end
@@ -0,0 +1,66 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/archive_command_test.rb
4
+ # Author: Tony Chan <api.htchan at gmail dot com>
5
+ # Copyright: (c) 2007 by Tony Chan
6
+ # License: MIT License as follows:
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining
9
+ # a copy of this software and associated documentation files (the
10
+ # "Software"), to deal in the Software without restriction, including
11
+ # without limitation the rights to use, copy, modify, merge, publish,
12
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
13
+ # persons to whom the Software is furnished to do so, subject to the
14
+ # following conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be included
17
+ # in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
25
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ #++
27
+
28
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
29
+
30
+ require 'google4r/checkout'
31
+
32
+ require 'test/frontend_configuration'
33
+
34
+ # Tests for the ArchiveOrderCommand class.
35
+ class Google4R::Checkout::ArchiveOrderCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_archive_order_command
41
+
42
+ @command.google_order_number = '841171949013218'
43
+
44
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
45
+ <archive-order xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'/>}
46
+ end
47
+
48
+ def test_behaves_correctly
49
+ [ :google_order_number ].each do |symbol|
50
+ assert_respond_to @command, symbol
51
+ end
52
+ end
53
+
54
+ def test_xml
55
+ assert_strings_equal(@sample_xml, @command.to_xml)
56
+ end
57
+
58
+ def test_accessors
59
+ assert_equal('841171949013218', @command.google_order_number)
60
+ end
61
+
62
+ def test_to_xml_does_not_raise_exception
63
+ assert_nothing_raised { @command.to_xml }
64
+ end
65
+
66
+ end
@@ -0,0 +1,44 @@
1
+ require 'google4r/checkout'
2
+
3
+ require 'test/frontend_configuration'
4
+ #--
5
+ # Project: google_checkout4r
6
+ # File: test/unit/area_test.rb
7
+ # Author: Manuel Holtgrewe <purestorm at ggnore dot net>
8
+ # Copyright: (c) 2007 by Manuel Holtgrewe
9
+ # License: MIT License as follows:
10
+ #
11
+ # Permission is hereby granted, free of charge, to any person obtaining
12
+ # a copy of this software and associated documentation files (the
13
+ # "Software"), to deal in the Software without restriction, including
14
+ # without limitation the rights to use, copy, modify, merge, publish,
15
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
16
+ # persons to whom the Software is furnished to do so, subject to the
17
+ # following conditions:
18
+ #
19
+ # The above copyright notice and this permission notice shall be included
20
+ # in all copies or substantial portions of the Software.
21
+ #
22
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
28
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
+ #++
30
+
31
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
32
+
33
+ require 'google4r/checkout'
34
+
35
+ require 'test/frontend_configuration'
36
+
37
+ # Test for the class Area.
38
+ class Google4R::Checkout::AreaTest < Test::Unit::TestCase
39
+ include Google4R::Checkout
40
+
41
+ def test_instanciating_area_raises_runtime_error
42
+ assert_raises(RuntimeError) { Area.new }
43
+ end
44
+ end
@@ -0,0 +1,69 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/authorization_amount_notification_test.rb
4
+ # Author: Tony Chan <api.htchan AT gmail.com>
5
+ # Copyright: (c) 2007 by Tony Chan
6
+ # License: MIT License as follows:
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining
9
+ # a copy of this software and associated documentation files (the
10
+ # "Software"), to deal in the Software without restriction, including
11
+ # without limitation the rights to use, copy, modify, merge, publish,
12
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
13
+ # persons to whom the Software is furnished to do so, subject to the
14
+ # following conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be included
17
+ # in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
25
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ #++
27
+
28
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
29
+
30
+ require 'google4r/checkout'
31
+ require 'rexml/document'
32
+ require 'test/frontend_configuration'
33
+
34
+ # Test for the class AuthorizationAmountNotification
35
+ class Google4R::Checkout::AuthorizationAmountNotificationTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @frontend.tax_table_factory = TestTaxTableFactory.new
41
+
42
+ @example_xml = %q{
43
+ <?xml version="1.0" encoding="UTF-8"?>
44
+ <authorization-amount-notification xmlns="http://checkout.google.com/schema/2"
45
+ serial-number="bea6bc1b-e1e2-44fe-80ff-2391b25c2510">
46
+ <google-order-number>841171949013218</google-order-number>
47
+ <authorization-amount currency="GBP">226.06</authorization-amount>
48
+ <authorization-expiration-date>2006-03-18T20:25:31</authorization-expiration-date>
49
+ <avs-response>Y</avs-response>
50
+ <cvn-response>Y</cvn-response>
51
+ <timestamp>2006-03-18T20:25:31</timestamp>
52
+ </authorization-amount-notification>
53
+ }
54
+ end
55
+
56
+ def test_create_from_element_works_correctly
57
+ root = REXML::Document.new(@example_xml).root
58
+
59
+ notification = AuthorizationAmountNotification.create_from_element(root, @frontend)
60
+
61
+ assert_equal 'bea6bc1b-e1e2-44fe-80ff-2391b25c2510', notification.serial_number
62
+ assert_equal '841171949013218', notification.google_order_number
63
+ assert_equal Time.parse('2006-03-18T20:25:31'), notification.timestamp
64
+ assert_equal Time.parse('2006-03-18T20:25:31'), notification.authorization_expiration_date
65
+ assert_equal(Money.new(22606, 'GBP'), notification.authorization_amount)
66
+ assert_equal 'Y', notification.avs_response
67
+ assert_equal 'Y', notification.cvn_response
68
+ end
69
+ end
@@ -0,0 +1,66 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/authorize_order_command_test.rb
4
+ # Author: Tony Chan <api.htchan at gmail dot com>
5
+ # Copyright: (c) 2007 by Tony Chan
6
+ # License: MIT License as follows:
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining
9
+ # a copy of this software and associated documentation files (the
10
+ # "Software"), to deal in the Software without restriction, including
11
+ # without limitation the rights to use, copy, modify, merge, publish,
12
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
13
+ # persons to whom the Software is furnished to do so, subject to the
14
+ # following conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be included
17
+ # in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
25
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ #++
27
+
28
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
29
+
30
+ require 'google4r/checkout'
31
+
32
+ require 'test/frontend_configuration'
33
+
34
+ # Tests for the AuthorizeOrderCommand class.
35
+ class Google4R::Checkout::AuthorizeOrderCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_authorize_order_command
41
+
42
+ @command.google_order_number = '841171949013218'
43
+
44
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
45
+ <authorize-order xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'/>}
46
+ end
47
+
48
+ def test_behaves_correctly
49
+ [ :google_order_number ].each do |symbol|
50
+ assert_respond_to @command, symbol
51
+ end
52
+ end
53
+
54
+ def test_xml
55
+ assert_strings_equal(@sample_xml, @command.to_xml)
56
+ end
57
+
58
+ def test_accessors
59
+ assert_equal('841171949013218', @command.google_order_number)
60
+ end
61
+
62
+ def test_to_xml_does_not_raise_exception
63
+ assert_nothing_raised { @command.to_xml }
64
+ end
65
+
66
+ end
@@ -0,0 +1,83 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/backorder_items_command_test.rb
4
+ # Author: Tony Chan <api.htchan at gmail dot com>
5
+ # Copyright: (c) 2007 by Dan Dukeson
6
+ # License: MIT License as follows:
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining
9
+ # a copy of this software and associated documentation files (the
10
+ # "Software"), to deal in the Software without restriction, including
11
+ # without limitation the rights to use, copy, modify, merge, publish,
12
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
13
+ # persons to whom the Software is furnished to do so, subject to the
14
+ # following conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be included
17
+ # in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
25
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ #++
27
+
28
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
29
+
30
+ require 'google4r/checkout'
31
+
32
+ require 'test/frontend_configuration'
33
+
34
+ # Tests for the BackorderItemsCommand class.
35
+ class Google4R::Checkout::BackorderItemsCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_backorder_items_command
41
+
42
+ @command.google_order_number = '841171949013218'
43
+ @command.send_email = true
44
+ @item_info1 = ItemInfo.new('A1')
45
+ @item_info2 = ItemInfo.new('B2')
46
+ @command.item_info_arr = [@item_info1, @item_info2]
47
+
48
+
49
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
50
+ <backorder-items xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
51
+ <item-ids>
52
+ <item-id>
53
+ <merchant-item-id>A1</merchant-item-id>
54
+ </item-id>
55
+ <item-id>
56
+ <merchant-item-id>B2</merchant-item-id>
57
+ </item-id>
58
+ </item-ids>
59
+ <send-email>true</send-email>
60
+ </backorder-items>}
61
+ end
62
+
63
+ def test_behaves_correctly
64
+ [ :google_order_number, :item_info_arr, :send_email,
65
+ :google_order_number=, :item_info_arr=, :send_email= ].each do |symbol|
66
+ assert_respond_to @command, symbol
67
+ end
68
+ end
69
+
70
+ def test_xml_send_email
71
+ assert_strings_equal(@sample_xml, @command.to_xml)
72
+ end
73
+
74
+ def test_accessors
75
+ assert_equal('841171949013218', @command.google_order_number)
76
+ assert @command.send_email
77
+ end
78
+
79
+ def test_to_xml_does_not_raise_exception
80
+ assert_nothing_raised { @command.to_xml }
81
+ end
82
+
83
+ end
@@ -0,0 +1,83 @@
1
+ #--
2
+ # Project: google4r
3
+ # File: test/unit/callback_handler_test.rb
4
+ # Author: Tony Chan <api dot htchan at gmail dot com>
5
+ # Copyright: (c) 2007 by Tony Chan
6
+ # License: MIT License as follows:
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining
9
+ # a copy of this software and associated documentation files (the
10
+ # "Software"), to deal in the Software without restriction, including
11
+ # without limitation the rights to use, copy, modify, merge, publish,
12
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
13
+ # persons to whom the Software is furnished to do so, subject to the
14
+ # following conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be included
17
+ # in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
25
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ #++
27
+
28
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
29
+
30
+ require 'google4r/checkout'
31
+
32
+ require 'test/frontend_configuration'
33
+
34
+ # Test for the class CallbackHandler.
35
+ class Google4R::Checkout::CallbackHandlerTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @frontend.tax_table_factory = TestTaxTableFactory.new
41
+ @callback_handler = @frontend.create_callback_handler
42
+
43
+ @xmls_with_known_tags =
44
+ [
45
+ [
46
+ '<merchant-calculation-callback xmlns="http://checkout.google.com/schema/2" />',
47
+ 'merchant-calculation-callback',
48
+ MerchantCalculationCallback
49
+ ]
50
+ ]
51
+
52
+ @xmls_with_unknown_tags =
53
+ [
54
+ '<unknown-callback/>'
55
+ ]
56
+ end
57
+
58
+ def test_handler_gets_initialized_correctly
59
+ assert_equal @frontend, @callback_handler.frontend
60
+ end
61
+
62
+ def test_returns_correct_callback_class_for_known_callback
63
+ @xmls_with_known_tags.each do |triple|
64
+ xml_str, tag_name, klass = triple
65
+
66
+ expect = klass.stubs(:create_from_element)
67
+ expect.times(1).returns(:foo)
68
+ expect.with { |element, frontend| element.name == tag_name and frontend == @frontend }
69
+
70
+ result = nil
71
+ assert_nothing_raised {
72
+ result = @callback_handler.handle(xml_str)
73
+ }
74
+ assert_equal :foo, result
75
+ end
76
+ end
77
+
78
+ def test_raises_exception_on_unknown_callback
79
+ @xmls_with_unknown_tags.each do |xml_str|
80
+ assert_raises(UnknownCallbackType) { @callback_handler.handle(xml_str) }
81
+ end
82
+ end
83
+ end