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(
18                     std::get<0>(params),
19                     [](const auto& sensorData) {
20                 return LabeledSensorInfo("Service", std::get<0>(sensorData),
21                                          std::get<1>(sensorData));
22                     }),
23                 utils::toOperationType(std::get<1>(params)),
24                 utils::toCollectionTimeScope(std::get<2>(params)),
25                 CollectionDuration(Milliseconds(std::get<3>(params))));
26         });
27     }
28 
29   public:
30     ReportFactoryMock()
31     {
32         using namespace testing;
33 
34         ON_CALL(*this, convertMetricParams(_))
35             .WillByDefault(
36                 WithArgs<0>(Invoke(&ReportFactoryMock::convertToLabeled)));
37 
38         ON_CALL(*this, convertMetricParams(_, _))
39             .WillByDefault(
40                 WithArgs<1>(Invoke(&ReportFactoryMock::convertToLabeled)));
41 
42         ON_CALL(*this,
43                 make(A<const std::string&>(), _, _, _, _, _, _, _, _, _, _, _))
44             .WillByDefault(WithArgs<0>(Invoke([](const std::string& id) {
45                 return std::make_unique<NiceMock<ReportMock>>(id);
46             })));
47     }
48 
49     MOCK_METHOD(std::vector<LabeledMetricParameters>, convertMetricParams,
50                 (boost::asio::yield_context&, const ReadingParameters&),
51                 (const, override));
52 
53     MOCK_METHOD(std::vector<LabeledMetricParameters>, convertMetricParams,
54                 (const ReadingParameters&), (const, override));
55 
56     MOCK_METHOD(void, updateMetrics,
57                 (std::vector<std::shared_ptr<interfaces::Metric>> & metrics,
58                  bool enabled, const std::vector<LabeledMetricParameters>&),
59                 (const, override));
60 
61     MOCK_METHOD(std::unique_ptr<interfaces::Report>, make,
62                 (const std::string&, const std::string&, const ReportingType,
63                  const std::vector<ReportAction>&, Milliseconds, uint64_t,
64                  const ReportUpdates, interfaces::ReportManager&,
65                  interfaces::JsonStorage&, std::vector<LabeledMetricParameters>,
66                  bool, Readings),
67                 (const, override));
68 
69     auto& expectMake(
70         std::optional<std::reference_wrapper<const ReportParams>> paramsRef,
71         const testing::Matcher<interfaces::ReportManager&>& rm,
72         const testing::Matcher<interfaces::JsonStorage&>& js)
73     {
74         using testing::_;
75         if (paramsRef)
76         {
77             const ReportParams& params = *paramsRef;
78             return EXPECT_CALL(
79                 *this,
80                 make(params.reportId(), params.reportName(),
81                      params.reportingType(), params.reportActions(),
82                      params.interval(), params.appendLimit(),
83                      params.reportUpdates(), rm, js, params.metricParameters(),
84                      params.enabled(), params.readings()));
85         }
86         else
87         {
88             return EXPECT_CALL(*this,
89                                make(_, _, _, _, _, _, _, rm, js, _, _, _));
90         }
91     }
92 };
93