1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 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 67
|
require 'stomp_server/topic_manager'
require 'test/unit' unless defined? $ZENTEST and $ZENTEST
class TestTopics < Test::Unit::TestCase
class UserMock
attr_accessor :data
def initialize ; @data = '' ; end
def stomp_send_data(data); @data += data.to_s ; end
end
class MessageMock
attr_accessor :headers, :data, :command
def initialize(dest, msg)
@headers = { 'destination' => dest }
@data = msg
end
def to_s ; @data ; end
end
def setup
@t = StompServer::TopicManager.new
end
def test_subscribe
u = UserMock.new
t = 'foo'
@t.subscribe(t, u)
m1 = MessageMock.new('foo', 'foomsg')
m2 = MessageMock.new('bar', 'barmsg')
@t.sendmsg(m1)
assert_equal(m1.data, u.data)
u.data = ''
@t.sendmsg(m2)
assert_equal('', u.data)
end
def test_unsubscribe
u = UserMock.new
t = 'foo'
@t.subscribe(t, u)
m1 = MessageMock.new('foo', 'foomsg')
@t.sendmsg(m1)
assert_equal(m1.data, u.data)
@t.unsubscribe(t,u)
u.data = ''
@t.sendmsg(m1)
assert_equal('', u.data)
end
def test_sendmsg
u = UserMock.new
t = 'foo'
@t.subscribe(t, u)
m1 = MessageMock.new('foo', 'foomsg')
@t.sendmsg(m1)
assert_equal(m1.data, u.data)
assert_equal('MESSAGE', m1.command)
end
end
|