summaryrefslogtreecommitdiff
path: root/fbdaemon
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2012-10-18 09:59:05 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2012-10-18 09:59:05 (GMT)
commitdfff5bc603fdcecd247a5a9c136371ef302e6b82 (patch)
treee8cdadc9a0286cd52fc0be9f1f255c737a723ac3 /fbdaemon
parent17601c16ef211e3de6d9751bef85cccfae38e8fb (diff)
downloadkolab-utils-dfff5bc603fdcecd247a5a9c136371ef302e6b82.tar.gz
Refactoring to make a first FreebusyGenerator test possible.
Diffstat (limited to 'fbdaemon')
-rw-r--r--fbdaemon/CMakeLists.txt3
-rw-r--r--fbdaemon/authenticationjob.cpp2
-rw-r--r--fbdaemon/kolabjob.cpp14
-rw-r--r--fbdaemon/settings.cpp61
-rw-r--r--fbdaemon/settings.h17
-rw-r--r--fbdaemon/tests/CMakeLists.txt9
-rw-r--r--fbdaemon/tests/fbgeneratortest.cpp100
7 files changed, 150 insertions, 56 deletions
diff --git a/fbdaemon/CMakeLists.txt b/fbdaemon/CMakeLists.txt
index 7f95c9a..a7cc449 100644
--- a/fbdaemon/CMakeLists.txt
+++ b/fbdaemon/CMakeLists.txt
@@ -1,5 +1,4 @@
set (FBDAEMON_SRCS
- ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/authenticationjob.cpp
${CMAKE_CURRENT_SOURCE_DIR}/fbcoordinator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/fbgeneratorjob.cpp
@@ -19,7 +18,7 @@ QT4_WRAP_CPP(FB_MOC
)
set( FBDAEMON_SRCS ${FBDAEMON_SRCS} ${FB_MOC} ${JOBS_SRCS} )
-add_executable(kolab-freebusyd ${FBDAEMON_SRCS} ${JOB_SRCS})
+add_executable(kolab-freebusyd ${FBDAEMON_SRCS} ${JOB_SRCS} main.cpp)
target_link_libraries(kolab-freebusyd ${COMMON_DEPENDENCIES} kolabutils)
install(TARGETS kolab-freebusyd
diff --git a/fbdaemon/authenticationjob.cpp b/fbdaemon/authenticationjob.cpp
index b6fc526..1b9f9ba 100644
--- a/fbdaemon/authenticationjob.cpp
+++ b/fbdaemon/authenticationjob.cpp
@@ -51,7 +51,7 @@ void AuthenticationJob::start()
}
loginJob->setPassword(Settings::instance().getPassword());
- loginJob->setEncryptionMode( KIMAP::LoginJob::AnySslVersion );
+ loginJob->setEncryptionMode( KIMAP::LoginJob::TlsV1 );
loginJob->setAuthenticationMode( KIMAP::LoginJob::Plain );
QObject::connect( loginJob, SIGNAL(result(KJob*)),
diff --git a/fbdaemon/kolabjob.cpp b/fbdaemon/kolabjob.cpp
index d2382bc..652a5ab 100644
--- a/fbdaemon/kolabjob.cpp
+++ b/fbdaemon/kolabjob.cpp
@@ -16,20 +16,14 @@
*/
#include "kolabjob.h"
-#include "authenticationjob.h"
-#include <jobs/probekolabserverjob.h>
+
#include <QTimer>
#include <kimap/logoutjob.h>
#include <kolab/errorhandler.h>
-class UiProxy: public KIMAP::SessionUiProxy {
- public:
- //We need this for ssl errors such as untrusted certificates
- bool ignoreSslError(const KSslErrorUiData& /*errorData*/) {
-// Warning() << "Error during ssl";
- return true;
- }
-};
+#include "uiproxy.h"
+#include "authenticationjob.h"
+#include "jobs/probekolabserverjob.h"
KolabJob::KolabJob(const QString& hostName, qint16 port, const QString& username, QObject* parent)
: KJob(parent),
diff --git a/fbdaemon/settings.cpp b/fbdaemon/settings.cpp
index 6c556e0..c48aef5 100644
--- a/fbdaemon/settings.cpp
+++ b/fbdaemon/settings.cpp
@@ -42,6 +42,15 @@
QString adminpw = settings.value("admin_password", "VerySecret");
settings.endGroup();
*/
+
+Settings::Settings()
+: mTimeframe(-1),
+ mThreshold(-1)
+{
+
+}
+
+
QVariant Settings::getValue(const QString &key, const QVariant &defaultValue) const
{
if (!QFile(mFile).exists()) {
@@ -59,8 +68,19 @@ QVariant Settings::getValue(const QString &key, const QVariant &defaultValue) co
return settings.value(key, defaultValue);
}
+void Settings::setServerUri(const QString& server, qint16 port)
+{
+ mServerUri = server;
+ mPort = port;
+}
+
+
QString Settings::getServerUri(qint16 &port) const
{
+ if (!mServerUri.isEmpty()) {
+ port = mPort;
+ return mServerUri;
+ }
QString serverUri = getValue("uri", "localhost").toString();
if (serverUri.contains(QLatin1String("://"))) {
serverUri.remove(0, serverUri.indexOf(QLatin1String("://"))+3);
@@ -74,32 +94,73 @@ QString Settings::getServerUri(qint16 &port) const
return serverUri;
}
+void Settings::setAuthorizationUser(const QString &user)
+{
+ mAuthorizationUser = user;
+}
+
QString Settings::getAuthorizationUser() const
{
+ if (!mAuthorizationUser.isEmpty()) {
+ return mAuthorizationUser;
+ }
return getValue("admin_login", "cyrus-admin").toString();
}
+void Settings::setPassword(const QString &password)
+{
+ mPassword = password;
+}
+
+
QString Settings::getPassword() const
{
+ if (!mPassword.isEmpty()) {
+ return mPassword;
+ }
return getValue("admin_password", "NoAdminPassword").toString();
}
+void Settings::setTimeframe(int t)
+{
+ mTimeframe = t;
+}
+
int Settings::getTimeframe() const
{
+ if (mTimeframe >= 0) {
+ return mTimeframe;
+ }
QSettings settings(mFile, QSettings::IniFormat);
settings.beginGroup("kolab");
return settings.value("timeframe", 90).toInt();
}
+void Settings::setThreshold(int t)
+{
+ mThreshold = t;
+}
+
int Settings::getThreshold() const
{
+ if (mThreshold >= 0) {
+ return mThreshold;
+ }
QSettings settings(mFile, QSettings::IniFormat);
settings.beginGroup("kolab");
return settings.value("threshold", 0).toInt();
}
+void Settings::setAggregatedICalOutputDirectory(const QString& dir)
+{
+ mAggregatedICalOutputDirectory = dir;
+}
+
QString Settings::getAggregatedICalOutputDirectory() const
{
+ if (!mAggregatedICalOutputDirectory.isEmpty()) {
+ return mAggregatedICalOutputDirectory;
+ }
return QLatin1String("/var/lib/kolab-freebusy");
// QSettings settings(mFile, QSettings::IniFormat);
// settings.beginGroup("kolab");
diff --git a/fbdaemon/settings.h b/fbdaemon/settings.h
index 7455889..b816075 100644
--- a/fbdaemon/settings.h
+++ b/fbdaemon/settings.h
@@ -31,24 +31,39 @@ public:
void setFile(const QString &file) {mFile = file;};
// QString file() {return mFile;};
+ void setServerUri(const QString &server, qint16 port);
QString getServerUri(qint16 &port) const;
+ void setAuthorizationUser(const QString &);
QString getAuthorizationUser() const;
+
+ void setPassword(const QString &);
QString getPassword() const;
//Number of days in f/b
+ void setTimeframe(int);
int getTimeframe() const;
//Number of days after which the f/b is considered out of date
+ void setThreshold(int);
int getThreshold() const;
+ void setAggregatedICalOutputDirectory(const QString &dir);
QString getAggregatedICalOutputDirectory() const;
private:
QVariant getValue(const QString &, const QVariant &) const;
- Settings() {};
+ Settings();
Settings(const Settings &);
Settings & operator= (const Settings &);
QString mFile;
+
+ QString mServerUri;
+ qint16 mPort;
+ QString mAuthorizationUser;
+ QString mPassword;
+ int mTimeframe;
+ int mThreshold;
+ QString mAggregatedICalOutputDirectory;
};
#endif // SETTINGS_H
diff --git a/fbdaemon/tests/CMakeLists.txt b/fbdaemon/tests/CMakeLists.txt
index 8b13789..4132332 100644
--- a/fbdaemon/tests/CMakeLists.txt
+++ b/fbdaemon/tests/CMakeLists.txt
@@ -1 +1,10 @@
+include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/.. )
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+qt4_generate_moc(
+ ${CMAKE_CURRENT_SOURCE_DIR}/fbgeneratortest.cpp
+ ${CMAKE_CURRENT_BINARY_DIR}/fbgeneratortest.moc
+)
+add_executable(fbgeneratortest ${FBDAEMON_SRCS} fbgeneratortest.cpp)
+target_link_libraries(fbgeneratortest ${COMMON_DEPENDENCIES} ${QT_QTTEST_LIBRARY} kolabutils)
diff --git a/fbdaemon/tests/fbgeneratortest.cpp b/fbdaemon/tests/fbgeneratortest.cpp
index 0cb9560..30ab638 100644
--- a/fbdaemon/tests/fbgeneratortest.cpp
+++ b/fbdaemon/tests/fbgeneratortest.cpp
@@ -18,76 +18,89 @@
#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 "kolabaccount.h"
+#include "testlib/testutils.h"
class FBGeneratorTest: public QObject
{
Q_OBJECT
- QString sourcehost;
+// QString sourcehost;
QString targethost;
QString user;
QString admin;
QString adminpw;
qint16 port;
+ QList<Folder> folders;
public:
- explicit MigrationScenarioTest(QObject* parent = 0)
+ explicit FBGeneratorTest(QObject* parent = 0)
: QObject(parent),
- sourcehost("192.168.122.104"),
+// sourcehost("192.168.122.104"),
targethost("192.168.122.10"),
user("john.doe@example.org"),
admin("cyrus-admin"),
adminpw("admin"),
port(143)
{
+ Object calObj1;
+ KCalCore::Event::Ptr event(new KCalCore::Event());
+ event->setUid("uid1");
+ event->setDtStart(KDateTime::currentUtcDateTime());
+ event->setDtEnd(KDateTime::currentUtcDateTime().addSecs(3600));
+ calObj1.message = Kolab::KolabObjectWriter::writeEvent(event, Kolab::KolabV3, "fbtest");
+ folders << Folder("Calendar", Kolab::EventType, QList<Object>() << calObj1);
+
+// folders << Folder("Freebusy", Kolab::FreebusyType, QList<Object>()/* << fbObj1*/);
}
- virtual ~MigrationScenarioTest(){};
-
private:
- void setupSourceAccount()
- {
- KolabServer *kolabServer = new KolabServer(this);
- kolabServer->setHost(sourcehost, port);
- kolabServer->setAdminCredentials(admin, adminpw);
- KolabAccount *account = kolabServer->getAccount(user);
- account->cleanAccount();
- createFolders(account, folders);
- }
-
void setupTargetAccount()
{
- //Depending on the test scenario, clear target account
+ QObject obj;
+ KolabAccount *account = new KolabAccount(&obj);
+ account->setHost(targethost, port);
+ account->setCredentials(user, adminpw, admin);
+ account->init();
+
+ account->cleanAccount();
+ createFolders(account, folders);
}
void executeGeneration()
{
+ 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;
-
FBGeneratorJob *job = new FBGeneratorJob(targethost, port, user, &obj);
job->exec();
}
- void checkFolders(SourceAccount *account, const QList<Folder> &folders)
+ void checkFolders(KolabAccount *account, const QList<Folder> &folders)
{
const QStringList &receivedFolders = account->lookupFolderList();
- QStringList::const_iterator recIt = receivedFolders.constBegin();
- QList<Folder>::const_iterator foldersIt = folders.constBegin();
- QCOMPARE(receivedFolders.size(), folders.size());
- for (;foldersIt != folders.constEnd() && recIt != receivedFolders.constEnd(); ++foldersIt, ++recIt) {
- qDebug() << "Folder: " << *recIt;
- QCOMPARE(*recIt, foldersIt->name);
- //TODO Check folder annotations
-
- const QList<Object> &objects = account->getObjects(foldersIt->name);
- QCOMPARE(objects.size(), foldersIt->objects.size());
+ qDebug() << receivedFolders;
+ foreach(const Folder &folder, folders) {
+ qDebug() << folder.name;
+ QVERIFY(receivedFolders.contains(folder.name));
+ const QList<Object> &objects = account->getObjects(folder.name);
+ QCOMPARE(objects.size(), folder.objects.size());
QList<Object>::const_iterator recObjIt = objects.constBegin();
- QList<Object>::const_iterator objIt = foldersIt->objects.constBegin();
- for (;objIt != foldersIt->objects.constEnd() && recObjIt != objects.constEnd(); ++objIt, ++recObjIt) {
+ 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));
@@ -98,21 +111,24 @@ private:
void checkTargetAccount()
{
-
+ //Check that fb-object and aggregated fb object has been created
QObject obj;
- KolabSourceServer *kolabSourceServer = new KolabSourceServer(&obj);
- kolabSourceServer->setHost(targethost, port);
- kolabSourceServer->setAdminCredentials(admin, adminpw);
- kolabSourceServer->setSingleUser(user);
+ KolabAccount *account = new KolabAccount(&obj);
+ account->setHost(targethost, port);
+ account->setCredentials(user, adminpw, admin);
+ account->init();
- SourceAccount *account = kolabSourceServer->getSourceAccount(user);
- checkFolders(account, folders);
- account->logout();
- }
- void checkSourceAccount()
- {
- //If we start clearing the source server on successful migration, check that messages are really gone.
+ 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");
+
+ QList<Folder> targetFolders;
+ targetFolders << Folder("Freebusy", Kolab::FreebusyType, QList<Object>() << fbObj1);
+ checkFolders(account, targetFolders);
+ account->logout();
}
private slots: