system.vala 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 SystemTest {
  24. private static GLib.HashTable<string,string> test_input;
  25. private static void init() {
  26. SystemTest.test_input = new GLib.HashTable<string,string>(GLib.str_hash, GLib.str_equal);
  27. SystemTest.test_input.insert("https://oparl.example.org/", Fixtures.system_sane);
  28. SystemTest.test_input.insert("https://oparl.example.org/bodies", Fixtures.body_list_sane);
  29. }
  30. public static void add_tests () {
  31. SystemTest.init();
  32. Test.add_func ("/oparl/system/sane_input", () => {
  33. var client = new Client();
  34. TestHelper.mock_connect(ref client, SystemTest.test_input, null);
  35. System s;
  36. try {
  37. s = client.open("https://oparl.example.org/");
  38. } catch (ParsingError e) {
  39. GLib.assert_not_reached();
  40. }
  41. try {
  42. assert (s.id == "https://oparl.example.org/");
  43. assert (s.name == "Beispiel-System");
  44. assert (s.oparl_version == "https://schema.oparl.org/1.0/");
  45. assert (s.get_body() != null);
  46. assert (s.get_body().nth_data(0) is OParl.Body);
  47. assert (s.short_name == null);
  48. assert (s.license == null);
  49. assert (s.web == null);
  50. assert (!s.deleted);
  51. assert (s.keyword.length == 0);
  52. assert (s.created == null);
  53. assert (s.modified == null);
  54. assert (s.contact_email == "info@example.org");
  55. assert (s.contact_name == "Allgemeiner OParl Kontakt");
  56. assert (s.website == "http://www.example.org/");
  57. assert (s.vendor == "http://example-software.com/");
  58. assert (s.product == "http://example-software.com/oparl-server/");
  59. assert (s.other_oparl_versions[0] == "https://oparl2.example.org/");
  60. assert (s.other_oparl_versions.length == 1);
  61. } catch (ParsingError e) {
  62. GLib.assert_not_reached();
  63. }
  64. });
  65. Test.add_func ("/oparl/system/wrong_oparl_version_type", () => {
  66. var client = new Client();
  67. TestHelper.mock_connect(ref client, SystemTest.test_input, "\"https://schema.oparl.org/1.0/\"");
  68. try {
  69. client.open("https://oparl.example.org/");
  70. GLib.assert_not_reached();
  71. } catch (ParsingError e) {
  72. assert(e.message.contains("'oparlVersion'"));
  73. }
  74. });
  75. Test.add_func ("/oparl/system/wrong_contact_email_type", () => {
  76. var client = new Client();
  77. TestHelper.mock_connect(ref client, SystemTest.test_input, "\"info@example.org\"");
  78. try {
  79. client.open("https://oparl.example.org/");
  80. GLib.assert_not_reached();
  81. } catch (ParsingError e) {
  82. assert(e.message.contains("'contactEmail'"));
  83. }
  84. });
  85. Test.add_func ("/oparl/system/wrong_contact_name_type", () => {
  86. var client = new Client();
  87. TestHelper.mock_connect(ref client, SystemTest.test_input, "\"Allgemeiner OParl Kontakt\"");
  88. try {
  89. client.open("https://oparl.example.org/");
  90. GLib.assert_not_reached();
  91. } catch (ParsingError e) {
  92. assert(e.message.contains("'contactName'"));
  93. }
  94. });
  95. Test.add_func ("/oparl/system/wrong_website_type", () => {
  96. var client = new Client();
  97. TestHelper.mock_connect(ref client, SystemTest.test_input, "\"http://www.example.org/\"");
  98. try {
  99. client.open("https://oparl.example.org/");
  100. GLib.assert_not_reached();
  101. } catch (ParsingError e) {
  102. assert(e.message.contains("'website'"));
  103. }
  104. });
  105. Test.add_func ("/oparl/system/wrong_vendor_type", () => {
  106. var client = new Client();
  107. TestHelper.mock_connect(ref client, SystemTest.test_input, "\"http://example-software.com/\"");
  108. try {
  109. client.open("https://oparl.example.org/");
  110. GLib.assert_not_reached();
  111. } catch (ParsingError e) {
  112. assert(e.message.contains("'vendor'"));
  113. }
  114. });
  115. Test.add_func ("/oparl/system/wrong_product_type", () => {
  116. var client = new Client();
  117. TestHelper.mock_connect(ref client, SystemTest.test_input, "\"http://example-software.com/oparl-server/\"");
  118. try {
  119. client.open("https://oparl.example.org/");
  120. GLib.assert_not_reached();
  121. } catch (ParsingError e) {
  122. assert(e.message.contains("'product'"));
  123. }
  124. });
  125. Test.add_func ("/oparl/system/wrong_other_oparl_versions_type", () => {
  126. var client = new Client();
  127. TestHelper.mock_connect(ref client, SystemTest.test_input, "[\"https://oparl2.example.org/\"]");
  128. try {
  129. client.open("https://oparl.example.org/");
  130. GLib.assert_not_reached();
  131. } catch (ParsingError e) {
  132. assert(e.message.contains("'otherOparlVersions'"));
  133. }
  134. });
  135. }
  136. }
  137. }