schemata-dea 0.0.1.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/lib/schemata/common/error.rb +12 -0
  2. data/lib/schemata/common/msgbase.rb +281 -0
  3. data/lib/schemata/common/msgtypebase.rb +144 -0
  4. data/lib/schemata/common/parsed_msg.rb +43 -0
  5. data/lib/schemata/dea/advertise_message/advertise_message_v1.rb +40 -0
  6. data/lib/schemata/dea/advertise_message.rb +13 -0
  7. data/lib/schemata/dea/dea_status_response/dea_status_response_v1.rb +48 -0
  8. data/lib/schemata/dea/dea_status_response.rb +13 -0
  9. data/lib/schemata/dea/discover_request/discover_request_v1.rb +93 -0
  10. data/lib/schemata/dea/discover_request.rb +13 -0
  11. data/lib/schemata/dea/droplet_status_response/droplet_status_response_v1.rb +38 -0
  12. data/lib/schemata/dea/droplet_status_response.rb +13 -0
  13. data/lib/schemata/dea/exit_message/exit_message_v1.rb +48 -0
  14. data/lib/schemata/dea/exit_message.rb +13 -0
  15. data/lib/schemata/dea/find_droplet_request/find_droplet_request_v1.rb +52 -0
  16. data/lib/schemata/dea/find_droplet_request.rb +13 -0
  17. data/lib/schemata/dea/find_droplet_response/find_droplet_response_v1.rb +107 -0
  18. data/lib/schemata/dea/find_droplet_response.rb +13 -0
  19. data/lib/schemata/dea/heartbeat_response/heartbeat_response_v1.rb +58 -0
  20. data/lib/schemata/dea/heartbeat_response.rb +13 -0
  21. data/lib/schemata/dea/hello_message/hello_message_v1.rb +40 -0
  22. data/lib/schemata/dea/hello_message.rb +13 -0
  23. data/lib/schemata/dea/start_request/start_request_v1.rb +141 -0
  24. data/lib/schemata/dea/start_request.rb +13 -0
  25. data/lib/schemata/dea/stop_request/stop_request_v1.rb +39 -0
  26. data/lib/schemata/dea/stop_request.rb +13 -0
  27. data/lib/schemata/dea/update_request/update_request_v1.rb +33 -0
  28. data/lib/schemata/dea/update_request.rb +13 -0
  29. data/lib/schemata/dea/version.rb +5 -0
  30. data/lib/schemata/dea.rb +64 -0
  31. data/lib/schemata/helpers/hash_copy.rb +28 -0
  32. data/lib/schemata/helpers/stringify.rb +26 -0
  33. data/spec/cloud_controller/cc_bar_spec.rb +140 -0
  34. data/spec/common/helpers_spec.rb +115 -0
  35. data/spec/common/parsed_msg_spec.rb +46 -0
  36. data/spec/component/aux_data_spec.rb +37 -0
  37. data/spec/component/component_bar_spec.rb +140 -0
  38. data/spec/component/component_foo_spec.rb +630 -0
  39. data/spec/component/foo_spec.rb +214 -0
  40. data/spec/dea/advertise_message_spec.rb +10 -0
  41. data/spec/dea/dea_spec.rb +6 -0
  42. data/spec/dea/dea_status_response_spec.rb +10 -0
  43. data/spec/dea/discover_request_spec.rb +10 -0
  44. data/spec/dea/droplet_status_response_spec.rb +10 -0
  45. data/spec/dea/exit_message_spec.rb +10 -0
  46. data/spec/dea/find_droplet_request_spec.rb +27 -0
  47. data/spec/dea/find_droplet_response_spec.rb +10 -0
  48. data/spec/dea/heartbeat_response_spec.rb +10 -0
  49. data/spec/dea/hello_message_spec.rb +10 -0
  50. data/spec/dea/start_request_spec.rb +10 -0
  51. data/spec/dea/stop_request_spec.rb +10 -0
  52. data/spec/dea/update_request_spec.rb +0 -0
  53. data/spec/router/register_request_spec.rb +10 -0
  54. data/spec/router/router_spec.rb +6 -0
  55. data/spec/router/start_message_spec.rb +10 -0
  56. data/spec/spec_helper.rb +1 -0
  57. data/spec/staging/staging_message_spec.rb +14 -0
  58. data/spec/staging/staging_spec.rb +6 -0
  59. data/spec/support/component_helpers.rb +51 -0
  60. data/spec/support/helpers.rb +54 -0
  61. data/spec/support/message_helpers.rb +138 -0
  62. data/spec/support/message_type_helpers.rb +171 -0
  63. metadata +234 -0
@@ -0,0 +1,33 @@
1
+ module Schemata
2
+ module DEA
3
+ module UpdateRequest
4
+ version 1 do
5
+ include_preschemata
6
+
7
+ define_schema do
8
+ {
9
+ "droplet" => String,
10
+ "uris" => [String]
11
+ }
12
+ end
13
+
14
+ define_min_version 1
15
+
16
+ define_upvert do |old_data|
17
+ raise NotImplmenetedError.new
18
+ end
19
+
20
+ define_generate_old_fields do |msg_obj|
21
+ raise NotImplementedError.new
22
+ end
23
+
24
+ define_mock_values do
25
+ {
26
+ "droplet" => proc { VCAP.secure_uuid },
27
+ "uris" => ["foo.vcap.me"],
28
+ }
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,13 @@
1
+ require 'schemata/common/msgtypebase'
2
+
3
+ module Schemata
4
+ module DEA
5
+ module UpdateRequest
6
+ extend Schemata::MessageTypeBase
7
+ end
8
+ end
9
+ end
10
+
11
+ Dir[File.dirname(__FILE__) + '/update_request/*.rb'].each do |file|
12
+ require file
13
+ end
@@ -0,0 +1,5 @@
1
+ module Schemata
2
+ module DEA
3
+ VERSION = "0.0.1.beta1"
4
+ end
5
+ end
@@ -0,0 +1,64 @@
1
+ require 'schemata/dea/heartbeat_response'
2
+ require 'schemata/dea/find_droplet_request'
3
+ require 'schemata/dea/find_droplet_response'
4
+ require 'schemata/dea/droplet_status_response'
5
+ require 'schemata/dea/advertise_message'
6
+ require 'schemata/dea/hello_message'
7
+ require 'schemata/dea/dea_status_response'
8
+ require 'schemata/dea/exit_message'
9
+ require 'schemata/dea/discover_request'
10
+ require 'schemata/dea/start_request'
11
+ require 'schemata/dea/stop_request'
12
+ require 'schemata/dea/update_request'
13
+
14
+ module Schemata
15
+ module DEA
16
+ def self.mock_heartbeat_response(version=HeartbeatResponse.current_version)
17
+ HeartbeatResponse::const_get("V#{version}").mock
18
+ end
19
+
20
+ def self.mock_find_droplet_request(version=FindDropletRequest.current_version)
21
+ FindDropletRequest::const_get("V#{version}").mock
22
+ end
23
+
24
+ def self.mock_find_droplet_response(version=FindDropletResponse.current_version)
25
+ FindDropletResponse::const_get("V#{version}").mock
26
+ end
27
+
28
+ def self.mock_droplet_status_response(version=DropletStatusResponse.current_version)
29
+ DropletStatusResponse::const_get("V#{version}").mock
30
+ end
31
+
32
+ def self.mock_advertise_message(version=AdvertiseMessage.current_version)
33
+ AdvertiseMessage::const_get("V#{version}").mock
34
+ end
35
+
36
+ def self.mock_hello_message(version=HelloMessage.current_version)
37
+ HelloMessage::const_get("V#{version}").mock
38
+ end
39
+
40
+ def self.mock_dea_status_response(version=DeaStatusResponse.current_version)
41
+ DeaStatusResponse::const_get("V#{version}").mock
42
+ end
43
+
44
+ def self.mock_exit_message(version=ExitMessage.current_version)
45
+ ExitMessage::const_get("V#{version}").mock
46
+ end
47
+
48
+ def self.mock_discover_request(version=DiscoverRequest.current_version)
49
+ DiscoverRequest::const_get("V#{version}").mock
50
+ end
51
+
52
+ def self.mock_start_request(version=StartRequest.current_version)
53
+ StartRequest::const_get("V#{version}").mock
54
+ end
55
+
56
+ def self.mock_stop_request(version=StopRequest.current_version)
57
+ StopRequest::const_get("V#{version}").mock
58
+ end
59
+
60
+ def self.mock_update_request(version=UpdateRequest.current_version)
61
+ UpdateRequest::const_get("V#{version}").mock
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,28 @@
1
+ module Schemata
2
+ module HashCopyHelpers
3
+ class CopyError < StandardError; end
4
+
5
+ def self.deep_copy(node)
6
+ case node
7
+ when String
8
+ return node.dup
9
+ when Numeric, TrueClass, FalseClass
10
+ return node
11
+ when Hash
12
+ copy = {}
13
+ # XXX NB: The 'to_s' below was included because some components use
14
+ # symbols as keys instead of strings. This fix is temporary; in the
15
+ # long term, we should change all components to use the same type for
16
+ # their keys
17
+ node.each { |k, v| copy[k.to_s] = deep_copy(v) }
18
+ return copy
19
+ when Array
20
+ return node.map { |v| deep_copy(v) }
21
+ when NilClass
22
+ return nil
23
+ else
24
+ raise CopyError.new("Unexpected class: #{node.class}")
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ module Schemata
2
+ module HashCopyHelpers
3
+
4
+ def self.stringify(node)
5
+ case node
6
+ when String
7
+ return node
8
+ when Numeric, TrueClass, FalseClass
9
+ return node
10
+ when Hash
11
+ copy = {}
12
+ node.each { |k, v| copy[k.to_s] = stringify(v) }
13
+ return copy
14
+ when Array
15
+ return node.map { |v| stringify(v) }
16
+ when NilClass
17
+ return nil
18
+ when Symbol
19
+ return node.to_s
20
+ else
21
+ raise CopyError.new("Unexpected class: #{node.class}")
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,140 @@
1
+ require 'schemata/cloud_controller/cloud_controller'
2
+ require 'support/helpers'
3
+
4
+ describe Schemata::CloudController 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::CloudController::Bar, 10)
41
+ end
42
+
43
+ after :each do
44
+ reset_version(Schemata::CloudController::Bar)
45
+ end
46
+
47
+ it "should take a v10 msg and create a v10 obj" do
48
+ msg_obj = Schemata::CloudController::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::CloudController::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::CloudController::Bar, 11)
63
+ end
64
+
65
+ after :each do
66
+ reset_version(Schemata::CloudController::Bar)
67
+ end
68
+
69
+ it "should take a v10 msg and create a v11 obj" do
70
+ msg_obj = Schemata::CloudController::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::CloudController::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::CloudController::Bar, 10)
87
+ end
88
+
89
+ after :each do
90
+ reset_version(Schemata::CloudController::Bar)
91
+ end
92
+
93
+ it "should take a v10 obj and encode a json msg" do
94
+ v10_obj = Schemata::CloudController::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::CloudController::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::CloudController::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::CloudController::Bar)
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,115 @@
1
+ require 'schemata/helpers/hash_copy'
2
+ require 'schemata/helpers/stringify'
3
+
4
+ describe Schemata::HashCopyHelpers do
5
+ describe "#deep_copy" do
6
+ it "should deep copy nil" do
7
+ copy = Schemata::HashCopyHelpers.deep_copy(nil)
8
+ copy.should == nil
9
+ end
10
+
11
+ it "should deep copy a given string" do
12
+ original = "foo"
13
+ copy = Schemata::HashCopyHelpers.deep_copy(original)
14
+ copy.should be_instance_of String
15
+ copy.should == original
16
+ copy.object_id.should_not == original.object_id
17
+ end
18
+
19
+ it "should deep copy a given boolean" do
20
+ Schemata::HashCopyHelpers.deep_copy(true).
21
+ should be_an_instance_of TrueClass
22
+ Schemata::HashCopyHelpers.deep_copy(false).
23
+ should be_an_instance_of FalseClass
24
+ end
25
+
26
+ it "should deep copy a given numeric type" do
27
+ original = 0
28
+ copy = Schemata::HashCopyHelpers.deep_copy(original)
29
+ copy.should == original
30
+ copy.should be_an_instance_of Fixnum
31
+
32
+ # set original to be max fixnum + 1
33
+ original = 2**(0.size * 8 - 2)
34
+ copy = Schemata::HashCopyHelpers.deep_copy(original)
35
+ copy.should == original
36
+ copy.should be_an_instance_of Bignum
37
+
38
+ original = 0.0
39
+ copy = Schemata::HashCopyHelpers.deep_copy(original)
40
+ copy.should == original
41
+ copy.should be_an_instance_of Float
42
+ end
43
+
44
+ it "should deep copy a given hash" do
45
+ original = {"foo" => "bar"}
46
+ copy = Schemata::HashCopyHelpers.deep_copy(original)
47
+ copy.should be_instance_of Hash
48
+ copy.should == original
49
+
50
+ copy.object_id.should_not == original.object_id
51
+ copy["foo"].object_id.should_not == original["foo"].object_id
52
+ end
53
+
54
+ it "should deep copy a given array" do
55
+ original = [1, 2, "hello"]
56
+ copy = Schemata::HashCopyHelpers.deep_copy(original)
57
+ copy.should be_instance_of Array
58
+ copy.should == original
59
+
60
+ copy.object_id.should_not == original.object_id
61
+ # only check object_id of String object
62
+ copy[2].object_id.should_not == original[2].object_id
63
+ end
64
+
65
+ it "should deep copy nested types" do
66
+ original = {
67
+ "foo" => "bar",
68
+ "inner" => {
69
+ "hello" => "goodbye",
70
+ },
71
+ }
72
+ copy = Schemata::HashCopyHelpers.deep_copy(original)
73
+ copy.should be_instance_of Hash
74
+ copy.should == original
75
+
76
+ copy.object_id.should_not == original.object_id
77
+ copy["foo"].object_id.should_not == original["foo"].object_id
78
+ copy["inner"].object_id.should_not == original["inner"].object_id
79
+ copy["inner"]["hello"].object_id.
80
+ should_not == original["inner"]["hello"].object_id
81
+ end
82
+
83
+ it "should raise error for unknown type" do
84
+ klass = Class.new
85
+ expect do
86
+ Schemata::HashCopyHelpers.deep_copy(klass.new)
87
+ end.to raise_error(described_class::CopyError, /Unexpected class: /)
88
+ end
89
+ end
90
+
91
+ describe "#stringify" do
92
+ it "should stringify nil" do
93
+ str = Schemata::HashCopyHelpers.stringify(nil)
94
+ str.should == nil
95
+ end
96
+
97
+ it "should stringify a string" do
98
+ original = "foo"
99
+ str = Schemata::HashCopyHelpers.stringify(original)
100
+ str.should == "foo"
101
+ end
102
+
103
+ it "should stringify a symbol" do
104
+ original = :foo
105
+ str = Schemata::HashCopyHelpers.stringify(original)
106
+ str.should == "foo"
107
+ end
108
+
109
+ it "should stringify a hash" do
110
+ original = { "foo" => :foo }
111
+ str = Schemata::HashCopyHelpers.stringify(original)
112
+ str.should == { "foo" => "foo" }
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,46 @@
1
+ require 'schemata/common/parsed_msg'
2
+
3
+ describe Schemata::ParsedMessage do
4
+ describe "#new" do
5
+ it "should raise an error if 'min_version' is missing" do
6
+ json = '{
7
+ "V10" : { "foo" : "bar" }
8
+ }'
9
+ expect {
10
+ msg = Schemata::ParsedMessage.new(json)
11
+ }.to raise_error(Schemata::DecodeError)
12
+ end
13
+
14
+ it "should raise an error if there are non-Vxx hashes" do
15
+ json = '{
16
+ "min_version" : 10,
17
+ "foo" : "bar"
18
+ }'
19
+ expect {
20
+ msg = Schemata::ParsedMessage.new(json)
21
+ }.to raise_error(Schemata::DecodeError)
22
+ end
23
+
24
+ it "should raise an error if there are no Vxx hashes" do
25
+ json = '{
26
+ "min_version" : 10
27
+ }'
28
+ expect {
29
+ msg = Schemata::ParsedMessage.new(json)
30
+ }.to raise_error(Schemata::DecodeError)
31
+ end
32
+
33
+ it "should return a new Schemata::ParsedMessage if the hash is valid" do
34
+ json = '{
35
+ "min_version" : 10,
36
+ "V10" : { "foo" : "bar" },
37
+ "V11" : { "foo" : "bar"}
38
+ }'
39
+ msg = Schemata::ParsedMessage.new(json)
40
+ msg.min_version.should == 10
41
+ msg.version.should == 11
42
+ msg.contents["V10"]["foo"].should == "bar"
43
+ msg.contents["V11"]["foo"].should == "bar"
44
+ end
45
+ end
46
+ end
@@ -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