summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2012-10-17 11:12:11 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2012-10-17 11:12:11 (GMT)
commit874ca245ef248cb1505e2f6e980a876e2fb2b340 (patch)
treefa88cb90ff7545c644734cd28b4ed12188ae1dfd
parentcd1870fd0fd1019299af5c91626f341e6b8e89db (diff)
downloadkolab-utils-874ca245ef248cb1505e2f6e980a876e2fb2b340.tar.gz
Added migration test which uses two real imap servers to test the migraiton.
-rw-r--r--migrationutility/tests/CMakeLists.txt9
-rw-r--r--migrationutility/tests/migrationscenariotest.cpp210
-rw-r--r--migrationutility/tests/migrationscenariotest.h25
-rw-r--r--migrationutility/tests/migrationtest.cpp12
4 files changed, 252 insertions, 4 deletions
diff --git a/migrationutility/tests/CMakeLists.txt b/migrationutility/tests/CMakeLists.txt
index d7c6144..37b2be6 100644
--- a/migrationutility/tests/CMakeLists.txt
+++ b/migrationutility/tests/CMakeLists.txt
@@ -18,7 +18,14 @@ qt4_generate_moc(
# message("blasbblab ${kolabproxy_shared_relative_SRCS} : ${MIGRATION_SRCS}")
# message("sdfsdf ${MIGRATIONTEST_MOC}")
-add_executable(migrationtest ${MIGRATION_SRCS} ${MIGRATION_MOC} migrationtest.cpp)
+add_executable(migrationtest ${MIGRATION_SRCS} ${MIGRATION_MOC} ${JOBS_SRCS} migrationtest.cpp)
# set_target_properties(migrationtest PROPERTIES AUTOMOC TRUE)
target_link_libraries(migrationtest ${COMMON_DEPENDENCIES} ${QT_QTTEST_LIBRARY})
+
+qt4_generate_moc(
+ ${CMAKE_CURRENT_SOURCE_DIR}/migrationscenariotest.cpp
+ ${CMAKE_CURRENT_BINARY_DIR}/migrationscenariotest.moc
+)
+add_executable(migrationscenariotest ${MIGRATION_SRCS} ${MIGRATION_MOC} ${JOBS_SRCS} migrationscenariotest.cpp)
+target_link_libraries(migrationscenariotest ${COMMON_DEPENDENCIES} ${QT_QTTEST_LIBRARY})
diff --git a/migrationutility/tests/migrationscenariotest.cpp b/migrationutility/tests/migrationscenariotest.cpp
new file mode 100644
index 0000000..bc0fc35
--- /dev/null
+++ b/migrationutility/tests/migrationscenariotest.cpp
@@ -0,0 +1,210 @@
+/*
+ * 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 "migrationutility/coordinationjob.h"
+#include "migrationutility/kolabserver.h"
+#include "migrationutility/sourceserver.h"
+#include "migrationutility/kolabaccount.h"
+
+
+struct Folder
+{
+ Folder(const QString &n, Kolab::FolderType type = Kolab::MailType, const QList<Object> &obj = QList<Object>(), const QList<Folder> &folders = QList<Folder>()): subfolders(folders), objects(obj), name(n), folderType(type){};
+ QList<Folder> subfolders;
+ QList<Object> objects;
+ QString name;
+ Kolab::FolderType folderType;
+};
+
+/**
+ * This test simulates an entier migration scenario.
+ *
+ * It requires two Kolab Servers, with all the required users already setup (ideally two local virtual machines, which are used for testing only)
+ * So this is really a rather complex integration test and not a unittest which has to be executed all the time.
+ *
+ */
+class MigrationScenarioTest: public QObject
+{
+ Q_OBJECT
+
+ QString sourcehost;
+ QString targethost;
+ QString user;
+ QString admin;
+ QString adminpw;
+ qint16 port;
+ QList<Folder> folders;
+
+public:
+ explicit MigrationScenarioTest(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)
+ {
+ folders << Folder("INBOX");
+ folders << Folder("Calendar", Kolab::EventType);
+ folders << Folder("Configuration", Kolab::ConfigurationType);
+ folders << Folder("Contacts", Kolab::ContactType);
+ folders << Folder("Drafts");
+ folders << Folder("Journal", Kolab::JournalType);
+ folders << Folder("Notes", Kolab::NoteType);
+ folders << Folder("Sent");
+ folders << Folder("Tasks", Kolab::TaskType);
+ folders << Folder("Trash");
+ }
+
+ virtual ~MigrationScenarioTest(){};
+
+private:
+ KolabSourceServer *getSourceServer()
+ {
+ KolabSourceServer *kolabSourceServer = new KolabSourceServer(this);
+ kolabSourceServer->setHost(sourcehost, port);
+ kolabSourceServer->setAdminCredentials(admin, adminpw);
+ kolabSourceServer->setSingleUser(user);
+ return kolabSourceServer;
+ }
+
+ void createFolders(KolabAccount *account, const QList<Folder> &folders)
+ {
+ foreach (const Folder &folder, folders) {
+ account->createFolder(folder.name, folder.folderType);
+ foreach(const Object &obj, folder.objects) {
+ account->appendObject(obj, folder.name);
+ }
+ createFolders(account, folder.subfolders);
+ }
+ }
+
+ void setupSourceAccount()
+ {
+ KolabServer *kolabServer = new KolabServer(this);
+ kolabServer->setHost(sourcehost, port);
+ kolabServer->setAdminCredentials(admin, adminpw);
+ KolabAccount *account = kolabServer->getAccount(user);
+ account->cleanAccount();
+// account->setupFolders();
+// account->createFolder();
+ createFolders(account, folders);
+ Object calObj1;
+// calObj1.message =
+ calObj1.flags << QByteArray("\\Seen");
+ account->appendObject(calObj1, "Calendar");
+
+ }
+
+ void setupTargetAccount()
+ {
+ //Depending on the test scenario, clear target account
+ }
+
+ void executeMigration()
+ {
+ QObject obj;
+ //Copy main.cpp
+ KolabSourceServer *kolabSourceServer = new KolabSourceServer(&obj);
+ kolabSourceServer->setHost(sourcehost, port);
+ kolabSourceServer->setAdminCredentials(admin, adminpw);
+ kolabSourceServer->setSingleUser(user);
+
+ KolabServer *kolabServer = new KolabServer(&obj);
+ kolabServer->setHost(targethost, port);
+ kolabServer->setAdminCredentials(admin, adminpw);
+
+ CoordinationJob *job = new CoordinationJob(kolabSourceServer, kolabServer, &obj);
+ job->exec();
+ }
+
+ void checkFolder(const QString &folder, const QList<Object> &objects)
+ {
+ foreach(const Object &obj, objects) {
+ qDebug() << "Object: " << obj.flags;
+ }
+ }
+
+ void checkTargetAccount()
+ {
+ QStringList expectedFolders;
+ expectedFolders << QLatin1String("INBOX");
+// expectedFolders << QLatin1String("Archive");
+ expectedFolders << QLatin1String("Calendar");
+// expectedFolders << QLatin1String("Calendar/Personal Calendar");
+// expectedFolders << QLatin1String("Calendar/Personal Calendar/another Folder");
+ expectedFolders << QLatin1String("Configuration");
+ expectedFolders << QLatin1String("Contacts");
+// expectedFolders << QLatin1String("Contacts/Personal Contacts");
+// expectedFolders << QLatin1String("Contacts/Personal Contacts/contacts");
+ expectedFolders << QLatin1String("Drafts");
+// expectedFolders << QLatin1String("Freebusy");
+ expectedFolders << QLatin1String("Journal");
+ expectedFolders << QLatin1String("Notes");
+ expectedFolders << QLatin1String("Sent");
+// expectedFolders << QLatin1String("Spam");
+ expectedFolders << QLatin1String("Tasks");
+// expectedFolders << QLatin1String("Tasks/aasdf");
+// expectedFolders << QLatin1String("Tasks/dfdslkjfdsljfs");
+ expectedFolders << QLatin1String("Trash");
+
+ QObject obj;
+ KolabSourceServer *kolabSourceServer = new KolabSourceServer(&obj);
+ kolabSourceServer->setHost(targethost, port);
+ kolabSourceServer->setAdminCredentials(admin, adminpw);
+ kolabSourceServer->setSingleUser(user);
+
+ SourceAccount *account = kolabSourceServer->getSourceAccount(user);
+ const QStringList &receivedFolders = account->lookupFolderList();
+ foreach (const QString & folder, receivedFolders) {
+ qDebug() << "Folder: " << folder;
+ checkFolder(folder, account->getObjects(folder));
+ }
+ account->logout();
+
+ QCOMPARE(receivedFolders, expectedFolders);
+
+ //Check created folder
+ //Check folder annotations
+ //Check converted messages
+
+
+ }
+
+ void checkSourceAccount()
+ {
+ //If we start clearing the source server on successful migration, check that messages are really gone.
+ }
+
+private slots:
+ void testMigration()
+ {
+ setupSourceAccount();
+ setupTargetAccount();
+ executeMigration();
+ checkTargetAccount();
+ checkSourceAccount();
+ }
+
+};
+QTEST_MAIN( MigrationScenarioTest )
+
+#include "migrationscenariotest.moc" \ No newline at end of file
diff --git a/migrationutility/tests/migrationscenariotest.h b/migrationutility/tests/migrationscenariotest.h
new file mode 100644
index 0000000..525e678
--- /dev/null
+++ b/migrationutility/tests/migrationscenariotest.h
@@ -0,0 +1,25 @@
+/*
+ * 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/>.
+ */
+
+#ifndef MIGRATIONSCENARIOTEST_H
+#define MIGRATIONSCENARIOTEST_H
+
+class MigrationScenarioTest
+{
+};
+
+#endif // MIGRATIONSCENARIOTEST_H
diff --git a/migrationutility/tests/migrationtest.cpp b/migrationutility/tests/migrationtest.cpp
index 521da79..933e39b 100644
--- a/migrationutility/tests/migrationtest.cpp
+++ b/migrationutility/tests/migrationtest.cpp
@@ -1,6 +1,10 @@
#include <QObject>
#include <QTest>
-#include <coordinationjob.h>
+#include "coordinationjob.h"
+#include "sourceserver.h"
+#include "kolabserver.h"
+#include "migrateuserjob.h"
+#include <kolabaccount.h>
class MigrationTest : public QObject
{
@@ -9,7 +13,8 @@ class MigrationTest : public QObject
void testUsersProcessed()
{
TestServer *server = new TestServer(this);
- CoordinationJob *job = new CoordinationJob(server, this);
+ KolabServer *kolabServer = new KolabServer(this);
+ CoordinationJob *job = new CoordinationJob(server, kolabServer, this);
job->exec();
QVERIFY(server->mUsers.isEmpty());
}
@@ -17,7 +22,8 @@ class MigrationTest : public QObject
void testFoldersProcessed()
{
TestAccount *server = new TestAccount(this);
- MigrateUserJob *job = new MigrateUserJob(server, this);
+ KolabAccount *kolabServer = new KolabAccount(this);
+ MigrateUserJob *job = new MigrateUserJob(server, kolabServer, this);
job->exec();
QVERIFY(server->mFolderList.isEmpty());
}