razorrisk-cassini-common 0.26.24
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +22 -0
- data/LICENSE +5 -0
- data/README.md +2 -0
- data/Rakefile +102 -0
- data/lib/razor_risk/cassini/applications/microservice.rb +318 -0
- data/lib/razor_risk/cassini/applications/rest_framework/route_verb_dispatcher.rb +120 -0
- data/lib/razor_risk/cassini/applications/rest_framework/verb_handler.rb +117 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/utilities/collection_get_helper.rb +86 -0
- data/lib/razor_risk/cassini/applications/securable_microservice.rb +164 -0
- data/lib/razor_risk/cassini/applications/secured_microservice.rb +63 -0
- data/lib/razor_risk/cassini/applications/unsecured_microservice.rb +77 -0
- data/lib/razor_risk/cassini/authorisation/header_helpers.rb +271 -0
- data/lib/razor_risk/cassini/authorisation/security_model_helpers.rb +93 -0
- data/lib/razor_risk/cassini/authorisation.rb +27 -0
- data/lib/razor_risk/cassini/cli.rb +19 -0
- data/lib/razor_risk/cassini/common/version.rb +44 -0
- data/lib/razor_risk/cassini/common.rb +32 -0
- data/lib/razor_risk/cassini/constants.rb +68 -0
- data/lib/razor_risk/cassini/diagnostics/util_functions.rb +248 -0
- data/lib/razor_risk/cassini/diagnostics/zeroth_include.rb +35 -0
- data/lib/razor_risk/cassini/extensions/libclimate/common_options.rb +267 -0
- data/lib/razor_risk/cassini/extensions/libclimate.rb +26 -0
- data/lib/razor_risk/cassini/header_functions.rb +59 -0
- data/lib/razor_risk/cassini/main.rb +238 -0
- data/lib/razor_risk/cassini/mixin/razor_response_validator.rb +176 -0
- data/lib/razor_risk/cassini/testing/suppress_pantheios_logging.rb +31 -0
- data/lib/razor_risk/cassini/util/conversion_util.rb +176 -0
- data/lib/razor_risk/cassini/util/program_execution_util.rb +379 -0
- data/lib/razor_risk/cassini/util/secrets_util.rb +229 -0
- data/lib/razor_risk/cassini/util/version_util.rb +88 -0
- data/lib/razor_risk/sinatra/helpers/check_auth_helper.rb +209 -0
- data/lib/razor_risk/sinatra/helpers/validate_accept_helper.rb +69 -0
- data/lib/razor_risk/sinatra/helpers/validate_content_type_helper.rb +74 -0
- data/lib/razor_risk/sinatra/helpers/validate_query_parameters_helper.rb +198 -0
- data/test/scratch/cassini/util/convert_XML.rb +54 -0
- data/test/unit/applications/route_verb_adaptors/utilities/tc_collection_get_helper.rb +236 -0
- data/test/unit/applications/tc_verb_handler.rb +130 -0
- data/test/unit/mixin/tc_razor_response_validator.rb +328 -0
- data/test/unit/sinatra/helpers/tc_validate_query_parameters_helper.rb +134 -0
- data/test/unit/tc_authorisation_util.rb +265 -0
- data/test/unit/tc_load_secrets.rb +95 -0
- data/test/unit/util/tc_conversion_util.rb +393 -0
- data/test/unit/util/tc_program_execution_util.rb +462 -0
- metadata +380 -0
@@ -0,0 +1,393 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 3), 'lib')
|
4
|
+
|
5
|
+
require 'simplecov'
|
6
|
+
|
7
|
+
unless $DEBUG
|
8
|
+
|
9
|
+
require 'pantheios/globals'
|
10
|
+
require 'pantheios/services/null_log_service'
|
11
|
+
|
12
|
+
::Pantheios::Globals.INITIAL_SERVICE_CLASSES = [ ::Pantheios::Services::NullLogService ]
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'razor_risk/cassini/util/conversion_util'
|
16
|
+
|
17
|
+
require 'xqsr3/extensions/test/unit'
|
18
|
+
|
19
|
+
require 'test/unit'
|
20
|
+
|
21
|
+
require 'json'
|
22
|
+
|
23
|
+
class Test_ConversionUtil_XML_to_Hash < Test::Unit::TestCase
|
24
|
+
|
25
|
+
include ::RazorRisk::Cassini::Util::ConversionUtil
|
26
|
+
|
27
|
+
def test_XML_to_Hash_invalid_paramerters
|
28
|
+
|
29
|
+
assert_raise(::ArgumentError) { convert_XML_to_Hash }
|
30
|
+
assert_raise(::ArgumentError) { convert_XML_to_Hash nil }
|
31
|
+
assert_raise(::TypeError) { convert_XML_to_Hash 1 }
|
32
|
+
assert_raise(::TypeError) { convert_XML_to_Hash :xml }
|
33
|
+
assert_raise(::TypeError) { convert_XML_to_Hash '', scheme: 'gdata' }
|
34
|
+
assert_raise(::ArgumentError) { convert_XML_to_Hash '', scheme: :json }
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_XML_to_Hash_element_conversion
|
38
|
+
|
39
|
+
xml = '<root/>'
|
40
|
+
expected = { 'root' => [] }
|
41
|
+
assert_equal expected, convert_XML_to_Hash(xml, scheme: :gdata)
|
42
|
+
|
43
|
+
xml = '<root></root>'
|
44
|
+
expected = { 'root' => [] }
|
45
|
+
assert_equal expected, convert_XML_to_Hash(xml, scheme: :gdata)
|
46
|
+
|
47
|
+
xml = '<root><child/></root>'
|
48
|
+
expected = { 'root' => { 'child' => [] } }
|
49
|
+
assert_equal expected, convert_XML_to_Hash(xml, scheme: :gdata)
|
50
|
+
|
51
|
+
xml = '<root><child1/><child2/></root>'
|
52
|
+
expected = { 'root' => { 'child1' => [], 'child2' => [] } }
|
53
|
+
assert_equal expected, convert_XML_to_Hash(xml, scheme: :gdata)
|
54
|
+
|
55
|
+
xml = '<root><child/><child/></root>'
|
56
|
+
expected = { 'root' => { 'child' => [[], [] ] } }
|
57
|
+
assert_equal expected, convert_XML_to_Hash(xml, scheme: :gdata)
|
58
|
+
|
59
|
+
xml = '<root><child><granchild/></child><child/></root>'
|
60
|
+
expected = { 'root' => { 'child' => [ { 'granchild' => [] }, [] ] } }
|
61
|
+
assert_equal expected, convert_XML_to_Hash(xml, scheme: :gdata)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_XML_to_Hash_element_text_conversion
|
65
|
+
|
66
|
+
xml = '<root>abc</root>'
|
67
|
+
expected = { 'root' => { '$t' => 'abc' } }
|
68
|
+
assert_equal expected, convert_XML_to_Hash(xml, scheme: :gdata)
|
69
|
+
|
70
|
+
xml = '<root><child>abc</child></root>'
|
71
|
+
expected = { 'root' => { 'child' => { '$t' => 'abc' } } }
|
72
|
+
assert_equal expected, convert_XML_to_Hash(xml, scheme: :gdata)
|
73
|
+
|
74
|
+
xml = '<root><child1>abc</child1><child2>abc</child2></root>'
|
75
|
+
expected = { 'root' => { 'child1' => { '$t' => 'abc' }, 'child2' => { '$t' => 'abc' } } }
|
76
|
+
assert_equal expected, convert_XML_to_Hash(xml, scheme: :gdata)
|
77
|
+
|
78
|
+
xml = '<root><child>abc</child><child>abc</child></root>'
|
79
|
+
expected = { 'root' => { 'child' => [ { '$t' => 'abc' }, { '$t' => 'abc' } ] } }
|
80
|
+
assert_equal expected, convert_XML_to_Hash(xml, scheme: :gdata)
|
81
|
+
|
82
|
+
xml = '<root><child>abc</child><child/></root>'
|
83
|
+
expected = { 'root' => { 'child' => [ { '$t' => 'abc' }, [ ] ] } }
|
84
|
+
assert_equal expected, convert_XML_to_Hash(xml, scheme: :gdata)
|
85
|
+
|
86
|
+
xml = '<root><child><grandchild>abc</granchild></child></root>'
|
87
|
+
expected = { 'root' => { 'child' => { 'grandchild' => { '$t' => 'abc' } } } }
|
88
|
+
assert_equal expected, convert_XML_to_Hash(xml, scheme: :gdata)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_XML_to_Hash_element_attributes_conversion
|
92
|
+
|
93
|
+
xml = '<root id=\'1\'/>'
|
94
|
+
expected = { 'root' => { 'id' => '1' } }
|
95
|
+
assert_equal expected, convert_XML_to_Hash(xml, scheme: :gdata)
|
96
|
+
|
97
|
+
xml = '<root id=\'1\'><child id=\'2\' type=\'abc\'/></root>'
|
98
|
+
expected = { 'root' => { 'child' => { 'id' => '2', 'type' => 'abc'}, 'id' => '1' } }
|
99
|
+
assert_equal expected, convert_XML_to_Hash(xml, scheme: :gdata)
|
100
|
+
|
101
|
+
xml = '<root id=\'1\'><child2 id=\'2\' type=\'abc\'/><child3 id=\'3\' type=\'def\'/></root>'
|
102
|
+
expected = { 'root' => { 'child2' => { 'id' => '2', 'type' => 'abc'}, 'child3' => { 'id' => '3', 'type' => 'def'}, 'id' => '1' } }
|
103
|
+
assert_equal expected, convert_XML_to_Hash(xml, scheme: :gdata)
|
104
|
+
|
105
|
+
xml = '<root id=\'1\'><child id=\'1\' type=\'abc\'/><child id=\'2\' type=\'abc\'/><child id=\'3\' type=\'def\'/></root>'
|
106
|
+
expected = { 'root' => { 'child' => [ { 'id' => '1', 'type' => 'abc' }, { 'id' => '2', 'type' => 'abc'}, { 'id' => '3', 'type' => 'def'} ], 'id' => '1' } }
|
107
|
+
assert_equal expected, convert_XML_to_Hash(xml, scheme: :gdata)
|
108
|
+
|
109
|
+
xml = '<root id=\'1\'><child id=\'1\' type=\'abc\'/><child id=\'2\' type=\'abc\'/><child1 id=\'3\' type=\'def\'/></root>'
|
110
|
+
expected = { 'root' => { 'child' => [ { 'id' => '1', 'type' => 'abc' }, { 'id' => '2', 'type' => 'abc'} ], 'child1' => { 'id' => '3', 'type' => 'def'}, 'id' => '1' } }
|
111
|
+
assert_equal expected, convert_XML_to_Hash(xml, scheme: :gdata)
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_XML_to_Hash_element_text_and_attributes_conversion
|
115
|
+
|
116
|
+
xml = '<root id=\'1\'>abc</root>'
|
117
|
+
expected = { 'root' => { '$t' => 'abc', 'id' => '1' } }
|
118
|
+
assert_equal expected, convert_XML_to_Hash(xml, scheme: :gdata)
|
119
|
+
|
120
|
+
xml = '<root id=\'1\'><child id=\'2\' type=\'abc\'>xyz</child></root>'
|
121
|
+
expected = { 'root' => { 'child' => { '$t' => 'xyz', 'id' => '2', 'type' => 'abc'}, 'id' => '1' } }
|
122
|
+
assert_equal expected, convert_XML_to_Hash(xml, scheme: :gdata)
|
123
|
+
|
124
|
+
xml = '<root id=\'1\'><child1 id=\'1\' type=\'abc\'>xyz</child><child2 id=\'2\' type=\'abc\'>xyz</child></root>'
|
125
|
+
expected = { 'root' => { 'child1' => { '$t' => 'xyz', 'id' => '1', 'type' => 'abc'}, 'child2' => { '$t' => 'xyz', 'id' => '2', 'type' => 'abc'}, 'id' => '1' } }
|
126
|
+
assert_equal expected, convert_XML_to_Hash(xml, scheme: :gdata)
|
127
|
+
|
128
|
+
xml = '<root id=\'1\'><child id=\'1\' type=\'abc\'>xyz</child><child id=\'2\' type=\'abc\'>xyz</child></root>'
|
129
|
+
expected = { 'root' => { 'child' => [ { '$t' => 'xyz', 'id' => '1', 'type' => 'abc'}, { '$t' => 'xyz', 'id' => '2', 'type' => 'abc'} ], 'id' => '1' } }
|
130
|
+
assert_equal expected, convert_XML_to_Hash(xml, scheme: :gdata)
|
131
|
+
|
132
|
+
xml = '<root id=\'1\'><child id=\'1\' type=\'abc\'>xyz</child><child id=\'2\' type=\'abc\'>xyz</child><child3 id=\'3\' type=\'abc\'>xyz</child></root>'
|
133
|
+
expected = { 'root' => { 'child' => [ { '$t' => 'xyz', 'id' => '1', 'type' => 'abc'}, { '$t' => 'xyz', 'id' => '2', 'type' => 'abc'} ], 'child3' => { '$t' => 'xyz', 'id' => '3', 'type' => 'abc'}, 'id' => '1' } }
|
134
|
+
assert_equal expected, convert_XML_to_Hash(xml, scheme: :gdata)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
class Test_ConversionUtil_XML_to_JSON < Test::Unit::TestCase
|
139
|
+
|
140
|
+
include ::RazorRisk::Cassini::Util::ConversionUtil
|
141
|
+
|
142
|
+
def test_XML_to_JSON_invalid_paramerters
|
143
|
+
|
144
|
+
assert_raise(::ArgumentError) { convert_XML_to_JSON }
|
145
|
+
assert_raise(::ArgumentError) { convert_XML_to_JSON nil }
|
146
|
+
assert_raise(::TypeError) { convert_XML_to_JSON 1 }
|
147
|
+
assert_raise(::TypeError) { convert_XML_to_JSON :xml }
|
148
|
+
assert_raise(::TypeError) { convert_XML_to_JSON '', scheme: 'gdata' }
|
149
|
+
assert_raise(::ArgumentError) { convert_XML_to_JSON '', scheme: :json }
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_XML_to_JSON_element_conversion
|
153
|
+
|
154
|
+
xml = '<root/>'
|
155
|
+
expected = '{ "root": [] }'
|
156
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
157
|
+
|
158
|
+
xml = '<root></root>'
|
159
|
+
expected = '{ "root": [] }'
|
160
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
161
|
+
|
162
|
+
xml = '<root><child/></root>'
|
163
|
+
expected = '{ "root": { "child": [] } }'
|
164
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
165
|
+
|
166
|
+
xml = '<root><child1/><child2/></root>'
|
167
|
+
expected = '{ "root": { "child1": [], "child2": [] } }'
|
168
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
169
|
+
|
170
|
+
xml = '<root><child/><child/></root>'
|
171
|
+
expected = '{ "root": { "child": [ [], [] ] } }'
|
172
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
173
|
+
|
174
|
+
xml = '<root><child><grandchild/></child><child/></root>'
|
175
|
+
expected = '{ "root": { "child": [ { "grandchild": [] }, [] ] } }'
|
176
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_XML_to_JSON_element_with_namespace_conversion
|
180
|
+
|
181
|
+
xml = '<ns:root/>'
|
182
|
+
expected = '{ "ns:root": [] }'
|
183
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_XML_to_JSON_element_text_conversion
|
187
|
+
|
188
|
+
xml = '<root>abc</root>'
|
189
|
+
expected = '{ "root": { "$t": "abc" } }'
|
190
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
191
|
+
|
192
|
+
xml = '<root><child>abc</child></root>'
|
193
|
+
expected = '{ "root": { "child": { "$t": "abc" } } }'
|
194
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
195
|
+
|
196
|
+
xml = '<root><child1>abc</child1><child2>abc</child2></root>'
|
197
|
+
expected = '{ "root": { "child1": { "$t": "abc" }, "child2": { "$t": "abc" } } }'
|
198
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
199
|
+
|
200
|
+
xml = '<root><child>abc</child><child>abc</child></root>'
|
201
|
+
expected = '{ "root": { "child": [ { "$t": "abc" }, { "$t": "abc" } ] } }'
|
202
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
203
|
+
|
204
|
+
xml = '<root><child>abc</child><child/></root>'
|
205
|
+
expected = '{ "root": { "child": [ { "$t": "abc" }, [ ] ] } }'
|
206
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
207
|
+
|
208
|
+
xml = '<root><child><grandchild>abc</granchild></child></root>'
|
209
|
+
expected = '{ "root": { "child": { "grandchild": { "$t": "abc" } } } }'
|
210
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_XML_to_JSON_element_attributes_conversion
|
214
|
+
|
215
|
+
xml = '<root id=\'1\'/>'
|
216
|
+
expected = '{ "root": { "id": "1" } }'
|
217
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
218
|
+
|
219
|
+
xml = '<root id=\'1\'><child id=\'2\' type=\'abc\'/></root>'
|
220
|
+
expected = '{ "root": { "child": { "id": "2", "type": "abc"}, "id": "1" } }'
|
221
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
222
|
+
|
223
|
+
xml = '<root id=\'1\'><child2 id=\'2\' type=\'abc\'/><child3 id=\'3\' type=\'def\'/></root>'
|
224
|
+
expected = '{ "root": { "child2": { "id": "2", "type": "abc"}, "child3": { "id": "3", "type": "def"}, "id": "1" } }'
|
225
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
226
|
+
|
227
|
+
xml = '<root id=\'1\'><child id=\'1\' type=\'abc\'/><child id=\'2\' type=\'abc\'/><child id=\'3\' type=\'def\'/></root>'
|
228
|
+
expected = '{ "root": { "child": [ { "id": "1", "type": "abc" }, { "id": "2", "type": "abc"}, { "id": "3", "type": "def"} ], "id": "1" } }'
|
229
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
230
|
+
|
231
|
+
xml = '<root id=\'1\'><child id=\'1\' type=\'abc\'/><child id=\'2\' type=\'abc\'/><child1 id=\'3\' type=\'def\'/></root>'
|
232
|
+
expected = '{ "root": { "child": [ { "id": "1", "type": "abc" }, { "id": "2", "type": "abc"} ], "child1": { "id": "3", "type": "def"}, "id": "1" } }'
|
233
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_XML_to_JSON_element_namespace_attributes_conversion
|
237
|
+
|
238
|
+
xml = '<root ns=\'1\'/>'
|
239
|
+
expected = '{ "root": [ ] }'
|
240
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
241
|
+
end
|
242
|
+
|
243
|
+
def test_XML_to_JSON_element_text_and_attributes_conversion
|
244
|
+
|
245
|
+
xml = '<root id=\'1\'>abc</root>'
|
246
|
+
expected = '{ "root": { "$t": "abc", "id": "1" } }'
|
247
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
248
|
+
|
249
|
+
xml = '<root id=\'1\'><child id=\'2\' type=\'abc\'>xyz</child></root>'
|
250
|
+
expected = '{ "root": { "child": { "$t": "xyz", "id": "2", "type": "abc"}, "id": "1" } }'
|
251
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
252
|
+
|
253
|
+
xml = '<root id=\'1\'><child1 id=\'1\' type=\'abc\'>xyz</child><child2 id=\'2\' type=\'abc\'>xyz</child></root>'
|
254
|
+
expected = '{ "root": { "child1": { "$t": "xyz", "id": "1", "type": "abc"}, "child2": { "$t": "xyz", "id": "2", "type": "abc"}, "id": "1" } }'
|
255
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
256
|
+
|
257
|
+
xml = '<root id=\'1\'><child id=\'1\' type=\'abc\'>xyz</child><child id=\'2\' type=\'abc\'>xyz</child></root>'
|
258
|
+
expected = '{ "root": { "child": [ { "$t": "xyz", "id": "1", "type": "abc"}, { "$t": "xyz", "id": "2", "type": "abc"} ], "id": "1" } }'
|
259
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
260
|
+
|
261
|
+
xml = '<root id=\'1\'><child id=\'1\' type=\'abc\'>xyz</child><child id=\'2\' type=\'abc\'>xyz</child><child3 id=\'3\' type=\'abc\'>xyz</child></root>'
|
262
|
+
expected = '{ "root": { "child": [ { "$t": "xyz", "id": "1", "type": "abc"}, { "$t": "xyz", "id": "2", "type": "abc"} ], "child3": { "$t": "xyz", "id": "3", "type": "abc"}, "id": "1" } }'
|
263
|
+
assert_equal JSON.unparse(JSON.parse(expected)), convert_XML_to_JSON(xml, scheme: :gdata)
|
264
|
+
end
|
265
|
+
|
266
|
+
def test_XML_to_JSON_accepted_types
|
267
|
+
|
268
|
+
json = convert_XML_to_JSON XML_example, scheme: :gdata
|
269
|
+
assert_equal JSON.unparse(JSON.parse(JSON_example)), json
|
270
|
+
|
271
|
+
json = convert_XML_to_JSON ::Nokogiri.XML(XML_example), scheme: :gdata
|
272
|
+
assert_equal JSON.unparse(JSON.parse(JSON_example)), json
|
273
|
+
|
274
|
+
json = convert_XML_to_JSON(convert_XML_to_Hash(XML_example, scheme: :gdata))
|
275
|
+
assert_equal JSON.unparse(JSON.parse(JSON_example)), json
|
276
|
+
end
|
277
|
+
|
278
|
+
XML_example = <<END_OF_xml
|
279
|
+
<razorOutbound environment="rzr_3_8_8_3351_RELEASE" request="selectTrades" server="CreditRiskServer">
|
280
|
+
<returnCode>ack</returnCode>
|
281
|
+
<requestReceivedTime>2018-09-19 13:46:23.715</requestReceivedTime>
|
282
|
+
<responseSentTime>2018-09-19 13:46:23.774</responseSentTime>
|
283
|
+
<responseReceivedTime>2018-09-19 13:46:23.777</responseReceivedTime>
|
284
|
+
<caller>RazorRequest</caller>
|
285
|
+
<body returnOffset='0' matchedRecordCount='22' returnedRecordCount='22'>
|
286
|
+
<tradeSummary contextId='334'>
|
287
|
+
<dealId>CRD5000001</dealId>
|
288
|
+
<dealDate>2017-10-31</dealDate>
|
289
|
+
<dealType>CUSTOM</dealType>
|
290
|
+
<context id='334' type='Cpty' tradeId='113' dealId='113' creditParty='1881974' internalParty='STU' currency='EUR' productConfig='SingleCDS' options='8'>
|
291
|
+
<attributes>
|
292
|
+
<attribute name='Book' value='TRADING'/>
|
293
|
+
<attribute name='BuySell' value='BUY'/>
|
294
|
+
</attributes>
|
295
|
+
<fields>
|
296
|
+
<field></field>
|
297
|
+
<field>ABC def</field>
|
298
|
+
<field id='5'></field>
|
299
|
+
<field id='6'>ABC def</field>
|
300
|
+
</fields>
|
301
|
+
<an_empty_element/>
|
302
|
+
<a_different_empty_element></a_different_empty_element>
|
303
|
+
</context>
|
304
|
+
</tradeSummary>
|
305
|
+
</body>
|
306
|
+
</razorOutbound>
|
307
|
+
END_OF_xml
|
308
|
+
|
309
|
+
JSON_example = <<END_OF_json
|
310
|
+
{
|
311
|
+
"razorOutbound": {
|
312
|
+
"returnCode": {
|
313
|
+
"$t": "ack"
|
314
|
+
},
|
315
|
+
"requestReceivedTime": {
|
316
|
+
"$t": "2018-09-19 13:46:23.715"
|
317
|
+
},
|
318
|
+
"responseSentTime": {
|
319
|
+
"$t": "2018-09-19 13:46:23.774"
|
320
|
+
},
|
321
|
+
"responseReceivedTime": {
|
322
|
+
"$t": "2018-09-19 13:46:23.777"
|
323
|
+
},
|
324
|
+
"caller": {
|
325
|
+
"$t": "RazorRequest"
|
326
|
+
},
|
327
|
+
"body": {
|
328
|
+
"tradeSummary": {
|
329
|
+
"dealId": {
|
330
|
+
"$t": "CRD5000001"
|
331
|
+
},
|
332
|
+
"dealDate": {
|
333
|
+
"$t": "2017-10-31"
|
334
|
+
},
|
335
|
+
"dealType": {
|
336
|
+
"$t": "CUSTOM"
|
337
|
+
},
|
338
|
+
"context": {
|
339
|
+
"attributes": {
|
340
|
+
"attribute": [
|
341
|
+
{
|
342
|
+
"name": "Book",
|
343
|
+
"value": "TRADING"
|
344
|
+
},
|
345
|
+
{
|
346
|
+
"name": "BuySell",
|
347
|
+
"value": "BUY"
|
348
|
+
}
|
349
|
+
]
|
350
|
+
},
|
351
|
+
"fields": {
|
352
|
+
"field": [
|
353
|
+
[],
|
354
|
+
{
|
355
|
+
"$t": "ABC def"
|
356
|
+
},
|
357
|
+
{
|
358
|
+
"id": "5"
|
359
|
+
},
|
360
|
+
{
|
361
|
+
"$t": "ABC def",
|
362
|
+
"id": "6"
|
363
|
+
}
|
364
|
+
]
|
365
|
+
},
|
366
|
+
"an_empty_element": [ ],
|
367
|
+
"a_different_empty_element": [ ],
|
368
|
+
"id": "334",
|
369
|
+
"type": "Cpty",
|
370
|
+
"tradeId": "113",
|
371
|
+
"dealId": "113",
|
372
|
+
"creditParty": "1881974",
|
373
|
+
"internalParty": "STU",
|
374
|
+
"currency": "EUR",
|
375
|
+
"productConfig": "SingleCDS",
|
376
|
+
"options": "8"
|
377
|
+
},
|
378
|
+
"contextId": "334"
|
379
|
+
},
|
380
|
+
"returnOffset": "0",
|
381
|
+
"matchedRecordCount": "22",
|
382
|
+
"returnedRecordCount": "22"
|
383
|
+
},
|
384
|
+
"environment": "rzr_3_8_8_3351_RELEASE",
|
385
|
+
"request": "selectTrades",
|
386
|
+
"server": "CreditRiskServer"
|
387
|
+
}
|
388
|
+
}
|
389
|
+
END_OF_json
|
390
|
+
end
|
391
|
+
|
392
|
+
|
393
|
+
|