1 #include "app.hpp"
2 #include "event_service_manager.hpp"
3 #include "include/async_resp.hpp"
4 #include "redfish-core/lib/health.hpp"
5 #include "redfish-core/lib/log_services.hpp"
6 
7 #include <nlohmann/json.hpp>
8 
9 #include <gmock/gmock.h>
10 #include <gtest/gtest.h>
11 
12 namespace redfish
13 {
14 namespace
15 {
16 
17 void assertLogServicesDumpServiceGet(crow::Response& res)
18 {
19     nlohmann::json& json = res.jsonValue;
20     EXPECT_EQ(json["@odata.type"], "#LogService.v1_2_0.LogService");
21     EXPECT_EQ(json["Name"], "Dump LogService");
22 }
23 
24 void assertLogServicesBMCDumpServiceGet(crow::Response& res)
25 {
26     assertLogServicesDumpServiceGet(res);
27 
28     nlohmann::json& json = res.jsonValue;
29     EXPECT_EQ(json["@odata.id"], "/redfish/v1/Managers/bmc/LogServices/Dump");
30     EXPECT_EQ(
31         json["Actions"]["#LogService.ClearLog"]["target"],
32         "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.ClearLog");
33     EXPECT_EQ(
34         json["Actions"]["#LogService.CollectDiagnosticData"]["target"],
35         "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData");
36     EXPECT_EQ(json["Description"], "BMC Dump LogService");
37     EXPECT_EQ(json["Entries"]["@odata.id"],
38               "/redfish/v1/Managers/bmc/LogServices/Dump/Entries");
39     EXPECT_EQ(json["Id"], "Dump");
40     EXPECT_EQ(json["OverWritePolicy"], "WrapsWhenFull");
41 }
42 
43 void assertLogServicesFaultLogDumpServiceGet(crow::Response& res)
44 {
45     assertLogServicesDumpServiceGet(res);
46 
47     nlohmann::json& json = res.jsonValue;
48     EXPECT_EQ(json["@odata.id"],
49               "/redfish/v1/Managers/bmc/LogServices/FaultLog");
50     EXPECT_EQ(
51         json["Actions"]["#LogService.ClearLog"]["target"],
52         "/redfish/v1/Managers/bmc/LogServices/FaultLog/Actions/LogService.ClearLog");
53     EXPECT_EQ(json["Actions"]["#LogService.CollectDiagnosticData"]["target"],
54               nlohmann::detail::value_t::null);
55     EXPECT_EQ(json["Description"], "FaultLog Dump LogService");
56     EXPECT_EQ(json["Entries"]["@odata.id"],
57               "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries");
58     EXPECT_EQ(json["Id"], "FaultLog");
59     EXPECT_EQ(json["OverWritePolicy"], "Unknown");
60 }
61 
62 void assertLogServicesSystemDumpServiceGet(crow::Response& res)
63 {
64     assertLogServicesDumpServiceGet(res);
65 
66     nlohmann::json& json = res.jsonValue;
67     EXPECT_EQ(json["@odata.id"], "/redfish/v1/Systems/system/LogServices/Dump");
68     EXPECT_EQ(
69         json["Actions"]["#LogService.ClearLog"]["target"],
70         "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.ClearLog");
71     EXPECT_EQ(
72         json["Actions"]["#LogService.CollectDiagnosticData"]["target"],
73         "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.CollectDiagnosticData");
74     EXPECT_EQ(json["Description"], "System Dump LogService");
75     EXPECT_EQ(json["Entries"]["@odata.id"],
76               "/redfish/v1/Systems/system/LogServices/Dump/Entries");
77     EXPECT_EQ(json["Id"], "Dump");
78     EXPECT_EQ(json["OverWritePolicy"], "WrapsWhenFull");
79 }
80 
81 TEST(LogServicesDumpServiceTest,
82      LogServicesBMCDumpServiceStaticAttributesAreExpected)
83 {
84     auto shareAsyncResp = std::make_shared<bmcweb::AsyncResp>();
85     shareAsyncResp->res.setCompleteRequestHandler(
86         assertLogServicesBMCDumpServiceGet);
87     getDumpServiceInfo(shareAsyncResp, "BMC");
88 }
89 
90 TEST(LogServicesDumpServiceTest,
91      LogServicesFaultLogDumpServiceStaticAttributesAreExpected)
92 {
93     auto shareAsyncResp = std::make_shared<bmcweb::AsyncResp>();
94     shareAsyncResp->res.setCompleteRequestHandler(
95         assertLogServicesFaultLogDumpServiceGet);
96     getDumpServiceInfo(shareAsyncResp, "FaultLog");
97 }
98 
99 TEST(LogServicesDumpServiceTest,
100      LogServicesSystemDumpServiceStaticAttributesAreExpected)
101 {
102     auto shareAsyncResp = std::make_shared<bmcweb::AsyncResp>();
103     shareAsyncResp->res.setCompleteRequestHandler(
104         assertLogServicesSystemDumpServiceGet);
105     getDumpServiceInfo(shareAsyncResp, "System");
106 }
107 
108 TEST(LogServicesDumpServiceTest, LogServicesInvalidDumpServiceGetReturnsError)
109 {
110     auto shareAsyncResp = std::make_shared<bmcweb::AsyncResp>();
111     getDumpServiceInfo(shareAsyncResp, "Invalid");
112     EXPECT_EQ(shareAsyncResp->res.result(),
113               boost::beast::http::status::internal_server_error);
114 }
115 
116 } // namespace
117 } // namespace redfish
118