File indexing completed on 2024-05-12 05:10:05
0001 /*************************************************************************** 0002 Copyright (C) 2009-2020 Robby Stephenson <robby@periapsis.org> 0003 ***************************************************************************/ 0004 0005 /*************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or * 0008 * modify it under the terms of the GNU General Public License as * 0009 * published by the Free Software Foundation; either version 2 of * 0010 * the License or (at your option) version 3 or any later version * 0011 * accepted by the membership of KDE e.V. (or its successor approved * 0012 * by the membership of KDE e.V.), which shall act as a proxy * 0013 * defined in Section 14 of version 3 of the license. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, * 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0018 * GNU General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0022 * * 0023 ***************************************************************************/ 0024 0025 #undef QT_NO_CAST_FROM_ASCII 0026 0027 #include "srufetchertest.h" 0028 0029 #include "../fetch/srufetcher.h" 0030 #include "../collections/bookcollection.h" 0031 #include "../collections/bibtexcollection.h" 0032 #include "../collectionfactory.h" 0033 #include "../entry.h" 0034 #include "../utils/datafileregistry.h" 0035 0036 #include <KSharedConfig> 0037 #include <KConfigGroup> 0038 0039 #include <QTest> 0040 0041 QTEST_GUILESS_MAIN( SRUFetcherTest ) 0042 0043 SRUFetcherTest::SRUFetcherTest() : AbstractFetcherTest() { 0044 } 0045 0046 void SRUFetcherTest::initTestCase() { 0047 Tellico::RegisterCollection<Tellico::Data::BookCollection> registerBook(Tellico::Data::Collection::Book, "book"); 0048 Tellico::RegisterCollection<Tellico::Data::BibtexCollection> registerBibtex(Tellico::Data::Collection::Bibtex, "bibtex"); 0049 // since we use the MODS importer 0050 Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/mods2tellico.xsl")); 0051 } 0052 0053 void SRUFetcherTest::testTitle() { 0054 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::Title, 0055 QStringLiteral("Foundations of Qt Development")); 0056 Tellico::Fetch::Fetcher::Ptr fetcher = Tellico::Fetch::SRUFetcher::libraryOfCongress(this); 0057 0058 Tellico::Data::EntryList results = DO_FETCH(fetcher, request); 0059 0060 QCOMPARE(results.size(), 1); 0061 0062 Tellico::Data::EntryPtr entry = results.at(0); 0063 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Foundations of Qt development")); 0064 QCOMPARE(entry->field(QStringLiteral("author")), QStringLiteral("Thelin, Johan.")); 0065 QCOMPARE(entry->field(QStringLiteral("isbn")), QStringLiteral("1-59059-831-8")); 0066 } 0067 0068 void SRUFetcherTest::testIsbn() { 0069 // also testing multiple values 0070 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::ISBN, 0071 QStringLiteral("978-1-59059-831-3; 0-201-88954-4")); 0072 Tellico::Fetch::Fetcher::Ptr fetcher = Tellico::Fetch::SRUFetcher::libraryOfCongress(this); 0073 0074 Tellico::Data::EntryList results = DO_FETCH(fetcher, request); 0075 0076 QCOMPARE(results.size(), 2); 0077 0078 Tellico::Data::EntryPtr entry = results.at(1); 0079 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Foundations of Qt development")); 0080 QCOMPARE(entry->field(QStringLiteral("author")), QStringLiteral("Thelin, Johan.")); 0081 QCOMPARE(entry->field(QStringLiteral("isbn")), QStringLiteral("1-59059-831-8")); 0082 } 0083 0084 // see http://raoulm.home.xs4all.nl/mcq.htm 0085 void SRUFetcherTest::testKBTitle() { 0086 KConfigGroup cg = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("KB")); 0087 cg.writeEntry("Format", QStringLiteral("dc")); 0088 cg.writeEntry("Host", QStringLiteral("jsru.kb.nl")); 0089 cg.writeEntry("Path", QStringLiteral("/sru/sru.pl")); 0090 cg.writeEntry("Port", 80); 0091 cg.writeEntry("QueryFields", QStringLiteral("x-collection,x-fields")); 0092 cg.writeEntry("QueryValues", QStringLiteral("GGC,ISBN")); 0093 0094 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::Title, 0095 QStringLiteral("Godfried Bomans: Erik of het klein insectenboek")); 0096 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::SRUFetcher(this)); 0097 fetcher->readConfig(cg); 0098 0099 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 5); 0100 0101 Tellico::Data::EntryPtr entry; 0102 foreach(Tellico::Data::EntryPtr testEntry, results) { 0103 if(testEntry->field(QStringLiteral("entry-type")) == QStringLiteral("book")) { 0104 entry = testEntry; 0105 break; 0106 } 0107 } 0108 QVERIFY(entry); 0109 0110 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Godfried Bomans: Erik of het klein insectenboek")); 0111 QCOMPARE(entry->field(QStringLiteral("entry-type")), QStringLiteral("book")); 0112 QCOMPARE(entry->field(QStringLiteral("publisher")), QStringLiteral("Purmerend : Muusses")); 0113 QCOMPARE(entry->field(QStringLiteral("isbn")), QStringLiteral("90-231-1704-2")); 0114 QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("1971")); 0115 QVERIFY(!entry->field(QStringLiteral("url")).isEmpty()); 0116 } 0117 0118 // see http://raoulm.home.xs4all.nl/mcq.htm 0119 void SRUFetcherTest::testKBIsbn() { 0120 KConfigGroup cg = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("KB")); 0121 cg.writeEntry("Format", QStringLiteral("dc")); 0122 cg.writeEntry("Host", QStringLiteral("jsru.kb.nl")); 0123 cg.writeEntry("Path", QStringLiteral("/sru/sru.pl")); 0124 cg.writeEntry("Port", 80); 0125 cg.writeEntry("QueryFields", QStringLiteral("x-collection,x-fields")); 0126 cg.writeEntry("QueryValues", QStringLiteral("GGC,ISBN")); 0127 0128 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::ISBN, 0129 QStringLiteral("9023117042")); 0130 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::SRUFetcher(this)); 0131 fetcher->readConfig(cg); 0132 0133 Tellico::Data::EntryList results = DO_FETCH(fetcher, request); 0134 0135 // for whatever reason, there are two results with the same isbn and we want the second 0136 QCOMPARE(results.size(), 2); 0137 0138 Tellico::Data::EntryPtr entry = results.at(1); 0139 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Godfried Bomans: Erik of het klein insectenboek")); 0140 QCOMPARE(entry->field(QStringLiteral("entry-type")), QStringLiteral("book")); 0141 QCOMPARE(entry->field(QStringLiteral("publisher")), QStringLiteral("Purmerend : Muusses")); 0142 QCOMPARE(entry->field(QStringLiteral("isbn")), QStringLiteral("90-231-1704-2")); 0143 QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("1971")); 0144 QVERIFY(!entry->field(QStringLiteral("url")).isEmpty()); 0145 } 0146 0147 void SRUFetcherTest::testCopacIsbn() { 0148 KConfigGroup cg = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("Copac")); 0149 cg.writeEntry("Format", QStringLiteral("mods")); 0150 cg.writeEntry("Host", QStringLiteral("discover.libraryhub.jisc.ac.uk")); 0151 cg.writeEntry("Path", QStringLiteral("/discover")); 0152 cg.writeEntry("Port", 210); 0153 cg.writeEntry("Custom Fields", QStringLiteral("lcc")); 0154 0155 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::ISBN, 0156 QStringLiteral("1430202513")); 0157 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::SRUFetcher(this)); 0158 fetcher->readConfig(cg); 0159 0160 Tellico::Data::EntryList results = DO_FETCH(fetcher, request); 0161 0162 QCOMPARE(results.size(), 1); 0163 0164 Tellico::Data::EntryPtr entry = results.at(0); 0165 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Foundations of Qt Development")); 0166 QCOMPARE(entry->field(QStringLiteral("author")), QStringLiteral("Thelin, Johan.")); 0167 // the mods2tellico.xsl file returns the last ISBN value in the response, which is different in this case. Ignore for now 0168 // QCOMPARE(entry->field(QStringLiteral("isbn")), QStringLiteral("1-43020-251-3")); 0169 QCOMPARE(entry->field(QStringLiteral("lcc")), QStringLiteral("T385")); 0170 QCOMPARE(entry->field(QStringLiteral("lccn")), QStringLiteral("2008295709")); 0171 QCOMPARE(entry->field(QStringLiteral("doi")), QStringLiteral("10.1007/978-1-4302-0251-6")); 0172 QCOMPARE(entry->field(QStringLiteral("pub_year")), QStringLiteral("2007")); 0173 QVERIFY(entry->field(QStringLiteral("publisher")).contains(QStringLiteral("Apress"))); 0174 } 0175 0176 // https://bugs.kde.org/show_bug.cgi?id=463438 0177 void SRUFetcherTest::testHttpFallback() { 0178 KConfigGroup cg = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("DNB")); 0179 cg.writeEntry("Format", QStringLiteral("MARC21-xml")); 0180 cg.writeEntry("Scheme", QStringLiteral("https")); 0181 cg.writeEntry("Host", QStringLiteral("services.dnb.de")); 0182 cg.writeEntry("Path", QStringLiteral("/sru/dnb")); 0183 cg.writeEntry("Port", 443); // port 443 forces https for this test. Port 80 seems to fallback on the server side 0184 cg.writeEntry("QueryFields", QStringLiteral("maximumRecords")); 0185 cg.writeEntry("QueryValues", QStringLiteral("1")); 0186 0187 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::Title, 0188 QStringLiteral("Goethe")); 0189 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::SRUFetcher(this)); 0190 fetcher->readConfig(cg); 0191 0192 Tellico::Data::EntryList results = DO_FETCH(fetcher, request); 0193 0194 QCOMPARE(results.size(), 1); 0195 0196 Tellico::Data::EntryPtr entry = results.at(0); 0197 QVERIFY(!entry->field(QStringLiteral("title")).isEmpty()); 0198 }