blob: cc0bc8e102866c91a5e3ef487dcbbc12eb56a04b [file] [log] [blame]
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +02001#pragma once
2
3#include "interfaces/report_factory.hpp"
4#include "mocks/report_mock.hpp"
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +00005#include "params/report_params.hpp"
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +00006#include "utils/transform.hpp"
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +02007
8#include <gmock/gmock.h>
9
10class ReportFactoryMock : public interfaces::ReportFactory
11{
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000012 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& sensorPath) {
19 return LabeledSensorParameters("Service",
20 sensorPath);
21 }),
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010022 utils::toOperationType(std::get<1>(params)),
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000023 std::get<2>(params), std::get<3>(params),
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010024 utils::toCollectionTimeScope(std::get<4>(params)),
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000025 CollectionDuration(Milliseconds(std::get<5>(params))));
26 });
27 }
28
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020029 public:
30 ReportFactoryMock()
31 {
32 using namespace testing;
33
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000034 ON_CALL(*this, convertMetricParams(_, _))
35 .WillByDefault(
36 WithArgs<1>(Invoke(&ReportFactoryMock::convertToLabeled)));
37
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010038 ON_CALL(*this, make(A<const std::string&>(), _, _, _, _, _, _, _, _, _))
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000039 .WillByDefault(WithArgs<0>(Invoke([](const std::string& name) {
40 return std::make_unique<NiceMock<ReportMock>>(name);
41 })));
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020042 }
43
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000044 MOCK_METHOD(std::vector<LabeledMetricParameters>, convertMetricParams,
45 (boost::asio::yield_context&, const ReadingParameters&),
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000046 (const, override));
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000047
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000048 MOCK_METHOD(std::unique_ptr<interfaces::Report>, make,
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010049 (const std::string&, const ReportingType,
50 const std::vector<ReportAction>&, Milliseconds, uint64_t,
51 const ReportUpdates, interfaces::ReportManager&,
52 interfaces::JsonStorage&, std::vector<LabeledMetricParameters>,
53 bool),
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000054 (const, override));
55
56 auto& expectMake(
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000057 std::optional<std::reference_wrapper<const ReportParams>> paramsRef,
58 const testing::Matcher<interfaces::ReportManager&>& rm,
59 const testing::Matcher<interfaces::JsonStorage&>& js)
60 {
61 if (paramsRef)
62 {
63 const ReportParams& params = *paramsRef;
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020064 return EXPECT_CALL(
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010065 *this, make(params.reportName(), params.reportingType(),
66 params.reportActions(), params.interval(),
67 params.appendLimit(), params.reportUpdates(), rm,
68 js, params.metricParameters(), params.enabled()));
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000069 }
70 else
71 {
72 using testing::_;
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010073 return EXPECT_CALL(*this, make(_, _, _, _, _, _, rm, js, _, _));
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000074 }
75 }
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020076};