schemata-staging 0.0.1.1
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.
- data/lib/schemata/common/error.rb +12 -0
- data/lib/schemata/common/msgbase.rb +260 -0
- data/lib/schemata/common/msgtypebase.rb +122 -0
- data/lib/schemata/common/parsed_msg.rb +43 -0
- data/lib/schemata/helpers/hash_copy.rb +28 -0
- data/lib/schemata/staging.rb +9 -0
- data/lib/schemata/staging/message.rb +13 -0
- data/lib/schemata/staging/message/message_v1.rb +148 -0
- data/lib/schemata/staging/version.rb +5 -0
- data/spec/cloud_controller/cc_bar_spec.rb +140 -0
- data/spec/common/helpers_spec.rb +89 -0
- data/spec/common/parsed_msg_spec.rb +46 -0
- data/spec/component/aux_data_spec.rb +37 -0
- data/spec/component/component_bar_spec.rb +140 -0
- data/spec/component/component_foo_spec.rb +630 -0
- data/spec/component/foo_spec.rb +214 -0
- data/spec/staging/staging_message_spec.rb +186 -0
- data/spec/support/helpers.rb +27 -0
- metadata +153 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'schemata/component/foo'
|
2
|
+
|
3
|
+
describe Schemata::Component::Foo::V14 do
|
4
|
+
describe "#new" do
|
5
|
+
it "should define accessors for aux schema fields" do
|
6
|
+
v14_obj = Schemata::Component::Foo::V14.new
|
7
|
+
v14_obj.aux_data.respond_to?(:foo4).should be_true
|
8
|
+
v14_obj.aux_data.respond_to?(:foo4=).should be_true
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#generate_old_fields" do
|
13
|
+
it "should emit correct fields if the object was constructed with aux_data" do
|
14
|
+
v14_hash = {
|
15
|
+
"foo1" => "hello",
|
16
|
+
"foo3" => [3]
|
17
|
+
}
|
18
|
+
aux_data = { "foo4" => "foo" }
|
19
|
+
v14_obj = Schemata::Component::Foo::V14.new(v14_hash, aux_data)
|
20
|
+
downverted, old_fields = v14_obj.generate_old_fields
|
21
|
+
|
22
|
+
old_fields.keys.should =~ ["foo4"]
|
23
|
+
old_fields["foo4"].should == "foo"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should raise an error if the object was constructed without aux_data" do
|
27
|
+
v14_hash = {
|
28
|
+
"foo1" => "hello",
|
29
|
+
"foo3" => [3]
|
30
|
+
}
|
31
|
+
v14_obj = Schemata::Component::Foo::V14.new(v14_hash)
|
32
|
+
expect {
|
33
|
+
v14_obj.generate_old_fields
|
34
|
+
}.to raise_error(Schemata::DecodeError)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'schemata/component/component'
|
2
|
+
require 'support/helpers'
|
3
|
+
|
4
|
+
describe Schemata::Component do
|
5
|
+
before :each do
|
6
|
+
@v10_msg = '{
|
7
|
+
"min_version": 10,
|
8
|
+
"V10": {
|
9
|
+
"bar1": "first",
|
10
|
+
"bar2": "second"
|
11
|
+
}
|
12
|
+
}'
|
13
|
+
|
14
|
+
@v11_msg = '{
|
15
|
+
"min_version": 10,
|
16
|
+
"V11": {
|
17
|
+
"bar1": 1,
|
18
|
+
"bar3": "third"
|
19
|
+
},
|
20
|
+
"V10": {
|
21
|
+
"bar1": "1",
|
22
|
+
"bar2": "second"
|
23
|
+
}
|
24
|
+
}'
|
25
|
+
|
26
|
+
@v10_hash = {
|
27
|
+
"bar1" => "1",
|
28
|
+
"bar2" => "second"
|
29
|
+
}
|
30
|
+
|
31
|
+
@v11_hash = {
|
32
|
+
"bar1" => 1,
|
33
|
+
"bar3" => "third"
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#decode" do
|
38
|
+
describe "(current version is 10)" do
|
39
|
+
before :each do
|
40
|
+
set_current_version(Schemata::Component::Bar, 10)
|
41
|
+
end
|
42
|
+
|
43
|
+
after :each do
|
44
|
+
reset_version(Schemata::Component::Bar)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should take a v10 msg and create a v10 obj" do
|
48
|
+
msg_obj = Schemata::Component::Bar.decode(@v10_msg)
|
49
|
+
msg_obj.bar1.should == "first"
|
50
|
+
msg_obj.bar2.should == "second"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should take a v11 msg and create a v10 obj" do
|
54
|
+
msg_obj = Schemata::Component::Bar.decode(@v11_msg)
|
55
|
+
msg_obj.bar1.should == "1"
|
56
|
+
msg_obj.bar2.should == "second"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "(current version is 11)" do
|
61
|
+
before :each do
|
62
|
+
set_current_version(Schemata::Component::Bar, 11)
|
63
|
+
end
|
64
|
+
|
65
|
+
after :each do
|
66
|
+
reset_version(Schemata::Component::Bar)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should take a v10 msg and create a v11 obj" do
|
70
|
+
msg_obj = Schemata::Component::Bar.decode(@v10_msg)
|
71
|
+
msg_obj.bar1.should == 5
|
72
|
+
msg_obj.bar3.should == "third"
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should take a v11 msg and create a v11 obj" do
|
76
|
+
msg_obj = Schemata::Component::Bar.decode(@v11_msg)
|
77
|
+
msg_obj.bar1.should == 1
|
78
|
+
msg_obj.bar3.should == "third"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "#encode" do
|
84
|
+
describe "(current version is 10)" do
|
85
|
+
before :each do
|
86
|
+
set_current_version(Schemata::Component::Bar, 10)
|
87
|
+
end
|
88
|
+
|
89
|
+
after :each do
|
90
|
+
reset_version(Schemata::Component::Bar)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should take a v10 obj and encode a json msg" do
|
94
|
+
v10_obj = Schemata::Component::Bar::V10.new(@v10_hash)
|
95
|
+
json_msg = v10_obj.encode
|
96
|
+
returned_hash = Yajl::Parser.parse(json_msg)
|
97
|
+
|
98
|
+
returned_hash.keys.should =~ ['min_version', 'V10']
|
99
|
+
returned_hash['min_version'].should ==
|
100
|
+
@curr_class::MIN_VERSION_ALLOWED
|
101
|
+
|
102
|
+
v10 = returned_hash['V10']
|
103
|
+
v10.each do |k, v|
|
104
|
+
v10[k].should == @v10_hash[k]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "(current version is 11)" do
|
110
|
+
before :each do
|
111
|
+
set_current_version(Schemata::Component::Bar, 11)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should take a v11 obj and encode a json msg" do
|
115
|
+
aux_data = {"bar2" => "second" }
|
116
|
+
v11_obj = Schemata::Component::Bar::V11.new(@v11_hash, aux_data)
|
117
|
+
json_msg = v11_obj.encode
|
118
|
+
returned_hash = Yajl::Parser.parse(json_msg)
|
119
|
+
|
120
|
+
returned_hash.keys.should =~ ['min_version', 'V10', 'V11']
|
121
|
+
returned_hash['min_version'].should ==
|
122
|
+
@curr_class::MIN_VERSION_ALLOWED
|
123
|
+
|
124
|
+
v10 = returned_hash['V10']
|
125
|
+
v10.each do |k, v|
|
126
|
+
v10[k].should == @v10_hash[k]
|
127
|
+
end
|
128
|
+
|
129
|
+
v11 = returned_hash['V11']
|
130
|
+
v11.each do |k, v|
|
131
|
+
v11[k].should == @v11_hash[k]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
after :each do
|
136
|
+
reset_version(Schemata::Component::Bar)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,630 @@
|
|
1
|
+
require 'schemata/component/component'
|
2
|
+
require 'support/helpers'
|
3
|
+
|
4
|
+
describe Schemata::Component do
|
5
|
+
before :each do
|
6
|
+
@v10_msg = '{
|
7
|
+
"min_version": 10,
|
8
|
+
"V10": {
|
9
|
+
"foo1": "hello",
|
10
|
+
"foo2": 1
|
11
|
+
}
|
12
|
+
}'
|
13
|
+
|
14
|
+
@v11_msg = '{
|
15
|
+
"min_version": 10,
|
16
|
+
"V11": {
|
17
|
+
"foo1": "hello",
|
18
|
+
"foo2": 1,
|
19
|
+
"foo3": 1
|
20
|
+
},
|
21
|
+
"V10": {}
|
22
|
+
}'
|
23
|
+
|
24
|
+
@v12_msg = '{
|
25
|
+
"min_version" : 10,
|
26
|
+
"V12": {
|
27
|
+
"foo1": "hello",
|
28
|
+
"foo2": 1,
|
29
|
+
"foo3": [1]
|
30
|
+
},
|
31
|
+
"V11": {
|
32
|
+
"foo3": 1
|
33
|
+
},
|
34
|
+
"V10": {}
|
35
|
+
}'
|
36
|
+
|
37
|
+
@v13_msg = '{
|
38
|
+
"min_version": 13,
|
39
|
+
"V13": {
|
40
|
+
"foo1": "hello",
|
41
|
+
"foo3": [1],
|
42
|
+
"foo4": "foo"
|
43
|
+
}
|
44
|
+
}'
|
45
|
+
|
46
|
+
@v14_msg = '{
|
47
|
+
"min_version": 13,
|
48
|
+
"V14" : {
|
49
|
+
"foo1" : "hello",
|
50
|
+
"foo3" : [1]
|
51
|
+
},
|
52
|
+
"V13" : { "foo4" : "foo" }
|
53
|
+
}'
|
54
|
+
|
55
|
+
@v10_hash = {
|
56
|
+
"foo1" => "hello",
|
57
|
+
"foo2" => 1
|
58
|
+
}
|
59
|
+
|
60
|
+
@v11_hash = {
|
61
|
+
"foo1" => "hello",
|
62
|
+
"foo2" => 1,
|
63
|
+
"foo3" => 1
|
64
|
+
}
|
65
|
+
|
66
|
+
@v12_hash = {
|
67
|
+
"foo1" => "hello",
|
68
|
+
"foo2" => 1,
|
69
|
+
"foo3" => [1]
|
70
|
+
}
|
71
|
+
|
72
|
+
@v13_hash = {
|
73
|
+
"foo1" => "hello",
|
74
|
+
"foo3" => [1],
|
75
|
+
"foo4" => "foo"
|
76
|
+
}
|
77
|
+
|
78
|
+
@v14_hash = {
|
79
|
+
"foo1" => "hello",
|
80
|
+
"foo3" => [1]
|
81
|
+
}
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#decode" do
|
86
|
+
it "should raise an error if the 'min_version' is missing" do
|
87
|
+
msg_hash = {
|
88
|
+
"V10" => {},
|
89
|
+
"V11" => {
|
90
|
+
"foo1" => "foo",
|
91
|
+
"foo2" => 1,
|
92
|
+
"foo3" => 1
|
93
|
+
}
|
94
|
+
}
|
95
|
+
json_msg = Yajl::Encoder.encode msg_hash
|
96
|
+
expect {
|
97
|
+
foo_obj = Schemata::Component::Foo.decode(json_msg)
|
98
|
+
}.to raise_error(Schemata::DecodeError)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should raise an error if the message has no Vxx key" do
|
102
|
+
msg_hash = {
|
103
|
+
"min_version" => 10
|
104
|
+
}
|
105
|
+
json_msg = Yajl::Encoder.encode msg_hash
|
106
|
+
expect {
|
107
|
+
foo_obj = Schemata::Component::Foo.decode(json_msg)
|
108
|
+
}.to raise_error(Schemata::DecodeError)
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "(current version is 10)" do
|
112
|
+
before :each do
|
113
|
+
set_current_version(Schemata::Component::Foo, 10)
|
114
|
+
end
|
115
|
+
|
116
|
+
after :each do
|
117
|
+
reset_version(Schemata::Component::Foo)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should take a v10 message and return a correct Foo::V10 object" do
|
121
|
+
foo_obj = Schemata::Component::Foo.decode(@v10_msg)
|
122
|
+
foo_obj.class.should == Schemata::Component::Foo::V10
|
123
|
+
foo_obj.foo1.should == "hello"
|
124
|
+
foo_obj.foo2.should == 1
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should take a v11 message and return a correct Foo::V10 object" do
|
128
|
+
foo_obj = Schemata::Component::Foo.decode(@v11_msg)
|
129
|
+
foo_obj.class.should == Schemata::Component::Foo::V10
|
130
|
+
foo_obj.foo1.should == "hello"
|
131
|
+
foo_obj.foo2.should == 1
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should take a v12 message and return a correct Foo::V10 object" do
|
135
|
+
foo_obj = Schemata::Component::Foo.decode(@v12_msg)
|
136
|
+
foo_obj.class.should == Schemata::Component::Foo::V10
|
137
|
+
foo_obj.foo1.should == "hello"
|
138
|
+
foo_obj.foo2.should == 1
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should raise an error when a v10 message has an invalid V10 hash" do
|
142
|
+
msg_hash = {
|
143
|
+
"min_version" => 10,
|
144
|
+
"V10" => {
|
145
|
+
"foo1" => "foo",
|
146
|
+
}
|
147
|
+
}
|
148
|
+
json_msg = Yajl::Encoder.encode(msg_hash)
|
149
|
+
expect {
|
150
|
+
foo_obj = Schemata::Component::Foo.decode(json_msg)
|
151
|
+
}.to raise_error(Schemata::DecodeError)
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should raise an error when a v11 message has an invalid union \
|
155
|
+
of V11 and V10 hashes" do
|
156
|
+
msg_hash = {
|
157
|
+
"min_version" => 10,
|
158
|
+
"V10" => {},
|
159
|
+
"V11" => {
|
160
|
+
"foo1" => "foo",
|
161
|
+
"foo2" => "bar",
|
162
|
+
"foo3" => 1
|
163
|
+
}
|
164
|
+
}
|
165
|
+
json_msg = Yajl::Encoder.encode(msg_hash)
|
166
|
+
expect {
|
167
|
+
foo_obj = Schemata::Component::Foo.decode(
|
168
|
+
json_msg)
|
169
|
+
}.to raise_error(Schemata::DecodeError)
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should raise an error when a v12 message has an invalid union \
|
173
|
+
of V10, V11, and V12 hashes" do
|
174
|
+
msg_hash = {
|
175
|
+
"min_version" => 10,
|
176
|
+
"V10" => {},
|
177
|
+
"V11" => {"foo3" => 1},
|
178
|
+
"V12" => {
|
179
|
+
"foo1" => "foo",
|
180
|
+
"foo2" => "bar",
|
181
|
+
"foo3" => [1]
|
182
|
+
}
|
183
|
+
}
|
184
|
+
json_msg = Yajl::Encoder.encode msg_hash
|
185
|
+
expect {
|
186
|
+
foo_obj = Schemata::Component::Foo.decode(json_msg)
|
187
|
+
}.to raise_error(Schemata::DecodeError)
|
188
|
+
|
189
|
+
msg_hash["V11"]["foo2"] = "bar"
|
190
|
+
msg_hash["V12"]["foo2"] = 1
|
191
|
+
json_msg = Yajl::Encoder.encode msg_hash
|
192
|
+
expect {
|
193
|
+
foo_obj = Schemata::Component::Foo.decode(json_msg)
|
194
|
+
}.to raise_error(Schemata::DecodeError)
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should raise an IncompatibleVersionError when it gets a v13 msg" do
|
198
|
+
expect {
|
199
|
+
foo_obj = Schemata::Component::Foo.decode(@v13_msg)
|
200
|
+
}.to raise_error(Schemata::IncompatibleVersionError)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
describe "(current version is 11)" do
|
205
|
+
before :each do
|
206
|
+
set_current_version(Schemata::Component::Foo, 11)
|
207
|
+
end
|
208
|
+
|
209
|
+
after :each do
|
210
|
+
reset_version(Schemata::Component::Foo)
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should take a v10 message, upvert, and return a correct V11 object" do
|
214
|
+
foo_obj = Schemata::Component::Foo.decode(@v10_msg)
|
215
|
+
foo_obj.class.should == Schemata::Component::Foo::V11
|
216
|
+
foo_obj.foo1.should == "hello"
|
217
|
+
foo_obj.foo2.should == 1
|
218
|
+
foo_obj.foo3.should == 1
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should take a v11 message and return a correct V11 object" do
|
222
|
+
foo_obj = Schemata::Component::Foo.decode(@v11_msg)
|
223
|
+
foo_obj.class.should == Schemata::Component::Foo::V11
|
224
|
+
foo_obj.foo1.should == "hello"
|
225
|
+
foo_obj.foo2.should == 1
|
226
|
+
foo_obj.foo3.should == 1
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should take a v12 message and return a correct V11 object" do
|
230
|
+
foo_obj = Schemata::Component::Foo.decode(@v12_msg)
|
231
|
+
foo_obj.class.should == Schemata::Component::Foo::V11
|
232
|
+
foo_obj.foo1.should == "hello"
|
233
|
+
foo_obj.foo2.should == 1
|
234
|
+
foo_obj.foo3.should == 1
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should raise an error when a v10 message has an invalid V10 hash" do
|
238
|
+
msg_hash = {
|
239
|
+
"min_version" => 10,
|
240
|
+
"V10" => {
|
241
|
+
"foo1" => "foo",
|
242
|
+
}
|
243
|
+
}
|
244
|
+
json_msg = Yajl::Encoder.encode msg_hash
|
245
|
+
expect {
|
246
|
+
foo_obj = Schemata::Component::Foo.decode(json_msg)
|
247
|
+
}.to raise_error(Schemata::DecodeError)
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should raise an error when a v11 message has an invalid V11 hash" do
|
251
|
+
msg_hash = {
|
252
|
+
"min_version" => 10,
|
253
|
+
"V10" => {},
|
254
|
+
"V11" => {
|
255
|
+
"foo1" => "foo",
|
256
|
+
"foo3" => 1
|
257
|
+
}
|
258
|
+
}
|
259
|
+
json_msg = Yajl::Encoder.encode msg_hash
|
260
|
+
expect {
|
261
|
+
foo_obj = Schemata::Component::Foo.decode(json_msg)
|
262
|
+
}.to raise_error(Schemata::DecodeError)
|
263
|
+
end
|
264
|
+
|
265
|
+
it "should raise an error when a v12 message has an invalid union \
|
266
|
+
of V10, V11, and V12 hashes" do
|
267
|
+
msg_hash = {
|
268
|
+
"min_version" => 10,
|
269
|
+
"V10" => {},
|
270
|
+
"V11" => {"foo3" => [1]},
|
271
|
+
"V12" => {
|
272
|
+
"foo1" => "foo",
|
273
|
+
"foo2" => 1,
|
274
|
+
"foo3" => [1]
|
275
|
+
}
|
276
|
+
}
|
277
|
+
json_msg = Yajl::Encoder.encode msg_hash
|
278
|
+
expect {
|
279
|
+
foo_obj = Schemata::Component::Foo.decode(json_msg)
|
280
|
+
}.to raise_error(Schemata::DecodeError)
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should raise an IncompatibleVersionError on a v13 message" do
|
284
|
+
expect {
|
285
|
+
foo_obj = Schemata::Component::Foo.decode(@v13_msg)
|
286
|
+
}.to raise_error(Schemata::IncompatibleVersionError)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
describe "(current version is 12)" do
|
291
|
+
before :each do
|
292
|
+
set_current_version(Schemata::Component::Foo, 12)
|
293
|
+
end
|
294
|
+
|
295
|
+
after :each do
|
296
|
+
reset_version(Schemata::Component::Foo)
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should take a v10 message, upvert twice, and return a correct V12 object" do
|
300
|
+
foo_obj = Schemata::Component::Foo.decode(@v10_msg)
|
301
|
+
foo_obj.class.should == Schemata::Component::Foo::V12
|
302
|
+
foo_obj.foo1.should == "hello"
|
303
|
+
foo_obj.foo2.should == 1
|
304
|
+
foo_obj.foo3.should == [1]
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should take a v11 message, upvert, and return a correct V12 object" do
|
308
|
+
foo_obj = Schemata::Component::Foo.decode(@v11_msg)
|
309
|
+
foo_obj.class.should == Schemata::Component::Foo::V12
|
310
|
+
foo_obj.foo1.should == "hello"
|
311
|
+
foo_obj.foo2.should == 1
|
312
|
+
foo_obj.foo3.should == [1]
|
313
|
+
end
|
314
|
+
|
315
|
+
it "should take a v12 message and return a correct V12 object" do
|
316
|
+
foo_obj = Schemata::Component::Foo.decode(@v12_msg)
|
317
|
+
foo_obj.class.should == Schemata::Component::Foo::V12
|
318
|
+
foo_obj.foo1.should == "hello"
|
319
|
+
foo_obj.foo2.should == 1
|
320
|
+
foo_obj.foo3.should == [1]
|
321
|
+
end
|
322
|
+
|
323
|
+
it "should raise an error when a v10 message has an invalid V10 hash" do
|
324
|
+
msg_hash = {
|
325
|
+
"min_version" => 10,
|
326
|
+
"V10" => {
|
327
|
+
"foo1" => "foo"
|
328
|
+
}
|
329
|
+
}
|
330
|
+
json_msg = Yajl::Encoder.encode(msg_hash)
|
331
|
+
expect {
|
332
|
+
foo_obj = Schemata::Component::Foo.decode(json_msg)
|
333
|
+
}.to raise_error(Schemata::DecodeError)
|
334
|
+
end
|
335
|
+
|
336
|
+
it "should raise an error when a v11 messsage an invalid V11 hash" do
|
337
|
+
msg_hash = {
|
338
|
+
"min_version" => 10,
|
339
|
+
"V10" => {},
|
340
|
+
"V11" => {}
|
341
|
+
}
|
342
|
+
json_msg = Yajl::Encoder.encode(msg_hash)
|
343
|
+
expect {
|
344
|
+
foo_obj = Schemata::Component::Foo.decode(json_msg)
|
345
|
+
}.to raise_error(Schemata::DecodeError)
|
346
|
+
end
|
347
|
+
|
348
|
+
it "should raise an error when a v12 message has an invalid V12 hash" do
|
349
|
+
msg_hash = {
|
350
|
+
"min_version" => 10,
|
351
|
+
"V10" => {},
|
352
|
+
"V11" => {"foo3" => 1},
|
353
|
+
"V12" => {}
|
354
|
+
}
|
355
|
+
json_msg = Yajl::Encoder.encode(msg_hash)
|
356
|
+
expect {
|
357
|
+
foo_obj = Schemata::Component::Foo.decode(json_msg)
|
358
|
+
}.to raise_error(Schemata::DecodeError)
|
359
|
+
end
|
360
|
+
|
361
|
+
it "should raise an IncompatibleVersionError on a v13 message" do
|
362
|
+
expect {
|
363
|
+
foo_obj = Schemata::Component::Foo.decode(@v13_msg)
|
364
|
+
}.to raise_error(Schemata::IncompatibleVersionError)
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
describe "(current version is 13)" do
|
369
|
+
before :each do
|
370
|
+
set_current_version(Schemata::Component::Foo, 13)
|
371
|
+
end
|
372
|
+
|
373
|
+
after :each do
|
374
|
+
reset_version(Schemata::Component::Foo)
|
375
|
+
end
|
376
|
+
|
377
|
+
it "should validate a v10 message and return a correct V13 object" do
|
378
|
+
foo_obj = Schemata::Component::Foo.decode(@v10_msg)
|
379
|
+
foo_obj.class.should == Schemata::Component::Foo::V13
|
380
|
+
foo_obj.foo1.should == "hello"
|
381
|
+
foo_obj.foo3.should == [1]
|
382
|
+
foo_obj.foo4.should == "foo"
|
383
|
+
end
|
384
|
+
|
385
|
+
it "should validate a v11 message and return a correct V13 object" do
|
386
|
+
foo_obj = Schemata::Component::Foo.decode(@v11_msg)
|
387
|
+
foo_obj.class.should == Schemata::Component::Foo::V13
|
388
|
+
foo_obj.foo1.should == "hello"
|
389
|
+
foo_obj.foo3.should == [1]
|
390
|
+
foo_obj.foo4.should == "foo"
|
391
|
+
end
|
392
|
+
|
393
|
+
it "should validate a v12 message and return a correct V13 object" do
|
394
|
+
foo_obj = Schemata::Component::Foo.decode(@v12_msg)
|
395
|
+
foo_obj.class.should == Schemata::Component::Foo::V13
|
396
|
+
foo_obj.foo1.should == "hello"
|
397
|
+
foo_obj.foo3.should == [1]
|
398
|
+
foo_obj.foo4.should == "foo"
|
399
|
+
end
|
400
|
+
|
401
|
+
it "should validate a v13 message and return a correct V13 object" do
|
402
|
+
foo_obj =Schemata::Component::Foo.decode(@v13_msg)
|
403
|
+
foo_obj.class.should == Schemata::Component::Foo::V13
|
404
|
+
foo_obj.foo1.should == "hello"
|
405
|
+
foo_obj.foo3.should == [1]
|
406
|
+
foo_obj.foo4.should == "foo"
|
407
|
+
end
|
408
|
+
|
409
|
+
it "should validate a v14 message and return a correct v13 object" do
|
410
|
+
foo_obj = Schemata::Component::Foo.decode(@v14_msg)
|
411
|
+
foo_obj.class.should == Schemata::Component::Foo::V13
|
412
|
+
foo_obj.foo1.should == "hello"
|
413
|
+
foo_obj.foo3.should == [1]
|
414
|
+
foo_obj.foo4.should == "foo"
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
describe "(current version is 14)" do
|
419
|
+
before :each do
|
420
|
+
Schemata::Component::Foo.stub(:current_version).and_return(14)
|
421
|
+
@curr_class = Schemata::Component::Foo.current_class
|
422
|
+
end
|
423
|
+
|
424
|
+
it "should validate a v13 message and return a correct v14 object" do
|
425
|
+
foo_obj = Schemata::Component::Foo.decode(@v13_msg)
|
426
|
+
foo_obj.class.should == Schemata::Component::Foo::V14
|
427
|
+
foo_obj.foo1.should == "hello"
|
428
|
+
foo_obj.foo3.should == [1]
|
429
|
+
end
|
430
|
+
|
431
|
+
it "should validate a v14 message and return a correct v14 object" do
|
432
|
+
foo_obj = Schemata::Component::Foo.decode(@v14_msg)
|
433
|
+
foo_obj.class.should == Schemata::Component::Foo::V14
|
434
|
+
foo_obj.foo1.should == "hello"
|
435
|
+
foo_obj.foo3.should == [1]
|
436
|
+
end
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
describe "#encode" do
|
441
|
+
describe "(current version is 10)" do
|
442
|
+
before :each do
|
443
|
+
set_current_version(Schemata::Component::Foo, 10)
|
444
|
+
end
|
445
|
+
|
446
|
+
after :each do
|
447
|
+
reset_version(Schemata::Component::Foo)
|
448
|
+
end
|
449
|
+
|
450
|
+
it "should take a v10 obj and return the correct json string" do
|
451
|
+
v10_obj = Schemata::Component::Foo::V10.new(@v10_hash)
|
452
|
+
json = v10_obj.encode
|
453
|
+
returned_hash = Yajl::Parser.parse json
|
454
|
+
returned_hash.keys.should =~ ['min_version', 'V10']
|
455
|
+
|
456
|
+
returned_hash['min_version'].should ==
|
457
|
+
@curr_class::MIN_VERSION_ALLOWED
|
458
|
+
|
459
|
+
v10 = returned_hash['V10']
|
460
|
+
v10.each do |k, v|
|
461
|
+
v10[k].should == @v10_hash[k]
|
462
|
+
end
|
463
|
+
end
|
464
|
+
|
465
|
+
it "should raise an error if the msg_obj is incomplete" do
|
466
|
+
msg_obj = Schemata::Component::Foo::V10.new({"foo1" => "foo"})
|
467
|
+
expect {
|
468
|
+
json = msg_obj.encode
|
469
|
+
}.to raise_error(Schemata::EncodeError)
|
470
|
+
end
|
471
|
+
end
|
472
|
+
|
473
|
+
describe "(current version is 11)" do
|
474
|
+
before :each do
|
475
|
+
set_current_version(Schemata::Component::Foo, 11)
|
476
|
+
end
|
477
|
+
|
478
|
+
after:each do
|
479
|
+
reset_version(Schemata::Component::Foo)
|
480
|
+
end
|
481
|
+
|
482
|
+
it "should take a v11 obj and return the correct json string" do
|
483
|
+
v11_obj = Schemata::Component::Foo::V11.new @v11_hash
|
484
|
+
json = v11_obj.encode
|
485
|
+
returned_hash = Yajl::Parser.parse json
|
486
|
+
|
487
|
+
returned_hash.keys.should =~ ['min_version', 'V10', 'V11']
|
488
|
+
|
489
|
+
returned_hash['min_version'].should ==
|
490
|
+
@curr_class::MIN_VERSION_ALLOWED
|
491
|
+
|
492
|
+
v10 = returned_hash["V10"]
|
493
|
+
v10.each do |k, v|
|
494
|
+
v10[k].should == @v10_hash[k]
|
495
|
+
end
|
496
|
+
|
497
|
+
v11 = returned_hash["V11"]
|
498
|
+
v11.each do |k, v|
|
499
|
+
v11[k].should == @v11_hash[k]
|
500
|
+
end
|
501
|
+
end
|
502
|
+
|
503
|
+
it "should raise an error if the msg_obj is incomplete" do
|
504
|
+
msg_obj = Schemata::Component::Foo::V11.new({"foo1" => "foo"})
|
505
|
+
expect {
|
506
|
+
json = msg_obj.encode
|
507
|
+
}.to raise_error(Schemata::EncodeError)
|
508
|
+
end
|
509
|
+
end
|
510
|
+
|
511
|
+
describe "(current version is 12)" do
|
512
|
+
before :each do
|
513
|
+
set_current_version(Schemata::Component::Foo, 12)
|
514
|
+
end
|
515
|
+
|
516
|
+
after :each do
|
517
|
+
reset_version(Schemata::Component::Foo)
|
518
|
+
end
|
519
|
+
|
520
|
+
it "should take a v12 obj and return the correct json string" do
|
521
|
+
v12_obj = Schemata::Component::Foo::V12.new @v12_hash
|
522
|
+
json = v12_obj.encode
|
523
|
+
returned_hash = Yajl::Parser.parse json
|
524
|
+
|
525
|
+
returned_hash.keys.should =~ ['min_version', 'V10', 'V11', 'V12']
|
526
|
+
|
527
|
+
returned_hash['min_version'].should ==
|
528
|
+
@curr_class::MIN_VERSION_ALLOWED
|
529
|
+
|
530
|
+
v10 = returned_hash['V10']
|
531
|
+
v10.each do |k, v|
|
532
|
+
v10[k].should == @v10_hash[k]
|
533
|
+
end
|
534
|
+
|
535
|
+
v11 = returned_hash['V11']
|
536
|
+
v11.each do |k, v|
|
537
|
+
v11[k].should == @v11_hash[k]
|
538
|
+
end
|
539
|
+
|
540
|
+
v12 = returned_hash['V12']
|
541
|
+
v12.each do |k, v|
|
542
|
+
v12[k].should == @v12_hash[k]
|
543
|
+
end
|
544
|
+
end
|
545
|
+
|
546
|
+
it "should raise an error if the msg_obj is incomplete" do
|
547
|
+
msg_obj = Schemata::Component::Foo::V12.new({"foo1" => "foo"})
|
548
|
+
expect {
|
549
|
+
json = msg_obj.encode
|
550
|
+
}.to raise_error(Schemata::EncodeError)
|
551
|
+
end
|
552
|
+
end
|
553
|
+
|
554
|
+
describe "(current version is 13)" do
|
555
|
+
before :each do
|
556
|
+
set_current_version(Schemata::Component::Foo, 13)
|
557
|
+
end
|
558
|
+
|
559
|
+
after :each do
|
560
|
+
reset_version(Schemata::Component::Foo)
|
561
|
+
end
|
562
|
+
|
563
|
+
it "should take a v13 obj and return the correct json string" do
|
564
|
+
v13_obj = Schemata::Component::Foo::V13.new @v13_hash
|
565
|
+
json = v13_obj.encode
|
566
|
+
returned_hash = Yajl::Parser.parse json
|
567
|
+
|
568
|
+
returned_hash.keys.should =~ ['min_version', 'V13']
|
569
|
+
|
570
|
+
returned_hash['min_version'].should ==
|
571
|
+
@curr_class::MIN_VERSION_ALLOWED
|
572
|
+
|
573
|
+
v13 = returned_hash['V13']
|
574
|
+
v13.each do |k, v|
|
575
|
+
v13[k].should == @v13_hash[k]
|
576
|
+
end
|
577
|
+
end
|
578
|
+
|
579
|
+
it "should raise an error if the msg_obj is incomplete" do
|
580
|
+
msg_obj = Schemata::Component::Foo::V13.new({"foo1" => "foo"})
|
581
|
+
expect {
|
582
|
+
json = msg_obj.encode
|
583
|
+
}.to raise_error(Schemata::EncodeError)
|
584
|
+
end
|
585
|
+
end
|
586
|
+
|
587
|
+
describe "(current version 14)" do
|
588
|
+
before :each do
|
589
|
+
Schemata::Component::Foo.stub(:current_version).and_return(14)
|
590
|
+
@curr_class = Schemata::Component::Foo.current_class
|
591
|
+
end
|
592
|
+
|
593
|
+
it "should take a v14 obj and return the correct json string" do
|
594
|
+
aux_data = { "foo4" => "foo" }
|
595
|
+
v14_obj = Schemata::Component::Foo::V14.new(@v14_hash, aux_data)
|
596
|
+
json = v14_obj.encode
|
597
|
+
returned_hash = Yajl::Parser.parse(json)
|
598
|
+
|
599
|
+
returned_hash.keys.should =~ ['min_version', 'V13', 'V14']
|
600
|
+
returned_hash['min_version'].should ==
|
601
|
+
@curr_class::MIN_VERSION_ALLOWED
|
602
|
+
|
603
|
+
v13 = returned_hash['V13']
|
604
|
+
v13.keys.should =~ ['foo4']
|
605
|
+
v13['foo4'].should == "foo"
|
606
|
+
|
607
|
+
v14 = returned_hash['V14']
|
608
|
+
v14.each do |k, v|
|
609
|
+
v14[k].should == @v14_hash[k]
|
610
|
+
end
|
611
|
+
end
|
612
|
+
|
613
|
+
it "should raise an error if the msg_obj is incomplete" do
|
614
|
+
msg_obj = Schemata::Component::Foo::V14.new({"foo1" => "foo"})
|
615
|
+
expect {
|
616
|
+
json = msg_obj.encode
|
617
|
+
}.to raise_error(Schemata::EncodeError)
|
618
|
+
|
619
|
+
msg_obj = Schemata::Component::Foo::V14.new({
|
620
|
+
"foo1" => "foo",
|
621
|
+
"foo3" => [1],
|
622
|
+
})
|
623
|
+
expect {
|
624
|
+
# aux data is missing, and therefore an error is expected.
|
625
|
+
json = msg_obj.encode
|
626
|
+
}.to raise_error(Schemata::EncodeError)
|
627
|
+
end
|
628
|
+
end
|
629
|
+
end
|
630
|
+
end
|