summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2012-10-18 10:41:06 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2012-10-18 10:41:06 (GMT)
commitfd348713860576b76584022de425414276326756 (patch)
tree37aa42e11a5631bbfd39816e97a5e80084bb9838
parentdfff5bc603fdcecd247a5a9c136371ef302e6b82 (diff)
downloadkolab-utils-fd348713860576b76584022de425414276326756.tar.gz
Freebusy aggregator test.
-rw-r--r--fbdaemon/fbaggregatorjob.cpp13
-rw-r--r--fbdaemon/fbaggregatorjob.h2
-rw-r--r--fbdaemon/tests/CMakeLists.txt7
-rw-r--r--fbdaemon/tests/fbaggregatortest.cpp115
-rw-r--r--fbdaemon/tests/fbgeneratortest.cpp5
5 files changed, 134 insertions, 8 deletions
diff --git a/fbdaemon/fbaggregatorjob.cpp b/fbdaemon/fbaggregatorjob.cpp
index 1772f98..f5620ef 100644
--- a/fbdaemon/fbaggregatorjob.cpp
+++ b/fbdaemon/fbaggregatorjob.cpp
@@ -18,13 +18,13 @@
#include "fbaggregatorjob.h"
#include "settings.h"
#include "jobs/probekolabserverjob.h"
-#include <jobs/fetchmessagesjob.h>
+#include "jobs/fetchmessagesjob.h"
#include <kdebug.h>
#include <QFile>
#include <QDir>
#include <kolab/kolabobject.h>
-#include <kolabdefinitions.h>
-#include <freebusy.h>
+#include <kolab/kolabdefinitions.h>
+#include <kolab/freebusy.h>
#include <kolab/errorhandler.h>
FBAggregatorJob::FBAggregatorJob(const QString& hostName, qint16 port, const QString& username, QObject* parent)
@@ -95,9 +95,14 @@ void FBAggregatorJob::onFetchFBDone(KJob *job)
logout();
return;
}
+ mGeneratedFile = QDir::current().absoluteFilePath(file.fileName());
QTextStream out(&file);
out << QString::fromStdString(Kolab::FreebusyUtils::toIFB(aggregatedFb));
- Debug() << "wrote " << QDir::current().absoluteFilePath (file.fileName());
+ Debug() << "wrote " << mGeneratedFile;
logout();
}
+QString FBAggregatorJob::generatedFile() const
+{
+ return mGeneratedFile;
+}
diff --git a/fbdaemon/fbaggregatorjob.h b/fbdaemon/fbaggregatorjob.h
index 71deab4..aa33749 100644
--- a/fbdaemon/fbaggregatorjob.h
+++ b/fbdaemon/fbaggregatorjob.h
@@ -30,6 +30,7 @@ class FBAggregatorJob: public KolabJob
Q_OBJECT
public:
explicit FBAggregatorJob(const QString &hostName, qint16 port, const QString &username, QObject* parent = 0);
+ QString generatedFile() const;
private Q_SLOTS:
void onFetchFBDone(KJob *job);
// void onGenerateFBDone(KJob*);
@@ -38,6 +39,7 @@ private:
virtual void startWork(ProbeKolabServerJob* job);
QString mFreebusyFolder;
+ QString mGeneratedFile;
Kolab::Freebusy mSimpleFreebusy;
};
diff --git a/fbdaemon/tests/CMakeLists.txt b/fbdaemon/tests/CMakeLists.txt
index 4132332..b8f30d8 100644
--- a/fbdaemon/tests/CMakeLists.txt
+++ b/fbdaemon/tests/CMakeLists.txt
@@ -8,3 +8,10 @@ qt4_generate_moc(
)
add_executable(fbgeneratortest ${FBDAEMON_SRCS} fbgeneratortest.cpp)
target_link_libraries(fbgeneratortest ${COMMON_DEPENDENCIES} ${QT_QTTEST_LIBRARY} kolabutils)
+
+qt4_generate_moc(
+ ${CMAKE_CURRENT_SOURCE_DIR}/fbaggregatortest.cpp
+ ${CMAKE_CURRENT_BINARY_DIR}/fbaggregatortest.moc
+)
+add_executable(fbaggregatortest ${FBDAEMON_SRCS} fbaggregatortest.cpp)
+target_link_libraries(fbaggregatortest ${COMMON_DEPENDENCIES} ${QT_QTTEST_LIBRARY} kolabutils) \ No newline at end of file
diff --git a/fbdaemon/tests/fbaggregatortest.cpp b/fbdaemon/tests/fbaggregatortest.cpp
new file mode 100644
index 0000000..82dbe6b
--- /dev/null
+++ b/fbdaemon/tests/fbaggregatortest.cpp
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <QObject>
+#include <QTest>
+#include <QDebug>
+#include <QDir>
+#include <kolabobject.h>
+#include <freebusy.h>
+#include <kcalconversion.h>
+#include "fbdaemon/fbgeneratorjob.h"
+#include "settings.h"
+#include <fbaggregatorjob.h>
+#include "kolabaccount.h"
+#include "testlib/testutils.h"
+
+class FBAggregatorTest: public QObject
+{
+ Q_OBJECT
+
+// QString sourcehost;
+ QString targethost;
+ QString user;
+ QString admin;
+ QString adminpw;
+ qint16 port;
+ QList<Folder> folders;
+ QString generatedFile;
+
+public:
+ explicit FBAggregatorTest(QObject* parent = 0)
+ : QObject(parent),
+// sourcehost("192.168.122.104"),
+ targethost("192.168.122.10"),
+ user("john.doe@example.org"),
+ admin("cyrus-admin"),
+ adminpw("admin"),
+ port(143)
+ {
+ Object fbObj1;
+ Kolab::Freebusy fb;
+ fb.setStart(Kolab::Conversion::fromDate(KDateTime::currentUtcDateTime()));
+ fb.setEnd(Kolab::Conversion::fromDate(KDateTime::currentUtcDateTime().addDays(60)));
+ fbObj1.message = Kolab::KolabObjectWriter::writeFreebusy(fb, Kolab::KolabV3, "fbtest");
+
+ Object fbObj2;
+ Kolab::Freebusy fb2;
+ fb2.setStart(Kolab::Conversion::fromDate(KDateTime::currentUtcDateTime()));
+ fb2.setEnd(Kolab::Conversion::fromDate(KDateTime::currentUtcDateTime().addDays(60)));
+ fbObj2.message = Kolab::KolabObjectWriter::writeFreebusy(fb2, Kolab::KolabV3, "fbtest");
+
+ folders << Folder("Freebusy", Kolab::FreebusyType, QList<Object>() << fbObj1 << fbObj2);
+ }
+
+private:
+
+ void setupTargetAccount()
+ {
+ QObject obj;
+ KolabAccount *account = new KolabAccount(&obj);
+ account->setHost(targethost, port);
+ account->setCredentials(user, adminpw, admin);
+ account->init();
+
+ account->cleanAccount();
+ createFolders(account, folders);
+ }
+
+ void executeAggregation()
+ {
+ Settings::instance().setAuthorizationUser(admin);
+ Settings::instance().setPassword(adminpw);
+ Settings::instance().setServerUri(targethost, port);
+ Settings::instance().setThreshold(10);
+ Settings::instance().setTimeframe(60);
+ Settings::instance().setAggregatedICalOutputDirectory(QDir::tempPath());
+
+ QObject obj;
+ FBAggregatorJob *job = new FBAggregatorJob(targethost, port, user, &obj);
+ job->exec();
+ generatedFile = job->generatedFile();
+ }
+
+ void checkFbObject()
+ {
+ QVERIFY(QFileInfo(generatedFile).exists());
+ //Check that aggregated fb object has been created
+ }
+
+private slots:
+ void testGenerator()
+ {
+ setupTargetAccount();
+ executeAggregation();
+ checkFbObject();
+ }
+
+};
+QTEST_MAIN( FBAggregatorTest )
+
+#include "fbaggregatortest.moc" \ No newline at end of file
diff --git a/fbdaemon/tests/fbgeneratortest.cpp b/fbdaemon/tests/fbgeneratortest.cpp
index 30ab638..b02aeda 100644
--- a/fbdaemon/tests/fbgeneratortest.cpp
+++ b/fbdaemon/tests/fbgeneratortest.cpp
@@ -101,10 +101,7 @@ private:
QList<Object>::const_iterator recObjIt = objects.constBegin();
QList<Object>::const_iterator objIt = folder.objects.constBegin();
for (;objIt != folder.objects.constEnd() && recObjIt != objects.constEnd(); ++objIt, ++recObjIt) {
- //TODO Check converted messages
- foreach (const QByteArray &flag, objIt->flags) {
- QVERIFY(recObjIt->flags.contains(flag));
- }
+ //TODO Check fb objects
}
}
}