mirror of https://github.com/nymea/nymea.git
fixed enable disable notification tests
parent
44bdfbcb13
commit
b67bd44722
|
|
@ -357,6 +357,8 @@ void DevicePlugin::deviceRemoved(Device *device)
|
|||
Q_UNUSED(device)
|
||||
}
|
||||
|
||||
/*! This method will be called for \l{Device}{Devices} with the \l{DeviceClass::SetupMethodDisplayPin} right after the paring request
|
||||
* with the given \a pairingTransactionId for the given \a deviceDescriptor.*/
|
||||
DeviceManager::DeviceError DevicePlugin::displayPin(const PairingTransactionId &pairingTransactionId, const DeviceDescriptor &deviceDescriptor)
|
||||
{
|
||||
Q_UNUSED(pairingTransactionId)
|
||||
|
|
@ -368,7 +370,8 @@ DeviceManager::DeviceError DevicePlugin::displayPin(const PairingTransactionId &
|
|||
}
|
||||
|
||||
/*! Confirms the pairing of a \a deviceClassId with the given \a pairingTransactionId and \a params.
|
||||
* Returns \l{DeviceManager::DeviceError}{DeviceError} to inform about the result. */
|
||||
* Returns \l{DeviceManager::DeviceError}{DeviceError} to inform about the result. The optional paramerter
|
||||
* \a secret contains for example the pin for \l{Device}{Devices} with the setup method \l{DeviceClass::SetupMethodDisplayPin}.*/
|
||||
DeviceManager::DeviceSetupStatus DevicePlugin::confirmPairing(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const ParamList ¶ms, const QString &secret = QString())
|
||||
{
|
||||
Q_UNUSED(pairingTransactionId)
|
||||
|
|
|
|||
|
|
@ -92,6 +92,10 @@
|
|||
This signal is emitted when a \a rule was added to the system.
|
||||
*/
|
||||
|
||||
/*! \fn void GuhCore::ruleConfigurationChanged(const Rule &rule);
|
||||
This signal is emitted when the configuration of \a rule changed.
|
||||
*/
|
||||
|
||||
/*! \fn void ruleActiveChanged(const Rule &rule);
|
||||
This signal is emitted when a \a rule changed the active state.
|
||||
A \l{Rule} is active, when all \l{State}{States} match with the \l{StateDescriptor} conditions.
|
||||
|
|
@ -311,34 +315,36 @@ DeviceManager::DeviceError GuhCore::editDevice(const DeviceId &deviceId, const D
|
|||
return m_deviceManager->editDevice(deviceId, deviceDescriptorId);
|
||||
}
|
||||
|
||||
/*! Calls the metheod RuleEngine::rule().
|
||||
* \sa RuleEngine, */
|
||||
/*! Calls the metheod RuleEngine::rules().
|
||||
* \sa RuleEngine::rules(), */
|
||||
QList<Rule> GuhCore::rules() const
|
||||
{
|
||||
return m_ruleEngine->rules();
|
||||
}
|
||||
|
||||
/*! Calls the metheod RuleEngine::ruleIds().
|
||||
* \sa RuleEngine, */
|
||||
* \sa RuleEngine::ruleIds(), */
|
||||
QList<RuleId> GuhCore::ruleIds() const
|
||||
{
|
||||
return m_ruleEngine->ruleIds();
|
||||
}
|
||||
|
||||
/*! Calls the metheod RuleEngine::findRule(\a ruleId).
|
||||
* \sa RuleEngine, */
|
||||
* \sa RuleEngine::findRule(), */
|
||||
Rule GuhCore::findRule(const RuleId &ruleId)
|
||||
{
|
||||
return m_ruleEngine->findRule(ruleId);
|
||||
}
|
||||
|
||||
/*! Calls the metheod RuleEngine::addRule(\a id, \a name, \a eventDescriptorList, \a stateEvaluator \a actionList, \a exitActionList, \a enabled).
|
||||
* \sa RuleEngine, */
|
||||
* \sa RuleEngine::addRule(), */
|
||||
RuleEngine::RuleError GuhCore::addRule(const RuleId &id, const QString &name, const QList<EventDescriptor> &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList<RuleAction> &actionList, const QList<RuleAction> &exitActionList, bool enabled)
|
||||
{
|
||||
return m_ruleEngine->addRule(id, name, eventDescriptorList, stateEvaluator, actionList, exitActionList, enabled);
|
||||
}
|
||||
|
||||
/*! Calls the metheod RuleEngine::editRule(\a id, \a name, \a eventDescriptorList, \a stateEvaluator \a actionList, \a exitActionList, \a enabled).
|
||||
* \sa RuleEngine::editRule(), */
|
||||
RuleEngine::RuleError GuhCore::editRule(const RuleId &id, const QString &name, const QList<EventDescriptor> &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList<RuleAction> &actionList, const QList<RuleAction> &exitActionList, bool enabled)
|
||||
{
|
||||
return m_ruleEngine->editRule(id, name, eventDescriptorList, stateEvaluator, actionList, exitActionList, enabled);
|
||||
|
|
@ -358,11 +364,15 @@ QList<RuleId> GuhCore::findRules(const DeviceId &deviceId)
|
|||
return m_ruleEngine->findRules(deviceId);
|
||||
}
|
||||
|
||||
/*! Calls the metheod RuleEngine::enableRule(\a ruleId).
|
||||
* \sa RuleEngine::enableRule(), */
|
||||
RuleEngine::RuleError GuhCore::enableRule(const RuleId &ruleId)
|
||||
{
|
||||
return m_ruleEngine->enableRule(ruleId);
|
||||
}
|
||||
|
||||
/*! Calls the metheod RuleEngine::disableRule(\a ruleId).
|
||||
* \sa RuleEngine::disableRule(), */
|
||||
RuleEngine::RuleError GuhCore::disableRule(const RuleId &ruleId)
|
||||
{
|
||||
return m_ruleEngine->disableRule(ruleId);
|
||||
|
|
|
|||
|
|
@ -42,9 +42,9 @@
|
|||
\a ruleId holds the id of the removed rule. You should remove any references
|
||||
or copies you hold for this rule.*/
|
||||
|
||||
/*! \fn void RuleEngine::ruleConfigurationChanged(const RuleId &ruleId)
|
||||
/*! \fn void RuleEngine::ruleConfigurationChanged(const Rule &rule)
|
||||
Will be emitted whenever a \l{Rule} changed his enable/disable status.
|
||||
\a ruleId holds the id of the changed rule.*/
|
||||
The parameter \a rule holds the changed rule.*/
|
||||
|
||||
/*! \enum RuleEngine::RuleError
|
||||
\value RuleErrorNoError
|
||||
|
|
@ -348,13 +348,17 @@ RuleEngine::RuleError RuleEngine::addRule(const RuleId &ruleId, const QString &n
|
|||
return RuleErrorNoError;
|
||||
}
|
||||
|
||||
/*! Edit a \l{Rule} with the given \a ruleId, \a name, \a eventDescriptorList, \a stateEvaluator, the list of \a actions the list of \a exitActions and the \a enabled in the engine. */
|
||||
RuleEngine::RuleError RuleEngine::editRule(const RuleId &ruleId, const QString &name, const QList<EventDescriptor> &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList<RuleAction> &actions, const QList<RuleAction> &exitActions, bool enabled)
|
||||
{
|
||||
if (ruleId.isNull()) {
|
||||
return RuleErrorInvalidRuleId;
|
||||
}
|
||||
|
||||
if (findRule(ruleId).id().isNull()) {
|
||||
// store rule in case the add new rule fails
|
||||
Rule rule = findRule(ruleId);
|
||||
|
||||
if (rule.id().isNull()) {
|
||||
qCWarning(dcRuleEngine) << "Cannot edit rule. There is no rule with id:" << ruleId.toString();
|
||||
return RuleErrorRuleNotFound;
|
||||
}
|
||||
|
|
@ -362,12 +366,15 @@ RuleEngine::RuleError RuleEngine::editRule(const RuleId &ruleId, const QString &
|
|||
// first remove old rule with this id
|
||||
RuleError removeResult = removeRule(ruleId, true);
|
||||
if (removeResult != RuleErrorNoError) {
|
||||
// no need to restore, rule is still in system
|
||||
return removeResult;
|
||||
}
|
||||
|
||||
// the rule is removed, now add it with the same id and new vonfiguration
|
||||
RuleError addResult = addRule(ruleId, name, eventDescriptorList, stateEvaluator, actions, exitActions, enabled, true);
|
||||
if (addResult != RuleErrorNoError) {
|
||||
// restore rule
|
||||
appendRule(rule);
|
||||
return addResult;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -168,16 +168,21 @@ bool GuhTestBase::enableNotifications()
|
|||
QVariantMap notificationParams;
|
||||
notificationParams.insert("enabled", true);
|
||||
QVariant response = injectAndWait("JSONRPC.SetNotificationStatus", notificationParams);
|
||||
|
||||
return response.toMap().value("params").toMap().value("enabled").toBool();
|
||||
if (response.toMap().value("params").toMap().value("enabled").toBool() != true) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GuhTestBase::disableNotifications()
|
||||
{
|
||||
QVariantMap notificationParams;
|
||||
notificationParams.insert("enabled", true);
|
||||
notificationParams.insert("enabled", false);
|
||||
QVariant response = injectAndWait("JSONRPC.SetNotificationStatus", notificationParams);
|
||||
return !response.toMap().value("params").toMap().value("enabled").toBool();
|
||||
if (response.toMap().value("params").toMap().value("enabled").toBool() != false) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void GuhTestBase::restartServer()
|
||||
|
|
|
|||
|
|
@ -268,10 +268,7 @@ 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);
|
||||
QCOMPARE(enableNotifications(), true);
|
||||
|
||||
// Setup connection to mock client
|
||||
QSignalSpy clientSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
|
||||
|
|
@ -283,27 +280,18 @@ void TestJSONRPC::deviceAddedRemovedNotifications()
|
|||
httpportParam.insert("value", 8765);
|
||||
deviceParams.append(httpportParam);
|
||||
|
||||
params.clear(); response.clear();
|
||||
QVariantMap params;
|
||||
params.insert("deviceClassId", mockDeviceClassId);
|
||||
params.insert("deviceParams", deviceParams);
|
||||
response = injectAndWait("Devices.AddConfiguredDevice", params);
|
||||
QVariant response = injectAndWait("Devices.AddConfiguredDevice", params);
|
||||
clientSpy.wait();
|
||||
verifyDeviceError(response);
|
||||
QVariantMap notificationDeviceMap = checkNotification(clientSpy, "Devices.DeviceAdded").toMap().value("params").toMap().value("device").toMap();
|
||||
|
||||
// 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());
|
||||
DeviceId deviceId = DeviceId(response.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()) {
|
||||
|
|
@ -312,35 +300,24 @@ void TestJSONRPC::deviceAddedRemovedNotifications()
|
|||
}
|
||||
}
|
||||
|
||||
// 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.clear(); response.clear(); clientSpy.clear();
|
||||
params.insert("deviceId", deviceId);
|
||||
response = injectAndWait("Devices.RemoveConfiguredDevice", params);
|
||||
clientSpy.wait();
|
||||
verifyDeviceError(response);
|
||||
checkNotification(clientSpy, "Devices.DeviceRemoved");
|
||||
|
||||
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());
|
||||
//QCOMPARE(disableNotifications(), true);
|
||||
}
|
||||
|
||||
void TestJSONRPC::ruleAddedRemovedNotifications()
|
||||
{
|
||||
// enable notificartions
|
||||
QVariantMap params;
|
||||
params.insert("enabled", true);
|
||||
QVariant response = injectAndWait("JSONRPC.SetNotificationStatus", params);
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("enabled").toBool(), true);
|
||||
QCOMPARE(enableNotifications(), true);
|
||||
|
||||
// Setup connection to mock client
|
||||
QSignalSpy clientSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
|
||||
|
||||
// Add rule and wait for notification
|
||||
// StateDescriptor
|
||||
|
|
@ -365,32 +342,20 @@ void TestJSONRPC::ruleAddedRemovedNotifications()
|
|||
eventDescriptor.insert("deviceId", m_mockDeviceId);
|
||||
eventDescriptor.insert("paramDescriptors", QVariantList());
|
||||
|
||||
params.clear(); response.clear();
|
||||
QVariantMap params;
|
||||
params.insert("name", "Test Rule notifications");
|
||||
params.insert("actions", QVariantList() << actionNoParams);
|
||||
params.insert("eventDescriptor", eventDescriptor);
|
||||
params.insert("stateEvaluator", stateEvaluator);
|
||||
|
||||
// Setup connection to mock client
|
||||
QSignalSpy clientSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
|
||||
QVariant response = injectAndWait("Rules.AddRule", params);
|
||||
clientSpy.wait();
|
||||
QVariantMap notificationRuleMap = checkNotification(clientSpy, "Rules.RuleAdded").toMap().value("params").toMap().value("rule").toMap();
|
||||
verifyRuleError(response);
|
||||
|
||||
response = injectAndWait("Rules.AddRule", params);
|
||||
|
||||
clientSpy.wait(500);
|
||||
qDebug() << "got" << clientSpy.count() << "notifications";
|
||||
QCOMPARE(clientSpy.count(), 2);
|
||||
|
||||
QJsonDocument jsonDocResponse = QJsonDocument::fromJson(clientSpy.at(1).at(1).toByteArray());
|
||||
QJsonDocument jsonDocNotification = QJsonDocument::fromJson(clientSpy.at(0).at(1).toByteArray());
|
||||
|
||||
verifyRuleError(jsonDocResponse.toVariant());
|
||||
RuleId ruleId = RuleId(jsonDocResponse.toVariant().toMap().value("params").toMap().value("ruleId").toString());
|
||||
RuleId ruleId = RuleId(response.toMap().value("params").toMap().value("ruleId").toString());
|
||||
QVERIFY(!ruleId.isNull());
|
||||
|
||||
// check the DeviceAdded notification
|
||||
QCOMPARE(jsonDocNotification.toVariant().toMap().value("notification").toString(), QString("Rules.RuleAdded"));
|
||||
QVariantMap notificationRuleMap = jsonDocNotification.toVariant().toMap().value("params").toMap().value("rule").toMap();
|
||||
|
||||
QCOMPARE(notificationRuleMap.value("enabled").toBool(), true);
|
||||
QCOMPARE(notificationRuleMap.value("name").toString(), params.value("name").toString());
|
||||
QCOMPARE(notificationRuleMap.value("id").toString(), ruleId.toString());
|
||||
|
|
@ -399,26 +364,16 @@ void TestJSONRPC::ruleAddedRemovedNotifications()
|
|||
QCOMPARE(notificationRuleMap.value("eventDescriptors").toList(), QVariantList() << eventDescriptor);
|
||||
QCOMPARE(notificationRuleMap.value("exitActions").toList(), QVariantList());
|
||||
|
||||
// Setup connection to mock client
|
||||
QSignalSpy clientSpy2(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
|
||||
|
||||
// now remove the rule and check the RuleRemoved notification
|
||||
params.clear(); response.clear();
|
||||
params.clear(); response.clear(); clientSpy.clear();
|
||||
params.insert("ruleId", ruleId);
|
||||
response = injectAndWait("Rules.RemoveRule", params);
|
||||
clientSpy.wait();
|
||||
checkNotification(clientSpy, "Devices.DeviceRemoved");
|
||||
verifyRuleError(response);
|
||||
|
||||
clientSpy2.wait(500);
|
||||
qDebug() << "got" << clientSpy2.count() << "notifications";
|
||||
QCOMPARE(clientSpy2.count(), 2); // wait for RuleRemoved notification and response
|
||||
|
||||
jsonDocResponse = QJsonDocument::fromJson(clientSpy2.at(1).at(1).toByteArray());
|
||||
jsonDocNotification = QJsonDocument::fromJson(clientSpy2.at(0).at(1).toByteArray());
|
||||
|
||||
verifyRuleError(jsonDocResponse.toVariant());
|
||||
|
||||
// check the DeviceRemoved notification
|
||||
QCOMPARE(jsonDocNotification.toVariant().toMap().value("notification").toString(), QString("Rules.RuleRemoved"));
|
||||
QCOMPARE(jsonDocNotification.toVariant().toMap().value("params").toMap().value("ruleId").toString(), ruleId.toString());
|
||||
QCOMPARE(disableNotifications(), true);
|
||||
}
|
||||
|
||||
void TestJSONRPC::ruleActiveChangedNotifications()
|
||||
|
|
@ -456,7 +411,7 @@ void TestJSONRPC::ruleActiveChangedNotifications()
|
|||
|
||||
response = injectAndWait("Rules.AddRule", params);
|
||||
|
||||
clientSpy.wait(500);
|
||||
clientSpy.wait();
|
||||
qDebug() << "got" << clientSpy.count() << "notifications";
|
||||
QCOMPARE(clientSpy.count(), 2);
|
||||
|
||||
|
|
@ -491,7 +446,7 @@ void TestJSONRPC::ruleActiveChangedNotifications()
|
|||
QCOMPARE(spy.count(), 1);
|
||||
reply->deleteLater();
|
||||
|
||||
clientSpy2.wait(500);
|
||||
clientSpy2.wait();
|
||||
qDebug() << "got" << clientSpy2.count() << "notifications";
|
||||
QCOMPARE(clientSpy2.count(), 6);
|
||||
|
||||
|
|
@ -515,7 +470,7 @@ void TestJSONRPC::ruleActiveChangedNotifications()
|
|||
QCOMPARE(spy.count(), 1);
|
||||
reply2->deleteLater();
|
||||
|
||||
clientSpy2.wait(500);
|
||||
clientSpy2.wait();
|
||||
QCOMPARE(clientSpy2.count(), 5);
|
||||
|
||||
for (int i = 0; i < clientSpy2.count(); i++) {
|
||||
|
|
@ -536,7 +491,7 @@ void TestJSONRPC::ruleActiveChangedNotifications()
|
|||
params.insert("ruleId", ruleId);
|
||||
response = injectAndWait("Rules.RemoveRule", params);
|
||||
|
||||
clientSpy3.wait(500);
|
||||
clientSpy3.wait();
|
||||
qDebug() << "got" << clientSpy3.count() << "notifications";
|
||||
QCOMPARE(clientSpy3.count(), 2); // wait for RuleRemoved notification and response
|
||||
|
||||
|
|
@ -576,7 +531,7 @@ void TestJSONRPC::deviceParamsChangedNotifications()
|
|||
response = injectAndWait("Devices.AddConfiguredDevice", params);
|
||||
|
||||
// Lets wait for the notification
|
||||
clientSpy.wait(500);
|
||||
clientSpy.wait();
|
||||
QCOMPARE(clientSpy.count(), 2); // wait for device added notification and response
|
||||
|
||||
QJsonDocument jsonDocResponse = QJsonDocument::fromJson(clientSpy.at(1).at(1).toByteArray());
|
||||
|
|
@ -615,7 +570,7 @@ void TestJSONRPC::deviceParamsChangedNotifications()
|
|||
params.insert("deviceParams", newDeviceParams);
|
||||
response = injectAndWait("Devices.EditDevice", params);
|
||||
|
||||
clientSpy2.wait(500);
|
||||
clientSpy2.wait();
|
||||
QCOMPARE(clientSpy2.count(), 2);
|
||||
|
||||
jsonDocResponse = QJsonDocument::fromJson(clientSpy2.at(1).at(1).toByteArray());
|
||||
|
|
@ -644,7 +599,7 @@ void TestJSONRPC::deviceParamsChangedNotifications()
|
|||
params.insert("deviceId", deviceId);
|
||||
response = injectAndWait("Devices.RemoveConfiguredDevice", params);
|
||||
|
||||
clientSpy3.wait(500);
|
||||
clientSpy3.wait();
|
||||
QCOMPARE(clientSpy3.count(), 2); // wait for device removed notification and response
|
||||
|
||||
jsonDocResponse = QJsonDocument::fromJson(clientSpy3.at(1).at(1).toByteArray());
|
||||
|
|
|
|||
|
|
@ -662,6 +662,8 @@ void TestRules::editRules()
|
|||
response = injectAndWait("Rules.EditRule", params);
|
||||
verifyRuleError(response, error);
|
||||
if (error == RuleEngine::RuleErrorNoError){
|
||||
clientSpy.wait();
|
||||
|
||||
QVariant notification = checkNotification(clientSpy, "Rules.RuleConfigurationChanged");
|
||||
QVERIFY2(notification != QVariant(), "not received \"Rules.RuleConfigurationChanged\" notification");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue