Update Trigger Actions implementation

Dbus trigger action names were modified to reflect separation of
Telemetry Service from Redfish:
- LogToLogService is renamed to LogToJournal,
- RedfishEvent was renamed to LogToRedfishEventLog

Both of those logging actions, now also include trigger id and threshold
name. Threshold naming logic:
- For discrete triggers, it can be specified by user, if left empty it
  will be changed to "{Severity} condition".
- Numeric triggers have no way of naming threshold, instead its type
  will be converted to string, example "UpperWarning"
- Discrete OnChange threshold will always be named "OnChange"

Additionally, defect was found with timestamp attached to Trigger Logs:
it was a steady_clock timestamp instead of system_clock. The function
which was supposed to format it was also working incorrectly, and was
improved to work with milliseconds. This change required major refactor
of unit tests, especially for numeric threshold.

Testing done:
- LogToJournal action is working properly,
- LogToRedfishEventLog action is working properly,
- UTs are passing.

Signed-off-by: Szymon Dompke <szymon.dompke@intel.com>
Change-Id: Iae2490682f0e9e2a610b45fd8af5cc5e21e66f35
diff --git a/tests/src/test_trigger_actions.cpp b/tests/src/test_trigger_actions.cpp
index 911197f..e8c48d4 100644
--- a/tests/src/test_trigger_actions.cpp
+++ b/tests/src/test_trigger_actions.cpp
@@ -31,26 +31,36 @@
         std::make_tuple(static_cast<::numeric::Type>(123), 123.0, 90));
 }
 
-class TestLogToJournalNumeric : public Test, public WithParamInterface<LogParam>
+template <typename ActionType>
+class TestActionNumeric : public Test, public WithParamInterface<LogParam>
 {
   public:
     void SetUp() override
     {
         auto [type, threshold, value] = GetParam();
-        sut = std::make_unique<numeric::LogToJournal>(type, threshold);
+        sut = std::make_unique<ActionType>(type, threshold);
         commmitValue = value;
     }
 
-    std::unique_ptr<numeric::LogToJournal> sut;
+    void commit()
+    {
+        sut->commit("MyTrigger", std::nullopt, "MySensor",
+                    Milliseconds{100'000}, commmitValue);
+    }
+
+    std::unique_ptr<ActionType> sut;
     double commmitValue;
 };
 
+class TestLogToJournalNumeric : public TestActionNumeric<LogToJournal>
+{};
+
 INSTANTIATE_TEST_SUITE_P(LogToJournalNumericParams, TestLogToJournalNumeric,
                          getCorrectParams());
 
 TEST_P(TestLogToJournalNumeric, commitAnActionDoesNotThrow)
 {
-    EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, commmitValue));
+    EXPECT_NO_THROW(commit());
 }
 
 class TestLogToJournalNumericThrow : public TestLogToJournalNumeric
@@ -60,80 +70,91 @@
 
 TEST_P(TestLogToJournalNumericThrow, commitAnActionExpectThrow)
 {
-    EXPECT_ANY_THROW(sut->commit("Test", Milliseconds{100'000}, commmitValue));
+    EXPECT_ANY_THROW(commit());
 }
 
-class TestLogToRedfishNumeric : public Test, public WithParamInterface<LogParam>
-{
-  public:
-    void SetUp() override
-    {
-        auto [type, threshold, value] = GetParam();
-        sut = std::make_unique<LogToRedfish>(type, threshold);
-        commmitValue = value;
-    }
-
-    std::unique_ptr<LogToRedfish> sut;
-    double commmitValue;
-};
-
-INSTANTIATE_TEST_SUITE_P(LogToRedfishNumericParams, TestLogToRedfishNumeric,
-                         getCorrectParams());
-
-TEST_P(TestLogToRedfishNumeric, commitExpectNoThrow)
-{
-    EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, commmitValue));
-}
-
-class TestLogToRedfishNumericThrow : public TestLogToRedfishNumeric
+class TestLogToRedfishEventLogNumeric :
+    public TestActionNumeric<LogToRedfishEventLog>
 {};
 
-INSTANTIATE_TEST_SUITE_P(_, TestLogToRedfishNumericThrow, getIncorrectParams());
+INSTANTIATE_TEST_SUITE_P(LogToRedfishEventLogNumericParams,
+                         TestLogToRedfishEventLogNumeric, getCorrectParams());
 
-TEST_P(TestLogToRedfishNumericThrow, commitExpectToThrow)
+TEST_P(TestLogToRedfishEventLogNumeric, commitExpectNoThrow)
 {
-    EXPECT_THROW(sut->commit("Test", Milliseconds{100'000}, commmitValue),
-                 std::runtime_error);
+    EXPECT_NO_THROW(commit());
+}
+
+class TestLogToRedfishEventLogNumericThrow :
+    public TestLogToRedfishEventLogNumeric
+{};
+
+INSTANTIATE_TEST_SUITE_P(_, TestLogToRedfishEventLogNumericThrow,
+                         getIncorrectParams());
+
+TEST_P(TestLogToRedfishEventLogNumericThrow, commitExpectToThrow)
+{
+    EXPECT_ANY_THROW(commit());
 }
 
 } // namespace numeric
 
 namespace discrete
 {
-using LogParam = ::discrete::Severity;
+using LogParam = std::tuple<::discrete::Severity, TriggerValue>;
 
 static auto getCorrectParams()
 {
-    return Values(::discrete::Severity::critical, ::discrete::Severity::warning,
-                  ::discrete::Severity::ok);
+    return Values(
+        std::make_tuple(::discrete::Severity::critical,
+                        TriggerValue("DiscreteVal")),
+        std::make_tuple(::discrete::Severity::warning, TriggerValue("On")),
+        std::make_tuple(::discrete::Severity::ok, TriggerValue("Off")));
 }
 
 static auto getIncorrectParams()
 {
-    return Values(static_cast<::discrete::Severity>(-1),
-                  static_cast<::discrete::Severity>(42));
+    return Values(
+        std::make_tuple(static_cast<::discrete::Severity>(-1),
+                        TriggerValue("DiscreteVal42")),
+        std::make_tuple(static_cast<::discrete::Severity>(42),
+                        TriggerValue("On")),
+        std::make_tuple(::discrete::Severity::critical, TriggerValue(42.0)),
+        std::make_tuple(::discrete::Severity::warning, TriggerValue(0.0)),
+        std::make_tuple(::discrete::Severity::ok, TriggerValue(0.1)));
 }
 
-class TestLogToJournalDiscrete :
-    public Test,
-    public WithParamInterface<LogParam>
+template <typename ActionType>
+class TestActionDiscrete : public Test, public WithParamInterface<LogParam>
 {
   public:
     void SetUp() override
     {
-        auto severity = GetParam();
-        sut = std::make_unique<LogToJournal>(severity);
+        auto [severity, value] = GetParam();
+        sut = std::make_unique<ActionType>(severity);
+        commitValue = value;
     }
 
-    std::unique_ptr<LogToJournal> sut;
+    void commit()
+    {
+        std::string thresholdName = "MyThreshold";
+        sut->commit("MyTrigger", std::cref(thresholdName), "MySensor",
+                    Milliseconds{100'000}, commitValue);
+    }
+
+    TriggerValue commitValue;
+    std::unique_ptr<ActionType> sut;
 };
 
+class TestLogToJournalDiscrete : public TestActionDiscrete<LogToJournal>
+{};
+
 INSTANTIATE_TEST_SUITE_P(LogToJournalDiscreteParams, TestLogToJournalDiscrete,
                          getCorrectParams());
 
-TEST_P(TestLogToJournalDiscrete, commitAnActionDoesNotThrow)
+TEST_P(TestLogToJournalDiscrete, commitAnActionWIthDiscreteValueDoesNotThrow)
 {
-    EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0));
+    EXPECT_NO_THROW(commit());
 }
 
 class TestLogToJournalDiscreteThrow : public TestLogToJournalDiscrete
@@ -144,76 +165,83 @@
 
 TEST_P(TestLogToJournalDiscreteThrow, commitAnActionExpectThrow)
 {
-    EXPECT_ANY_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0));
+    EXPECT_ANY_THROW(commit());
 }
 
-class TestLogToRedfishDiscrete :
-    public Test,
-    public WithParamInterface<LogParam>
-{
-  public:
-    void SetUp() override
-    {
-        auto severity = GetParam();
-        sut = std::make_unique<LogToRedfish>(severity);
-    }
-
-    std::unique_ptr<LogToRedfish> sut;
-};
-
-INSTANTIATE_TEST_SUITE_P(LogToRedfishDiscreteParams, TestLogToRedfishDiscrete,
-                         getCorrectParams());
-
-TEST_P(TestLogToRedfishDiscrete, commitExpectNoThrow)
-{
-    EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0));
-}
-
-class TestLogToRedfishDiscreteThrow : public TestLogToRedfishDiscrete
+class TestLogToRedfishEventLogDiscrete :
+    public TestActionDiscrete<LogToRedfishEventLog>
 {};
 
-INSTANTIATE_TEST_SUITE_P(_, TestLogToRedfishDiscreteThrow,
+INSTANTIATE_TEST_SUITE_P(LogToRedfishEventLogDiscreteParams,
+                         TestLogToRedfishEventLogDiscrete, getCorrectParams());
+
+TEST_P(TestLogToRedfishEventLogDiscrete, commitExpectNoThrow)
+{
+    EXPECT_NO_THROW(commit());
+}
+
+class TestLogToRedfishEventLogDiscreteThrow :
+    public TestLogToRedfishEventLogDiscrete
+{};
+
+INSTANTIATE_TEST_SUITE_P(_, TestLogToRedfishEventLogDiscreteThrow,
                          getIncorrectParams());
 
-TEST_P(TestLogToRedfishDiscreteThrow, commitExpectToThrow)
+TEST_P(TestLogToRedfishEventLogDiscreteThrow, commitExpectToThrow)
 {
-    EXPECT_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0),
-                 std::runtime_error);
+    EXPECT_ANY_THROW(commit());
 }
 
 namespace onChange
 {
-class TestLogToJournalDiscreteOnChange : public Test
+
+template <typename ActionType>
+class TestActionOnChange : public Test
 {
   public:
     void SetUp() override
     {
-        sut = std::make_unique<LogToJournal>();
+        sut = std::make_unique<ActionType>();
     }
 
-    std::unique_ptr<LogToJournal> sut;
-};
-
-TEST_F(TestLogToJournalDiscreteOnChange, commitExpectNoThrow)
-{
-    EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0));
-}
-
-class TestLogToRedfishDiscreteOnChange : public Test
-{
-  public:
-    void SetUp() override
+    void commit(TriggerValue value)
     {
-        sut = std::make_unique<LogToRedfish>();
+        sut->commit("MyTrigger", std::nullopt, "MySensor",
+                    Milliseconds{100'000}, value);
     }
 
-    std::unique_ptr<LogToRedfish> sut;
+    std::unique_ptr<ActionType> sut;
 };
 
-TEST_F(TestLogToRedfishDiscreteOnChange, commitExpectNoThrow)
+class TestLogToJournalDiscreteOnChange : public TestActionOnChange<LogToJournal>
+{};
+
+TEST_F(TestLogToJournalDiscreteOnChange, commitNumericValueExpectNoThrow)
 {
-    EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0));
+    EXPECT_NO_THROW(commit(90.0));
 }
+
+TEST_F(TestLogToJournalDiscreteOnChange, commitDiscreteValueExpectNoThrow)
+{
+    EXPECT_NO_THROW(commit("Off"));
+}
+
+class TestLogToRedfishEventLogDiscreteOnChange :
+    public TestActionOnChange<LogToRedfishEventLog>
+{};
+
+TEST_F(TestLogToRedfishEventLogDiscreteOnChange,
+       commitNumericValueExpectNoThrow)
+{
+    EXPECT_NO_THROW(commit(90.0));
+}
+
+TEST_F(TestLogToRedfishEventLogDiscreteOnChange,
+       commitDiscreteValueExpectNoThrow)
+{
+    EXPECT_NO_THROW(commit("Off"));
+}
+
 } // namespace onChange
 } // namespace discrete
 
@@ -233,9 +261,16 @@
             std::make_shared<std::vector<std::string>>(std::move(names)));
     }
 
+    void commit(TriggerValue value)
+    {
+        sut->commit(triggerId, std::nullopt, "MySensor", Milliseconds{100'000},
+                    value);
+    }
+
     utils::Messanger messanger;
     NiceMock<MockFunction<void(const messages::UpdateReportInd&)>> updateReport;
     std::unique_ptr<UpdateReport> sut;
+    std::string triggerId = "MyTrigger";
 };
 
 TEST_F(TestUpdateReport, commitWhenReportNameIsEmptyExpectNoReportUpdate)
@@ -243,7 +278,7 @@
     EXPECT_CALL(updateReport, Call(_)).Times(0);
 
     make({});
-    sut->commit("Test", Milliseconds{100'000}, 90.0);
+    commit(90.0);
 }
 
 TEST_F(TestUpdateReport, commitExpectReportUpdate)
@@ -253,7 +288,7 @@
                 Call(FieldsAre(UnorderedElementsAreArray(names))));
 
     make(names);
-    sut->commit("Test", Milliseconds{100'000}, 90.0);
+    commit(90.0);
 }
 
 } // namespace action