Review fixes for 'Created metric class'
- Changed metric to_json to dumpConfiguration returning LabeledTuple
- LabeledTuple can be created and assigned directly to json
- LabeledTuple can be readed from json using json.get<LabeledTuple>
- Added PrintTo for LabeledMetricParams, LabeledSensorParams
- Added helper method expectMake to ReportFactoryMock
- sensorPaths are serialized to tuple<service, path> instead of single
field with service and path separated via ':'
- Changed configuration version from 1 to 2
Change-Id: I7c45fb584687172f88fd549a93329264793b0b8e
Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
diff --git a/tests/src/mocks/metric_mock.hpp b/tests/src/mocks/metric_mock.hpp
index 21f7733..98bad87 100644
--- a/tests/src/mocks/metric_mock.hpp
+++ b/tests/src/mocks/metric_mock.hpp
@@ -18,5 +18,6 @@
MOCK_METHOD(void, initialize, (), (override));
MOCK_METHOD(const std::vector<MetricValue>&, getReadings, (),
(const, override));
- MOCK_METHOD(nlohmann::json, to_json, (), (const, override));
+ MOCK_METHOD(LabeledMetricParameters, dumpConfiguration, (),
+ (const, override));
};
diff --git a/tests/src/mocks/report_factory_mock.hpp b/tests/src/mocks/report_factory_mock.hpp
index fcb9b7e..0730d9e 100644
--- a/tests/src/mocks/report_factory_mock.hpp
+++ b/tests/src/mocks/report_factory_mock.hpp
@@ -2,6 +2,7 @@
#include "interfaces/report_factory.hpp"
#include "mocks/report_mock.hpp"
+#include "params/report_params.hpp"
#include <gmock/gmock.h>
@@ -12,20 +13,73 @@
{
using namespace testing;
- ON_CALL(*this, make)
+ ON_CALL(*this,
+ make(A<boost::asio::yield_context&>(), _, _, _, _, _, _, _, _))
.WillByDefault(WithArgs<1>(Invoke([](const std::string& name) {
return std::make_unique<NiceMock<ReportMock>>(name);
})));
+ ON_CALL(*this, make(A<const std::string&>(), _, _, _, _, _, _, _, _))
+ .WillByDefault(WithArgs<0>(Invoke([](const std::string& name) {
+ return std::make_unique<NiceMock<ReportMock>>(name);
+ })));
}
- MOCK_METHOD(
- std::unique_ptr<interfaces::Report>, make,
- (std::optional<std::reference_wrapper<boost::asio::yield_context>>,
- const std::string& name, const std::string& reportingType,
- bool emitsReadingsSignal, bool logToMetricReportsCollection,
- std::chrono::milliseconds period,
- const ReadingParameters& metricParams,
- interfaces::ReportManager& reportManager,
- interfaces::JsonStorage& reportStorage),
- (const, override));
+ MOCK_METHOD(std::unique_ptr<interfaces::Report>, make,
+ (boost::asio::yield_context&, const std::string&,
+ const std::string&, bool, bool, std::chrono::milliseconds,
+ const ReadingParameters&, interfaces::ReportManager&,
+ interfaces::JsonStorage&),
+ (const, override));
+ MOCK_METHOD(std::unique_ptr<interfaces::Report>, make,
+ (const std::string&, const std::string&, bool, bool,
+ std::chrono::milliseconds, const ReadingParameters&,
+ interfaces::ReportManager&, interfaces::JsonStorage&,
+ std::vector<LabeledMetricParameters>),
+ (const, override));
+
+ auto& expectMake(
+ const testing::Matcher<boost::asio::yield_context&>& yield,
+ std::optional<std::reference_wrapper<const ReportParams>> paramsRef,
+ const testing::Matcher<interfaces::ReportManager&>& rm,
+ const testing::Matcher<interfaces::JsonStorage&>& js)
+ {
+ if (paramsRef)
+ {
+ const ReportParams& params = *paramsRef;
+ return EXPECT_CALL(*this, make(yield, params.reportName(),
+ params.reportingType(),
+ params.emitReadingUpdate(),
+ params.logToMetricReportCollection(),
+ params.interval(),
+ params.readingParameters(), rm, js));
+ }
+ else
+ {
+ using testing::_;
+ return EXPECT_CALL(*this, make(yield, _, _, _, _, _, _, rm, js));
+ }
+ }
+
+ auto& expectMake(
+ std::optional<std::reference_wrapper<const ReportParams>> paramsRef,
+ const testing::Matcher<interfaces::ReportManager&>& rm,
+ const testing::Matcher<interfaces::JsonStorage&>& js,
+ const testing::Matcher<std::vector<LabeledMetricParameters>>& lrp)
+ {
+ if (paramsRef)
+ {
+ const ReportParams& params = *paramsRef;
+ return EXPECT_CALL(*this,
+ make(params.reportName(), params.reportingType(),
+ params.emitReadingUpdate(),
+ params.logToMetricReportCollection(),
+ params.interval(),
+ params.readingParameters(), rm, js, lrp));
+ }
+ else
+ {
+ using testing::_;
+ return EXPECT_CALL(*this, make(_, _, _, _, _, _, rm, js, lrp));
+ }
+ }
};
diff --git a/tests/src/mocks/report_mock.hpp b/tests/src/mocks/report_mock.hpp
index 4943421..2f6ffac 100644
--- a/tests/src/mocks/report_mock.hpp
+++ b/tests/src/mocks/report_mock.hpp
@@ -18,8 +18,6 @@
return "/" + reportName;
});
- EXPECT_CALL(*this, getPath).Times(AnyNumber());
- EXPECT_CALL(*this, getName).Times(AnyNumber());
EXPECT_CALL(*this, Die).Times(AnyNumber());
}