Browse files

Added more get functionality to CWIGA, will finish off later.

  • Loading branch information...
1 parent 1c0f3d1 commit 2d3218670307ece9e8b8b6756121cc8968c9827a @baphled committed Mar 28, 2009
Showing with 52 additions and 1 deletion.
  1. +6 −0 lib/chatterl/src/cwiga.erl
  2. +46 −1 lib/chatterl/src/test_cwiga.erl
View
6 lib/chatterl/src/cwiga.erl
@@ -55,8 +55,14 @@ handle('GET',"/users/connect/" ++ Client,ContentType,_Post) ->
success(chatterl_mid_man:connect(ContentType,Client),ContentType);
handle('GET',"/users/disconnect/" ++ Client,ContentType,_Post) ->
success(chatterl_mid_man:disconnect(ContentType,Client),ContentType);
+handle('GET',"/users/list/" ++ Group,ContentType,_Post) ->
+ success(chatterl_mid_man:user_list(ContentType,Group),ContentType);
handle('GET',"/users/list",ContentType,_Post) ->
success(chatterl_mid_man:user_list(ContentType),ContentType);
+handle('GET',"/users/poll/" ++ Client,ContentType,_Post) ->
+ success(chatterl_mid_man:user_poll(ContentType,Client),ContentType);
+handle('GET',"/groups/list",ContentType,_Post) ->
+ success(chatterl_mid_man:group_list(ContentType),ContentType);
handle(_,Path,ContentType,_) ->
Response = message_handler:get_response_body(ContentType,
message_handler:build_carrier("error", "Unknown command: " ++Path)),
View
47 lib/chatterl/src/test_cwiga.erl
@@ -6,12 +6,13 @@
-import(test_helpers,[check_response/2,check_json/1]).
handles_test_() ->
- {Client,Group,ContentType} = {"baph","nu",["text/json"]},
+ {Client,Client2,Group,ContentType} = {"baph","baphled","nu",["text/json"]},
[{setup,
fun() ->
inets:start(),
chatterl_serv:start(),
chatterl_mid_man:start(),
+ chatterl_serv:create(Group,"nu room"),
cwiga:start_link(8080)
end,
fun(_) ->
@@ -35,6 +36,14 @@ handles_test_() ->
?assertEqual(200,check_response(code,Response)),
?assertEqual({struct,[{<<"clients">>,[]}]},check_json(mochijson2:decode(check_response(body,Response))))
end},
+ {"CWIGA can list of users in a groups",
+ fun() ->
+ Response = http:request("http://127.0.0.1:8080/users/list/" ++ Group),
+ Response2 = http:request("http://127.0.0.1:8080/users/list/" ++ "blah"),
+ ?assertEqual(200,check_response(code,Response)),
+ ?assertEqual({struct,[{<<"clients">>,[]}]},check_json(mochijson2:decode(check_response(body,Response)))),
+ ?assertEqual(<<"Group: blah doesn't exist">>,check_json(mochijson2:decode(check_response(body,Response2))))
+ end},
{"CWIGA can retrieve responses in XML format",
fun() ->
Response = http:request("http://127.0.0.1:8080/users/list.xml"),
@@ -56,3 +65,39 @@ handles_test_() ->
?assertEqual(<<"Disconnected">>,check_json(mochijson2:decode(check_response(body,Response)))),
?assertEqual(<<"Not connected">>,check_json(mochijson2:decode(check_response(body,Response2))))
end}]}].
+
+groups_handle_test_() ->
+ {Client,Client2,Group,ContentType} = {"baph","baphled","nu",["text/json"]},
+ [{setup,
+ fun() ->
+ inets:start(),
+ chatterl_serv:start(),
+ chatterl_mid_man:start(),
+ cwiga:start_link(8080),
+ http:request("http://127.0.0.1:8080/users/connect/" ++ Client)
+ end,
+ fun(_) ->
+ chatterl_mid_man:stop(),
+ chatterl_serv:stop(),
+ cwiga:stop()
+ end,
+ [
+ {"CWIGA allows clients to poll chatterl for messages",
+ fun() ->
+ Response = http:request("http://127.0.0.1:8080/users/poll/" ++ "blah"),
+ Response2 = http:request("http://127.0.0.1:8080/users/poll/" ++ Client),
+ ?assertEqual(200,check_response(code,Response)),
+ ?assertEqual(200,check_response(code,Response)),
+ ?assertEqual(<<"Client: blah doesn't exist">>,check_json(mochijson2:decode(check_response(body,Response)))),
+ ?assertEqual({struct,[{<<"messages">>,[]}]},check_json(mochijson2:decode(check_response(body,Response2))))
+ end},
+ {"CWIGA can list the groups on chatterl",
+ fun() ->
+ Response = http:request("http://127.0.0.1:8080/groups/list"),
+ chatterl_serv:create(Group,"nu room"),
+ Response2 = http:request("http://127.0.0.1:8080/groups/list"),
+ ?assertEqual(200,check_response(code,Response)),
+ ?assertEqual(200,check_response(code,Response2)),
+ ?assertEqual({struct,[{<<"groups">>,[]}]},check_json(mochijson2:decode(check_response(body,Response)))),
+ ?assert(Response /= Response2)
+ end}]}].

0 comments on commit 2d32186

Please sign in to comment.