/ucengine/src/tests/meeting_tests.erl
Erlang | 202 lines | 156 code | 29 blank | 17 comment | 0 complexity | cab96cb76b136c39dd45f6b086e85ffe MD5 | raw file
1%% 2%% U.C.Engine - Unified Collaboration Engine 3%% Copyright (C) 2011 af83 4%% 5%% This program is free software: you can redistribute it and/or modify 6%% it under the terms of the GNU Affero General Public License as published by 7%% the Free Software Foundation, either version 3 of the License, or 8%% (at your option) any later version. 9%% 10%% This program is distributed in the hope that it will be useful, 11%% but WITHOUT ANY WARRANTY; without even the implied warranty of 12%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13%% GNU Affero General Public License for more details. 14%% 15%% You should have received a copy of the GNU Affero General Public License 16%% along with this program. If not, see <http://www.gnu.org/licenses/>. 17%% 18-module(meeting_tests). 19 20-include("uce.hrl"). 21-include_lib("eunit/include/eunit.hrl"). 22 23meeting_test_() -> 24 { setup 25 , fun fixtures:setup/0 26 , fun fixtures:teardown/1 27 , fun([_, BaseUrl, [Root, _Participant, Ugly|_]]) -> 28 [ ?_test(test_create(BaseUrl, Root)), 29 ?_test(test_create_conflict(BaseUrl, Root)), 30 ?_test(test_create_unauthorized(BaseUrl, Ugly)), 31 32 ?_test(test_get(BaseUrl, Root)), 33 ?_test(test_get_not_found_meeting(BaseUrl, Root)), 34 35 ?_test(test_list(BaseUrl, Root)), 36 37 ?_test(test_update(BaseUrl, Root)), 38 ?_test(test_update_not_found_meeting(BaseUrl, Root)), 39 ?_test(test_update_unauthorized(BaseUrl, Ugly)), 40 41 ?_test(test_join(BaseUrl, Root)), 42 ?_test(test_join_not_found_meeting(BaseUrl, Root)), 43 ?_test(test_join_not_found_uid(BaseUrl)), 44 ?_test(test_join_unauthorized(BaseUrl, Ugly)), 45 46 ?_test(test_leave(BaseUrl, Root)), 47 ?_test(test_leave_not_found_meeting(BaseUrl, Root)), 48 ?_test(test_leave_not_found_uid(BaseUrl, Root)), 49 ?_test(test_leave_unauthorized(BaseUrl, Ugly))] 50 end 51 }. 52 53test_create(BaseUrl, {RootUid, RootSid}) -> 54 Params = [ {"uid", RootUid} 55 , {"sid", RootSid} 56 , {"name", "newmeeting"} 57 , {"metadata[description]", "Meeting"}], 58 {struct, [{"result", "created"}]} = tests_utils:post(BaseUrl, "/meeting/", Params). 59 60test_create_conflict(BaseUrl, {RootUid, RootSid}) -> 61 Params = [ {"uid", RootUid} 62 , {"sid", RootSid} 63 , {"name", "newmeeting"} 64 , {"metadata[description]", "Meeting"}], 65 {struct, [{"error", "conflict"}]} = tests_utils:post(BaseUrl, "/meeting/", Params). 66 67test_create_unauthorized(BaseUrl, {UglyUid, UglySid}) -> 68 Params = [ {"uid", UglyUid} 69 , {"sid", UglySid} 70 , {"name", "newmeeting2"} 71 , {"metadata[description]", "Meeting"}], 72 {struct, [{"error", "unauthorized"}]} = 73 tests_utils:post(BaseUrl, "/meeting/", Params). 74 75 76test_get(BaseUrl, {RootUid, RootSid}) -> 77 Params = [ {"uid", RootUid} 78 , {"sid", RootSid}], 79 {struct, [{"result", 80 {struct, 81 [{"name", "newmeeting"}, 82 {"domain", _}, 83 {"metadata",{struct, [{"description", "Meeting"}]}}]}}]} = 84 tests_utils:get(BaseUrl, "/meeting/newmeeting", Params). 85 86test_get_not_found_meeting(BaseUrl, {RootUid, RootSid}) -> 87 Params = [ {"uid", RootUid} 88 , {"sid", RootSid}], 89 {struct, [{"error", "not_found"}]} = 90 tests_utils:get(BaseUrl, "/meeting/unexistentmeeting", Params). 91 92test_list(BaseUrl, {RootUid, RootSid}) -> 93 Params = [{"uid", RootUid}, 94 {"sid", RootSid}], 95 JSON = tests_utils:get(BaseUrl, "/meeting", Params), 96 test_meeting_in_list(["testmeeting"], JSON), 97 test_meeting_in_list(["meeting2"], JSON), 98 test_meeting_in_list(["meeting3"], JSON). 99 100test_update(BaseUrl, {RootUid, RootSid}) -> 101 Params = [ {"uid", RootUid} 102 , {"sid", RootSid} 103 , {"metadata[description]", "A new description"}], 104 {struct, [{"result", "ok"}]} = 105 tests_utils:put(BaseUrl, "/meeting/testmeeting", Params), 106 {struct, [{"result", 107 {struct, 108 [{"name", "testmeeting"}, 109 {"domain", _}, 110 {"metadata",{struct, [{"description", "A new description"}]}}]}}]} = 111 tests_utils:get(BaseUrl, "/meeting/testmeeting", Params). 112 113test_update_not_found_meeting(BaseUrl, {RootUid, RootSid}) -> 114 Params = [ {"uid", RootUid} 115 , {"sid", RootSid} 116 , {"metadata[description]", "A new description"}], 117 {struct, [{"error", "not_found"}]} = 118 tests_utils:put(BaseUrl, "/meeting/unexistentmeeting", Params). 119 120test_update_unauthorized(BaseUrl, {UglyUid, UglySid}) -> 121 Params = [ {"uid", UglyUid} 122 , {"sid", UglySid} 123 , {"metadata[description]", "Meeting"}], 124 {struct, [{"error", "unauthorized"}]} = 125 tests_utils:put(BaseUrl, "/meeting/testmeeting", Params). 126 127 128test_join(BaseUrl, {RootUid, RootSid}) -> 129 Params = [ {"uid", RootUid} 130 , {"sid", RootSid}], 131 132 {struct, [{"result", "ok"}]} = 133 tests_utils:post(BaseUrl, "/meeting/testmeeting/roster/", Params), 134 135 {struct, [{"result", {array, Array}}]} = 136 tests_utils:get(BaseUrl, "/meeting/testmeeting/roster/", Params), 137 [{struct,[{"uid",RootUid}, 138 {"name",_}, 139 {"domain",_}, 140 {"auth","password"}, 141 {"metadata",{struct,[]}}]}] = Array. 142 143test_join_not_found_meeting(BaseUrl, {RootUid, RootSid}) -> 144 Params = [ {"uid", RootUid} 145 , {"sid", RootSid}], 146 {struct, [{"error", "not_found"}]} = 147 tests_utils:post(BaseUrl, "/meeting/unexistentmeeting/roster/", Params). 148 149test_join_not_found_uid(BaseUrl) -> 150 Params = [ {"uid", "unexistentuid"}, 151 {"sid", ""}], 152 {struct, [{"error", "unauthorized"}]} = 153 tests_utils:post(BaseUrl, "/meeting/testmeeting/roster/", Params). 154 155test_join_unauthorized(BaseUrl, {UglyUid, UglySid}) -> 156 Params = [{"uid", UglyUid}, 157 {"sid", UglySid}], 158 {struct, [{"error", "unauthorized"}]} = 159 tests_utils:post(BaseUrl, "/meeting/testmeeting/roster/", Params). 160 161test_leave(BaseUrl, {RootUid, RootSid}) -> 162 Params = [ {"uid", RootUid} 163 , {"sid", RootSid}], 164 {struct, [{"result", "ok"}]} = 165 tests_utils:delete(BaseUrl, "/meeting/testmeeting/roster/" ++ RootUid, Params), 166 {struct, [{"result", {array, Array}}]} = 167 tests_utils:get(BaseUrl, "/meeting/testmeeting/roster", Params), 168 [] = Array. 169 170test_leave_not_found_meeting(BaseUrl, {RootUid, RootSid}) -> 171 Params = [ {"uid", RootUid} 172 , {"sid", RootSid}], 173 {struct, [{"error", "not_found"}]} = 174 tests_utils:delete(BaseUrl, "/meeting/unexistentmeeting/roster/" ++ RootUid, Params). 175 176test_leave_not_found_uid(BaseUrl, {RootUid, RootSid}) -> 177 Params = [ {"uid", RootUid} 178 , {"sid", RootSid}], 179 {struct, [{"error", "not_found"}]} = 180 tests_utils:delete(BaseUrl, "/meeting/testmeeting/roster/unexistentuid", Params). 181 182test_leave_unauthorized(BaseUrl, {UglyUid, UglySid}) -> 183 Params = [ {"uid", UglyUid}, 184 {"sid", UglySid}], 185 {struct, [{"error", "unauthorized"}]} = 186 tests_utils:delete(BaseUrl, "/meeting/testmeeting/roster/test.user@af83.com", Params). 187 188test_meeting_in_list(Id, {struct, [{"result", {array, List}}]}) -> 189 test_meeting_in_list(Id, List); 190test_meeting_in_list(Id, []) -> 191 throw({not_found, Id}); 192test_meeting_in_list(Id, [Meeting|Tail]) -> 193 {struct, 194 [{"name", MeetingName}, 195 {"domain", _}, 196 {"metadata",_}]} = Meeting, 197 case Id of 198 [MeetingName] -> 199 true; 200 _ -> 201 test_meeting_in_list(Id, Tail) 202 end.