lutaml-model 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/dependent-repos.json +2 -1
- data/.rubocop_todo.yml +10 -80
- data/lib/lutaml/model/attribute.rb +6 -1
- data/lib/lutaml/model/schema/xml_compiler.rb +3 -1
- data/lib/lutaml/model/type/float.rb +0 -4
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/model/xml_adapter/xml_document.rb +0 -4
- data/lib/lutaml/model/xml_adapter/xml_element.rb +1 -3
- data/spec/address_spec.rb +3 -3
- data/spec/benchmarks/xml_parsing_benchmark_spec.rb +3 -3
- data/spec/lutaml/model/collection_spec.rb +0 -16
- data/spec/lutaml/model/json_adapter_spec.rb +26 -24
- data/spec/lutaml/model/key_value_mapping_spec.rb +1 -13
- data/spec/lutaml/model/schema/json_schema_spec.rb +12 -12
- data/spec/lutaml/model/schema/relaxng_schema_spec.rb +12 -12
- data/spec/lutaml/model/schema/xml_compiler_spec.rb +447 -147
- data/spec/lutaml/model/schema/xsd_schema_spec.rb +12 -12
- data/spec/lutaml/model/schema/yaml_schema_spec.rb +12 -12
- data/spec/lutaml/model/sequence_spec.rb +129 -113
- data/spec/lutaml/model/toml_adapter_spec.rb +27 -25
- data/spec/lutaml/model/transformation_spec.rb +80 -80
- data/spec/lutaml/model/type/boolean_spec.rb +4 -10
- data/spec/lutaml/model/type/decimal_spec.rb +3 -3
- data/spec/lutaml/model/type/hash_spec.rb +39 -26
- data/spec/lutaml/model/type/integer_spec.rb +2 -2
- data/spec/lutaml/model/type/time_without_date_spec.rb +0 -6
- data/spec/lutaml/model/type_spec.rb +6 -26
- data/spec/lutaml/model/utils_spec.rb +25 -30
- data/spec/lutaml/model/validation_spec.rb +9 -6
- data/spec/lutaml/model/xml_adapter/oga_adapter_spec.rb +2 -2
- data/spec/lutaml/model/xml_adapter/ox_adapter_spec.rb +2 -2
- data/spec/lutaml/model/xml_adapter/xml_namespace_spec.rb +280 -281
- data/spec/lutaml/model/xml_adapter_spec.rb +128 -120
- data/spec/lutaml/model/xml_mapping_spec.rb +23 -16
- data/spec/person_spec.rb +6 -16
- metadata +2 -2
@@ -4,366 +4,365 @@ require "lutaml/model/xml_adapter/ox_adapter"
|
|
4
4
|
require "lutaml/model/xml_adapter/oga_adapter"
|
5
5
|
require "lutaml/model"
|
6
6
|
|
7
|
-
RSpec.
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
RSpec.describe "XmlNamespace" do
|
8
|
+
shared_context "with XML namespace models" do
|
9
|
+
class TestModelNoPrefix < Lutaml::Model::Serializable
|
10
|
+
attribute :name, :string
|
11
|
+
|
12
|
+
xml do
|
13
|
+
root "test"
|
14
|
+
namespace "http://example.com/test", "test"
|
15
|
+
map_element "name", to: :name
|
16
|
+
end
|
15
17
|
end
|
16
|
-
end
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
class TestModelWithPrefix < Lutaml::Model::Serializable
|
20
|
+
attribute :name, :string
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
xml do
|
23
|
+
root "test"
|
24
|
+
namespace "http://example.com/test", "test"
|
25
|
+
map_element "name", to: :name
|
26
|
+
end
|
25
27
|
end
|
26
|
-
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
class SamplePrefixedNamespacedModel < Lutaml::Model::Serializable
|
30
|
+
attribute :id, :string
|
31
|
+
attribute :lang, :string
|
32
|
+
attribute :name, :string, default: -> { "Anonymous" }
|
33
|
+
attribute :age, :integer, default: -> { 18 }
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
xml do
|
36
|
+
root "SamplePrefixedNamespacedModel"
|
37
|
+
namespace "http://example.com/foo", "foo"
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
map_attribute "id", to: :id
|
40
|
+
map_attribute "lang", to: :lang,
|
41
|
+
prefix: "xml",
|
42
|
+
namespace: "http://example.com/xml"
|
42
43
|
|
43
|
-
|
44
|
-
|
44
|
+
map_element "Name", to: :name, prefix: "bar", namespace: "http://example.com/bar"
|
45
|
+
map_element "Age", to: :age, prefix: "baz", namespace: "http://example.com/baz"
|
46
|
+
end
|
45
47
|
end
|
46
|
-
end
|
47
48
|
|
48
|
-
|
49
|
-
|
49
|
+
class NamespaceNilPrefixedNamespaced < Lutaml::Model::Serializable
|
50
|
+
attribute :namespace_model, SamplePrefixedNamespacedModel
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
xml do
|
53
|
+
root "NamespaceNil"
|
54
|
+
map_element "SamplePrefixedNamespacedModel", to: :namespace_model,
|
55
|
+
namespace: nil,
|
56
|
+
prefix: nil
|
57
|
+
end
|
56
58
|
end
|
57
|
-
end
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
class SampleDefaultNamespacedModel < Lutaml::Model::Serializable
|
61
|
+
attribute :id, :string
|
62
|
+
attribute :lang, :string
|
63
|
+
attribute :name, :string, default: -> { "Anonymous" }
|
64
|
+
attribute :age, :integer, default: -> { 18 }
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
66
|
+
xml do
|
67
|
+
root "SampleDefaultNamespacedModel"
|
68
|
+
namespace "http://example.com/foo"
|
68
69
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
map_attribute "id", to: :id
|
71
|
+
map_attribute "lang", to: :lang,
|
72
|
+
prefix: "xml",
|
73
|
+
namespace: "http://example.com/xml"
|
73
74
|
|
74
|
-
|
75
|
-
|
75
|
+
map_element "Name", to: :name, prefix: "bar", namespace: "http://example.com/bar"
|
76
|
+
map_element "Age", to: :age, prefix: "baz", namespace: "http://example.com/baz"
|
77
|
+
end
|
76
78
|
end
|
77
|
-
end
|
78
79
|
|
79
|
-
|
80
|
-
|
80
|
+
class NamespaceNilDefaultNamespaced < Lutaml::Model::Serializable
|
81
|
+
attribute :namespace_model, SampleDefaultNamespacedModel
|
81
82
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
83
|
+
xml do
|
84
|
+
root "NamespaceNil"
|
85
|
+
map_element "SampleDefaultNamespacedModel", to: :namespace_model,
|
86
|
+
namespace: nil,
|
87
|
+
prefix: nil
|
88
|
+
end
|
87
89
|
end
|
88
|
-
end
|
89
90
|
|
90
|
-
|
91
|
-
|
91
|
+
class Body < Lutaml::Model::Serializable
|
92
|
+
attribute :paragraph, :string
|
92
93
|
|
93
|
-
|
94
|
-
|
94
|
+
xml do
|
95
|
+
map_element "p", to: :paragraph
|
96
|
+
end
|
95
97
|
end
|
96
|
-
end
|
97
98
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
99
|
+
class Element < Lutaml::Model::Serializable
|
100
|
+
attribute :text, :string
|
101
|
+
xml do
|
102
|
+
root "test-element"
|
103
|
+
namespace "http://www.test.com/schemas/test/1.0/", "test"
|
104
|
+
map_content to: :text
|
105
|
+
end
|
104
106
|
end
|
105
|
-
end
|
106
107
|
|
107
|
-
|
108
|
-
|
108
|
+
class Front < Lutaml::Model::Serializable
|
109
|
+
attribute :test_element, Element
|
109
110
|
|
110
|
-
|
111
|
-
|
112
|
-
|
111
|
+
xml do
|
112
|
+
namespace "http://www.test.com/schemas/test/1.0/", "test"
|
113
|
+
map_element "test-element", to: :test_element
|
114
|
+
end
|
113
115
|
end
|
114
|
-
end
|
115
116
|
|
116
|
-
|
117
|
-
|
118
|
-
|
117
|
+
class Article < Lutaml::Model::Serializable
|
118
|
+
attribute :front, Front
|
119
|
+
attribute :body, Body
|
119
120
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
121
|
+
xml do
|
122
|
+
root "article"
|
123
|
+
map_element "front", to: :front, prefix: "test", namespace: "http://www.test.com/schemas/test/1.0/"
|
124
|
+
map_element "body", to: :body
|
125
|
+
end
|
124
126
|
end
|
125
|
-
end
|
126
127
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
128
|
+
class OwnedEnd < Lutaml::Model::Serializable
|
129
|
+
attribute :id, :string
|
130
|
+
attribute :type, :string
|
131
|
+
attribute :uml_type, :string
|
131
132
|
|
132
|
-
|
133
|
-
|
133
|
+
xml do
|
134
|
+
root "ownedEnd"
|
134
135
|
|
135
|
-
|
136
|
-
|
137
|
-
|
136
|
+
map_attribute "id", to: :id, namespace: "http://www.omg.org/spec/XMI/20131001", prefix: "xmi"
|
137
|
+
map_attribute "type", to: :type, namespace: "http://www.omg.org/spec/XMI/20131001", prefix: "xmi"
|
138
|
+
map_attribute "type", to: :uml_type
|
139
|
+
end
|
138
140
|
end
|
139
141
|
end
|
140
|
-
end
|
141
|
-
|
142
|
-
RSpec.shared_examples "XML serialization with namespace" do |model_class, xml_string|
|
143
|
-
it "serializes to XML" do
|
144
|
-
model = model_class.new(name: "Test Name")
|
145
|
-
expect(model.to_xml).to be_equivalent_to(xml_string)
|
146
|
-
end
|
147
|
-
|
148
|
-
it "deserializes from XML" do
|
149
|
-
model = model_class.from_xml(xml_string)
|
150
|
-
expect(model.name).to eq("Test Name")
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
RSpec.shared_examples "an XML namespace parser" do |adapter_class|
|
155
|
-
include_context "XML namespace models"
|
156
142
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
Lutaml::Model::Config.xml_adapter = old_adapter
|
163
|
-
end
|
164
|
-
|
165
|
-
context "with no prefix" do
|
166
|
-
include_examples "XML serialization with namespace",
|
167
|
-
TestModelNoPrefix,
|
168
|
-
'<test xmlns="http://example.com/test"><name>Test Name</name></test>'
|
169
|
-
end
|
143
|
+
shared_examples "XML serialization with namespace" do |model_class, xml_string|
|
144
|
+
it "serializes to XML" do
|
145
|
+
model = model_class.new(name: "Test Name")
|
146
|
+
expect(model.to_xml).to be_equivalent_to(xml_string)
|
147
|
+
end
|
170
148
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
149
|
+
it "deserializes from XML" do
|
150
|
+
model = model_class.from_xml(xml_string)
|
151
|
+
expect(model.name).to eq("Test Name")
|
152
|
+
end
|
175
153
|
end
|
176
154
|
|
177
|
-
|
178
|
-
|
179
|
-
let(:model) { SamplePrefixedNamespacedModel.new(attributes) }
|
155
|
+
shared_examples "an XML namespace parser" do |adapter_class|
|
156
|
+
include_context "with XML namespace models"
|
180
157
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
XML
|
188
|
-
|
189
|
-
expect(model.to_xml).to be_equivalent_to(expected_xml)
|
158
|
+
around do |example|
|
159
|
+
old_adapter = Lutaml::Model::Config.xml_adapter
|
160
|
+
Lutaml::Model::Config.xml_adapter = adapter_class
|
161
|
+
example.run
|
162
|
+
ensure
|
163
|
+
Lutaml::Model::Config.xml_adapter = old_adapter
|
190
164
|
end
|
191
165
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
<baz:Age>30</baz:Age>
|
197
|
-
</foo:SamplePrefixedNamespacedModel>
|
198
|
-
XML
|
199
|
-
|
200
|
-
new_model = SamplePrefixedNamespacedModel.from_xml(xml)
|
201
|
-
expect(new_model.name).to eq("John Doe")
|
202
|
-
expect(new_model.age).to eq(30)
|
166
|
+
context "with no prefix" do
|
167
|
+
include_examples "XML serialization with namespace",
|
168
|
+
TestModelNoPrefix,
|
169
|
+
'<test xmlns="http://example.com/test"><name>Test Name</name></test>'
|
203
170
|
end
|
204
171
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
<baz:Age>30</baz:Age>
|
210
|
-
</foo:SamplePrefixedNamespacedModel>
|
211
|
-
XML
|
212
|
-
|
213
|
-
doc = SamplePrefixedNamespacedModel.from_xml(xml)
|
214
|
-
generated_xml = doc.to_xml
|
215
|
-
expect(generated_xml).to be_equivalent_to(xml)
|
172
|
+
context "with prefix" do
|
173
|
+
include_examples "XML serialization with namespace",
|
174
|
+
TestModelWithPrefix,
|
175
|
+
'<test:test xmlns:test="http://example.com/test"><test:name>Test Name</test:name></test:test>'
|
216
176
|
end
|
217
177
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
178
|
+
context "with prefixed namespace" do
|
179
|
+
let(:attributes) { { name: "John Doe", age: 30 } }
|
180
|
+
let(:model) { SamplePrefixedNamespacedModel.new(attributes) }
|
181
|
+
|
182
|
+
let(:xml) do
|
183
|
+
<<~XML
|
184
|
+
<foo:SamplePrefixedNamespacedModel xmlns:foo="http://example.com/foo" xmlns:bar="http://example.com/bar" xmlns:baz="http://example.com/baz">
|
222
185
|
<bar:Name>John Doe</bar:Name>
|
223
186
|
<baz:Age>30</baz:Age>
|
224
|
-
</SamplePrefixedNamespacedModel>
|
225
|
-
|
226
|
-
|
187
|
+
</foo:SamplePrefixedNamespacedModel>
|
188
|
+
XML
|
189
|
+
end
|
227
190
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
191
|
+
let(:xml_with_lang) do
|
192
|
+
<<~XML
|
193
|
+
<foo:SamplePrefixedNamespacedModel xml:lang="en" xmlns:foo="http://example.com/foo" xmlns:bar="http://example.com/bar" xmlns:baz="http://example.com/baz">
|
194
|
+
<bar:Name>John Doe</bar:Name>
|
195
|
+
<baz:Age>30</baz:Age>
|
196
|
+
</foo:SamplePrefixedNamespacedModel>
|
197
|
+
XML
|
198
|
+
end
|
233
199
|
|
234
|
-
|
235
|
-
|
236
|
-
|
200
|
+
it "serializes to XML" do
|
201
|
+
expect(model.to_xml).to be_equivalent_to(xml)
|
202
|
+
end
|
237
203
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
</SampleDefaultNamespacedModel>
|
244
|
-
XML
|
245
|
-
|
246
|
-
expect(model.to_xml).to be_equivalent_to(expected_xml)
|
247
|
-
end
|
204
|
+
it "deserializes from XML" do
|
205
|
+
new_model = SamplePrefixedNamespacedModel.from_xml(xml)
|
206
|
+
expect(new_model.name).to eq("John Doe")
|
207
|
+
expect(new_model.age).to eq(30)
|
208
|
+
end
|
248
209
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
</SampleDefaultNamespacedModel>
|
255
|
-
XML
|
256
|
-
|
257
|
-
new_model = SampleDefaultNamespacedModel.from_xml(xml)
|
258
|
-
expect(new_model.name).to eq("Jane Smith")
|
259
|
-
expect(new_model.age).to eq(25)
|
260
|
-
end
|
210
|
+
it "round-trips if namespace is set" do
|
211
|
+
doc = SamplePrefixedNamespacedModel.from_xml(xml_with_lang)
|
212
|
+
generated_xml = doc.to_xml
|
213
|
+
expect(generated_xml).to be_equivalent_to(xml_with_lang)
|
214
|
+
end
|
261
215
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
216
|
+
it "round-trips if namespace is set to nil in parent" do
|
217
|
+
xml = <<~XML
|
218
|
+
<NamespaceNil xmlns:foo="http://example.com/foo" xmlns:bar="http://example.com/bar" xmlns:baz="http://example.com/baz">
|
219
|
+
<SamplePrefixedNamespacedModel xml:lang="en">
|
220
|
+
<bar:Name>John Doe</bar:Name>
|
221
|
+
<baz:Age>30</baz:Age>
|
222
|
+
</SamplePrefixedNamespacedModel>
|
223
|
+
</NamespaceNil>
|
224
|
+
XML
|
225
|
+
|
226
|
+
doc = NamespaceNilPrefixedNamespaced.from_xml(xml)
|
227
|
+
generated_xml = doc.to_xml
|
228
|
+
expect(generated_xml).to be_equivalent_to(xml)
|
229
|
+
end
|
273
230
|
end
|
274
231
|
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
232
|
+
context "with default namespace" do
|
233
|
+
let(:attributes) { { name: "Jane Smith", age: 25 } }
|
234
|
+
let(:model) { SampleDefaultNamespacedModel.new(attributes) }
|
235
|
+
|
236
|
+
it "serializes to XML" do
|
237
|
+
expected_xml = <<~XML
|
238
|
+
<SampleDefaultNamespacedModel xmlns="http://example.com/foo" xmlns:bar="http://example.com/bar" xmlns:baz="http://example.com/baz">
|
279
239
|
<bar:Name>Jane Smith</bar:Name>
|
280
240
|
<baz:Age>25</baz:Age>
|
281
241
|
</SampleDefaultNamespacedModel>
|
282
|
-
|
283
|
-
XML
|
242
|
+
XML
|
284
243
|
|
285
|
-
|
286
|
-
|
287
|
-
expect(generated_xml).to be_equivalent_to(xml)
|
288
|
-
end
|
289
|
-
end
|
244
|
+
expect(model.to_xml).to be_equivalent_to(expected_xml)
|
245
|
+
end
|
290
246
|
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
<body>
|
299
|
-
<p>This is a paragraph</p>
|
300
|
-
</body>
|
301
|
-
</article>
|
302
|
-
XML
|
303
|
-
end
|
247
|
+
it "deserializes from XML" do
|
248
|
+
xml = <<~XML
|
249
|
+
<SampleDefaultNamespacedModel xmlns="http://example.com/foo" xmlns:bar="http://example.com/bar" xmlns:baz="http://example.com/baz">
|
250
|
+
<bar:Name>Jane Smith</bar:Name>
|
251
|
+
<baz:Age>25</baz:Age>
|
252
|
+
</SampleDefaultNamespacedModel>
|
253
|
+
XML
|
304
254
|
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
expect(article.body.paragraph).to eq("This is a paragraph")
|
255
|
+
new_model = SampleDefaultNamespacedModel.from_xml(xml)
|
256
|
+
expect(new_model.name).to eq("Jane Smith")
|
257
|
+
expect(new_model.age).to eq(25)
|
309
258
|
end
|
310
259
|
|
311
|
-
it "round-trips
|
312
|
-
|
313
|
-
|
260
|
+
it "round-trips if namespace is set" do
|
261
|
+
xml = <<~XML
|
262
|
+
<SampleDefaultNamespacedModel xml:lang="en" xmlns="http://example.com/foo" xmlns:bar="http://example.com/bar" xmlns:baz="http://example.com/baz">
|
263
|
+
<bar:Name>Jane Smith</bar:Name>
|
264
|
+
<baz:Age>25</baz:Age>
|
265
|
+
</SampleDefaultNamespacedModel>
|
266
|
+
XML
|
267
|
+
|
268
|
+
doc = SampleDefaultNamespacedModel.from_xml(xml)
|
269
|
+
generated_xml = doc.to_xml
|
270
|
+
expect(generated_xml).to be_equivalent_to(xml)
|
271
|
+
end
|
314
272
|
|
315
|
-
|
273
|
+
it "round-trips if namespace is set to nil in parent" do
|
274
|
+
xml = <<~XML
|
275
|
+
<NamespaceNil xmlns:bar="http://example.com/bar" xmlns:baz="http://example.com/baz">
|
276
|
+
<SampleDefaultNamespacedModel xml:lang="en">
|
277
|
+
<bar:Name>Jane Smith</bar:Name>
|
278
|
+
<baz:Age>25</baz:Age>
|
279
|
+
</SampleDefaultNamespacedModel>
|
280
|
+
</NamespaceNil>
|
281
|
+
XML
|
282
|
+
|
283
|
+
doc = NamespaceNilDefaultNamespaced.from_xml(xml)
|
284
|
+
generated_xml = doc.to_xml
|
285
|
+
expect(generated_xml).to be_equivalent_to(xml)
|
316
286
|
end
|
317
287
|
end
|
318
|
-
end
|
319
288
|
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
289
|
+
context "when custom namespace is used" do
|
290
|
+
let(:xml_input) do
|
291
|
+
<<~XML
|
292
|
+
<article xmlns:test="http://www.test.com/schemas/test/1.0/">
|
293
|
+
<test:front>
|
294
|
+
<test:test-element>Text Here</test:test-element>
|
295
|
+
</test:front>
|
296
|
+
<body>
|
297
|
+
<p>This is a paragraph</p>
|
298
|
+
</body>
|
299
|
+
</article>
|
300
|
+
XML
|
301
|
+
end
|
329
302
|
|
330
|
-
|
331
|
-
|
332
|
-
|
303
|
+
describe "XML serialization" do
|
304
|
+
it "correctly deserializes from XML" do
|
305
|
+
article = Article.from_xml(xml_input)
|
306
|
+
expect(article.body.paragraph).to eq("This is a paragraph")
|
307
|
+
end
|
333
308
|
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
end
|
309
|
+
it "round-trips XML" do
|
310
|
+
article = Article.from_xml(xml_input)
|
311
|
+
output_xml = article.to_xml(pretty: true)
|
338
312
|
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
uml_type: "test",
|
344
|
-
)
|
313
|
+
expect(output_xml).to be_equivalent_to(xml_input)
|
314
|
+
end
|
315
|
+
end
|
316
|
+
end
|
345
317
|
|
346
|
-
|
318
|
+
context "when two attributes have same name but different prefix" do
|
319
|
+
let(:xml_input) do
|
320
|
+
<<~XML
|
321
|
+
<ownedEnd xmlns:xmi="http://www.omg.org/spec/XMI/20131001"
|
322
|
+
xmi:type="xmi_type"
|
323
|
+
xmi:id="my_id"
|
324
|
+
type="test" />
|
325
|
+
XML
|
347
326
|
end
|
348
327
|
|
349
|
-
|
350
|
-
|
351
|
-
|
328
|
+
describe "XML serialization" do
|
329
|
+
it "correctly deserializes from XML" do
|
330
|
+
owned_end = OwnedEnd.from_xml(xml_input)
|
352
331
|
|
353
|
-
|
332
|
+
expect(owned_end.id).to eq("my_id")
|
333
|
+
expect(owned_end.type).to eq("xmi_type")
|
334
|
+
expect(owned_end.uml_type).to eq("test")
|
335
|
+
end
|
336
|
+
|
337
|
+
it "correctly serializes to XML" do
|
338
|
+
owned_end = OwnedEnd.new(
|
339
|
+
id: "my_id",
|
340
|
+
type: "xmi_type",
|
341
|
+
uml_type: "test",
|
342
|
+
)
|
343
|
+
|
344
|
+
expect(owned_end.to_xml).to be_equivalent_to(xml_input)
|
345
|
+
end
|
346
|
+
|
347
|
+
it "round-trips XML" do
|
348
|
+
owned_end = OwnedEnd.from_xml(xml_input)
|
349
|
+
output_xml = owned_end.to_xml
|
350
|
+
|
351
|
+
expect(output_xml).to be_equivalent_to(xml_input)
|
352
|
+
end
|
354
353
|
end
|
355
354
|
end
|
356
355
|
end
|
357
|
-
end
|
358
356
|
|
359
|
-
|
360
|
-
|
361
|
-
end
|
357
|
+
describe Lutaml::Model::XmlAdapter::NokogiriAdapter do
|
358
|
+
it_behaves_like "an XML namespace parser", described_class
|
359
|
+
end
|
362
360
|
|
363
|
-
|
364
|
-
|
365
|
-
end
|
361
|
+
describe Lutaml::Model::XmlAdapter::OxAdapter do
|
362
|
+
it_behaves_like "an XML namespace parser", described_class
|
363
|
+
end
|
366
364
|
|
367
|
-
|
368
|
-
|
365
|
+
describe Lutaml::Model::XmlAdapter::OgaAdapter do
|
366
|
+
it_behaves_like "an XML namespace parser", described_class
|
367
|
+
end
|
369
368
|
end
|