[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [conquirere] /: add unittest for the Nepomuk -> bibtex export and fix some small bugs with it
From:       Jörg_Ehrichs <Joerg.Ehrichs () gmx ! de>
Date:       2012-08-31 16:36:51
Message-ID: 20120831163651.F3431A60A6 () git ! kde ! org
[Download RAW message or body]

Git commit b71f2d421438fa6415e3126f5d661eb480d24966 by Jörg Ehrichs.
Committed on 31/08/2012 at 18:35.
Pushed by jehrichs into branch 'master'.

add unittest for the Nepomuk -> bibtex export and fix some small bugs with it

M  +1    -0    src/nbibio/nbibexporterfile.cpp
M  +1    -0    src/nbibio/nbibexporterfile.h
M  +1    -1    src/nbibio/nbibimporterbibtex.h
M  +24   -10   src/nbibio/pipe/nepomuktobibtexpipe.cpp
M  +1    -1    src/sro/nbib/chapter.h
M  +1    -1    src/sro/nbib/collection.h
M  +1    -1    src/sro/nbib/journal.h
M  +1    -1    src/sro/nbib/journalissue.h
M  +1    -1    src/sro/nbib/techreport.h
M  +1    -1    src/sro/ncal/unionparentclass.h
M  +1    -0    tests/CMakeLists.txt
M  +1    -1    tests/Test-core.project/coreproject.cpp
A  +39   -0    tests/Test-nbibio.nepomuk2bibtex/CMakeLists.txt
A  +568  -0    tests/Test-nbibio.nepomuk2bibtex/nepomukbibtex.cpp     [License: GPL \
(v2+)]

http://commits.kde.org/conquirere/b71f2d421438fa6415e3126f5d661eb480d24966

diff --git a/src/nbibio/nbibexporterfile.cpp b/src/nbibio/nbibexporterfile.cpp
index d59426f..c19d1ba 100644
--- a/src/nbibio/nbibexporterfile.cpp
+++ b/src/nbibio/nbibexporterfile.cpp
@@ -68,6 +68,7 @@ bool NBibExporterFile::save(QIODevice *iodevice, const \
QList<Nepomuk2::Resource>  case EXPORT_BIBTEX:
     {
         FileExporterBibTeX feb;
+        //FIXME: define strings for BibTex Config enum values and use the min the \
exporters  /*
         feb.setEncoding(ConqSettings::encoding())
         feb.keyEncoding = ConqSettings::encoding();
diff --git a/src/nbibio/nbibexporterfile.h b/src/nbibio/nbibexporterfile.h
index 6214a47..28936ee 100644
--- a/src/nbibio/nbibexporterfile.h
+++ b/src/nbibio/nbibexporterfile.h
@@ -47,6 +47,7 @@ public:
     explicit NBibExporterFile();
 
     void setFileType(FileType type);
+
     /**
       * Exports a list of publication or reference resources to a file
       *
diff --git a/src/nbibio/nbibimporterbibtex.h b/src/nbibio/nbibimporterbibtex.h
index 797470e..9514011 100644
--- a/src/nbibio/nbibimporterbibtex.h
+++ b/src/nbibio/nbibimporterbibtex.h
@@ -56,7 +56,7 @@ public:
     virtual ~NBibImporterBibTex();
 
     /**
-      * loads the bibtex file directly into the nepomuk staorage without using \
Akonadi or the possibility +      * loads the bibtex file directly into the nepomuk \
                storage without using Akonadi or the possibility
       * to find duplicates first.
       *
       * @p iodevice the device to read from via KBibTeX::FileImporterBibTeX
diff --git a/src/nbibio/pipe/nepomuktobibtexpipe.cpp \
b/src/nbibio/pipe/nepomuktobibtexpipe.cpp index c749760..f3037cb 100644
--- a/src/nbibio/pipe/nepomuktobibtexpipe.cpp
+++ b/src/nbibio/pipe/nepomuktobibtexpipe.cpp
@@ -70,6 +70,9 @@ void NepomukToBibTexPipe::pipeExport(QList<Nepomuk2::Resource> \
resources)  Nepomuk2::Resource reference;
         Nepomuk2::Resource publication;
 
+        //BUG: not all types are fetched correctly, fixed in 4.9.1
+        kDebug() << resource.types();
+
         // first check if we operate on a Reference or a Publication
         if(resource.hasType( NBIB::Reference() )) {
             // we have a Reference
@@ -83,6 +86,10 @@ void NepomukToBibTexPipe::pipeExport(QList<Nepomuk2::Resource> \
resources)  publication = resource;
         }
 
+        //BUG: not all types are fetched correctly, fixed in 4.9.1
+        kDebug() << publication.types();
+        kDebug() << reference.types();
+
         QString citeKey = reference.property(NBIB::citeKey()).toString();
         if(citeKey.isEmpty()) {
             kDebug() << "unknown citeKey for the bibtex pipe export :: create one";
@@ -155,7 +162,7 @@ void NepomukToBibTexPipe::useStrictTypes(bool strict)
 QString NepomukToBibTexPipe::retrieveEntryType(Nepomuk2::Resource reference, \
Nepomuk2::Resource publication)  {
     QString type;
-
+    //FIXME: simplyfy this via globals.h refactoring, not all types are recocnized \
currently  if(publication.hasType(NBIB::Dictionary())) {
         QString pages = reference.property(NBIB::pages()).toString();
         Nepomuk2::Resource chapter = \
reference.property(NBIB::referencedPart()).toResource(); @@ -184,8 +191,12 @@ QString \
NepomukToBibTexPipe::retrieveEntryType(Nepomuk2::Resource reference, Nep  }
         }
         else {
-            Nepomuk2::Resource typeResource(publication.type());
-            type = typeResource.genericLabel();
+            // check for publisher, its book with and booklet without
+            QList<Nepomuk2::Resource> publisher = publication.property( \
NCO::publisher() ).toResourceList(); +            if(publisher.isEmpty())
+                type = QLatin1String("Booklet");
+            else
+                type = QLatin1String("Book");
         }
     }
     else if(publication.hasType(NBIB::Proceedings())) {
@@ -203,9 +214,17 @@ QString \
NepomukToBibTexPipe::retrieveEntryType(Nepomuk2::Resource reference, Nep  else \
if(publication.hasType(NBIB::Website())) {  type = QLatin1String("Website");
     }
+    else if(publication.hasType(NBIB::Techreport())) {
+        type = QLatin1String("Techreport");
+    }
+    else if(publication.hasType(NBIB::Manual())) {
+        type = QLatin1String("Manual");
+    }
     // handle special articles
     else if(publication.hasType(NBIB::Article())) {
         Nepomuk2::Resource collection = \
publication.property(NBIB::collection()).toResource(); +        //BUG:: Not all types \
are fetched, fixed in 4.9.1 +        collection.types();
         if(collection.hasType(NBIB::Proceedings())) {
             type = QLatin1String("Inproceedings"); //article in some proceedings \
paper  }
@@ -222,13 +241,8 @@ QString \
NepomukToBibTexPipe::retrieveEntryType(Nepomuk2::Resource reference, Nep  }
     // all other cases
     else {
-        Nepomuk2::Resource typeResource(publication.type());
-        type = typeResource.genericLabel();
-
-        Nepomuk2::Resource typeResource2(NBIB::Publication());
-        if(type == typeResource2.genericLabel()) {
-            type = QLatin1String("Misc");
-        }
+        //FIXME: not everything here is misc type, use global function to get the \
correct type +        type = QLatin1String("Misc");
     }
 
     // if we have strict export, transforn into standard types
diff --git a/src/sro/nbib/chapter.h b/src/sro/nbib/chapter.h
index 5e2a65b..b11823b 100644
--- a/src/sro/nbib/chapter.h
+++ b/src/sro/nbib/chapter.h
@@ -10,7 +10,7 @@
 
 #include <nepomuk2/simpleresource.h>
 
-#include "nbib/documentpart.h"
+#include "documentpart.h"
 
 namespace Nepomuk2 {
 namespace NBIB {
diff --git a/src/sro/nbib/collection.h b/src/sro/nbib/collection.h
index 88e3b7d..824e679 100644
--- a/src/sro/nbib/collection.h
+++ b/src/sro/nbib/collection.h
@@ -10,7 +10,7 @@
 
 #include <nepomuk2/simpleresource.h>
 
-#include "nbib/publication.h"
+#include "publication.h"
 
 namespace Nepomuk2 {
 namespace NBIB {
diff --git a/src/sro/nbib/journal.h b/src/sro/nbib/journal.h
index cc64bab..51e395e 100644
--- a/src/sro/nbib/journal.h
+++ b/src/sro/nbib/journal.h
@@ -10,7 +10,7 @@
 
 #include <nepomuk2/simpleresource.h>
 
-#include "nbib/series.h"
+#include "series.h"
 
 namespace Nepomuk2 {
 namespace NBIB {
diff --git a/src/sro/nbib/journalissue.h b/src/sro/nbib/journalissue.h
index 720f969..92a3782 100644
--- a/src/sro/nbib/journalissue.h
+++ b/src/sro/nbib/journalissue.h
@@ -10,7 +10,7 @@
 
 #include <nepomuk2/simpleresource.h>
 
-#include "nbib/collection.h"
+#include "collection.h"
 
 namespace Nepomuk2 {
 namespace NBIB {
diff --git a/src/sro/nbib/techreport.h b/src/sro/nbib/techreport.h
index bd01ba5..23d20e7 100644
--- a/src/sro/nbib/techreport.h
+++ b/src/sro/nbib/techreport.h
@@ -10,7 +10,7 @@
 
 #include <nepomuk2/simpleresource.h>
 
-#include "nbib/report.h"
+#include "report.h"
 
 namespace Nepomuk2 {
 namespace NBIB {
diff --git a/src/sro/ncal/unionparentclass.h b/src/sro/ncal/unionparentclass.h
index 247ca17..19af6fe 100644
--- a/src/sro/ncal/unionparentclass.h
+++ b/src/sro/ncal/unionparentclass.h
@@ -391,7 +391,7 @@ public:
     /**
      * Get property http://www.w3.org/2003/01/geo/wgs84_pos#long. 
      */
-    double long() const {
+    double FAILlong() const {
         double value;
         if(contains(QUrl::fromEncoded("http://www.w3.org/2003/01/geo/wgs84_pos#long", \
                QUrl::StrictMode)))
             value = \
property(QUrl::fromEncoded("http://www.w3.org/2003/01/geo/wgs84_pos#long", \
                QUrl::StrictMode)).first().value<double>();
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 6234354..c8efb9c 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -11,3 +11,4 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/testdatadir.h.in \
${CMAKE_CURRENT_BINA  add_subdirectory( Test-core.project )
 add_subdirectory( Test-core.model )
 
+add_subdirectory( Test-nbibio.nepomuk2bibtex )
diff --git a/tests/Test-core.project/coreproject.cpp \
b/tests/Test-core.project/coreproject.cpp index 805d09e..0a93d87 100644
--- a/tests/Test-core.project/coreproject.cpp
+++ b/tests/Test-core.project/coreproject.cpp
@@ -254,4 +254,4 @@ void CoreProject::cleanupTestCase()
 }
 
 
-#include "coreproject.moc"
+#include "coremodel.moc"
diff --git a/tests/Test-nbibio.nepomuk2bibtex/CMakeLists.txt \
b/tests/Test-nbibio.nepomuk2bibtex/CMakeLists.txt new file mode 100644
index 0000000..fb726b9
--- /dev/null
+++ b/tests/Test-nbibio.nepomuk2bibtex/CMakeLists.txt
@@ -0,0 +1,39 @@
+
+
+kde4_add_unit_test(Test-nbibio.nepomuk2bibtex
+  nepomukbibtex.cpp
+)
+
+target_link_libraries(Test-nbibio.nepomuk2bibtex
+# include static libs from conquirere
+        ontology
+        core
+        nbibio
+        propertywidgets
+        onlinestorage
+        mainui
+
+# include general kde libs
+        ${KDE4_KDECORE_LIBS}
+        ${KDE4_KDEUI_LIBS}
+        ${KDE4_KIO_LIBS}
+        #${KDE4_KPARTS_LIBS}
+        #${KDE4_KHTML_LIBS}
+
+        ${QT_QTTEST_LIBRARY}
+
+#include akonadi stuff
+        ${KDE4_AKONADI_LIBS}
+        ${KDE4_KABC_LIBS}
+        akonadi-contact
+
+#include nepomuk
+        ${NEPOMUK_LIBRARIES}
+        ${NEPOMUK_QUERY_LIBRARIES}
+        nepomukcore
+        nepomuksync
+
+#include kbibtex
+        ${KBIBTEX_LIBRARIES}
+
+)
diff --git a/tests/Test-nbibio.nepomuk2bibtex/nepomukbibtex.cpp \
b/tests/Test-nbibio.nepomuk2bibtex/nepomukbibtex.cpp new file mode 100644
index 0000000..138a0b7
--- /dev/null
+++ b/tests/Test-nbibio.nepomuk2bibtex/nepomukbibtex.cpp
@@ -0,0 +1,568 @@
+/*
+ * Copyright 2012 Jörg Ehrichs <joerg.ehrichs@gmx.de>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <Nepomuk2/Variant>
+#include <Nepomuk2/Resource>
+#include <Nepomuk2/DataManagement>
+#include <Nepomuk2/SimpleResource>
+#include <Nepomuk2/SimpleResourceGraph>
+#include <Nepomuk2/StoreResourcesJob>
+#include <KDE/KJob>
+
+#include "nbib.h"
+#include "sro/nbib/series.h"
+#include "sro/nbib/article.h"
+#include "sro/nbib/journal.h"
+#include "sro/nbib/journalissue.h"
+#include "sro/nbib/proceedings.h"
+#include "sro/nbib/book.h"
+#include "sro/nbib/chapter.h"
+#include "sro/nbib/techreport.h"
+#include "sro/nbib/reference.h"
+#include "sro/ncal/event.h"
+#include "sro/nco/contact.h"
+#include "sro/nco/organizationcontact.h"
+
+#include "nbibio/nbibexporterfile.h"
+
+#include <QtTest>
+#include <QtDebug>
+
+/**
+ * @brief UnitTest for the nbibio exporter Nepomuk -> Bibtex
+ *
+ * checks: a few defined test cases.
+ * for a full data driven test see Test-nbibio.bibtex2bibtex
+ */
+class NepomukBibtex: public QObject
+{
+    Q_OBJECT
+
+private slots:
+
+    void initTestCase();
+
+    void exportArticleTest();
+    void exportBookTest();
+    void exportBookletTest();
+    void exportInBookTest();
+    void exportInCollectionTest();
+    void exportProceedingsTest();
+    void exportInProceedingsTest();
+    void exportTechreportTest();
+
+    void cleanupTestCase();
+
+private:
+    void checkEquality(Nepomuk2::Resource ref, const QStringList & original);
+
+    QUrl articleReferenceUri;
+    QUrl proceedingsReferenceUri;
+    QUrl inProceedingsReferenceUri;
+    QUrl bookReferenceUri;
+    QUrl bookletReferenceUri;
+    QUrl inBookReferenceUri;
+    QUrl inCollectionReferenceUri;
+    QUrl techreportReferenceUri;
+
+};
+
+QTEST_MAIN(NepomukBibtex)
+
+void NepomukBibtex::initTestCase()
+{
+    //insert some test publication
+    Nepomuk2::SimpleResourceGraph graph;
+
+    //##############################################
+    // General stuff usefull for any publication
+    Nepomuk2::NCO::Contact author;
+    author.setFullname(QLatin1String("UNITTEST-Author"));
+
+    Nepomuk2::NCO::Contact bookAuthor;
+    bookAuthor.setFullname(QLatin1String("UNITTEST-Author"));
+
+    Nepomuk2::NCO::Contact seriesAuthor;
+    seriesAuthor.setFullname(QLatin1String("UNITTEST-SeriesAuthor"));
+
+    Nepomuk2::NCO::Contact editor;
+    editor.setFullname(QLatin1String("UNITTEST-Editor"));
+
+    Nepomuk2::NCO::OrganizationContact publisher;
+    publisher.setFullname(QLatin1String("UNITTEST-Publisher"));
+    //TODO: add publisher address
+
+    Nepomuk2::NCO::OrganizationContact organization;
+    organization.setFullname(QLatin1String("UNITTEST-Organization"));
+    //TODO: add publisher address
+
+    Nepomuk2::NCAL::Event event;
+    event.setTitle(QLatin1String("UNITTEST-Title"));
+
+    Nepomuk2::NBIB::Series series;
+    series.setTitle(QLatin1String("UNITTEST-Series"));
+    series.setIssn(QLatin1String("UNITTEST-ISSN"));
+
+    QDateTime publicationDate = QDateTime::fromString("1987-01-01", "yyyy-MM-dd");
+
+
+    //##############################################
+    //# Article in a journal
+    Nepomuk2::NBIB::Journal journal;
+    journal.setTitle( QLatin1String("UNITTEST-Jounal"));
+
+    Nepomuk2::NBIB::JournalIssue journalIssue;
+    //TODO: should we allow to add a title to the sournalIssue? (collection) usually \
this should be covered by the Journal (Series) the issue is in +    \
//journalIssue.setTitle( QLatin1String("UNITTEST-JounalIssue")); +    \
journalIssue.setVolume(QString("443")); +    journalIssue.setNumber(QString("21"));
+    journalIssue.addPublisher( publisher.uri() );
+
+    journalIssue.setInSeries( journal.uri() );
+    journal.addSeriesOf( journalIssue.uri() );
+
+    Nepomuk2::NBIB::Article article;
+    article.setTitle(QLatin1String("UNITTEST-Article-Title"));
+    article.setPublicationDate( publicationDate );
+    article.setDoi(QLatin1String("10.4204/EPTCS"));
+    article.setPublicationMethod(QString("UNITTEST-Howpublished"));
+
+    article.addCreator( author.uri() );
+    article.addEditor( editor.uri() );
+
+    journalIssue.addArticle( article.uri() );
+    article.setCollection(journalIssue.uri());
+    article.setInSeries( series.uri() );
+    series.addSeriesOf( article.uri() );
+
+    Nepomuk2::NBIB::Reference articleReference;
+    articleReference.setPages(QLatin1String("1-999"));
+    articleReference.setCiteKey(QLatin1String("UNITTEST-article"));
+
+    articleReference.setPublication(article.uri());
+    article.addReference(articleReference.uri());
+
+
+    //######################################
+    //# Proceedings
+    Nepomuk2::NBIB::Proceedings proceedings;
+    proceedings.setTitle(QLatin1String("UNITTEST-Title: A Proceedings"));
+    proceedings.setPublicationDate( publicationDate );
+    proceedings.setOrganization( organization.uri() );
+    proceedings.addPublisher( publisher.uri() );
+
+    proceedings.setEvent( event.uri() );
+    event.addProperty( Nepomuk2::Vocabulary::NBIB::eventPublication(), \
proceedings.uri()); +
+    series.addSeriesOf(proceedings.uri());
+    proceedings.setInSeries(series.uri());
+
+    Nepomuk2::NBIB::Reference proceedingsReference;
+    proceedingsReference.setPages(QLatin1String("1-999"));
+    proceedingsReference.setCiteKey(QLatin1String("UNITTEST-proceedings"));
+
+    proceedingsReference.setPublication(proceedings.uri());
+    proceedings.addReference(proceedingsReference.uri());
+
+
+    //######################################
+    //# Article InProceedings
+    Nepomuk2::NBIB::Article inProceedings;
+    inProceedings.setTitle(QLatin1String("UNITTEST-Title: An Inproceedings"));
+    inProceedings.setPublicationDate( publicationDate );
+    inProceedings.setDoi(QLatin1String("10.4204/EPTCS"));
+    inProceedings.setPublicationMethod(QString("UNITTEST-Howpublished"));
+
+    proceedings.addArticle( inProceedings.uri() );
+    inProceedings.setCollection( proceedings.uri() );
+
+    inProceedings.addCreator( author.uri() );
+    inProceedings.addEditor( editor.uri() );
+
+    Nepomuk2::NBIB::Reference inProceedingsReference;
+    inProceedingsReference.setPages(QLatin1String("1-999"));
+    inProceedingsReference.setCiteKey(QLatin1String("UNITTEST-inproceedings"));
+
+    inProceedingsReference.setPublication(inProceedings.uri());
+    inProceedings.addReference(inProceedingsReference.uri());
+
+
+    //######################################
+    //# Book
+    Nepomuk2::NBIB::Book book;
+    book.setTitle(QLatin1String("UNITTEST-book"));
+    book.setEdition(QLatin1String("UNITTEST-second"));
+    book.setPublicationDate( publicationDate );
+    book.addCreator( author.uri() );
+    book.addEditor( editor.uri() );
+    book.addPublisher( publisher.uri() );
+    book.setVolume(QLatin1String("UNITTEST-volume"));
+    book.setNumber(QLatin1String("UNITTEST-number"));
+
+    book.setInSeries( series.uri() );
+    series.addSeriesOf( book.uri() );
+
+    Nepomuk2::NBIB::Reference bookReference;
+    bookReference.setCiteKey(QLatin1String("UNITTEST-book"));
+
+    bookReference.setPublication( book.uri() );
+    book.addReference(bookReference.uri());
+
+    //######################################
+    //# Booklet (book without publisher)
+    Nepomuk2::NBIB::Book booklet;
+    booklet.setTitle(QLatin1String("UNITTEST-book"));
+    booklet.setEdition(QLatin1String("UNITTEST-second"));
+    booklet.setPublicationDate( publicationDate );
+    booklet.addCreator( author.uri() );
+    booklet.addEditor( editor.uri() );
+    booklet.setPublicationMethod( QLatin1String("UNITTEST-how published") );
+
+    booklet.setInSeries( series.uri() );
+    series.addSeriesOf( booklet.uri() );
+
+    Nepomuk2::NBIB::Reference bookletReference;
+    bookletReference.setCiteKey(QLatin1String("UNITTEST-booklet"));
+
+    bookletReference.setPublication( booklet.uri() );
+    booklet.addReference(bookletReference.uri());
+
+
+    //######################################
+    //# inBook (chapter in book but untitled)
+    Nepomuk2::NBIB::Chapter chapter;
+    chapter.setChapterNumber(QString("UNITTEST-II"));
+    chapter.setPageStart(45);
+    chapter.setPageEnd(67);
+
+    Nepomuk2::NBIB::Book inBook;
+    inBook.setTitle(QLatin1String("UNITTEST-inbook"));
+    inBook.setEdition(QLatin1String("UNITTEST-second"));
+    inBook.addCreator( author.uri() );
+    inBook.addEditor( editor.uri() );
+    inBook.addPublisher( publisher.uri() );
+    inBook.setPublicationDate( publicationDate );
+
+    inBook.addDocumentPart( chapter.uri() );
+    chapter.setDocumentPartOf( inBook.uri() );
+
+    Nepomuk2::NBIB::Reference inBookReference;
+    inBookReference.setCiteKey(QLatin1String("UNITTEST-inBook"));
+    inBookReference.setReferencedPart(chapter.uri());
+
+    inBookReference.setPublication( inBook.uri() );
+    inBook.addReference(inBookReference.uri());
+
+
+    //######################################
+    //# inCollection (chapter in book having its own title)
+    Nepomuk2::NBIB::Chapter chapter2;
+    chapter2.setTitle(QLatin1String("UNITTEST-Chapter-Title"));
+    chapter2.setChapterNumber(QString("UNITTEST-II"));
+    chapter2.setPageStart(45);
+    chapter2.setPageEnd(67);
+    chapter2.addCreator( author.uri() );
+
+    Nepomuk2::NBIB::Book inCollection;
+    inCollection.setTitle(QLatin1String("UNITTEST-incollection"));
+    inCollection.setEdition(QLatin1String("UNITTEST-second"));
+    inCollection.addCreator( bookAuthor.uri() );
+    inCollection.addEditor( editor.uri() );
+    inCollection.addPublisher( publisher.uri() );
+    inCollection.setPublicationDate( publicationDate );
+
+    inCollection.addDocumentPart( chapter2.uri() );
+    chapter2.setDocumentPartOf( inCollection.uri() );
+
+    Nepomuk2::NBIB::Reference inCollectionReference;
+    inCollectionReference.setCiteKey(QLatin1String("UNITTEST-inCollection"));
+    inCollectionReference.setReferencedPart(chapter2.uri());
+
+    inCollectionReference.setPublication( inCollection.uri() );
+    inCollection.addReference(inCollectionReference.uri());
+
+    //######################################
+    //# Techreport
+    Nepomuk2::NBIB::Techreport techreport;
+    techreport.setTitle(QLatin1String("UNITTEST-techreport"));
+    techreport.setPublicationDate( publicationDate );
+    techreport.addCreator( author.uri() );
+    techreport.addPublisher( publisher.uri() );
+    techreport.setOrganization( organization.uri() );
+    techreport.setPublicationMethod( QLatin1String("UNITTEST-how published") );
+    techreport.setPublicationType(QLatin1String("UNITTEST-publication-type"));
+
+    Nepomuk2::NBIB::Reference techreportReference;
+    techreportReference.setCiteKey(QLatin1String("UNITTEST-techreport"));
+
+    techreportReference.setPublication( techreport.uri() );
+    techreport.addReference(techreportReference.uri());
+
+
+    // Now add all the stuff to the graph
+    graph << author << bookAuthor << seriesAuthor << editor << publisher << \
organization << event << series; +    graph << journal << journalIssue << article << \
articleReference; +    graph << proceedings << proceedingsReference;
+    graph << inProceedings << inProceedingsReference;
+    graph << book << bookReference;
+    graph << booklet << bookletReference;
+    graph << chapter << inBook << inBookReference;
+    graph << chapter2 << inCollection << inCollectionReference;
+    graph << techreport << techreportReference;
+
+    Nepomuk2::StoreResourcesJob* srj = \
Nepomuk2::storeResources(graph,Nepomuk2::IdentifyNone); +
+    if(!srj->exec()) {
+        qDebug() << srj->errorString();
+        QFAIL("Could not insert test publication into Nepomuk");
+    }
+
+    // save the real nepomuk uris for later use
+    articleReferenceUri = srj->mappings().value(articleReference.uri());
+    bookReferenceUri = srj->mappings().value(bookReference.uri());
+    bookletReferenceUri = srj->mappings().value(bookletReference.uri());
+    inBookReferenceUri = srj->mappings().value(inBookReference.uri());
+    proceedingsReferenceUri = srj->mappings().value(proceedingsReference.uri());
+    inProceedingsReferenceUri = srj->mappings().value(inProceedingsReference.uri());
+    inCollectionReferenceUri = srj->mappings().value(inCollectionReference.uri());
+    techreportReferenceUri = srj->mappings().value(techreportReference.uri());
+}
+
+void NepomukBibtex::checkEquality(Nepomuk2::Resource ref, const QStringList \
&original) +{
+    NBibExporterFile exporter;
+    exporter.setFileType( NBibExporterFile::EXPORT_BIBTEX );
+
+    QByteArray byteArray;
+    QBuffer iodev(&byteArray);
+    iodev.open(QBuffer::ReadWrite);
+
+    QStringList errorLog;
+    exporter.save(&iodev, QList<Nepomuk2::Resource>() << ref, &errorLog);
+
+    if(!errorLog.isEmpty()) {
+        qDebug() << errorLog;
+        QFAIL("Errors occured while exporting the data");
+    }
+
+    QTextStream output(&byteArray);
+
+    bool equal = true;
+    int line = 0;
+    while ( !output.atEnd() && line < original.size()) {
+        QString outputLine = output.readLine();
+
+        if(outputLine != original.at(line)) {
+            qDebug() << "OUT:" << outputLine << " NOT EQUAL Original: " << \
original.at(line); +            equal = false;
+        }
+        line++;
+    }
+
+    if(!equal) {
+        QFAIL("exported data not equal reference data");
+    }
+}
+
+void NepomukBibtex::exportArticleTest()
+{
+    Nepomuk2::Resource ref = Nepomuk2::Resource( articleReferenceUri );
+
+    QStringList originalLine;
+    originalLine << "@article{UNITTEST-article,";
+    originalLine << "	author = {UNITTEST-Author},";
+    originalLine << "	date = {1986-12-31T23:00:00Z},";
+    originalLine << "	doi = {10.4204/EPTCS},";
+    originalLine << "	editor = {UNITTEST-Editor},";
+    originalLine << "	howpublished = {UNITTEST-Howpublished},";
+    originalLine << "	issn = {UNITTEST-ISSN},";
+    originalLine << "	journal = {UNITTEST-Jounal},";
+    originalLine << "	month = {dec},";
+    originalLine << "	number = {21},";
+    originalLine << "	pages = {1-999},";
+    originalLine << "	series = {{UNITTEST-Series}},";
+    originalLine << "	title = {{UNITTEST-Article-Title}},";
+    originalLine << "	volume = {443},";
+    originalLine << "	year = {1986}";
+    originalLine << "}";
+
+    checkEquality(ref, originalLine);
+}
+
+void NepomukBibtex::exportBookTest()
+{
+    Nepomuk2::Resource ref = Nepomuk2::Resource( bookReferenceUri );
+
+    QStringList originalLine;
+    originalLine << "@book{UNITTEST-book,";
+    originalLine << "	author = {UNITTEST-Author},";
+    originalLine << "	date = {1986-12-31T23:00:00Z},";
+    originalLine << "	edition = {UNITTEST-second},";
+    originalLine << "	editor = {UNITTEST-Editor},";
+    originalLine << "	issn = {UNITTEST-ISSN},";
+    originalLine << "	month = {dec},";
+    originalLine << "	number = {UNITTEST-number},";
+    originalLine << "	publisher = {UNITTEST-Publisher},";
+    originalLine << "	series = {{UNITTEST-Series}},";
+    originalLine << "	title = {{UNITTEST-book}},";
+    originalLine << "	volume = {UNITTEST-volume},";
+    originalLine << "	year = {1986}";
+    originalLine << "}";
+
+    checkEquality(ref, originalLine);
+}
+
+void NepomukBibtex::exportBookletTest()
+{
+    Nepomuk2::Resource ref = Nepomuk2::Resource( bookletReferenceUri );
+
+    QStringList originalLine;
+    originalLine << "@booklet{UNITTEST-booklet,";
+    originalLine << "	author = {UNITTEST-Author},";
+    originalLine << "	date = {1986-12-31T23:00:00Z},";
+    originalLine << "	edition = {UNITTEST-second},";
+    originalLine << "	editor = {UNITTEST-Editor},";
+    originalLine << "	howpublished = {UNITTEST-how published},";
+    originalLine << "	issn = {UNITTEST-ISSN},";
+    originalLine << "	month = {dec},";
+    originalLine << "	series = {{UNITTEST-Series}},";
+    originalLine << "	title = {{UNITTEST-book}},";
+    originalLine << "	year = {1986}";
+    originalLine << "}";
+
+    checkEquality(ref, originalLine);
+}
+
+void NepomukBibtex::exportInBookTest()
+{
+    Nepomuk2::Resource ref = Nepomuk2::Resource( inBookReferenceUri );
+
+    QStringList originalLine;
+    originalLine << "@inbook{UNITTEST-inBook,";
+    originalLine << "	author = {UNITTEST-Author},";
+    originalLine << "	chapter = {UNITTEST-II},";
+    originalLine << "	date = {1986-12-31T23:00:00Z},";
+    originalLine << "	edition = {UNITTEST-second},";
+    originalLine << "	editor = {UNITTEST-Editor},";
+    originalLine << "	month = {dec},";
+    originalLine << "	publisher = {UNITTEST-Publisher},";
+    originalLine << "	title = {{UNITTEST-inbook}},";
+    originalLine << "	year = {1986}";
+    originalLine << "}";
+
+    checkEquality(ref, originalLine);
+}
+
+void NepomukBibtex::exportInCollectionTest()
+{
+    Nepomuk2::Resource ref = Nepomuk2::Resource( inCollectionReferenceUri );
+
+    QStringList originalLine;
+    originalLine << "@incollection{UNITTEST-inCollection,";
+    originalLine << "	author = {, UNITTEST-Author},";
+    originalLine << "	bookauthor = {UNITTEST-Author},";
+    originalLine << "	booktitle = {{UNITTEST-incollection}},";
+    originalLine << "	chapter = {UNITTEST-II},";
+    originalLine << "	chaptername = {UNITTEST-Chapter-Title},";
+    originalLine << "	date = {1986-12-31T23:00:00Z},";
+    originalLine << "	edition = {UNITTEST-second},";
+    originalLine << "	editor = {UNITTEST-Editor},";
+    originalLine << "	month = {dec},";
+    originalLine << "	publisher = {UNITTEST-Publisher},";
+    originalLine << "	title = {{UNITTEST-Chapter-Title}},";
+    originalLine << "	year = {1986}";
+    originalLine << "}";
+
+    checkEquality(ref, originalLine);
+}
+
+void NepomukBibtex::exportProceedingsTest()
+{
+    Nepomuk2::Resource ref = Nepomuk2::Resource( proceedingsReferenceUri );
+
+    QStringList originalLine;
+    originalLine << "@proceedings{UNITTEST-proceedings,";
+    originalLine << "	date = {1986-12-31T23:00:00Z},";
+    originalLine << "	event = {UNITTEST-Title},";
+    originalLine << "	issn = {UNITTEST-ISSN},";
+    originalLine << "	month = {dec},";
+    originalLine << "	organization = {UNITTEST-Organization},";
+    originalLine << "	pages = {1-999},";
+    originalLine << "	publisher = {UNITTEST-Publisher},";
+    originalLine << "	series = {{UNITTEST-Series}},";
+    originalLine << "	title = {{UNITTEST-Title: A Proceedings}},";
+    originalLine << "	year = {1986}";
+    originalLine << "}";
+
+    checkEquality(ref, originalLine);
+}
+
+void NepomukBibtex::exportInProceedingsTest()
+{
+    Nepomuk2::Resource ref = Nepomuk2::Resource( inProceedingsReferenceUri );
+
+    QStringList originalLine;
+    originalLine << "@inproceedings{UNITTEST-inproceedings,";
+    originalLine << "	author = {UNITTEST-Author},";
+    originalLine << "	booktitle = {{UNITTEST-Title: A Proceedings}},";
+    originalLine << "	date = {1986-12-31T23:00:00Z},";
+    originalLine << "	doi = {10.4204/EPTCS},";
+    originalLine << "	editor = {UNITTEST-Editor},";
+    originalLine << "	event = {UNITTEST-Title},";
+    originalLine << "	howpublished = {UNITTEST-Howpublished},";
+    originalLine << "	issn = {UNITTEST-ISSN},";
+    originalLine << "	journal = {UNITTEST-Series},";
+    originalLine << "	month = {dec},";
+    originalLine << "	pages = {1-999},";
+    originalLine << "	title = {{UNITTEST-Title: An Inproceedings}},";
+    originalLine << "	year = {1986}";
+    originalLine << "}";
+
+    checkEquality(ref, originalLine);
+}
+
+void NepomukBibtex::exportTechreportTest()
+{
+    Nepomuk2::Resource ref = Nepomuk2::Resource( techreportReferenceUri );
+
+    QStringList originalLine;
+    originalLine << "@techreport{UNITTEST-techreport,";
+    originalLine << "	author = {UNITTEST-Author},";
+    originalLine << "	date = {1986-12-31T23:00:00Z},";
+    originalLine << "	howpublished = {UNITTEST-how published},";
+    originalLine << "	institution = {UNITTEST-Publisher},";
+    originalLine << "	month = {dec},";
+    originalLine << "	organization = {UNITTEST-Organization},";
+    originalLine << "	title = {{UNITTEST-techreport}},";
+    originalLine << "	type = {UNITTEST-publication-type},";
+    originalLine << "	year = {1986}";
+    originalLine << "}";
+
+    checkEquality(ref, originalLine);
+}
+
+void NepomukBibtex::cleanupTestCase()
+{
+    // remove all data created by this unittest from the nepomuk database again
+    KJob *job = Nepomuk2::removeDataByApplication();
+    if(!job->exec()) {
+        qWarning() << job->errorString();
+        QFAIL("Cleanup did not work");
+    }
+}
+
+#include "nepomukbibtex.moc"


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic