rabbitmq-bql / test / amq_interface_test.erl

%%   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 the RabbitMQ BQL Module.
%%
%%   The Initial Developers of the Original Code are LShift Ltd.,
%%   Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd.
%%
%%   Portions created by LShift Ltd., Cohesive Financial
%%   Technologies LLC., and Rabbit Technologies Ltd. are Copyright (C)
%%   2009 LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit
%%   Technologies Ltd.;
%%
%%   All Rights Reserved.
%%
%%   Contributor(s): ___________________________
%%
-module(amq_interface_test).

-include_lib("rabbit_common/include/rabbit.hrl").
-include_lib("rabbit_common/include/rabbit_framing.hrl").
-include_lib("eunit/include/eunit.hrl").

submit_create_command_test() ->
    Response = send_request("create exchange myexchange;"),
    ?assertEqual("{\"success\":true,\"messages\":[\"ok\"]}", Response).

submit_query_test() ->
    Response = send_request("select * from vhosts where name='/';"),
    ?assertEqual("{\"success\":true,\"messages\":[[{\"name\":\"/\"}]]}", Response).

submit_badly_formatted_query_test() ->
    Response = send_request("create invalidexchange myexchange;"),
    ?assertEqual("{\"success\":false,\"message\":\"syntax error before: \\\"invalidexchange\\\" on line 1\"}", Response).

submit_query_against_non_existant_object_test() ->
    Response = send_request("select * from something;"),
    ?assertEqual("{\"success\":true,\"messages\":[\"Unknown entity something specified to query\"]}", Response).

send_request(Content) ->
    Connection = Connection = lib_amqp:start_connection(),
    Client = bql_amqp_rpc_client:start(Connection, <<>>),
    Res = bql_amqp_rpc_client:call(Client, <<"bql.query">>, <<"application/json">>,
                                   list_to_binary("{\"query\":\"" ++ Content ++ "\"}"), 500),
    lib_amqp:close_connection(Connection),
    Res.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.