importmailjobinterfacetest.cpp 3.95 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
24
25
26
27
28
29
30
31
32
33
34
/*
   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"
#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(QLatin1String(PIMDATAEXPORTER_DIR));
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
53
54
    //TODO
}

QString ImportMailJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap<QString, QVariant> &settings)
{
55
    mLogCreateResource->logCreateResource(resources, name, settings, false);
56
    qDebug() << " QString ImportMailJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap<QString, QVariant> &settings)" << resources << " name " << name << " settings " << settings;
Laurent Montel's avatar
Laurent Montel committed
57
58
59
60
61
62
63
64
65
66
67
68
    //TODO
    return {};
}

void ImportMailJobInterfaceTestImpl::registerSpecialCollection(Akonadi::SpecialMailCollections::Type type, qint64 colId)
{
}

void ImportMailJobInterfaceTestImpl::importFilters(const QVector<MailCommon::MailFilter *> &filters)
{
}

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

Laurent Montel's avatar
Laurent Montel committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
ImportMailJobInterfaceTest::ImportMailJobInterfaceTest(QObject *parent)
    : QObject(parent)
{
}

void ImportMailJobInterfaceTest::importMailConfig_data()
{
    QTest::addColumn<QString>("zipFilePath");
    QTest::addColumn<QString>("testPath");
    const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/import/");
    QTest::newRow("test1") << QString::fromLatin1(pathConfig) << QStringLiteral("/test1/");
}

void ImportMailJobInterfaceTest::importMailConfig()
{
    QFETCH(QString, zipFilePath);
    QFETCH(QString, testPath);
Laurent Montel's avatar
Fix url    
Laurent Montel committed
93
    TestImportFile *file = new TestImportFile(zipFilePath + testPath, this);
Laurent Montel's avatar
Laurent Montel committed
94
95
    file->setPathConfig(zipFilePath + testPath);
    file->setExtractPath(QDir::tempPath() + testPath);
Laurent Montel's avatar
Laurent Montel committed
96
    file->setExcludePath(Utils::mailsPath()); // ???
Laurent Montel's avatar
Laurent Montel committed
97
98
    ImportMailJobInterfaceTestImpl *impl = new ImportMailJobInterfaceTestImpl(this, {Utils::StoredType::Config}, file->archiveStorage(), 1);
    file->setAbstractImportExportJob(impl);
Laurent Montel's avatar
Laurent Montel committed
99
    file->setLoggingFilePath(impl->loggingFilePath());
Laurent Montel's avatar
Laurent Montel committed
100
101
102
103
    file->start();
    delete impl;
    delete file;
}
Laurent Montel's avatar
Laurent Montel committed
104
105