add remove policy tests
This commit is contained in:
parent
574bbcd7b6
commit
9d2ab92d42
@ -1712,6 +1712,12 @@ QPair<bool, QString> JsonTypes::validateVariant(const QVariant &templateVariant,
|
|||||||
qCWarning(dcJsonRpc) << QString("Value %1 not allowed in %2").arg(variant.toString()).arg(repeatingModeRef());
|
qCWarning(dcJsonRpc) << QString("Value %1 not allowed in %2").arg(variant.toString()).arg(repeatingModeRef());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
} else if (refName == removePolicyRef()) {
|
||||||
|
QPair<bool, QString> result = validateEnum(s_removePolicy, variant);
|
||||||
|
if (!result.first) {
|
||||||
|
qCWarning(dcJsonRpc) << QString("Value %1 not allowed in %2").arg(variant.toString()).arg(removePolicyRef());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Q_ASSERT_X(false, "JsonTypes", QString("Unhandled ref: %1").arg(refName).toLatin1().data());
|
Q_ASSERT_X(false, "JsonTypes", QString("Unhandled ref: %1").arg(refName).toLatin1().data());
|
||||||
return report(false, QString("Unhandled ref %1. Server implementation incomplete.").arg(refName));
|
return report(false, QString("Unhandled ref %1. Server implementation incomplete.").arg(refName));
|
||||||
|
|||||||
@ -61,6 +61,11 @@ ActionTypeId mockActionIdAsync = ActionTypeId("fbae06d3-7666-483e-a39e-ec50fe890
|
|||||||
ActionTypeId mockActionIdFailing = ActionTypeId("df3cf33d-26d5-4577-9132-9823bd33fad0");
|
ActionTypeId mockActionIdFailing = ActionTypeId("df3cf33d-26d5-4577-9132-9823bd33fad0");
|
||||||
ActionTypeId mockActionIdAsyncFailing = ActionTypeId("bfe89a1d-3497-4121-8318-e77c37537219");
|
ActionTypeId mockActionIdAsyncFailing = ActionTypeId("bfe89a1d-3497-4121-8318-e77c37537219");
|
||||||
|
|
||||||
|
// Parent device
|
||||||
|
EventTypeId mockParentChildEventId = EventTypeId("d24ede5f-4064-4898-bb84-cfb533b1fbc0");
|
||||||
|
ActionTypeId mockParentChildActionId = ActionTypeId("d24ede5f-4064-4898-bb84-cfb533b1fbc0");
|
||||||
|
StateTypeId mockParentChildStateId = StateTypeId("d24ede5f-4064-4898-bb84-cfb533b1fbc0");
|
||||||
|
|
||||||
static QHash<QString, bool> s_loggingFilters;
|
static QHash<QString, bool> s_loggingFilters;
|
||||||
|
|
||||||
static void loggingCategoryFilter(QLoggingCategory *category)
|
static void loggingCategoryFilter(QLoggingCategory *category)
|
||||||
|
|||||||
@ -55,6 +55,11 @@ extern EventTypeId mockEvent2Id;
|
|||||||
extern StateTypeId mockIntStateId;
|
extern StateTypeId mockIntStateId;
|
||||||
extern StateTypeId mockBoolStateId;
|
extern StateTypeId mockBoolStateId;
|
||||||
|
|
||||||
|
// Parent / Child device
|
||||||
|
extern EventTypeId mockParentChildEventId;
|
||||||
|
extern ActionTypeId mockParentChildActionId;
|
||||||
|
extern StateTypeId mockParentChildStateId;
|
||||||
|
|
||||||
using namespace guhserver;
|
using namespace guhserver;
|
||||||
|
|
||||||
class MockTcpServer;
|
class MockTcpServer;
|
||||||
|
|||||||
@ -42,6 +42,9 @@ private:
|
|||||||
void cleanupMockHistory();
|
void cleanupMockHistory();
|
||||||
void cleanupRules();
|
void cleanupRules();
|
||||||
|
|
||||||
|
QVariantMap createEventDescriptor(const DeviceId &deviceId, const EventTypeId &eventTypeId);
|
||||||
|
QVariantMap createActionWithParams(const DeviceId &deviceId);
|
||||||
|
|
||||||
void verifyRuleExecuted(const ActionTypeId &actionTypeId);
|
void verifyRuleExecuted(const ActionTypeId &actionTypeId);
|
||||||
void verifyRuleNotExecuted();
|
void verifyRuleNotExecuted();
|
||||||
|
|
||||||
@ -82,7 +85,8 @@ private slots:
|
|||||||
|
|
||||||
void testEventBasedAction();
|
void testEventBasedAction();
|
||||||
|
|
||||||
void removePolicy();
|
void removePolicyUpdate();
|
||||||
|
void removePolicyCascade();
|
||||||
|
|
||||||
void testRuleActionParams_data();
|
void testRuleActionParams_data();
|
||||||
void testRuleActionParams();
|
void testRuleActionParams();
|
||||||
@ -107,26 +111,30 @@ void TestRules::cleanupRules() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestRules::cleanup() {
|
QVariantMap TestRules::createEventDescriptor(const DeviceId &deviceId, const EventTypeId &eventTypeId)
|
||||||
cleanupMockHistory();
|
{
|
||||||
cleanupRules();
|
QVariantMap eventDescriptor;
|
||||||
|
eventDescriptor.insert("eventTypeId", eventTypeId);
|
||||||
|
eventDescriptor.insert("deviceId", deviceId);
|
||||||
|
return eventDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestRules::emptyRule()
|
QVariantMap TestRules::createActionWithParams(const DeviceId &deviceId)
|
||||||
{
|
{
|
||||||
QVariantMap params;
|
QVariantMap action;
|
||||||
params.insert("name", QString());
|
QVariantList ruleActionParams;
|
||||||
params.insert("actions", QVariantList());
|
QVariantMap param1;
|
||||||
QVariant response = injectAndWait("Rules.AddRule", params);
|
param1.insert("name", "mockActionParam1");
|
||||||
verifyRuleError(response, RuleEngine::RuleErrorInvalidRuleFormat);
|
param1.insert("value", 4);
|
||||||
}
|
QVariantMap param2;
|
||||||
|
param2.insert("name", "mockActionParam2");
|
||||||
void TestRules::getInvalidRule()
|
param2.insert("value", true);
|
||||||
{
|
ruleActionParams.append(param1);
|
||||||
QVariantMap params;
|
ruleActionParams.append(param2);
|
||||||
params.insert("ruleId", QUuid::createUuid());
|
action.insert("deviceId", deviceId);
|
||||||
QVariant response = injectAndWait("Rules.GetRuleDetails", params);
|
action.insert("actionTypeId", mockActionIdWithParams);
|
||||||
verifyRuleError(response, RuleEngine::RuleErrorRuleNotFound);
|
action.insert("ruleActionParams", ruleActionParams);
|
||||||
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestRules::verifyRuleExecuted(const ActionTypeId &actionTypeId)
|
void TestRules::verifyRuleExecuted(const ActionTypeId &actionTypeId)
|
||||||
@ -160,6 +168,29 @@ void TestRules::verifyRuleNotExecuted()
|
|||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***********************************************************************/
|
||||||
|
|
||||||
|
void TestRules::cleanup() {
|
||||||
|
cleanupMockHistory();
|
||||||
|
cleanupRules();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestRules::emptyRule()
|
||||||
|
{
|
||||||
|
QVariantMap params;
|
||||||
|
params.insert("name", QString());
|
||||||
|
params.insert("actions", QVariantList());
|
||||||
|
QVariant response = injectAndWait("Rules.AddRule", params);
|
||||||
|
verifyRuleError(response, RuleEngine::RuleErrorInvalidRuleFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestRules::getInvalidRule()
|
||||||
|
{
|
||||||
|
QVariantMap params;
|
||||||
|
params.insert("ruleId", QUuid::createUuid());
|
||||||
|
QVariant response = injectAndWait("Rules.GetRuleDetails", params);
|
||||||
|
verifyRuleError(response, RuleEngine::RuleErrorRuleNotFound);
|
||||||
|
}
|
||||||
|
|
||||||
QVariant TestRules::validIntStateBasedRule(const QString &name, const bool &executable, const bool &enabled)
|
QVariant TestRules::validIntStateBasedRule(const QString &name, const bool &executable, const bool &enabled)
|
||||||
{
|
{
|
||||||
@ -1563,7 +1594,7 @@ void TestRules::testEventBasedAction()
|
|||||||
// TODO: check if this action was realy executed with the int state value 42
|
// TODO: check if this action was realy executed with the int state value 42
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestRules::removePolicy()
|
void TestRules::removePolicyUpdate()
|
||||||
{
|
{
|
||||||
// ADD parent device
|
// ADD parent device
|
||||||
QVariantMap params;
|
QVariantMap params;
|
||||||
@ -1595,12 +1626,128 @@ void TestRules::removePolicy()
|
|||||||
QVERIFY2(!childDeviceId.isNull(), "Could not find child device");
|
QVERIFY2(!childDeviceId.isNull(), "Could not find child device");
|
||||||
|
|
||||||
// Add rule with child device
|
// Add rule with child device
|
||||||
|
QVariantList eventDescriptors;
|
||||||
|
eventDescriptors.append(createEventDescriptor(childDeviceId, mockParentChildEventId));
|
||||||
|
eventDescriptors.append(createEventDescriptor(parentDeviceId, mockParentChildEventId));
|
||||||
|
eventDescriptors.append(createEventDescriptor(m_mockDeviceId, mockEvent1Id));
|
||||||
|
|
||||||
|
params.clear(); response.clear();
|
||||||
|
params.insert("name", "RemovePolicy");
|
||||||
|
params.insert("eventDescriptors", eventDescriptors);
|
||||||
|
params.insert("actions", QVariantList() << createActionWithParams(m_mockDeviceId));
|
||||||
|
|
||||||
|
response = injectAndWait("Rules.AddRule", params);
|
||||||
|
verifyRuleError(response);
|
||||||
|
RuleId ruleId = RuleId(response.toMap().value("params").toMap().value("ruleId").toString());
|
||||||
|
QVERIFY2(!ruleId.isNull(), "Could not get ruleId");
|
||||||
|
|
||||||
|
// Try to remove child device
|
||||||
|
params.clear(); response.clear();
|
||||||
|
params.insert("deviceId", childDeviceId);
|
||||||
|
response = injectAndWait("Devices.RemoveConfiguredDevice", params);
|
||||||
|
verifyDeviceError(response, DeviceManager::DeviceErrorDeviceIsChild);
|
||||||
|
|
||||||
|
// Try to remove child device
|
||||||
|
params.clear(); response.clear();
|
||||||
|
params.insert("deviceId", parentDeviceId);
|
||||||
|
response = injectAndWait("Devices.RemoveConfiguredDevice", params);
|
||||||
|
verifyDeviceError(response, DeviceManager::DeviceErrorDeviceInRule);
|
||||||
|
|
||||||
|
// Remove policy
|
||||||
|
params.clear(); response.clear();
|
||||||
|
params.insert("deviceId", parentDeviceId);
|
||||||
|
params.insert("removePolicy", "RemovePolicyUpdate");
|
||||||
|
response = injectAndWait("Devices.RemoveConfiguredDevice", params);
|
||||||
|
verifyDeviceError(response);
|
||||||
|
|
||||||
|
// get updated rule
|
||||||
|
params.clear();
|
||||||
|
params.insert("ruleId", ruleId);
|
||||||
|
response = injectAndWait("Rules.GetRuleDetails", params);
|
||||||
|
verifyRuleError(response);
|
||||||
|
|
||||||
|
QVariantMap rule = response.toMap().value("params").toMap().value("rule").toMap();
|
||||||
|
qDebug() << QJsonDocument::fromVariant(rule).toJson();
|
||||||
|
QVERIFY(rule.value("eventDescriptors").toList().count() == 1);
|
||||||
|
|
||||||
|
// REMOVE rule
|
||||||
|
QVariantMap removeParams;
|
||||||
|
removeParams.insert("ruleId", ruleId);
|
||||||
|
response = injectAndWait("Rules.RemoveRule", removeParams);
|
||||||
|
verifyRuleError(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestRules::removePolicyCascade()
|
||||||
|
{
|
||||||
|
// ADD parent device
|
||||||
|
QVariantMap params;
|
||||||
|
params.insert("deviceClassId", mockParentDeviceClassId);
|
||||||
|
params.insert("name", "Parent device");
|
||||||
|
|
||||||
|
QVariant response = injectAndWait("Devices.AddConfiguredDevice", params);
|
||||||
|
verifyDeviceError(response);
|
||||||
|
|
||||||
|
DeviceId parentDeviceId = DeviceId(response.toMap().value("params").toMap().value("deviceId").toString());
|
||||||
|
QVERIFY(!parentDeviceId.isNull());
|
||||||
|
|
||||||
|
// find child device
|
||||||
|
response = injectAndWait("Devices.GetConfiguredDevices");
|
||||||
|
|
||||||
|
QVariantList devices = response.toMap().value("params").toMap().value("devices").toList();
|
||||||
|
|
||||||
|
DeviceId childDeviceId;
|
||||||
|
foreach (const QVariant deviceVariant, devices) {
|
||||||
|
QVariantMap deviceMap = deviceVariant.toMap();
|
||||||
|
|
||||||
|
if (deviceMap.value("deviceClassId").toString() == mockChildDeviceClassId.toString()) {
|
||||||
|
if (deviceMap.value("parentId") == parentDeviceId.toString()) {
|
||||||
|
//qDebug() << QJsonDocument::fromVariant(deviceVariant).toJson();
|
||||||
|
childDeviceId = DeviceId(deviceMap.value("id").toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QVERIFY2(!childDeviceId.isNull(), "Could not find child device");
|
||||||
|
|
||||||
|
// Add rule with child device
|
||||||
|
QVariantList eventDescriptors;
|
||||||
|
eventDescriptors.append(createEventDescriptor(childDeviceId, mockParentChildEventId));
|
||||||
|
eventDescriptors.append(createEventDescriptor(parentDeviceId, mockParentChildEventId));
|
||||||
|
eventDescriptors.append(createEventDescriptor(m_mockDeviceId, mockEvent1Id));
|
||||||
|
|
||||||
|
params.clear(); response.clear();
|
||||||
|
params.insert("name", "RemovePolicy");
|
||||||
|
params.insert("eventDescriptors", eventDescriptors);
|
||||||
|
params.insert("actions", QVariantList() << createActionWithParams(m_mockDeviceId));
|
||||||
|
|
||||||
|
response = injectAndWait("Rules.AddRule", params);
|
||||||
|
verifyRuleError(response);
|
||||||
|
RuleId ruleId = RuleId(response.toMap().value("params").toMap().value("ruleId").toString());
|
||||||
|
QVERIFY2(!ruleId.isNull(), "Could not get ruleId");
|
||||||
|
|
||||||
|
// Try to remove child device
|
||||||
|
params.clear(); response.clear();
|
||||||
|
params.insert("deviceId", childDeviceId);
|
||||||
|
response = injectAndWait("Devices.RemoveConfiguredDevice", params);
|
||||||
|
verifyDeviceError(response, DeviceManager::DeviceErrorDeviceIsChild);
|
||||||
|
|
||||||
|
// Try to remove child device
|
||||||
|
params.clear(); response.clear();
|
||||||
|
params.insert("deviceId", parentDeviceId);
|
||||||
|
response = injectAndWait("Devices.RemoveConfiguredDevice", params);
|
||||||
|
verifyDeviceError(response, DeviceManager::DeviceErrorDeviceInRule);
|
||||||
|
|
||||||
|
// Remove policy
|
||||||
|
params.clear(); response.clear();
|
||||||
|
params.insert("deviceId", parentDeviceId);
|
||||||
|
params.insert("removePolicy", "RemovePolicyCascade");
|
||||||
|
response = injectAndWait("Devices.RemoveConfiguredDevice", params);
|
||||||
|
verifyDeviceError(response);
|
||||||
|
|
||||||
|
// get updated rule
|
||||||
|
params.clear();
|
||||||
|
params.insert("ruleId", ruleId);
|
||||||
|
response = injectAndWait("Rules.GetRuleDetails", params);
|
||||||
|
verifyRuleError(response, RuleEngine::RuleErrorRuleNotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestRules::testRuleActionParams_data()
|
void TestRules::testRuleActionParams_data()
|
||||||
@ -1645,12 +1792,10 @@ void TestRules::testRuleActionParams_data()
|
|||||||
|
|
||||||
void TestRules::testRuleActionParams()
|
void TestRules::testRuleActionParams()
|
||||||
{
|
{
|
||||||
|
|
||||||
QFETCH(QVariantMap, action);
|
QFETCH(QVariantMap, action);
|
||||||
QFETCH(QVariantMap, exitAction);
|
QFETCH(QVariantMap, exitAction);
|
||||||
QFETCH(RuleEngine::RuleError, error);
|
QFETCH(RuleEngine::RuleError, error);
|
||||||
|
|
||||||
|
|
||||||
// Add a rule
|
// Add a rule
|
||||||
QVariantMap addRuleParams;
|
QVariantMap addRuleParams;
|
||||||
addRuleParams.insert("name", "TestRule");
|
addRuleParams.insert("name", "TestRule");
|
||||||
@ -1662,9 +1807,6 @@ void TestRules::testRuleActionParams()
|
|||||||
|
|
||||||
QVariant response = injectAndWait("Rules.AddRule", addRuleParams);
|
QVariant response = injectAndWait("Rules.AddRule", addRuleParams);
|
||||||
verifyRuleError(response, error);
|
verifyRuleError(response, error);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "testrules.moc"
|
#include "testrules.moc"
|
||||||
|
|||||||
Reference in New Issue
Block a user