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()))); |
| 168 | EXPECT_THAT( |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 169 | getProperty<TriggerThresholdParams>(sut->getPath(), "Thresholds"), |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 170 | Eq(std::visit(utils::FromLabeledThresholdParamConversion(), |
| 171 | triggerParams.thresholdParams()))); |
| 172 | } |
| 173 | |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 174 | TEST_F(TestTrigger, checkBasicGetters) |
| 175 | { |
| 176 | EXPECT_THAT(sut->getId(), Eq(triggerParams.id())); |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 177 | EXPECT_THAT(sut->getPath(), |
| 178 | Eq(utils::constants::triggerDirPath.str + triggerParams.id())); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 179 | } |
| 180 | |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 181 | TEST_F(TestTrigger, setPropertyNameToCorrectValue) |
| 182 | { |
| 183 | std::string name = "custom name 1234 %^#5"; |
| 184 | EXPECT_THAT(setProperty(sut->getPath(), "Name", name), |
| 185 | Eq(boost::system::errc::success)); |
| 186 | EXPECT_THAT(getProperty<std::string>(sut->getPath(), "Name"), Eq(name)); |
| 187 | } |
| 188 | |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 189 | TEST_F(TestTrigger, setPropertyReportNames) |
| 190 | { |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 191 | std::vector<object_path> newNames = { |
| 192 | utils::constants::reportDirPath / "abc", |
| 193 | utils::constants::reportDirPath / "one", |
| 194 | utils::constants::reportDirPath / "prefix" / "two"}; |
| 195 | EXPECT_THAT(setProperty(sut->getPath(), "Reports", newNames), |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 196 | Eq(boost::system::errc::success)); |
| 197 | EXPECT_THAT( |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 198 | getProperty<std::vector<object_path>>(sut->getPath(), "Reports"), |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 199 | Eq(newNames)); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 200 | } |
| 201 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 202 | TEST_F(TestTrigger, sendsUpdateWhenReportNamesChanges) |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 203 | { |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 204 | std::vector<object_path> newPropertyVal = { |
| 205 | utils::constants::reportDirPath / "abc", |
| 206 | utils::constants::reportDirPath / "one", |
| 207 | utils::constants::reportDirPath / "two"}; |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 208 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 209 | EXPECT_CALL(triggerPresenceChanged, |
| 210 | Call(FieldsAre(messages::Presence::Exist, triggerParams.id(), |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 211 | UnorderedElementsAre("abc", "one", "two")))); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 212 | |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 213 | EXPECT_THAT(setProperty(sut->getPath(), "Reports", newPropertyVal), |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 214 | Eq(boost::system::errc::success)); |
| 215 | } |
| 216 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 217 | TEST_F(TestTrigger, sendsUpdateWhenReportNamesChangesToSameValue) |
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 | const std::vector<object_path> newPropertyVal = triggerParams.reports(); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 220 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 221 | EXPECT_CALL( |
| 222 | triggerPresenceChanged, |
| 223 | Call(FieldsAre(messages::Presence::Exist, triggerParams.id(), |
| 224 | UnorderedElementsAreArray(triggerParams.reportIds())))); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 225 | |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 226 | EXPECT_THAT(setProperty(sut->getPath(), "Reports", newPropertyVal), |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 227 | Eq(boost::system::errc::success)); |
| 228 | } |
| 229 | |
| 230 | TEST_F(TestTrigger, |
Michal Orzel | b47b7db | 2024-09-16 10:02:29 +0200 | [diff] [blame^] | 231 | settingPropertyReportNamesThrowsExceptionWhenDuplicateReportIds) |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 232 | { |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 233 | std::vector<object_path> newPropertyVal{ |
| 234 | utils::constants::reportDirPath / "report1", |
| 235 | utils::constants::reportDirPath / "report2", |
| 236 | utils::constants::reportDirPath / "report1"}; |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 237 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 238 | EXPECT_CALL(triggerPresenceChanged, Call(_)).Times(0); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 239 | |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 240 | EXPECT_THAT(setProperty(sut->getPath(), "Reports", newPropertyVal), |
| 241 | Eq(boost::system::errc::invalid_argument)); |
| 242 | } |
| 243 | |
Michal Orzel | b47b7db | 2024-09-16 10:02:29 +0200 | [diff] [blame^] | 244 | TEST_F(TestTrigger, |
| 245 | settingPropertyReportNamesThrowsExceptionWhenReportWithTooManyPrefixes) |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 246 | { |
| 247 | std::vector<object_path> newPropertyVal{ |
| 248 | object_path("/xyz/openbmc_project/Telemetry/Reports/P1/P2/MyReport")}; |
| 249 | |
| 250 | EXPECT_CALL(triggerPresenceChanged, Call(_)).Times(0); |
| 251 | |
| 252 | EXPECT_THAT(setProperty(sut->getPath(), "Reports", newPropertyVal), |
| 253 | Eq(boost::system::errc::invalid_argument)); |
| 254 | } |
| 255 | |
Michal Orzel | b47b7db | 2024-09-16 10:02:29 +0200 | [diff] [blame^] | 256 | TEST_F(TestTrigger, |
| 257 | settingPropertyReportNamesThrowsExceptionWhenReportWithTooLongPrefix) |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 258 | { |
| 259 | std::vector<object_path> newPropertyVal{ |
| 260 | object_path("/xyz/openbmc_project/Telemetry/Reports/" + |
| 261 | utils::string_utils::getTooLongPrefix() + "/MyReport")}; |
| 262 | |
| 263 | EXPECT_CALL(triggerPresenceChanged, Call(_)).Times(0); |
| 264 | |
| 265 | EXPECT_THAT(setProperty(sut->getPath(), "Reports", newPropertyVal), |
| 266 | Eq(boost::system::errc::invalid_argument)); |
| 267 | } |
| 268 | |
Michal Orzel | b47b7db | 2024-09-16 10:02:29 +0200 | [diff] [blame^] | 269 | TEST_F(TestTrigger, |
| 270 | settingPropertyReportNamesThrowsExceptionWhenReportWithTooLongId) |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 271 | { |
| 272 | std::vector<object_path> newPropertyVal{ |
| 273 | object_path("/xyz/openbmc_project/Telemetry/Reports/Prefix/" + |
| 274 | utils::string_utils::getTooLongId())}; |
| 275 | |
| 276 | EXPECT_CALL(triggerPresenceChanged, Call(_)).Times(0); |
| 277 | |
| 278 | EXPECT_THAT(setProperty(sut->getPath(), "Reports", newPropertyVal), |
| 279 | Eq(boost::system::errc::invalid_argument)); |
| 280 | } |
| 281 | |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 282 | TEST_F(TestTrigger, |
Michal Orzel | b47b7db | 2024-09-16 10:02:29 +0200 | [diff] [blame^] | 283 | settingPropertyReportNamesThrowsExceptionWhenReportWithBadPath) |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 284 | { |
| 285 | std::vector<object_path> newPropertyVal{ |
| 286 | object_path("/xyz/openbmc_project/Telemetry/NotReports/MyReport")}; |
| 287 | |
| 288 | EXPECT_CALL(triggerPresenceChanged, Call(_)).Times(0); |
| 289 | |
| 290 | EXPECT_THAT(setProperty(sut->getPath(), "Reports", newPropertyVal), |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 291 | Eq(boost::system::errc::invalid_argument)); |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | TEST_F(TestTrigger, setPropertySensors) |
| 295 | { |
| 296 | EXPECT_CALL(*triggerFactoryMockPtr, updateSensors(_, _)); |
| 297 | for (const auto& threshold : thresholdMocks) |
| 298 | { |
| 299 | auto thresholdMockPtr = |
| 300 | std::dynamic_pointer_cast<NiceMock<ThresholdMock>>(threshold); |
| 301 | EXPECT_CALL(*thresholdMockPtr, updateSensors(_)); |
| 302 | } |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 303 | SensorsInfo newSensors( |
| 304 | {std::make_pair(object_path("/abc/def"), "metadata")}); |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 305 | EXPECT_THAT(setProperty(sut->getPath(), "Sensors", newSensors), |
| 306 | Eq(boost::system::errc::success)); |
| 307 | } |
| 308 | |
| 309 | TEST_F(TestTrigger, setPropertyThresholds) |
| 310 | { |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 311 | EXPECT_CALL(*triggerFactoryMockPtr, updateThresholds(_, _, _, _, _, _)); |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 312 | TriggerThresholdParams newThresholds = |
Krzysztof Grobelny | cff70c1 | 2022-10-27 07:16:08 +0000 | [diff] [blame] | 313 | std::vector<discrete::ThresholdParam>({std::make_tuple( |
| 314 | "discrete threshold", utils::enumToString(discrete::Severity::ok), |
| 315 | 10, "12.3")}); |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 316 | EXPECT_THAT(setProperty(sut->getPath(), "Thresholds", newThresholds), |
| 317 | Eq(boost::system::errc::success)); |
| 318 | } |
| 319 | |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 320 | TEST_F(TestTrigger, setThresholdParamsWithTooLongDiscreteName) |
| 321 | { |
| 322 | const TriggerThresholdParams currentValue = |
| 323 | std::visit(utils::FromLabeledThresholdParamConversion(), |
| 324 | triggerParams.thresholdParams()); |
| 325 | |
| 326 | TriggerThresholdParams newThresholds = |
| 327 | std::vector<discrete::ThresholdParam>({std::make_tuple( |
Krzysztof Grobelny | cff70c1 | 2022-10-27 07:16:08 +0000 | [diff] [blame] | 328 | utils::string_utils::getTooLongName(), |
| 329 | utils::enumToString(discrete::Severity::ok), 10, "12.3")}); |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 330 | |
| 331 | changeProperty<TriggerThresholdParams>( |
| 332 | sut->getPath(), "Thresholds", |
| 333 | {.valueBefore = Eq(currentValue), |
| 334 | .newValue = newThresholds, |
| 335 | .ec = Eq(boost::system::errc::invalid_argument), |
| 336 | .valueAfter = Eq(currentValue)}); |
| 337 | } |
| 338 | |
| 339 | TEST_F(TestTrigger, setNameTooLong) |
| 340 | { |
| 341 | std::string currentValue = TriggerParams().name(); |
| 342 | |
| 343 | changeProperty<std::string>( |
| 344 | sut->getPath(), "Name", |
| 345 | {.valueBefore = Eq(currentValue), |
| 346 | .newValue = utils::string_utils::getTooLongName(), |
| 347 | .ec = Eq(boost::system::errc::invalid_argument), |
| 348 | .valueAfter = Eq(currentValue)}); |
| 349 | } |
| 350 | |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 351 | TEST_F(TestTrigger, checkIfNumericCoversionsAreGood) |
| 352 | { |
| 353 | const auto& labeledParamsBase = |
| 354 | std::get<std::vector<numeric::LabeledThresholdParam>>( |
| 355 | triggerParams.thresholdParams()); |
| 356 | const auto paramsToCheck = |
| 357 | std::visit(utils::FromLabeledThresholdParamConversion(), |
| 358 | triggerParams.thresholdParams()); |
| 359 | const auto labeledParamsToCheck = |
| 360 | std::get<std::vector<numeric::LabeledThresholdParam>>(std::visit( |
| 361 | utils::ToLabeledThresholdParamConversion(), paramsToCheck)); |
| 362 | |
| 363 | for (const auto& [tocheck, base] : |
| 364 | boost::combine(labeledParamsToCheck, labeledParamsBase)) |
| 365 | { |
| 366 | EXPECT_THAT(tocheck.at_label<utils::tstring::Type>(), |
| 367 | Eq(base.at_label<utils::tstring::Type>())); |
| 368 | EXPECT_THAT(tocheck.at_label<utils::tstring::Direction>(), |
| 369 | Eq(base.at_label<utils::tstring::Direction>())); |
| 370 | EXPECT_THAT(tocheck.at_label<utils::tstring::DwellTime>(), |
| 371 | Eq(base.at_label<utils::tstring::DwellTime>())); |
| 372 | EXPECT_THAT(tocheck.at_label<utils::tstring::ThresholdValue>(), |
| 373 | Eq(base.at_label<utils::tstring::ThresholdValue>())); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | TEST_F(TestTrigger, checkIfDiscreteCoversionsAreGood) |
| 378 | { |
| 379 | const auto& labeledParamsBase = |
| 380 | std::get<std::vector<discrete::LabeledThresholdParam>>( |
| 381 | triggerDiscreteParams.thresholdParams()); |
| 382 | const auto paramsToCheck = |
| 383 | std::visit(utils::FromLabeledThresholdParamConversion(), |
| 384 | triggerDiscreteParams.thresholdParams()); |
| 385 | const auto labeledParamsToCheck = |
| 386 | std::get<std::vector<discrete::LabeledThresholdParam>>(std::visit( |
| 387 | utils::ToLabeledThresholdParamConversion(), paramsToCheck)); |
| 388 | |
| 389 | for (const auto& [tocheck, base] : |
| 390 | boost::combine(labeledParamsToCheck, labeledParamsBase)) |
| 391 | { |
| 392 | EXPECT_THAT(tocheck.at_label<utils::tstring::UserId>(), |
| 393 | Eq(base.at_label<utils::tstring::UserId>())); |
| 394 | EXPECT_THAT(tocheck.at_label<utils::tstring::Severity>(), |
| 395 | Eq(base.at_label<utils::tstring::Severity>())); |
| 396 | EXPECT_THAT(tocheck.at_label<utils::tstring::DwellTime>(), |
| 397 | Eq(base.at_label<utils::tstring::DwellTime>())); |
| 398 | EXPECT_THAT(tocheck.at_label<utils::tstring::ThresholdValue>(), |
| 399 | Eq(base.at_label<utils::tstring::ThresholdValue>())); |
| 400 | } |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | TEST_F(TestTrigger, deleteTrigger) |
| 404 | { |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 405 | EXPECT_CALL(storageMock, remove(to_file_path(sut->getId()))); |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 406 | EXPECT_CALL(*triggerManagerMockPtr, removeTrigger(sut.get())); |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 407 | |
| 408 | auto ec = deleteTrigger(sut->getPath()); |
| 409 | EXPECT_THAT(ec, Eq(boost::system::errc::success)); |
| 410 | } |
| 411 | |
| 412 | TEST_F(TestTrigger, sendUpdateWhenTriggerIsDeleted) |
| 413 | { |
| 414 | EXPECT_CALL(triggerPresenceChanged, |
| 415 | Call(FieldsAre(messages::Presence::Removed, triggerParams.id(), |
| 416 | UnorderedElementsAre()))); |
| 417 | |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 418 | auto ec = deleteTrigger(sut->getPath()); |
| 419 | EXPECT_THAT(ec, Eq(boost::system::errc::success)); |
| 420 | } |
| 421 | |
| 422 | TEST_F(TestTrigger, deletingNonExistingTriggerReturnInvalidRequestDescriptor) |
| 423 | { |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 424 | auto ec = |
| 425 | deleteTrigger(utils::constants::triggerDirPath.str + "NonExisting"s); |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 426 | EXPECT_THAT(ec.value(), Eq(EBADR)); |
| 427 | } |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 428 | |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 429 | TEST_F(TestTrigger, settingPersistencyToFalseRemovesTriggerFromStorage) |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 430 | { |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 431 | EXPECT_CALL(storageMock, remove(to_file_path(sut->getId()))); |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 432 | |
| 433 | bool persistent = false; |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 434 | EXPECT_THAT(setProperty(sut->getPath(), "Persistent", persistent), |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 435 | Eq(boost::system::errc::success)); |
| 436 | EXPECT_THAT(getProperty<bool>(sut->getPath(), "Persistent"), |
| 437 | Eq(persistent)); |
| 438 | } |
| 439 | |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 440 | class TestTriggerInitialization : public TestTrigger |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 441 | { |
| 442 | public: |
Patrick Williams | 3a1c297 | 2023-05-10 07:51:04 -0500 | [diff] [blame] | 443 | void SetUp() override {} |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 444 | |
| 445 | nlohmann::json storedConfiguration; |
| 446 | }; |
| 447 | |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 448 | TEST_F(TestTriggerInitialization, |
| 449 | exceptionDuringTriggerStoreDisablesPersistency) |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 450 | { |
| 451 | EXPECT_CALL(storageMock, store(_, _)) |
| 452 | .WillOnce(Throw(std::runtime_error("Generic error!"))); |
| 453 | |
| 454 | sut = makeTrigger(triggerParams); |
| 455 | |
| 456 | EXPECT_THAT(getProperty<bool>(sut->getPath(), "Persistent"), Eq(false)); |
| 457 | } |
| 458 | |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 459 | TEST_F(TestTriggerInitialization, creatingTriggerThrowsExceptionWhenIdIsInvalid) |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 460 | { |
| 461 | EXPECT_CALL(storageMock, store(_, _)).Times(0); |
| 462 | |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 463 | EXPECT_THROW(makeTrigger(triggerParams.id("inv?lidId")), |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 464 | sdbusplus::exception::SdBusError); |
| 465 | } |
| 466 | |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 467 | TEST_F(TestTriggerInitialization, creatingTriggerUpdatesTriggersIdsInReports) |
| 468 | { |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 469 | EXPECT_CALL( |
| 470 | triggerPresenceChanged, |
| 471 | Call(FieldsAre(messages::Presence::Exist, triggerParams.id(), |
| 472 | UnorderedElementsAreArray(triggerParams.reportIds())))); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 473 | |
| 474 | sut = makeTrigger(triggerParams); |
| 475 | } |
| 476 | |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 477 | class TestTriggerStore : public TestTrigger |
| 478 | { |
| 479 | public: |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 480 | nlohmann::json storedConfiguration; |
| 481 | nlohmann::json storedDiscreteConfiguration; |
| 482 | std::unique_ptr<Trigger> sutDiscrete; |
| 483 | |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 484 | void SetUp() override |
| 485 | { |
| 486 | ON_CALL(storageMock, store(_, _)) |
| 487 | .WillByDefault(SaveArg<1>(&storedConfiguration)); |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 488 | sut = makeTrigger(triggerParams); |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 489 | |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 490 | ON_CALL(storageMock, store(_, _)) |
| 491 | .WillByDefault(SaveArg<1>(&storedDiscreteConfiguration)); |
| 492 | sutDiscrete = makeTrigger(triggerDiscreteParams); |
| 493 | } |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 494 | }; |
| 495 | |
| 496 | TEST_F(TestTriggerStore, settingPersistencyToTrueStoresTriggerVersion) |
| 497 | { |
| 498 | ASSERT_THAT(storedConfiguration.at("Version"), Eq(expectedTriggerVersion)); |
| 499 | } |
| 500 | |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 501 | TEST_F(TestTriggerStore, settingPersistencyToTrueStoresTriggerId) |
| 502 | { |
| 503 | ASSERT_THAT(storedConfiguration.at("Id"), Eq(triggerParams.id())); |
| 504 | } |
| 505 | |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 506 | TEST_F(TestTriggerStore, settingPersistencyToTrueStoresTriggerName) |
| 507 | { |
| 508 | ASSERT_THAT(storedConfiguration.at("Name"), Eq(triggerParams.name())); |
| 509 | } |
| 510 | |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 511 | TEST_F(TestTriggerStore, settingPersistencyToTrueStoresTriggerTriggerActions) |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 512 | { |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 513 | ASSERT_THAT(storedConfiguration.at("TriggerActions"), |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 514 | Eq(utils::transform(triggerParams.triggerActions(), |
| 515 | [](const auto& action) { |
Patrick Williams | 3a1c297 | 2023-05-10 07:51:04 -0500 | [diff] [blame] | 516 | return actionToString(action); |
Patrick Williams | c7935fa | 2023-10-20 11:19:30 -0500 | [diff] [blame] | 517 | }))); |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 518 | } |
| 519 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 520 | TEST_F(TestTriggerStore, settingPersistencyToTrueStoresTriggerReportIds) |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 521 | { |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 522 | ASSERT_THAT(storedConfiguration.at("ReportIds"), |
| 523 | Eq(triggerParams.reportIds())); |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | TEST_F(TestTriggerStore, settingPersistencyToTrueStoresTriggerSensors) |
| 527 | { |
| 528 | nlohmann::json expectedItem; |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 529 | expectedItem["service"] = "service1"; |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 530 | expectedItem["path"] = "/xyz/openbmc_project/sensors/temperature/BMC_Temp"; |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 531 | expectedItem["metadata"] = "metadata1"; |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 532 | |
| 533 | ASSERT_THAT(storedConfiguration.at("Sensors"), ElementsAre(expectedItem)); |
| 534 | } |
| 535 | |
| 536 | TEST_F(TestTriggerStore, settingPersistencyToTrueStoresTriggerThresholdParams) |
| 537 | { |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 538 | nlohmann::json expectedItem0; |
| 539 | expectedItem0["type"] = 0; |
| 540 | expectedItem0["dwellTime"] = 10; |
| 541 | expectedItem0["direction"] = 1; |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 542 | expectedItem0["thresholdValue"] = 0.5; |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 543 | |
| 544 | nlohmann::json expectedItem1; |
| 545 | expectedItem1["type"] = 3; |
| 546 | expectedItem1["dwellTime"] = 10; |
| 547 | expectedItem1["direction"] = 2; |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 548 | expectedItem1["thresholdValue"] = 90.2; |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 549 | |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 550 | ASSERT_THAT(storedConfiguration.at("ThresholdParamsDiscriminator"), Eq(0)); |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 551 | ASSERT_THAT(storedConfiguration.at("ThresholdParams"), |
| 552 | ElementsAre(expectedItem0, expectedItem1)); |
| 553 | } |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 554 | |
| 555 | TEST_F(TestTriggerStore, |
| 556 | settingPersistencyToTrueStoresDiscreteTriggerThresholdParams) |
| 557 | { |
| 558 | nlohmann::json expectedItem0; |
| 559 | expectedItem0["userId"] = "userId"; |
| 560 | expectedItem0["severity"] = discrete::Severity::warning; |
| 561 | expectedItem0["dwellTime"] = 10; |
Szymon Dompke | 9f34679 | 2021-07-14 21:07:11 +0200 | [diff] [blame] | 562 | expectedItem0["thresholdValue"] = "15.2"; |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 563 | |
| 564 | nlohmann::json expectedItem1; |
| 565 | expectedItem1["userId"] = "userId_2"; |
| 566 | expectedItem1["severity"] = discrete::Severity::critical; |
| 567 | expectedItem1["dwellTime"] = 5; |
Szymon Dompke | 9f34679 | 2021-07-14 21:07:11 +0200 | [diff] [blame] | 568 | expectedItem1["thresholdValue"] = "32.7"; |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 569 | |
| 570 | ASSERT_THAT(storedDiscreteConfiguration.at("ThresholdParamsDiscriminator"), |
| 571 | Eq(1)); |
| 572 | ASSERT_THAT(storedDiscreteConfiguration.at("ThresholdParams"), |
| 573 | ElementsAre(expectedItem0, expectedItem1)); |
| 574 | } |