diff --git a/tests/auto/configurations/testconfigurations.cpp b/tests/auto/configurations/testconfigurations.cpp index b46087b3..03c2e3ca 100644 --- a/tests/auto/configurations/testconfigurations.cpp +++ b/tests/auto/configurations/testconfigurations.cpp @@ -40,8 +40,8 @@ class TestConfigurations: public GuhTestBase private slots: void getConfigurations(); - void testTimeZones(); + void testServerName(); }; @@ -63,14 +63,80 @@ void TestConfigurations::getConfigurations() void TestConfigurations::testTimeZones() { - QVariantMap configurations = injectAndWait("Configuration.GetConfigurations").toMap().value("params").toMap(); - QString currentTimeZone = configurations.value("basicConfiguration").toMap().value("timeZone").toString(); - QString currentTime = configurations.value("basicConfiguration").toMap().value("serverTime").toString(); - qDebug() << currentTimeZone << QDateTime::fromTime_t(currentTime.toInt()); + QVariantMap params; QVariant response; QVariantMap configurations; + QVariantList timeZones = injectAndWait("Configuration.GetTimeZones").toMap().value("params").toMap().value("timeZones").toList(); QVERIFY(timeZones.count() > 0); QVERIFY(timeZones.contains("America/Toronto")); + QVERIFY(timeZones.contains("Europe/Vienna")); + // Set current timezone (Europe/Vienna) + params.clear(); response.clear(); configurations.clear(); + params.insert("timeZone", "Europe/Vienna"); + response = injectAndWait("Configuration.SetTimeZone", params); + verifyConfigurationError(response); + + // Get current timezone and time + params.clear(); response.clear(); configurations.clear(); + configurations = injectAndWait("Configuration.GetConfigurations").toMap().value("params").toMap(); + QString currentTimeZone = configurations.value("basicConfiguration").toMap().value("timeZone").toString(); + int currentTime = configurations.value("basicConfiguration").toMap().value("serverTime").toInt(); + qDebug() << currentTimeZone << QDateTime::fromTime_t(currentTime); + + // Set new timezone + params.clear(); response.clear(); configurations.clear(); + params.insert("timeZone", "Moon/Darkside"); + response = injectAndWait("Configuration.SetTimeZone", params); + verifyConfigurationError(response, GuhConfiguration::ConfigurationErrorInvalidTimeZone); + + // Set new timezone + params.clear(); response.clear(); configurations.clear(); + params.insert("timeZone", "America/Toronto"); + response = injectAndWait("Configuration.SetTimeZone", params); + verifyConfigurationError(response); + + // Check new timezone + params.clear(); response.clear(); configurations.clear(); + configurations = injectAndWait("Configuration.GetConfigurations").toMap().value("params").toMap(); + QString newTimeZone = configurations.value("basicConfiguration").toMap().value("timeZone").toString(); + int newTime = configurations.value("basicConfiguration").toMap().value("serverTime").toInt(); + qDebug() << newTimeZone << QDateTime::fromTime_t(newTime); + QVERIFY(currentTimeZone != newTimeZone); + + restartServer(); + + // Check loaded timezone + configurations = injectAndWait("Configuration.GetConfigurations").toMap().value("params").toMap(); + QString reloadedTimeZone = configurations.value("basicConfiguration").toMap().value("timeZone").toString(); + QVERIFY(newTimeZone == reloadedTimeZone); + + params.clear(); response.clear(); + params.insert("timeZone", "Europe/Vienna"); + response = injectAndWait("Configuration.SetTimeZone", params); + verifyConfigurationError(response); +} + +void TestConfigurations::testServerName() +{ + QVariantMap params; QVariant response; QVariantMap configurations; + configurations = injectAndWait("Configuration.GetConfigurations").toMap().value("params").toMap(); + QString serverName = configurations.value("basicConfiguration").toMap().value("serverName").toString(); + QString serverUuid = configurations.value("basicConfiguration").toMap().value("serverUuid").toString(); + qDebug() << "Server name" << serverName << "(" << serverUuid << ")"; + + params.insert("serverName", "Test server"); + response = injectAndWait("Configuration.SetServerName", params); + verifyConfigurationError(response); + + configurations = injectAndWait("Configuration.GetConfigurations").toMap().value("params").toMap(); + QString newServerName = configurations.value("basicConfiguration").toMap().value("serverName").toString(); + QVERIFY(newServerName == "Test server"); + + restartServer(); + + configurations = injectAndWait("Configuration.GetConfigurations").toMap().value("params").toMap(); + QString reloadedServerName = configurations.value("basicConfiguration").toMap().value("serverName").toString(); + QVERIFY(newServerName == reloadedServerName); } #include "testconfigurations.moc" diff --git a/tests/auto/guhtestbase.h b/tests/auto/guhtestbase.h index 47527b02..501d5c3d 100644 --- a/tests/auto/guhtestbase.h +++ b/tests/auto/guhtestbase.h @@ -145,6 +145,10 @@ protected: verifyError(response, "loggingError", JsonTypes::loggingErrorToString(error)); } + inline void verifyConfigurationError(const QVariant &response, GuhConfiguration::ConfigurationError error = GuhConfiguration::ConfigurationErrorNoError) { + verifyError(response, "configurationError", JsonTypes::configurationErrorToString(error)); + } + inline void verifyParams(const QVariantList &requestList, const QVariantList &responseList, bool allRequired = true) { if (allRequired)