123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- /********************************************************************
- # Copyright 2016-2017 Daniel 'grindhold' Brendle
- #
- # This file is part of liboparl.
- #
- # liboparl is free software: you can redistribute it and/or
- # modify it under the terms of the GNU Lesser General Public License
- # as published by the Free Software Foundation, either
- # version 3 of the License, or (at your option) any later
- # version.
- #
- # liboparl is distributed in the hope that it will be
- # useful, but WITHOUT ANY WARRANTY; without even the implied
- # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- # PURPOSE. See the GNU Lesser General Public License for more details.
- #
- # You should have received a copy of the GNU Lesser General Public
- # License along with liboparl.
- # If not, see http://www.gnu.org/licenses/.
- *********************************************************************/
- using OParl;
- namespace OParlTest {
- public class SystemTest {
- private static GLib.HashTable<string,string> test_input;
- private static void init() {
- SystemTest.test_input = new GLib.HashTable<string,string>(GLib.str_hash, GLib.str_equal);
- SystemTest.test_input.insert("https://oparl.example.org/", Fixtures.system_sane);
- SystemTest.test_input.insert("https://oparl.example.org/bodies", Fixtures.body_list_sane);
- }
- public static void add_tests () {
- SystemTest.init();
- Test.add_func ("/oparl/system/sane_input", () => {
- var client = new Client();
- TestHelper.mock_connect(ref client, SystemTest.test_input, null);
- System s;
- try {
- s = client.open("https://oparl.example.org/");
- } catch (ParsingError e) {
- GLib.assert_not_reached();
- }
- try {
- assert (s.id == "https://oparl.example.org/");
- assert (s.name == "Beispiel-System");
- assert (s.oparl_version == "https://schema.oparl.org/1.0/");
- assert (s.get_body() != null);
- assert (s.get_body().nth_data(0) is OParl.Body);
- assert (s.short_name == null);
- assert (s.license == null);
- assert (s.web == null);
- assert (!s.deleted);
- assert (s.keyword.length == 0);
- assert (s.created == null);
- assert (s.modified == null);
- assert (s.contact_email == "info@example.org");
- assert (s.contact_name == "Allgemeiner OParl Kontakt");
- assert (s.website == "http://www.example.org/");
- assert (s.vendor == "http://example-software.com/");
- assert (s.product == "http://example-software.com/oparl-server/");
- assert (s.other_oparl_versions[0] == "https://oparl2.example.org/");
- assert (s.other_oparl_versions.length == 1);
- } catch (ParsingError e) {
- GLib.assert_not_reached();
- }
- });
- Test.add_func ("/oparl/system/wrong_oparl_version_type", () => {
- var client = new Client();
- TestHelper.mock_connect(ref client, SystemTest.test_input, "\"https://schema.oparl.org/1.0/\"");
- try {
- client.open("https://oparl.example.org/");
- GLib.assert_not_reached();
- } catch (ParsingError e) {
- assert(e.message.contains("'oparlVersion'"));
- }
- });
- Test.add_func ("/oparl/system/wrong_contact_email_type", () => {
- var client = new Client();
- TestHelper.mock_connect(ref client, SystemTest.test_input, "\"info@example.org\"");
- try {
- client.open("https://oparl.example.org/");
- GLib.assert_not_reached();
- } catch (ParsingError e) {
- assert(e.message.contains("'contactEmail'"));
- }
- });
- Test.add_func ("/oparl/system/wrong_contact_name_type", () => {
- var client = new Client();
- TestHelper.mock_connect(ref client, SystemTest.test_input, "\"Allgemeiner OParl Kontakt\"");
- try {
- client.open("https://oparl.example.org/");
- GLib.assert_not_reached();
- } catch (ParsingError e) {
- assert(e.message.contains("'contactName'"));
- }
- });
- Test.add_func ("/oparl/system/wrong_website_type", () => {
- var client = new Client();
- TestHelper.mock_connect(ref client, SystemTest.test_input, "\"http://www.example.org/\"");
- try {
- client.open("https://oparl.example.org/");
- GLib.assert_not_reached();
- } catch (ParsingError e) {
- assert(e.message.contains("'website'"));
- }
- });
- Test.add_func ("/oparl/system/wrong_vendor_type", () => {
- var client = new Client();
- TestHelper.mock_connect(ref client, SystemTest.test_input, "\"http://example-software.com/\"");
- try {
- client.open("https://oparl.example.org/");
- GLib.assert_not_reached();
- } catch (ParsingError e) {
- assert(e.message.contains("'vendor'"));
- }
- });
- Test.add_func ("/oparl/system/wrong_product_type", () => {
- var client = new Client();
- TestHelper.mock_connect(ref client, SystemTest.test_input, "\"http://example-software.com/oparl-server/\"");
- try {
- client.open("https://oparl.example.org/");
- GLib.assert_not_reached();
- } catch (ParsingError e) {
- assert(e.message.contains("'product'"));
- }
- });
- Test.add_func ("/oparl/system/wrong_other_oparl_versions_type", () => {
- var client = new Client();
- TestHelper.mock_connect(ref client, SystemTest.test_input, "[\"https://oparl2.example.org/\"]");
- try {
- client.open("https://oparl.example.org/");
- GLib.assert_not_reached();
- } catch (ParsingError e) {
- assert(e.message.contains("'otherOparlVersions'"));
- }
- });
- }
- }
- }
|