Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 1 | #include "mocks/report_manager_mock.hpp" |
| 2 | #include "trigger_actions.hpp" |
| 3 | |
| 4 | #include <stdexcept> |
| 5 | |
| 6 | using namespace testing; |
| 7 | |
| 8 | namespace action |
| 9 | { |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 10 | namespace numeric |
| 11 | { |
| 12 | using LogParam = std::tuple<::numeric::Type, double, double>; |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 13 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 14 | static auto getCorrectParams() |
| 15 | { |
| 16 | return Values(std::make_tuple(::numeric::Type::upperCritical, 91.1, 90), |
| 17 | std::make_tuple(::numeric::Type::lowerCritical, 91.2, 90), |
| 18 | std::make_tuple(::numeric::Type::upperWarning, 88.5, 90), |
| 19 | std::make_tuple(::numeric::Type::lowerWarning, 88.6, 90)); |
| 20 | } |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 21 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 22 | static auto getIncorrectParams() |
| 23 | { |
| 24 | return Values( |
| 25 | std::make_tuple(::numeric::Type::upperCritical, 90.0, 90), |
| 26 | std::make_tuple(static_cast<::numeric::Type>(-1), 88.0, 90), |
| 27 | std::make_tuple(static_cast<::numeric::Type>(123), 123.0, 90)); |
| 28 | } |
| 29 | |
| 30 | class TestLogToJournalNumeric : public Test, public WithParamInterface<LogParam> |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 31 | { |
| 32 | public: |
| 33 | void SetUp() override |
| 34 | { |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 35 | auto [type, threshold, value] = GetParam(); |
| 36 | sut = std::make_unique<numeric::LogToJournal>(type, threshold); |
| 37 | commmitValue = value; |
| 38 | } |
| 39 | |
| 40 | std::unique_ptr<numeric::LogToJournal> sut; |
| 41 | double commmitValue; |
| 42 | }; |
| 43 | |
| 44 | INSTANTIATE_TEST_SUITE_P(LogToJournalNumericParams, TestLogToJournalNumeric, |
| 45 | getCorrectParams()); |
| 46 | |
| 47 | TEST_P(TestLogToJournalNumeric, commitAnActionDoesNotThrow) |
| 48 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame^] | 49 | EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, commmitValue)); |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | class TestLogToJournalNumericThrow : public TestLogToJournalNumeric |
| 53 | {}; |
| 54 | |
| 55 | INSTANTIATE_TEST_SUITE_P(_, TestLogToJournalNumericThrow, getIncorrectParams()); |
| 56 | |
| 57 | TEST_P(TestLogToJournalNumericThrow, commitAnActionExpectThrow) |
| 58 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame^] | 59 | EXPECT_THROW(sut->commit("Test", Milliseconds{100'000}, commmitValue), |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 60 | std::runtime_error); |
| 61 | } |
| 62 | |
| 63 | class TestLogToRedfishNumeric : public Test, public WithParamInterface<LogParam> |
| 64 | { |
| 65 | public: |
| 66 | void SetUp() override |
| 67 | { |
| 68 | auto [type, threshold, value] = GetParam(); |
| 69 | sut = std::make_unique<LogToRedfish>(type, threshold); |
| 70 | commmitValue = value; |
| 71 | } |
| 72 | |
| 73 | std::unique_ptr<LogToRedfish> sut; |
| 74 | double commmitValue; |
| 75 | }; |
| 76 | |
| 77 | INSTANTIATE_TEST_SUITE_P(LogToRedfishNumericParams, TestLogToRedfishNumeric, |
| 78 | getCorrectParams()); |
| 79 | |
| 80 | TEST_P(TestLogToRedfishNumeric, commitExpectNoThrow) |
| 81 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame^] | 82 | EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, commmitValue)); |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | class TestLogToRedfishNumericThrow : public TestLogToRedfishNumeric |
| 86 | {}; |
| 87 | |
| 88 | INSTANTIATE_TEST_SUITE_P(_, TestLogToRedfishNumericThrow, getIncorrectParams()); |
| 89 | |
| 90 | TEST_P(TestLogToRedfishNumericThrow, commitExpectToThrow) |
| 91 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame^] | 92 | EXPECT_THROW(sut->commit("Test", Milliseconds{100'000}, commmitValue), |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 93 | std::runtime_error); |
| 94 | } |
| 95 | |
| 96 | } // namespace numeric |
| 97 | |
| 98 | namespace discrete |
| 99 | { |
| 100 | using LogParam = ::discrete::Severity; |
| 101 | |
| 102 | static auto getCorrectParams() |
| 103 | { |
| 104 | return Values(::discrete::Severity::critical, ::discrete::Severity::warning, |
| 105 | ::discrete::Severity::ok); |
| 106 | } |
| 107 | |
| 108 | static auto getIncorrectParams() |
| 109 | { |
| 110 | return Values(static_cast<::discrete::Severity>(-1), |
| 111 | static_cast<::discrete::Severity>(42)); |
| 112 | } |
| 113 | |
| 114 | class TestLogToJournalDiscrete : |
| 115 | public Test, |
| 116 | public WithParamInterface<LogParam> |
| 117 | { |
| 118 | public: |
| 119 | void SetUp() override |
| 120 | { |
| 121 | auto severity = GetParam(); |
| 122 | sut = std::make_unique<LogToJournal>(severity); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | std::unique_ptr<LogToJournal> sut; |
| 126 | }; |
| 127 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 128 | INSTANTIATE_TEST_SUITE_P(LogToJournalDiscreteParams, TestLogToJournalDiscrete, |
| 129 | getCorrectParams()); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 130 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 131 | TEST_P(TestLogToJournalDiscrete, commitAnActionDoesNotThrow) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 132 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame^] | 133 | EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0)); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 134 | } |
| 135 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 136 | class TestLogToJournalDiscreteThrow : public TestLogToJournalDiscrete |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 137 | {}; |
| 138 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 139 | INSTANTIATE_TEST_SUITE_P(_, TestLogToJournalDiscreteThrow, |
| 140 | getIncorrectParams()); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 141 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 142 | TEST_P(TestLogToJournalDiscreteThrow, commitAnActionExpectThrow) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 143 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame^] | 144 | EXPECT_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0), |
| 145 | std::runtime_error); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 146 | } |
| 147 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 148 | class TestLogToRedfishDiscrete : |
| 149 | public Test, |
| 150 | public WithParamInterface<LogParam> |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 151 | { |
| 152 | public: |
| 153 | void SetUp() override |
| 154 | { |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 155 | auto severity = GetParam(); |
| 156 | sut = std::make_unique<LogToRedfish>(severity); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | std::unique_ptr<LogToRedfish> sut; |
| 160 | }; |
| 161 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 162 | INSTANTIATE_TEST_SUITE_P(LogToRedfishDiscreteParams, TestLogToRedfishDiscrete, |
| 163 | getCorrectParams()); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 164 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 165 | TEST_P(TestLogToRedfishDiscrete, commitExpectNoThrow) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 166 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame^] | 167 | EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0)); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 168 | } |
| 169 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 170 | class TestLogToRedfishDiscreteThrow : public TestLogToRedfishDiscrete |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 171 | {}; |
| 172 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 173 | INSTANTIATE_TEST_SUITE_P(_, TestLogToRedfishDiscreteThrow, |
| 174 | getIncorrectParams()); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 175 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 176 | TEST_P(TestLogToRedfishDiscreteThrow, commitExpectToThrow) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 177 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame^] | 178 | EXPECT_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0), |
| 179 | std::runtime_error); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 180 | } |
| 181 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 182 | namespace onChange |
| 183 | { |
| 184 | class TestLogToJournalDiscreteOnChange : public Test |
| 185 | { |
| 186 | public: |
| 187 | void SetUp() override |
| 188 | { |
| 189 | sut = std::make_unique<LogToJournal>(); |
| 190 | } |
| 191 | |
| 192 | std::unique_ptr<LogToJournal> sut; |
| 193 | }; |
| 194 | |
| 195 | TEST_F(TestLogToJournalDiscreteOnChange, commitExpectNoThrow) |
| 196 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame^] | 197 | EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0)); |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | class TestLogToRedfishDiscreteOnChange : public Test |
| 201 | { |
| 202 | public: |
| 203 | void SetUp() override |
| 204 | { |
| 205 | sut = std::make_unique<LogToRedfish>(); |
| 206 | } |
| 207 | |
| 208 | std::unique_ptr<LogToRedfish> sut; |
| 209 | }; |
| 210 | |
| 211 | TEST_F(TestLogToRedfishDiscreteOnChange, commitExpectNoThrow) |
| 212 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame^] | 213 | EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0)); |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 214 | } |
| 215 | } // namespace onChange |
| 216 | } // namespace discrete |
| 217 | |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 218 | class TestUpdateReport : public Test |
| 219 | { |
| 220 | public: |
| 221 | void make(std::vector<std::string> names) |
| 222 | { |
| 223 | sut = std::make_unique<UpdateReport>(reportManager, std::move(names)); |
| 224 | } |
| 225 | |
| 226 | NiceMock<ReportManagerMock> reportManager; |
| 227 | std::unique_ptr<UpdateReport> sut; |
| 228 | }; |
| 229 | |
| 230 | TEST_F(TestUpdateReport, commitWhenReportNameIsEmptyExpectNoReportUpdate) |
| 231 | { |
| 232 | EXPECT_CALL(reportManager, updateReport(_)).Times(0); |
| 233 | |
| 234 | make({}); |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame^] | 235 | sut->commit("Test", Milliseconds{100'000}, 90.0); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | TEST_F(TestUpdateReport, commitExpectReportUpdate) |
| 239 | { |
| 240 | std::vector<std::string> names = {"Report1", "Report2", "Report3"}; |
| 241 | for (const auto& name : names) |
| 242 | { |
| 243 | EXPECT_CALL(reportManager, updateReport(name)); |
| 244 | } |
| 245 | |
| 246 | make(names); |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame^] | 247 | sut->commit("Test", Milliseconds{100'000}, 90.0); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | } // namespace action |