blob: 80a62a10ac7220f466389af6ab95535012e6f21e [file] [log] [blame]
Wludzik, Jozef76833cb2020-12-21 14:42:41 +01001#pragma once
2
3#include "interfaces/trigger_factory.hpp"
4#include "mocks/trigger_mock.hpp"
5#include "params/trigger_params.hpp"
Cezary Zwolak4416fce2021-03-17 03:21:06 +01006#include "trigger.hpp"
7#include "utils/conversion_trigger.hpp"
Szymon Dompke94f71c52021-12-10 07:16:33 +01008#include "utils/transform.hpp"
Wludzik, Jozef76833cb2020-12-21 14:42:41 +01009
10#include <gmock/gmock.h>
11
12class TriggerFactoryMock : public interfaces::TriggerFactory
13{
14 public:
15 TriggerFactoryMock()
16 {
17 using namespace testing;
18
Szymon Dompkee28aa532021-10-27 12:33:12 +020019 ON_CALL(*this, make(A<const std::string&>(), _, _, _, _, _, _, _))
20 .WillByDefault(WithArgs<0>(Invoke([](const std::string& id) {
21 return std::make_unique<NiceMock<TriggerMock>>(id);
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010022 })));
23 }
24
Cezary Zwolak4416fce2021-03-17 03:21:06 +010025 MOCK_METHOD(std::unique_ptr<interfaces::Trigger>, make,
Szymon Dompkee28aa532021-10-27 12:33:12 +020026 (const std::string& id, const std::string& name,
Szymon Dompke20013012021-07-23 09:54:20 +020027 const std::vector<std::string>& triggerActions,
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010028 const std::vector<std::string>& reportIds,
Cezary Zwolak4416fce2021-03-17 03:21:06 +010029 interfaces::TriggerManager& triggerManager,
30 interfaces::JsonStorage& triggerStorage,
31 const LabeledTriggerThresholdParams& labeledThresholdParams,
32 const std::vector<LabeledSensorInfo>& labeledSensorsInfo),
33 (const, override));
34
35 MOCK_METHOD(std::vector<LabeledSensorInfo>, getLabeledSensorsInfo,
36 (boost::asio::yield_context&, const SensorsInfo&),
37 (const, override));
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010038
Szymon Dompke94f71c52021-12-10 07:16:33 +010039 MOCK_METHOD(std::vector<LabeledSensorInfo>, getLabeledSensorsInfo,
40 (const SensorsInfo&), (const, override));
41
42 MOCK_METHOD(void, updateThresholds,
43 (std::vector<std::shared_ptr<interfaces::Threshold>> &
44 currentThresholds,
45 const std::vector<TriggerAction>& triggerActions,
46 const std::shared_ptr<std::vector<std::string>>& reportIds,
47 const Sensors& sensors,
48 const LabeledTriggerThresholdParams& newParams),
49 (const, override));
50
51 MOCK_METHOD(void, updateSensors,
52 (Sensors & currentSensors,
53 const std::vector<LabeledSensorInfo>& senorParams),
54 (const, override));
55
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010056 auto& expectMake(
Cezary Zwolak4416fce2021-03-17 03:21:06 +010057 std::optional<TriggerParams> paramsOpt,
Cezary Zwolaka4e67612021-02-18 13:16:16 +010058 const testing::Matcher<interfaces::TriggerManager&>& tm,
59 const testing::Matcher<interfaces::JsonStorage&>& triggerStorage)
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010060 {
Wludzik, Jozef1477fe62021-01-02 11:56:10 +010061 using namespace testing;
62
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010063 if (paramsOpt)
64 {
65 const TriggerParams& params = *paramsOpt;
Cezary Zwolak4416fce2021-03-17 03:21:06 +010066
67 const auto sensorInfos =
68 utils::fromLabeledSensorsInfo(params.sensors());
69
70 ON_CALL(*this, getLabeledSensorsInfo(_, sensorInfos))
71 .WillByDefault(Return(params.sensors()));
72
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010073 return EXPECT_CALL(
Szymon Dompke94f71c52021-12-10 07:16:33 +010074 *this, make(params.id(), params.name(),
75 utils::transform(params.triggerActions(),
76 [](const auto& action) {
77 return actionToString(action);
78 }),
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010079 params.reportIds(), tm, triggerStorage,
Szymon Dompke20013012021-07-23 09:54:20 +020080 params.thresholdParams(), params.sensors()));
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010081 }
82 else
83 {
Cezary Zwolak4416fce2021-03-17 03:21:06 +010084 const std::vector<LabeledSensorInfo> dummy = {
85 {"service99",
86 "/xyz/openbmc_project/sensors/temperature/BMC_Temp99",
87 "metadata99"}};
88
89 ON_CALL(*this, getLabeledSensorsInfo(_, _))
90 .WillByDefault(Return(dummy));
91
Szymon Dompke20013012021-07-23 09:54:20 +020092 return EXPECT_CALL(*this,
Szymon Dompkee28aa532021-10-27 12:33:12 +020093 make(_, _, _, _, tm, triggerStorage, _, dummy));
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010094 }
95 }
96};