importmailjobinterfacetest.cpp 5.27 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
   Copyright (C) 2020 Laurent Montel <montel@kde.org>

   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; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "importmailjobinterfacetest.h"
#include "archivestorage.h"
#include "resourceconvertertest.h"
#include "testimportfile.h"
Laurent Montel's avatar
Laurent Montel committed
24
#include "utils.h"
Laurent Montel's avatar
Laurent Montel committed
25
26
27
28
29
30
31
32
33
34
#include <QSignalSpy>
#include <QTest>
QTEST_MAIN(ImportMailJobInterfaceTest)
ImportMailJobInterfaceTestImpl::ImportMailJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep)
    : ImportMailJobInterface(parent, typeSelected, archiveStorage, numberOfStep)
{
}

ImportMailJobInterfaceTestImpl::~ImportMailJobInterfaceTestImpl()
{
Laurent Montel's avatar
Laurent Montel committed
35
36
    //Clean up temp repo
    QVERIFY(QDir(QDir::tempPath() + QLatin1Char('/') + Utils::storeMails()).removeRecursively());
Laurent Montel's avatar
Laurent Montel committed
37
38
39
40
41
}

Akonadi::Collection::Id ImportMailJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path)
{
    ResourceConverterTest resourceConverterTest;
Laurent Montel's avatar
Laurent Montel committed
42
    resourceConverterTest.setTestPath(mPathConfig);
Laurent Montel's avatar
Laurent Montel committed
43
44
45
46
47
    return resourceConverterTest.convertFolderPathToCollectionId(path);
}

void ImportMailJobInterfaceTestImpl::synchronizeResource(const QStringList &lst)
{
Laurent Montel's avatar
Laurent Montel committed
48
    mLogCreateResource->logSynchronizeResource(lst);
49
    slotNextStep();
Laurent Montel's avatar
Laurent Montel committed
50
51
}

52
QString ImportMailJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap<QString, QVariant> &settings, bool synchronizeTree)
Laurent Montel's avatar
Laurent Montel committed
53
{
Laurent Montel's avatar
Laurent Montel committed
54
    return mLogCreateResource->logCreateResource(resources, name, settings, synchronizeTree);
Laurent Montel's avatar
Laurent Montel committed
55
56
57
58
}

void ImportMailJobInterfaceTestImpl::registerSpecialCollection(Akonadi::SpecialMailCollections::Type type, qint64 colId)
{
59
    mLogCreateResource->logRegisterSpecialCollection(type, colId);
Laurent Montel's avatar
Laurent Montel committed
60
61
62
63
}

void ImportMailJobInterfaceTestImpl::importFilters(const QVector<MailCommon::MailFilter *> &filters)
{
Laurent Montel's avatar
Laurent Montel committed
64
    qDebug() << " void ImportMailJobInterfaceTestImpl::importFilters(const QVector<MailCommon::MailFilter *> &filters)";
Laurent Montel's avatar
Laurent Montel committed
65
66
}

Laurent Montel's avatar
Laurent Montel committed
67
68
69
QString ImportMailJobInterfaceTestImpl::adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData)
{
    ResourceConverterTest resourceConverterTest;
Laurent Montel's avatar
Laurent Montel committed
70
    resourceConverterTest.setTestPath(mPathConfig);
Laurent Montel's avatar
Laurent Montel committed
71
72
73
    return resourceConverterTest.adaptResourcePath(resourceConfig, storedData);
}

Laurent Montel's avatar
Laurent Montel committed
74
75
76
77
78
79
80
QString ImportMailJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath)
{
    ResourceConverterTest resourceConverterTest;
    resourceConverterTest.setTestPath(mPathConfig);
    return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath);
}

Laurent Montel's avatar
Laurent Montel committed
81
82
83
84
85
ImportMailJobInterfaceTest::ImportMailJobInterfaceTest(QObject *parent)
    : QObject(parent)
{
}

86
void ImportMailJobInterfaceTest::importMail_data()
Laurent Montel's avatar
Laurent Montel committed
87
88
89
{
    QTest::addColumn<QString>("zipFilePath");
    QTest::addColumn<QString>("testPath");
Laurent Montel's avatar
Laurent Montel committed
90
91
    QTest::addColumn<Utils::StoredTypes>("options");
    Utils::StoredTypes options = {Utils::StoredType::Config};
92
    const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/import/");
Laurent Montel's avatar
Laurent Montel committed
93

Laurent Montel's avatar
Laurent Montel committed
94
    QTest::newRow("mailonlyconfig") << QString::fromLatin1(pathConfig) << QStringLiteral("/mailonlyconfig/") << options;
Laurent Montel's avatar
Laurent Montel committed
95
    options = {Utils::StoredType::Config|Utils::StoredType::Resources};
Laurent Montel's avatar
Laurent Montel committed
96
    QTest::newRow("mailconfigandresource") << QString::fromLatin1(pathConfig) <<  QStringLiteral("mailconfigandresource/") << options;
Laurent Montel's avatar
Laurent Montel committed
97
    options = {Utils::StoredType::MailTransport};
Laurent Montel's avatar
Laurent Montel committed
98
    QTest::newRow("mailtransport") << QString::fromLatin1(pathConfig) << QStringLiteral("mailtransport/") << options;
Laurent Montel's avatar
Laurent Montel committed
99
    options = {Utils::StoredType::Identity};
Laurent Montel's avatar
Laurent Montel committed
100
    QTest::newRow("identities") << QString::fromLatin1(pathConfig) << QStringLiteral("identities/") << options;
Laurent Montel's avatar
Laurent Montel committed
101
102
}

103
void ImportMailJobInterfaceTest::importMail()
Laurent Montel's avatar
Laurent Montel committed
104
105
106
{
    QFETCH(QString, zipFilePath);
    QFETCH(QString, testPath);
Laurent Montel's avatar
Laurent Montel committed
107
    QFETCH(Utils::StoredTypes, options);
Laurent Montel's avatar
Fix url    
Laurent Montel committed
108
    TestImportFile *file = new TestImportFile(zipFilePath + testPath, this);
Laurent Montel's avatar
Laurent Montel committed
109
    file->setPathConfig(zipFilePath + testPath);
110
    file->setExtractPath(QDir::tempPath() + QLatin1Char('/') + testPath);
Laurent Montel's avatar
Laurent Montel committed
111
    file->setExcludePath(Utils::mailsPath()); // ???
Laurent Montel's avatar
Laurent Montel committed
112
    ImportMailJobInterfaceTestImpl *impl = new ImportMailJobInterfaceTestImpl(this, options, file->archiveStorage(), 1);
Laurent Montel's avatar
Laurent Montel committed
113
    impl->setPathConfig(file->pathConfig());
Laurent Montel's avatar
Laurent Montel committed
114
    file->setAbstractImportExportJob(impl);
Laurent Montel's avatar
Laurent Montel committed
115
    file->setLoggingFilePath(impl->loggingFilePath());
Laurent Montel's avatar
Laurent Montel committed
116
117
118
119
    file->start();
    delete impl;
    delete file;
}
120
121
122
123
124
125


void ImportMailJobInterfaceTestImpl::addNewIdentity(const QString &name, KConfigGroup &group, int defaultIdentities, int oldUid)
{
    qDebug() << " void ImportMailJobInterfaceTestImpl::addNewIdentity(const QString &name, KConfigGroup &group, int defaultIdentities, int oldUid) not implemented yet";
}