File indexing completed on 2024-05-12 05:09:56

0001 /***************************************************************************
0002     Copyright (C) 2015-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 "crossreffetchertest.h"
0028 
0029 #include "../fetch/crossreffetcher.h"
0030 #include "../collections/bibtexcollection.h"
0031 #include "../collectionfactory.h"
0032 #include "../entry.h"
0033 #include "../utils/datafileregistry.h"
0034 
0035 #include <KSharedConfig>
0036 
0037 #include <QTest>
0038 
0039 QTEST_GUILESS_MAIN( CrossRefFetcherTest )
0040 
0041 CrossRefFetcherTest::CrossRefFetcherTest() : AbstractFetcherTest() {
0042 }
0043 
0044 void CrossRefFetcherTest::initTestCase() {
0045   Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/unixref2tellico.xsl"));
0046   Tellico::RegisterCollection<Tellico::Data::BibtexCollection> registerBibtex(Tellico::Data::Collection::Bibtex, "bibtex");
0047 
0048   m_config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("crossref"));
0049   m_config.writeEntry("Email", QStringLiteral("robby@periapsis.org"));
0050 
0051   m_fieldValues.insert(QStringLiteral("doi"), QStringLiteral("10.2514/1.G000894"));
0052   m_fieldValues.insert(QStringLiteral("entry-type"), QStringLiteral("article"));
0053   m_fieldValues.insert(QStringLiteral("title"), QStringLiteral("Robustness and Efficiency Improvements for Star Tracker Attitude Estimation"));
0054   m_fieldValues.insert(QStringLiteral("author"), QStringLiteral("Tjorven Delabie; Joris De Schutter; Bart Vandenbussche"));
0055   m_fieldValues.insert(QStringLiteral("pages"), QStringLiteral("2108-2121"));
0056   m_fieldValues.insert(QStringLiteral("journal"), QStringLiteral("Journal of Guidance, Control, and Dynamics"));
0057   m_fieldValues.insert(QStringLiteral("year"), QStringLiteral("2015"));
0058   m_fieldValues.insert(QStringLiteral("month"), QStringLiteral("11"));
0059 }
0060 
0061 void CrossRefFetcherTest::testDOI() {
0062   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::DOI,
0063                                        m_fieldValues.value(QStringLiteral("doi")));
0064   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::CrossRefFetcher(this));
0065   fetcher->readConfig(m_config);
0066 
0067   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0068 
0069   QCOMPARE(results.size(), 1);
0070   Tellico::Data::EntryPtr entry = results.at(0);
0071 
0072   QHashIterator<QString, QString> i(m_fieldValues);
0073   while(i.hasNext()) {
0074     i.next();
0075     QCOMPARE(entry->field(i.key()), i.value());
0076   }
0077 }