omf_common 6.1.2.pre.2 → 6.1.2.pre.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -1
- data/lib/omf_common/comm.rb +28 -29
- data/lib/omf_common/comm/amqp/amqp_communicator.rb +1 -0
- data/lib/omf_common/eventloop.rb +16 -17
- data/lib/omf_common/message.rb +23 -25
- data/omf_common.gemspec +1 -1
- data/test/omf_common/auth/certificate_store_spec.rb +0 -6
- data/test/omf_common/comm/amqp/communicator_spec.rb +49 -0
- data/test/omf_common/comm/topic_spec.rb +4 -0
- data/test/omf_common/comm/xmpp/communicator_spec.rb +262 -229
- data/test/omf_common/comm/xmpp/topic_spec.rb +188 -144
- data/test/omf_common/comm_spec.rb +4 -6
- data/test/omf_common/message/xml/message_spec.rb +2 -3
- data/test/omf_common/message_spec.rb +3 -0
- data/test/test_helper.rb +13 -5
- metadata +9 -10
- data/lib/omf_common/message/xml/topic_message.rb +0 -25
- data/test/fixture/3rd_level.pem +0 -19
data/Rakefile
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'bundler/setup'
|
1
2
|
require 'rake/testtask'
|
2
3
|
require "bundler/gem_tasks"
|
3
4
|
|
@@ -8,6 +9,7 @@ Rake::Task[:release].clear
|
|
8
9
|
Rake::TestTask.new do |t|
|
9
10
|
t.libs << 'test'
|
10
11
|
t.pattern = "test/**/*_spec.rb"
|
12
|
+
#t.pattern = "test/**/message_spec.rb"
|
13
|
+
#t.pattern = "test/**/xmpp/topic_spec.rb"
|
11
14
|
t.verbose = true
|
12
15
|
end
|
13
|
-
|
data/lib/omf_common/comm.rb
CHANGED
@@ -42,40 +42,39 @@ module OmfCommon
|
|
42
42
|
# :constructor - Class implementing provider
|
43
43
|
#
|
44
44
|
def self.init(opts)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
type = url.split(':')[0].to_sym
|
45
|
+
unless @@instance
|
46
|
+
unless provider = opts[:provider]
|
47
|
+
unless type = opts[:type]
|
48
|
+
if url = opts[:url]
|
49
|
+
type = url.split(':')[0].to_sym
|
50
|
+
end
|
52
51
|
end
|
52
|
+
provider = @@providers[type]
|
53
|
+
end
|
54
|
+
unless provider
|
55
|
+
raise ArgumentError, "Missing Comm provider declaration. Either define 'type', 'provider', or 'url'"
|
53
56
|
end
|
54
|
-
provider = @@providers[type]
|
55
|
-
end
|
56
|
-
unless provider
|
57
|
-
raise ArgumentError, "Missing Comm provider declaration. Either define 'type', 'provider', or 'url'"
|
58
|
-
end
|
59
57
|
|
60
|
-
|
58
|
+
require provider[:require] if provider[:require]
|
61
59
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
60
|
+
if class_name = provider[:constructor]
|
61
|
+
provider_class = class_name.split('::').inject(Object) {|c,n| c.const_get(n) }
|
62
|
+
inst = provider_class.new(opts)
|
63
|
+
else
|
64
|
+
raise ArgumentError, "Missing communicator creation info - :constructor"
|
65
|
+
end
|
66
|
+
@@instance = inst
|
67
|
+
mopts = provider[:message_provider]
|
68
|
+
mopts[:authenticate] = opts[:auth]
|
69
|
+
Message.init(mopts)
|
70
|
+
|
71
|
+
if aopts = opts[:auth]
|
72
|
+
require 'omf_common/auth'
|
73
|
+
OmfCommon::Auth.init(aopts)
|
74
|
+
end
|
77
75
|
|
78
|
-
|
76
|
+
inst.init(opts)
|
77
|
+
end
|
79
78
|
end
|
80
79
|
|
81
80
|
def self.instance
|
data/lib/omf_common/eventloop.rb
CHANGED
@@ -28,26 +28,25 @@ module OmfCommon
|
|
28
28
|
# :constructor - Class implementing provider
|
29
29
|
#
|
30
30
|
def self.init(opts, &block)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
provider
|
36
|
-
|
37
|
-
|
38
|
-
raise "Missing Eventloop provider declaration. Either define 'type' or 'provider'"
|
39
|
-
end
|
31
|
+
unless @@instance
|
32
|
+
unless provider = opts[:provider]
|
33
|
+
provider = @@providers[opts[:type].to_sym]
|
34
|
+
end
|
35
|
+
unless provider
|
36
|
+
raise "Missing Eventloop provider declaration. Either define 'type' or 'provider'"
|
37
|
+
end
|
40
38
|
|
41
|
-
|
39
|
+
require provider[:require] if provider[:require]
|
42
40
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
if class_name = provider[:constructor]
|
42
|
+
provider_class = class_name.split('::').inject(Object) {|c,n| c.const_get(n) }
|
43
|
+
inst = provider_class.new(opts, &block)
|
44
|
+
else
|
45
|
+
raise "Missing provider creation info - :constructor"
|
46
|
+
end
|
47
|
+
@@instance = inst
|
48
48
|
end
|
49
|
-
@@instance
|
50
|
-
inst
|
49
|
+
@@instance
|
51
50
|
end
|
52
51
|
|
53
52
|
def self.instance
|
data/lib/omf_common/message.rb
CHANGED
@@ -66,34 +66,32 @@ module OmfCommon
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def self.init(opts = {})
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
unless provider
|
77
|
-
raise "Missing Message provider declaration. Either define 'type' or 'provider'"
|
78
|
-
end
|
69
|
+
unless @@message_class
|
70
|
+
unless provider = opts[:provider]
|
71
|
+
provider = @@providers[opts[:type]]
|
72
|
+
end
|
73
|
+
unless provider
|
74
|
+
raise "Missing Message provider declaration. Either define 'type' or 'provider'"
|
75
|
+
end
|
79
76
|
|
80
|
-
|
77
|
+
require provider[:require] if provider[:require]
|
81
78
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
79
|
+
if class_name = provider[:constructor]
|
80
|
+
@@message_class = class_name.split('::').inject(Object) {|c,n| c.const_get(n) }
|
81
|
+
else
|
82
|
+
raise "Missing provider class info - :constructor"
|
83
|
+
end
|
84
|
+
aopts = opts[:authenticate] || {}
|
85
|
+
@@authenticate_messages = opts[:authenticate] && !(aopts[:authenticate] == false)
|
86
|
+
if pdp_opts = (opts[:authenticate] || {})[:pdp]
|
87
|
+
require pdp_opts.delete(:require) if pdp_opts[:require]
|
88
|
+
unless pdp_constructor = pdp_opts.delete(:constructor)
|
89
|
+
raise "Missing PDP provider declaration."
|
90
|
+
end
|
91
|
+
|
92
|
+
pdp_class = pdp_constructor.split('::').inject(Object) {|c,n| c.const_get(n) }
|
93
|
+
@@authorisation_hook = pdp_class.new(pdp_opts)
|
93
94
|
end
|
94
|
-
|
95
|
-
pdp_class = pdp_constructor.split('::').inject(Object) {|c,n| c.const_get(n) }
|
96
|
-
@@authorisation_hook = pdp_class.new(pdp_opts)
|
97
95
|
end
|
98
96
|
end
|
99
97
|
|
data/omf_common.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
|
23
23
|
# specify any dependencies here; for example:
|
24
24
|
s.add_development_dependency "minitest"
|
25
|
-
s.add_development_dependency "
|
25
|
+
s.add_development_dependency "evented-spec", "~> 1.0.0.beta"
|
26
26
|
s.add_development_dependency "simplecov"
|
27
27
|
s.add_development_dependency "pry"
|
28
28
|
s.add_development_dependency "mocha"
|
@@ -26,18 +26,12 @@ describe OmfCommon::Auth::CertificateStore do
|
|
26
26
|
# 2 level CAs
|
27
27
|
cert_1 = OmfCommon::Auth::Certificate.create_from_pem(File.read "#{@private_folder}/1st_level.pem")
|
28
28
|
cert_2 = OmfCommon::Auth::Certificate.create_from_pem(File.read "#{@private_folder}/2nd_level.pem")
|
29
|
-
cert_3 = OmfCommon::Auth::Certificate.create_from_pem(File.read "#{@private_folder}/3rd_level.pem")
|
30
29
|
|
31
30
|
OmfCommon::Auth::CertificateStore.instance.verify(cert_2.to_x509).must_equal false
|
32
31
|
|
33
32
|
OmfCommon::Auth::CertificateStore.instance.register_trusted(cert_1)
|
34
33
|
|
35
34
|
OmfCommon::Auth::CertificateStore.instance.verify(cert_2.to_x509).must_equal true
|
36
|
-
OmfCommon::Auth::CertificateStore.instance.verify(cert_3.to_x509).must_equal false
|
37
|
-
|
38
|
-
OmfCommon::Auth::CertificateStore.instance.register_trusted(cert_2)
|
39
|
-
|
40
|
-
OmfCommon::Auth::CertificateStore.instance.verify(cert_3.to_x509).must_equal true
|
41
35
|
|
42
36
|
# 1 level CA
|
43
37
|
cert_4 = OmfCommon::Auth::Certificate.create_root
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'omf_common/comm/amqp/amqp_communicator'
|
3
|
+
|
4
|
+
describe "Using AMQP communicator" do
|
5
|
+
include EventedSpec::SpecHelper
|
6
|
+
default_timeout 1.1
|
7
|
+
|
8
|
+
before do
|
9
|
+
@amqp_comm = OmfCommon::Comm::AMQP::Communicator.new
|
10
|
+
OmfCommon::Eventloop.init(type: :em)
|
11
|
+
OmfCommon.stubs(:comm).returns(@amqp_comm)
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
em do
|
16
|
+
@amqp_comm.init(url: 'amqp://localhost')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "must allow you to connect" do
|
21
|
+
@amqp_comm.on_connected do |c|
|
22
|
+
assert_kind_of OmfCommon::Comm::AMQP::Communicator, c
|
23
|
+
assert_equal :amqp, c.conn_info[:proto]
|
24
|
+
assert_equal "guest", c.conn_info[:user]
|
25
|
+
done
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "must construct topic address string" do
|
30
|
+
@amqp_comm.on_connected do |c|
|
31
|
+
t_name = SecureRandom.uuid
|
32
|
+
assert_equal "amqp://localhost/frcp.#{t_name}", c.string_to_topic_address(t_name)
|
33
|
+
done
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "must allow you to create a new pubsub topic" do
|
38
|
+
@amqp_comm.on_connected do |c|
|
39
|
+
t_name = SecureRandom.uuid.to_sym
|
40
|
+
c.create_topic(t_name)
|
41
|
+
assert_kind_of OmfCommon::Comm::AMQP::Topic, OmfCommon::Comm::Topic[t_name]
|
42
|
+
done
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it "must allow you to delete a pubsub topic" do
|
47
|
+
skip
|
48
|
+
end
|
49
|
+
end
|
@@ -46,6 +46,10 @@ describe OmfCommon::Comm::Topic do
|
|
46
46
|
describe "when interact with topic instance" do
|
47
47
|
before do
|
48
48
|
@comm = mock
|
49
|
+
|
50
|
+
# TODO Again, can not create an abstract topic without init a message
|
51
|
+
OmfCommon::Message.init(type: :xml)
|
52
|
+
|
49
53
|
OmfCommon.stubs(:comm).returns(@comm)
|
50
54
|
@topic = OmfCommon::Comm::Topic.create(:bob)
|
51
55
|
@comm.stubs(:local_address).returns(:bob_address)
|
@@ -1,252 +1,285 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- encoding: utf-8 -*-
|
3
|
+
|
1
4
|
# Copyright (c) 2012 National ICT Australia Limited (NICTA).
|
2
5
|
# This software may be used and distributed solely under the terms of the MIT license (License).
|
3
6
|
# You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
|
4
7
|
# By downloading or using this software you accept the terms and the liability disclaimer in the License.
|
5
8
|
|
6
9
|
require 'test_helper'
|
7
|
-
require 'monitor'
|
8
|
-
require 'fixture/pubsub'
|
9
|
-
|
10
10
|
require 'omf_common/comm/xmpp/communicator'
|
11
11
|
|
12
|
-
describe
|
13
|
-
|
14
|
-
@client = Blather::Client.new
|
15
|
-
@stream = MiniTest::Mock.new
|
16
|
-
@stream.expect(:send, true, [Blather::Stanza])
|
17
|
-
@client.post_init @stream, Blather::JID.new('bob@example.com')
|
18
|
-
@xmpp = OmfCommon::Comm::XMPP::Communicator.new
|
19
|
-
@xmpp.instance_eval do
|
20
|
-
@lock = Monitor.new
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "when communicating to xmpp server (via mocking)" do
|
25
|
-
include EM::MiniTest::Spec
|
26
|
-
|
27
|
-
it "must be able to connect and tigger on_connected callbacks" do
|
28
|
-
Blather::Client.stub :new, @client do
|
29
|
-
@xmpp.jid.to_s.must_equal "bob@example.com"
|
12
|
+
describe "Using XMPP communicator" do
|
13
|
+
include EventedSpec::SpecHelper
|
30
14
|
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
@stream.verify
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
it "must be able to disconnect" do
|
39
|
-
Blather::Client.stub :new, @client do
|
40
|
-
@stream.expect(:close_connection_after_writing, true)
|
41
|
-
@xmpp.disconnect
|
42
|
-
end
|
43
|
-
end
|
15
|
+
# XMPP requires more time
|
16
|
+
default_timeout 3.1
|
44
17
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
write_callback = proc do |event|
|
50
|
-
event.must_be_kind_of Blather::Stanza::PubSub::Subscribe
|
51
|
-
subscription.id = event.id
|
52
|
-
@client.receive_data subscription
|
53
|
-
end
|
54
|
-
@client.stub :write, write_callback do
|
55
|
-
@xmpp.subscribe('xmpp_topic') do |topic|
|
56
|
-
topic.must_be_kind_of OmfCommon::Comm::XMPP::Topic
|
57
|
-
topic.id.must_equal :xmpp_topic
|
58
|
-
done!
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
wait!
|
63
|
-
end
|
64
|
-
|
65
|
-
it "must be able to create topic & trigger callback when created" do
|
66
|
-
Blather::Client.stub :new, @client do
|
67
|
-
OmfCommon.stub :comm, @xmpp do
|
68
|
-
@stream.expect(:send, true, [Blather::Stanza])
|
69
|
-
@xmpp.create_topic('xmpp_topic').must_be_kind_of OmfCommon::Comm::XMPP::Topic
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
it "must be able to delete topic & trigger callback when topic deleted" do
|
75
|
-
Blather::Client.stub :new, @client do
|
76
|
-
deleted = Blather::XMPPNode.parse(fabulous_xmpp_empty_success_xml)
|
77
|
-
write_callback = proc do |event|
|
78
|
-
event.must_be_kind_of Blather::Stanza::PubSubOwner::Delete
|
79
|
-
deleted.id = event.id
|
80
|
-
@client.receive_data deleted
|
81
|
-
end
|
82
|
-
@client.stub :write, write_callback do
|
83
|
-
@xmpp.delete_topic('xmpp_topic') do |stanza|
|
84
|
-
done!
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
wait!
|
89
|
-
end
|
90
|
-
|
91
|
-
it "must be able to list affiliations (owned pubsub nodes) & react if received" do
|
92
|
-
Blather::Client.stub :new, @client do
|
93
|
-
affiliations = Blather::XMPPNode.parse(affiliations_xml)
|
94
|
-
write_callback = proc do |event|
|
95
|
-
event.must_be_kind_of Blather::Stanza::PubSub::Affiliations
|
96
|
-
affiliations.id = event.id
|
97
|
-
@client.receive_data affiliations
|
98
|
-
end
|
99
|
-
@client.stub :write, write_callback do
|
100
|
-
@xmpp.affiliations { |event| event[:owner].must_equal %w(node1 node2); done! }
|
101
|
-
end
|
102
|
-
end
|
103
|
-
wait!
|
104
|
-
end
|
105
|
-
|
106
|
-
it "must be able to publish if message is valid" do
|
107
|
-
Blather::Client.stub :new, @client do
|
108
|
-
@stream.expect(:send, true, [Blather::Stanza::PubSub::Publish])
|
109
|
-
@xmpp.publish 'xmpp_topic', OmfCommon::Message.create(:create, { type: 'test' })
|
110
|
-
proc { @xmpp.publish 'xmpp_topic', OmfCommon::Message.create(:inform, nil, { blah: 'blah' })}.must_raise StandardError
|
111
|
-
@stream.verify
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
it "must trigger callback when item published" do
|
116
|
-
Blather::Client.stub :new, @client do
|
117
|
-
published = Blather::XMPPNode.parse(published_xml)
|
118
|
-
write_callback = proc do |event|
|
119
|
-
event.must_be_kind_of Blather::Stanza::PubSub::Publish
|
120
|
-
published.id = event.id
|
121
|
-
@client.receive_data published
|
122
|
-
end
|
123
|
-
@client.stub :write, write_callback do
|
124
|
-
@xmpp.publish 'xmpp_topic', OmfCommon::Message.create(:create, { type: 'test' }) do |event|
|
125
|
-
event.must_equal published
|
126
|
-
done!
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
wait!
|
131
|
-
end
|
132
|
-
|
133
|
-
it "must be able to unsubscribe" do
|
134
|
-
Blather::Client.stub :new, @client do
|
135
|
-
@stream.expect(:send, true, [Blather::Stanza::PubSub::Subscriptions])
|
136
|
-
@xmpp.unsubscribe
|
137
|
-
@stream.verify
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
it "must trigger callback when unsubscribed (all topics)" do
|
142
|
-
Blather::Client.stub :new, @client do
|
143
|
-
2.times do
|
144
|
-
@stream.expect(:send, true, [Blather::Stanza])
|
145
|
-
end
|
146
|
-
|
147
|
-
subscriptions = Blather::XMPPNode.parse(subscriptions_xml)
|
148
|
-
write_callback = proc do |event|
|
149
|
-
event.must_be_kind_of Blather::Stanza::PubSub::Subscriptions
|
150
|
-
subscriptions.id = event.id
|
151
|
-
@client.receive_data subscriptions
|
152
|
-
end
|
153
|
-
@client.stub :write, write_callback do
|
154
|
-
@xmpp.unsubscribe
|
155
|
-
end
|
156
|
-
@stream.verify
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
it "must be able to add a topic event handler" do
|
161
|
-
Blather::Client.stub :new, @client do
|
162
|
-
@xmpp.topic_event
|
163
|
-
@stream.verify
|
164
|
-
end
|
165
|
-
end
|
18
|
+
before do
|
19
|
+
@xmpp_comm = OmfCommon::Comm::XMPP::Communicator.new
|
20
|
+
OmfCommon::Eventloop.init(type: :em)
|
21
|
+
OmfCommon.stubs(:comm).returns(@xmpp_comm)
|
166
22
|
end
|
167
23
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
m1 = @xmpp.create_message([type: 'engine'])
|
172
|
-
m2 = @xmpp.create_message do |v|
|
173
|
-
v.property('type', 'engine')
|
174
|
-
end
|
175
|
-
m1.must_be_kind_of OmfCommon::TopicMessage
|
176
|
-
m2.must_be_kind_of OmfCommon::TopicMessage
|
177
|
-
m1.body.name.must_equal 'create'
|
178
|
-
m1.body.marshall[1].must_match /<property key="type" type="string">engine<\/property>/
|
179
|
-
m2.body.marshall[1].must_match /<property key="type" type="string">engine<\/property>/
|
180
|
-
end
|
181
|
-
|
182
|
-
it "must generate omf configure xml fragment" do
|
183
|
-
skip
|
184
|
-
m1 = @xmpp.configure_message([throttle: 50])
|
185
|
-
m2 = @xmpp.configure_message do |v|
|
186
|
-
v.property('throttle', 50)
|
187
|
-
end
|
188
|
-
m1.must_be_kind_of OmfCommon::TopicMessage
|
189
|
-
m2.must_be_kind_of OmfCommon::TopicMessage
|
190
|
-
m1.body.name.must_equal 'configure'
|
191
|
-
m1.body.marshall[1].must_match /<property key="throttle" type="integer">50<\/property>/
|
192
|
-
m2.body.marshall[1].must_match /<property key="throttle" type="integer">50<\/property>/
|
193
|
-
end
|
194
|
-
|
195
|
-
it "must generate omf inform xml fragment" do
|
196
|
-
skip
|
197
|
-
m1 = @xmpp.inform_message([itype: 'CREATION.OK'])
|
198
|
-
m2 = @xmpp.inform_message do |v|
|
199
|
-
v.property('itype', 'CREATION.OK')
|
200
|
-
end
|
201
|
-
m1.must_be_kind_of OmfCommon::TopicMessage
|
202
|
-
m2.must_be_kind_of OmfCommon::TopicMessage
|
203
|
-
m1.body.name.must_equal 'inform'
|
204
|
-
m1.body.marshall[1].must_match /<property key="itype" type="string">CREATION.OK<\/property>/
|
205
|
-
m2.body.marshall[1].must_match /<property key="itype" type="string">CREATION.OK<\/property>/
|
24
|
+
after do
|
25
|
+
em do
|
26
|
+
@xmpp_comm.init(url: 'xmpp://srv.mytestbed.net')
|
206
27
|
end
|
28
|
+
end
|
207
29
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
m1.must_be_kind_of OmfCommon::TopicMessage
|
215
|
-
m2.must_be_kind_of OmfCommon::TopicMessage
|
216
|
-
m1.body.name.must_equal 'release'
|
217
|
-
m1.body.marshall[1].must_match /<property key="res_id" type="integer">100<\/property>/
|
218
|
-
m2.body.marshall[1].must_match /<property key="res_id" type="integer">100<\/property>/
|
30
|
+
it "must allow you to connect" do
|
31
|
+
@xmpp_comm.on_connected do |c|
|
32
|
+
assert_equal :xmpp, c.conn_info[:proto]
|
33
|
+
assert_match /#{Socket.gethostname}/, c.conn_info[:user]
|
34
|
+
assert_kind_of OmfCommon::Comm::XMPP::Communicator, c
|
35
|
+
done
|
219
36
|
end
|
37
|
+
end
|
220
38
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
v.property('max_power')
|
228
|
-
end
|
229
|
-
m1.must_be_kind_of OmfCommon::TopicMessage
|
230
|
-
m2.must_be_kind_of OmfCommon::TopicMessage
|
231
|
-
m1.body.name.must_equal 'request'
|
232
|
-
m1.body.marshall[1].must_match /<property key="max_rpm"\/>/
|
233
|
-
m1.body.marshall[1].must_match /<property key="provider" type="hash">/
|
234
|
-
m2.body.marshall[1].must_match /<property key="provider" type="hash">/
|
235
|
-
m1.body.marshall[1].must_match /<country type="string">japan<\/country>/
|
236
|
-
m2.body.marshall[1].must_match /<country type="string">japan<\/country>/
|
237
|
-
m1.body.marshall[1].must_match /<property key="max_power"\/>/
|
39
|
+
it "must construct topic address string" do
|
40
|
+
@xmpp_comm.on_connected do |c|
|
41
|
+
t_name = SecureRandom.uuid
|
42
|
+
# TODO This format is different to AMQP
|
43
|
+
assert_match /xmpp:\/\/#{t_name}@/, c.string_to_topic_address(t_name)
|
44
|
+
done
|
238
45
|
end
|
239
46
|
end
|
240
47
|
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
OmfCommon.eventloop.every(0.05) { done! }
|
248
|
-
wait!
|
48
|
+
it "must allow you to create a new pubsub topic" do
|
49
|
+
@xmpp_comm.on_connected do |c|
|
50
|
+
t_name = SecureRandom.uuid.to_sym
|
51
|
+
c.create_topic(t_name)
|
52
|
+
assert_kind_of OmfCommon::Comm::XMPP::Topic, OmfCommon::Comm::Topic[t_name]
|
53
|
+
done
|
249
54
|
end
|
250
55
|
end
|
251
56
|
end
|
252
57
|
|
58
|
+
# describe "when communicating to xmpp server (via mocking)" do
|
59
|
+
# #include EM::MiniTest::Spec
|
60
|
+
#
|
61
|
+
# it "must be able to connect and tigger on_connected callbacks" do
|
62
|
+
# skip
|
63
|
+
# Blather::Client.stub :new, @client do
|
64
|
+
# @xmpp.jid.to_s.must_equal "bob@example.com"
|
65
|
+
#
|
66
|
+
# @xmpp.on_connected do |communicator|
|
67
|
+
# communicator.must_be_kind_of OmfCommon::Comm::XMPP::Communicator
|
68
|
+
# end
|
69
|
+
# @stream.verify
|
70
|
+
# end
|
71
|
+
# end
|
72
|
+
#
|
73
|
+
# it "must be able to disconnect" do
|
74
|
+
# skip
|
75
|
+
# Blather::Client.stub :new, @client do
|
76
|
+
# @stream.expect(:close_connection_after_writing, true)
|
77
|
+
# @xmpp.disconnect
|
78
|
+
# end
|
79
|
+
# end
|
80
|
+
#
|
81
|
+
# it "must be able to subscribe & trigger callback when subscribed" do
|
82
|
+
# skip
|
83
|
+
# Blather::Client.stub :new, @client do
|
84
|
+
# subscription = Blather::XMPPNode.parse(subscription_xml)
|
85
|
+
# write_callback = proc do |event|
|
86
|
+
# event.must_be_kind_of Blather::Stanza::PubSub::Subscribe
|
87
|
+
# subscription.id = event.id
|
88
|
+
# @client.receive_data subscription
|
89
|
+
# end
|
90
|
+
# @client.stub :write, write_callback do
|
91
|
+
# @xmpp.subscribe('xmpp_topic') do |topic|
|
92
|
+
# topic.must_be_kind_of OmfCommon::Comm::XMPP::Topic
|
93
|
+
# topic.id.must_equal :xmpp_topic
|
94
|
+
# done!
|
95
|
+
# end
|
96
|
+
# end
|
97
|
+
# end
|
98
|
+
# wait!
|
99
|
+
# end
|
100
|
+
#
|
101
|
+
# it "must be able to delete topic & trigger callback when topic deleted" do
|
102
|
+
# skip
|
103
|
+
# Blather::Client.stub :new, @client do
|
104
|
+
# deleted = Blather::XMPPNode.parse(fabulous_xmpp_empty_success_xml)
|
105
|
+
# write_callback = proc do |event|
|
106
|
+
# event.must_be_kind_of Blather::Stanza::PubSubOwner::Delete
|
107
|
+
# deleted.id = event.id
|
108
|
+
# @client.receive_data deleted
|
109
|
+
# end
|
110
|
+
# @client.stub :write, write_callback do
|
111
|
+
# @xmpp.delete_topic('xmpp_topic') do |stanza|
|
112
|
+
# done!
|
113
|
+
# end
|
114
|
+
# end
|
115
|
+
# end
|
116
|
+
# wait!
|
117
|
+
# end
|
118
|
+
#
|
119
|
+
# it "must be able to list affiliations (owned pubsub nodes) & react if received" do
|
120
|
+
# skip
|
121
|
+
# Blather::Client.stub :new, @client do
|
122
|
+
# affiliations = Blather::XMPPNode.parse(affiliations_xml)
|
123
|
+
# write_callback = proc do |event|
|
124
|
+
# event.must_be_kind_of Blather::Stanza::PubSub::Affiliations
|
125
|
+
# affiliations.id = event.id
|
126
|
+
# @client.receive_data affiliations
|
127
|
+
# end
|
128
|
+
# @client.stub :write, write_callback do
|
129
|
+
# @xmpp.affiliations { |event| puts event[:owner]; event[:owner].must_equal %w(node1 node2); done! }
|
130
|
+
# end
|
131
|
+
# end
|
132
|
+
# wait!
|
133
|
+
# end
|
134
|
+
#
|
135
|
+
# it "must be able to publish if message is valid" do
|
136
|
+
# skip
|
137
|
+
# Blather::Client.stub :new, @client do
|
138
|
+
# @stream.expect(:send, true, [Blather::Stanza::PubSub::Publish])
|
139
|
+
# @xmpp.publish 'xmpp_topic', OmfCommon::Message.create(:create, { type: 'test' })
|
140
|
+
# proc { @xmpp.publish 'xmpp_topic', OmfCommon::Message.create(:inform, nil, { blah: 'blah' })}.must_raise StandardError
|
141
|
+
# @stream.verify
|
142
|
+
# end
|
143
|
+
# end
|
144
|
+
#
|
145
|
+
# it "must trigger callback when item published" do
|
146
|
+
# skip
|
147
|
+
# Blather::Client.stub :new, @client do
|
148
|
+
# published = Blather::XMPPNode.parse(published_xml)
|
149
|
+
# write_callback = proc do |event|
|
150
|
+
# event.must_be_kind_of Blather::Stanza::PubSub::Publish
|
151
|
+
# published.id = event.id
|
152
|
+
# @client.receive_data published
|
153
|
+
# end
|
154
|
+
# @client.stub :write, write_callback do
|
155
|
+
# @xmpp.publish 'xmpp_topic', OmfCommon::Message.create(:create, { type: 'test' }) do |event|
|
156
|
+
# event.must_equal published
|
157
|
+
# done!
|
158
|
+
# end
|
159
|
+
# end
|
160
|
+
# end
|
161
|
+
# wait!
|
162
|
+
# end
|
163
|
+
#
|
164
|
+
# it "must be able to unsubscribe" do
|
165
|
+
# skip
|
166
|
+
# Blather::Client.stub :new, @client do
|
167
|
+
# @stream.expect(:send, true, [Blather::Stanza::PubSub::Subscriptions])
|
168
|
+
# @xmpp.unsubscribe
|
169
|
+
# @stream.verify
|
170
|
+
# end
|
171
|
+
# end
|
172
|
+
#
|
173
|
+
# it "must trigger callback when unsubscribed (all topics)" do
|
174
|
+
# skip
|
175
|
+
# Blather::Client.stub :new, @client do
|
176
|
+
# 2.times do
|
177
|
+
# @stream.expect(:send, true, [Blather::Stanza])
|
178
|
+
# end
|
179
|
+
#
|
180
|
+
# subscriptions = Blather::XMPPNode.parse(subscriptions_xml)
|
181
|
+
# write_callback = proc do |event|
|
182
|
+
# event.must_be_kind_of Blather::Stanza::PubSub::Subscriptions
|
183
|
+
# subscriptions.id = event.id
|
184
|
+
# @client.receive_data subscriptions
|
185
|
+
# end
|
186
|
+
# @client.stub :write, write_callback do
|
187
|
+
# @xmpp.unsubscribe
|
188
|
+
# end
|
189
|
+
# @stream.verify
|
190
|
+
# end
|
191
|
+
# end
|
192
|
+
#
|
193
|
+
# it "must be able to add a topic event handler" do
|
194
|
+
# skip
|
195
|
+
# Blather::Client.stub :new, @client do
|
196
|
+
# @xmpp.topic_event
|
197
|
+
# @stream.verify
|
198
|
+
# end
|
199
|
+
# end
|
200
|
+
# end
|
201
|
+
#
|
202
|
+
# describe "when omf message related methods" do
|
203
|
+
# it "must generate omf create xml fragment" do
|
204
|
+
# skip
|
205
|
+
# m1 = @xmpp.create_message([type: 'engine'])
|
206
|
+
# m2 = @xmpp.create_message do |v|
|
207
|
+
# v.property('type', 'engine')
|
208
|
+
# end
|
209
|
+
# m1.must_be_kind_of OmfCommon::TopicMessage
|
210
|
+
# m2.must_be_kind_of OmfCommon::TopicMessage
|
211
|
+
# m1.body.name.must_equal 'create'
|
212
|
+
# m1.body.marshall[1].must_match /<property key="type" type="string">engine<\/property>/
|
213
|
+
# m2.body.marshall[1].must_match /<property key="type" type="string">engine<\/property>/
|
214
|
+
# end
|
215
|
+
#
|
216
|
+
# it "must generate omf configure xml fragment" do
|
217
|
+
# skip
|
218
|
+
# m1 = @xmpp.configure_message([throttle: 50])
|
219
|
+
# m2 = @xmpp.configure_message do |v|
|
220
|
+
# v.property('throttle', 50)
|
221
|
+
# end
|
222
|
+
# m1.must_be_kind_of OmfCommon::TopicMessage
|
223
|
+
# m2.must_be_kind_of OmfCommon::TopicMessage
|
224
|
+
# m1.body.name.must_equal 'configure'
|
225
|
+
# m1.body.marshall[1].must_match /<property key="throttle" type="integer">50<\/property>/
|
226
|
+
# m2.body.marshall[1].must_match /<property key="throttle" type="integer">50<\/property>/
|
227
|
+
# end
|
228
|
+
#
|
229
|
+
# it "must generate omf inform xml fragment" do
|
230
|
+
# skip
|
231
|
+
# m1 = @xmpp.inform_message([itype: 'CREATION.OK'])
|
232
|
+
# m2 = @xmpp.inform_message do |v|
|
233
|
+
# v.property('itype', 'CREATION.OK')
|
234
|
+
# end
|
235
|
+
# m1.must_be_kind_of OmfCommon::TopicMessage
|
236
|
+
# m2.must_be_kind_of OmfCommon::TopicMessage
|
237
|
+
# m1.body.name.must_equal 'inform'
|
238
|
+
# m1.body.marshall[1].must_match /<property key="itype" type="string">CREATION.OK<\/property>/
|
239
|
+
# m2.body.marshall[1].must_match /<property key="itype" type="string">CREATION.OK<\/property>/
|
240
|
+
# end
|
241
|
+
#
|
242
|
+
# it "must generate omf release xml fragment" do
|
243
|
+
# skip
|
244
|
+
# m1 = @xmpp.release_message([res_id: 100])
|
245
|
+
# m2 = @xmpp.release_message do |v|
|
246
|
+
# v.property('res_id', 100)
|
247
|
+
# end
|
248
|
+
# m1.must_be_kind_of OmfCommon::TopicMessage
|
249
|
+
# m2.must_be_kind_of OmfCommon::TopicMessage
|
250
|
+
# m1.body.name.must_equal 'release'
|
251
|
+
# m1.body.marshall[1].must_match /<property key="res_id" type="integer">100<\/property>/
|
252
|
+
# m2.body.marshall[1].must_match /<property key="res_id" type="integer">100<\/property>/
|
253
|
+
# end
|
254
|
+
#
|
255
|
+
# it "must generate omf request xml fragment" do
|
256
|
+
# skip
|
257
|
+
# m1 = @xmpp.request_message([:max_rpm, {:provider => {country: 'japan'}}, :max_power])
|
258
|
+
# m2 = @xmpp.request_message do |v|
|
259
|
+
# v.property('max_rpm')
|
260
|
+
# v.property('provider', { country: 'japan' })
|
261
|
+
# v.property('max_power')
|
262
|
+
# end
|
263
|
+
# m1.must_be_kind_of OmfCommon::TopicMessage
|
264
|
+
# m2.must_be_kind_of OmfCommon::TopicMessage
|
265
|
+
# m1.body.name.must_equal 'request'
|
266
|
+
# m1.body.marshall[1].must_match /<property key="max_rpm"\/>/
|
267
|
+
# m1.body.marshall[1].must_match /<property key="provider" type="hash">/
|
268
|
+
# m2.body.marshall[1].must_match /<property key="provider" type="hash">/
|
269
|
+
# m1.body.marshall[1].must_match /<country type="string">japan<\/country>/
|
270
|
+
# m2.body.marshall[1].must_match /<country type="string">japan<\/country>/
|
271
|
+
# m1.body.marshall[1].must_match /<property key="max_power"\/>/
|
272
|
+
# end
|
273
|
+
# end
|
274
|
+
#
|
275
|
+
# describe "when use event machine style method" do
|
276
|
+
# #include EM::MiniTest::Spec
|
277
|
+
#
|
278
|
+
# it "must accept these methods and forward to event machine" do
|
279
|
+
# skip
|
280
|
+
# OmfCommon.eventloop.after(0.05) { done! }
|
281
|
+
# OmfCommon.eventloop.every(0.05) { done! }
|
282
|
+
# wait!
|
283
|
+
# end
|
284
|
+
# end
|
285
|
+
|