2010-10-01 19:27:10 +08:00
|
|
|
%% The contents of this file are subject to the Mozilla Public License
|
|
|
|
|
%% Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
|
%% compliance with the License. You may obtain a copy of the License at
|
|
|
|
|
%% http://www.mozilla.org/MPL/
|
|
|
|
|
%%
|
|
|
|
|
%% Software distributed under the License is distributed on an "AS IS"
|
|
|
|
|
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
|
%% License for the specific language governing rights and limitations
|
|
|
|
|
%% under the License.
|
|
|
|
|
%%
|
|
|
|
|
%% The Original Code is RabbitMQ Management Console.
|
|
|
|
|
%%
|
|
|
|
|
%% The Initial Developers of the Original Code are Rabbit Technologies Ltd.
|
|
|
|
|
%%
|
|
|
|
|
%% Copyright (C) 2010 Rabbit Technologies Ltd.
|
|
|
|
|
%%
|
|
|
|
|
%% All Rights Reserved.
|
|
|
|
|
%%
|
|
|
|
|
%% Contributor(s): ______________________________________.
|
|
|
|
|
%%
|
2010-10-08 00:31:18 +08:00
|
|
|
-module(rabbit_stomp_test_util).
|
2010-10-01 19:27:10 +08:00
|
|
|
|
|
|
|
|
-include_lib("eunit/include/eunit.hrl").
|
|
|
|
|
|
|
|
|
|
valid_queue_test() ->
|
2010-10-01 21:49:23 +08:00
|
|
|
{ok, {queue, "test"}} = parse_destination("/queue/test").
|
2010-10-01 19:27:10 +08:00
|
|
|
|
2010-10-01 20:41:04 +08:00
|
|
|
valid_topic_test() ->
|
2010-10-01 21:49:23 +08:00
|
|
|
{ok, {topic, "test"}} = parse_destination("/topic/test").
|
2010-10-01 20:41:04 +08:00
|
|
|
|
|
|
|
|
valid_exchange_test() ->
|
2010-10-01 21:49:23 +08:00
|
|
|
{ok, {exchange, {"test", undefined}}} = parse_destination("/exchange/test").
|
2010-10-01 20:41:04 +08:00
|
|
|
|
|
|
|
|
valid_exchange_with_pattern_test() ->
|
2010-10-08 00:31:18 +08:00
|
|
|
{ok, {exchange, {"test", "pattern"}}} =
|
2010-10-01 20:41:04 +08:00
|
|
|
parse_destination("/exchange/test/pattern").
|
|
|
|
|
|
|
|
|
|
queue_with_no_name_test() ->
|
|
|
|
|
{error, {invalid_destination, queue, ""}} = parse_destination("/queue").
|
|
|
|
|
|
|
|
|
|
topic_with_no_name_test() ->
|
|
|
|
|
{error, {invalid_destination, topic, ""}} = parse_destination("/topic").
|
|
|
|
|
|
|
|
|
|
exchange_with_no_name_test() ->
|
2010-10-08 00:31:18 +08:00
|
|
|
{error, {invalid_destination, exchange, ""}} =
|
2010-10-01 20:41:04 +08:00
|
|
|
parse_destination("/exchange").
|
|
|
|
|
|
|
|
|
|
queue_with_no_name_slash_test() ->
|
|
|
|
|
{error, {invalid_destination, queue, "/"}} = parse_destination("/queue/").
|
|
|
|
|
|
|
|
|
|
topic_with_no_name_slash_test() ->
|
|
|
|
|
{error, {invalid_destination, topic, "/"}} = parse_destination("/topic/").
|
|
|
|
|
|
|
|
|
|
exchange_with_no_name_slash_test() ->
|
2010-10-08 00:31:18 +08:00
|
|
|
{error, {invalid_destination, exchange, "/"}} =
|
2010-10-01 21:49:23 +08:00
|
|
|
parse_destination("/exchange/").
|
|
|
|
|
|
|
|
|
|
queue_with_invalid_name_test() ->
|
2010-10-08 00:31:18 +08:00
|
|
|
{error, {invalid_destination, queue, "/foo/bar"}} =
|
2010-10-01 21:49:23 +08:00
|
|
|
parse_destination("/queue/foo/bar").
|
|
|
|
|
|
|
|
|
|
topic_with_invalid_name_test() ->
|
2010-10-08 00:31:18 +08:00
|
|
|
{error, {invalid_destination, topic, "/foo/bar"}} =
|
2010-10-01 21:49:23 +08:00
|
|
|
parse_destination("/topic/foo/bar").
|
|
|
|
|
|
|
|
|
|
exchange_with_invalid_name_test() ->
|
2010-10-08 00:31:18 +08:00
|
|
|
{error, {invalid_destination, exchange, "/foo/bar/baz"}} =
|
2010-10-01 21:49:23 +08:00
|
|
|
parse_destination("/exchange/foo/bar/baz").
|
|
|
|
|
|
|
|
|
|
unknown_destination_test() ->
|
2010-10-08 00:31:18 +08:00
|
|
|
{error, {unknown_destination, "/blah/boo"}} =
|
2010-10-05 20:36:12 +08:00
|
|
|
parse_destination("/blah/boo").
|
2010-10-01 20:41:04 +08:00
|
|
|
|
2010-10-18 20:29:51 +08:00
|
|
|
queue_with_escaped_name_test() ->
|
|
|
|
|
{ok, {queue, "te/st"}} = parse_destination("/queue/te%2Fst").
|
|
|
|
|
|
|
|
|
|
valid_exchange_with_escaped_name_and_pattern_test() ->
|
|
|
|
|
{ok, {exchange, {"te/st", "pa/tt/ern"}}} =
|
|
|
|
|
parse_destination("/exchange/te%2Fst/pa%2Ftt%2Fern").
|
|
|
|
|
|
2010-10-08 00:31:18 +08:00
|
|
|
create_message_id_test() ->
|
|
|
|
|
[<<"baz">>, "@@", "abc", "@@", "123"] =
|
|
|
|
|
rabbit_stomp_util:create_message_id(<<"baz">>, "abc", 123).
|
|
|
|
|
|
|
|
|
|
parse_valid_message_id_test() ->
|
|
|
|
|
{ok, {<<"bar">>, "abc", 123}} =
|
|
|
|
|
rabbit_stomp_util:parse_message_id("bar@@abc@@123").
|
|
|
|
|
|
|
|
|
|
parse_invalid_message_id_test() ->
|
|
|
|
|
{error, invalid_message_id} =
|
|
|
|
|
rabbit_stomp_util:parse_message_id("blah").
|
|
|
|
|
|
2010-10-01 19:27:10 +08:00
|
|
|
parse_destination(Destination) ->
|
2010-10-08 00:31:18 +08:00
|
|
|
rabbit_stomp_util:parse_destination(Destination).
|