Commit f6cb7404 authored by Volker Krause's avatar Volker Krause
Browse files

Remove special import code path for unit tests

This now all goes through the general import code in ApplicationController.
parent d9cfd328
......@@ -6,6 +6,7 @@
#include <livedata.h>
#include <livedatamanager.h>
#include <applicationcontroller.h>
#include <reservationmanager.h>
#include <KItinerary/Reservation>
......@@ -92,7 +93,9 @@ private Q_SLOTS:
ldm.m_unitTestTime = QDateTime({2017, 9, 10}, {12, 0}, QTimeZone("Europe/Zurich")); // that's in the middle of the first train leg
ldm.setReservationManager(&resMgr);
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
ApplicationController ctrl;
ctrl.setReservationManager(&resMgr);
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
QCOMPARE(resMgr.batches().size(), 11);
const auto flight = resMgr.batches()[0];
......
......@@ -39,13 +39,6 @@ private:
}
}
QByteArray readFile(const QString &fn)
{
QFile f(fn);
f.open(QFile::ReadOnly);
return f.readAll();
}
private Q_SLOTS:
void initTestCase()
{
......@@ -65,7 +58,9 @@ private Q_SLOTS:
QVERIFY(rmSpy.isValid());
QVERIFY(mgr.batches().empty());
mgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/data/4U8465-v1.json")));
ApplicationController ctrl;
ctrl.setReservationManager(&mgr);
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/4U8465-v1.json")));
auto res = mgr.batches();
QCOMPARE(res.size(), 1);
......@@ -77,7 +72,7 @@ private Q_SLOTS:
QVERIFY(updateSpy.isEmpty());
QVERIFY(!mgr.reservation(resId).isNull());
mgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/data/4U8465-v2.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/4U8465-v2.json")));
QCOMPARE(addSpy.size(), 1);
QCOMPARE(updateSpy.size(), 1);
QCOMPARE(mgr.batches().size(), 1);
......@@ -140,9 +135,11 @@ private Q_SLOTS:
{
ReservationManager mgr;
clearReservations(&mgr);
ApplicationController ctrl;
ctrl.setReservationManager(&mgr);
QCOMPARE(mgr.batches().size(), 0);
mgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/data/google-multi-passenger-flight.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/google-multi-passenger-flight.json")));
QCOMPARE(mgr.batches().size(), 2);
const auto batchId = mgr.batches()[0];
......@@ -180,7 +177,9 @@ private Q_SLOTS:
QSignalSpy batchRenameSpy(&mgr, &ReservationManager::batchRenamed);
QSignalSpy batchRemovedSpy(&mgr, &ReservationManager::batchRemoved);
mgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/data/google-multi-passenger-flight.json")));
ApplicationController ctrl;
ctrl.setReservationManager(&mgr);
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/google-multi-passenger-flight.json")));
QCOMPARE(batchAddSpy.size(), 2);
QCOMPARE(batchChangeSpy.size(), 2);
QCOMPARE(batchRenameSpy.size(), 0);
......@@ -336,8 +335,10 @@ private Q_SLOTS:
{
ReservationManager mgr;
clearReservations(&mgr);
ApplicationController ctrl;
ctrl.setReservationManager(&mgr);
QCOMPARE(mgr.batches().size(), 0);
mgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
QCOMPARE(mgr.batches().size(), 11);
auto res = mgr.reservation(mgr.batches().at(0));
......@@ -352,7 +353,7 @@ private Q_SLOTS:
QSignalSpy batchRenameSpy(&mgr, &ReservationManager::batchRenamed);
QSignalSpy batchRemovedSpy(&mgr, &ReservationManager::batchRemoved);
mgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/../tests/randa2017-flight-cancellation.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/../tests/randa2017-flight-cancellation.json")));
QCOMPARE(mgr.batches().size(), 11);
QCOMPARE(batchAddSpy.size(), 0);
QCOMPARE(batchChangeSpy.size(), 0);
......
......@@ -6,6 +6,7 @@
#include <statisticsmodel.h>
#include <statisticstimerangemodel.h>
#include <applicationcontroller.h>
#include <reservationmanager.h>
#include <tripgroupmanager.h>
......@@ -36,13 +37,6 @@ private:
QCOMPARE(mgr->batches().size(), 0);
}
QByteArray readFile(const QString &fn)
{
QFile f(fn);
f.open(QFile::ReadOnly);
return f.readAll();
}
private Q_SLOTS:
void initTestCase()
{
......@@ -60,16 +54,18 @@ private Q_SLOTS:
TripGroupManager::clear();
TripGroupManager tgMgr;
tgMgr.setReservationManager(&resMgr);
ApplicationController ctrl;
ctrl.setReservationManager(&resMgr);
StatisticsModel stats;
QSignalSpy changeSpy(&stats, &StatisticsModel::changed);
stats.setReservationManager(&resMgr);
stats.setTripGroupManager(&tgMgr);
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/../tests/akademy2017.json")));
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/../tests/akademy2018-program.json")));
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/data/timeline/flight-cancelation.json"))); // canceled flight, should not change stats
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/../tests/akademy2017.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/../tests/akademy2018-program.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/timeline/flight-cancelation.json"))); // canceled flight, should not change stats
stats.setTimeRange({}, {});
QVERIFY(!changeSpy.isEmpty());
......@@ -151,9 +147,12 @@ private Q_SLOTS:
{
ReservationManager resMgr;
clearReservations(&resMgr);
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/../tests/akademy2017.json")));
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/../tests/akademy2018-program.json")));
ApplicationController ctrl;
ctrl.setReservationManager(&resMgr);
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/../tests/akademy2017.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/../tests/akademy2018-program.json")));
StatisticsTimeRangeModel model;
QAbstractItemModelTester tester(&model);
......
......@@ -5,6 +5,7 @@
*/
#include <timelinedelegatecontroller.h>
#include <applicationcontroller.h>
#include <livedatamanager.h>
#include <reservationmanager.h>
......@@ -163,7 +164,9 @@ private Q_SLOTS:
{
ReservationManager mgr;
clearReservations(&mgr);
mgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
ApplicationController ctrl;
ctrl.setReservationManager(&mgr);
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
TimelineDelegateController controller;
controller.setReservationManager(&mgr);
......@@ -193,7 +196,9 @@ private Q_SLOTS:
LiveData::clearStorage();
LiveDataManager ldm;
ldm.setReservationManager(&mgr);
mgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
ApplicationController ctrl;
ctrl.setReservationManager(&mgr);
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
TimelineDelegateController controller;
controller.setReservationManager(&mgr);
......@@ -233,7 +238,9 @@ private Q_SLOTS:
{
ReservationManager mgr;
clearReservations(&mgr);
mgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/data/timeline/flight-cancelation.json")));
ApplicationController ctrl;
ctrl.setReservationManager(&mgr);
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/timeline/flight-cancelation.json")));
TimelineDelegateController controller;
controller.setReservationManager(&mgr);
......
......@@ -58,13 +58,6 @@ private:
QCOMPARE(mgr->batches().size(), 0);
}
QByteArray readFile(const QString &fn)
{
QFile f(fn);
f.open(QFile::ReadOnly);
return f.readAll();
}
private Q_SLOTS:
void initTestCase()
{
......@@ -155,6 +148,8 @@ private Q_SLOTS:
{
ReservationManager resMgr;
clearReservations(&resMgr);
ApplicationController ctrl;
ctrl.setReservationManager(&resMgr);
TimelineModel model;
QAbstractItemModelTester tester(&model);
......@@ -170,7 +165,7 @@ private Q_SLOTS:
QCOMPARE(model.rowCount(), 1);
QCOMPARE(model.index(0, 0).data(TimelineModel::ElementTypeRole), TimelineElement::TodayMarker);
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/data/haus-randa-v1.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/haus-randa-v1.json")));
QCOMPARE(insertSpy.size(), 3);
QCOMPARE(insertSpy.at(0).at(1).toInt(), 0);
QCOMPARE(insertSpy.at(0).at(2).toInt(), 0);
......@@ -185,7 +180,7 @@ private Q_SLOTS:
QCOMPARE(model.index(2, 0).data(TimelineModel::ElementRangeRole), TimelineElement::RangeEnd);
// move end date of a hotel booking: dataChanged on RangeBegin, move (or del/ins) on RangeEnd
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/data/haus-randa-v2.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/haus-randa-v2.json")));
QCOMPARE(insertSpy.size(), 5);
QCOMPARE(updateSpy.size(), 1);
QCOMPARE(rmSpy.size(), 2);
......@@ -208,6 +203,8 @@ private Q_SLOTS:
{
ReservationManager resMgr;
clearReservations(&resMgr);
ApplicationController ctrl;
ctrl.setReservationManager(&resMgr);
TimelineModel model;
QAbstractItemModelTester tester(&model);
......@@ -217,7 +214,7 @@ private Q_SLOTS:
QCOMPARE(model.rowCount(), 1);
QCOMPARE(model.index(0, 0).data(TimelineModel::ElementTypeRole), TimelineElement::TodayMarker);
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/data/flight-txl-lhr-sfo.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/flight-txl-lhr-sfo.json")));
QCOMPARE(model.rowCount(), 5); // 2x country info, 2x flights, today marker
QCOMPARE(model.index(0, 0).data(TimelineModel::ElementTypeRole), TimelineElement::Flight);
......@@ -402,6 +399,8 @@ private Q_SLOTS:
ReservationManager resMgr;
clearReservations(&resMgr);
ApplicationController ctrl;
ctrl.setReservationManager(&resMgr);
TimelineModel model;
QAbstractItemModelTester tester(&model);
model.setReservationManager(&resMgr);
......@@ -415,7 +414,7 @@ private Q_SLOTS:
QVERIFY(rmSpy.isValid());
// full import at runtime
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/data/google-multi-passenger-flight.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/google-multi-passenger-flight.json")));
QCOMPARE(model.rowCount(), 3); // 2x Flight, 1x TodayMarger
QCOMPARE(insertSpy.count(), 2);
QCOMPARE(updateSpy.count(), 2);
......@@ -475,6 +474,8 @@ private Q_SLOTS:
{
ReservationManager resMgr;
clearReservations(&resMgr);
ApplicationController ctrl;
ctrl.setReservationManager(&resMgr);
WeatherForecastManager weatherMgr;
weatherMgr.setTestModeEnabled(true);
......@@ -496,7 +497,7 @@ private Q_SLOTS:
QVERIFY(vp1.verify(&model));
// load something to define the current location, so we get weather
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/data/flight-txl-lhr-sfo.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/flight-txl-lhr-sfo.json")));
ModelVerificationPoint vp2(QLatin1String(SOURCE_DIR "/data/timeline/daychange-r2.model"));
vp2.setRoleFilter({TimelineModel::BatchIdRole});
QVERIFY(vp2.verify(&model));
......@@ -525,7 +526,9 @@ private Q_SLOTS:
QFETCH(QString, baseName);
ReservationManager resMgr;
clearReservations(&resMgr);
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/data/timeline/") + baseName + QLatin1String(".json")));
ApplicationController ctrl;
ctrl.setReservationManager(&resMgr);
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/timeline/") + baseName + QLatin1String(".json")));
TripGroupManager groupMgr;
groupMgr.setReservationManager(&resMgr);
WeatherForecastManager weatherMgr;
......@@ -566,7 +569,7 @@ private Q_SLOTS:
// retry with loading during runtime
clearReservations(&resMgr);
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/data/timeline/") + baseName + QLatin1String(".json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/timeline/") + baseName + QLatin1String(".json")));
QVERIFY(vp.verify(&model));
}
};
......
......@@ -6,6 +6,7 @@
#include <transfer.h>
#include <transfermanager.h>
#include <applicationcontroller.h>
#include <reservationmanager.h>
#include <tripgroupmanager.h>
#include <favoritelocationmodel.h>
......@@ -28,13 +29,6 @@ private:
QCOMPARE(mgr->batches().size(), 0);
}
QByteArray readFile(const QString &fn)
{
QFile f(fn);
f.open(QFile::ReadOnly);
return f.readAll();
}
private Q_SLOTS:
void initTestCase()
{
......@@ -48,6 +42,8 @@ private Q_SLOTS:
{
ReservationManager resMgr;
clearReservations(&resMgr);
ApplicationController ctrl;
ctrl.setReservationManager(&resMgr);
TripGroupManager::clear();
TripGroupManager tgMgr;
......@@ -74,9 +70,9 @@ private Q_SLOTS:
QSignalSpy changeSpy(&mgr, &TransferManager::transferChanged);
QSignalSpy removeSpy(&mgr, &TransferManager::transferRemoved);
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
// resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/../tests/akademy2017.json")));
// resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/../tests/akademy2018-program.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
// ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/../tests/akademy2017.json")));
// ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/../tests/akademy2018-program.json")));
QCOMPARE(addSpy.size() - removeSpy.size(), 4); // to/from home, and one inbetween
......
......@@ -4,6 +4,7 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include <applicationcontroller.h>
#include <locationinformation.h>
#include <reservationmanager.h>
#include <tripgroup.h>
......@@ -29,13 +30,6 @@ private:
QCOMPARE(mgr->batches().size(), 0);
}
QByteArray readFile(const QString &fn)
{
QFile f(fn);
f.open(QFile::ReadOnly);
return f.readAll();
}
private Q_SLOTS:
void initTestCase()
{
......@@ -52,8 +46,10 @@ private Q_SLOTS:
mgr.setReservationManager(&resMgr);
WeatherForecastManager fcMgr;
fcMgr.setTestModeEnabled(true);
ApplicationController ctrl;
ctrl.setReservationManager(&resMgr);
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
QCOMPARE(mgr.tripGroups().size(), 1);
TripGroupInfoProvider provider;
......
......@@ -6,6 +6,7 @@
#include "modelverificationpoint.h"
#include <applicationcontroller.h>
#include <reservationmanager.h>
#include <timelinemodel.h>
#include <tripgroupmanager.h>
......@@ -38,13 +39,6 @@ private:
QCOMPARE(mgr->batches().size(), 0);
}
QByteArray readFile(const QString &fn)
{
QFile f(fn);
f.open(QFile::ReadOnly);
return f.readAll();
}
private Q_SLOTS:
void initTestCase()
{
......@@ -60,9 +54,11 @@ private Q_SLOTS:
{
ReservationManager resMgr;
clearReservations(&resMgr);
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/data/timeline/multi-traveler-merge-with-countryinfo.json")));
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/data/google-multi-passenger-flight.json")));
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
ApplicationController ctrl;
ctrl.setReservationManager(&resMgr);
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/timeline/multi-traveler-merge-with-countryinfo.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/google-multi-passenger-flight.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
TripGroupManager groupMgr;
QSignalSpy addSpy(&groupMgr, &TripGroupManager::tripGroupAdded);
......@@ -114,7 +110,9 @@ private Q_SLOTS:
{
ReservationManager resMgr;
clearReservations(&resMgr);
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
ApplicationController ctrl;
ctrl.setReservationManager(&resMgr);
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
TripGroupManager groupMgr;
QSignalSpy addSpy(&groupMgr, &TripGroupManager::tripGroupAdded);
......
......@@ -4,6 +4,7 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include <applicationcontroller.h>
#include <reservationmanager.h>
#include <tripgroup.h>
#include <tripgroupmanager.h>
......@@ -33,13 +34,6 @@ private:
QCOMPARE(mgr->batches().size(), 0);
}
QByteArray readFile(const QString &fn)
{
QFile f(fn);
f.open(QFile::ReadOnly);
return f.readAll();
}
private Q_SLOTS:
void initTestCase()
{
......@@ -56,7 +50,9 @@ private Q_SLOTS:
{
ReservationManager resMgr;
clearReservations(&resMgr);
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/data/google-multi-passenger-flight.json")));
ApplicationController ctrl;
ctrl.setReservationManager(&resMgr);
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/google-multi-passenger-flight.json")));
{
TripGroupManager mgr;
QSignalSpy addSpy(&mgr, &TripGroupManager::tripGroupAdded);
......@@ -69,7 +65,7 @@ private Q_SLOTS:
TripGroupManager::clear();
clearReservations(&resMgr);
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
{
TripGroupManager mgr;
QSignalSpy addSpy(&mgr, &TripGroupManager::tripGroupAdded);
......@@ -82,7 +78,7 @@ private Q_SLOTS:
TripGroupManager::clear();
clearReservations(&resMgr);
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/data/timeline/multi-traveler-merge-with-countryinfo.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/timeline/multi-traveler-merge-with-countryinfo.json")));
{
TripGroupManager mgr;
QSignalSpy addSpy(&mgr, &TripGroupManager::tripGroupAdded);
......@@ -94,8 +90,8 @@ private Q_SLOTS:
}
TripGroupManager::clear();
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/data/google-multi-passenger-flight.json")));
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/google-multi-passenger-flight.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
{
TripGroupManager mgr;
QSignalSpy addSpy(&mgr, &TripGroupManager::tripGroupAdded);
......@@ -109,7 +105,7 @@ private Q_SLOTS:
clearReservations(&resMgr);
TripGroupManager::clear();
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/data/tripgroup/time-based-layover-detection.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/tripgroup/time-based-layover-detection.json")));
{
TripGroupManager mgr;
mgr.setReservationManager (&resMgr);
......@@ -125,10 +121,12 @@ private Q_SLOTS:
TripGroupManager::clear();
TripGroupManager mgr;
mgr.setReservationManager(&resMgr);
ApplicationController ctrl;
ctrl.setReservationManager(&resMgr);
// after adding the third element this will find a loop between the two inner legs and remove the first leg as a leading appendix
// the fourth leg however should be fixing that and result in a single 4 leg group
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/data/tripgroup/symmetric-two-leg-return-flight.json")));
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/tripgroup/symmetric-two-leg-return-flight.json")));
QCOMPARE(mgr.tripGroups().size(), 1);
auto g = mgr.tripGroup(mgr.tripGroups().at(0));
QCOMPARE(g.elements().size(), resMgr.batches().size());
......@@ -145,7 +143,9 @@ private Q_SLOTS:
QSignalSpy changeSpy(&mgr, &TripGroupManager::tripGroupChanged);
QSignalSpy rmSpy(&mgr, &TripGroupManager::tripGroupRemoved);
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/data/google-multi-passenger-flight.json")));
ApplicationController ctrl;
ctrl.setReservationManager(&resMgr);
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/google-multi-passenger-flight.json")));
QCOMPARE(addSpy.size(), 1);
auto g = mgr.tripGroup(addSpy.at(0).at(0).toString());
QCOMPARE(g.elements().size(), resMgr.batches().size());
......@@ -180,7 +180,9 @@ private Q_SLOTS:
ReservationManager resMgr;
clearReservations(&resMgr);
resMgr.importReservation(readFile(fileName));
ApplicationController ctrl;
ctrl.setReservationManager(&resMgr);
ctrl.importFromUrl(QUrl::fromLocalFile(fileName));
TripGroupManager mgr;
QSignalSpy addSpy(&mgr, &TripGroupManager::tripGroupAdded);
mgr.setReservationManager(&resMgr);
......@@ -194,7 +196,9 @@ private Q_SLOTS:
{
ReservationManager resMgr;
clearReservations(&resMgr);
resMgr.importReservation(readFile(QStringLiteral(SOURCE_DIR "/data/tripgroup/leading-appendix.json")));
ApplicationController ctrl;
ctrl.setReservationManager(&resMgr);
ctrl.importFromUrl(QUrl::fromLocalFile(QStringLiteral(SOURCE_DIR "/data/tripgroup/leading-appendix.json")));
TripGroupManager mgr;
QSignalSpy addSpy(&mgr, &TripGroupManager::tripGroupAdded);
mgr.setReservationManager(&resMgr);
......@@ -208,7 +212,9 @@ private Q_SLOTS:
{
ReservationManager resMgr;
clearReservations(&resMgr);
resMgr.importReservation(readFile(QStringLiteral(SOURCE_DIR "/../tests/randa2017.json")));
ApplicationController ctrl;
ctrl.setReservationManager(&resMgr);
ctrl.importFromUrl(QUrl::fromLocalFile(QStringLiteral(SOURCE_DIR "/../tests/randa2017.json")));
TripGroupManager mgr;
QSignalSpy addSpy(&mgr, &TripGroupManager::tripGroupAdded);
mgr.setReservationManager(&resMgr);
......
......@@ -141,14 +141,6 @@ QString ReservationManager::batchesBasePath()
return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QLatin1String("/batches/");
}
QVector<QString> ReservationManager::importReservation(const QByteArray& data, const QString &fileName)
{
ExtractorEngine engine;
engine.setContextDate(QDateTime(QDate::currentDate(), QTime(0, 0)));
engine.setData(data, fileName);
return importReservations(JsonLdDocument::fromJson(engine.extract()));
}
#ifdef Q_OS_ANDROID
QVector<QString> ReservationManager::importReservation(KMime::Message *msg)
{
......
......@@ -48,11 +48,10 @@ public:
Q_INVOKABLE void updateReservation(const QString &resId, const QVariant &res);
Q_INVOKABLE void removeReservation(const QString &id);
/** Attempts to extract reservation information from @p data.
/** Imports reservation in @p resData.
* @returns A list of reservation ids for the extracted elements. Those can be reservation
* ids that previously existed, in case the extracted elements could be merged.
*/
QVector<QString> importReservation(const QByteArray &data, const QString &fileName = {});
QVector<QString> importReservations(const QVector<QVariant> &resData);
#ifdef Q_OS_ANDROID
QVector<QString> importReservation(KMime::Message *msg);
......
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