Class: Roster::HelperTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- Roster::HelperTest
- Includes:
- ClientTester
- Defined in:
- lib/vendor/xmpp4r/test/roster/tc_helper.rb
Instance Method Summary collapse
- #test_accept_subscription ⇒ Object
- #test_decline_subscription ⇒ Object
- #test_groupset ⇒ Object
- #test_nameset ⇒ Object
- #test_presence ⇒ Object
- #test_rosterpush ⇒ Object
- #test_simple ⇒ Object
- #test_subscribe ⇒ Object
- #test_update_callback ⇒ Object
Instance Method Details
#test_accept_subscription ⇒ Object
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'lib/vendor/xmpp4r/test/roster/tc_helper.rb', line 321 def test_accept_subscription state { |iq| send("<iq type='result' id='#{iq.id}'> <query xmlns='jabber:iq:roster'/> </iq>") } query_waiter = Semaphore.new h = Roster::Helper.new(@client) h.add_query_callback { |iq| query_waiter.run } wait_state query_waiter.wait state { |pres| assert_kind_of(Presence, pres) assert_equal(:subscribed, pres.type) } state { |iq| assert_kind_of(Iq, iq) assert_equal(:set, iq.type) send("<iq type='result' id='#{iq.id}'/>") } cb_lock = Semaphore.new h.add_subscription_request_callback { |item,pres| assert_nil(item) assert_kind_of(Presence, pres) h.accept_subscription(pres.from) cb_lock.run } send("<presence type='subscribe' from='[email protected]' to='[email protected]'/>") skip_state wait_state cb_lock.wait state { |pres| assert_kind_of(Presence, pres) assert_equal(:subscribed, pres.type) assert_equal(JID.new('[email protected]'), pres.to) } wait_state end |
#test_decline_subscription ⇒ Object
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'lib/vendor/xmpp4r/test/roster/tc_helper.rb', line 364 def test_decline_subscription state { |iq| send("<iq type='result' id='#{iq.id}'> <query xmlns='jabber:iq:roster'/> </iq>") } query_waiter = Semaphore.new h = Roster::Helper.new(@client) h.add_query_callback { |iq| query_waiter.run } wait_state query_waiter.wait state { |pres| assert_kind_of(Presence, pres) assert_equal(:unsubscribed, pres.type) assert_equal(JID.new('[email protected]'), pres.to) } cb_lock = Semaphore.new h.add_subscription_request_callback { |item,pres| assert_nil(item) assert_kind_of(Presence, pres) h.decline_subscription(pres.from) cb_lock.run } send("<presence type='subscribe' from='[email protected]' to='[email protected]'/>") wait_state cb_lock.wait end |
#test_groupset ⇒ Object
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
# File 'lib/vendor/xmpp4r/test/roster/tc_helper.rb', line 396 def test_groupset state { |iq| send("<iq type='result'> <query xmlns='jabber:iq:roster'> <item jid='test@test' subscription='both'> <group>One</group> <group>Two</group> </item> </query> </iq>") } query_waiter = Semaphore.new h = Roster::Helper.new(@client) h.add_query_callback { query_waiter.run } wait_state query_waiter.wait assert_equal(1, h.items.size) assert_equal(%w(One Two).sort, h['test@test'].groups.sort) state { |iq| send("<iq type='result' id='#{iq.id}'>#{iq.query}</iq>") } h['test@test'].groups = %w(One Two Three) h['test@test'].send wait_state query_waiter.wait assert_equal(%w(One Two Three).sort, h['test@test'].groups.sort) end |
#test_nameset ⇒ Object
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
# File 'lib/vendor/xmpp4r/test/roster/tc_helper.rb', line 427 def test_nameset state { |iq| send("<iq type='result'> <query xmlns='jabber:iq:roster'> <item jid='test@test' subscription='both'/> </query> </iq>") } query_waiter = Semaphore.new h = Roster::Helper.new(@client) h.add_query_callback { query_waiter.run } wait_state query_waiter.wait assert_equal(1, h.items.size) assert_nil(h['test@test'].iname) state { |iq| send("<iq type='result' id='#{iq.id}'>#{iq.query}</iq>") } h['test@test'].iname = 'Unknown' h['test@test'].send wait_state query_waiter.wait assert_equal('Unknown', h['test@test'].iname) state { |iq| send("<iq type='result' id='#{iq.id}'>#{iq.query}</iq>") } h['test@test'].iname = 'Known' h['test@test'].send wait_state query_waiter.wait assert_equal('Known', h['test@test'].iname) state { |iq| send("<iq type='result' id='#{iq.id}'>#{iq.query}</iq>") } h['test@test'].iname = nil h['test@test'].send wait_state query_waiter.wait assert_nil(h['test@test'].iname) end |
#test_presence ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/vendor/xmpp4r/test/roster/tc_helper.rb', line 134 def test_presence state { |iq| send("<iq type='result' id='#{iq.id}'> <query xmlns='jabber:iq:roster'> <item jid='[email protected]' subscription='both'/> </query> </iq>") } query_waiter = Semaphore.new presence_waiter = Semaphore.new h = Roster::Helper.new(@client) h.add_query_callback { |iq| query_waiter.run } cb_item, cb_op, cb_p = nil, nil, nil h.add_presence_callback { |item,oldpres,pres| # HACK: # if two stanzas are expected for one sent stanza, # race conditions may appear here Thread.pass cb_item, cb_op, cb_p = item, oldpres, pres presence_waiter.run } wait_state query_waiter.wait assert_equal(false, h['[email protected]'].online?) presences = 0 h['[email protected]'].each_presence { presences += 1 } assert_equal(0, presences) send("<presence from='[email protected]/r'/>") presence_waiter.wait assert_kind_of(Roster::Helper::RosterItem, cb_item) assert_nil(cb_op) assert_kind_of(Presence, cb_p) assert_nil(cb_p.type) assert_equal(true, h['[email protected]'].online?) presences = 0 h['[email protected]'].each_presence { presences += 1 } assert_equal(1, presences) send("<presence from='[email protected]/r2'/>") presence_waiter.wait assert_kind_of(Roster::Helper::RosterItem, cb_item) assert_nil(cb_op) assert_kind_of(Presence, cb_p) assert_nil(cb_p.type) assert_equal(true, h['[email protected]'].online?) presences = 0 h['[email protected]'].each_presence { presences += 1 } assert_equal(2, presences) send("<presence from='[email protected]/r'/>") presence_waiter.wait assert_kind_of(Roster::Helper::RosterItem, cb_item) assert_kind_of(Presence, cb_op) assert_nil(cb_op.type) assert_kind_of(Presence, cb_p) assert_nil(cb_p.type) assert_equal(true, h['[email protected]'].online?) presences = 0 h['[email protected]'].each_presence { presences += 1 } assert_equal(2, presences) send("<presence from='[email protected]/r' type='error'/>") presence_waiter.wait assert_kind_of(Roster::Helper::RosterItem, cb_item) assert_kind_of(Presence, cb_op) assert_nil(cb_op.type) assert_kind_of(Presence, cb_p) assert_equal(:error, cb_p.type) assert_equal(true, h['[email protected]'].online?) presences = 0 h['[email protected]'].each_presence { presences += 1 } assert_equal(2, presences) send("<presence from='[email protected]/r2' type='unavailable'/>") presence_waiter.wait assert_kind_of(Roster::Helper::RosterItem, cb_item) assert_kind_of(Presence, cb_op) assert_nil(cb_op.type) assert_kind_of(Presence, cb_p) assert_equal(:unavailable, cb_p.type) assert_equal(false, h['[email protected]'].online?) presences = 0 h['[email protected]'].each_presence { presences += 1 } assert_equal(2, presences) send("<presence from='[email protected]/r'/>") presence_waiter.wait assert_kind_of(Roster::Helper::RosterItem, cb_item) assert_kind_of(Presence, cb_op) assert_equal(:error, cb_op.type) assert_kind_of(Presence, cb_p) assert_nil(cb_p.type) assert_equal(true, h['[email protected]'].online?) presences = 0 h['[email protected]'].each_presence { presences += 1 } assert_equal(2, presences) send("<presence from='[email protected]/r2'/>") presence_waiter.wait assert_kind_of(Roster::Helper::RosterItem, cb_item) assert_kind_of(Presence, cb_op) assert_equal(:unavailable, cb_op.type) assert_kind_of(Presence, cb_p) assert_nil(cb_p.type) assert_equal(true, h['[email protected]'].online?) presences = 0 h['[email protected]'].each_presence { presences += 1 } assert_equal(2, presences) send("<presence from='[email protected]' type='error'/>") 2.times { presence_waiter.wait assert_kind_of(Roster::Helper::RosterItem, cb_item) assert_kind_of(Presence, cb_op) assert_kind_of(Presence, cb_p) assert_equal(:error, cb_p.type) } assert_equal(false, h['[email protected]'].online?) presences = 0 h['[email protected]'].each_presence { presences += 1 } assert_equal(1, presences) send("<presence from='[email protected]/r'/>") presence_waiter.wait assert_kind_of(Roster::Helper::RosterItem, cb_item) assert_nil(cb_op) assert_kind_of(Presence, cb_p) assert_nil(cb_p.type) assert_equal(true, h['[email protected]'].online?) presences = 0 h['[email protected]'].each_presence { presences += 1 } assert_equal(1, presences) end |
#test_rosterpush ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/vendor/xmpp4r/test/roster/tc_helper.rb', line 68 def test_rosterpush state { |iq| send("<iq type='result' id='#{iq.id}'> <query xmlns='jabber:iq:roster'> </query> </iq>") } query_waiter = Semaphore.new h = Roster::Helper.new(@client) h.add_query_callback { |iq| query_waiter.run } wait_state query_waiter.wait assert_equal([], h.groups) assert_nil(h['[email protected]']) send("<iq type='set'> <query xmlns='jabber:iq:roster'> <item jid='[email protected]'/> </query> </iq>") query_waiter.wait assert_kind_of(Roster::Helper::RosterItem, h['[email protected]']) assert_equal(JID.new('[email protected]'), h['[email protected]'].jid) assert_nil(h['[email protected]'].iname) assert_nil(h['[email protected]'].subscription) assert_nil(h['[email protected]'].ask) send("<iq type='set'> <query xmlns='jabber:iq:roster'> <item jid='[email protected]' subscription='from' name='ABC' ask='subscribe'/> </query> </iq>") query_waiter.wait assert_kind_of(Roster::Helper::RosterItem, h['[email protected]']) assert_equal(JID.new('[email protected]'), h['[email protected]'].jid) assert_equal('ABC', h['[email protected]'].iname) assert_equal(:from, h['[email protected]'].subscription) assert_equal(:subscribe, h['[email protected]'].ask) send("<iq type='set'> <query xmlns='jabber:iq:roster'> <item jid='[email protected]'/> </query> </iq>") query_waiter.wait assert_kind_of(Roster::Helper::RosterItem, h['[email protected]']) assert_equal(JID.new('[email protected]'), h['[email protected]'].jid) assert_nil(h['[email protected]'].iname) assert_nil(h['[email protected]'].subscription) assert_nil(h['[email protected]'].ask) send("<iq type='set'> <query xmlns='jabber:iq:roster'> <item jid='[email protected]' subscription='remove'/> </query> </iq>") query_waiter.wait assert_nil(h['[email protected]']) end |
#test_simple ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/vendor/xmpp4r/test/roster/tc_helper.rb', line 16 def test_simple state { |iq| assert_kind_of(Iq, iq) assert_equal(:get, iq.type) assert_nil(iq.to) assert_equal('jabber:iq:roster', iq.queryns) send("<iq type='result'><query xmlns='jabber:iq:version'/></iq>") send("<iq type='result' id='#{iq.id}'> <query xmlns='jabber:iq:roster'> <item jid='[email protected]' subscription='both'/> <item jid='[email protected]' name='b guy' subscription='from' ask='subscribe'/> <item jid='123@xyz' name='123' subscription='to'/> </query> </iq>") } query_waiter = Semaphore.new h = Roster::Helper.new(@client) h.add_query_callback { |iq| query_waiter.run } wait_state query_waiter.wait assert_equal([nil], h.groups) jids = h.find_by_group(nil).collect { |item| item.jid }.sort assert_equal([JID.new('123@xyz'), JID.new('[email protected]'), JID.new('[email protected]')], jids) assert_equal(1, h.find('123@xyz/res').size) assert_kind_of(Roster::Helper::RosterItem, h['[email protected]']) assert_equal(JID.new('[email protected]'), h['[email protected]'].jid) assert_nil(h['[email protected]'].iname) assert_equal(:both, h['[email protected]'].subscription) assert_nil(h['[email protected]'].ask) assert_kind_of(Roster::Helper::RosterItem, h[JID.new('[email protected]')]) assert_equal(JID.new('[email protected]'), h['[email protected]'].jid) assert_equal('b guy', h['[email protected]'].iname) assert_equal(:from, h['[email protected]'].subscription) assert_equal(:subscribe, h['[email protected]'].ask) assert_kind_of(Roster::Helper::RosterItem, h['123@xyz']) assert_equal(JID.new('123@xyz'), h['123@xyz'].jid) assert_equal('123', h['123@xyz'].iname) assert_equal(:to, h['123@xyz'].subscription) assert_nil(h['123@xyz'].ask) assert_nil(h['[email protected]']) assert_nil(h[JID.new('[email protected]')]) end |
#test_subscribe ⇒ Object
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/vendor/xmpp4r/test/roster/tc_helper.rb', line 284 def test_subscribe state { |iq| send("<iq type='result' id='#{iq.id}'> <query xmlns='jabber:iq:roster'/> </iq>") } query_waiter = Semaphore.new h = Roster::Helper.new(@client) h.add_query_callback { |iq| query_waiter.run } wait_state query_waiter.wait state { |iq| assert_kind_of(Iq, iq) assert_equal('jabber:iq:roster', iq.queryns) assert_equal(JID.new('[email protected]'), iq.query.first_element('item').jid) assert_equal('MyContact', iq.query.first_element('item').iname) send("<iq type='set'> <query xmlns='jabber:iq:roster'> <item jid='[email protected]' subscription='none' name='MyContact'/> </query> </iq> <iq type='result' id='#{iq.id}'/>") } state { |pres| assert_kind_of(Presence, pres) assert_equal(:subscribe, pres.type) assert_equal(JID.new('[email protected]'), pres.to) Thread.pass } h.add('[email protected]', 'MyContact', true) wait_state query_waiter.wait wait_state end |
#test_update_callback ⇒ Object
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
# File 'lib/vendor/xmpp4r/test/roster/tc_helper.rb', line 473 def test_update_callback update_args = nil update_waiter = Semaphore.new h = Roster::Helper.new(@client) h.add_update_callback { |*a| update_args = a update_waiter.run } send("<iq type='set'> <query xmlns='jabber:iq:roster'> <item jid='foo@bar' name='Foo'/> </query> </iq>") update_waiter.wait assert_nil(update_args[0]) assert_equal(JID.new('foo@bar'), update_args[1].jid) assert_equal('Foo', update_args[1].iname) send("<iq type='set'> <query xmlns='jabber:iq:roster'> <item jid='foo@bar'/> </query> </iq>") update_waiter.wait assert_equal(JID.new('foo@bar'), update_args[0].jid) assert_equal('Foo', update_args[0].iname) assert_equal(JID.new('foo@bar'), update_args[1].jid) assert_nil(update_args[1].iname) send("<iq type='set'> <query xmlns='jabber:iq:roster'> <item jid='foo@bar' subscription='remove'/> </query> </iq>") update_waiter.wait assert_equal(JID.new('foo@bar'), update_args[0].jid) assert_nil(update_args[0].iname) assert_nil(update_args[1]) end |