176833cb5SWludzik, Jozef #pragma once 276833cb5SWludzik, Jozef 376833cb5SWludzik, Jozef #include "interfaces/trigger_factory.hpp" 476833cb5SWludzik, Jozef #include "mocks/trigger_mock.hpp" 576833cb5SWludzik, Jozef #include "params/trigger_params.hpp" 64416fce6SCezary Zwolak #include "trigger.hpp" 74416fce6SCezary Zwolak #include "utils/conversion_trigger.hpp" 894f71c51SSzymon Dompke #include "utils/transform.hpp" 976833cb5SWludzik, Jozef 1076833cb5SWludzik, Jozef #include <gmock/gmock.h> 1176833cb5SWludzik, Jozef 1276833cb5SWludzik, Jozef class TriggerFactoryMock : public interfaces::TriggerFactory 1376833cb5SWludzik, Jozef { 1476833cb5SWludzik, Jozef public: TriggerFactoryMock()1576833cb5SWludzik, Jozef TriggerFactoryMock() 1676833cb5SWludzik, Jozef { 1776833cb5SWludzik, Jozef using namespace testing; 1876833cb5SWludzik, Jozef 19e28aa53dSSzymon Dompke ON_CALL(*this, make(A<const std::string&>(), _, _, _, _, _, _, _)) 20e28aa53dSSzymon Dompke .WillByDefault(WithArgs<0>(Invoke([](const std::string& id) { 21e28aa53dSSzymon Dompke return std::make_unique<NiceMock<TriggerMock>>(id); 2276833cb5SWludzik, Jozef }))); 2376833cb5SWludzik, Jozef } 2476833cb5SWludzik, Jozef 254416fce6SCezary Zwolak MOCK_METHOD(std::unique_ptr<interfaces::Trigger>, make, 26e28aa53dSSzymon Dompke (const std::string& id, const std::string& name, 272001301aSSzymon Dompke const std::vector<std::string>& triggerActions, 28b8cc78ddSKrzysztof Grobelny const std::vector<std::string>& reportIds, 29a4e67616SCezary Zwolak interfaces::TriggerManager& triggerManager, 304416fce6SCezary Zwolak interfaces::JsonStorage& triggerStorage, 314416fce6SCezary Zwolak const LabeledTriggerThresholdParams& labeledThresholdParams, 324416fce6SCezary Zwolak const std::vector<LabeledSensorInfo>& labeledSensorsInfo), 334416fce6SCezary Zwolak (const, override)); 344416fce6SCezary Zwolak 354416fce6SCezary Zwolak MOCK_METHOD(std::vector<LabeledSensorInfo>, getLabeledSensorsInfo, 364416fce6SCezary Zwolak (boost::asio::yield_context&, const SensorsInfo&), 3776833cb5SWludzik, Jozef (const, override)); 3876833cb5SWludzik, Jozef 3994f71c51SSzymon Dompke MOCK_METHOD(std::vector<LabeledSensorInfo>, getLabeledSensorsInfo, 4094f71c51SSzymon Dompke (const SensorsInfo&), (const, override)); 4194f71c51SSzymon Dompke 4294f71c51SSzymon Dompke MOCK_METHOD(void, updateThresholds, 4394f71c51SSzymon Dompke (std::vector<std::shared_ptr<interfaces::Threshold>> & 4494f71c51SSzymon Dompke currentThresholds, 45b7b7e1b6SSzymon Dompke const std::string& triggerId, 4694f71c51SSzymon Dompke const std::vector<TriggerAction>& triggerActions, 4794f71c51SSzymon Dompke const std::shared_ptr<std::vector<std::string>>& reportIds, 4894f71c51SSzymon Dompke const Sensors& sensors, 4994f71c51SSzymon Dompke const LabeledTriggerThresholdParams& newParams), 5094f71c51SSzymon Dompke (const, override)); 5194f71c51SSzymon Dompke 5294f71c51SSzymon Dompke MOCK_METHOD(void, updateSensors, 5394f71c51SSzymon Dompke (Sensors & currentSensors, 5494f71c51SSzymon Dompke const std::vector<LabeledSensorInfo>& senorParams), 5594f71c51SSzymon Dompke (const, override)); 5694f71c51SSzymon Dompke expectMake(std::optional<TriggerParams> paramsOpt,const testing::Matcher<interfaces::TriggerManager &> & tm,const testing::Matcher<interfaces::JsonStorage &> & triggerStorage)5776833cb5SWludzik, Jozef auto& expectMake( 584416fce6SCezary Zwolak std::optional<TriggerParams> paramsOpt, 59a4e67616SCezary Zwolak const testing::Matcher<interfaces::TriggerManager&>& tm, 60a4e67616SCezary Zwolak const testing::Matcher<interfaces::JsonStorage&>& triggerStorage) 6176833cb5SWludzik, Jozef { 621477fe6aSWludzik, Jozef using namespace testing; 631477fe6aSWludzik, Jozef 6476833cb5SWludzik, Jozef if (paramsOpt) 6576833cb5SWludzik, Jozef { 6676833cb5SWludzik, Jozef const TriggerParams& params = *paramsOpt; 674416fce6SCezary Zwolak 684416fce6SCezary Zwolak const auto sensorInfos = 694416fce6SCezary Zwolak utils::fromLabeledSensorsInfo(params.sensors()); 704416fce6SCezary Zwolak 714416fce6SCezary Zwolak ON_CALL(*this, getLabeledSensorsInfo(_, sensorInfos)) 724416fce6SCezary Zwolak .WillByDefault(Return(params.sensors())); 734416fce6SCezary Zwolak 7476833cb5SWludzik, Jozef return EXPECT_CALL( 7594f71c51SSzymon Dompke *this, make(params.id(), params.name(), 76*c7935fa1SPatrick Williams utils::transform(params.triggerActions(), 7794f71c51SSzymon Dompke [](const auto& action) { 7894f71c51SSzymon Dompke return actionToString(action); 7994f71c51SSzymon Dompke }), 80b8cc78ddSKrzysztof Grobelny params.reportIds(), tm, triggerStorage, 814416fce6SCezary Zwolak params.thresholdParams(), params.sensors())); 8276833cb5SWludzik, Jozef } 8376833cb5SWludzik, Jozef else 8476833cb5SWludzik, Jozef { 854416fce6SCezary Zwolak const std::vector<LabeledSensorInfo> dummy = { 864416fce6SCezary Zwolak {"service99", 874416fce6SCezary Zwolak "/xyz/openbmc_project/sensors/temperature/BMC_Temp99", 884416fce6SCezary Zwolak "metadata99"}}; 894416fce6SCezary Zwolak 904416fce6SCezary Zwolak ON_CALL(*this, getLabeledSensorsInfo(_, _)) 914416fce6SCezary Zwolak .WillByDefault(Return(dummy)); 924416fce6SCezary Zwolak 932001301aSSzymon Dompke return EXPECT_CALL(*this, 94e28aa53dSSzymon Dompke make(_, _, _, _, tm, triggerStorage, _, dummy)); 9576833cb5SWludzik, Jozef } 9676833cb5SWludzik, Jozef } 9776833cb5SWludzik, Jozef }; 98