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 | { |
| 49 | EXPECT_NO_THROW(sut->commit("Test", 100'000, commmitValue)); |
| 50 | } |
| 51 | |
| 52 | class TestLogToJournalNumericThrow : public TestLogToJournalNumeric |
| 53 | {}; |
| 54 | |
| 55 | INSTANTIATE_TEST_SUITE_P(_, TestLogToJournalNumericThrow, getIncorrectParams()); |
| 56 | |
| 57 | TEST_P(TestLogToJournalNumericThrow, commitAnActionExpectThrow) |
| 58 | { |
| 59 | EXPECT_THROW(sut->commit("Test", 100'000, commmitValue), |
| 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 | { |
| 82 | EXPECT_NO_THROW(sut->commit("Test", 100'000, commmitValue)); |
| 83 | } |
| 84 | |
| 85 | class TestLogToRedfishNumericThrow : public TestLogToRedfishNumeric |
| 86 | {}; |
| 87 | |
| 88 | INSTANTIATE_TEST_SUITE_P(_, TestLogToRedfishNumericThrow, getIncorrectParams()); |
| 89 | |
| 90 | TEST_P(TestLogToRedfishNumericThrow, commitExpectToThrow) |
| 91 | { |
| 92 | EXPECT_THROW(sut->commit("Test", 100'000, commmitValue), |
| 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 | { |
| 133 | EXPECT_NO_THROW(sut->commit("Test", 100'000, 90.0)); |
| 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 | { |
| 144 | EXPECT_THROW(sut->commit("Test", 100'000, 90.0), std::runtime_error); |
| 145 | } |
| 146 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 147 | class TestLogToRedfishDiscrete : |
| 148 | public Test, |
| 149 | public WithParamInterface<LogParam> |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 150 | { |
| 151 | public: |
| 152 | void SetUp() override |
| 153 | { |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 154 | auto severity = GetParam(); |
| 155 | sut = std::make_unique<LogToRedfish>(severity); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | std::unique_ptr<LogToRedfish> sut; |
| 159 | }; |
| 160 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 161 | INSTANTIATE_TEST_SUITE_P(LogToRedfishDiscreteParams, TestLogToRedfishDiscrete, |
| 162 | getCorrectParams()); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 163 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 164 | TEST_P(TestLogToRedfishDiscrete, commitExpectNoThrow) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 165 | { |
| 166 | EXPECT_NO_THROW(sut->commit("Test", 100'000, 90.0)); |
| 167 | } |
| 168 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 169 | class TestLogToRedfishDiscreteThrow : public TestLogToRedfishDiscrete |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 170 | {}; |
| 171 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 172 | INSTANTIATE_TEST_SUITE_P(_, TestLogToRedfishDiscreteThrow, |
| 173 | getIncorrectParams()); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 174 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 175 | TEST_P(TestLogToRedfishDiscreteThrow, commitExpectToThrow) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 176 | { |
| 177 | EXPECT_THROW(sut->commit("Test", 100'000, 90.0), std::runtime_error); |
| 178 | } |
| 179 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 180 | namespace onChange |
| 181 | { |
| 182 | class TestLogToJournalDiscreteOnChange : public Test |
| 183 | { |
| 184 | public: |
| 185 | void SetUp() override |
| 186 | { |
| 187 | sut = std::make_unique<LogToJournal>(); |
| 188 | } |
| 189 | |
| 190 | std::unique_ptr<LogToJournal> sut; |
| 191 | }; |
| 192 | |
| 193 | TEST_F(TestLogToJournalDiscreteOnChange, commitExpectNoThrow) |
| 194 | { |
| 195 | EXPECT_NO_THROW(sut->commit("Test", 100'000, 90.0)); |
| 196 | } |
| 197 | |
| 198 | class TestLogToRedfishDiscreteOnChange : public Test |
| 199 | { |
| 200 | public: |
| 201 | void SetUp() override |
| 202 | { |
| 203 | sut = std::make_unique<LogToRedfish>(); |
| 204 | } |
| 205 | |
| 206 | std::unique_ptr<LogToRedfish> sut; |
| 207 | }; |
| 208 | |
| 209 | TEST_F(TestLogToRedfishDiscreteOnChange, commitExpectNoThrow) |
| 210 | { |
| 211 | EXPECT_NO_THROW(sut->commit("Test", 100'000, 90.0)); |
| 212 | } |
| 213 | } // namespace onChange |
| 214 | } // namespace discrete |
| 215 | |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 216 | class TestUpdateReport : public Test |
| 217 | { |
| 218 | public: |
| 219 | void make(std::vector<std::string> names) |
| 220 | { |
| 221 | sut = std::make_unique<UpdateReport>(reportManager, std::move(names)); |
| 222 | } |
| 223 | |
| 224 | NiceMock<ReportManagerMock> reportManager; |
| 225 | std::unique_ptr<UpdateReport> sut; |
| 226 | }; |
| 227 | |
| 228 | TEST_F(TestUpdateReport, commitWhenReportNameIsEmptyExpectNoReportUpdate) |
| 229 | { |
| 230 | EXPECT_CALL(reportManager, updateReport(_)).Times(0); |
| 231 | |
| 232 | make({}); |
| 233 | sut->commit("Test", 100'000, 90.0); |
| 234 | } |
| 235 | |
| 236 | TEST_F(TestUpdateReport, commitExpectReportUpdate) |
| 237 | { |
| 238 | std::vector<std::string> names = {"Report1", "Report2", "Report3"}; |
| 239 | for (const auto& name : names) |
| 240 | { |
| 241 | EXPECT_CALL(reportManager, updateReport(name)); |
| 242 | } |
| 243 | |
| 244 | make(names); |
| 245 | sut->commit("Test", 100'000, 90.0); |
| 246 | } |
| 247 | |
| 248 | } // namespace action |