Commit e510a900 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Reduce duplicate code

parent e44ad396
......@@ -17,8 +17,9 @@ add_library(test_resourceconverter STATIC
logcreatingressource.cpp
comparefilehelper.cpp
exportimportutil.cpp
saveresourceconfigtest.cpp
)
target_link_libraries(test_resourceconverter PUBLIC KF5::ConfigCore pimdataexporterprivate KF5::Archive Qt5::Test)
target_link_libraries(test_resourceconverter PUBLIC KF5::ConfigCore pimdataexporterprivate KF5::Archive Qt5::Test KF5::AkonadiCore)
#####
......
......@@ -43,3 +43,4 @@ void ExportImportUtil::addLogCreateResource(const QString &str)
{
mLogCreateResource->appendText(str);
}
......@@ -25,6 +25,7 @@
#include <KZip>
#include <QDebug>
#include <QTest>
#include <saveresourceconfigtest.h>
QTEST_MAIN(ExportNotesJobInterfaceTest)
......@@ -57,17 +58,9 @@ QVector<Utils::AkonadiInstanceInfo> ExportNotesJobInterfaceTestImpl::listOfResou
void ExportNotesJobInterfaceTestImpl::exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier)
{
qDebug() << " void ExportNotesJobInterfaceTestImpl::exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier)" << archivePath << " url " << url << " identifier " << identifier;
QVERIFY(identifier.startsWith(QLatin1String("akonadi_akonotes_resource_")));
QVERIFY(mArchiveStorage->archive()->addLocalFile(url + identifier + QLatin1String(".zip"), archivePath + Utils::resourceNoteArchiveName()));
ResourceConverterTest converter;
const QString errorStr = converter.storeResources(archive(), identifier, archivePath);
QVERIFY(!errorStr.isEmpty());
const QString urlAgentConfig = Akonadi::ServerManager::agentConfigFilePath(identifier);
QVERIFY(!urlAgentConfig.isEmpty());
const QFileInfo fi(urlAgentConfig);
const QString filename = fi.fileName();
QVERIFY(mArchiveStorage->archive()->addLocalFile(urlAgentConfig, archivePath + filename));
SaveResoureConfigTest saveResourceConfig;
saveResourceConfig.setArchive(mArchiveStorage->archive());
saveResourceConfig.exportResourceToArchive(archivePath, url, identifier, Utils::resourceNoteArchiveName(), {QLatin1String("akonadi_akonotes_resource_")});
slotNoteJobTerminated();
}
......
/*
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 "saveresourceconfigtest.h"
#include "resourceconvertertest.h"
#include <QTest>
#include <AkonadiCore/ServerManager>
SaveResoureConfigTest::SaveResoureConfigTest()
{
}
KZip *SaveResoureConfigTest::archive() const
{
return mArchive;
}
void SaveResoureConfigTest::setArchive(KZip *archive)
{
mArchive = archive;
}
void SaveResoureConfigTest::exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier, const QString &resourceArchiveName, const QStringList &resourceIdentifierTypes)
{
QVERIFY(mArchive);
bool typeIdentifierFound = false;
for (const QString & resourceType: resourceIdentifierTypes) {
typeIdentifierFound = identifier.startsWith(resourceType);
if (typeIdentifierFound) {
break;
}
}
QVERIFY(typeIdentifierFound);
QVERIFY(mArchive->addLocalFile(url + identifier + QLatin1String(".zip"), archivePath + resourceArchiveName));
ResourceConverterTest converter;
const QString errorStr = converter.storeResources(mArchive, identifier, archivePath);
QVERIFY(errorStr.isEmpty());
const QString urlAgentConfig = Akonadi::ServerManager::agentConfigFilePath(identifier);
QVERIFY(!urlAgentConfig.isEmpty());
const QFileInfo fi(urlAgentConfig);
const QString filename = fi.fileName();
QVERIFY(mArchive->addLocalFile(urlAgentConfig, archivePath + filename));
}
/*
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.
*/
#ifndef SAVERESOURECONFIGTEST_H
#define SAVERESOURECONFIGTEST_H
#include <KZip>
class SaveResoureConfigTest
{
public:
SaveResoureConfigTest();
KZip *archive() const;
void setArchive(KZip *archive);
void exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier, const QString &resourceArchiveName, const QStringList &resourceIdentifierTypes);
private:
KZip *mArchive = nullptr;
};
#endif // SAVERESOURECONFIGTEST_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment