Class: Roster::IqQueryRosterTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/vendor/xmpp4r/test/roster/tc_iqqueryroster.rb

Instance Method Summary collapse

Instance Method Details

#test_answerObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vendor/xmpp4r/test/roster/tc_iqqueryroster.rb', line 30

def test_answer
  iq = Iq.new_rosterget
  assert_equal(:get, iq.type)
  assert_nil(iq.to)
  assert_equal('jabber:client', iq.namespace)
  assert_equal('jabber:iq:roster', iq.queryns)
  assert_equal(0, iq.query.children.size)

  iq2 = iq.answer(true)
  assert_equal(:get, iq2.type)
  assert_nil(iq2.from)
  assert_equal('jabber:client', iq2.namespace)
  assert_equal('jabber:iq:roster', iq2.queryns)
  assert_equal(0, iq2.query.children.size)
end

#test_createObject



13
14
15
16
17
18
19
# File 'lib/vendor/xmpp4r/test/roster/tc_iqqueryroster.rb', line 13

def test_create
  r = Roster::IqQueryRoster.new
  assert_equal('jabber:iq:roster', r.namespace)
  assert_equal(r.to_a.size, 0)
  assert_equal(r.to_a, [])
  assert_equal(r.to_s, "<query xmlns='jabber:iq:roster'/>")
end

#test_dupitemsObject



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
# File 'lib/vendor/xmpp4r/test/roster/tc_iqqueryroster.rb', line 90

def test_dupitems
  r = Roster::IqQueryRoster.new
  jid = JID.new('a@b')
  jid2 = JID.new('c@d')
  ri = Roster::RosterItem.new(jid, 'ab')
  r.add(ri)
  assert_equal('ab', ri.iname)
  assert_equal('ab', r[jid].iname)
  ri.iname = 'cd'
  assert_equal('cd', ri.iname)
  # There are no shallow copies - everything is alright.
  assert_equal('cd', r[jid].iname)

  r.add(ri)
  assert_equal('cd', r[jid].iname)
  assert_equal(ri, r[jid])

  ri.jid = jid2
  assert_equal(nil, r[jid])
  assert_equal(ri, r[jid2])
  assert_equal(2, r.to_a.size)

  r.each_element('item') { |item|
    assert_equal(ri, item)
    assert_equal(ri.jid, item.jid)
    assert_equal(ri.iname, item.iname)
    assert_equal(jid2, item.jid)
    assert_equal('cd', item.iname)
  }
end

#test_importObject



21
22
23
24
25
26
27
28
# File 'lib/vendor/xmpp4r/test/roster/tc_iqqueryroster.rb', line 21

def test_import
  iq = Iq.new
  q = REXML::Element.new('query')
  q.add_namespace('jabber:iq:roster')
  iq.add(q)
  iq2 = Iq.new.import(iq)
  assert_equal(Roster::IqQueryRoster, iq2.query.class)
end

#test_itemsObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/vendor/xmpp4r/test/roster/tc_iqqueryroster.rb', line 61

def test_items
  r = Roster::IqQueryRoster.new
  r.add(Roster::RosterItem.new)
  r.add(Roster::RosterItem.new(JID.new('a@b/d'), 'ABC', :none, :subscribe)).groups = ['a']
  itemstr = "<item jid='[email protected]' name='Astro' subscribtion='both'>" \
          + "<group>SpaceBoyZ</group><group>xmpp4r</group></item>"
  r.typed_add(REXML::Document.new(itemstr).root)

  r.each { |item|
    assert_equal(item, r[item.jid])
  }

  r.to_a.each { |item|
    assert_equal(item, r[item.jid])
  }

  assert_equal(JID.new, r.to_a[0].jid)
  assert_equal(nil, r.to_a[0].iname)
  assert_equal(nil, r.to_a[0].subscription)
  assert_equal(nil, r.to_a[0].ask)

  assert_equal(JID.new('a@b/d'), r.to_a[1].jid)
  assert_equal('ABC', r.to_a[1].iname)
  assert_equal(:none, r.to_a[1].subscription)
  assert_equal(:subscribe, r.to_a[1].ask)

  assert_equal(REXML::Document.new(itemstr).root.to_s, r.to_a[2].to_s)
end

#test_xmlnsObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vendor/xmpp4r/test/roster/tc_iqqueryroster.rb', line 46

def test_xmlns
  ri = Roster::RosterItem.new
  assert_equal('jabber:iq:roster', ri.namespace)
  assert_equal('jabber:iq:roster', ri.attributes['xmlns'])

  r = Roster::IqQueryRoster.new
  assert_equal('jabber:iq:roster', r.namespace)
  assert_equal('jabber:iq:roster', r.attributes['xmlns'])

  r.add(ri)

  assert_equal('jabber:iq:roster', ri.namespace)
  assert_nil(ri.attributes['xmlns'])
end