add invalid filter tests
This commit is contained in:
parent
fe3cc8995b
commit
c59c9f4173
@ -61,6 +61,9 @@ public:
|
|||||||
LoggingEventTypeActionsExecuted,
|
LoggingEventTypeActionsExecuted,
|
||||||
LoggingEventTypeExitActionsExecuted
|
LoggingEventTypeExitActionsExecuted
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Logging(QObject *parent = 0);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,6 +23,7 @@
|
|||||||
#define GUHTESTBASE_H
|
#define GUHTESTBASE_H
|
||||||
|
|
||||||
#include "typeutils.h"
|
#include "typeutils.h"
|
||||||
|
#include "logging/logging.h"
|
||||||
#include "mocktcpserver.h"
|
#include "mocktcpserver.h"
|
||||||
#include "devicemanager.h"
|
#include "devicemanager.h"
|
||||||
#include "ruleengine.h"
|
#include "ruleengine.h"
|
||||||
|
|||||||
@ -41,6 +41,10 @@ private:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void initLogs();
|
void initLogs();
|
||||||
|
void systemLogs();
|
||||||
|
|
||||||
|
void invalidFilter_data();
|
||||||
|
void invalidFilter();
|
||||||
|
|
||||||
void eventLogs();
|
void eventLogs();
|
||||||
void actionLog();
|
void actionLog();
|
||||||
@ -62,11 +66,76 @@ void TestLogging::initLogs()
|
|||||||
|
|
||||||
response = injectAndWait("Logging.GetLogEntries");
|
response = injectAndWait("Logging.GetLogEntries");
|
||||||
verifyLoggingError(response);
|
verifyLoggingError(response);
|
||||||
|
|
||||||
logEntries = response.toMap().value("params").toMap().value("logEntries").toList();
|
logEntries = response.toMap().value("params").toMap().value("logEntries").toList();
|
||||||
QVERIFY(logEntries.count() == 0);
|
QVERIFY(logEntries.count() == 0);
|
||||||
|
|
||||||
|
restartServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestLogging::systemLogs()
|
||||||
|
{
|
||||||
|
// check the active system log at boot
|
||||||
|
QVariantMap params;
|
||||||
|
params.insert("loggingSources", QVariantList() << JsonTypes::loggingSourceToString(Logging::LoggingSourceSystem));
|
||||||
|
params.insert("eventTypes", QVariantList() << JsonTypes::loggingEventTypeToString(Logging::LoggingEventTypeActiveChange));
|
||||||
|
|
||||||
|
// there should be 2 logs, one for shutdown, one for startup (from server restart)
|
||||||
|
QVariant response = injectAndWait("Logging.GetLogEntries", params);
|
||||||
|
verifyLoggingError(response);
|
||||||
|
QVariantList logEntries = response.toMap().value("params").toMap().value("logEntries").toList();
|
||||||
|
QVERIFY(logEntries.count() == 2);
|
||||||
|
|
||||||
|
QVariantMap logEntryShutdown = logEntries.first().toMap();
|
||||||
|
|
||||||
|
QCOMPARE(logEntryShutdown.value("active").toBool(), false);
|
||||||
|
QCOMPARE(logEntryShutdown.value("eventType").toString(), JsonTypes::loggingEventTypeToString(Logging::LoggingEventTypeActiveChange));
|
||||||
|
QCOMPARE(logEntryShutdown.value("source").toString(), JsonTypes::loggingSourceToString(Logging::LoggingSourceSystem));
|
||||||
|
QCOMPARE(logEntryShutdown.value("loggingLevel").toString(), JsonTypes::loggingLevelToString(Logging::LoggingLevelInfo));
|
||||||
|
|
||||||
|
QVariantMap logEntryStartup = logEntries.last().toMap();
|
||||||
|
|
||||||
|
QCOMPARE(logEntryStartup.value("active").toBool(), true);
|
||||||
|
QCOMPARE(logEntryStartup.value("eventType").toString(), JsonTypes::loggingEventTypeToString(Logging::LoggingEventTypeActiveChange));
|
||||||
|
QCOMPARE(logEntryStartup.value("source").toString(), JsonTypes::loggingSourceToString(Logging::LoggingSourceSystem));
|
||||||
|
QCOMPARE(logEntryStartup.value("loggingLevel").toString(), JsonTypes::loggingLevelToString(Logging::LoggingLevelInfo));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestLogging::invalidFilter_data()
|
||||||
|
{
|
||||||
|
QVariantMap invalidSourcesFilter;
|
||||||
|
invalidSourcesFilter.insert("loggingSources", QVariantList() << "bla");
|
||||||
|
|
||||||
|
QVariantMap invalidFilterValue;
|
||||||
|
invalidFilterValue.insert("loggingSource", QVariantList() << "bla");
|
||||||
|
|
||||||
|
QVariantMap invalidTypeIds;
|
||||||
|
invalidTypeIds.insert("typeId", QVariantList() << "bla" << "blub");
|
||||||
|
|
||||||
|
QVariantMap invalidEventTypes;
|
||||||
|
invalidEventTypes.insert("eventTypes", QVariantList() << JsonTypes::loggingEventTypeToString(Logging::LoggingEventTypeTrigger) << "blub");
|
||||||
|
|
||||||
|
QTest::addColumn<QVariantMap>("filter");
|
||||||
|
|
||||||
|
QTest::newRow("Invalid source") << invalidSourcesFilter;
|
||||||
|
QTest::newRow("Invalid filter value") << invalidFilterValue;
|
||||||
|
QTest::newRow("Invalid typeIds") << invalidTypeIds;
|
||||||
|
QTest::newRow("Invalid eventTypes") << invalidEventTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestLogging::invalidFilter()
|
||||||
|
{
|
||||||
|
QFETCH(QVariantMap, filter);
|
||||||
|
QVariant response = injectAndWait("Logging.GetLogEntries", filter);
|
||||||
|
QVERIFY(!response.isNull());
|
||||||
|
//qDebug() << QJsonDocument::fromVariant(response).toJson();
|
||||||
|
|
||||||
|
// verify json error
|
||||||
|
QVERIFY(response.toMap().value("status").toString() == "error");
|
||||||
|
qDebug() << response.toMap().value("error").toString();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void TestLogging::eventLogs()
|
void TestLogging::eventLogs()
|
||||||
{
|
{
|
||||||
QList<Device*> devices = GuhCore::instance()->findConfiguredDevices(mockDeviceClassId);
|
QList<Device*> devices = GuhCore::instance()->findConfiguredDevices(mockDeviceClassId);
|
||||||
|
|||||||
Reference in New Issue
Block a user