1 #pragma once 2 3 #include "interfaces/report_factory.hpp" 4 #include "mocks/report_mock.hpp" 5 #include "params/report_params.hpp" 6 #include "utils/transform.hpp" 7 8 #include <gmock/gmock.h> 9 10 class ReportFactoryMock : public interfaces::ReportFactory 11 { 12 static std::vector<LabeledMetricParameters> 13 convertToLabeled(const ReadingParameters& readingParams) 14 { 15 return utils::transform(readingParams, [](const auto& params) { 16 return LabeledMetricParameters( 17 utils::transform(std::get<0>(params), 18 [](const auto& sensorData) { 19 return LabeledSensorInfo( 20 "Service", std::get<0>(sensorData), 21 std::get<1>(sensorData)); 22 }), 23 utils::toOperationType(std::get<1>(params)), 24 std::get<2>(params), 25 utils::toCollectionTimeScope(std::get<3>(params)), 26 CollectionDuration(Milliseconds(std::get<4>(params)))); 27 }); 28 } 29 30 public: 31 ReportFactoryMock() 32 { 33 using namespace testing; 34 35 ON_CALL(*this, convertMetricParams(_, _)) 36 .WillByDefault( 37 WithArgs<1>(Invoke(&ReportFactoryMock::convertToLabeled))); 38 39 ON_CALL(*this, 40 make(A<const std::string&>(), _, _, _, _, _, _, _, _, _, _)) 41 .WillByDefault(WithArgs<0>(Invoke([](const std::string& id) { 42 return std::make_unique<NiceMock<ReportMock>>(id); 43 }))); 44 } 45 46 MOCK_METHOD(std::vector<LabeledMetricParameters>, convertMetricParams, 47 (boost::asio::yield_context&, const ReadingParameters&), 48 (const, override)); 49 50 MOCK_METHOD(std::unique_ptr<interfaces::Report>, make, 51 (const std::string&, const std::string&, const ReportingType, 52 const std::vector<ReportAction>&, Milliseconds, uint64_t, 53 const ReportUpdates, interfaces::ReportManager&, 54 interfaces::JsonStorage&, std::vector<LabeledMetricParameters>, 55 bool), 56 (const, override)); 57 58 auto& expectMake( 59 std::optional<std::reference_wrapper<const ReportParams>> paramsRef, 60 const testing::Matcher<interfaces::ReportManager&>& rm, 61 const testing::Matcher<interfaces::JsonStorage&>& js) 62 { 63 if (paramsRef) 64 { 65 const ReportParams& params = *paramsRef; 66 return EXPECT_CALL( 67 *this, make(params.reportId(), params.reportName(), 68 params.reportingType(), params.reportActions(), 69 params.interval(), params.appendLimit(), 70 params.reportUpdates(), rm, js, 71 params.metricParameters(), params.enabled())); 72 } 73 else 74 { 75 using testing::_; 76 return EXPECT_CALL(*this, make(_, _, _, _, _, _, _, rm, js, _, _)); 77 } 78 } 79 }; 80