Report: Add TriggerIds property
This change is adding TriggerIds property for Report interface. It is an
array of strings, each representing id of trigger which may update given
report Readings property, due to UpdateReport action. This properly is
read-only, but it can be changed in the runtime, when:
- New Trigger is made using AddTrigger dbus method, when ReportId
argument contains id of given report.
- Trigger is deleted from dbus, and its ReportNames property included id
of given report.
- ReportNames property of any trigger is updated to include (or not) id
of given report.
When this property is modified by service, signal will be emitted on
dbus for property change.
When there is existing trigger with id of non-existing report in its
ReportNames property, its id will be added to TriggerIds property of
such report, the moment it is created by user.
Testing done:
- new UTs were made, all UTs are passing.
- manual testing on dbus interface was successful.
Signed-off-by: Szymon Dompke <szymon.dompke@intel.com>
Change-Id: I1c4c94ce751ddaee001e3cadde3ea60aa8e1c224
diff --git a/tests/src/test_trigger.cpp b/tests/src/test_trigger.cpp
index a2286ee..5ad2a81 100644
--- a/tests/src/test_trigger.cpp
+++ b/tests/src/test_trigger.cpp
@@ -1,6 +1,7 @@
#include "dbus_environment.hpp"
#include "helpers.hpp"
#include "mocks/json_storage_mock.hpp"
+#include "mocks/report_manager_mock.hpp"
#include "mocks/sensor_mock.hpp"
#include "mocks/threshold_mock.hpp"
#include "mocks/trigger_factory_mock.hpp"
@@ -36,6 +37,8 @@
Milliseconds(5).count(), "32.7"},
});
+ std::unique_ptr<ReportManagerMock> reportManagerMockPtr =
+ std::make_unique<NiceMock<ReportManagerMock>>();
std::unique_ptr<TriggerManagerMock> triggerManagerMockPtr =
std::make_unique<NiceMock<TriggerManagerMock>>();
std::unique_ptr<TriggerFactoryMock> triggerFactoryMockPtr =
@@ -70,7 +73,8 @@
params.reportIds().begin(), params.reportIds().end()),
std::vector<std::shared_ptr<interfaces::Threshold>>(thresholdMocks),
*triggerManagerMockPtr, storageMock, *triggerFactoryMockPtr,
- SensorMock::makeSensorMocks(params.sensors()));
+ SensorMock::makeSensorMocks(params.sensors()),
+ *reportManagerMockPtr);
}
static interfaces::JsonStorage::FilePath to_file_path(std::string name)
@@ -132,6 +136,13 @@
triggerParams.thresholdParams())));
}
+TEST_F(TestTrigger, checkBasicGetters)
+{
+ EXPECT_THAT(sut->getId(), Eq(triggerParams.id()));
+ EXPECT_THAT(sut->getPath(), Eq(Trigger::triggerDir + triggerParams.id()));
+ EXPECT_THAT(sut->getReportIds(), Eq(triggerParams.reportIds()));
+}
+
TEST_F(TestTrigger, setPropertyNameToCorrectValue)
{
std::string name = "custom name 1234 %^#5";
@@ -148,6 +159,70 @@
EXPECT_THAT(
getProperty<std::vector<std::string>>(sut->getPath(), "ReportNames"),
Eq(newNames));
+ EXPECT_THAT(
+ getProperty<std::vector<std::string>>(sut->getPath(), "ReportNames"),
+ Eq(sut->getReportIds()));
+}
+
+TEST_F(TestTrigger, settingPropertyReportNamesUptadesTriggerIdsInReports)
+{
+ std::vector<std::string> newPropertyVal = {"abc", "one", "two"};
+
+ for (const auto& reportId : newPropertyVal)
+ {
+ EXPECT_CALL(
+ *reportManagerMockPtr,
+ updateTriggerIds(reportId, sut->getId(), TriggerIdUpdate::Add));
+ }
+ for (const auto& reportId : triggerParams.reportIds())
+ {
+ EXPECT_CALL(
+ *reportManagerMockPtr,
+ updateTriggerIds(reportId, sut->getId(), TriggerIdUpdate::Remove));
+ }
+
+ EXPECT_THAT(setProperty(sut->getPath(), "ReportNames", newPropertyVal),
+ Eq(boost::system::errc::success));
+}
+
+TEST_F(TestTrigger, settingPropertyReportNamesWillNotRemoveTriggerIdsInReports)
+{
+ std::vector<std::string> newPropertyVal = triggerParams.reportIds();
+ std::vector<std::string> newNames{"abc", "one", "two"};
+ newPropertyVal.insert(newPropertyVal.end(), newNames.begin(),
+ newNames.end());
+
+ for (const auto& reportId : newNames)
+ {
+ EXPECT_CALL(
+ *reportManagerMockPtr,
+ updateTriggerIds(reportId, sut->getId(), TriggerIdUpdate::Add));
+ }
+
+ EXPECT_THAT(setProperty(sut->getPath(), "ReportNames", newPropertyVal),
+ Eq(boost::system::errc::success));
+}
+
+TEST_F(TestTrigger,
+ settingPropertyReportNamesToSameValueWillNotUpdateTriggerIdsInReports)
+{
+ std::vector<std::string> newPropertyVal = triggerParams.reportIds();
+
+ EXPECT_CALL(*reportManagerMockPtr, updateTriggerIds(_, _, _)).Times(0);
+
+ EXPECT_THAT(setProperty(sut->getPath(), "ReportNames", newPropertyVal),
+ Eq(boost::system::errc::success));
+}
+
+TEST_F(TestTrigger,
+ DISABLED_settingPropertyReportNamesThrowsExceptionWhenDuplicateReportIds)
+{
+ std::vector<std::string> newPropertyVal{"trigger1", "trigger2", "trigger1"};
+
+ EXPECT_CALL(*reportManagerMockPtr, updateTriggerIds(_, _, _)).Times(0);
+
+ EXPECT_THAT(setProperty(sut->getPath(), "ReportNames", newPropertyVal),
+ Eq(boost::system::errc::invalid_argument));
}
TEST_F(TestTrigger, setPropertySensors)
@@ -231,6 +306,12 @@
{
EXPECT_CALL(storageMock, remove(to_file_path(sut->getId())));
EXPECT_CALL(*triggerManagerMockPtr, removeTrigger(sut.get()));
+ for (const auto& reportId : triggerParams.reportIds())
+ {
+ EXPECT_CALL(
+ *reportManagerMockPtr,
+ updateTriggerIds(reportId, sut->getId(), TriggerIdUpdate::Remove));
+ }
auto ec = deleteTrigger(sut->getPath());
EXPECT_THAT(ec, Eq(boost::system::errc::success));
}
@@ -252,7 +333,7 @@
Eq(persistent));
}
-class TestTriggerErrors : public TestTrigger
+class TestTriggerInitialization : public TestTrigger
{
public:
void SetUp() override
@@ -261,7 +342,8 @@
nlohmann::json storedConfiguration;
};
-TEST_F(TestTriggerErrors, exceptionDuringTriggerStoreDisablesPersistency)
+TEST_F(TestTriggerInitialization,
+ exceptionDuringTriggerStoreDisablesPersistency)
{
EXPECT_CALL(storageMock, store(_, _))
.WillOnce(Throw(std::runtime_error("Generic error!")));
@@ -271,7 +353,7 @@
EXPECT_THAT(getProperty<bool>(sut->getPath(), "Persistent"), Eq(false));
}
-TEST_F(TestTriggerErrors, creatingTriggerThrowsExceptionWhenIdIsInvalid)
+TEST_F(TestTriggerInitialization, creatingTriggerThrowsExceptionWhenIdIsInvalid)
{
EXPECT_CALL(storageMock, store(_, _)).Times(0);
@@ -279,6 +361,18 @@
sdbusplus::exception::SdBusError);
}
+TEST_F(TestTriggerInitialization, creatingTriggerUpdatesTriggersIdsInReports)
+{
+ for (const auto& reportId : triggerParams.reportIds())
+ {
+ EXPECT_CALL(*reportManagerMockPtr,
+ updateTriggerIds(reportId, triggerParams.id(),
+ TriggerIdUpdate::Add));
+ }
+
+ sut = makeTrigger(triggerParams);
+}
+
class TestTriggerStore : public TestTrigger
{
public: