limit log db size for tests
This commit is contained in:
parent
c0b19c168c
commit
f954f10d0f
@ -105,6 +105,7 @@
|
|||||||
#include "loggingcategories.h"
|
#include "loggingcategories.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
#include <QSqlDatabase>
|
#include <QSqlDatabase>
|
||||||
#include <QSqlDriver>
|
#include <QSqlDriver>
|
||||||
#include <QSqlQuery>
|
#include <QSqlQuery>
|
||||||
@ -114,7 +115,6 @@
|
|||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
|
||||||
#define DB_SCHEMA_VERSION 2
|
#define DB_SCHEMA_VERSION 2
|
||||||
#define DB_MAX_SIZE 8000
|
|
||||||
|
|
||||||
namespace guhserver {
|
namespace guhserver {
|
||||||
|
|
||||||
@ -122,9 +122,14 @@ namespace guhserver {
|
|||||||
LogEngine::LogEngine(QObject *parent):
|
LogEngine::LogEngine(QObject *parent):
|
||||||
QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
m_db = QSqlDatabase::addDatabase("QSQLITE");
|
m_db = QSqlDatabase::addDatabase("QSQLITE");
|
||||||
m_db.setDatabaseName(GuhSettings::logPath());
|
m_db.setDatabaseName(GuhSettings::logPath());
|
||||||
|
m_dbMaxSize = 8000;
|
||||||
|
|
||||||
|
if (QCoreApplication::instance()->organizationName() == "guh-test") {
|
||||||
|
m_dbMaxSize = 20;
|
||||||
|
qCDebug(dcLogEngine) << "Set logging dab max size to" << m_dbMaxSize << "for testing.";
|
||||||
|
}
|
||||||
|
|
||||||
qCDebug(dcLogEngine) << "Opening logging database" << m_db.databaseName();
|
qCDebug(dcLogEngine) << "Opening logging database" << m_db.databaseName();
|
||||||
|
|
||||||
@ -297,6 +302,7 @@ void LogEngine::appendLogEntry(const LogEntry &entry)
|
|||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
if (!query.exec(queryString)) {
|
if (!query.exec(queryString)) {
|
||||||
qCWarning(dcLogEngine) << "Error writing log entry. Driver error:" << query.lastError().driverText() << "Database error:" << query.lastError().databaseText();
|
qCWarning(dcLogEngine) << "Error writing log entry. Driver error:" << query.lastError().driverText() << "Database error:" << query.lastError().databaseText();
|
||||||
|
qCWarning(dcLogEngine) << entry;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,10 +323,10 @@ void LogEngine::checkDBSize()
|
|||||||
numRows = query.at() + 1;
|
numRows = query.at() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numRows >= DB_MAX_SIZE) {
|
if (numRows >= m_dbMaxSize) {
|
||||||
// keep only the latest DB_MAX_SIZE entries
|
// keep only the latest m_dbMaxSize entries
|
||||||
qCDebug(dcLogEngine) << "Deleting oldest entries and keep only the latest" << DB_MAX_SIZE << "entries.";
|
qCDebug(dcLogEngine) << "Deleting oldest entries and keep only the latest" << m_dbMaxSize << "entries.";
|
||||||
QString queryDeleteString = QString("DELETE FROM entries WHERE ROWID IN (SELECT ROWID FROM entries ORDER BY timestamp DESC LIMIT -1 OFFSET %1);").arg(QString::number(DB_MAX_SIZE));
|
QString queryDeleteString = QString("DELETE FROM entries WHERE ROWID IN (SELECT ROWID FROM entries ORDER BY timestamp DESC LIMIT -1 OFFSET %1);").arg(QString::number(m_dbMaxSize));
|
||||||
if (!query.exec(queryDeleteString)) {
|
if (!query.exec(queryDeleteString)) {
|
||||||
qCWarning(dcLogEngine) << "Error deleting oldest log entries to keep size. Driver error:" << query.lastError().driverText() << "Database error:" << query.lastError().databaseText();
|
qCWarning(dcLogEngine) << "Error deleting oldest log entries to keep size. Driver error:" << query.lastError().driverText() << "Database error:" << query.lastError().databaseText();
|
||||||
} else {
|
} else {
|
||||||
@ -392,7 +398,7 @@ void LogEngine::initDB()
|
|||||||
qCWarning(dcLogEngine) << "Error creating log table in database. Driver error:" << query.lastError().driverText() << "Database error:" << query.lastError().databaseText();
|
qCWarning(dcLogEngine) << "Error creating log table in database. Driver error:" << query.lastError().driverText() << "Database error:" << query.lastError().databaseText();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qCDebug(dcLogEngine) << "Initialized logging DB successfully.";
|
qCDebug(dcLogEngine) << "Initialized logging DB successfully. (maximum DB size:" << m_dbMaxSize << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,6 +49,7 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QSqlDatabase m_db;
|
QSqlDatabase m_db;
|
||||||
|
int m_dbMaxSize;
|
||||||
|
|
||||||
void initDB();
|
void initDB();
|
||||||
void appendLogEntry(const LogEntry &entry);
|
void appendLogEntry(const LogEntry &entry);
|
||||||
|
|||||||
@ -76,41 +76,11 @@ Logging::LoggingLevel LogEntry::level() const
|
|||||||
return m_level;
|
return m_level;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LogEntry::levelString() const
|
|
||||||
{
|
|
||||||
switch (m_level) {
|
|
||||||
case Logging::LoggingLevelAlert:
|
|
||||||
return "LoggingLevelAlert";
|
|
||||||
case Logging::LoggingLevelInfo:
|
|
||||||
return "LoggingLevelInfo";
|
|
||||||
default:
|
|
||||||
return "< Unknown >";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Logging::LoggingSource LogEntry::source() const
|
Logging::LoggingSource LogEntry::source() const
|
||||||
{
|
{
|
||||||
return m_source;
|
return m_source;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LogEntry::sourceString() const
|
|
||||||
{
|
|
||||||
switch (m_source) {
|
|
||||||
case Logging::LoggingSourceActions:
|
|
||||||
return "LoggingSourceActions";
|
|
||||||
case Logging::LoggingSourceEvents:
|
|
||||||
return "LoggingSourceEvents";
|
|
||||||
case Logging::LoggingSourceRules:
|
|
||||||
return "LoggingSourceRules";
|
|
||||||
case Logging::LoggingSourceStates:
|
|
||||||
return "LoggingSourceStates";
|
|
||||||
case Logging::LoggingSourceSystem:
|
|
||||||
return "LoggingSourceSystem";
|
|
||||||
default:
|
|
||||||
return "< Unknown >";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QUuid LogEntry::typeId() const
|
QUuid LogEntry::typeId() const
|
||||||
{
|
{
|
||||||
return m_typeId;
|
return m_typeId;
|
||||||
@ -145,18 +115,6 @@ Logging::LoggingEventType LogEntry::eventType() const
|
|||||||
return m_eventType;
|
return m_eventType;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LogEntry::eventTypeString() const
|
|
||||||
{
|
|
||||||
switch (m_eventType) {
|
|
||||||
case Logging::LoggingEventTypeActiveChange:
|
|
||||||
return "LoggingEventTypeActiveChange";
|
|
||||||
case Logging::LoggingEventTypeTrigger:
|
|
||||||
return "LoggingEventTypeTrigger";
|
|
||||||
default:
|
|
||||||
return "< Unknown >";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LogEntry::active() const
|
bool LogEntry::active() const
|
||||||
{
|
{
|
||||||
return m_active;
|
return m_active;
|
||||||
@ -179,9 +137,9 @@ QDebug operator<<(QDebug dbg, const LogEntry &entry)
|
|||||||
dbg.nospace() << " time stamp: " << entry.timestamp().toTime_t() << endl;
|
dbg.nospace() << " time stamp: " << entry.timestamp().toTime_t() << endl;
|
||||||
dbg.nospace() << " DeviceId: " << entry.deviceId().toString() << endl;
|
dbg.nospace() << " DeviceId: " << entry.deviceId().toString() << endl;
|
||||||
dbg.nospace() << " type id: " << entry.typeId().toString() << endl;
|
dbg.nospace() << " type id: " << entry.typeId().toString() << endl;
|
||||||
dbg.nospace() << " source: " << entry.sourceString() << endl;
|
dbg.nospace() << " source: " << JsonTypes::loggingSourceToString(entry.source()) << endl;
|
||||||
dbg.nospace() << " level: " << entry.levelString() << endl;
|
dbg.nospace() << " level: " << JsonTypes::loggingLevelToString(entry.level()) << endl;
|
||||||
dbg.nospace() << " eventType: " << entry.eventTypeString() << endl;
|
dbg.nospace() << " eventType: " << JsonTypes::loggingEventTypeToString(entry.eventType()) << endl;
|
||||||
dbg.nospace() << " error code: " << entry.errorCode() << endl;
|
dbg.nospace() << " error code: " << entry.errorCode() << endl;
|
||||||
dbg.nospace() << " active: " << entry.active() << endl;
|
dbg.nospace() << " active: " << entry.active() << endl;
|
||||||
dbg.nospace() << " value: " << entry.value() << endl;
|
dbg.nospace() << " value: " << entry.value() << endl;
|
||||||
|
|||||||
@ -42,11 +42,8 @@ public:
|
|||||||
// Valid for all LoggingSources
|
// Valid for all LoggingSources
|
||||||
QDateTime timestamp() const;
|
QDateTime timestamp() const;
|
||||||
Logging::LoggingLevel level() const;
|
Logging::LoggingLevel level() const;
|
||||||
QString levelString() const;
|
|
||||||
Logging::LoggingSource source() const;
|
Logging::LoggingSource source() const;
|
||||||
QString sourceString() const;
|
|
||||||
Logging::LoggingEventType eventType() const;
|
Logging::LoggingEventType eventType() const;
|
||||||
QString eventTypeString() const;
|
|
||||||
|
|
||||||
// Valid for LoggingSourceStates, LoggingSourceEvents, LoggingSourceActions, LoggingSourceRules
|
// Valid for LoggingSourceStates, LoggingSourceEvents, LoggingSourceActions, LoggingSourceRules
|
||||||
QUuid typeId() const;
|
QUuid typeId() const;
|
||||||
|
|||||||
@ -127,12 +127,10 @@ void TestLogging::invalidFilter()
|
|||||||
QFETCH(QVariantMap, filter);
|
QFETCH(QVariantMap, filter);
|
||||||
QVariant response = injectAndWait("Logging.GetLogEntries", filter);
|
QVariant response = injectAndWait("Logging.GetLogEntries", filter);
|
||||||
QVERIFY(!response.isNull());
|
QVERIFY(!response.isNull());
|
||||||
//qDebug() << QJsonDocument::fromVariant(response).toJson();
|
|
||||||
|
|
||||||
// verify json error
|
// verify json error
|
||||||
QVERIFY(response.toMap().value("status").toString() == "error");
|
QVERIFY(response.toMap().value("status").toString() == "error");
|
||||||
qDebug() << response.toMap().value("error").toString();
|
qDebug() << response.toMap().value("error").toString();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -213,7 +211,7 @@ void TestLogging::actionLog()
|
|||||||
QVariant response = injectAndWait("Actions.ExecuteAction", params);
|
QVariant response = injectAndWait("Actions.ExecuteAction", params);
|
||||||
verifyDeviceError(response);
|
verifyDeviceError(response);
|
||||||
|
|
||||||
// Lets wait for the notification
|
// Lets wait 3for the notification
|
||||||
clientSpy.wait(200);
|
clientSpy.wait(200);
|
||||||
QVariant notification = checkNotification(clientSpy, "Logging.LogEntryAdded");
|
QVariant notification = checkNotification(clientSpy, "Logging.LogEntryAdded");
|
||||||
QVERIFY(!notification.isNull());
|
QVERIFY(!notification.isNull());
|
||||||
@ -249,7 +247,7 @@ void TestLogging::actionLog()
|
|||||||
verifyLoggingError(response);
|
verifyLoggingError(response);
|
||||||
|
|
||||||
QVariantList logEntries = response.toMap().value("params").toMap().value("logEntries").toList();
|
QVariantList logEntries = response.toMap().value("params").toMap().value("logEntries").toList();
|
||||||
QVERIFY(logEntries.count() == 1);
|
QCOMPARE(logEntries.count(), 1);
|
||||||
|
|
||||||
// EXECUTE broken action
|
// EXECUTE broken action
|
||||||
params.clear(); clientSpy.clear();
|
params.clear(); clientSpy.clear();
|
||||||
@ -283,7 +281,7 @@ void TestLogging::actionLog()
|
|||||||
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() == 1);
|
QCOMPARE(logEntries.count(), 1);
|
||||||
|
|
||||||
// check different filters
|
// check different filters
|
||||||
params.clear();
|
params.clear();
|
||||||
@ -296,7 +294,7 @@ void TestLogging::actionLog()
|
|||||||
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() == 1);
|
QCOMPARE(logEntries.count(), 1);
|
||||||
|
|
||||||
params.clear();
|
params.clear();
|
||||||
params.insert("deviceIds", QVariantList() << m_mockDeviceId);
|
params.insert("deviceIds", QVariantList() << m_mockDeviceId);
|
||||||
|
|||||||
@ -44,6 +44,7 @@ class TestRestDeviceClasses: public GuhTestBase
|
|||||||
private slots:
|
private slots:
|
||||||
void getSupportedDevices();
|
void getSupportedDevices();
|
||||||
|
|
||||||
|
|
||||||
void getActionTypes_data();
|
void getActionTypes_data();
|
||||||
void getActionTypes();
|
void getActionTypes();
|
||||||
|
|
||||||
@ -63,7 +64,8 @@ private slots:
|
|||||||
void TestRestDeviceClasses::getSupportedDevices()
|
void TestRestDeviceClasses::getSupportedDevices()
|
||||||
{
|
{
|
||||||
// Get all deviceclasses
|
// Get all deviceclasses
|
||||||
QVariant response = getAndWait(QNetworkRequest(QUrl("http://localhost:3333/api/v1/deviceclasses")));
|
QUrl url("http://localhost:3333/api/v1/deviceclasses");
|
||||||
|
QVariant response = getAndWait(QNetworkRequest(url));
|
||||||
QVariantList deviceClassesList = response.toList();
|
QVariantList deviceClassesList = response.toList();
|
||||||
QVERIFY2(deviceClassesList.count() > 0, "Not enought deviceclasses.");
|
QVERIFY2(deviceClassesList.count() > 0, "Not enought deviceclasses.");
|
||||||
|
|
||||||
@ -77,37 +79,49 @@ void TestRestDeviceClasses::getSupportedDevices()
|
|||||||
response = getAndWait(request);
|
response = getAndWait(request);
|
||||||
QVERIFY2(!response.isNull(), "Could not get device");
|
QVERIFY2(!response.isNull(), "Could not get device");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QUrlQuery query;
|
||||||
|
query.addQueryItem("vendorId", guhVendorId.toString());
|
||||||
|
url.setQuery(query);
|
||||||
|
|
||||||
|
response = getAndWait(QNetworkRequest(url));
|
||||||
|
deviceClassesList = response.toList();
|
||||||
|
QVERIFY2(deviceClassesList.count() > 0, "Not enought deviceclasses.");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestRestDeviceClasses::getActionTypes_data()
|
void TestRestDeviceClasses::getActionTypes_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<DeviceClassId>("deviceClassId");
|
QTest::addColumn<QString>("deviceClassId");
|
||||||
QTest::addColumn<ActionTypeId>("actionTypeId");
|
QTest::addColumn<QString>("actionTypeId");
|
||||||
QTest::addColumn<int>("expectedStatusCode");
|
QTest::addColumn<int>("expectedStatusCode");
|
||||||
QTest::addColumn<DeviceManager::DeviceError>("error");
|
QTest::addColumn<DeviceManager::DeviceError>("error");
|
||||||
|
|
||||||
QTest::newRow("all ActionTypes") << mockDeviceClassId << ActionTypeId() << 200 << DeviceManager::DeviceErrorNoError;
|
QTest::newRow("all ActionTypes") << mockDeviceClassId.toString() << QString() << 200 << DeviceManager::DeviceErrorNoError;
|
||||||
QTest::newRow("ActionType async") << mockDeviceClassId << mockActionIdAsync << 200 << DeviceManager::DeviceErrorNoError;
|
QTest::newRow("ActionType async") << mockDeviceClassId.toString() << mockActionIdAsync.toString() << 200 << DeviceManager::DeviceErrorNoError;
|
||||||
QTest::newRow("ActionType no params") << mockDeviceClassId << mockActionIdNoParams << 200 << DeviceManager::DeviceErrorNoError;
|
QTest::newRow("ActionType no params") << mockDeviceClassId.toString() << mockActionIdNoParams.toString() << 200 << DeviceManager::DeviceErrorNoError;
|
||||||
QTest::newRow("ActionType failing") << mockDeviceClassId << mockActionIdFailing << 200 << DeviceManager::DeviceErrorNoError;
|
QTest::newRow("ActionType failing") << mockDeviceClassId.toString() << mockActionIdFailing.toString() << 200 << DeviceManager::DeviceErrorNoError;
|
||||||
QTest::newRow("ActionType with params") << mockDeviceClassId << mockActionIdWithParams << 200 << DeviceManager::DeviceErrorNoError;
|
QTest::newRow("ActionType with params") << mockDeviceClassId.toString() << mockActionIdWithParams.toString() << 200 << DeviceManager::DeviceErrorNoError;
|
||||||
QTest::newRow("invalid DeviceClassId") << DeviceClassId::createDeviceClassId() << mockActionIdNoParams << 404 << DeviceManager::DeviceErrorDeviceClassNotFound;
|
QTest::newRow("invalid DeviceClassId") << DeviceClassId::createDeviceClassId().toString() << mockActionIdNoParams.toString() << 404 << DeviceManager::DeviceErrorDeviceClassNotFound;
|
||||||
QTest::newRow("invalid ActionTypeId") << mockDeviceClassId << ActionTypeId::createActionTypeId() << 404 << DeviceManager::DeviceErrorActionTypeNotFound;
|
QTest::newRow("invalid ActionTypeId") << mockDeviceClassId.toString() << ActionTypeId::createActionTypeId().toString() << 404 << DeviceManager::DeviceErrorActionTypeNotFound;
|
||||||
|
QTest::newRow("invalid ActionTypeId format") << mockDeviceClassId.toString() << "uuid" << 400 << DeviceManager::DeviceErrorActionTypeNotFound;
|
||||||
|
QTest::newRow("invalid DeviceClassId format") << "uuid" << "uuid" << 400 << DeviceManager::DeviceErrorDeviceClassNotFound;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestRestDeviceClasses::getActionTypes()
|
void TestRestDeviceClasses::getActionTypes()
|
||||||
{
|
{
|
||||||
QFETCH(DeviceClassId, deviceClassId);
|
QFETCH(QString, deviceClassId);
|
||||||
QFETCH(ActionTypeId, actionTypeId);
|
QFETCH(QString, actionTypeId);
|
||||||
QFETCH(int, expectedStatusCode);
|
QFETCH(int, expectedStatusCode);
|
||||||
QFETCH(DeviceManager::DeviceError, error);
|
QFETCH(DeviceManager::DeviceError, error);
|
||||||
|
|
||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
if (!actionTypeId.isNull()) {
|
if (!actionTypeId.isEmpty()) {
|
||||||
request.setUrl(QUrl(QString("http://localhost:3333/api/v1/deviceclasses/%1/actiontypes/%2").arg(deviceClassId.toString()).arg(actionTypeId.toString())));
|
request.setUrl(QUrl(QString("http://localhost:3333/api/v1/deviceclasses/%1/actiontypes/%2").arg(deviceClassId).arg(actionTypeId)));
|
||||||
} else {
|
} else {
|
||||||
// Get all actiontypes
|
// Get all actiontypes
|
||||||
request.setUrl(QUrl(QString("http://localhost:3333/api/v1/deviceclasses/%1/actiontypes").arg(deviceClassId.toString())));
|
request.setUrl(QUrl(QString("http://localhost:3333/api/v1/deviceclasses/%1/actiontypes").arg(deviceClassId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant response = getAndWait(request, expectedStatusCode);
|
QVariant response = getAndWait(request, expectedStatusCode);
|
||||||
@ -119,31 +133,33 @@ void TestRestDeviceClasses::getActionTypes()
|
|||||||
|
|
||||||
void TestRestDeviceClasses::getStateTypes_data()
|
void TestRestDeviceClasses::getStateTypes_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<DeviceClassId>("deviceClassId");
|
QTest::addColumn<QString>("deviceClassId");
|
||||||
QTest::addColumn<StateTypeId>("stateTypeId");
|
QTest::addColumn<QString>("stateTypeId");
|
||||||
QTest::addColumn<int>("expectedStatusCode");
|
QTest::addColumn<int>("expectedStatusCode");
|
||||||
QTest::addColumn<DeviceManager::DeviceError>("error");
|
QTest::addColumn<DeviceManager::DeviceError>("error");
|
||||||
|
|
||||||
QTest::newRow("all ActionTypes") << mockDeviceClassId << StateTypeId() << 200 << DeviceManager::DeviceErrorNoError;
|
QTest::newRow("all ActionTypes") << mockDeviceClassId.toString() << QString() << 200 << DeviceManager::DeviceErrorNoError;
|
||||||
QTest::newRow("StateType bool") << mockDeviceClassId << mockBoolStateId << 200 << DeviceManager::DeviceErrorNoError;
|
QTest::newRow("StateType bool") << mockDeviceClassId.toString() << mockBoolStateId.toString() << 200 << DeviceManager::DeviceErrorNoError;
|
||||||
QTest::newRow("StateType int") << mockDeviceClassId << mockIntStateId << 200 << DeviceManager::DeviceErrorNoError;
|
QTest::newRow("StateType int") << mockDeviceClassId.toString() << mockIntStateId.toString() << 200 << DeviceManager::DeviceErrorNoError;
|
||||||
QTest::newRow("invalid DeviceClassId") << DeviceClassId::createDeviceClassId() << mockBoolStateId << 404 << DeviceManager::DeviceErrorDeviceClassNotFound;
|
QTest::newRow("invalid DeviceClassId") << DeviceClassId::createDeviceClassId().toString() << mockBoolStateId.toString() << 404 << DeviceManager::DeviceErrorDeviceClassNotFound;
|
||||||
QTest::newRow("invalid StateTypeId") << mockDeviceClassId << StateTypeId::createStateTypeId() << 404 << DeviceManager::DeviceErrorStateTypeNotFound;
|
QTest::newRow("invalid StateTypeId") << mockDeviceClassId.toString() << StateTypeId::createStateTypeId().toString() << 404 << DeviceManager::DeviceErrorStateTypeNotFound;
|
||||||
|
QTest::newRow("invalid StateTypeId format") << mockDeviceClassId.toString() << "uuid" << 400 << DeviceManager::DeviceErrorStateTypeNotFound;
|
||||||
|
QTest::newRow("invalid DeviceClassId format") << "uuid" << "uuid" << 400 << DeviceManager::DeviceErrorDeviceClassNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestRestDeviceClasses::getStateTypes()
|
void TestRestDeviceClasses::getStateTypes()
|
||||||
{
|
{
|
||||||
QFETCH(DeviceClassId, deviceClassId);
|
QFETCH(QString, deviceClassId);
|
||||||
QFETCH(StateTypeId, stateTypeId);
|
QFETCH(QString, stateTypeId);
|
||||||
QFETCH(int, expectedStatusCode);
|
QFETCH(int, expectedStatusCode);
|
||||||
QFETCH(DeviceManager::DeviceError, error);
|
QFETCH(DeviceManager::DeviceError, error);
|
||||||
|
|
||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
if (!stateTypeId.isNull()) {
|
if (!stateTypeId.isEmpty()) {
|
||||||
request.setUrl(QUrl(QString("http://localhost:3333/api/v1/deviceclasses/%1/statetypes/%2").arg(deviceClassId.toString()).arg(stateTypeId.toString())));
|
request.setUrl(QUrl(QString("http://localhost:3333/api/v1/deviceclasses/%1/statetypes/%2").arg(deviceClassId).arg(stateTypeId)));
|
||||||
} else {
|
} else {
|
||||||
// Get all actiontypes
|
// Get all actiontypes
|
||||||
request.setUrl(QUrl(QString("http://localhost:3333/api/v1/deviceclasses/%1/statetypes").arg(deviceClassId.toString())));
|
request.setUrl(QUrl(QString("http://localhost:3333/api/v1/deviceclasses/%1/statetypes").arg(deviceClassId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant response = getAndWait(request, expectedStatusCode);
|
QVariant response = getAndWait(request, expectedStatusCode);
|
||||||
@ -155,31 +171,33 @@ void TestRestDeviceClasses::getStateTypes()
|
|||||||
|
|
||||||
void TestRestDeviceClasses::getEventTypes_data()
|
void TestRestDeviceClasses::getEventTypes_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<DeviceClassId>("deviceClassId");
|
QTest::addColumn<QString>("deviceClassId");
|
||||||
QTest::addColumn<EventTypeId>("eventTypeId");
|
QTest::addColumn<QString>("eventTypeId");
|
||||||
QTest::addColumn<int>("expectedStatusCode");
|
QTest::addColumn<int>("expectedStatusCode");
|
||||||
QTest::addColumn<DeviceManager::DeviceError>("error");
|
QTest::addColumn<DeviceManager::DeviceError>("error");
|
||||||
|
|
||||||
QTest::newRow("all ActionTypes") << mockDeviceClassId << EventTypeId() << 200 << DeviceManager::DeviceErrorNoError;
|
QTest::newRow("all ActionTypes") << mockDeviceClassId.toString() << QString() << 200 << DeviceManager::DeviceErrorNoError;
|
||||||
QTest::newRow("EventType 1") << mockDeviceClassId << mockEvent1Id << 200 << DeviceManager::DeviceErrorNoError;
|
QTest::newRow("EventType 1") << mockDeviceClassId.toString() << mockEvent1Id.toString() << 200 << DeviceManager::DeviceErrorNoError;
|
||||||
QTest::newRow("EventType 2") << mockDeviceClassId << mockEvent2Id << 200 << DeviceManager::DeviceErrorNoError;
|
QTest::newRow("EventType 2") << mockDeviceClassId.toString() << mockEvent2Id.toString() << 200 << DeviceManager::DeviceErrorNoError;
|
||||||
QTest::newRow("invalid DeviceClassId") << DeviceClassId::createDeviceClassId() << mockEvent2Id << 404 << DeviceManager::DeviceErrorDeviceClassNotFound;
|
QTest::newRow("invalid DeviceClassId") << DeviceClassId::createDeviceClassId().toString() << mockEvent2Id.toString() << 404 << DeviceManager::DeviceErrorDeviceClassNotFound;
|
||||||
QTest::newRow("invalid EventTypeId") << mockDeviceClassId << EventTypeId::createEventTypeId() << 404 << DeviceManager::DeviceErrorEventTypeNotFound;
|
QTest::newRow("invalid EventTypeId") << mockDeviceClassId.toString() << EventTypeId::createEventTypeId().toString() << 404 << DeviceManager::DeviceErrorEventTypeNotFound;
|
||||||
|
QTest::newRow("invalid EventTypeId format") << mockDeviceClassId.toString() << "uuid" << 400 << DeviceManager::DeviceErrorEventTypeNotFound;
|
||||||
|
QTest::newRow("invalid DeviceClassId format") << "uuid" << "uuid" << 400 << DeviceManager::DeviceErrorDeviceClassNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestRestDeviceClasses::getEventTypes()
|
void TestRestDeviceClasses::getEventTypes()
|
||||||
{
|
{
|
||||||
QFETCH(DeviceClassId, deviceClassId);
|
QFETCH(QString, deviceClassId);
|
||||||
QFETCH(EventTypeId, eventTypeId);
|
QFETCH(QString, eventTypeId);
|
||||||
QFETCH(int, expectedStatusCode);
|
QFETCH(int, expectedStatusCode);
|
||||||
QFETCH(DeviceManager::DeviceError, error);
|
QFETCH(DeviceManager::DeviceError, error);
|
||||||
|
|
||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
if (!eventTypeId.isNull()) {
|
if (!eventTypeId.isNull()) {
|
||||||
request.setUrl(QUrl(QString("http://localhost:3333/api/v1/deviceclasses/%1/eventtypes/%2").arg(deviceClassId.toString()).arg(eventTypeId.toString())));
|
request.setUrl(QUrl(QString("http://localhost:3333/api/v1/deviceclasses/%1/eventtypes/%2").arg(deviceClassId).arg(eventTypeId)));
|
||||||
} else {
|
} else {
|
||||||
// Get all actiontypes
|
// Get all actiontypes
|
||||||
request.setUrl(QUrl(QString("http://localhost:3333/api/v1/deviceclasses/%1/eventtypes").arg(deviceClassId.toString())));
|
request.setUrl(QUrl(QString("http://localhost:3333/api/v1/deviceclasses/%1/eventtypes").arg(deviceClassId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant response = getAndWait(request, expectedStatusCode);
|
QVariant response = getAndWait(request, expectedStatusCode);
|
||||||
@ -197,15 +215,24 @@ void TestRestDeviceClasses::discoverDevices_data()
|
|||||||
QTest::addColumn<int>("expectedStatusCode");
|
QTest::addColumn<int>("expectedStatusCode");
|
||||||
QTest::addColumn<DeviceManager::DeviceError>("error");
|
QTest::addColumn<DeviceManager::DeviceError>("error");
|
||||||
|
|
||||||
QVariantList discoveryParams;
|
|
||||||
QVariantMap resultCountParam;
|
QVariantMap resultCountParam;
|
||||||
resultCountParam.insert("name", "resultCount");
|
resultCountParam.insert("name", "resultCount");
|
||||||
resultCountParam.insert("value", 1);
|
resultCountParam.insert("value", 1);
|
||||||
|
|
||||||
|
QVariantMap invalidResultCountParam;
|
||||||
|
invalidResultCountParam.insert("name", "resultCount");
|
||||||
|
invalidResultCountParam.insert("value", 10);
|
||||||
|
|
||||||
|
QVariantList discoveryParams;
|
||||||
discoveryParams.append(resultCountParam);
|
discoveryParams.append(resultCountParam);
|
||||||
|
|
||||||
|
QVariantList invalidDiscoveryParams;
|
||||||
|
invalidDiscoveryParams.append(invalidResultCountParam);
|
||||||
|
|
||||||
QTest::newRow("valid deviceClassId without params") << mockDeviceClassId << 2 << QVariantList() << 200 << DeviceManager::DeviceErrorNoError;
|
QTest::newRow("valid deviceClassId without params") << mockDeviceClassId << 2 << QVariantList() << 200 << DeviceManager::DeviceErrorNoError;
|
||||||
QTest::newRow("valid deviceClassId with params") << mockDeviceClassId << 1 << discoveryParams << 200 << DeviceManager::DeviceErrorNoError;
|
QTest::newRow("valid deviceClassId with params") << mockDeviceClassId << 1 << discoveryParams << 200 << DeviceManager::DeviceErrorNoError;
|
||||||
QTest::newRow("invalid deviceClassId") << DeviceClassId::createDeviceClassId() << 0 << QVariantList() << 404 << DeviceManager::DeviceErrorDeviceClassNotFound;
|
QTest::newRow("invalid deviceClassId") << DeviceClassId::createDeviceClassId() << 0 << QVariantList() << 404 << DeviceManager::DeviceErrorDeviceClassNotFound;
|
||||||
|
QTest::newRow("valid deviceClassId with invalid params") << mockDeviceClassId << 10 << invalidDiscoveryParams << 500 << DeviceManager::DeviceErrorInvalidParameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestRestDeviceClasses::discoverDevices()
|
void TestRestDeviceClasses::discoverDevices()
|
||||||
|
|||||||
@ -54,6 +54,7 @@ private:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void getRules();
|
void getRules();
|
||||||
|
void findRule();
|
||||||
void invalidMethod();
|
void invalidMethod();
|
||||||
void invalidPath();
|
void invalidPath();
|
||||||
|
|
||||||
@ -209,6 +210,37 @@ void TestRestRules::getRules()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestRestRules::findRule()
|
||||||
|
{
|
||||||
|
QVariant params = validIntStateBasedRule("Find", true, true);
|
||||||
|
QNetworkRequest request(QUrl(QString("http://localhost:3333/api/v1/rules")));
|
||||||
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "text/json");
|
||||||
|
QVariant response = postAndWait(request, params);
|
||||||
|
|
||||||
|
RuleId ruleId = RuleId(response.toMap().value("id").toString());
|
||||||
|
QVERIFY(!ruleId.isNull());
|
||||||
|
|
||||||
|
QUrl url(QString("http://localhost:3333/api/v1/rules/%1").arg(ruleId.toString()));
|
||||||
|
QUrlQuery query;
|
||||||
|
query.addQueryItem("deviceId", m_mockDeviceId.toString());
|
||||||
|
url.setQuery(query);
|
||||||
|
request.setUrl(QUrl(url));
|
||||||
|
response = getAndWait(request);
|
||||||
|
QVERIFY(!response.isNull());
|
||||||
|
|
||||||
|
// REMOVE rule
|
||||||
|
request.setUrl(QUrl(QString("http://localhost:3333/api/v1/rules/%1").arg(ruleId.toString())));
|
||||||
|
response = deleteAndWait(request);
|
||||||
|
QVERIFY(!response.isNull());
|
||||||
|
QCOMPARE(JsonTypes::ruleErrorToString(RuleEngine::RuleErrorNoError), response.toMap().value("error").toString());
|
||||||
|
|
||||||
|
// check if removed
|
||||||
|
request.setUrl(QUrl(QString("http://localhost:3333/api/v1/rules/%1").arg(ruleId.toString())));
|
||||||
|
response = getAndWait(request, 404);
|
||||||
|
QVERIFY(!response.isNull());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void TestRestRules::invalidMethod()
|
void TestRestRules::invalidMethod()
|
||||||
{
|
{
|
||||||
QNetworkAccessManager nam;
|
QNetworkAccessManager nam;
|
||||||
|
|||||||
Reference in New Issue
Block a user