omf_common 6.0.0.pre.10 → 6.0.0.pre.11
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/monitor_topic.rb +80 -0
- data/bin/send_create.rb +94 -0
- data/bin/send_request.rb +58 -0
- data/example/engine_alt.rb +136 -0
- data/example/vm_alt.rb +65 -0
- data/lib/omf_common.rb +224 -3
- data/lib/omf_common/comm.rb +113 -46
- data/lib/omf_common/comm/amqp/amqp_communicator.rb +76 -0
- data/lib/omf_common/comm/amqp/amqp_topic.rb +91 -0
- data/lib/omf_common/comm/local/local_communicator.rb +64 -0
- data/lib/omf_common/comm/local/local_topic.rb +42 -0
- data/lib/omf_common/comm/topic.rb +190 -0
- data/lib/omf_common/{dsl/xmpp.rb → comm/xmpp/communicator.rb} +93 -53
- data/lib/omf_common/comm/xmpp/topic.rb +147 -0
- data/lib/omf_common/{dsl → comm/xmpp}/xmpp_mp.rb +2 -0
- data/lib/omf_common/eventloop.rb +94 -0
- data/lib/omf_common/eventloop/em.rb +57 -0
- data/lib/omf_common/eventloop/local_evl.rb +78 -0
- data/lib/omf_common/message.rb +112 -229
- data/lib/omf_common/message/json/json_message.rb +129 -0
- data/lib/omf_common/message/xml/message.rb +410 -0
- data/lib/omf_common/message/xml/relaxng_schema.rb +17 -0
- data/lib/omf_common/message/xml/topic_message.rb +20 -0
- data/lib/omf_common/protocol/6.0.rnc +11 -21
- data/lib/omf_common/protocol/6.0.rng +52 -119
- data/lib/omf_common/version.rb +1 -1
- data/omf_common.gemspec +4 -2
- data/test/fixture/pubsub.rb +19 -19
- data/test/omf_common/{dsl/xmpp_spec.rb → comm/xmpp/communicator_spec.rb} +47 -111
- data/test/omf_common/comm/xmpp/topic_spec.rb +113 -0
- data/test/omf_common/comm_spec.rb +1 -0
- data/test/omf_common/message/xml/message_spec.rb +136 -0
- data/test/omf_common/message_spec.rb +37 -131
- data/test/test_helper.rb +4 -1
- metadata +38 -28
- data/lib/omf_common/core_ext/object.rb +0 -21
- data/lib/omf_common/relaxng_schema.rb +0 -17
- data/lib/omf_common/topic.rb +0 -34
- data/lib/omf_common/topic_message.rb +0 -20
- data/test/omf_common/topic_message_spec.rb +0 -114
- data/test/omf_common/topic_spec.rb +0 -75
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module OmfCommon
|
4
|
+
class RelaxNGSchema
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
SCHEMA_FILE = "#{File.dirname(__FILE__)}/../../protocol/#{OmfCommon::PROTOCOL_VERSION}.rng"
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@rng = File.read(SCHEMA_FILE)
|
11
|
+
end
|
12
|
+
|
13
|
+
def validate(document)
|
14
|
+
Nokogiri::XML::RelaxNG(@rng).validate(document)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# module OmfCommon
|
2
|
+
# class TopicMessage
|
3
|
+
# attr_accessor :body, :comm
|
4
|
+
#
|
5
|
+
# def initialize(body, comm)
|
6
|
+
# self.body ||= body
|
7
|
+
# self.comm ||= comm
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# def publish(topic_id, &block)
|
11
|
+
# comm.publish(topic_id, body.dup, &block)
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# %w(created status failed released).each do |itype|
|
15
|
+
# define_method("on_inform_#{itype}") do |*args, &message_block|
|
16
|
+
# comm.send("on_#{itype}_message", body, &message_block)
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
# end
|
@@ -2,47 +2,37 @@ default namespace = "http://schema.mytestbed.net/omf/6.0/protocol"
|
|
2
2
|
|
3
3
|
start = (create | configure | request | release | inform)
|
4
4
|
|
5
|
-
common_elements = attribute
|
5
|
+
common_elements = attribute mid { text }?
|
6
|
+
& element ts { text }
|
7
|
+
& element src { text }?
|
8
|
+
& element replyto { text }?
|
9
|
+
& element props { property * }?
|
10
|
+
& element guard { property * }?
|
6
11
|
|
7
12
|
anything = ( text | element * { (attribute type { text })?, (text | anything) * })
|
8
13
|
|
9
|
-
|
14
|
+
property = element * { (attribute type { text })?, anything * }
|
10
15
|
|
11
16
|
create = element create {
|
12
17
|
common_elements
|
13
|
-
& element
|
14
|
-
& element guard { element property { prop_content } * }?
|
15
|
-
& element property { prop_content } *
|
18
|
+
& element rtype { text }
|
16
19
|
}
|
17
20
|
|
18
21
|
configure = element configure {
|
19
22
|
common_elements
|
20
|
-
& element publish_to { text }?
|
21
|
-
& element guard { element property { prop_content } * }?
|
22
|
-
& element property { prop_content } *
|
23
23
|
}
|
24
24
|
|
25
25
|
request = element request {
|
26
26
|
common_elements
|
27
|
-
& element publish_to { text }?
|
28
|
-
& element guard { element property { prop_content } * }?
|
29
|
-
& element property { prop_content } *
|
30
27
|
}
|
31
28
|
|
32
29
|
release = element release {
|
33
30
|
common_elements
|
34
|
-
& element
|
35
|
-
& element resource_id { text }
|
36
|
-
& element guard { element property { prop_content } * }?
|
37
|
-
& element property { prop_content } *
|
31
|
+
& element res_id { text }?
|
38
32
|
}
|
39
33
|
|
40
34
|
inform = element inform {
|
41
35
|
common_elements
|
42
|
-
& element
|
43
|
-
& element
|
44
|
-
& element resource_id { text }?
|
45
|
-
& element resource_address { text }?
|
46
|
-
& element reason { text }?
|
47
|
-
& element property { prop_content } *
|
36
|
+
& element cid { text }?
|
37
|
+
& element itype { "CREATION.OK" | "CREATION.FAILED" | "STATUS" | "RELEASED" | "ERROR" | "WARN" }
|
48
38
|
}
|
@@ -10,12 +10,38 @@
|
|
10
10
|
</choice>
|
11
11
|
</start>
|
12
12
|
<define name="common_elements">
|
13
|
-
<
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
<
|
18
|
-
|
13
|
+
<interleave>
|
14
|
+
<optional>
|
15
|
+
<attribute name="mid"/>
|
16
|
+
</optional>
|
17
|
+
<element name="ts">
|
18
|
+
<text/>
|
19
|
+
</element>
|
20
|
+
<optional>
|
21
|
+
<element name="src">
|
22
|
+
<text/>
|
23
|
+
</element>
|
24
|
+
</optional>
|
25
|
+
<optional>
|
26
|
+
<element name="replyto">
|
27
|
+
<text/>
|
28
|
+
</element>
|
29
|
+
</optional>
|
30
|
+
<optional>
|
31
|
+
<element name="props">
|
32
|
+
<zeroOrMore>
|
33
|
+
<ref name="property"/>
|
34
|
+
</zeroOrMore>
|
35
|
+
</element>
|
36
|
+
</optional>
|
37
|
+
<optional>
|
38
|
+
<element name="guard">
|
39
|
+
<zeroOrMore>
|
40
|
+
<ref name="property"/>
|
41
|
+
</zeroOrMore>
|
42
|
+
</element>
|
43
|
+
</optional>
|
44
|
+
</interleave>
|
19
45
|
</define>
|
20
46
|
<define name="anything">
|
21
47
|
<choice>
|
@@ -34,91 +60,35 @@
|
|
34
60
|
</element>
|
35
61
|
</choice>
|
36
62
|
</define>
|
37
|
-
<define name="
|
38
|
-
<
|
39
|
-
|
40
|
-
<
|
41
|
-
|
42
|
-
|
43
|
-
<
|
44
|
-
|
63
|
+
<define name="property">
|
64
|
+
<element>
|
65
|
+
<anyName/>
|
66
|
+
<optional>
|
67
|
+
<attribute name="type"/>
|
68
|
+
</optional>
|
69
|
+
<zeroOrMore>
|
70
|
+
<ref name="anything"/>
|
71
|
+
</zeroOrMore>
|
72
|
+
</element>
|
45
73
|
</define>
|
46
74
|
<define name="create">
|
47
75
|
<element name="create">
|
48
76
|
<interleave>
|
49
77
|
<ref name="common_elements"/>
|
50
|
-
<
|
51
|
-
<
|
52
|
-
|
53
|
-
</element>
|
54
|
-
</optional>
|
55
|
-
<optional>
|
56
|
-
<element name="guard">
|
57
|
-
<zeroOrMore>
|
58
|
-
<element name="property">
|
59
|
-
<ref name="prop_content"/>
|
60
|
-
</element>
|
61
|
-
</zeroOrMore>
|
62
|
-
</element>
|
63
|
-
</optional>
|
64
|
-
<zeroOrMore>
|
65
|
-
<element name="property">
|
66
|
-
<ref name="prop_content"/>
|
67
|
-
</element>
|
68
|
-
</zeroOrMore>
|
78
|
+
<element name="rtype">
|
79
|
+
<text/>
|
80
|
+
</element>
|
69
81
|
</interleave>
|
70
82
|
</element>
|
71
83
|
</define>
|
72
84
|
<define name="configure">
|
73
85
|
<element name="configure">
|
74
|
-
<
|
75
|
-
<ref name="common_elements"/>
|
76
|
-
<optional>
|
77
|
-
<element name="publish_to">
|
78
|
-
<text/>
|
79
|
-
</element>
|
80
|
-
</optional>
|
81
|
-
<optional>
|
82
|
-
<element name="guard">
|
83
|
-
<zeroOrMore>
|
84
|
-
<element name="property">
|
85
|
-
<ref name="prop_content"/>
|
86
|
-
</element>
|
87
|
-
</zeroOrMore>
|
88
|
-
</element>
|
89
|
-
</optional>
|
90
|
-
<zeroOrMore>
|
91
|
-
<element name="property">
|
92
|
-
<ref name="prop_content"/>
|
93
|
-
</element>
|
94
|
-
</zeroOrMore>
|
95
|
-
</interleave>
|
86
|
+
<ref name="common_elements"/>
|
96
87
|
</element>
|
97
88
|
</define>
|
98
89
|
<define name="request">
|
99
90
|
<element name="request">
|
100
|
-
<
|
101
|
-
<ref name="common_elements"/>
|
102
|
-
<optional>
|
103
|
-
<element name="publish_to">
|
104
|
-
<text/>
|
105
|
-
</element>
|
106
|
-
</optional>
|
107
|
-
<optional>
|
108
|
-
<element name="guard">
|
109
|
-
<zeroOrMore>
|
110
|
-
<element name="property">
|
111
|
-
<ref name="prop_content"/>
|
112
|
-
</element>
|
113
|
-
</zeroOrMore>
|
114
|
-
</element>
|
115
|
-
</optional>
|
116
|
-
<zeroOrMore>
|
117
|
-
<element name="property">
|
118
|
-
<ref name="prop_content"/>
|
119
|
-
</element>
|
120
|
-
</zeroOrMore>
|
121
|
-
</interleave>
|
91
|
+
<ref name="common_elements"/>
|
122
92
|
</element>
|
123
93
|
</define>
|
124
94
|
<define name="release">
|
@@ -126,27 +96,10 @@
|
|
126
96
|
<interleave>
|
127
97
|
<ref name="common_elements"/>
|
128
98
|
<optional>
|
129
|
-
<element name="
|
99
|
+
<element name="res_id">
|
130
100
|
<text/>
|
131
101
|
</element>
|
132
102
|
</optional>
|
133
|
-
<element name="resource_id">
|
134
|
-
<text/>
|
135
|
-
</element>
|
136
|
-
<optional>
|
137
|
-
<element name="guard">
|
138
|
-
<zeroOrMore>
|
139
|
-
<element name="property">
|
140
|
-
<ref name="prop_content"/>
|
141
|
-
</element>
|
142
|
-
</zeroOrMore>
|
143
|
-
</element>
|
144
|
-
</optional>
|
145
|
-
<zeroOrMore>
|
146
|
-
<element name="property">
|
147
|
-
<ref name="prop_content"/>
|
148
|
-
</element>
|
149
|
-
</zeroOrMore>
|
150
103
|
</interleave>
|
151
104
|
</element>
|
152
105
|
</define>
|
@@ -155,40 +108,20 @@
|
|
155
108
|
<interleave>
|
156
109
|
<ref name="common_elements"/>
|
157
110
|
<optional>
|
158
|
-
<element name="
|
111
|
+
<element name="cid">
|
159
112
|
<text/>
|
160
113
|
</element>
|
161
114
|
</optional>
|
162
|
-
<element name="
|
115
|
+
<element name="itype">
|
163
116
|
<choice>
|
164
|
-
<value>
|
165
|
-
<value>FAILED</value>
|
117
|
+
<value>CREATION.OK</value>
|
118
|
+
<value>CREATION.FAILED</value>
|
166
119
|
<value>STATUS</value>
|
167
120
|
<value>RELEASED</value>
|
168
121
|
<value>ERROR</value>
|
169
122
|
<value>WARN</value>
|
170
123
|
</choice>
|
171
124
|
</element>
|
172
|
-
<optional>
|
173
|
-
<element name="resource_id">
|
174
|
-
<text/>
|
175
|
-
</element>
|
176
|
-
</optional>
|
177
|
-
<optional>
|
178
|
-
<element name="resource_address">
|
179
|
-
<text/>
|
180
|
-
</element>
|
181
|
-
</optional>
|
182
|
-
<optional>
|
183
|
-
<element name="reason">
|
184
|
-
<text/>
|
185
|
-
</element>
|
186
|
-
</optional>
|
187
|
-
<zeroOrMore>
|
188
|
-
<element name="property">
|
189
|
-
<ref name="prop_content"/>
|
190
|
-
</element>
|
191
|
-
</zeroOrMore>
|
192
125
|
</interleave>
|
193
126
|
</element>
|
194
127
|
</define>
|
data/lib/omf_common/version.rb
CHANGED
data/omf_common.gemspec
CHANGED
@@ -7,9 +7,11 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = OmfCommon::VERSION
|
8
8
|
s.authors = ["NICTA"]
|
9
9
|
s.email = ["omf-user@lists.nicta.com.au"]
|
10
|
-
s.homepage = "
|
10
|
+
s.homepage = "http://omf.mytestbed.net"
|
11
11
|
s.summary = %q{Common library of OMF}
|
12
12
|
s.description = %q{Common library of OMF, a generic framework for controlling and managing networking testbeds.}
|
13
|
+
s.required_ruby_version = '>= 1.9.3'
|
14
|
+
s.license = 'MIT'
|
13
15
|
|
14
16
|
s.rubyforge_project = "omf_common"
|
15
17
|
|
@@ -23,7 +25,7 @@ Gem::Specification.new do |s|
|
|
23
25
|
s.add_development_dependency "em-minitest-spec", "~> 1.1.1"
|
24
26
|
s.add_development_dependency "simplecov"
|
25
27
|
s.add_runtime_dependency "eventmachine", "~> 0.12.10"
|
26
|
-
s.add_runtime_dependency "blather", "= 0.8.
|
28
|
+
s.add_runtime_dependency "blather", "= 0.8.1"
|
27
29
|
s.add_runtime_dependency "logging", "~> 1.7.1"
|
28
30
|
s.add_runtime_dependency "hashie", "~> 1.2.0"
|
29
31
|
s.add_runtime_dependency "oml4r", "~> 2.8.0"
|
data/test/fixture/pubsub.rb
CHANGED
@@ -170,13 +170,12 @@ def omf_created_xml
|
|
170
170
|
<<-NODE
|
171
171
|
<message from="pubsub.localhost" to="bravo@localhost" id="mclaren__bravo@localhost__FT6ea">
|
172
172
|
<event xmlns="http://jabber.org/protocol/pubsub#event">
|
173
|
-
<items node="
|
173
|
+
<items node="test_topic">
|
174
174
|
<item id="4JMgcKzxFDLsP74">
|
175
|
-
<inform xmlns="http://schema.mytestbed.net/omf/6.0/protocol"
|
176
|
-
<
|
177
|
-
<
|
178
|
-
<
|
179
|
-
<resource_address>444f17fb-546e-4685-a0d0-63e64fa046c8</resource_address>
|
175
|
+
<inform xmlns="http://schema.mytestbed.net/omf/6.0/protocol" mid="a2b6aba9f11dc5bb88306a32d0720641f5020c1f">
|
176
|
+
<cid>bf840fe9-c176-4fae-b7de-6fc27f183f76</cid>
|
177
|
+
<itype>CREATION.OK</itype>
|
178
|
+
<res_id>444f17fb-546e-4685-a0d0-63e64fa046c8</res_id>
|
180
179
|
</inform>
|
181
180
|
</item>
|
182
181
|
</items>
|
@@ -192,11 +191,11 @@ def omf_status_xml
|
|
192
191
|
<<-NODE
|
193
192
|
<message from="pubsub.localhost" to="bravo@localhost" id="mclaren__bravo@localhost__FT6ea">
|
194
193
|
<event xmlns="http://jabber.org/protocol/pubsub#event">
|
195
|
-
<items node="
|
194
|
+
<items node="test_topic">
|
196
195
|
<item id="4JMgcKzxFDLsP74">
|
197
|
-
<inform xmlns="http://schema.mytestbed.net/omf/6.0/protocol"
|
198
|
-
<
|
199
|
-
<
|
196
|
+
<inform xmlns="http://schema.mytestbed.net/omf/6.0/protocol" mid="a2b6aba9f11dc5bb88306a32d0720641f5020c1f">
|
197
|
+
<cid>bf840fe9-c176-4fae-b7de-6fc27f183f76</cid>
|
198
|
+
<itype>STATUS</itype>
|
200
199
|
<property key="bob">bob</property>
|
201
200
|
</inform>
|
202
201
|
</item>
|
@@ -213,11 +212,11 @@ def omf_failed_xml
|
|
213
212
|
<<-NODE
|
214
213
|
<message from="pubsub.localhost" to="bravo@localhost" id="mclaren__bravo@localhost__FT6ea">
|
215
214
|
<event xmlns="http://jabber.org/protocol/pubsub#event">
|
216
|
-
<items node="
|
215
|
+
<items node="test_topic">
|
217
216
|
<item id="4JMgcKzxFDLsP74">
|
218
|
-
<inform xmlns="http://schema.mytestbed.net/omf/6.0/protocol"
|
219
|
-
<
|
220
|
-
<
|
217
|
+
<inform xmlns="http://schema.mytestbed.net/omf/6.0/protocol" mid="a2b6aba9f11dc5bb88306a32d0720641f5020c1f">
|
218
|
+
<cid>bf840fe9-c176-4fae-b7de-6fc27f183f76</cid>
|
219
|
+
<itype>CREATION.FAILED</itype>
|
221
220
|
<reason>No idea</reason>
|
222
221
|
</inform>
|
223
222
|
</item>
|
@@ -234,12 +233,13 @@ def omf_released_xml
|
|
234
233
|
<<-NODE
|
235
234
|
<message from="pubsub.localhost" to="bravo@localhost" id="mclaren__bravo@localhost__FT6ea">
|
236
235
|
<event xmlns="http://jabber.org/protocol/pubsub#event">
|
237
|
-
<items node="
|
236
|
+
<items node="test_topic">
|
238
237
|
<item id="4JMgcKzxFDLsP74">
|
239
|
-
<inform xmlns="http://schema.mytestbed.net/omf/6.0/protocol"
|
240
|
-
<
|
241
|
-
<
|
242
|
-
<
|
238
|
+
<inform xmlns="http://schema.mytestbed.net/omf/6.0/protocol">
|
239
|
+
<mid>a2b6aba9f11dc5bb88306a32d0720641f5020c1f</mid>
|
240
|
+
<cid>bf840fe9-c176-4fae-b7de-6fc27f183f76</cid>
|
241
|
+
<itype>RELEASED</itype>
|
242
|
+
<res_id>444f17fb-546e-4685-a0d0-63e64fa046c8</res_id>
|
243
243
|
</inform>
|
244
244
|
</item>
|
245
245
|
</items>
|
@@ -2,39 +2,41 @@ require 'test_helper'
|
|
2
2
|
require 'fixture/pubsub'
|
3
3
|
require 'em/minitest/spec'
|
4
4
|
|
5
|
-
|
5
|
+
require 'omf_common/comm/xmpp/communicator'
|
6
|
+
|
7
|
+
describe OmfCommon::Comm::XMPP::Communicator do
|
6
8
|
before do
|
7
9
|
@client = Blather::Client.new
|
8
10
|
@stream = MiniTest::Mock.new
|
9
11
|
@stream.expect(:send, true, [Blather::Stanza])
|
10
|
-
@client.post_init @stream, Blather::JID.new('
|
11
|
-
@xmpp = OmfCommon::Comm.new
|
12
|
+
@client.post_init @stream, Blather::JID.new('bob@example.com')
|
13
|
+
@xmpp = OmfCommon::Comm::XMPP::Communicator.new
|
12
14
|
end
|
13
15
|
|
14
16
|
describe "when communicating to xmpp server (via mocking)" do
|
15
17
|
include EM::MiniTest::Spec
|
16
18
|
|
17
|
-
it "must be able to connect" do
|
18
|
-
Blather::
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
it "must be able to connect and tigger on_connected callbacks" do
|
20
|
+
Blather::Client.stub :new, @client do
|
21
|
+
@xmpp.jid.inspect.must_equal "bob@example.com"
|
22
|
+
|
23
|
+
@xmpp.on_connected do |communicator|
|
24
|
+
communicator.must_be_kind_of OmfCommon::Comm::XMPP::Communicator
|
23
25
|
end
|
26
|
+
@stream.verify
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
27
30
|
it "must be able to disconnect" do
|
28
|
-
Blather::
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
@stream.verify
|
33
|
-
end
|
31
|
+
Blather::Client.stub :new, @client do
|
32
|
+
@stream.expect(:close_connection_after_writing, true)
|
33
|
+
@xmpp.disconnect
|
34
|
+
@stream.verify
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
37
38
|
it "must be able to subscribe & trigger callback when subscribed" do
|
39
|
+
skip
|
38
40
|
Blather::Client.stub :new, @client do
|
39
41
|
subscription = Blather::XMPPNode.parse(subscription_xml)
|
40
42
|
write_callback = proc do |event|
|
@@ -43,7 +45,11 @@ describe OmfCommon::DSL::Xmpp do
|
|
43
45
|
@client.receive_data subscription
|
44
46
|
end
|
45
47
|
@client.stub :write, write_callback do
|
46
|
-
@xmpp.subscribe('xmpp_topic')
|
48
|
+
@xmpp.subscribe('xmpp_topic') do |topic|
|
49
|
+
topic.must_be_kind_of OmfCommon::Comm::XMPP::Topic
|
50
|
+
topic.id.must_equal :xmpp_topic
|
51
|
+
done!
|
52
|
+
end
|
47
53
|
end
|
48
54
|
end
|
49
55
|
wait!
|
@@ -51,17 +57,11 @@ describe OmfCommon::DSL::Xmpp do
|
|
51
57
|
|
52
58
|
it "must be able to create topic & trigger callback when created" do
|
53
59
|
Blather::Client.stub :new, @client do
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
created.id = event.id
|
58
|
-
@client.receive_data created
|
59
|
-
end
|
60
|
-
@client.stub :write, write_callback do
|
61
|
-
@xmpp.create_topic('xmpp_topic') { |event| event.must_equal created; done! }
|
60
|
+
OmfCommon.stub :comm, @xmpp do
|
61
|
+
@stream.expect(:send, true, [Blather::Stanza])
|
62
|
+
@xmpp.create_topic('xmpp_topic').must_be_kind_of OmfCommon::Comm::XMPP::Topic
|
62
63
|
end
|
63
64
|
end
|
64
|
-
wait!
|
65
65
|
end
|
66
66
|
|
67
67
|
it "must be able to delete topic & trigger callback when topic deleted" do
|
@@ -73,7 +73,9 @@ describe OmfCommon::DSL::Xmpp do
|
|
73
73
|
@client.receive_data deleted
|
74
74
|
end
|
75
75
|
@client.stub :write, write_callback do
|
76
|
-
@xmpp.delete_topic('xmpp_topic')
|
76
|
+
@xmpp.delete_topic('xmpp_topic') do |stanza|
|
77
|
+
done!
|
78
|
+
end
|
77
79
|
end
|
78
80
|
end
|
79
81
|
wait!
|
@@ -97,8 +99,8 @@ describe OmfCommon::DSL::Xmpp do
|
|
97
99
|
it "must be able to publish if message is valid" do
|
98
100
|
Blather::Client.stub :new, @client do
|
99
101
|
@stream.expect(:send, true, [Blather::Stanza::PubSub::Publish])
|
100
|
-
@xmpp.publish 'xmpp_topic', Message.create {
|
101
|
-
proc { @xmpp.publish 'xmpp_topic', Message.inform {
|
102
|
+
@xmpp.publish 'xmpp_topic', OmfCommon::Message.create(:create, { type: 'test' })
|
103
|
+
proc { @xmpp.publish 'xmpp_topic', OmfCommon::Message.create(:inform, nil, { blah: 'blah' })}.must_raise StandardError
|
102
104
|
@stream.verify
|
103
105
|
end
|
104
106
|
end
|
@@ -112,7 +114,7 @@ describe OmfCommon::DSL::Xmpp do
|
|
112
114
|
@client.receive_data published
|
113
115
|
end
|
114
116
|
@client.stub :write, write_callback do
|
115
|
-
@xmpp.publish 'xmpp_topic', Message.create {
|
117
|
+
@xmpp.publish 'xmpp_topic', OmfCommon::Message.create(:create, { type: 'test' }) do |event|
|
116
118
|
event.must_equal published
|
117
119
|
done!
|
118
120
|
end
|
@@ -158,6 +160,7 @@ describe OmfCommon::DSL::Xmpp do
|
|
158
160
|
|
159
161
|
describe "when omf message related methods" do
|
160
162
|
it "must generate omf create xml fragment" do
|
163
|
+
skip
|
161
164
|
m1 = @xmpp.create_message([type: 'engine'])
|
162
165
|
m2 = @xmpp.create_message do |v|
|
163
166
|
v.property('type', 'engine')
|
@@ -170,6 +173,7 @@ describe OmfCommon::DSL::Xmpp do
|
|
170
173
|
end
|
171
174
|
|
172
175
|
it "must generate omf configure xml fragment" do
|
176
|
+
skip
|
173
177
|
m1 = @xmpp.configure_message([throttle: 50])
|
174
178
|
m2 = @xmpp.configure_message do |v|
|
175
179
|
v.property('throttle', 50)
|
@@ -182,30 +186,33 @@ describe OmfCommon::DSL::Xmpp do
|
|
182
186
|
end
|
183
187
|
|
184
188
|
it "must generate omf inform xml fragment" do
|
185
|
-
|
189
|
+
skip
|
190
|
+
m1 = @xmpp.inform_message([itype: 'CREATION.OK'])
|
186
191
|
m2 = @xmpp.inform_message do |v|
|
187
|
-
v.property('
|
192
|
+
v.property('itype', 'CREATION.OK')
|
188
193
|
end
|
189
194
|
m1.must_be_kind_of OmfCommon::TopicMessage
|
190
195
|
m2.must_be_kind_of OmfCommon::TopicMessage
|
191
196
|
m1.body.name.must_equal 'inform'
|
192
|
-
m1.body.to_xml.must_match /<property key="
|
193
|
-
m2.body.to_xml.must_match /<property key="
|
197
|
+
m1.body.to_xml.must_match /<property key="itype" type="string">CREATION.OK<\/property>/
|
198
|
+
m2.body.to_xml.must_match /<property key="itype" type="string">CREATION.OK<\/property>/
|
194
199
|
end
|
195
200
|
|
196
201
|
it "must generate omf release xml fragment" do
|
197
|
-
|
202
|
+
skip
|
203
|
+
m1 = @xmpp.release_message([res_id: 100])
|
198
204
|
m2 = @xmpp.release_message do |v|
|
199
|
-
v.property('
|
205
|
+
v.property('res_id', 100)
|
200
206
|
end
|
201
207
|
m1.must_be_kind_of OmfCommon::TopicMessage
|
202
208
|
m2.must_be_kind_of OmfCommon::TopicMessage
|
203
209
|
m1.body.name.must_equal 'release'
|
204
|
-
m1.body.to_xml.must_match /<property key="
|
205
|
-
m2.body.to_xml.must_match /<property key="
|
210
|
+
m1.body.to_xml.must_match /<property key="res_id" type="integer">100<\/property>/
|
211
|
+
m2.body.to_xml.must_match /<property key="res_id" type="integer">100<\/property>/
|
206
212
|
end
|
207
213
|
|
208
214
|
it "must generate omf request xml fragment" do
|
215
|
+
skip
|
209
216
|
m1 = @xmpp.request_message([:max_rpm, {:provider => {country: 'japan'}}, :max_power])
|
210
217
|
m2 = @xmpp.request_message do |v|
|
211
218
|
v.property('max_rpm')
|
@@ -224,86 +231,15 @@ describe OmfCommon::DSL::Xmpp do
|
|
224
231
|
end
|
225
232
|
end
|
226
233
|
|
227
|
-
describe "when informed message received" do
|
228
|
-
include EM::MiniTest::Spec
|
229
|
-
|
230
|
-
it "must react to omf created message" do
|
231
|
-
Blather::Client.stub :new, @client do
|
232
|
-
omf_create = OmfCommon::Message.create { |v| v.property('type', 'engine') }
|
233
|
-
omf_create.stub :msg_id, "bf840fe9-c176-4fae-b7de-6fc27f183f76" do
|
234
|
-
omf_created = Blather::XMPPNode.parse(omf_created_xml)
|
235
|
-
@client.receive_data omf_created
|
236
|
-
@xmpp.on_created_message(omf_create) do |n|
|
237
|
-
n.must_equal Message.parse(omf_created.items.first.payload)
|
238
|
-
done!
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
242
|
-
wait!
|
243
|
-
end
|
244
|
-
|
245
|
-
it "must react to omf status message" do
|
246
|
-
Blather::Client.stub :new, @client do
|
247
|
-
omf_request = OmfCommon::Message.request { |v| v.property('bob') }
|
248
|
-
omf_request.stub :msg_id, "bf840fe9-c176-4fae-b7de-6fc27f183f76" do
|
249
|
-
omf_status = Blather::XMPPNode.parse(omf_status_xml)
|
250
|
-
@client.receive_data omf_status
|
251
|
-
@xmpp.on_status_message(omf_request) do |n|
|
252
|
-
n.must_equal Message.parse(omf_status.items.first.payload)
|
253
|
-
done!
|
254
|
-
end
|
255
|
-
end
|
256
|
-
end
|
257
|
-
wait!
|
258
|
-
end
|
259
|
-
|
260
|
-
it "must react to omf release message" do
|
261
|
-
Blather::Client.stub :new, @client do
|
262
|
-
omf_release = OmfCommon::Message.release { |v| v.property('resource_id', '100') }
|
263
|
-
omf_release.stub :msg_id, "bf840fe9-c176-4fae-b7de-6fc27f183f76" do
|
264
|
-
omf_released = Blather::XMPPNode.parse(omf_released_xml)
|
265
|
-
@client.receive_data omf_released
|
266
|
-
@xmpp.on_released_message(omf_release) do |n|
|
267
|
-
n.must_equal Message.parse(omf_released.items.first.payload)
|
268
|
-
done!
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|
272
|
-
wait!
|
273
|
-
end
|
274
|
-
|
275
|
-
it "must react to omf failed message" do
|
276
|
-
Blather::Client.stub :new, @client do
|
277
|
-
omf_create = OmfCommon::Message.create { |v| v.property('type', 'engine') }
|
278
|
-
omf_create.stub :msg_id, "bf840fe9-c176-4fae-b7de-6fc27f183f76" do
|
279
|
-
omf_failed = Blather::XMPPNode.parse(omf_failed_xml)
|
280
|
-
@client.receive_data omf_failed
|
281
|
-
@xmpp.on_failed_message(omf_create) do |n|
|
282
|
-
n.must_equal Message.parse(omf_failed.items.first.payload)
|
283
|
-
done!
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|
287
|
-
wait!
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
234
|
describe "when use event machine style method" do
|
292
235
|
include EM::MiniTest::Spec
|
293
236
|
|
294
237
|
it "must accept these methods and forward to event machine" do
|
295
|
-
|
296
|
-
|
238
|
+
skip
|
239
|
+
OmfCommon.eventloop.after(0.05) { done! }
|
240
|
+
OmfCommon.eventloop.every(0.05) { done! }
|
297
241
|
wait!
|
298
242
|
end
|
299
243
|
end
|
300
|
-
|
301
|
-
describe "when asked to get a topic object" do
|
302
|
-
it "must return a topic object (pubsub topic) or nil if not found" do
|
303
|
-
topic = @xmpp.get_topic('xmpp_topic')
|
304
|
-
topic.must_be_kind_of OmfCommon::Topic
|
305
|
-
topic.comm.must_equal @xmpp
|
306
|
-
end
|
307
|
-
end
|
308
244
|
end
|
309
245
|
|