added notification tests for DeviceRemoved and DeviceAdded
This commit is contained in:
parent
2aa55e469e
commit
26ac948f98
@ -49,6 +49,8 @@ private slots:
|
||||
void enableDisableNotifications();
|
||||
|
||||
void stateChangeEmitsNotifications();
|
||||
void deviceAddedRemovedNotifications();
|
||||
|
||||
|
||||
private:
|
||||
QStringList extractRefs(const QVariant &variant);
|
||||
@ -187,6 +189,7 @@ void TestJSONRPC::enableDisableNotifications()
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("enabled").toString(), enabled);
|
||||
}
|
||||
|
||||
|
||||
void TestJSONRPC::stateChangeEmitsNotifications()
|
||||
{
|
||||
QVariantMap params;
|
||||
@ -256,6 +259,76 @@ void TestJSONRPC::stateChangeEmitsNotifications()
|
||||
|
||||
}
|
||||
|
||||
void TestJSONRPC::deviceAddedRemovedNotifications()
|
||||
{
|
||||
// enable notificartions
|
||||
QVariantMap params;
|
||||
params.insert("enabled", true);
|
||||
QVariant response = injectAndWait("JSONRPC.SetNotificationStatus", params);
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("enabled").toBool(), true);
|
||||
|
||||
// Setup connection to mock client
|
||||
QSignalSpy clientSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
|
||||
|
||||
// add device and wait for notification
|
||||
QVariantList deviceParams;
|
||||
QVariantMap httpportParam;
|
||||
httpportParam.insert("name", "httpport");
|
||||
httpportParam.insert("value", 8765);
|
||||
deviceParams.append(httpportParam);
|
||||
|
||||
params.clear(); response.clear();
|
||||
params.insert("deviceClassId", mockDeviceClassId);
|
||||
params.insert("deviceParams", deviceParams);
|
||||
response = injectAndWait("Devices.AddConfiguredDevice", params);
|
||||
|
||||
// Lets wait for the notification
|
||||
clientSpy.wait(500);
|
||||
qDebug() << "got" << clientSpy.count() << "notifications";
|
||||
QCOMPARE(clientSpy.count(), 2); // wait for device added notification and response
|
||||
|
||||
QJsonDocument jsonDocResponse = QJsonDocument::fromJson(clientSpy.at(1).at(1).toByteArray());
|
||||
QJsonDocument jsonDocNotification = QJsonDocument::fromJson(clientSpy.at(0).at(1).toByteArray());
|
||||
|
||||
verifyDeviceError(jsonDocResponse.toVariant());
|
||||
DeviceId deviceId = DeviceId(jsonDocResponse.toVariant().toMap().value("params").toMap().value("deviceId").toString());
|
||||
QVERIFY(!deviceId.isNull());
|
||||
|
||||
// check the DeviceAdded notification
|
||||
QCOMPARE(jsonDocNotification.toVariant().toMap().value("notification").toString(), QString("Devices.DeviceAdded"));
|
||||
QVariantMap notificationDeviceMap = jsonDocNotification.toVariant().toMap().value("params").toMap().value("device").toMap();
|
||||
|
||||
QCOMPARE(notificationDeviceMap.value("deviceClassId").toString(), mockDeviceClassId.toString());
|
||||
QCOMPARE(notificationDeviceMap.value("id").toString(), deviceId.toString());
|
||||
foreach (const QVariant ¶m, notificationDeviceMap.value("params").toList()) {
|
||||
if (param.toMap().value("name").toString() == "httpport") {
|
||||
QCOMPARE(param.toMap().value("value").toInt(), httpportParam.value("value").toInt());
|
||||
}
|
||||
}
|
||||
|
||||
// Setup connection to mock client
|
||||
QSignalSpy clientSpy2(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
|
||||
|
||||
// now remove the device and check the device removed notification
|
||||
params.clear(); response.clear();
|
||||
params.insert("deviceId", deviceId);
|
||||
response = injectAndWait("Devices.RemoveConfiguredDevice", params);
|
||||
|
||||
clientSpy2.wait(500);
|
||||
qDebug() << "got" << clientSpy2.count() << "notifications";
|
||||
QCOMPARE(clientSpy2.count(), 2); // wait for device removed notification and response
|
||||
|
||||
jsonDocResponse = QJsonDocument::fromJson(clientSpy2.at(1).at(1).toByteArray());
|
||||
jsonDocNotification = QJsonDocument::fromJson(clientSpy2.at(0).at(1).toByteArray());
|
||||
|
||||
verifyDeviceError(jsonDocResponse.toVariant());
|
||||
|
||||
// check the DeviceRemoved notification
|
||||
QCOMPARE(jsonDocNotification.toVariant().toMap().value("notification").toString(), QString("Devices.DeviceRemoved"));
|
||||
QCOMPARE(jsonDocNotification.toVariant().toMap().value("params").toMap().value("deviceId").toString(), deviceId.toString());
|
||||
}
|
||||
|
||||
|
||||
#include "testjsonrpc.moc"
|
||||
|
||||
QTEST_MAIN(TestJSONRPC)
|
||||
|
||||
Reference in New Issue
Block a user