From ed4794f43aebf6b61f3abbd4d2b504c361569fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Fri, 4 Mar 2016 12:25:17 +0100 Subject: [PATCH] fix logging tests --- .../awattar/devicepluginawattar.cpp | 2 +- tests/auto/jsonrpc/testjsonrpc.cpp | 7 +- tests/auto/logging/testlogging.cpp | 100 ++++++++++++------ 3 files changed, 71 insertions(+), 38 deletions(-) diff --git a/plugins/deviceplugins/awattar/devicepluginawattar.cpp b/plugins/deviceplugins/awattar/devicepluginawattar.cpp index 52a78315..f0708a1a 100644 --- a/plugins/deviceplugins/awattar/devicepluginawattar.cpp +++ b/plugins/deviceplugins/awattar/devicepluginawattar.cpp @@ -377,7 +377,7 @@ void DevicePluginAwattar::processPumpSearchData(const QByteArray &data) } } -QNetworkReply *DevicePluginAwattar:: requestPriceData(const QString &token) +QNetworkReply *DevicePluginAwattar::requestPriceData(const QString &token) { QByteArray data = QString(token + ":").toUtf8().toBase64(); QString header = "Basic " + data; diff --git a/tests/auto/jsonrpc/testjsonrpc.cpp b/tests/auto/jsonrpc/testjsonrpc.cpp index 6e8c888d..37f14ca2 100644 --- a/tests/auto/jsonrpc/testjsonrpc.cpp +++ b/tests/auto/jsonrpc/testjsonrpc.cpp @@ -511,7 +511,6 @@ void TestJSONRPC::stateChangeEmitsNotifications() // Make sure the notification contains all the stuff we expect QVariantList stateChangedVariants = checkNotifications(clientSpy, "Devices.StateChanged"); QVERIFY2(!stateChangedVariants.isEmpty(), "Did not get Devices.StateChanged notification."); - qDebug() << "got" << stateChangedVariants.count() << "Devices.StateChanged notifications"; foreach (const QVariant &stateChangedVariant, stateChangedVariants) { if (stateChangedVariant.toMap().value("params").toMap().value("stateTypeId").toUuid() == stateTypeId) { @@ -525,15 +524,13 @@ void TestJSONRPC::stateChangeEmitsNotifications() QVERIFY2(found, "Could not find the correct Devices.StateChanged notification"); + // Make sure the logg notification contains all the stuff we expect QVariantList loggEntryAddedVariants = checkNotifications(clientSpy, "Logging.LogEntryAdded"); QVERIFY2(!loggEntryAddedVariants.isEmpty(), "Did not get Logging.LogEntryAdded notification."); qDebug() << "got" << loggEntryAddedVariants.count() << "Logging.LogEntryAdded notifications"; - found = false; - qDebug() << "got" << loggEntryAddedVariants.count() << "Logging.LogEntryAdded"; foreach (const QVariant &loggEntryAddedVariant, loggEntryAddedVariants) { - qDebug() << QJsonDocument::fromVariant(loggEntryAddedVariant).toJson(); if (loggEntryAddedVariant.toMap().value("params").toMap().value("logEntry").toMap().value("typeId").toUuid() == stateTypeId) { found = true; QCOMPARE(loggEntryAddedVariant.toMap().value("params").toMap().value("logEntry").toMap().value("source").toString(), QString("LoggingSourceStates")); @@ -550,11 +547,9 @@ void TestJSONRPC::stateChangeEmitsNotifications() // Make sure the notification contains all the stuff we expect QVariantList eventTriggeredVariants = checkNotifications(clientSpy, "Events.EventTriggered"); QVERIFY2(!eventTriggeredVariants.isEmpty(), "Did not get Events.EventTriggered notification."); - found = false; qDebug() << "got" << eventTriggeredVariants.count() << "Events.EventTriggered notifications"; foreach (const QVariant &eventTriggeredVariant, eventTriggeredVariants) { - qDebug() << QJsonDocument::fromVariant(eventTriggeredVariant).toJson(); if (eventTriggeredVariant.toMap().value("params").toMap().value("event").toMap().value("eventTypeId").toUuid() == stateTypeId) { found = true; QCOMPARE(eventTriggeredVariant.toMap().value("params").toMap().value("event").toMap().value("params").toList().first().toMap().value("value").toInt(), newVal); diff --git a/tests/auto/logging/testlogging.cpp b/tests/auto/logging/testlogging.cpp index d0a6e0db..1a312e8e 100644 --- a/tests/auto/logging/testlogging.cpp +++ b/tests/auto/logging/testlogging.cpp @@ -154,19 +154,32 @@ void TestLogging::eventLogs() QNetworkReply *reply = nam.get(request); // Lets wait for the notification - clientSpy.wait(200); - QVariant notification = checkNotification(clientSpy, "Logging.LogEntryAdded"); - QVERIFY(!notification.isNull()); + clientSpy.wait(1000); reply->deleteLater(); - QVariantMap logEntry = notification.toMap().value("params").toMap().value("logEntry").toMap(); + // Make sure the logg notification contains all the stuff we expect + QVariantList loggEntryAddedVariants = checkNotifications(clientSpy, "Logging.LogEntryAdded"); + QVERIFY2(!loggEntryAddedVariants.isEmpty(), "Did not get Logging.LogEntryAdded notification."); + qDebug() << "got" << loggEntryAddedVariants.count() << "Logging.LogEntryAdded notifications"; - // Make sure the notification contains all the stuff we expect - QCOMPARE(logEntry.value("typeId").toString(), mockEvent1Id.toString()); - QCOMPARE(logEntry.value("deviceId").toString(), device->id().toString()); - QCOMPARE(logEntry.value("eventType").toString(), JsonTypes::loggingEventTypeToString(Logging::LoggingEventTypeTrigger)); - QCOMPARE(logEntry.value("source").toString(), JsonTypes::loggingSourceToString(Logging::LoggingSourceEvents)); - QCOMPARE(logEntry.value("loggingLevel").toString(), JsonTypes::loggingLevelToString(Logging::LoggingLevelInfo)); + bool found = false; + qDebug() << "got" << loggEntryAddedVariants.count() << "Logging.LogEntryAdded"; + foreach (const QVariant &loggEntryAddedVariant, loggEntryAddedVariants) { + QVariantMap logEntry = loggEntryAddedVariant.toMap().value("params").toMap().value("logEntry").toMap(); + if (logEntry.value("deviceId").toString() == device->id().toString()) { + found = true; + // Make sure the notification contains all the stuff we expect + QCOMPARE(logEntry.value("typeId").toString(), mockEvent1Id.toString()); + QCOMPARE(logEntry.value("eventType").toString(), JsonTypes::loggingEventTypeToString(Logging::LoggingEventTypeTrigger)); + QCOMPARE(logEntry.value("source").toString(), JsonTypes::loggingSourceToString(Logging::LoggingSourceEvents)); + QCOMPARE(logEntry.value("loggingLevel").toString(), JsonTypes::loggingLevelToString(Logging::LoggingLevelInfo)); + break; + } + } + if (!found) + qDebug() << QJsonDocument::fromVariant(loggEntryAddedVariants).toJson(); + + QVERIFY2(found, "Could not find the corresponding Logging.LogEntryAdded notification"); // get this logentry with filter QVariantMap params; @@ -211,19 +224,31 @@ void TestLogging::actionLog() QVariant response = injectAndWait("Actions.ExecuteAction", params); verifyDeviceError(response); - // Lets wait 3for the notification + // Lets wait for the notification clientSpy.wait(200); - QVariant notification = checkNotification(clientSpy, "Logging.LogEntryAdded"); - QVERIFY(!notification.isNull()); - QVariantMap logEntry = notification.toMap().value("params").toMap().value("logEntry").toMap(); + QVariantList loggEntryAddedVariants = checkNotifications(clientSpy, "Logging.LogEntryAdded"); + QVERIFY2(!loggEntryAddedVariants.isEmpty(), "Did not get Logging.LogEntryAdded notification."); + qDebug() << "got" << loggEntryAddedVariants.count() << "Logging.LogEntryAdded notifications"; - // Make sure the notification contains all the stuff we expect - QCOMPARE(logEntry.value("typeId").toString(), mockActionIdWithParams.toString()); - QCOMPARE(logEntry.value("deviceId").toString(), m_mockDeviceId.toString()); - QCOMPARE(logEntry.value("eventType").toString(), JsonTypes::loggingEventTypeToString(Logging::LoggingEventTypeTrigger)); - QCOMPARE(logEntry.value("source").toString(), JsonTypes::loggingSourceToString(Logging::LoggingSourceActions)); - QCOMPARE(logEntry.value("loggingLevel").toString(), JsonTypes::loggingLevelToString(Logging::LoggingLevelInfo)); + bool found = false; + qDebug() << "got" << loggEntryAddedVariants.count() << "Logging.LogEntryAdded"; + foreach (const QVariant &loggEntryAddedVariant, loggEntryAddedVariants) { + QVariantMap logEntry = loggEntryAddedVariant.toMap().value("params").toMap().value("logEntry").toMap(); + if (logEntry.value("deviceId").toString() == m_mockDeviceId.toString()) { + found = true; + // Make sure the notification contains all the stuff we expect + QCOMPARE(logEntry.value("typeId").toString(), mockActionIdWithParams.toString()); + QCOMPARE(logEntry.value("eventType").toString(), JsonTypes::loggingEventTypeToString(Logging::LoggingEventTypeTrigger)); + QCOMPARE(logEntry.value("source").toString(), JsonTypes::loggingSourceToString(Logging::LoggingSourceActions)); + QCOMPARE(logEntry.value("loggingLevel").toString(), JsonTypes::loggingLevelToString(Logging::LoggingLevelInfo)); + break; + } + } + if (!found) + qDebug() << QJsonDocument::fromVariant(loggEntryAddedVariants).toJson(); + + QVERIFY2(found, "Could not find the corresponding Logging.LogEntryAdded notification"); // EXECUTE without params params.clear(); clientSpy.clear(); @@ -233,7 +258,8 @@ void TestLogging::actionLog() verifyDeviceError(response); clientSpy.wait(200); - notification = checkNotification(clientSpy, "Logging.LogEntryAdded"); + + QVariant notification = checkNotification(clientSpy, "Logging.LogEntryAdded"); QVERIFY(!notification.isNull()); // get this logentry with filter @@ -257,18 +283,30 @@ void TestLogging::actionLog() verifyDeviceError(response, DeviceManager::DeviceErrorSetupFailed); clientSpy.wait(200); - notification = checkNotification(clientSpy, "Logging.LogEntryAdded"); - QVERIFY(!notification.isNull()); - logEntry = notification.toMap().value("params").toMap().value("logEntry").toMap(); + loggEntryAddedVariants = checkNotifications(clientSpy, "Logging.LogEntryAdded"); + QVERIFY2(!loggEntryAddedVariants.isEmpty(), "Did not get Logging.LogEntryAdded notification."); + qDebug() << "got" << loggEntryAddedVariants.count() << "Logging.LogEntryAdded notifications"; - // Make sure the notification contains all the stuff we expect - QCOMPARE(logEntry.value("typeId").toString(), mockActionIdFailing.toString()); - QCOMPARE(logEntry.value("deviceId").toString(), m_mockDeviceId.toString()); - QCOMPARE(logEntry.value("eventType").toString(), JsonTypes::loggingEventTypeToString(Logging::LoggingEventTypeTrigger)); - QCOMPARE(logEntry.value("source").toString(), JsonTypes::loggingSourceToString(Logging::LoggingSourceActions)); - QCOMPARE(logEntry.value("loggingLevel").toString(), JsonTypes::loggingLevelToString(Logging::LoggingLevelAlert)); - QCOMPARE(logEntry.value("errorCode").toString(), JsonTypes::deviceErrorToString(DeviceManager::DeviceErrorSetupFailed)); + found = false; + qDebug() << "got" << loggEntryAddedVariants.count() << "Logging.LogEntryAdded"; + foreach (const QVariant &loggEntryAddedVariant, loggEntryAddedVariants) { + QVariantMap logEntry = loggEntryAddedVariant.toMap().value("params").toMap().value("logEntry").toMap(); + if (logEntry.value("deviceId").toString() == m_mockDeviceId.toString()) { + found = true; + // Make sure the notification contains all the stuff we expect + QCOMPARE(logEntry.value("typeId").toString(), mockActionIdFailing.toString()); + QCOMPARE(logEntry.value("eventType").toString(), JsonTypes::loggingEventTypeToString(Logging::LoggingEventTypeTrigger)); + QCOMPARE(logEntry.value("source").toString(), JsonTypes::loggingSourceToString(Logging::LoggingSourceActions)); + QCOMPARE(logEntry.value("loggingLevel").toString(), JsonTypes::loggingLevelToString(Logging::LoggingLevelAlert)); + QCOMPARE(logEntry.value("errorCode").toString(), JsonTypes::deviceErrorToString(DeviceManager::DeviceErrorSetupFailed)); + break; + } + } + if (!found) + qDebug() << QJsonDocument::fromVariant(loggEntryAddedVariants).toJson(); + + QVERIFY2(found, "Could not find the corresponding Logging.LogEntryAdded notification"); // get this logentry with filter params.clear();