google-ads-common 0.14.0 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/COPYING +0 -0
- data/ChangeLog +22 -0
- data/README.md +1 -1
- data/lib/ads_common/api.rb +11 -21
- data/lib/ads_common/api_config.rb +10 -38
- data/lib/ads_common/auth/base_handler.rb +0 -0
- data/lib/ads_common/auth/oauth2_handler.rb +4 -0
- data/lib/ads_common/auth/oauth2_service_account_handler.rb +0 -0
- data/lib/ads_common/build/savon_abstract_generator.rb +0 -0
- data/lib/ads_common/build/savon_generator.rb +0 -0
- data/lib/ads_common/build/savon_registry.rb +19 -0
- data/lib/ads_common/build/savon_registry_generator.rb +0 -0
- data/lib/ads_common/build/savon_service_generator.rb +0 -0
- data/lib/ads_common/config.rb +0 -0
- data/lib/ads_common/credential_handler.rb +0 -0
- data/lib/ads_common/env_check.rb +0 -0
- data/lib/ads_common/errors.rb +0 -0
- data/lib/ads_common/http.rb +4 -0
- data/lib/ads_common/parameters_validator.rb +0 -0
- data/lib/ads_common/results_extractor.rb +0 -0
- data/lib/ads_common/savon_headers/base_header_handler.rb +0 -0
- data/lib/ads_common/savon_headers/oauth_header_handler.rb +0 -0
- data/lib/ads_common/savon_service.rb +12 -11
- data/lib/ads_common/utils.rb +1 -2
- data/lib/ads_common/version.rb +1 -1
- metadata +76 -29
- data/test/coverage.rb +0 -33
- data/test/suite_unittests.rb +0 -28
- data/test/test_config.rb +0 -96
- data/test/test_config.yml +0 -11
- data/test/test_credential_handler.rb +0 -125
- data/test/test_env.rb +0 -43
- data/test/test_oauth2_handler.rb +0 -84
- data/test/test_oauth2_service_account_handler.rb +0 -61
- data/test/test_parameters_validator.rb +0 -153
- data/test/test_results_extractor.rb +0 -250
- data/test/test_savon_service.rb +0 -125
- data/test/test_utils.rb +0 -111
@@ -1,153 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Encoding: utf-8
|
3
|
-
#
|
4
|
-
# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
|
5
|
-
#
|
6
|
-
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
15
|
-
# implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
# Tests validator methods.
|
20
|
-
|
21
|
-
require 'test/unit'
|
22
|
-
|
23
|
-
require 'ads_common/errors'
|
24
|
-
require 'ads_common/parameters_validator'
|
25
|
-
|
26
|
-
module AdsCommon
|
27
|
-
class ParametersValidator
|
28
|
-
public :deep_copy, :add_attribute, :array_from_named_list
|
29
|
-
public :check_required_argument_present, :arrayize
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
class TestParametersValidator < Test::Unit::TestCase
|
34
|
-
def setup
|
35
|
-
@validator = AdsCommon::ParametersValidator.new(nil)
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_deep_copy_simple
|
39
|
-
result1 = @validator.deep_copy(42)
|
40
|
-
assert_equal(42, result1)
|
41
|
-
|
42
|
-
result2 = @validator.deep_copy('Hello World')
|
43
|
-
assert_equal('Hello World', result2)
|
44
|
-
|
45
|
-
result3 = @validator.deep_copy(nil)
|
46
|
-
assert_nil(result3)
|
47
|
-
|
48
|
-
result4 = @validator.deep_copy([])
|
49
|
-
assert_equal([], result4)
|
50
|
-
assert_not_same([], result4)
|
51
|
-
|
52
|
-
result5 = @validator.deep_copy({})
|
53
|
-
assert_equal({}, result5)
|
54
|
-
assert_not_same({}, result5)
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_deep_copy_complex
|
58
|
-
data = {:ab => 'ab', :cd => ['cd', 'de', 'ef']}
|
59
|
-
|
60
|
-
result1 = @validator.deep_copy(data)
|
61
|
-
assert_equal(data, result1)
|
62
|
-
assert_not_same(data, result1)
|
63
|
-
|
64
|
-
result2 = @validator.deep_copy(data)
|
65
|
-
assert_equal(result2, result1)
|
66
|
-
assert_not_same(result2, result1)
|
67
|
-
|
68
|
-
result2[:cd] = nil
|
69
|
-
assert_not_equal(data, result2)
|
70
|
-
assert_equal(data, result1)
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_add_attribute
|
74
|
-
node = {}
|
75
|
-
|
76
|
-
key, name, value1, value2, value3 = 'key', 'name', 'Lorem', 'ipsum', 'dolor'
|
77
|
-
|
78
|
-
@validator.add_attribute(node, key, name, value1)
|
79
|
-
assert_kind_of(Hash, node)
|
80
|
-
assert_kind_of(Hash, node[:attributes!])
|
81
|
-
assert_kind_of(Hash, node[:attributes!][key])
|
82
|
-
assert_equal(value1, node[:attributes!][key][name])
|
83
|
-
|
84
|
-
@validator.add_attribute(node, key, name, value2)
|
85
|
-
assert_kind_of(Hash, node)
|
86
|
-
assert_kind_of(Hash, node[:attributes!])
|
87
|
-
assert_kind_of(Hash, node[:attributes!][key])
|
88
|
-
assert_kind_of(Array, node[:attributes!][key][name])
|
89
|
-
assert_equal(value1, node[:attributes!][key][name][0])
|
90
|
-
assert_equal(value2, node[:attributes!][key][name][1])
|
91
|
-
|
92
|
-
@validator.add_attribute(node, key, name, value3)
|
93
|
-
assert_equal(value1, node[:attributes!][key][name][0])
|
94
|
-
assert_equal(value2, node[:attributes!][key][name][1])
|
95
|
-
assert_equal(value3, node[:attributes!][key][name][2])
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_array_from_named_list
|
99
|
-
src = [{:name => 'foo'}, {:name => 'bar', :bar => :baz}, {:name => 'ipsum'}]
|
100
|
-
result = @validator.array_from_named_list(src)
|
101
|
-
assert_equal(['foo', 'bar', 'ipsum'], result)
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_check_required_argument_present
|
105
|
-
field1 = {:min_occurs => 1, :max_occurs => 1,
|
106
|
-
:name => 'field1', :type => 'type1'}
|
107
|
-
assert_raises(AdsCommon::Errors::MissingPropertyError) do
|
108
|
-
@validator.check_required_argument_present(nil, field1)
|
109
|
-
end
|
110
|
-
assert_raises(AdsCommon::Errors::TypeMismatchError) do
|
111
|
-
@validator.check_required_argument_present([], field1)
|
112
|
-
end
|
113
|
-
assert_nothing_raised do
|
114
|
-
@validator.check_required_argument_present({}, field1)
|
115
|
-
@validator.check_required_argument_present('foobar', field1)
|
116
|
-
@validator.check_required_argument_present(42, field1)
|
117
|
-
end
|
118
|
-
|
119
|
-
field2 = {:min_occurs => 0, :max_occurs => :unbounded,
|
120
|
-
:name => 'field2', :type => 'type2'}
|
121
|
-
assert_raises(AdsCommon::Errors::TypeMismatchError) do
|
122
|
-
@validator.check_required_argument_present({}, field2)
|
123
|
-
end
|
124
|
-
assert_nothing_raised do
|
125
|
-
@validator.check_required_argument_present(nil, field2)
|
126
|
-
@validator.check_required_argument_present([], field2)
|
127
|
-
@validator.check_required_argument_present([field1, field2], field2)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_arrayize_empty
|
132
|
-
result1 = @validator.arrayize(nil)
|
133
|
-
assert_instance_of(Array, result1, 'returned object is not an Array')
|
134
|
-
assert_equal(0, result1.size, 'array is not empty')
|
135
|
-
|
136
|
-
result2 = @validator.arrayize([])
|
137
|
-
assert_instance_of(Array, result2, 'returned object is not an Array')
|
138
|
-
assert_equal(0, result2.size, 'array is not empty')
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_arrayize_on_array
|
142
|
-
result1 = @validator.arrayize([nil])
|
143
|
-
assert_instance_of(Array, result1, 'returned object is not an Array')
|
144
|
-
assert_equal(1, result1.size, 'array changed size')
|
145
|
-
assert_equal(nil, result1[0], 'array changed data')
|
146
|
-
|
147
|
-
result2 = @validator.arrayize(['a', 'b'])
|
148
|
-
assert_instance_of(Array, result2, 'returned object is not an Array')
|
149
|
-
assert_equal(2, result2.size, 'array changed size')
|
150
|
-
assert_equal('a', result2[0], 'array changed data')
|
151
|
-
assert_equal('b', result2[1], 'array changed data')
|
152
|
-
end
|
153
|
-
end
|
@@ -1,250 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Encoding: utf-8
|
3
|
-
#
|
4
|
-
# Copyright:: Copyright 2012, Google Inc. All Rights Reserved.
|
5
|
-
#
|
6
|
-
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
15
|
-
# implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
# Tests the array replies from services.
|
20
|
-
|
21
|
-
require 'test/unit'
|
22
|
-
|
23
|
-
require 'ads_common/results_extractor'
|
24
|
-
|
25
|
-
module AdsCommon
|
26
|
-
class ResultsExtractor
|
27
|
-
|
28
|
-
public :check_array_collapse
|
29
|
-
public :normalize_item
|
30
|
-
public :check_key_value_struct
|
31
|
-
public :check_key_value_hash
|
32
|
-
public :convert_key_value_to_hash
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
class StubRegistry
|
37
|
-
def get_type_signature(type_name)
|
38
|
-
if type_name == :SoapResponseHeader
|
39
|
-
return {:fields => []}
|
40
|
-
else
|
41
|
-
return nil
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
class StubResponse
|
47
|
-
attr_accessor :header
|
48
|
-
end
|
49
|
-
|
50
|
-
class TestResultsExtractor < Test::Unit::TestCase
|
51
|
-
|
52
|
-
# Initialize tests.
|
53
|
-
def setup()
|
54
|
-
registry = StubRegistry.new()
|
55
|
-
@extractor = AdsCommon::ResultsExtractor.new(registry)
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_normalize_item_nil()
|
59
|
-
result1 = @extractor.normalize_item(nil, {:type => 'unknown'})
|
60
|
-
assert_equal(nil, result1, 'bad conversion')
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_normalize_item_int()
|
64
|
-
result1 = @extractor.normalize_item(5, {:type => 'int'})
|
65
|
-
assert_kind_of(Integer, result1)
|
66
|
-
assert_equal(5, result1, 'bad conversion')
|
67
|
-
|
68
|
-
result2 = @extractor.normalize_item(2147483648, {:type => 'int'})
|
69
|
-
assert_kind_of(Integer, result2)
|
70
|
-
assert_equal(2147483648, result2, 'bad conversion')
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_normalize_item_string()
|
74
|
-
result1 = @extractor.normalize_item('foobar',
|
75
|
-
{:type => 'string'})
|
76
|
-
assert_kind_of(String, result1)
|
77
|
-
assert_equal('foobar', result1, 'bad conversion')
|
78
|
-
|
79
|
-
result2 = @extractor.normalize_item('', {:type => 'string'})
|
80
|
-
assert_kind_of(String, result2)
|
81
|
-
assert_equal('', result2, 'bad conversion')
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_normalize_item_long()
|
85
|
-
result1 = @extractor.normalize_item(2147483648, {:type => 'long'})
|
86
|
-
assert_kind_of(Integer, result1)
|
87
|
-
assert_equal(2147483648, result1, 'bad conversion')
|
88
|
-
|
89
|
-
result2 = @extractor.normalize_item(-1, {:type => 'long'})
|
90
|
-
assert_kind_of(Integer, result2)
|
91
|
-
assert_equal(-1, result2, 'bad conversion')
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_normalize_item_boolean()
|
95
|
-
result1 = @extractor.normalize_item(true, {:type => 'boolean'})
|
96
|
-
assert_kind_of(TrueClass, result1)
|
97
|
-
|
98
|
-
result2 = @extractor.normalize_item(false, {:type => 'boolean'})
|
99
|
-
assert_kind_of(FalseClass, result2)
|
100
|
-
|
101
|
-
result3 = @extractor.normalize_item('true', {:type => 'boolean'})
|
102
|
-
assert_kind_of(TrueClass, result3)
|
103
|
-
|
104
|
-
result4 = @extractor.normalize_item('false', {:type => 'boolean'})
|
105
|
-
assert_kind_of(FalseClass, result4)
|
106
|
-
|
107
|
-
result5 = @extractor.normalize_item('True', {:type => 'boolean'})
|
108
|
-
assert_kind_of(TrueClass, result5)
|
109
|
-
|
110
|
-
result6 = @extractor.normalize_item('False', {:type => 'boolean'})
|
111
|
-
assert_kind_of(FalseClass, result6)
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_normalize_item_object()
|
115
|
-
result1 = @extractor.normalize_item({:a => 'b'}, {:type => 'StubClass'})
|
116
|
-
assert_equal('b', result1[:a], 'object corrupted')
|
117
|
-
|
118
|
-
result2 = @extractor.normalize_item(@extractor, {:type => 'SavonService'})
|
119
|
-
assert_equal(@extractor.hash, result2.hash, 'object corrupted')
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_normalize_item_double()
|
123
|
-
result1 = @extractor.normalize_item(3.14, {:type => 'double'})
|
124
|
-
assert_kind_of(Float, result1)
|
125
|
-
assert_equal(3.14, result1, 'bad conversion')
|
126
|
-
|
127
|
-
result2 = @extractor.normalize_item('-3.14', {:type => 'double'})
|
128
|
-
assert_kind_of(Float, result2)
|
129
|
-
assert_equal(-3.14, result2, 'bad conversion')
|
130
|
-
|
131
|
-
result3 = @extractor.normalize_item('42', {:type => 'double'})
|
132
|
-
assert_kind_of(Float, result3)
|
133
|
-
assert_equal(42.0, result3, 'bad conversion')
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_check_array_collapse()
|
137
|
-
result1 = @extractor.check_array_collapse(
|
138
|
-
42.0, {:min_occurs => '0', :max_occurs => 1})
|
139
|
-
assert_kind_of(Float, result1)
|
140
|
-
assert_equal(42.0, result1, 'Float is expected for max_occurs 1')
|
141
|
-
|
142
|
-
result2 = @extractor.check_array_collapse(
|
143
|
-
42.0, {:min_occurs => '0', :max_occurs => :unbounded})
|
144
|
-
assert_instance_of(Array, result2)
|
145
|
-
assert_equal(42.0, result2[0])
|
146
|
-
|
147
|
-
result3 = @extractor.check_array_collapse(
|
148
|
-
42.0, {:min_occurs => '0', :max_occurs => 2})
|
149
|
-
assert_instance_of(Array, result3)
|
150
|
-
assert_equal(42.0, result3[0])
|
151
|
-
|
152
|
-
result4 = @extractor.check_array_collapse(
|
153
|
-
42.0, {:min_occurs => '0', :max_occurs => nil})
|
154
|
-
assert_instance_of(Float, result4)
|
155
|
-
assert_equal(42.0, result4, 'Float is expected for nil max_occurs')
|
156
|
-
|
157
|
-
result5 = @extractor.check_array_collapse(
|
158
|
-
[42, -1], {:min_occurs => '0', :max_occurs => :unbounded})
|
159
|
-
assert_instance_of(Array, result5)
|
160
|
-
assert_equal(42, result5[0])
|
161
|
-
assert_equal(-1, result5[1])
|
162
|
-
|
163
|
-
result6 = @extractor.check_array_collapse(
|
164
|
-
{}, {:min_occurs => '0', :max_occurs => 1})
|
165
|
-
assert_equal({}, result6)
|
166
|
-
|
167
|
-
result7 = @extractor.check_array_collapse(
|
168
|
-
{}, {:min_occurs => '0', :max_occurs => :unbounded})
|
169
|
-
assert_equal([{}], result7)
|
170
|
-
end
|
171
|
-
|
172
|
-
def test_check_array_collapse_exception()
|
173
|
-
result1 = @extractor.check_array_collapse(
|
174
|
-
42.0, {:min_occurs => '0', :max_occurs => 2, :type => 'FloatMapEntry'})
|
175
|
-
assert_kind_of(Float, result1)
|
176
|
-
assert_equal(42.0, result1)
|
177
|
-
|
178
|
-
result2 = @extractor.check_array_collapse(
|
179
|
-
42.0, {:min_occurs => '0', :max_occurs => 2, :type => 'MapEntryTest'})
|
180
|
-
assert_kind_of(Array, result2)
|
181
|
-
assert_equal(42.0, result2[0])
|
182
|
-
end
|
183
|
-
|
184
|
-
def test_extract_headers_empty()
|
185
|
-
headers = {}
|
186
|
-
response = StubResponse.new()
|
187
|
-
response.header = {:response_header => headers}
|
188
|
-
result = @extractor.extract_header_data(response)
|
189
|
-
assert_equal(headers, result)
|
190
|
-
assert_not_same(headers, result)
|
191
|
-
end
|
192
|
-
|
193
|
-
def test_extract_headers_passthrough()
|
194
|
-
headers = {:a => 'aa', :b => '42'}
|
195
|
-
response = StubResponse.new()
|
196
|
-
response.header = {:response_header => headers}
|
197
|
-
result = @extractor.extract_header_data(response)
|
198
|
-
assert_equal(headers, result)
|
199
|
-
assert_not_same(headers, result)
|
200
|
-
end
|
201
|
-
|
202
|
-
def test_extract_headers_attrs_removed()
|
203
|
-
headers = {:a => 'aa', :@xmlns => '42'}
|
204
|
-
expected = {:a => 'aa'}
|
205
|
-
response = StubResponse.new()
|
206
|
-
response.header = {:response_header => headers}
|
207
|
-
result = @extractor.extract_header_data(response)
|
208
|
-
assert_equal(expected, result)
|
209
|
-
end
|
210
|
-
|
211
|
-
def test_check_key_value_struct()
|
212
|
-
assert(!@extractor.check_key_value_struct([]))
|
213
|
-
assert(!@extractor.check_key_value_struct({}))
|
214
|
-
|
215
|
-
test1 = [{:key => 'foo', :value => 'bar'}]
|
216
|
-
assert(@extractor.check_key_value_struct(test1))
|
217
|
-
test2 = [{:key => 'foo'}]
|
218
|
-
assert(!@extractor.check_key_value_struct(test2))
|
219
|
-
test3 = [{:key => 'foo', :value => 'bar', :extra => 42}]
|
220
|
-
assert(!@extractor.check_key_value_struct(test3))
|
221
|
-
test4 = [{:key => 'foo', :value => 'bar'}, {:baz => 'bar'}]
|
222
|
-
assert(!@extractor.check_key_value_struct(test4))
|
223
|
-
test5 = [
|
224
|
-
{:key => 'foo', :value => 'bar'},
|
225
|
-
{:key => 'bar', :value => {:bar => 'baz'}}
|
226
|
-
]
|
227
|
-
assert(@extractor.check_key_value_struct(test5))
|
228
|
-
test6 = {:key => 'foo', :value => 'bar'}
|
229
|
-
assert(@extractor.check_key_value_struct(test6))
|
230
|
-
test7 = {:key => 'foo'}
|
231
|
-
assert(!@extractor.check_key_value_struct(test7))
|
232
|
-
test8 = {:value => 'baz', :key => 'foo'}
|
233
|
-
assert(@extractor.check_key_value_struct(test8))
|
234
|
-
end
|
235
|
-
|
236
|
-
def test_convert_key_value_to_hash()
|
237
|
-
result1 = @extractor.convert_key_value_to_hash(
|
238
|
-
[{:key => 'foo', :value => 'bar'}, {:key => 42, :value => 88.2}])
|
239
|
-
assert_kind_of(Hash, result1)
|
240
|
-
assert(result1.include?('foo'))
|
241
|
-
assert(result1.include?(42))
|
242
|
-
assert_equal('bar', result1['foo'])
|
243
|
-
assert_equal(88.2, result1[42])
|
244
|
-
result2 = @extractor.convert_key_value_to_hash(
|
245
|
-
{:key => 'foo', :value => 'bar'})
|
246
|
-
assert_kind_of(Hash, result2)
|
247
|
-
assert_equal(['foo'], result2.keys)
|
248
|
-
assert_equal('bar', result2['foo'])
|
249
|
-
end
|
250
|
-
end
|
data/test/test_savon_service.rb
DELETED
@@ -1,125 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Encoding: utf-8
|
3
|
-
#
|
4
|
-
# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
|
5
|
-
#
|
6
|
-
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
15
|
-
# implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
# Tests the array replies from services.
|
20
|
-
|
21
|
-
require 'test/unit'
|
22
|
-
require 'logger'
|
23
|
-
|
24
|
-
require 'ads_common/config'
|
25
|
-
require 'ads_common/savon_service'
|
26
|
-
|
27
|
-
# SavonService is abstract, defining a child class for the test.
|
28
|
-
class StubService < AdsCommon::SavonService
|
29
|
-
|
30
|
-
public :get_service_registry, :get_module
|
31
|
-
public :format_headers, :sanitize_request, :format_fault
|
32
|
-
public :should_log_summary, :should_log_payloads
|
33
|
-
|
34
|
-
def initialize(namespace, endpoint, version)
|
35
|
-
@logger = Logger.new(STDERR)
|
36
|
-
@config = AdsCommon::Config.new({:library => {:logger => @logger}})
|
37
|
-
super(@config, namespace, endpoint, version)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
class TestSavonService < Test::Unit::TestCase
|
43
|
-
|
44
|
-
TEST_NAMESPACE = 'namespace'
|
45
|
-
TEST_ENDPOINT = 'endpoint'
|
46
|
-
TEST_VERSION = :vVersion
|
47
|
-
|
48
|
-
# Initialize tests.
|
49
|
-
def setup()
|
50
|
-
@stub_service = StubService.new(TEST_NAMESPACE, TEST_ENDPOINT, TEST_VERSION)
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_initialize_abstract()
|
54
|
-
assert_raises(NoMethodError) do
|
55
|
-
AdsCommon::SavonService.new(nil, TEST_NAMESPACE, TEST_ENDPOINT,
|
56
|
-
TEST_VERSION)
|
57
|
-
end
|
58
|
-
assert_nothing_raised do
|
59
|
-
StubService.new(TEST_NAMESPACE, TEST_ENDPOINT, TEST_VERSION)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_get_service_registry_abstract()
|
64
|
-
assert_raises(NoMethodError) { @stub_service.get_service_registry() }
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_get_module_abstract()
|
68
|
-
assert_raises(NoMethodError) { @stub_service.get_module() }
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_format_headers()
|
72
|
-
test1 = {
|
73
|
-
'header1' => 'value1',
|
74
|
-
'header2' => 'value2'
|
75
|
-
}
|
76
|
-
expected1 = "header1: value1, header2: value2"
|
77
|
-
test2 = {
|
78
|
-
'Authorization' => 'Bearer ABCD',
|
79
|
-
'header3' => 'value3'
|
80
|
-
}
|
81
|
-
expected2 = "Authorization: REDACTED, header3: value3"
|
82
|
-
assert_equal(expected1, @stub_service.format_headers(test1))
|
83
|
-
assert_equal(expected2, @stub_service.format_headers(test2))
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_sanitize_request()
|
87
|
-
test1 = "<some_xml><developerToken>ab1cdEF2GH-IJ3KL_mn4OP" +
|
88
|
-
"</developerToken></some_xml>"
|
89
|
-
expected1 = "<some_xml><developerToken>REDACTED</developerToken></some_xml>"
|
90
|
-
test2 = "<xml><element1></element1><element2></element2></xml>"
|
91
|
-
test3 = "<xml><ns1:developerToken>w-x_Y-Z_</ns1:developerToken></xml>"
|
92
|
-
expected3 = "<xml><ns1:developerToken>REDACTED</ns1:developerToken></xml>"
|
93
|
-
assert_equal(expected1, @stub_service.sanitize_request(test1))
|
94
|
-
assert_equal(test2, @stub_service.sanitize_request(test2))
|
95
|
-
assert_equal(expected3, @stub_service.sanitize_request(test3))
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_format_fault()
|
99
|
-
test1 = "fault\nwith\nnewlines\nand\nunicode\n\u2713\n"+
|
100
|
-
"\u3084\u3063\u305F".encode('utf-8')
|
101
|
-
expected1 = "fault with newlines and unicode \u2713 \u3084\u3063\u305F"
|
102
|
-
test2 = "This needs to be more than 16000 characters......." * 1000
|
103
|
-
expected2 = "This needs to be more than 16000 characters......." * 320
|
104
|
-
assert(test2.length > AdsCommon::SavonService::MAX_FAULT_LOG_LENGTH)
|
105
|
-
assert(expected2.length == AdsCommon::SavonService::MAX_FAULT_LOG_LENGTH)
|
106
|
-
assert_equal(expected1, @stub_service.format_fault(test1))
|
107
|
-
assert_equal(expected2, @stub_service.format_fault(test2))
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_log_levels()
|
111
|
-
assert_equal(true, @stub_service.should_log_payloads(Logger::DEBUG, true))
|
112
|
-
assert_equal(true, @stub_service.should_log_payloads(Logger::DEBUG, false))
|
113
|
-
assert_equal(true, @stub_service.should_log_payloads(Logger::INFO, true))
|
114
|
-
assert_equal(false, @stub_service.should_log_payloads(Logger::INFO, false))
|
115
|
-
assert_equal(false, @stub_service.should_log_payloads(Logger::WARN, true))
|
116
|
-
assert_equal(false, @stub_service.should_log_payloads(Logger::WARN, false))
|
117
|
-
|
118
|
-
assert_equal(true, @stub_service.should_log_summary(Logger::INFO, true))
|
119
|
-
assert_equal(true, @stub_service.should_log_summary(Logger::INFO, false))
|
120
|
-
assert_equal(true, @stub_service.should_log_summary(Logger::WARN, true))
|
121
|
-
assert_equal(false, @stub_service.should_log_summary(Logger::WARN, false))
|
122
|
-
assert_equal(false, @stub_service.should_log_summary(Logger::ERROR, true))
|
123
|
-
assert_equal(false, @stub_service.should_log_summary(Logger::ERROR, false))
|
124
|
-
end
|
125
|
-
end
|