blob: cf9047f2cf9035f9f21c132e6c51b42d3b5c62e7 [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),
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010018 [](const auto& sensorData) {
Szymon Dompke94f71c52021-12-10 07:16:33 +010019 return LabeledSensorInfo(
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010020 "Service", std::get<0>(sensorData),
21 std::get<1>(sensorData));
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000022 }),
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010023 utils::toOperationType(std::get<1>(params)),
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010024 std::get<2>(params),
25 utils::toCollectionTimeScope(std::get<3>(params)),
26 CollectionDuration(Milliseconds(std::get<4>(params))));
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000027 });
28 }
29
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020030 public:
31 ReportFactoryMock()
32 {
33 using namespace testing;
34
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000035 ON_CALL(*this, convertMetricParams(_, _))
36 .WillByDefault(
37 WithArgs<1>(Invoke(&ReportFactoryMock::convertToLabeled)));
38
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010039 ON_CALL(*this,
Szymon Dompkeb4ef22e2022-02-07 15:15:12 +010040 make(A<const std::string&>(), _, _, _, _, _, _, _, _, _, _, _))
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010041 .WillByDefault(WithArgs<0>(Invoke([](const std::string& id) {
42 return std::make_unique<NiceMock<ReportMock>>(id);
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000043 })));
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020044 }
45
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000046 MOCK_METHOD(std::vector<LabeledMetricParameters>, convertMetricParams,
47 (boost::asio::yield_context&, const ReadingParameters&),
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000048 (const, override));
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000049
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000050 MOCK_METHOD(std::unique_ptr<interfaces::Report>, make,
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010051 (const std::string&, const std::string&, const ReportingType,
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010052 const std::vector<ReportAction>&, Milliseconds, uint64_t,
53 const ReportUpdates, interfaces::ReportManager&,
54 interfaces::JsonStorage&, std::vector<LabeledMetricParameters>,
Szymon Dompkeb4ef22e2022-02-07 15:15:12 +010055 bool, const std::vector<std::string>&),
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000056 (const, override));
57
58 auto& expectMake(
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000059 std::optional<std::reference_wrapper<const ReportParams>> paramsRef,
60 const testing::Matcher<interfaces::ReportManager&>& rm,
61 const testing::Matcher<interfaces::JsonStorage&>& js)
62 {
Szymon Dompkeb4ef22e2022-02-07 15:15:12 +010063 using testing::_;
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000064 if (paramsRef)
65 {
66 const ReportParams& params = *paramsRef;
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020067 return EXPECT_CALL(
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010068 *this, make(params.reportId(), params.reportName(),
69 params.reportingType(), params.reportActions(),
70 params.interval(), params.appendLimit(),
71 params.reportUpdates(), rm, js,
Szymon Dompkeb4ef22e2022-02-07 15:15:12 +010072 params.metricParameters(), params.enabled(), _));
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000073 }
74 else
75 {
Szymon Dompkeb4ef22e2022-02-07 15:15:12 +010076 return EXPECT_CALL(*this,
77 make(_, _, _, _, _, _, _, rm, js, _, _, _));
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000078 }
79 }
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020080};