omf_common 6.1.2.pre.2 → 6.1.2.pre.3

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.
@@ -4,168 +4,212 @@
4
4
  # By downloading or using this software you accept the terms and the liability disclaimer in the License.
5
5
 
6
6
  require 'test_helper'
7
- require 'fixture/pubsub'
7
+ #require 'fixture/pubsub'
8
8
 
9
9
  require 'omf_common/comm/xmpp/communicator'
10
10
  require 'omf_common/comm/xmpp/topic'
11
11
 
12
12
  describe OmfCommon::Comm::XMPP::Topic do
13
- before do
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('n@d/r')
18
- @xmpp = OmfCommon::Comm::XMPP::Communicator.new
19
-
20
- OmfCommon.stub :comm, @xmpp do
21
- Blather::Client.stub :new, @client do
22
- @stream.expect(:send, true, [Blather::Stanza::PubSub::Create])
23
- @topic = OmfCommon::Comm::XMPP::Topic.create(:test_topic)
24
- end
25
- end
26
- end
27
-
28
- describe "when calling operation method" do
29
- include EM::MiniTest::Spec
30
-
31
- it "must send create message" do
32
- skip
33
- OmfCommon.stub :comm, @xmpp do
34
- Blather::Client.stub :new, @client do
35
- published = Blather::XMPPNode.parse(published_xml)
13
+ include EventedSpec::SpecHelper
36
14
 
37
- write_callback = proc do |event|
38
- event.must_be_kind_of Blather::Stanza::PubSub::Publish
39
- published.id = event.id
40
- @client.receive_data published
41
- end
15
+ # XMPP requires more time
16
+ default_timeout 3.1
42
17
 
43
- @client.stub :write, write_callback do
44
- @xmpp.stub :local_address, 'test_addr' do
45
- @topic.create(:bob, { hrn: 'bob' })
46
- end
47
- end
48
- end
49
- end
50
- end
51
-
52
- it "must trigger operation callbacks" do
53
- skip
54
- OmfCommon.stub :comm, @xmpp do
55
- Blather::Client.stub :new, @client do
56
- @client.stub :write, proc {} do
57
- @xmpp.stub :local_address, 'test_addr' do
58
- omf_create = OmfCommon::Message.create(:create, { type: 'engine' })
59
- omf_create.stub :mid, "bf840fe9-c176-4fae-b7de-6fc27f183f76" do
60
- warn omf_create.mid
61
- OmfCommon::Message.stub :create, omf_create do
62
- @topic.create(:bob, { hrn: 'bob' }) do |reply_msg|
63
- error 'bob'
64
- #reply_msg.cid.must_equal "bf840fe9-c176-4fae-b7de-6fc27f183f76"
65
- done!
66
- end
67
-
68
- @client.receive_data Blather::XMPPNode.parse(omf_created_xml)
69
- end
70
- end
71
- end
72
- end
73
- end
74
- 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)
22
+ end
75
23
 
76
- wait!
24
+ after do
25
+ em do
26
+ @xmpp_comm.init(url: 'xmpp://srv.mytestbed.net')
77
27
  end
78
28
  end
79
29
 
80
- describe "when informed message received" do
81
- include EM::MiniTest::Spec
82
-
83
- it "must react to omf created message" do
84
- skip
85
- OmfCommon.stub :comm, @xmpp do
86
- Blather::Client.stub :new, @client do
87
- omf_create = OmfCommon::Message.create(:create, { type: 'engine' })
88
- omf_create.stub :mid, "bf840fe9-c176-4fae-b7de-6fc27f183f76" do
89
- omf_created = Blather::XMPPNode.parse(omf_created_xml)
90
- @client.receive_data omf_created
91
- @topic.on_creation_ok(omf_create) do |n|
92
- OmfCommon::Message.parse(omf_created.items.first.payload) do |parsed_msg|
93
- n.stub :ts, parsed_msg.ts do
94
- n.must_equal parsed_msg
95
- end
96
- done!
97
- end
98
- end
99
- end
100
- end
101
- end
102
- wait!
103
- end
30
+ it "must allow you to subscribe/unsubscribe to a new pubsub topic" do
31
+ @xmpp_comm.on_connected do |c|
32
+ t_name = SecureRandom.uuid.to_sym
33
+ c.subscribe(t_name) do |topic|
34
+ assert_kind_of OmfCommon::Comm::XMPP::Topic, topic
35
+ assert_match /xmpp:\/\/#{t_name}@/, topic.address
104
36
 
105
- it "must react to omf status message" do
106
- skip
107
- OmfCommon.stub :comm, @xmpp do
108
- Blather::Client.stub :new, @client do
109
- omf_request = OmfCommon::Message.create(:request, [:bob])
110
- omf_request.stub :mid, "bf840fe9-c176-4fae-b7de-6fc27f183f76" do
111
- omf_status = Blather::XMPPNode.parse(omf_status_xml)
112
- @client.receive_data omf_status
113
- @topic.on_status(omf_request) do |n|
114
- OmfCommon::Message.parse(omf_status.items.first.payload) do |parsed_msg|
115
- n.stub :ts, parsed_msg.ts do
116
- n.must_equal parsed_msg
117
- end
118
- done!
119
- end
120
- end
121
- end
122
- end
37
+ topic.unsubscribe(t_name)
38
+ done
123
39
  end
124
- wait!
125
40
  end
41
+ end
126
42
 
127
- it "must react to omf release message" do
128
- skip
129
- OmfCommon.stub :comm, @xmpp do
130
- Blather::Client.stub :new, @client do
131
- omf_release = OmfCommon::Message.create(:release, nil, { res_id: '100' })
132
- omf_release.stub :mid, "bf840fe9-c176-4fae-b7de-6fc27f183f76" do
133
- omf_released = Blather::XMPPNode.parse(omf_released_xml)
134
- @client.receive_data omf_released
135
- @topic.on_released(omf_release) do |n|
136
- OmfCommon::Message.parse(omf_released.items.first.payload) do |parsed_msg|
137
- n.stub :ts, parsed_msg.ts do
138
- n.must_equal parsed_msg
139
- end
140
- done!
141
- end
142
- end
143
- end
144
- end
145
- end
146
- wait!
147
- end
43
+ it "must allow you to send and monitor messages" do
44
+ @xmpp_comm.on_connected do |c|
45
+ t_name = SecureRandom.uuid.to_sym
46
+ c.subscribe(t_name) do |topic|
47
+ topic.inform('STATUS', attr_1: 'xxx')
148
48
 
149
- it "must react to omf failed message" do
150
- skip
151
- OmfCommon.stub :comm, @xmpp do
152
- Blather::Client.stub :new, @client do
153
- omf_create = OmfCommon::Message.create(:create, { type: 'engine' })
154
- omf_create.stub :mid, "bf840fe9-c176-4fae-b7de-6fc27f183f76" do
155
- omf_failed = Blather::XMPPNode.parse(omf_failed_xml)
156
- @client.receive_data omf_failed
157
- @topic.on_creation_failed(omf_create) do |n|
158
- OmfCommon::Message.parse(omf_failed.items.first.payload) do |parsed_msg|
159
- n.stub :ts, parsed_msg.ts do
160
- n.must_equal parsed_msg
161
- end
162
- done!
163
- end
164
- end
165
- end
49
+ topic.on_message do |msg|
50
+ assert_equal 'xxx', msg[:attr_1]
51
+ done
166
52
  end
167
53
  end
168
- wait!
169
54
  end
170
55
  end
171
56
  end
57
+ # before do
58
+ # @client = Blather::Client.new
59
+ # @stream = MiniTest::Mock.new
60
+ # @stream.expect(:send, true, [Blather::Stanza])
61
+ # @client.post_init @stream, Blather::JID.new('n@d/r')
62
+ # @xmpp = OmfCommon::Comm::XMPP::Communicator.new
63
+ #
64
+ # OmfCommon.stub :comm, @xmpp do
65
+ # Blather::Client.stub :new, @client do
66
+ # @stream.expect(:send, true, [Blather::Stanza::PubSub::Create])
67
+ # @topic = OmfCommon::Comm::XMPP::Topic.create(:test_topic)
68
+ # end
69
+ # end
70
+ # end
71
+ #
72
+ # describe "when calling operation method" do
73
+ # include EM::MiniTest::Spec
74
+ #
75
+ # it "must send create message" do
76
+ # skip
77
+ # OmfCommon.stub :comm, @xmpp do
78
+ # Blather::Client.stub :new, @client do
79
+ # published = Blather::XMPPNode.parse(published_xml)
80
+ #
81
+ # write_callback = proc do |event|
82
+ # event.must_be_kind_of Blather::Stanza::PubSub::Publish
83
+ # published.id = event.id
84
+ # @client.receive_data published
85
+ # end
86
+ #
87
+ # @client.stub :write, write_callback do
88
+ # @xmpp.stub :local_address, 'test_addr' do
89
+ # @topic.create(:bob, { hrn: 'bob' })
90
+ # end
91
+ # end
92
+ # end
93
+ # end
94
+ # end
95
+ #
96
+ # it "must trigger operation callbacks" do
97
+ # skip
98
+ # OmfCommon.stub :comm, @xmpp do
99
+ # Blather::Client.stub :new, @client do
100
+ # @client.stub :write, proc {} do
101
+ # @xmpp.stub :local_address, 'test_addr' do
102
+ # omf_create = OmfCommon::Message.create(:create, { type: 'engine' })
103
+ # omf_create.stub :mid, "bf840fe9-c176-4fae-b7de-6fc27f183f76" do
104
+ # warn omf_create.mid
105
+ # OmfCommon::Message.stub :create, omf_create do
106
+ # @topic.create(:bob, { hrn: 'bob' }) do |reply_msg|
107
+ # error 'bob'
108
+ # #reply_msg.cid.must_equal "bf840fe9-c176-4fae-b7de-6fc27f183f76"
109
+ # done!
110
+ # end
111
+ #
112
+ # @client.receive_data Blather::XMPPNode.parse(omf_created_xml)
113
+ # end
114
+ # end
115
+ # end
116
+ # end
117
+ # end
118
+ # end
119
+ #
120
+ # wait!
121
+ # end
122
+ # end
123
+ #
124
+ # describe "when informed message received" do
125
+ # include EM::MiniTest::Spec
126
+ #
127
+ # it "must react to omf created message" do
128
+ # skip
129
+ # OmfCommon.stub :comm, @xmpp do
130
+ # Blather::Client.stub :new, @client do
131
+ # omf_create = OmfCommon::Message.create(:create, { type: 'engine' })
132
+ # omf_create.stub :mid, "bf840fe9-c176-4fae-b7de-6fc27f183f76" do
133
+ # omf_created = Blather::XMPPNode.parse(omf_created_xml)
134
+ # @client.receive_data omf_created
135
+ # @topic.on_creation_ok(omf_create) do |n|
136
+ # OmfCommon::Message.parse(omf_created.items.first.payload) do |parsed_msg|
137
+ # n.stub :ts, parsed_msg.ts do
138
+ # n.must_equal parsed_msg
139
+ # end
140
+ # done!
141
+ # end
142
+ # end
143
+ # end
144
+ # end
145
+ # end
146
+ # wait!
147
+ # end
148
+ #
149
+ # it "must react to omf status message" do
150
+ # skip
151
+ # OmfCommon.stub :comm, @xmpp do
152
+ # Blather::Client.stub :new, @client do
153
+ # omf_request = OmfCommon::Message.create(:request, [:bob])
154
+ # omf_request.stub :mid, "bf840fe9-c176-4fae-b7de-6fc27f183f76" do
155
+ # omf_status = Blather::XMPPNode.parse(omf_status_xml)
156
+ # @client.receive_data omf_status
157
+ # @topic.on_status(omf_request) do |n|
158
+ # OmfCommon::Message.parse(omf_status.items.first.payload) do |parsed_msg|
159
+ # n.stub :ts, parsed_msg.ts do
160
+ # n.must_equal parsed_msg
161
+ # end
162
+ # done!
163
+ # end
164
+ # end
165
+ # end
166
+ # end
167
+ # end
168
+ # wait!
169
+ # end
170
+ #
171
+ # it "must react to omf release message" do
172
+ # skip
173
+ # OmfCommon.stub :comm, @xmpp do
174
+ # Blather::Client.stub :new, @client do
175
+ # omf_release = OmfCommon::Message.create(:release, nil, { res_id: '100' })
176
+ # omf_release.stub :mid, "bf840fe9-c176-4fae-b7de-6fc27f183f76" do
177
+ # omf_released = Blather::XMPPNode.parse(omf_released_xml)
178
+ # @client.receive_data omf_released
179
+ # @topic.on_released(omf_release) do |n|
180
+ # OmfCommon::Message.parse(omf_released.items.first.payload) do |parsed_msg|
181
+ # n.stub :ts, parsed_msg.ts do
182
+ # n.must_equal parsed_msg
183
+ # end
184
+ # done!
185
+ # end
186
+ # end
187
+ # end
188
+ # end
189
+ # end
190
+ # wait!
191
+ # end
192
+ #
193
+ # it "must react to omf failed message" do
194
+ # skip
195
+ # OmfCommon.stub :comm, @xmpp do
196
+ # Blather::Client.stub :new, @client do
197
+ # omf_create = OmfCommon::Message.create(:create, { type: 'engine' })
198
+ # omf_create.stub :mid, "bf840fe9-c176-4fae-b7de-6fc27f183f76" do
199
+ # omf_failed = Blather::XMPPNode.parse(omf_failed_xml)
200
+ # @client.receive_data omf_failed
201
+ # @topic.on_creation_failed(omf_create) do |n|
202
+ # OmfCommon::Message.parse(omf_failed.items.first.payload) do |parsed_msg|
203
+ # n.stub :ts, parsed_msg.ts do
204
+ # n.must_equal parsed_msg
205
+ # end
206
+ # done!
207
+ # end
208
+ # end
209
+ # end
210
+ # end
211
+ # end
212
+ # wait!
213
+ # end
214
+ # end
215
+ #end
@@ -57,14 +57,12 @@ describe OmfCommon::Comm do
57
57
  lambda { OmfCommon::Comm.init(provider: { constructor: {}, require: {} }) }.must_raise TypeError
58
58
  end
59
59
 
60
- it 'must fail if already initialised' do
60
+ it 'wont fail if already initialised' do
61
61
  OmfCommon::Comm::Local::Communicator.any_instance.stubs(:on_connected)
62
62
  OmfCommon::Message.stubs(:init)
63
- error = lambda do
64
- OmfCommon::Comm.init(type: :local)
65
- OmfCommon::Comm.init(type: :local)
66
- end.call rescue $!
67
- error.message.must_match /Comms layer already initialised/
63
+
64
+ OmfCommon::Comm.init(type: :local)
65
+ OmfCommon::Comm.init(type: :local)
68
66
  end
69
67
 
70
68
  it 'must handle auth options and be able to return singleton instance' do
@@ -11,10 +11,9 @@ include OmfCommon
11
11
  describe OmfCommon::Message::XML::Message do
12
12
  describe "when create message initialised" do
13
13
  before do
14
- # We will test prop value other than just strings
15
14
  @message = Message::XML::Message.create(:create,
16
- { type: 'bob', p1: 'p1_value', p2: { unit: 'u', precision: 2 } },
17
- { rtype: 'bob', guard: { p1: 'p1_value' } })
15
+ { type: 'bob', p1: 'p1_value', p2: { unit: 'u', precision: 2 } },
16
+ { rtype: 'bob', guard: { p1: 'p1_value' } })
18
17
  end
19
18
 
20
19
  it "must to be validated using relaxng schema" do
@@ -9,6 +9,8 @@ describe OmfCommon::Message do
9
9
  describe "when initialised" do
10
10
  before do
11
11
  @internal_attr = %w(type operation guard mid ts replyto cid itype)
12
+ # TODO Abstract message class does NOT provide most of method implementation
13
+ OmfCommon::Message.init(type: :xml)
12
14
  @message = OmfCommon::Message.create(:create, { p1: 'p1_value', p2: 'p2_value' }, { rtype: :bob })
13
15
  end
14
16
 
@@ -38,6 +40,7 @@ describe OmfCommon::Message do
38
40
  end
39
41
 
40
42
  it "must evaluate erb code when read property with evaluate option is true" do
43
+ # TODO need to find a way to pass remote eval expression
41
44
  skip
42
45
  @message[:p3] = "1 + 1 = <%= 1 + 1 %>"
43
46
  @message[:p4] = "1 + 1 = <%= two %>"
data/test/test_helper.rb CHANGED
@@ -4,22 +4,30 @@
4
4
  # By downloading or using this software you accept the terms and the liability disclaimer in the License.
5
5
 
6
6
  require 'simplecov'
7
+ # Generate coverage
7
8
  SimpleCov.start { add_filter "/test" }
8
9
 
10
+ # Setup MiniTest
9
11
  gem 'minitest'
12
+
10
13
  require 'minitest/autorun'
11
14
  require 'minitest/pride'
12
15
  require 'minitest/spec'
13
16
  require 'minitest/mock'
14
- require 'em/minitest/spec'
17
+
18
+ # Spec helper to test async
19
+ require 'evented-spec'
20
+
21
+ # Use mocha for Mocking and Stubbing
15
22
  require 'mocha/setup'
16
23
 
17
- require 'omf_common'
18
- require 'blather/client/dsl'
24
+ require 'securerandom'
25
+
26
+ #require 'em/minitest/spec'
19
27
 
20
- require 'singleton'
28
+ require 'omf_common'
21
29
 
22
- OmfCommon::Message.init(type: :xml)
30
+ #require 'blather/client/dsl'
23
31
 
24
32
  # Shut up all the loggers
25
33
  Logging.logger.root.clear_appenders
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omf_common
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.2.pre.2
4
+ version: 6.1.2.pre.3
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-29 00:00:00.000000000 Z
12
+ date: 2014-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -28,21 +28,21 @@ dependencies:
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
30
  - !ruby/object:Gem::Dependency
31
- name: em-minitest-spec
31
+ name: evented-spec
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - ! '>='
35
+ - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: '0'
37
+ version: 1.0.0.beta
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ! '>='
43
+ - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: '0'
45
+ version: 1.0.0.beta
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: simplecov
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -302,14 +302,12 @@ files:
302
302
  - lib/omf_common/message/json/json_message.rb
303
303
  - lib/omf_common/message/xml/message.rb
304
304
  - lib/omf_common/message/xml/relaxng_schema.rb
305
- - lib/omf_common/message/xml/topic_message.rb
306
305
  - lib/omf_common/protocol/6.0.rnc
307
306
  - lib/omf_common/protocol/6.0.rng
308
307
  - lib/omf_common/version.rb
309
308
  - omf_common.gemspec
310
309
  - test/fixture/1st_level.pem
311
310
  - test/fixture/2nd_level.pem
312
- - test/fixture/3rd_level.pem
313
311
  - test/fixture/alice-cert.pem
314
312
  - test/fixture/alice-key.pem
315
313
  - test/fixture/omf_test.cert.pem
@@ -322,6 +320,7 @@ files:
322
320
  - test/omf_common/auth/certificate_spec.rb
323
321
  - test/omf_common/auth/certificate_store_spec.rb
324
322
  - test/omf_common/auth/ssh_pub_key_convert_spec.rb
323
+ - test/omf_common/comm/amqp/communicator_spec.rb
325
324
  - test/omf_common/comm/topic_spec.rb
326
325
  - test/omf_common/comm/xmpp/communicator_spec.rb
327
326
  - test/omf_common/comm/xmpp/topic_spec.rb
@@ -352,7 +351,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
352
351
  version: 1.3.1
353
352
  requirements: []
354
353
  rubyforge_project: omf_common
355
- rubygems_version: 1.8.28
354
+ rubygems_version: 1.8.23
356
355
  signing_key:
357
356
  specification_version: 3
358
357
  summary: Common library of OMF