diff --git a/tests/auto/rules/testrules.cpp b/tests/auto/rules/testrules.cpp index 4288e7a9..d02819c0 100644 --- a/tests/auto/rules/testrules.cpp +++ b/tests/auto/rules/testrules.cpp @@ -38,6 +38,8 @@ private slots: void addRules(); void loadStoreConfig(); + + void evaluateEvent(); }; void TestRules::addRules_data() @@ -139,6 +141,7 @@ void TestRules::addRules() QVERIFY2(eventDescriptorVariant == replyEventDescriptorVariant, "Event descriptor doesn't match"); } } + QVERIFY2(found, "Missing event descriptor"); } } @@ -241,5 +244,49 @@ void TestRules::loadStoreConfig() QVERIFY2(rules.count() == 0, "There should be no rules."); } +void TestRules::evaluateEvent() +{ + // Add a rule + QVariantMap addRuleParams; + QVariantList events; + QVariantMap event1; + event1.insert("eventTypeId", mockEvent1Id); + event1.insert("deviceId", m_mockDeviceId); + events.append(event1); + addRuleParams.insert("eventDescriptorList", events); + + QVariantList actions; + QVariantMap action; + action.insert("actionTypeId", mockActionIdNoParams); + action.insert("deviceId", m_mockDeviceId); + actions.append(action); + addRuleParams.insert("actions", actions); + QVariant response = injectAndWait("Rules.AddRule", addRuleParams); + verifySuccess(response, true); + + // Trigger an event + QNetworkAccessManager nam; + QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*))); + + // trigger event in mock device + QNetworkRequest request(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(m_mockDevice1Port).arg(mockEvent1Id.toString()))); + QNetworkReply *reply = nam.get(request); + spy.wait(); + QCOMPARE(spy.count(), 1); + reply->deleteLater(); + + // Verify rule got executed + spy.clear(); + request.setUrl(QUrl(QString("http://localhost:%1/actionhistory").arg(m_mockDevice1Port))); + reply = nam.get(request); + spy.wait(); + QCOMPARE(spy.count(), 1); + + reply->deleteLater(); + + QByteArray actionHistory = reply->readAll(); + QVERIFY2(mockActionIdNoParams == ActionTypeId(actionHistory), "Action not triggered"); +} + #include "testrules.moc" QTEST_MAIN(TestRules) diff --git a/tests/scripts/addrule.sh b/tests/scripts/addrule.sh index aa187f97..521019b5 100755 --- a/tests/scripts/addrule.sh +++ b/tests/scripts/addrule.sh @@ -3,7 +3,7 @@ if test -z $5; then echo "usage: $0 host sourceDevice eventTypeId targetDeviceId actionTypeId [paramname paramvalue]" elif test -z $6; then - (echo '{"id":1, "method":"Rules.AddRule", "params":{"event": {"eventTypeId": "$3", "deviceId":"'$2'"}, "actions": [ { "deviceId":"'$4'", "actionTypeId":"'$5'"}]}}'; sleep 1) | nc $1 1234 + (echo '{"id":1, "method":"Rules.AddRule", "params":{"eventDescriptor": {"eventTypeId": "'$3'", "deviceId":"'$2'"}, "actions": [ { "deviceId":"'$4'", "actionTypeId":"'$5'"}]}}'; sleep 1) | nc $1 1234 elif test -z $7; then echo "usage: $0 host sourceDevice eventTypeId targetDeviceId actionTypeId [paramname paramvalue]" else