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_report_manager.cpp b/tests/src/test_report_manager.cpp
index 10b4de9..bf76efc 100644
--- a/tests/src/test_report_manager.cpp
+++ b/tests/src/test_report_manager.cpp
@@ -1,7 +1,9 @@
#include "dbus_environment.hpp"
#include "helpers.hpp"
+#include "interfaces/trigger_manager.hpp"
#include "mocks/json_storage_mock.hpp"
#include "mocks/report_factory_mock.hpp"
+#include "mocks/trigger_manager_mock.hpp"
#include "params/report_params.hpp"
#include "report.hpp"
#include "report_manager.hpp"
@@ -29,6 +31,9 @@
std::make_unique<NiceMock<ReportMock>>(reportParams.reportId());
ReportMock& reportMock = *reportMockPtr;
+ std::unique_ptr<interfaces::TriggerManager> triggerManagerMockPtr =
+ std::make_unique<NiceMock<TriggerManagerMock>>();
+
std::unique_ptr<ReportManager> sut;
MockFunction<void(std::string)> checkPoint;
@@ -38,9 +43,9 @@
EXPECT_CALL(reportFactoryMock, convertMetricParams(_, _))
.Times(AnyNumber());
- sut = std::make_unique<ReportManager>(std::move(reportFactoryMockPtr),
- std::move(storageMockPtr),
- DbusEnvironment::getObjServer());
+ sut = std::make_unique<ReportManager>(
+ std::move(reportFactoryMockPtr), std::move(storageMockPtr),
+ DbusEnvironment::getObjServer(), triggerManagerMockPtr);
}
void TearDown() override
@@ -378,6 +383,32 @@
sut->updateReport("NotAReport");
}
+TEST_F(TestReportManager, updateTriggerIdsUpdatesThemForExistReport)
+{
+ reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock))
+ .WillOnce(Return(ByMove(std::move(reportMockPtr))));
+ EXPECT_CALL(reportMock, updateTriggerIds("Trigger1", TriggerIdUpdate::Add));
+ EXPECT_CALL(reportMock,
+ updateTriggerIds("Trigger2", TriggerIdUpdate::Remove));
+
+ addReport(reportParams);
+ sut->updateTriggerIds(reportParams.reportId(), "Trigger1",
+ TriggerIdUpdate::Add);
+
+ sut->updateTriggerIds(reportParams.reportId(), "Trigger2",
+ TriggerIdUpdate::Remove);
+}
+
+TEST_F(TestReportManager, updateTriggerIdsDoNothingIfReportDoesNotExist)
+{
+ reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock))
+ .WillOnce(Return(ByMove(std::move(reportMockPtr))));
+ EXPECT_CALL(reportMock, updateTriggerIds(_, _)).Times(0);
+
+ addReport(reportParams);
+ sut->updateTriggerIds("NotAReport", "Trigger1", TriggerIdUpdate::Add);
+}
+
class TestReportManagerWithAggregationOperationType :
public TestReportManager,
public WithParamInterface<OperationType>
@@ -431,9 +462,9 @@
void makeReportManager()
{
- sut = std::make_unique<ReportManager>(std::move(reportFactoryMockPtr),
- std::move(storageMockPtr),
- DbusEnvironment::getObjServer());
+ sut = std::make_unique<ReportManager>(
+ std::move(reportFactoryMockPtr), std::move(storageMockPtr),
+ DbusEnvironment::getObjServer(), triggerManagerMockPtr);
}
nlohmann::json data = nlohmann::json{