xref: /openbmc/bmcweb/test/redfish-core/include/utils/dbus_utils.cpp (revision 6f056f246d9bcfd611102ee712d4a2935504b448)
1 
2 #include "utils/dbus_utils.hpp"
3 
4 #include "http_request.hpp"
5 #include "http_response.hpp"
6 
7 #include <boost/beast/http/status.hpp>
8 #include <nlohmann/json.hpp>
9 
10 #include <cstdint>
11 #include <optional>
12 #include <string>
13 #include <system_error>
14 #include <vector>
15 
16 #include <gmock/gmock.h>
17 #include <gtest/gtest.h>
18 
19 namespace redfish::details
20 {
21 namespace
22 {
23 
24 TEST(DbusUtils, AfterPropertySetSuccess)
25 {
26     std::shared_ptr<bmcweb::AsyncResp> asyncResp =
27         std::make_shared<bmcweb::AsyncResp>();
28 
29     boost::system::error_code ec;
30     sdbusplus::message_t msg;
31     afterSetProperty(asyncResp, "MyRedfishProperty",
32                      nlohmann::json("MyRedfishValue"), ec, msg);
33 
34     EXPECT_EQ(asyncResp->res.result(), boost::beast::http::status::no_content);
35     EXPECT_TRUE(asyncResp->res.jsonValue.empty());
36 }
37 
38 TEST(DbusUtils, AfterPropertySetInternalError)
39 {
40     std::shared_ptr<bmcweb::AsyncResp> asyncResp =
41         std::make_shared<bmcweb::AsyncResp>();
42 
43     boost::system::error_code ec =
44         boost::system::errc::make_error_code(boost::system::errc::timed_out);
45     sdbusplus::message_t msg;
46     afterSetProperty(asyncResp, "MyRedfishProperty",
47                      nlohmann::json("MyRedfishValue"), ec, msg);
48 
49     EXPECT_EQ(asyncResp->res.result(),
50               boost::beast::http::status::internal_server_error);
51     EXPECT_EQ(asyncResp->res.jsonValue.size(), 1);
52     using nlohmann::literals::operator""_json;
53 
54     EXPECT_EQ(asyncResp->res.jsonValue,
55               R"({
56                     "error": {
57                     "@Message.ExtendedInfo": [
58                         {
59                         "@odata.type": "#Message.v1_1_1.Message",
60                         "Message": "The request failed due to an internal service error.  The service is still operational.",
61                         "MessageArgs": [],
62                         "MessageId": "Base.1.16.0.InternalError",
63                         "MessageSeverity": "Critical",
64                         "Resolution": "Resubmit the request.  If the problem persists, consider resetting the service."
65                         }
66                     ],
67                     "code": "Base.1.16.0.InternalError",
68                     "message": "The request failed due to an internal service error.  The service is still operational."
69                     }
70                 })"_json);
71 }
72 
73 } // namespace
74 } // namespace redfish::details
75