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 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 133 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
|
# -*- encoding: utf-8 -*-
require 'test/unit'
require 'timeout'
if Kernel.respond_to?(:require_relative)
require_relative("../lib/stomp")
require_relative("tlogger")
else
$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
require 'stomp'
require 'tlogger'
end
begin
_ = RUBY_ENGINE
rescue NameError
RUBY_ENGINE = "unknown"
end
=begin
Test helper methods.
=end
module TestBase
# Get user
def user
ENV['STOMP_USER'] || "guest"
end
# Gete passcode
def passcode
ENV['STOMP_PASSCODE'] || "guest"
end
# Get host
def host
ENV['STOMP_HOST'] || "localhost"
end
# Get port
def port
(ENV['STOMP_PORT'] || 61613).to_i
end
# Get SSL port
def ssl_port
(ENV['STOMP_SSLPORT'] || 61611).to_i
end
# Helper for minitest on 1.9
def caller_method_name
parse_caller(caller(2).first).last
end
# Helper for minitest on 1.9
def parse_caller(at)
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
file = Regexp.last_match[1]
line = Regexp.last_match[2].to_i
method = Regexp.last_match[3]
method.gsub!(" ","_")
[file, line, method]
end
end
# Get a Stomp Connection.
def get_connection()
ch = get_conn_headers()
hash = { :hosts => [
{:login => user, :passcode => passcode, :host => host, :port => port, :ssl => nil},
],
:reliable => false,
:connect_headers => ch,
:stompconn => get_stomp_conn(),
:usecrlf => get_crlf(),
}
conn = Stomp::Connection.open(hash)
no_rep_error()
conn
end
# Get a Stomp Anonymous Connection.
def get_anonymous_connection()
ch = get_conn_headers()
hash = { :hosts => [
{:host => host, :port => port, :ssl => nil},
],
:reliable => false,
:connect_headers => ch,
:stompconn => get_stomp_conn(),
:usecrlf => get_crlf(),
}
conn = Stomp::Connection.open(hash)
no_rep_error()
conn
end
# Get a Stomp SSL Connection.
def get_ssl_connection()
ch = get_conn_headers()
ssl_params = Stomp::SSLParams.new(:use_ruby_ciphers => jruby?())
hash = { :hosts => [
{:login => user, :passcode => passcode, :host => host, :port => ssl_port, :ssl => ssl_params},
],
:connect_headers => ch,
:stompconn => get_stomp_conn(),
:usecrlf => get_crlf(),
}
conn = Stomp::Connection.new(hash)
no_rep_error()
conn
end
#
def no_rep_error()
ct = Thread::current
if ct.respond_to?(:report_on_exception=)
ct.report_on_exception=false
end
end
# Get a Stomp Client.
def get_client()
hash = { :hosts => [
{:login => user, :passcode => passcode, :host => host, :port => port},
],
:connect_headers => get_conn_headers(),
:stompconn => get_stomp_conn(),
:usecrlf => get_crlf(),
}
client = Stomp::Client.new(hash)
client
end
# Get a connection headers hash.
def get_conn_headers()
ch = {}
if ENV['STOMP_TEST11p']
#
raise "Invalid 1.1 plus test protocol" if ENV['STOMP_TEST11p'] == Stomp::SPL_10
#
if Stomp::SUPPORTED.index(ENV['STOMP_TEST11p'])
ch['accept-version'] = ENV['STOMP_TEST11p']
else
ch['accept-version'] = Stomp::SPL_11 # Just use 1.1
end
#
ch['host'] = ENV['STOMP_RABBIT'] ? "/" : host
end
ch
end
# Determine if tests should use STOMP instead of CONNECT
def get_stomp_conn()
usc = false
usc = true if ENV['STOMP_TEST11p'] && Stomp::SUPPORTED.index(ENV['STOMP_TEST11p']) && ENV['STOMP_TEST11p'] >= Stomp::SPL_11 && ENV['STOMP_CONN']
usc
end
# Determine if tests should \r\n as line ends
def get_crlf()
ucr = false
ucr = true if ENV['STOMP_TEST11p'] && Stomp::SUPPORTED.index(ENV['STOMP_TEST11p']) && ENV['STOMP_TEST11p'] >= Stomp::SPL_12 && ENV['STOMP_CRLF']
ucr
end
# Subscribe to a destination.
def conn_subscribe(dest, headers = {})
if @conn.protocol >= Stomp::SPL_11
headers[:id] = @conn.uuid() unless headers[:id]
end
@conn.subscribe dest, headers
end
# Get a dynamic destination name.
def make_destination
name = caller_method_name unless name
case
when ENV['STOMP_DOTQUEUE']
qname = "/queue/test.ruby.stomp." + name
when ENV['STOMP_ARTEMIS']
qname = "jms.queue.queue.test.ruby.stomp." + name
else
qname = "/queue/test/ruby/stomp/" + name
end
return qname
end
# get DLQ name
def make_dlq
return "jms.queue.DLQ" if ENV['STOMP_ARTEMIS']
"/queue/DLQ"
end
#
def checkEmsg(cc)
m = cc.poll
if m
assert m.command != Stomp::CMD_ERROR, "checkEmsg"
end
end
# Check for JRuby before a connection exists
def jruby?()
jr = defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/ ? true : false
return jr
end
# OK Data For Default Tests
def dflt_data_ok()
[
#
{ :hosts => [
{:login => 'guest', :passcode => 'guest', :host => "localhost", :port => 61613, :ssl => false},
],
:reliable => false,
},
#
{ :hosts => [
{:login => 'guest', :passcode => 'guest', :ssl => false},
],
:reliable => false,
},
#
{ :hosts => [
{:login => 'guest', :passcode => 'guest', :port => 61613, :ssl => false},
],
:reliable => false,
},
#
{ :hosts => [
{:login => 'guest', :passcode => 'guest', :host => "localhost" , :ssl => false},
],
:reliable => false,
},
#
{ :hosts => [
{:login => 'guest', :passcode => 'guest', :host => '' , :ssl => false},
],
:reliable => false,
},
]
end
# Exception Data For Default Tests
def dflt_data_ex()
[
{},
{:hosts => 123},
{ :hosts => [
{:login => 'guest', :passcode => 'guest', :host => "localhost", :port => '' , :ssl => false},
],
:reliable => false,
},
{ :hosts => [
{:login => 'guest', :passcode => 'guest', :host => "localhost", :port => -1 , :ssl => false},
],
:reliable => false,
},
]
end
end
|