Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 1 | #include "dbus_environment.hpp" |
| 2 | #include "helpers.hpp" |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 3 | #include "messages/collect_trigger_id.hpp" |
| 4 | #include "messages/trigger_presence_changed_ind.hpp" |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 5 | #include "mocks/json_storage_mock.hpp" |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 6 | #include "mocks/report_manager_mock.hpp" |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 7 | #include "mocks/sensor_mock.hpp" |
| 8 | #include "mocks/threshold_mock.hpp" |
| 9 | #include "mocks/trigger_factory_mock.hpp" |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 10 | #include "mocks/trigger_manager_mock.hpp" |
| 11 | #include "params/trigger_params.hpp" |
| 12 | #include "trigger.hpp" |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 13 | #include "trigger_manager.hpp" |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 14 | #include "utils/conversion_trigger.hpp" |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 15 | #include "utils/dbus_path_utils.hpp" |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 16 | #include "utils/messanger.hpp" |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 17 | #include "utils/string_utils.hpp" |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 18 | #include "utils/transform.hpp" |
| 19 | #include "utils/tstring.hpp" |
| 20 | |
| 21 | #include <boost/range/combine.hpp> |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 22 | |
| 23 | using namespace testing; |
| 24 | using namespace std::literals::string_literals; |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 25 | using sdbusplus::message::object_path; |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 26 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 27 | static constexpr size_t expectedTriggerVersion = 2; |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 28 | |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 29 | class TestTrigger : public Test |
| 30 | { |
| 31 | public: |
| 32 | TriggerParams triggerParams; |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 33 | TriggerParams triggerDiscreteParams = |
| 34 | TriggerParams() |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 35 | .id("DiscreteTrigger") |
| 36 | .name("My Discrete Trigger") |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 37 | .thresholdParams(std::vector<discrete::LabeledThresholdParam>{ |
| 38 | discrete::LabeledThresholdParam{ |
| 39 | "userId", discrete::Severity::warning, |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 40 | Milliseconds(10).count(), "15.2"}, |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 41 | discrete::LabeledThresholdParam{ |
| 42 | "userId_2", discrete::Severity::critical, |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 43 | Milliseconds(5).count(), "32.7"}, |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 44 | }); |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 45 | |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 46 | std::unique_ptr<ReportManagerMock> reportManagerMockPtr = |
| 47 | std::make_unique<NiceMock<ReportManagerMock>>(); |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 48 | std::unique_ptr<TriggerManagerMock> triggerManagerMockPtr = |
| 49 | std::make_unique<NiceMock<TriggerManagerMock>>(); |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 50 | std::unique_ptr<TriggerFactoryMock> triggerFactoryMockPtr = |
| 51 | std::make_unique<NiceMock<TriggerFactoryMock>>(); |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 52 | testing::NiceMock<StorageMock> storageMock; |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 53 | NiceMock<MockFunction<void(const messages::TriggerPresenceChangedInd)>> |
| 54 | triggerPresenceChanged; |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 55 | std::vector<std::shared_ptr<interfaces::Threshold>> thresholdMocks; |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 56 | utils::Messanger messanger; |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 57 | std::unique_ptr<Trigger> sut; |
| 58 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 59 | TestTrigger() : messanger(DbusEnvironment::getIoc()) |
| 60 | { |
| 61 | messanger.on_receive<messages::TriggerPresenceChangedInd>( |
| 62 | [this](const auto& msg) { triggerPresenceChanged.Call(msg); }); |
| 63 | } |
| 64 | |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 65 | void SetUp() override |
| 66 | { |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 67 | sut = makeTrigger(triggerParams); |
| 68 | } |
| 69 | |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 70 | static std::vector<LabeledSensorInfo> |
| 71 | convertToLabeledSensor(const SensorsInfo& sensorsInfo) |
| 72 | { |
| 73 | return utils::transform(sensorsInfo, [](const auto& sensorInfo) { |
| 74 | const auto& [sensorPath, sensorMetadata] = sensorInfo; |
| 75 | return LabeledSensorInfo("service1", sensorPath, sensorMetadata); |
| 76 | }); |
| 77 | } |
| 78 | |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 79 | std::unique_ptr<Trigger> makeTrigger(const TriggerParams& params) |
| 80 | { |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 81 | thresholdMocks = |
| 82 | ThresholdMock::makeThresholds(params.thresholdParams()); |
| 83 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 84 | auto id = std::make_unique<const std::string>(params.id()); |
| 85 | |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 86 | return std::make_unique<Trigger>( |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 87 | DbusEnvironment::getIoc(), DbusEnvironment::getObjServer(), |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 88 | std::move(id), params.name(), params.triggerActions(), |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 89 | std::make_shared<std::vector<std::string>>( |
| 90 | params.reportIds().begin(), params.reportIds().end()), |
| 91 | std::vector<std::shared_ptr<interfaces::Threshold>>(thresholdMocks), |
| 92 | *triggerManagerMockPtr, storageMock, *triggerFactoryMockPtr, |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 93 | SensorMock::makeSensorMocks(params.sensors())); |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | static interfaces::JsonStorage::FilePath to_file_path(std::string name) |
| 97 | { |
| 98 | return interfaces::JsonStorage::FilePath( |
| 99 | std::to_string(std::hash<std::string>{}(name))); |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | template <class T> |
| 103 | static T getProperty(const std::string& path, const std::string& property) |
| 104 | { |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 105 | return DbusEnvironment::getProperty<T>(path, Trigger::triggerIfaceName, |
| 106 | property); |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 107 | } |
| 108 | |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 109 | template <class T> |
| 110 | static boost::system::error_code setProperty(const std::string& path, |
| 111 | const std::string& property, |
| 112 | const T& newValue) |
| 113 | { |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 114 | return DbusEnvironment::setProperty<T>(path, Trigger::triggerIfaceName, |
| 115 | property, newValue); |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 116 | } |
| 117 | |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 118 | template <class T> |
| 119 | struct ChangePropertyParams |
| 120 | { |
| 121 | Matcher<T> valueBefore = _; |
| 122 | T newValue; |
| 123 | Matcher<boost::system::error_code> ec = |
| 124 | Eq(boost::system::errc::success); |
| 125 | Matcher<T> valueAfter = Eq(newValue); |
| 126 | }; |
| 127 | |
| 128 | template <class T> |
| 129 | static void changeProperty(const std::string& path, |
| 130 | const std::string& property, |
| 131 | ChangePropertyParams<T> p) |
| 132 | { |
| 133 | ASSERT_THAT(getProperty<T>(path, property), p.valueBefore); |
| 134 | ASSERT_THAT(setProperty<T>(path, property, p.newValue), p.ec); |
| 135 | EXPECT_THAT(getProperty<T>(path, property), p.valueAfter); |
| 136 | } |
| 137 | |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 138 | boost::system::error_code deleteTrigger(const std::string& path) |
| 139 | { |
| 140 | std::promise<boost::system::error_code> methodPromise; |
| 141 | DbusEnvironment::getBus()->async_method_call( |
| 142 | [&methodPromise](boost::system::error_code ec) { |
Patrick Williams | 3a1c297 | 2023-05-10 07:51:04 -0500 | [diff] [blame] | 143 | methodPromise.set_value(ec); |
Patrick Williams | f535cad | 2024-08-16 15:21:20 -0400 | [diff] [blame] | 144 | }, DbusEnvironment::serviceName(), path, Trigger::deleteIfaceName, |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 145 | "Delete"); |
| 146 | return DbusEnvironment::waitForFuture(methodPromise.get_future()); |
| 147 | } |
| 148 | }; |
| 149 | |
| 150 | TEST_F(TestTrigger, checkIfPropertiesAreSet) |
| 151 | { |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 152 | EXPECT_THAT(getProperty<std::string>(sut->getPath(), "Name"), |
| 153 | Eq(triggerParams.name())); |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 154 | EXPECT_THAT(getProperty<bool>(sut->getPath(), "Persistent"), Eq(true)); |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 155 | EXPECT_THAT( |
| 156 | getProperty<std::vector<std::string>>(sut->getPath(), "TriggerActions"), |
Patrick Williams | c7935fa | 2023-10-20 11:19:30 -0500 | [diff] [blame] | 157 | Eq(utils::transform( |
| 158 | triggerParams.triggerActions(), |
| 159 | [](const auto& action) { return actionToString(action); }))); |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 160 | EXPECT_THAT((getProperty<SensorsInfo>(sut->getPath(), "Sensors")), |
| 161 | Eq(utils::fromLabeledSensorsInfo(triggerParams.sensors()))); |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 162 | EXPECT_THAT( |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 163 | getProperty<std::vector<object_path>>(sut->getPath(), "Reports"), |
| 164 | Eq(triggerParams.reports())); |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 165 | EXPECT_THAT( |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 166 | getProperty<bool>(sut->getPath(), "Discrete"), |
| 167 | Eq(isTriggerThresholdDiscrete(triggerParams.thresholdParams()))); |
Ed Tanous | 2efa95d | 2024-10-19 11:36:53 -0700 | [diff] [blame] | 168 | |
| 169 | EXPECT_THAT(getProperty<std::vector<numeric::ThresholdParam>>( |
| 170 | sut->getPath(), "NumericThresholds"), |
| 171 | Eq(std::get<0>(utils::FromLabeledThresholdParamConversion()( |
| 172 | triggerParams.numericThresholdParams())))); |
| 173 | |
| 174 | EXPECT_THAT(getProperty<std::vector<discrete::ThresholdParam>>( |
| 175 | sut->getPath(), "DiscreteThresholds"), |
| 176 | Eq(std::get<1>(utils::FromLabeledThresholdParamConversion()( |
| 177 | triggerParams.discreteThresholdParams())))); |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 178 | } |
| 179 | |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 180 | TEST_F(TestTrigger, checkBasicGetters) |
| 181 | { |
| 182 | EXPECT_THAT(sut->getId(), Eq(triggerParams.id())); |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 183 | EXPECT_THAT(sut->getPath(), |
| 184 | Eq(utils::constants::triggerDirPath.str + triggerParams.id())); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 185 | } |
| 186 | |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 187 | TEST_F(TestTrigger, setPropertyNameToCorrectValue) |
| 188 | { |
| 189 | std::string name = "custom name 1234 %^#5"; |
| 190 | EXPECT_THAT(setProperty(sut->getPath(), "Name", name), |
| 191 | Eq(boost::system::errc::success)); |
| 192 | EXPECT_THAT(getProperty<std::string>(sut->getPath(), "Name"), Eq(name)); |
| 193 | } |
| 194 | |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 195 | TEST_F(TestTrigger, setPropertyReportNames) |
| 196 | { |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 197 | std::vector<object_path> newNames = { |
| 198 | utils::constants::reportDirPath / "abc", |
| 199 | utils::constants::reportDirPath / "one", |
| 200 | utils::constants::reportDirPath / "prefix" / "two"}; |
| 201 | EXPECT_THAT(setProperty(sut->getPath(), "Reports", newNames), |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 202 | Eq(boost::system::errc::success)); |
| 203 | EXPECT_THAT( |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 204 | getProperty<std::vector<object_path>>(sut->getPath(), "Reports"), |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 205 | Eq(newNames)); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 206 | } |
| 207 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 208 | TEST_F(TestTrigger, sendsUpdateWhenReportNamesChanges) |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 209 | { |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 210 | std::vector<object_path> newPropertyVal = { |
| 211 | utils::constants::reportDirPath / "abc", |
| 212 | utils::constants::reportDirPath / "one", |
| 213 | utils::constants::reportDirPath / "two"}; |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 214 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 215 | EXPECT_CALL(triggerPresenceChanged, |
| 216 | Call(FieldsAre(messages::Presence::Exist, triggerParams.id(), |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 217 | UnorderedElementsAre("abc", "one", "two")))); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 218 | |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 219 | EXPECT_THAT(setProperty(sut->getPath(), "Reports", newPropertyVal), |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 220 | Eq(boost::system::errc::success)); |
| 221 | } |
| 222 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 223 | TEST_F(TestTrigger, sendsUpdateWhenReportNamesChangesToSameValue) |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 224 | { |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 225 | const std::vector<object_path> newPropertyVal = triggerParams.reports(); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 226 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 227 | EXPECT_CALL( |
| 228 | triggerPresenceChanged, |
| 229 | Call(FieldsAre(messages::Presence::Exist, triggerParams.id(), |
| 230 | UnorderedElementsAreArray(triggerParams.reportIds())))); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 231 | |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 232 | EXPECT_THAT(setProperty(sut->getPath(), "Reports", newPropertyVal), |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 233 | Eq(boost::system::errc::success)); |
| 234 | } |
| 235 | |
| 236 | TEST_F(TestTrigger, |
Michal Orzel | b47b7db | 2024-09-16 10:02:29 +0200 | [diff] [blame] | 237 | settingPropertyReportNamesThrowsExceptionWhenDuplicateReportIds) |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 238 | { |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 239 | std::vector<object_path> newPropertyVal{ |
| 240 | utils::constants::reportDirPath / "report1", |
| 241 | utils::constants::reportDirPath / "report2", |
| 242 | utils::constants::reportDirPath / "report1"}; |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 243 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 244 | EXPECT_CALL(triggerPresenceChanged, Call(_)).Times(0); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 245 | |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 246 | EXPECT_THAT(setProperty(sut->getPath(), "Reports", newPropertyVal), |
| 247 | Eq(boost::system::errc::invalid_argument)); |
| 248 | } |
| 249 | |
Michal Orzel | b47b7db | 2024-09-16 10:02:29 +0200 | [diff] [blame] | 250 | TEST_F(TestTrigger, |
| 251 | settingPropertyReportNamesThrowsExceptionWhenReportWithTooManyPrefixes) |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 252 | { |
| 253 | std::vector<object_path> newPropertyVal{ |
| 254 | object_path("/xyz/openbmc_project/Telemetry/Reports/P1/P2/MyReport")}; |
| 255 | |
| 256 | EXPECT_CALL(triggerPresenceChanged, Call(_)).Times(0); |
| 257 | |
| 258 | EXPECT_THAT(setProperty(sut->getPath(), "Reports", newPropertyVal), |
| 259 | Eq(boost::system::errc::invalid_argument)); |
| 260 | } |
| 261 | |
Michal Orzel | b47b7db | 2024-09-16 10:02:29 +0200 | [diff] [blame] | 262 | TEST_F(TestTrigger, |
| 263 | settingPropertyReportNamesThrowsExceptionWhenReportWithTooLongPrefix) |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 264 | { |
| 265 | std::vector<object_path> newPropertyVal{ |
| 266 | object_path("/xyz/openbmc_project/Telemetry/Reports/" + |
| 267 | utils::string_utils::getTooLongPrefix() + "/MyReport")}; |
| 268 | |
| 269 | EXPECT_CALL(triggerPresenceChanged, Call(_)).Times(0); |
| 270 | |
| 271 | EXPECT_THAT(setProperty(sut->getPath(), "Reports", newPropertyVal), |
| 272 | Eq(boost::system::errc::invalid_argument)); |
| 273 | } |
| 274 | |
Michal Orzel | b47b7db | 2024-09-16 10:02:29 +0200 | [diff] [blame] | 275 | TEST_F(TestTrigger, |
| 276 | settingPropertyReportNamesThrowsExceptionWhenReportWithTooLongId) |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 277 | { |
| 278 | std::vector<object_path> newPropertyVal{ |
| 279 | object_path("/xyz/openbmc_project/Telemetry/Reports/Prefix/" + |
| 280 | utils::string_utils::getTooLongId())}; |
| 281 | |
| 282 | EXPECT_CALL(triggerPresenceChanged, Call(_)).Times(0); |
| 283 | |
| 284 | EXPECT_THAT(setProperty(sut->getPath(), "Reports", newPropertyVal), |
| 285 | Eq(boost::system::errc::invalid_argument)); |
| 286 | } |
| 287 | |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 288 | TEST_F(TestTrigger, |
Michal Orzel | b47b7db | 2024-09-16 10:02:29 +0200 | [diff] [blame] | 289 | settingPropertyReportNamesThrowsExceptionWhenReportWithBadPath) |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 290 | { |
| 291 | std::vector<object_path> newPropertyVal{ |
| 292 | object_path("/xyz/openbmc_project/Telemetry/NotReports/MyReport")}; |
| 293 | |
| 294 | EXPECT_CALL(triggerPresenceChanged, Call(_)).Times(0); |
| 295 | |
| 296 | EXPECT_THAT(setProperty(sut->getPath(), "Reports", newPropertyVal), |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 297 | Eq(boost::system::errc::invalid_argument)); |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | TEST_F(TestTrigger, setPropertySensors) |
| 301 | { |
| 302 | EXPECT_CALL(*triggerFactoryMockPtr, updateSensors(_, _)); |
| 303 | for (const auto& threshold : thresholdMocks) |
| 304 | { |
| 305 | auto thresholdMockPtr = |
| 306 | std::dynamic_pointer_cast<NiceMock<ThresholdMock>>(threshold); |
| 307 | EXPECT_CALL(*thresholdMockPtr, updateSensors(_)); |
| 308 | } |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 309 | SensorsInfo newSensors( |
| 310 | {std::make_pair(object_path("/abc/def"), "metadata")}); |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 311 | EXPECT_THAT(setProperty(sut->getPath(), "Sensors", newSensors), |
| 312 | Eq(boost::system::errc::success)); |
| 313 | } |
| 314 | |
| 315 | TEST_F(TestTrigger, setPropertyThresholds) |
| 316 | { |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 317 | EXPECT_CALL(*triggerFactoryMockPtr, updateThresholds(_, _, _, _, _, _)); |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 318 | TriggerThresholdParams newThresholds = |
Krzysztof Grobelny | cff70c1 | 2022-10-27 07:16:08 +0000 | [diff] [blame] | 319 | std::vector<discrete::ThresholdParam>({std::make_tuple( |
| 320 | "discrete threshold", utils::enumToString(discrete::Severity::ok), |
| 321 | 10, "12.3")}); |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 322 | EXPECT_THAT(setProperty(sut->getPath(), "Thresholds", newThresholds), |
| 323 | Eq(boost::system::errc::success)); |
| 324 | } |
| 325 | |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 326 | TEST_F(TestTrigger, setThresholdParamsWithTooLongDiscreteName) |
| 327 | { |
| 328 | const TriggerThresholdParams currentValue = |
| 329 | std::visit(utils::FromLabeledThresholdParamConversion(), |
| 330 | triggerParams.thresholdParams()); |
| 331 | |
| 332 | TriggerThresholdParams newThresholds = |
| 333 | std::vector<discrete::ThresholdParam>({std::make_tuple( |
Krzysztof Grobelny | cff70c1 | 2022-10-27 07:16:08 +0000 | [diff] [blame] | 334 | utils::string_utils::getTooLongName(), |
| 335 | utils::enumToString(discrete::Severity::ok), 10, "12.3")}); |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 336 | |
| 337 | changeProperty<TriggerThresholdParams>( |
| 338 | sut->getPath(), "Thresholds", |
| 339 | {.valueBefore = Eq(currentValue), |
| 340 | .newValue = newThresholds, |
| 341 | .ec = Eq(boost::system::errc::invalid_argument), |
| 342 | .valueAfter = Eq(currentValue)}); |
| 343 | } |
| 344 | |
| 345 | TEST_F(TestTrigger, setNameTooLong) |
| 346 | { |
| 347 | std::string currentValue = TriggerParams().name(); |
| 348 | |
| 349 | changeProperty<std::string>( |
| 350 | sut->getPath(), "Name", |
| 351 | {.valueBefore = Eq(currentValue), |
| 352 | .newValue = utils::string_utils::getTooLongName(), |
| 353 | .ec = Eq(boost::system::errc::invalid_argument), |
| 354 | .valueAfter = Eq(currentValue)}); |
| 355 | } |
| 356 | |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 357 | TEST_F(TestTrigger, checkIfNumericCoversionsAreGood) |
| 358 | { |
| 359 | const auto& labeledParamsBase = |
| 360 | std::get<std::vector<numeric::LabeledThresholdParam>>( |
| 361 | triggerParams.thresholdParams()); |
| 362 | const auto paramsToCheck = |
| 363 | std::visit(utils::FromLabeledThresholdParamConversion(), |
| 364 | triggerParams.thresholdParams()); |
| 365 | const auto labeledParamsToCheck = |
| 366 | std::get<std::vector<numeric::LabeledThresholdParam>>(std::visit( |
| 367 | utils::ToLabeledThresholdParamConversion(), paramsToCheck)); |
| 368 | |
| 369 | for (const auto& [tocheck, base] : |
| 370 | boost::combine(labeledParamsToCheck, labeledParamsBase)) |
| 371 | { |
| 372 | EXPECT_THAT(tocheck.at_label<utils::tstring::Type>(), |
| 373 | Eq(base.at_label<utils::tstring::Type>())); |
| 374 | EXPECT_THAT(tocheck.at_label<utils::tstring::Direction>(), |
| 375 | Eq(base.at_label<utils::tstring::Direction>())); |
| 376 | EXPECT_THAT(tocheck.at_label<utils::tstring::DwellTime>(), |
| 377 | Eq(base.at_label<utils::tstring::DwellTime>())); |
| 378 | EXPECT_THAT(tocheck.at_label<utils::tstring::ThresholdValue>(), |
| 379 | Eq(base.at_label<utils::tstring::ThresholdValue>())); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | TEST_F(TestTrigger, checkIfDiscreteCoversionsAreGood) |
| 384 | { |
| 385 | const auto& labeledParamsBase = |
| 386 | std::get<std::vector<discrete::LabeledThresholdParam>>( |
| 387 | triggerDiscreteParams.thresholdParams()); |
| 388 | const auto paramsToCheck = |
| 389 | std::visit(utils::FromLabeledThresholdParamConversion(), |
| 390 | triggerDiscreteParams.thresholdParams()); |
| 391 | const auto labeledParamsToCheck = |
| 392 | std::get<std::vector<discrete::LabeledThresholdParam>>(std::visit( |
| 393 | utils::ToLabeledThresholdParamConversion(), paramsToCheck)); |
| 394 | |
| 395 | for (const auto& [tocheck, base] : |
| 396 | boost::combine(labeledParamsToCheck, labeledParamsBase)) |
| 397 | { |
| 398 | EXPECT_THAT(tocheck.at_label<utils::tstring::UserId>(), |
| 399 | Eq(base.at_label<utils::tstring::UserId>())); |
| 400 | EXPECT_THAT(tocheck.at_label<utils::tstring::Severity>(), |
| 401 | Eq(base.at_label<utils::tstring::Severity>())); |
| 402 | EXPECT_THAT(tocheck.at_label<utils::tstring::DwellTime>(), |
| 403 | Eq(base.at_label<utils::tstring::DwellTime>())); |
| 404 | EXPECT_THAT(tocheck.at_label<utils::tstring::ThresholdValue>(), |
| 405 | Eq(base.at_label<utils::tstring::ThresholdValue>())); |
| 406 | } |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | TEST_F(TestTrigger, deleteTrigger) |
| 410 | { |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 411 | EXPECT_CALL(storageMock, remove(to_file_path(sut->getId()))); |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 412 | EXPECT_CALL(*triggerManagerMockPtr, removeTrigger(sut.get())); |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 413 | |
| 414 | auto ec = deleteTrigger(sut->getPath()); |
| 415 | EXPECT_THAT(ec, Eq(boost::system::errc::success)); |
| 416 | } |
| 417 | |
| 418 | TEST_F(TestTrigger, sendUpdateWhenTriggerIsDeleted) |
| 419 | { |
| 420 | EXPECT_CALL(triggerPresenceChanged, |
| 421 | Call(FieldsAre(messages::Presence::Removed, triggerParams.id(), |
| 422 | UnorderedElementsAre()))); |
| 423 | |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 424 | auto ec = deleteTrigger(sut->getPath()); |
| 425 | EXPECT_THAT(ec, Eq(boost::system::errc::success)); |
| 426 | } |
| 427 | |
| 428 | TEST_F(TestTrigger, deletingNonExistingTriggerReturnInvalidRequestDescriptor) |
| 429 | { |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 430 | auto ec = |
| 431 | deleteTrigger(utils::constants::triggerDirPath.str + "NonExisting"s); |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 432 | EXPECT_THAT(ec.value(), Eq(EBADR)); |
| 433 | } |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 434 | |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 435 | TEST_F(TestTrigger, settingPersistencyToFalseRemovesTriggerFromStorage) |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 436 | { |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 437 | EXPECT_CALL(storageMock, remove(to_file_path(sut->getId()))); |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 438 | |
| 439 | bool persistent = false; |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 440 | EXPECT_THAT(setProperty(sut->getPath(), "Persistent", persistent), |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 441 | Eq(boost::system::errc::success)); |
| 442 | EXPECT_THAT(getProperty<bool>(sut->getPath(), "Persistent"), |
| 443 | Eq(persistent)); |
| 444 | } |
| 445 | |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 446 | class TestTriggerInitialization : public TestTrigger |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 447 | { |
| 448 | public: |
Patrick Williams | 3a1c297 | 2023-05-10 07:51:04 -0500 | [diff] [blame] | 449 | void SetUp() override {} |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 450 | |
| 451 | nlohmann::json storedConfiguration; |
| 452 | }; |
| 453 | |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 454 | TEST_F(TestTriggerInitialization, |
| 455 | exceptionDuringTriggerStoreDisablesPersistency) |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 456 | { |
| 457 | EXPECT_CALL(storageMock, store(_, _)) |
| 458 | .WillOnce(Throw(std::runtime_error("Generic error!"))); |
| 459 | |
| 460 | sut = makeTrigger(triggerParams); |
| 461 | |
| 462 | EXPECT_THAT(getProperty<bool>(sut->getPath(), "Persistent"), Eq(false)); |
| 463 | } |
| 464 | |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 465 | TEST_F(TestTriggerInitialization, creatingTriggerThrowsExceptionWhenIdIsInvalid) |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 466 | { |
| 467 | EXPECT_CALL(storageMock, store(_, _)).Times(0); |
| 468 | |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 469 | EXPECT_THROW(makeTrigger(triggerParams.id("inv?lidId")), |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 470 | sdbusplus::exception::SdBusError); |
| 471 | } |
| 472 | |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 473 | TEST_F(TestTriggerInitialization, creatingTriggerUpdatesTriggersIdsInReports) |
| 474 | { |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 475 | EXPECT_CALL( |
| 476 | triggerPresenceChanged, |
| 477 | Call(FieldsAre(messages::Presence::Exist, triggerParams.id(), |
| 478 | UnorderedElementsAreArray(triggerParams.reportIds())))); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 479 | |
| 480 | sut = makeTrigger(triggerParams); |
| 481 | } |
| 482 | |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 483 | class TestTriggerStore : public TestTrigger |
| 484 | { |
| 485 | public: |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 486 | nlohmann::json storedConfiguration; |
| 487 | nlohmann::json storedDiscreteConfiguration; |
| 488 | std::unique_ptr<Trigger> sutDiscrete; |
| 489 | |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 490 | void SetUp() override |
| 491 | { |
| 492 | ON_CALL(storageMock, store(_, _)) |
| 493 | .WillByDefault(SaveArg<1>(&storedConfiguration)); |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 494 | sut = makeTrigger(triggerParams); |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 495 | |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 496 | ON_CALL(storageMock, store(_, _)) |
| 497 | .WillByDefault(SaveArg<1>(&storedDiscreteConfiguration)); |
| 498 | sutDiscrete = makeTrigger(triggerDiscreteParams); |
| 499 | } |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 500 | }; |
| 501 | |
| 502 | TEST_F(TestTriggerStore, settingPersistencyToTrueStoresTriggerVersion) |
| 503 | { |
| 504 | ASSERT_THAT(storedConfiguration.at("Version"), Eq(expectedTriggerVersion)); |
| 505 | } |
| 506 | |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 507 | TEST_F(TestTriggerStore, settingPersistencyToTrueStoresTriggerId) |
| 508 | { |
| 509 | ASSERT_THAT(storedConfiguration.at("Id"), Eq(triggerParams.id())); |
| 510 | } |
| 511 | |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 512 | TEST_F(TestTriggerStore, settingPersistencyToTrueStoresTriggerName) |
| 513 | { |
| 514 | ASSERT_THAT(storedConfiguration.at("Name"), Eq(triggerParams.name())); |
| 515 | } |
| 516 | |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 517 | TEST_F(TestTriggerStore, settingPersistencyToTrueStoresTriggerTriggerActions) |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 518 | { |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 519 | ASSERT_THAT(storedConfiguration.at("TriggerActions"), |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 520 | Eq(utils::transform(triggerParams.triggerActions(), |
| 521 | [](const auto& action) { |
Patrick Williams | 3a1c297 | 2023-05-10 07:51:04 -0500 | [diff] [blame] | 522 | return actionToString(action); |
Patrick Williams | c7935fa | 2023-10-20 11:19:30 -0500 | [diff] [blame] | 523 | }))); |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 524 | } |
| 525 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 526 | TEST_F(TestTriggerStore, settingPersistencyToTrueStoresTriggerReportIds) |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 527 | { |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 528 | ASSERT_THAT(storedConfiguration.at("ReportIds"), |
| 529 | Eq(triggerParams.reportIds())); |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | TEST_F(TestTriggerStore, settingPersistencyToTrueStoresTriggerSensors) |
| 533 | { |
| 534 | nlohmann::json expectedItem; |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 535 | expectedItem["service"] = "service1"; |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 536 | expectedItem["path"] = "/xyz/openbmc_project/sensors/temperature/BMC_Temp"; |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 537 | expectedItem["metadata"] = "metadata1"; |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 538 | |
| 539 | ASSERT_THAT(storedConfiguration.at("Sensors"), ElementsAre(expectedItem)); |
| 540 | } |
| 541 | |
| 542 | TEST_F(TestTriggerStore, settingPersistencyToTrueStoresTriggerThresholdParams) |
| 543 | { |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 544 | nlohmann::json expectedItem0; |
| 545 | expectedItem0["type"] = 0; |
| 546 | expectedItem0["dwellTime"] = 10; |
| 547 | expectedItem0["direction"] = 1; |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 548 | expectedItem0["thresholdValue"] = 0.5; |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 549 | |
| 550 | nlohmann::json expectedItem1; |
| 551 | expectedItem1["type"] = 3; |
| 552 | expectedItem1["dwellTime"] = 10; |
| 553 | expectedItem1["direction"] = 2; |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 554 | expectedItem1["thresholdValue"] = 90.2; |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 555 | |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 556 | ASSERT_THAT(storedConfiguration.at("ThresholdParamsDiscriminator"), Eq(0)); |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 557 | ASSERT_THAT(storedConfiguration.at("ThresholdParams"), |
| 558 | ElementsAre(expectedItem0, expectedItem1)); |
| 559 | } |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 560 | |
| 561 | TEST_F(TestTriggerStore, |
| 562 | settingPersistencyToTrueStoresDiscreteTriggerThresholdParams) |
| 563 | { |
| 564 | nlohmann::json expectedItem0; |
| 565 | expectedItem0["userId"] = "userId"; |
| 566 | expectedItem0["severity"] = discrete::Severity::warning; |
| 567 | expectedItem0["dwellTime"] = 10; |
Szymon Dompke | 9f34679 | 2021-07-14 21:07:11 +0200 | [diff] [blame] | 568 | expectedItem0["thresholdValue"] = "15.2"; |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 569 | |
| 570 | nlohmann::json expectedItem1; |
| 571 | expectedItem1["userId"] = "userId_2"; |
| 572 | expectedItem1["severity"] = discrete::Severity::critical; |
| 573 | expectedItem1["dwellTime"] = 5; |
Szymon Dompke | 9f34679 | 2021-07-14 21:07:11 +0200 | [diff] [blame] | 574 | expectedItem1["thresholdValue"] = "32.7"; |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 575 | |
| 576 | ASSERT_THAT(storedDiscreteConfiguration.at("ThresholdParamsDiscriminator"), |
| 577 | Eq(1)); |
| 578 | ASSERT_THAT(storedDiscreteConfiguration.at("ThresholdParams"), |
| 579 | ElementsAre(expectedItem0, expectedItem1)); |
| 580 | } |