File indexing completed on 2024-05-12 05:10:05
0001 /*************************************************************************** 0002 Copyright (C) 2012 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 "springerfetchertest.h" 0028 0029 #include "../fetch/springerfetcher.h" 0030 #include "../entry.h" 0031 #include "../collections/bibtexcollection.h" 0032 #include "../collectionfactory.h" 0033 #include "../utils/datafileregistry.h" 0034 0035 #include <QTest> 0036 0037 QTEST_GUILESS_MAIN( SpringerFetcherTest ) 0038 0039 SpringerFetcherTest::SpringerFetcherTest() : AbstractFetcherTest() { 0040 } 0041 0042 void SpringerFetcherTest::initTestCase() { 0043 Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/springer2tellico.xsl")); 0044 Tellico::RegisterCollection<Tellico::Data::BibtexCollection> registerBibtex(Tellico::Data::Collection::Bibtex, "bibtex"); 0045 0046 m_fieldValues.insert(QStringLiteral("doi"), QStringLiteral("10.1007/BF02174211")); 0047 // m_fieldValues.insert(QStringLiteral("entry-type"), QStringLiteral("article")); 0048 m_fieldValues.insert(QStringLiteral("title"), QStringLiteral("The roughening transition of the three-dimensional Ising interface: A Monte Carlo study")); 0049 m_fieldValues.insert(QStringLiteral("author"), QStringLiteral("Hasenbusch, M.; Meyer, S.; Pütz, M.")); 0050 m_fieldValues.insert(QStringLiteral("volume"), QStringLiteral("85")); 0051 m_fieldValues.insert(QStringLiteral("journal"), QStringLiteral("Journal of Statistical Physics")); 0052 m_fieldValues.insert(QStringLiteral("publisher"), QStringLiteral("Springer")); 0053 m_fieldValues.insert(QStringLiteral("year"), QStringLiteral("1996")); 0054 m_fieldValues.insert(QStringLiteral("entry-type"), QStringLiteral("article")); 0055 } 0056 0057 void SpringerFetcherTest::testTitle() { 0058 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::Title, 0059 QStringLiteral("roughening transition of the three-dimensional Ising interface")); 0060 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::SpringerFetcher(this)); 0061 QVERIFY(fetcher->canSearch(request.key())); 0062 0063 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0064 0065 QCOMPARE(results.size(), 1); 0066 Tellico::Data::EntryPtr entry = results.at(0); 0067 0068 QHashIterator<QString, QString> i(m_fieldValues); 0069 while(i.hasNext()) { 0070 i.next(); 0071 QCOMPARE(entry->field(i.key()), i.value()); 0072 } 0073 QVERIFY(entry->field(QStringLiteral("abstract")).contains(QStringLiteral("Kosterlitz-Thouless"))); 0074 } 0075 0076 void SpringerFetcherTest::testAuthor() { 0077 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::Person, 0078 QStringLiteral("Albert Einstein")); 0079 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::SpringerFetcher(this)); 0080 QVERIFY(fetcher->canSearch(request.key())); 0081 0082 Tellico::Data::EntryList results = DO_FETCH(fetcher, request); 0083 0084 QVERIFY(results.size() > 1); 0085 } 0086 0087 void SpringerFetcherTest::testKeyword() { 0088 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::Keyword, 0089 QStringLiteral("Hadron-hadron scattering")); 0090 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::SpringerFetcher(this)); 0091 QVERIFY(fetcher->canSearch(request.key())); 0092 0093 // spring fetcher defaults to 10 at a time, expect 11 to check search continue 0094 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 11); 0095 0096 QCOMPARE(results.size(), 11); 0097 } 0098 0099 void SpringerFetcherTest::testISBN() { 0100 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::ISBN, 0101 QStringLiteral("978-3-7643-7436-5")); 0102 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::SpringerFetcher(this)); 0103 QVERIFY(fetcher->canSearch(request.key())); 0104 0105 // there are several results for the same ISBN here 0106 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0107 0108 QCOMPARE(results.size(), 1); 0109 } 0110 0111 void SpringerFetcherTest::testDOI() { 0112 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::DOI, 0113 m_fieldValues.value(QStringLiteral("doi"))); 0114 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::SpringerFetcher(this)); 0115 QVERIFY(fetcher->canSearch(request.key())); 0116 0117 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0118 0119 QCOMPARE(results.size(), 1); 0120 Tellico::Data::EntryPtr entry = results.at(0); 0121 0122 QHashIterator<QString, QString> i(m_fieldValues); 0123 while(i.hasNext()) { 0124 i.next(); 0125 QCOMPARE(entry->field(i.key()), i.value()); 0126 } 0127 QVERIFY(entry->field(QStringLiteral("abstract")).contains(QStringLiteral("Kosterlitz-Thouless"))); 0128 } 0129 0130 void SpringerFetcherTest::testUpdate() { 0131 Tellico::Data::CollPtr coll(new Tellico::Data::BibtexCollection(true)); 0132 Tellico::Data::EntryPtr entry(new Tellico::Data::Entry(coll)); 0133 coll->addEntries(entry); 0134 entry->setField(QStringLiteral("doi"), m_fieldValues.value(QStringLiteral("doi"))); 0135 0136 Tellico::Fetch::SpringerFetcher fetcher(this); 0137 auto request = fetcher.updateRequest(entry); 0138 request.setCollectionType(coll->type()); 0139 QCOMPARE(request.key(), Tellico::Fetch::DOI); 0140 QCOMPARE(request.value(), m_fieldValues.value(QStringLiteral("doi"))); 0141 }