From bad8d6b3b53d22ee6b406cd73dbd2e8f83352493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Thu, 10 Mar 2016 16:23:13 +0100 Subject: [PATCH] fix rest logging --- tests/auto/restlogging/testrestlogging.cpp | 40 ++++++++++++++++------ 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/tests/auto/restlogging/testrestlogging.cpp b/tests/auto/restlogging/testrestlogging.cpp index 00b66312..7bd8648c 100644 --- a/tests/auto/restlogging/testrestlogging.cpp +++ b/tests/auto/restlogging/testrestlogging.cpp @@ -174,21 +174,41 @@ void TestRestLogging::eventLogs() int port = device->paramValue("httpport").toInt(); QNetworkRequest request(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(port).arg(mockEvent1Id.toString()))); QNetworkReply *reply = nam.get(request); + clientSpy.wait(); // Lets wait for the notification - clientSpy.wait(200); - QVariant notification = checkNotification(clientSpy, "Logging.LogEntryAdded"); - QVERIFY(!notification.isNull()); + QVariantList loggEntryAddedVariants = checkNotifications(clientSpy, "Logging.LogEntryAdded"); + QVERIFY2(!loggEntryAddedVariants.isEmpty(), "Did not get Logging.LogEntryAdded notification."); + qDebug() << "got" << loggEntryAddedVariants.count() << "Logging.LogEntryAdded notifications"; reply->deleteLater(); - QVariantMap logEntry = notification.toMap().value("params").toMap().value("logEntry").toMap(); - // 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"); + + +// // 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)); // get this logentry with filter QVariantMap params;