1 
2 #include "utils/dbus_utils.hpp"
3 
4 #include "async_resp.hpp"
5 #include "http_response.hpp"
6 
7 #include <boost/beast/http/status.hpp>
8 #include <boost/system/errc.hpp>
9 #include <nlohmann/json.hpp>
10 #include <sdbusplus/message.hpp>
11 
12 #include <memory>
13 #include <string>
14 
15 #include <gtest/gtest.h>
16 
17 namespace redfish::details
18 {
19 namespace
20 {
21 
TEST(DbusUtils,AfterPropertySetSuccess)22 TEST(DbusUtils, AfterPropertySetSuccess)
23 {
24     std::shared_ptr<bmcweb::AsyncResp> asyncResp =
25         std::make_shared<bmcweb::AsyncResp>();
26 
27     boost::system::error_code ec;
28     sdbusplus::message_t msg;
29     afterSetProperty(asyncResp, "MyRedfishProperty",
30                      nlohmann::json("MyRedfishValue"), ec, msg);
31 
32     EXPECT_EQ(asyncResp->res.result(), boost::beast::http::status::no_content);
33 }
34 
TEST(DbusUtils,AfterActionPropertySetSuccess)35 TEST(DbusUtils, AfterActionPropertySetSuccess)
36 {
37     std::shared_ptr<bmcweb::AsyncResp> asyncResp =
38         std::make_shared<bmcweb::AsyncResp>();
39 
40     boost::system::error_code ec;
41     sdbusplus::message_t msg;
42     afterSetPropertyAction(asyncResp, "MyRedfishProperty",
43                            nlohmann::json("MyRedfishValue"), ec, msg);
44 
45     EXPECT_EQ(asyncResp->res.result(), boost::beast::http::status::ok);
46     EXPECT_EQ(asyncResp->res.jsonValue,
47               R"({
48                     "@Message.ExtendedInfo": [
49                         {
50                             "@odata.type": "#Message.v1_1_1.Message",
51                             "Message": "The request completed successfully.",
52                             "MessageArgs": [],
53                             "MessageId": "Base.1.19.0.Success",
54                             "MessageSeverity": "OK",
55                             "Resolution": "None."
56                         }
57                     ]
58                 })"_json);
59 }
60 
TEST(DbusUtils,AfterPropertySetInternalError)61 TEST(DbusUtils, AfterPropertySetInternalError)
62 {
63     std::shared_ptr<bmcweb::AsyncResp> asyncResp =
64         std::make_shared<bmcweb::AsyncResp>();
65 
66     boost::system::error_code ec =
67         boost::system::errc::make_error_code(boost::system::errc::timed_out);
68     sdbusplus::message_t msg;
69     afterSetProperty(asyncResp, "MyRedfishProperty",
70                      nlohmann::json("MyRedfishValue"), ec, msg);
71 
72     EXPECT_EQ(asyncResp->res.result(),
73               boost::beast::http::status::internal_server_error);
74     EXPECT_EQ(asyncResp->res.jsonValue.size(), 1);
75     using nlohmann::literals::operator""_json;
76 
77     EXPECT_EQ(asyncResp->res.jsonValue,
78               R"({
79                     "error": {
80                     "@Message.ExtendedInfo": [
81                         {
82                         "@odata.type": "#Message.v1_1_1.Message",
83                         "Message": "The request failed due to an internal service error.  The service is still operational.",
84                         "MessageArgs": [],
85                         "MessageId": "Base.1.19.0.InternalError",
86                         "MessageSeverity": "Critical",
87                         "Resolution": "Resubmit the request.  If the problem persists, consider resetting the service."
88                         }
89                     ],
90                     "code": "Base.1.19.0.InternalError",
91                     "message": "The request failed due to an internal service error.  The service is still operational."
92                     }
93                 })"_json);
94 }
95 
96 } // namespace
97 } // namespace redfish::details
98