File indexing completed on 2024-05-12 05:09:57
0001 /*************************************************************************** 0002 Copyright (C) 2013 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 "entrezfetchertest.h" 0028 0029 #include "../fetch/entrezfetcher.h" 0030 #include "../entry.h" 0031 #include "../collections/bibtexcollection.h" 0032 #include "../collectionfactory.h" 0033 #include "../utils/datafileregistry.h" 0034 0035 #include <KSharedConfig> 0036 0037 #include <QTest> 0038 0039 QTEST_GUILESS_MAIN( EntrezFetcherTest ) 0040 0041 EntrezFetcherTest::EntrezFetcherTest() : AbstractFetcherTest() { 0042 } 0043 0044 void EntrezFetcherTest::initTestCase() { 0045 Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/pubmed2tellico.xsl")); 0046 Tellico::RegisterCollection<Tellico::Data::BibtexCollection> registerBibtex(Tellico::Data::Collection::Bibtex, "bibtex"); 0047 0048 m_config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("entrez")); 0049 m_config.writeEntry("Custom Fields", QStringLiteral("abstract")); 0050 0051 m_fieldValues.insert(QStringLiteral("doi"), QStringLiteral("10.1016/j.tcb.2013.03.001")); 0052 m_fieldValues.insert(QStringLiteral("pmid"), QStringLiteral("23597843")); 0053 m_fieldValues.insert(QStringLiteral("title"), QStringLiteral("Stem cell competition: finding balance in the niche.")); 0054 m_fieldValues.insert(QStringLiteral("author"), QStringLiteral("Rachel R Stine; Erika L Matunis")); 0055 // m_fieldValues.insert(QStringLiteral("volume"), QStringLiteral("85")); 0056 m_fieldValues.insert(QStringLiteral("journal"), QStringLiteral("Trends in cell biology")); 0057 // m_fieldValues.insert(QStringLiteral("publisher"), QStringLiteral("Springer")); 0058 m_fieldValues.insert(QStringLiteral("year"), QStringLiteral("2013")); 0059 m_fieldValues.insert(QStringLiteral("month"), QStringLiteral("8")); 0060 m_fieldValues.insert(QStringLiteral("entry-type"), QStringLiteral("article")); 0061 } 0062 0063 void EntrezFetcherTest::testTitle() { 0064 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::Title, 0065 m_fieldValues.value(QStringLiteral("title"))); 0066 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::EntrezFetcher(this)); 0067 fetcher->readConfig(m_config); 0068 0069 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0070 0071 QCOMPARE(results.size(), 1); 0072 Tellico::Data::EntryPtr entry = results.at(0); 0073 0074 QHashIterator<QString, QString> i(m_fieldValues); 0075 while(i.hasNext()) { 0076 i.next(); 0077 QCOMPARE(entry->field(i.key()), i.value()); 0078 } 0079 QVERIFY(entry->field(QStringLiteral("abstract")).contains(QStringLiteral("Drosophila"))); 0080 } 0081 0082 void EntrezFetcherTest::testAuthor() { 0083 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::Person, 0084 QStringLiteral("Rachel R Stine")); 0085 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::EntrezFetcher(this)); 0086 0087 Tellico::Data::EntryList results = DO_FETCH(fetcher, request); 0088 0089 QVERIFY(results.size() > 1); 0090 } 0091 0092 void EntrezFetcherTest::testKeyword() { 0093 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::Keyword, 0094 QStringLiteral("Drosophila")); 0095 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::EntrezFetcher(this)); 0096 0097 // fetcher defaults to 25 at a time, ask for 26 to check search continue 0098 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 26); 0099 QCOMPARE(results.size(), 26); 0100 0101 // and make sure it's 26 different 0102 QSet<QString> titles; 0103 foreach(Tellico::Data::EntryPtr entry, results) { 0104 titles.insert(entry->title()); 0105 } 0106 QCOMPARE(titles.size(), results.size()); 0107 0108 } 0109 0110 void EntrezFetcherTest::testPMID() { 0111 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::PubmedID, 0112 m_fieldValues.value(QStringLiteral("pmid"))); 0113 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::EntrezFetcher(this)); 0114 0115 // there are several results for the same ISBN here 0116 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0117 0118 QCOMPARE(results.size(), 1); 0119 } 0120 0121 void EntrezFetcherTest::testDOI() { 0122 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::DOI, 0123 m_fieldValues.value(QStringLiteral("doi"))); 0124 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::EntrezFetcher(this)); 0125 fetcher->readConfig(m_config); 0126 0127 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0128 0129 QCOMPARE(results.size(), 1); 0130 Tellico::Data::EntryPtr entry = results.at(0); 0131 0132 QHashIterator<QString, QString> i(m_fieldValues); 0133 while(i.hasNext()) { 0134 i.next(); 0135 QCOMPARE(entry->field(i.key()), i.value()); 0136 } 0137 QVERIFY(entry->field(QStringLiteral("abstract")).contains(QStringLiteral("Drosophila"))); 0138 }