PageRenderTime 43ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/ucengine/src/tests/meeting_tests.erl

http://github.com/AF83/ucengine
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. -include("uce.hrl").
  20. -include_lib("eunit/include/eunit.hrl").
  21. meeting_test_() ->
  22. { setup
  23. , fun fixtures:setup/0
  24. , fun fixtures:teardown/1
  25. , fun([_, BaseUrl, [Root, _Participant, Ugly|_]]) ->
  26. [ ?_test(test_create(BaseUrl, Root)),
  27. ?_test(test_create_conflict(BaseUrl, Root)),
  28. ?_test(test_create_unauthorized(BaseUrl, Ugly)),
  29. ?_test(test_get(BaseUrl, Root)),
  30. ?_test(test_get_not_found_meeting(BaseUrl, Root)),
  31. ?_test(test_list(BaseUrl, Root)),
  32. ?_test(test_update(BaseUrl, Root)),
  33. ?_test(test_update_not_found_meeting(BaseUrl, Root)),
  34. ?_test(test_update_unauthorized(BaseUrl, Ugly)),
  35. ?_test(test_join(BaseUrl, Root)),
  36. ?_test(test_join_not_found_meeting(BaseUrl, Root)),
  37. ?_test(test_join_not_found_uid(BaseUrl)),
  38. ?_test(test_join_unauthorized(BaseUrl, Ugly)),
  39. ?_test(test_leave(BaseUrl, Root)),
  40. ?_test(test_leave_not_found_meeting(BaseUrl, Root)),
  41. ?_test(test_leave_not_found_uid(BaseUrl, Root)),
  42. ?_test(test_leave_unauthorized(BaseUrl, Ugly))]
  43. end
  44. }.
  45. test_create(BaseUrl, {RootUid, RootSid}) ->
  46. Params = [ {"uid", RootUid}
  47. , {"sid", RootSid}
  48. , {"name", "newmeeting"}
  49. , {"metadata[description]", "Meeting"}],
  50. {struct, [{"result", "created"}]} = tests_utils:post(BaseUrl, "/meeting/", Params).
  51. test_create_conflict(BaseUrl, {RootUid, RootSid}) ->
  52. Params = [ {"uid", RootUid}
  53. , {"sid", RootSid}
  54. , {"name", "newmeeting"}
  55. , {"metadata[description]", "Meeting"}],
  56. {struct, [{"error", "conflict"}]} = tests_utils:post(BaseUrl, "/meeting/", Params).
  57. test_create_unauthorized(BaseUrl, {UglyUid, UglySid}) ->
  58. Params = [ {"uid", UglyUid}
  59. , {"sid", UglySid}
  60. , {"name", "newmeeting2"}
  61. , {"metadata[description]", "Meeting"}],
  62. {struct, [{"error", "unauthorized"}]} =
  63. tests_utils:post(BaseUrl, "/meeting/", Params).
  64. test_get(BaseUrl, {RootUid, RootSid}) ->
  65. Params = [ {"uid", RootUid}
  66. , {"sid", RootSid}],
  67. {struct, [{"result",
  68. {struct,
  69. [{"name", "newmeeting"},
  70. {"domain", _},
  71. {"metadata",{struct, [{"description", "Meeting"}]}}]}}]} =
  72. tests_utils:get(BaseUrl, "/meeting/newmeeting", Params).
  73. test_get_not_found_meeting(BaseUrl, {RootUid, RootSid}) ->
  74. Params = [ {"uid", RootUid}
  75. , {"sid", RootSid}],
  76. {struct, [{"error", "not_found"}]} =
  77. tests_utils:get(BaseUrl, "/meeting/unexistentmeeting", Params).
  78. test_list(BaseUrl, {RootUid, RootSid}) ->
  79. Params = [{"uid", RootUid},
  80. {"sid", RootSid}],
  81. JSON = tests_utils:get(BaseUrl, "/meeting", Params),
  82. test_meeting_in_list(["testmeeting"], JSON),
  83. test_meeting_in_list(["meeting2"], JSON),
  84. test_meeting_in_list(["meeting3"], JSON).
  85. test_update(BaseUrl, {RootUid, RootSid}) ->
  86. Params = [ {"uid", RootUid}
  87. , {"sid", RootSid}
  88. , {"metadata[description]", "A new description"}],
  89. {struct, [{"result", "ok"}]} =
  90. tests_utils:put(BaseUrl, "/meeting/testmeeting", Params),
  91. {struct, [{"result",
  92. {struct,
  93. [{"name", "testmeeting"},
  94. {"domain", _},
  95. {"metadata",{struct, [{"description", "A new description"}]}}]}}]} =
  96. tests_utils:get(BaseUrl, "/meeting/testmeeting", Params).
  97. test_update_not_found_meeting(BaseUrl, {RootUid, RootSid}) ->
  98. Params = [ {"uid", RootUid}
  99. , {"sid", RootSid}
  100. , {"metadata[description]", "A new description"}],
  101. {struct, [{"error", "not_found"}]} =
  102. tests_utils:put(BaseUrl, "/meeting/unexistentmeeting", Params).
  103. test_update_unauthorized(BaseUrl, {UglyUid, UglySid}) ->
  104. Params = [ {"uid", UglyUid}
  105. , {"sid", UglySid}
  106. , {"metadata[description]", "Meeting"}],
  107. {struct, [{"error", "unauthorized"}]} =
  108. tests_utils:put(BaseUrl, "/meeting/testmeeting", Params).
  109. test_join(BaseUrl, {RootUid, RootSid}) ->
  110. Params = [ {"uid", RootUid}
  111. , {"sid", RootSid}],
  112. {struct, [{"result", "ok"}]} =
  113. tests_utils:post(BaseUrl, "/meeting/testmeeting/roster/", Params),
  114. {struct, [{"result", {array, Array}}]} =
  115. tests_utils:get(BaseUrl, "/meeting/testmeeting/roster/", Params),
  116. [{struct,[{"uid",RootUid},
  117. {"name",_},
  118. {"domain",_},
  119. {"auth","password"},
  120. {"metadata",{struct,[]}}]}] = Array.
  121. test_join_not_found_meeting(BaseUrl, {RootUid, RootSid}) ->
  122. Params = [ {"uid", RootUid}
  123. , {"sid", RootSid}],
  124. {struct, [{"error", "not_found"}]} =
  125. tests_utils:post(BaseUrl, "/meeting/unexistentmeeting/roster/", Params).
  126. test_join_not_found_uid(BaseUrl) ->
  127. Params = [ {"uid", "unexistentuid"},
  128. {"sid", ""}],
  129. {struct, [{"error", "unauthorized"}]} =
  130. tests_utils:post(BaseUrl, "/meeting/testmeeting/roster/", Params).
  131. test_join_unauthorized(BaseUrl, {UglyUid, UglySid}) ->
  132. Params = [{"uid", UglyUid},
  133. {"sid", UglySid}],
  134. {struct, [{"error", "unauthorized"}]} =
  135. tests_utils:post(BaseUrl, "/meeting/testmeeting/roster/", Params).
  136. test_leave(BaseUrl, {RootUid, RootSid}) ->
  137. Params = [ {"uid", RootUid}
  138. , {"sid", RootSid}],
  139. {struct, [{"result", "ok"}]} =
  140. tests_utils:delete(BaseUrl, "/meeting/testmeeting/roster/" ++ RootUid, Params),
  141. {struct, [{"result", {array, Array}}]} =
  142. tests_utils:get(BaseUrl, "/meeting/testmeeting/roster", Params),
  143. [] = Array.
  144. test_leave_not_found_meeting(BaseUrl, {RootUid, RootSid}) ->
  145. Params = [ {"uid", RootUid}
  146. , {"sid", RootSid}],
  147. {struct, [{"error", "not_found"}]} =
  148. tests_utils:delete(BaseUrl, "/meeting/unexistentmeeting/roster/" ++ RootUid, Params).
  149. test_leave_not_found_uid(BaseUrl, {RootUid, RootSid}) ->
  150. Params = [ {"uid", RootUid}
  151. , {"sid", RootSid}],
  152. {struct, [{"error", "not_found"}]} =
  153. tests_utils:delete(BaseUrl, "/meeting/testmeeting/roster/unexistentuid", Params).
  154. test_leave_unauthorized(BaseUrl, {UglyUid, UglySid}) ->
  155. Params = [ {"uid", UglyUid},
  156. {"sid", UglySid}],
  157. {struct, [{"error", "unauthorized"}]} =
  158. tests_utils:delete(BaseUrl, "/meeting/testmeeting/roster/test.user@af83.com", Params).
  159. test_meeting_in_list(Id, {struct, [{"result", {array, List}}]}) ->
  160. test_meeting_in_list(Id, List);
  161. test_meeting_in_list(Id, []) ->
  162. throw({not_found, Id});
  163. test_meeting_in_list(Id, [Meeting|Tail]) ->
  164. {struct,
  165. [{"name", MeetingName},
  166. {"domain", _},
  167. {"metadata",_}]} = Meeting,
  168. case Id of
  169. [MeetingName] ->
  170. true;
  171. _ ->
  172. test_meeting_in_list(Id, Tail)
  173. end.