google4r 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +5 -0
- data/LICENSE +22 -0
- data/README +75 -0
- data/lib/google4r/checkout.rb +36 -0
- data/lib/google4r/checkout/commands.rb +267 -0
- data/lib/google4r/checkout/frontend.rb +100 -0
- data/lib/google4r/checkout/notifications.rb +533 -0
- data/lib/google4r/checkout/shared.rb +501 -0
- data/lib/google4r/checkout/xml_generation.rb +271 -0
- data/lib/google4r/maps.rb +174 -0
- data/test/checkout/integration/checkout_command_test.rb +103 -0
- data/test/checkout/unit/address_test.rb +131 -0
- data/test/checkout/unit/area_test.rb +41 -0
- data/test/checkout/unit/checkout_command_test.rb +112 -0
- data/test/checkout/unit/checkout_command_xml_generator_test.rb +187 -0
- data/test/checkout/unit/command_test.rb +126 -0
- data/test/checkout/unit/flat_rate_shipping_test.rb +114 -0
- data/test/checkout/unit/frontend_test.rb +63 -0
- data/test/checkout/unit/item_test.rb +159 -0
- data/test/checkout/unit/marketing_preferences_test.rb +65 -0
- data/test/checkout/unit/merchant_code_test.rb +122 -0
- data/test/checkout/unit/new_order_notification_test.rb +115 -0
- data/test/checkout/unit/notification_acknowledgement_test.rb +43 -0
- data/test/checkout/unit/notification_handler_test.rb +93 -0
- data/test/checkout/unit/order_adjustment_test.rb +95 -0
- data/test/checkout/unit/order_state_change_notification_test.rb +159 -0
- data/test/checkout/unit/pickup_shipping_test.rb +70 -0
- data/test/checkout/unit/private_data_parser_test.rb +68 -0
- data/test/checkout/unit/shipping_adjustment_test.rb +100 -0
- data/test/checkout/unit/shipping_method_test.rb +41 -0
- data/test/checkout/unit/shopping_cart_test.rb +146 -0
- data/test/checkout/unit/tax_rule_test.rb +65 -0
- data/test/checkout/unit/tax_table_test.rb +82 -0
- data/test/checkout/unit/us_country_area_test.rb +76 -0
- data/test/checkout/unit/us_state_area_test.rb +70 -0
- data/test/checkout/unit/us_zip_area_test.rb +66 -0
- data/test/maps/geocoder_test.rb +143 -0
- data/var/cacert.pem +7815 -0
- metadata +100 -0
@@ -0,0 +1,65 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/area_test.rb
|
4
|
+
# Author: Manuel Holtgrewe <purestorm at ggnore dot net>
|
5
|
+
# Copyright: (c) 2007 by Manuel Holtgrewe
|
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 'test/checkout/frontend_configuration'
|
31
|
+
|
32
|
+
require 'google4r/checkout'
|
33
|
+
|
34
|
+
# Tests for the TaxRule class.
|
35
|
+
class Google4R::Checkout::TaxRuleTest < 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
|
+
@command = @frontend.create_checkout_command
|
42
|
+
@table = TaxTable.new(false)
|
43
|
+
@rule = @table.create_rule
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_tax_rule_gets_initialized_correctly
|
47
|
+
assert_equal @table, @rule.table
|
48
|
+
assert_nil @rule.area
|
49
|
+
assert_nil @rule.rate
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_tax_rule_behaves_correctly
|
53
|
+
assert_respond_to @rule, :table
|
54
|
+
assert_respond_to @rule, :area
|
55
|
+
assert_respond_to @rule, :rate
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_tax_rule_accessors_work
|
59
|
+
@rule.area = :area
|
60
|
+
assert_equal :area, @rule.area
|
61
|
+
|
62
|
+
@rule.rate = 0.5
|
63
|
+
assert_equal 0.5, @rule.rate
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/area_test.rb
|
4
|
+
# Author: Manuel Holtgrewe <purestorm at ggnore dot net>
|
5
|
+
# Copyright: (c) 2007 by Manuel Holtgrewe
|
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 'test/checkout/frontend_configuration'
|
31
|
+
|
32
|
+
require 'google4r/checkout'
|
33
|
+
|
34
|
+
# Test for the TaxTable class.
|
35
|
+
class Google4R::Checkout::TaxTableTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@table = TaxTable.new(false)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_table_behaves_correctly
|
43
|
+
assert_respond_to @table, :rules
|
44
|
+
assert_respond_to @table, :name
|
45
|
+
assert_respond_to @table, :name=
|
46
|
+
assert_respond_to @table, :standalone
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_initialized_correctly
|
50
|
+
assert_nil @table.name
|
51
|
+
assert_equal [], @table.rules
|
52
|
+
assert_equal false, @table.standalone
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_accessors_work_correctly
|
56
|
+
@table.name = "name"
|
57
|
+
assert_equal "name", @table.name
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_create_rule_works_correctly_with_block
|
61
|
+
the_rule = nil
|
62
|
+
|
63
|
+
res =
|
64
|
+
@table.create_rule do |rule|
|
65
|
+
the_rule = rule
|
66
|
+
assert_kind_of TaxRule, rule
|
67
|
+
end
|
68
|
+
|
69
|
+
assert_equal res, the_rule
|
70
|
+
assert @table.rules.include?(the_rule)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_create_rule_works_correctly_without_block
|
74
|
+
res = nil
|
75
|
+
|
76
|
+
res = @table.create_rule
|
77
|
+
|
78
|
+
assert_kind_of TaxRule, res
|
79
|
+
|
80
|
+
assert @table.rules.include?(res)
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/us_country_area_test.rb
|
4
|
+
# Author: Manuel Holtgrewe <purestorm at ggnore dot net>
|
5
|
+
# Copyright: (c) 2007 by Manuel Holtgrewe
|
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 'test/checkout/frontend_configuration'
|
31
|
+
|
32
|
+
require 'google4r/checkout'
|
33
|
+
|
34
|
+
# Test for the class UsCountryArea.
|
35
|
+
class Google4R::Checkout::UsCountryAreaTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@area = UsCountryArea.new
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_constants_are_defined
|
43
|
+
assert defined?(UsCountryArea::CONTINENTAL_48)
|
44
|
+
assert defined?(UsCountryArea::FULL_50_STATES)
|
45
|
+
assert defined?(UsCountryArea::ALL)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_initialization
|
49
|
+
assert_nil @area.area
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_creator_sets_area
|
53
|
+
area = UsCountryArea.new(UsCountryArea::ALL)
|
54
|
+
assert_equal UsCountryArea::ALL, area.area
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def test_us_country_area_behaves_correctly
|
59
|
+
assert_respond_to @area, :area
|
60
|
+
assert_respond_to @area, :area=
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_us_country_area_area_accessor_works
|
64
|
+
assert_nil @area.area
|
65
|
+
|
66
|
+
[ UsCountryArea::CONTINENTAL_48, UsCountryArea::FULL_50_STATES, UsCountryArea::ALL ].each do |str|
|
67
|
+
@area.area = str
|
68
|
+
assert_equal str, @area.area
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_us_country_area_area_validation_works
|
73
|
+
assert_raises(RuntimeError) { @area.area = 'invalid value' }
|
74
|
+
assert_nil @area.area
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/area_test.rb
|
4
|
+
# Author: Manuel Holtgrewe <purestorm at ggnore dot net>
|
5
|
+
# Copyright: (c) 2007 by Manuel Holtgrewe
|
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 'test/checkout/frontend_configuration'
|
31
|
+
|
32
|
+
require 'google4r/checkout'
|
33
|
+
|
34
|
+
# Test for the class UsStateArea.
|
35
|
+
class Google4R::Checkout::UsStateAreaTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@area = UsStateArea.new
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_initialization
|
43
|
+
assert_nil @area.state
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_creator_sets_state
|
47
|
+
area = UsStateArea.new('CA')
|
48
|
+
assert_equal 'CA', area.state
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_us_state_area_behaves_correctly
|
52
|
+
assert_respond_to @area, :state
|
53
|
+
assert_respond_to @area, :state=
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_us_country_area_area_accessor_works
|
57
|
+
assert_nil @area.state
|
58
|
+
|
59
|
+
@area.state = 'CA'
|
60
|
+
assert_equal 'CA', @area.state
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_us_country_area_area_must_have_the_correct_format
|
64
|
+
assert_raises(RuntimeError) { @area.state = 'ca' }
|
65
|
+
assert_nil @area.state
|
66
|
+
|
67
|
+
assert_raises(RuntimeError) { @area.state = 'CAL' }
|
68
|
+
assert_nil @area.state
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/area_test.rb
|
4
|
+
# Author: Manuel Holtgrewe <purestorm at ggnore dot net>
|
5
|
+
# Copyright: (c) 2007 by Manuel Holtgrewe
|
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 'test/checkout/frontend_configuration'
|
31
|
+
|
32
|
+
require 'google4r/checkout'
|
33
|
+
|
34
|
+
# Test for the class UsZipArea.
|
35
|
+
class Google4R::Checkout::UsZipAreaTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@area = UsZipArea.new
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_initialization
|
43
|
+
assert_nil @area.pattern
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_creator_sets_area
|
47
|
+
area = UsZipArea.new('123*')
|
48
|
+
assert_equal '123*', area.pattern
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_us_zip_area_behaves_correctly
|
52
|
+
# test that the methods and constants are defined correctly
|
53
|
+
assert_respond_to @area, :pattern
|
54
|
+
assert_respond_to @area, :pattern=
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_us_zip_area_pattern_accessor_works
|
58
|
+
assert_nil @area.pattern
|
59
|
+
|
60
|
+
@area.pattern = '12345678'
|
61
|
+
assert_equal '12345678', @area.pattern
|
62
|
+
|
63
|
+
@area.pattern = '12*'
|
64
|
+
assert_equal '12*', @area.pattern
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
# Project: google4r
|
2
|
+
# File: /test/maps/test_geocoder.rb
|
3
|
+
# Author: Manuel Holtgrewe <purestorm at ggnore dot net>
|
4
|
+
# Copyright: (c) 2007 by Manuel Holtgrewe
|
5
|
+
# License: MIT License as follows:
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
8
|
+
# a copy of this software and associated documentation files (the
|
9
|
+
# "Software"), to deal in the Software without restriction, including
|
10
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
11
|
+
# distribute, sublicense, and/or sell copies of the Software, and to permit
|
12
|
+
# persons to whom the Software is furnished to do so, subject to the
|
13
|
+
# following conditions:
|
14
|
+
#
|
15
|
+
# The above copyright notice and this permission notice shall be included
|
16
|
+
# in all copies or substantial portions of the Software.
|
17
|
+
#
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
19
|
+
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
20
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
21
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
22
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
23
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
24
|
+
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
25
|
+
|
26
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
27
|
+
|
28
|
+
require 'google4r/maps'
|
29
|
+
|
30
|
+
require 'test/maps/key'
|
31
|
+
|
32
|
+
# Runs tests for the Google4R::Maps::Geocoder class. You have to provide a file named
|
33
|
+
# "key.rb" in the test directory which defines the constant GOOGLE_MAPS_KEY.
|
34
|
+
# This value will be used as the key for the "real" tests against the Google
|
35
|
+
# servers.
|
36
|
+
class GeocoderTest < Test::Unit::TestCase
|
37
|
+
def setup
|
38
|
+
@test_adress = "Janitell Rd, Colorado Springs, CO"
|
39
|
+
|
40
|
+
@valid_query_result = %q{{"name":"Janitell Rd, Colorado Springs, CO","Status":{"code":200,"request":"geocode"},"Placemark":[{"address":"Janitell Rd, Colorado Springs, CO 80906, USA","AddressDetails":{"Country":{"CountryNameCode":"US","AdministrativeArea":{"AdministrativeAreaName":"CO","SubAdministrativeArea":{"SubAdministrativeAreaName":"El Paso","Locality":{"LocalityName":"Colorado Springs","Thoroughfare":{"ThoroughfareName":"Janitell Rd"},"PostalCode":{"PostalCodeNumber":"80906"}}}}},"Accuracy": 6},"Point":{"coordinates":[-104.790060,38.795330,0]}},{"address":"Janitell Rd, Stratmoor, CO 80906, USA","AddressDetails":{"Country":{"CountryNameCode":"US","AdministrativeArea":{"AdministrativeAreaName":"CO","SubAdministrativeArea":{"SubAdministrativeAreaName":"El Paso","Locality":{"LocalityName":"Stratmoor","Thoroughfare":{"ThoroughfareName":"Janitell Rd"},"PostalCode":{"PostalCodeNumber":"80906"}}}}},"Accuracy": 6},"Point":{"coordinates":[-104.790390,38.789840,0]}},{"address":"Janitell Rd, CO 80906, USA","AddressDetails":{"Country":{"CountryNameCode":"US","AdministrativeArea":{"AdministrativeAreaName":"CO","SubAdministrativeArea":{"SubAdministrativeAreaName":"El Paso","Thoroughfare":{"ThoroughfareName":"Janitell Rd"},"PostalCode":{"PostalCodeNumber":"80906"}}}},"Accuracy": 6},"Point":{"coordinates":[-104.794390,38.803230,0]}}]}}
|
41
|
+
|
42
|
+
@valid_parsed_result =
|
43
|
+
{"Status"=>{"code"=>200, "request"=>"geocode"},
|
44
|
+
"name"=>"Janitell Rd, Colorado Springs, CO",
|
45
|
+
"Placemark"=>
|
46
|
+
[{"AddressDetails"=>
|
47
|
+
{"Country"=>
|
48
|
+
{"AdministrativeArea"=>
|
49
|
+
{"SubAdministrativeArea"=>
|
50
|
+
{"Locality"=>
|
51
|
+
{"LocalityName"=>"Colorado Springs",
|
52
|
+
"Thoroughfare"=>{"ThoroughfareName"=>"Janitell Rd"},
|
53
|
+
"PostalCode"=>{"PostalCodeNumber"=>"80906"}},
|
54
|
+
"SubAdministrativeAreaName"=>"El Paso"},
|
55
|
+
"AdministrativeAreaName"=>"CO"},
|
56
|
+
"CountryNameCode"=>"US"},
|
57
|
+
"Accuracy"=>6},
|
58
|
+
"Point"=>{"coordinates"=>[-104.79006, 38.79533, 0]},
|
59
|
+
"address"=>"Janitell Rd, Colorado Springs, CO 80906, USA"},
|
60
|
+
{"AddressDetails"=>
|
61
|
+
{"Country"=>
|
62
|
+
{"AdministrativeArea"=>
|
63
|
+
{"SubAdministrativeArea"=>
|
64
|
+
{"Locality"=>
|
65
|
+
{"LocalityName"=>"Stratmoor",
|
66
|
+
"Thoroughfare"=>{"ThoroughfareName"=>"Janitell Rd"},
|
67
|
+
"PostalCode"=>{"PostalCodeNumber"=>"80906"}},
|
68
|
+
"SubAdministrativeAreaName"=>"El Paso"},
|
69
|
+
"AdministrativeAreaName"=>"CO"},
|
70
|
+
"CountryNameCode"=>"US"},
|
71
|
+
"Accuracy"=>6},
|
72
|
+
"Point"=>{"coordinates"=>[-104.79039, 38.78984, 0]},
|
73
|
+
"address"=>"Janitell Rd, Stratmoor, CO 80906, USA"},
|
74
|
+
{"AddressDetails"=>
|
75
|
+
{"Country"=>
|
76
|
+
{"AdministrativeArea"=>
|
77
|
+
{"SubAdministrativeArea"=>
|
78
|
+
{"Thoroughfare"=>{"ThoroughfareName"=>"Janitell Rd"},
|
79
|
+
"PostalCode"=>{"PostalCodeNumber"=>"80906"},
|
80
|
+
"SubAdministrativeAreaName"=>"El Paso"},
|
81
|
+
"AdministrativeAreaName"=>"CO"},
|
82
|
+
"CountryNameCode"=>"US"},
|
83
|
+
"Accuracy"=>6},
|
84
|
+
"Point"=>{"coordinates"=>[-104.79439, 38.80323, 0]},
|
85
|
+
"address"=>"Janitell Rd, CO 80906, USA"}]}
|
86
|
+
|
87
|
+
@invalid_key_result = %q{{"name":"Janitell Rd, Colorado Springs, CO","Status":{"code":610,"request":"geocode"}}}
|
88
|
+
end
|
89
|
+
|
90
|
+
def teardown
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_locate_performs_correct_query
|
94
|
+
# required parameters
|
95
|
+
query = 'query'
|
96
|
+
key = 'key'
|
97
|
+
|
98
|
+
# setup stubs & mocks
|
99
|
+
url = URI.escape(Google4R::Maps::Geocoder::GET_URL % [ @test_adress, 'json', key ])
|
100
|
+
fake_response = stub()
|
101
|
+
fake_response.stubs(:body).times(1).with().returns(@valid_query_result)
|
102
|
+
Net::HTTP.stubs(:get_response).returns(fake_response).times(1).with(URI.parse(url))
|
103
|
+
|
104
|
+
# perform query
|
105
|
+
geocoder = Google4R::Maps::Geocoder.new(key)
|
106
|
+
geocoder.query(@test_adress)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_query_without_key_raises_exception
|
110
|
+
coder = Google4R::Maps::Geocoder.new(nil)
|
111
|
+
|
112
|
+
assert_raises(Google4R::Maps::KeyException) { coder.query("") }
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_query_with_invalid_key_raises_exception
|
116
|
+
coder = Google4R::Maps::Geocoder.new("Invalid Google Maps Key")
|
117
|
+
|
118
|
+
assert_raises(Google4R::Maps::KeyException) do
|
119
|
+
coder.query(@test_adress)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# Make sure that querying with a broken network connection works, i.e. Google's server
|
124
|
+
# is not accessible.
|
125
|
+
def test_query_with_broken_network_connection
|
126
|
+
Net::HTTP.stubs(:get_response).raises(Net::HTTPRequestTimeOut)
|
127
|
+
|
128
|
+
coder = Google4R::Maps::Geocoder.new(GOOGLE_MAPS_KEY)
|
129
|
+
|
130
|
+
assert_raises(Google4R::Maps::ConnectionException) do
|
131
|
+
coder.query(@test_adress)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_do_query
|
136
|
+
coder = Google4R::Maps::Geocoder.new(GOOGLE_MAPS_KEY)
|
137
|
+
coder.query @test_adress
|
138
|
+
|
139
|
+
assert_equal 200, coder.last_status_code
|
140
|
+
|
141
|
+
# no assertion, just make sure that querying works
|
142
|
+
end
|
143
|
+
end
|