body.vala 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /********************************************************************
  2. # Copyright 2016-2017 Daniel 'grindhold' Brendle
  3. #
  4. # This file is part of liboparl.
  5. #
  6. # liboparl is free software: you can redistribute it and/or
  7. # modify it under the terms of the GNU Lesser General Public License
  8. # as published by the Free Software Foundation, either
  9. # version 3 of the License, or (at your option) any later
  10. # version.
  11. #
  12. # liboparl is distributed in the hope that it will be
  13. # useful, but WITHOUT ANY WARRANTY; without even the implied
  14. # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. # PURPOSE. See the GNU Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public
  18. # License along with liboparl.
  19. # If not, see http://www.gnu.org/licenses/.
  20. *********************************************************************/
  21. using OParl;
  22. namespace OParlTest {
  23. public class BodyTest {
  24. private static GLib.HashTable<string,string> test_input;
  25. private static void init() {
  26. BodyTest.test_input = new GLib.HashTable<string,string>(GLib.str_hash, GLib.str_equal);
  27. BodyTest.test_input.insert("https://oparl.example.org/", Fixtures.system_sane);
  28. BodyTest.test_input.insert("https://oparl.example.org/bodies", Fixtures.body_list_sane);
  29. BodyTest.test_input.insert("https://oparl.example.org/body/0/organizations/", Fixtures.organization_list_sane);
  30. BodyTest.test_input.insert("https://oparl.example.org/body/0/meetings/", Fixtures.meeting_list_sane);
  31. BodyTest.test_input.insert("https://oparl.example.org/body/0/people/", Fixtures.person_list_sane);
  32. BodyTest.test_input.insert("https://oparl.example.org/body/0/papers/", Fixtures.paper_list_sane);
  33. }
  34. public static void add_tests () {
  35. BodyTest.init();
  36. Test.add_func ("/oparl/body/sane_input", () => {
  37. var client = new Client();
  38. TestHelper.mock_connect(ref client, BodyTest.test_input, null);
  39. System s;
  40. try {
  41. s = client.open("https://oparl.example.org/");
  42. } catch (ParsingError e) {
  43. GLib.assert_not_reached();
  44. }
  45. try {
  46. Body b = s.get_body().nth_data(0);
  47. assert (b.id == "https://oparl.example.org/body/0");
  48. assert (b.get_system() != null);
  49. assert (b.get_system() is OParl.System);
  50. assert (b.contact_email == "ris@beispielstadt.de");
  51. assert (b.contact_name == "RIS-Betreuung");
  52. assert (b.ags == "05315000");
  53. assert (b.rgs == "053150000000");
  54. assert (b.classification == "Kreisfreie Stadt");
  55. assert (b.equivalent.length == 2);
  56. assert (b.equivalent[0] == "http://d-nb.info/gnd/2015732-0");
  57. assert (b.equivalent[1] == "http://dbpedia.org/resource/Cologne");
  58. assert (b.short_name == "Köln");
  59. assert (b.name == "Stadt Köln, kreisfreie Stadt");
  60. assert (b.website == "http://www.beispielstadt.de/");
  61. assert (b.license == "http://creativecommons.org/licenses/by/4.0/");
  62. assert (b.license_valid_since.to_string() == "2015-01-01T14:28:31+0000");
  63. assert (b.oparl_since.to_string() == "2014-01-01T14:28:31+0000");
  64. assert (b.get_organization() != null);
  65. assert (b.get_organization().nth_data(0) != null);
  66. assert (b.get_organization().nth_data(0) is Organization);
  67. assert (b.get_person() != null);
  68. assert (b.get_person().nth_data(0) != null);
  69. assert (b.get_person().nth_data(0) is Person);
  70. assert (b.get_meeting() != null);
  71. assert (b.get_meeting().nth_data(0) != null);
  72. assert (b.get_meeting().nth_data(0) is Meeting);
  73. assert (b.get_paper() != null);
  74. assert (b.get_paper().nth_data(0) != null);
  75. assert (b.get_paper().nth_data(0) is Paper);
  76. } catch (ParsingError e) {
  77. GLib.assert_not_reached();
  78. }
  79. });
  80. Test.add_func ("/oparl/body/wrong_id_type", () => {
  81. var client = new Client();
  82. TestHelper.mock_connect(ref client, BodyTest.test_input, "\"https://oparl.example.org/body/0\"");
  83. try {
  84. System s = client.open("https://oparl.example.org/");
  85. s.get_body().nth_data(0);
  86. GLib.assert_not_reached();
  87. } catch (ParsingError e) {
  88. assert(e.message.contains("'id'"));
  89. }
  90. });
  91. Test.add_func ("/oparl/body/wrong_system_type", () => {
  92. var client = new Client();
  93. TestHelper.mock_connect(ref client, BodyTest.test_input, "\"https://oparl.example.org/\"");
  94. try {
  95. System s = client.open("https://oparl.example.org/");
  96. s.get_body().nth_data(0);
  97. GLib.assert_not_reached();
  98. } catch (ParsingError e) {
  99. assert(e.message.contains("'id'"));
  100. }
  101. });
  102. Test.add_func ("/oparl/body/wrong_contact_email_type", () => {
  103. var client = new Client();
  104. TestHelper.mock_connect(ref client, BodyTest.test_input, "\"ris@beispielstadt.de\"");
  105. try {
  106. System s = client.open("https://oparl.example.org/");
  107. s.get_body().nth_data(0);
  108. GLib.assert_not_reached();
  109. } catch (ParsingError e) {
  110. assert(e.message.contains("'contactEmail'"));
  111. }
  112. });
  113. Test.add_func ("/oparl/body/wrong_contact_name_type", () => {
  114. var client = new Client();
  115. TestHelper.mock_connect(ref client, BodyTest.test_input, "\"RIS-Betreuung\"");
  116. try {
  117. System s = client.open("https://oparl.example.org/");
  118. s.get_body().nth_data(0);
  119. GLib.assert_not_reached();
  120. } catch (ParsingError e) {
  121. assert(e.message.contains("'contactName'"));
  122. }
  123. });
  124. Test.add_func ("/oparl/body/wrong_ags_type", () => {
  125. var client = new Client();
  126. TestHelper.mock_connect(ref client, BodyTest.test_input, "\"05315000\"");
  127. try {
  128. System s = client.open("https://oparl.example.org/");
  129. s.get_body().nth_data(0);
  130. GLib.assert_not_reached();
  131. } catch (ParsingError e) {
  132. assert(e.message.contains("'ags'"));
  133. }
  134. });
  135. Test.add_func ("/oparl/body/wrong_rgs_type", () => {
  136. var client = new Client();
  137. TestHelper.mock_connect(ref client, BodyTest.test_input, "\"053150000000\"");
  138. try {
  139. System s = client.open("https://oparl.example.org/");
  140. s.get_body().nth_data(0);
  141. GLib.assert_not_reached();
  142. } catch (ParsingError e) {
  143. assert(e.message.contains("'rgs'"));
  144. }
  145. });
  146. Test.add_func ("/oparl/body/wrong_classification_type", () => {
  147. var client = new Client();
  148. TestHelper.mock_connect(ref client, BodyTest.test_input, "\"Kreisfreie Stadt\"");
  149. try {
  150. System s = client.open("https://oparl.example.org/");
  151. s.get_body().nth_data(0);
  152. GLib.assert_not_reached();
  153. } catch (ParsingError e) {
  154. assert(e.message.contains("'classification'"));
  155. }
  156. });
  157. Test.add_func ("/oparl/body/wrong_equivalent_type", () => {
  158. // TODO: implement
  159. });
  160. Test.add_func ("/oparl/body/wrong_website_type", () => {
  161. var client = new Client();
  162. TestHelper.mock_connect(ref client, BodyTest.test_input, "\"http://www.beispielstadt.de/\"");
  163. try {
  164. System s = client.open("https://oparl.example.org/");
  165. s.get_body().nth_data(0);
  166. GLib.assert_not_reached();
  167. } catch (ParsingError e) {
  168. assert(e.message.contains("'website'"));
  169. }
  170. });
  171. Test.add_func ("/oparl/body/wrong_license_type", () => {
  172. var client = new Client();
  173. TestHelper.mock_connect(ref client, BodyTest.test_input, "\"http://creativecommons.org/licenses/by/4.0/\"");
  174. try {
  175. System s = client.open("https://oparl.example.org/");
  176. s.get_body().nth_data(0);
  177. GLib.assert_not_reached();
  178. } catch (ParsingError e) {
  179. assert(e.message.contains("'license'"));
  180. }
  181. });
  182. Test.add_func ("/oparl/body/wrong_license_valid_since_type", () => {
  183. var client = new Client();
  184. TestHelper.mock_connect(ref client, BodyTest.test_input, "\"2015-01-01T14:28:31.568+0000\"");
  185. try {
  186. System s = client.open("https://oparl.example.org/");
  187. s.get_body().nth_data(0);
  188. GLib.assert_not_reached();
  189. } catch (ParsingError e) {
  190. assert(e.message.contains("'licenseValidSince'"));
  191. }
  192. });
  193. Test.add_func ("/oparl/body/wrong_oparl_since_type", () => {
  194. var client = new Client();
  195. TestHelper.mock_connect(ref client, BodyTest.test_input, "\"2014-01-01T14:28:31.568+0000\"");
  196. try {
  197. System s = client.open("https://oparl.example.org/");
  198. s.get_body().nth_data(0);
  199. GLib.assert_not_reached();
  200. } catch (ParsingError e) {
  201. assert(e.message.contains("'oparlSince'"));
  202. }
  203. });
  204. }
  205. }
  206. }