omf_common 6.0.0 → 6.0.2.pre.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/Gemfile +4 -0
- data/bin/file_broadcaster.rb +56 -0
- data/bin/file_receiver.rb +62 -0
- data/bin/omf_keygen +21 -0
- data/bin/{monitor_topic.rb → omf_monitor_topic} +21 -8
- data/bin/omf_send_create +118 -0
- data/bin/{send_request.rb → omf_send_request} +12 -7
- data/example/engine_alt.rb +23 -24
- data/example/ls_app.yaml +21 -0
- data/lib/omf_common.rb +73 -12
- data/lib/omf_common/auth.rb +15 -0
- data/lib/omf_common/auth/certificate.rb +174 -0
- data/lib/omf_common/auth/certificate_store.rb +72 -0
- data/lib/omf_common/auth/ssh_pub_key_convert.rb +80 -0
- data/lib/omf_common/comm.rb +66 -9
- data/lib/omf_common/comm/amqp/amqp_communicator.rb +40 -13
- data/lib/omf_common/comm/amqp/amqp_file_transfer.rb +259 -0
- data/lib/omf_common/comm/amqp/amqp_topic.rb +14 -21
- data/lib/omf_common/comm/local/local_communicator.rb +31 -2
- data/lib/omf_common/comm/local/local_topic.rb +19 -3
- data/lib/omf_common/comm/topic.rb +48 -34
- data/lib/omf_common/comm/xmpp/communicator.rb +19 -10
- data/lib/omf_common/comm/xmpp/topic.rb +22 -81
- data/lib/omf_common/default_logging.rb +11 -0
- data/lib/omf_common/eventloop.rb +14 -0
- data/lib/omf_common/eventloop/em.rb +39 -6
- data/lib/omf_common/eventloop/local_evl.rb +15 -0
- data/lib/omf_common/exec_app.rb +29 -15
- data/lib/omf_common/message.rb +53 -5
- data/lib/omf_common/message/json/json_message.rb +149 -39
- data/lib/omf_common/message/xml/message.rb +112 -39
- data/lib/omf_common/protocol/6.0.rnc +5 -1
- data/lib/omf_common/protocol/6.0.rng +12 -0
- data/lib/omf_common/version.rb +1 -1
- data/omf_common.gemspec +7 -2
- data/test/fixture/omf_test.cert.pem +15 -0
- data/test/fixture/omf_test.pem +15 -0
- data/test/fixture/omf_test.pub +1 -0
- data/test/fixture/omf_test.pub.pem +6 -0
- data/test/omf_common/auth/certificate_spec.rb +113 -0
- data/test/omf_common/auth/ssh_pub_key_convert_spec.rb +13 -0
- data/test/omf_common/comm/topic_spec.rb +175 -0
- data/test/omf_common/comm/xmpp/communicator_spec.rb +15 -16
- data/test/omf_common/comm/xmpp/topic_spec.rb +63 -10
- data/test/omf_common/comm_spec.rb +66 -9
- data/test/omf_common/message/xml/message_spec.rb +43 -13
- data/test/omf_common/message_spec.rb +14 -0
- data/test/test_helper.rb +25 -0
- metadata +78 -15
- data/bin/send_create.rb +0 -94
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe OmfCommon::Auth::SSHPubKeyConvert do
|
4
|
+
it "must import ssh pub key format to ruby rsa instance" do
|
5
|
+
private_folder = "#{File.dirname(__FILE__)}/../../fixture"
|
6
|
+
|
7
|
+
pub_key = OpenSSL::PKey::RSA.new(File.read("#{private_folder}/omf_test.pub.pem"))
|
8
|
+
|
9
|
+
ssh_pub_key = File.read("#{private_folder}/omf_test.pub")
|
10
|
+
|
11
|
+
OmfCommon::Auth::SSHPubKeyConvert.convert(ssh_pub_key).to_s.must_equal pub_key.to_s
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,175 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe OmfCommon::Comm::Topic do
|
4
|
+
describe "when using factory method to initialise" do
|
5
|
+
before do
|
6
|
+
@topic = OmfCommon::Comm::Topic.create(:bob)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "must add it to the instance list" do
|
10
|
+
OmfCommon::Comm::Topic[:bob].must_equal @topic
|
11
|
+
end
|
12
|
+
|
13
|
+
it "must have interface for its address" do
|
14
|
+
lambda { @topic.address }.must_raise NotImplementedError
|
15
|
+
end
|
16
|
+
|
17
|
+
it "must have interface for on_subscribed handler" do
|
18
|
+
lambda { @topic.on_subscribed }.must_raise NotImplementedError
|
19
|
+
end
|
20
|
+
|
21
|
+
it "must have error? returns false by default" do
|
22
|
+
@topic.error?.must_equal false
|
23
|
+
end
|
24
|
+
|
25
|
+
it "must have interface for timer :after" do
|
26
|
+
OmfCommon::Eventloop.init(type: :em)
|
27
|
+
|
28
|
+
@topic.after(5, & lambda {})
|
29
|
+
|
30
|
+
OmfCommon.eventloop.run do
|
31
|
+
@topic.after(0.1) do |t|
|
32
|
+
t.must_equal @topic
|
33
|
+
OmfCommon.eventloop.stop
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
OmfCommon::Eventloop.reset
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "when interact with topic instance" do
|
42
|
+
before do
|
43
|
+
@comm = mock
|
44
|
+
OmfCommon.stubs(:comm).returns(@comm)
|
45
|
+
@topic = OmfCommon::Comm::Topic.create(:bob)
|
46
|
+
@comm.stubs(:local_address).returns(:bob_address)
|
47
|
+
end
|
48
|
+
|
49
|
+
after do
|
50
|
+
OmfCommon::Comm.reset
|
51
|
+
OmfCommon.unstub(:comm)
|
52
|
+
OmfCommon::Message::XML::Message.any_instance.unstub(:mid)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "must create and send frcp create message" do
|
56
|
+
@topic.create(:rtype).must_equal @topic
|
57
|
+
end
|
58
|
+
|
59
|
+
it "must create and send frcp configure message" do
|
60
|
+
@topic.configure(attr: 'value').must_equal @topic
|
61
|
+
end
|
62
|
+
|
63
|
+
it "must create and send frcp request message" do
|
64
|
+
@topic.request([:attr]).must_equal @topic
|
65
|
+
end
|
66
|
+
|
67
|
+
it "must create and send frcp inform message" do
|
68
|
+
@topic.inform('CREATION.OK', attr: 'value').must_equal @topic
|
69
|
+
end
|
70
|
+
|
71
|
+
it "must create and send frcp inform message" do
|
72
|
+
lambda { @topic.release(:bob) }.must_raise ArgumentError
|
73
|
+
@topic.release(@topic)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "must create different types of message handlers" do
|
77
|
+
@topic.class_eval do
|
78
|
+
define_method(:handlers, &(lambda { @handlers }))
|
79
|
+
end
|
80
|
+
|
81
|
+
[:message, :inform].each do |name|
|
82
|
+
m_name = "on_#{name}"
|
83
|
+
# No callback block given shall fail
|
84
|
+
lambda { @topic.send(m_name) }.must_raise ArgumentError
|
85
|
+
cbk = proc {}
|
86
|
+
@topic.send(m_name, &(cbk))
|
87
|
+
@topic.handlers[name].must_include cbk
|
88
|
+
end
|
89
|
+
|
90
|
+
@topic.class_eval do
|
91
|
+
undef_method(:handlers)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
it "must send a message and register callbacks" do
|
96
|
+
@topic.class_eval do
|
97
|
+
define_method(:context2cbk, &(lambda { @context2cbk }))
|
98
|
+
define_method(:_send_message_public) do |*args|
|
99
|
+
_send_message(*args)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
cbk = proc { 'called' }
|
104
|
+
msg = mock
|
105
|
+
msg.stubs(:mid).returns(:bob_id)
|
106
|
+
|
107
|
+
@topic._send_message_public(msg, cbk)
|
108
|
+
|
109
|
+
h = @topic.context2cbk['bob_id']
|
110
|
+
h.must_be_kind_of Hash
|
111
|
+
h[:block].call.must_equal 'called'
|
112
|
+
|
113
|
+
@topic.class_eval do
|
114
|
+
undef_method(:context2cbk)
|
115
|
+
undef_method(:_send_message_public)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
it "must process incoming messages and trigger registered callbacks" do
|
120
|
+
@topic.class_eval do
|
121
|
+
define_method(:handlers, &(lambda { @handlers }))
|
122
|
+
define_method(:context2cbk, &(lambda { @context2cbk }))
|
123
|
+
define_method(:on_incoming_message_public) do |*args|
|
124
|
+
on_incoming_message(*args)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
msg = mock
|
129
|
+
msg.stubs(:operation).returns(:inform)
|
130
|
+
msg.stubs(:itype).with(:ruby).returns('creation_ok')
|
131
|
+
msg.stubs(:cid).returns(:bob_id)
|
132
|
+
|
133
|
+
OmfCommon::Message::XML::Message.any_instance.stubs(:mid).returns(:bob_id)
|
134
|
+
|
135
|
+
cbk_called = [false, false, false, false]
|
136
|
+
|
137
|
+
@topic.create(:rtype) do |reply_msg|
|
138
|
+
cbk_called[0] = true
|
139
|
+
reply_msg.cid.must_equal :bob_id
|
140
|
+
end
|
141
|
+
|
142
|
+
@topic.on_inform do |incoming_msg|
|
143
|
+
cbk_called[1] = true
|
144
|
+
incoming_msg.cid.must_equal :bob_id
|
145
|
+
end
|
146
|
+
|
147
|
+
@topic.on_message do |incoming_msg|
|
148
|
+
cbk_called[2] = true
|
149
|
+
incoming_msg.cid.must_equal :bob_id
|
150
|
+
end
|
151
|
+
|
152
|
+
@topic.on_creation_ok do |incoming_msg|
|
153
|
+
cbk_called[3] = true
|
154
|
+
incoming_msg.cid.must_equal :bob_id
|
155
|
+
end
|
156
|
+
|
157
|
+
@topic.on_incoming_message_public(msg)
|
158
|
+
|
159
|
+
msg.stubs(:itype).returns(:status)
|
160
|
+
|
161
|
+
@topic.on_incoming_message_public(msg)
|
162
|
+
|
163
|
+
cbk_called[0].must_equal true
|
164
|
+
cbk_called[1].must_equal true
|
165
|
+
cbk_called[2].must_equal true
|
166
|
+
cbk_called[3].must_equal true
|
167
|
+
|
168
|
+
@topic.class_eval do
|
169
|
+
undef_method(:context2cbk)
|
170
|
+
undef_method(:handlers)
|
171
|
+
undef_method(:on_incoming_message_public)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
require 'fixture/pubsub'
|
3
|
-
require 'em/minitest/spec'
|
4
3
|
|
5
4
|
require 'omf_common/comm/xmpp/communicator'
|
6
5
|
|
@@ -18,7 +17,7 @@ describe OmfCommon::Comm::XMPP::Communicator do
|
|
18
17
|
|
19
18
|
it "must be able to connect and tigger on_connected callbacks" do
|
20
19
|
Blather::Client.stub :new, @client do
|
21
|
-
@xmpp.jid.
|
20
|
+
@xmpp.jid.to_s.must_equal "bob@example.com"
|
22
21
|
|
23
22
|
@xmpp.on_connected do |communicator|
|
24
23
|
communicator.must_be_kind_of OmfCommon::Comm::XMPP::Communicator
|
@@ -168,8 +167,8 @@ describe OmfCommon::Comm::XMPP::Communicator do
|
|
168
167
|
m1.must_be_kind_of OmfCommon::TopicMessage
|
169
168
|
m2.must_be_kind_of OmfCommon::TopicMessage
|
170
169
|
m1.body.name.must_equal 'create'
|
171
|
-
m1.body.
|
172
|
-
m2.body.
|
170
|
+
m1.body.marshall[1].must_match /<property key="type" type="string">engine<\/property>/
|
171
|
+
m2.body.marshall[1].must_match /<property key="type" type="string">engine<\/property>/
|
173
172
|
end
|
174
173
|
|
175
174
|
it "must generate omf configure xml fragment" do
|
@@ -181,8 +180,8 @@ describe OmfCommon::Comm::XMPP::Communicator do
|
|
181
180
|
m1.must_be_kind_of OmfCommon::TopicMessage
|
182
181
|
m2.must_be_kind_of OmfCommon::TopicMessage
|
183
182
|
m1.body.name.must_equal 'configure'
|
184
|
-
m1.body.
|
185
|
-
m2.body.
|
183
|
+
m1.body.marshall[1].must_match /<property key="throttle" type="integer">50<\/property>/
|
184
|
+
m2.body.marshall[1].must_match /<property key="throttle" type="integer">50<\/property>/
|
186
185
|
end
|
187
186
|
|
188
187
|
it "must generate omf inform xml fragment" do
|
@@ -194,8 +193,8 @@ describe OmfCommon::Comm::XMPP::Communicator do
|
|
194
193
|
m1.must_be_kind_of OmfCommon::TopicMessage
|
195
194
|
m2.must_be_kind_of OmfCommon::TopicMessage
|
196
195
|
m1.body.name.must_equal 'inform'
|
197
|
-
m1.body.
|
198
|
-
m2.body.
|
196
|
+
m1.body.marshall[1].must_match /<property key="itype" type="string">CREATION.OK<\/property>/
|
197
|
+
m2.body.marshall[1].must_match /<property key="itype" type="string">CREATION.OK<\/property>/
|
199
198
|
end
|
200
199
|
|
201
200
|
it "must generate omf release xml fragment" do
|
@@ -207,8 +206,8 @@ describe OmfCommon::Comm::XMPP::Communicator do
|
|
207
206
|
m1.must_be_kind_of OmfCommon::TopicMessage
|
208
207
|
m2.must_be_kind_of OmfCommon::TopicMessage
|
209
208
|
m1.body.name.must_equal 'release'
|
210
|
-
m1.body.
|
211
|
-
m2.body.
|
209
|
+
m1.body.marshall[1].must_match /<property key="res_id" type="integer">100<\/property>/
|
210
|
+
m2.body.marshall[1].must_match /<property key="res_id" type="integer">100<\/property>/
|
212
211
|
end
|
213
212
|
|
214
213
|
it "must generate omf request xml fragment" do
|
@@ -222,12 +221,12 @@ describe OmfCommon::Comm::XMPP::Communicator do
|
|
222
221
|
m1.must_be_kind_of OmfCommon::TopicMessage
|
223
222
|
m2.must_be_kind_of OmfCommon::TopicMessage
|
224
223
|
m1.body.name.must_equal 'request'
|
225
|
-
m1.body.
|
226
|
-
m1.body.
|
227
|
-
m2.body.
|
228
|
-
m1.body.
|
229
|
-
m2.body.
|
230
|
-
m1.body.
|
224
|
+
m1.body.marshall[1].must_match /<property key="max_rpm"\/>/
|
225
|
+
m1.body.marshall[1].must_match /<property key="provider" type="hash">/
|
226
|
+
m2.body.marshall[1].must_match /<property key="provider" type="hash">/
|
227
|
+
m1.body.marshall[1].must_match /<country type="string">japan<\/country>/
|
228
|
+
m2.body.marshall[1].must_match /<country type="string">japan<\/country>/
|
229
|
+
m1.body.marshall[1].must_match /<property key="max_power"\/>/
|
231
230
|
end
|
232
231
|
end
|
233
232
|
|
@@ -1,6 +1,7 @@
|
|
1
|
+
require 'test_helper'
|
1
2
|
require 'fixture/pubsub'
|
2
|
-
require 'em/minitest/spec'
|
3
3
|
|
4
|
+
require 'omf_common/comm/xmpp/communicator'
|
4
5
|
require 'omf_common/comm/xmpp/topic'
|
5
6
|
|
6
7
|
describe OmfCommon::Comm::XMPP::Topic do
|
@@ -20,7 +21,10 @@ describe OmfCommon::Comm::XMPP::Topic do
|
|
20
21
|
end
|
21
22
|
|
22
23
|
describe "when calling operation method" do
|
24
|
+
include EM::MiniTest::Spec
|
25
|
+
|
23
26
|
it "must send create message" do
|
27
|
+
skip
|
24
28
|
OmfCommon.stub :comm, @xmpp do
|
25
29
|
Blather::Client.stub :new, @client do
|
26
30
|
published = Blather::XMPPNode.parse(published_xml)
|
@@ -32,10 +36,39 @@ describe OmfCommon::Comm::XMPP::Topic do
|
|
32
36
|
end
|
33
37
|
|
34
38
|
@client.stub :write, write_callback do
|
35
|
-
@
|
39
|
+
@xmpp.stub :local_address, 'test_addr' do
|
40
|
+
@topic.create(:bob, { hrn: 'bob' })
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it "must trigger operation callbacks" do
|
48
|
+
skip
|
49
|
+
OmfCommon.stub :comm, @xmpp do
|
50
|
+
Blather::Client.stub :new, @client do
|
51
|
+
@client.stub :write, proc {} do
|
52
|
+
@xmpp.stub :local_address, 'test_addr' do
|
53
|
+
omf_create = OmfCommon::Message.create(:create, { type: 'engine' })
|
54
|
+
omf_create.stub :mid, "bf840fe9-c176-4fae-b7de-6fc27f183f76" do
|
55
|
+
warn omf_create.mid
|
56
|
+
OmfCommon::Message.stub :create, omf_create do
|
57
|
+
@topic.create(:bob, { hrn: 'bob' }) do |reply_msg|
|
58
|
+
error 'bob'
|
59
|
+
#reply_msg.cid.must_equal "bf840fe9-c176-4fae-b7de-6fc27f183f76"
|
60
|
+
done!
|
61
|
+
end
|
62
|
+
|
63
|
+
@client.receive_data Blather::XMPPNode.parse(omf_created_xml)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
36
67
|
end
|
37
68
|
end
|
38
69
|
end
|
70
|
+
|
71
|
+
wait!
|
39
72
|
end
|
40
73
|
end
|
41
74
|
|
@@ -43,6 +76,7 @@ describe OmfCommon::Comm::XMPP::Topic do
|
|
43
76
|
include EM::MiniTest::Spec
|
44
77
|
|
45
78
|
it "must react to omf created message" do
|
79
|
+
skip
|
46
80
|
OmfCommon.stub :comm, @xmpp do
|
47
81
|
Blather::Client.stub :new, @client do
|
48
82
|
omf_create = OmfCommon::Message.create(:create, { type: 'engine' })
|
@@ -50,8 +84,12 @@ describe OmfCommon::Comm::XMPP::Topic do
|
|
50
84
|
omf_created = Blather::XMPPNode.parse(omf_created_xml)
|
51
85
|
@client.receive_data omf_created
|
52
86
|
@topic.on_creation_ok(omf_create) do |n|
|
53
|
-
|
54
|
-
|
87
|
+
OmfCommon::Message.parse(omf_created.items.first.payload) do |parsed_msg|
|
88
|
+
n.stub :ts, parsed_msg.ts do
|
89
|
+
n.must_equal parsed_msg
|
90
|
+
end
|
91
|
+
done!
|
92
|
+
end
|
55
93
|
end
|
56
94
|
end
|
57
95
|
end
|
@@ -60,6 +98,7 @@ describe OmfCommon::Comm::XMPP::Topic do
|
|
60
98
|
end
|
61
99
|
|
62
100
|
it "must react to omf status message" do
|
101
|
+
skip
|
63
102
|
OmfCommon.stub :comm, @xmpp do
|
64
103
|
Blather::Client.stub :new, @client do
|
65
104
|
omf_request = OmfCommon::Message.create(:request, [:bob])
|
@@ -67,8 +106,12 @@ describe OmfCommon::Comm::XMPP::Topic do
|
|
67
106
|
omf_status = Blather::XMPPNode.parse(omf_status_xml)
|
68
107
|
@client.receive_data omf_status
|
69
108
|
@topic.on_status(omf_request) do |n|
|
70
|
-
|
71
|
-
|
109
|
+
OmfCommon::Message.parse(omf_status.items.first.payload) do |parsed_msg|
|
110
|
+
n.stub :ts, parsed_msg.ts do
|
111
|
+
n.must_equal parsed_msg
|
112
|
+
end
|
113
|
+
done!
|
114
|
+
end
|
72
115
|
end
|
73
116
|
end
|
74
117
|
end
|
@@ -77,6 +120,7 @@ describe OmfCommon::Comm::XMPP::Topic do
|
|
77
120
|
end
|
78
121
|
|
79
122
|
it "must react to omf release message" do
|
123
|
+
skip
|
80
124
|
OmfCommon.stub :comm, @xmpp do
|
81
125
|
Blather::Client.stub :new, @client do
|
82
126
|
omf_release = OmfCommon::Message.create(:release, nil, { res_id: '100' })
|
@@ -84,8 +128,12 @@ describe OmfCommon::Comm::XMPP::Topic do
|
|
84
128
|
omf_released = Blather::XMPPNode.parse(omf_released_xml)
|
85
129
|
@client.receive_data omf_released
|
86
130
|
@topic.on_released(omf_release) do |n|
|
87
|
-
|
88
|
-
|
131
|
+
OmfCommon::Message.parse(omf_released.items.first.payload) do |parsed_msg|
|
132
|
+
n.stub :ts, parsed_msg.ts do
|
133
|
+
n.must_equal parsed_msg
|
134
|
+
end
|
135
|
+
done!
|
136
|
+
end
|
89
137
|
end
|
90
138
|
end
|
91
139
|
end
|
@@ -94,6 +142,7 @@ describe OmfCommon::Comm::XMPP::Topic do
|
|
94
142
|
end
|
95
143
|
|
96
144
|
it "must react to omf failed message" do
|
145
|
+
skip
|
97
146
|
OmfCommon.stub :comm, @xmpp do
|
98
147
|
Blather::Client.stub :new, @client do
|
99
148
|
omf_create = OmfCommon::Message.create(:create, { type: 'engine' })
|
@@ -101,8 +150,12 @@ describe OmfCommon::Comm::XMPP::Topic do
|
|
101
150
|
omf_failed = Blather::XMPPNode.parse(omf_failed_xml)
|
102
151
|
@client.receive_data omf_failed
|
103
152
|
@topic.on_creation_failed(omf_create) do |n|
|
104
|
-
|
105
|
-
|
153
|
+
OmfCommon::Message.parse(omf_failed.items.first.payload) do |parsed_msg|
|
154
|
+
n.stub :ts, parsed_msg.ts do
|
155
|
+
n.must_equal parsed_msg
|
156
|
+
end
|
157
|
+
done!
|
158
|
+
end
|
106
159
|
end
|
107
160
|
end
|
108
161
|
end
|
@@ -1,18 +1,75 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
require 'omf_common/comm/local/local_communicator'
|
2
3
|
|
3
4
|
describe OmfCommon::Comm do
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
@
|
8
|
-
|
9
|
-
|
5
|
+
describe "when initialised without providing a pubsub implementation" do
|
6
|
+
before do
|
7
|
+
OmfCommon::Comm.any_instance.stubs(:on_connected)
|
8
|
+
@abstract_comm = OmfCommon::Comm.new(bob: nil)
|
9
|
+
@topic = mock
|
10
|
+
end
|
11
|
+
|
12
|
+
it "must raise no implementation error for abstract methods" do
|
13
|
+
OmfCommon::Comm.any_instance.unstub(:on_connected)
|
14
|
+
[:disconnect, :on_connected, :on_connected].each do |m|
|
15
|
+
lambda { @abstract_comm.send(m, ) }.must_raise NotImplementedError
|
10
16
|
end
|
11
17
|
|
12
|
-
|
13
|
-
|
14
|
-
@comm.must_respond_to m
|
18
|
+
[:create_topic, :delete_topic].each do |m|
|
19
|
+
lambda { @abstract_comm.send(m, :bob) }.must_raise NotImplementedError
|
15
20
|
end
|
16
21
|
end
|
22
|
+
|
23
|
+
it "must return options" do
|
24
|
+
@abstract_comm.options.must_equal(bob: nil)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "must return connection info" do
|
28
|
+
@abstract_comm.conn_info.must_equal({ proto: nil, user: nil, domain: nil })
|
29
|
+
end
|
30
|
+
|
31
|
+
it "must be able to subscribe to a topic" do
|
32
|
+
@abstract_comm.stubs(:create_topic).returns(@topic)
|
33
|
+
@topic.expects(:on_subscribed)
|
34
|
+
@abstract_comm.subscribe(:bob) { 'do nothing' }
|
35
|
+
end
|
36
|
+
|
37
|
+
it "must be able to publish message" do
|
38
|
+
@abstract_comm.stubs(:create_topic).returns(@topic)
|
39
|
+
@topic.expects(:publish)
|
40
|
+
@abstract_comm.publish(:bob, 'message')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'when initialised with a pubsub implementation' do
|
45
|
+
after do
|
46
|
+
OmfCommon::Comm.reset
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'must fail if you throw in rubbish options' do
|
50
|
+
lambda { OmfCommon::Comm.init(bob: nil) }.must_raise ArgumentError
|
51
|
+
lambda { OmfCommon::Comm.init(provider: {}) }.must_raise ArgumentError
|
52
|
+
lambda { OmfCommon::Comm.init(provider: { constructor: {}, require: {} }) }.must_raise TypeError
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'must fail if already initialised' do
|
56
|
+
OmfCommon::Comm::Local::Communicator.any_instance.stubs(:on_connected)
|
57
|
+
OmfCommon::Message.stubs(:init)
|
58
|
+
error = lambda do
|
59
|
+
OmfCommon::Comm.init(type: :local)
|
60
|
+
OmfCommon::Comm.init(type: :local)
|
61
|
+
end.call rescue $!
|
62
|
+
error.message.must_match /Comms layer already initialised/
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'must handle auth options and be able to return singleton instance' do
|
66
|
+
OmfCommon::Comm::Local::Communicator.any_instance.stubs(:on_connected)
|
67
|
+
|
68
|
+
OmfCommon::Message.stubs(:init)
|
69
|
+
OmfCommon::Auth::CertificateStore.stubs(:init)
|
70
|
+
OmfCommon::Comm.init(type: :local, auth: {})
|
71
|
+
|
72
|
+
OmfCommon::Comm.instance.must_be_kind_of OmfCommon::Comm::Local::Communicator
|
73
|
+
end
|
17
74
|
end
|
18
75
|
end
|