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 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::ok); 33 EXPECT_EQ(asyncResp->res.jsonValue, 34 R"({ 35 "@Message.ExtendedInfo": [ 36 { 37 "@odata.type": "#Message.v1_1_1.Message", 38 "Message": "The request completed successfully.", 39 "MessageArgs": [], 40 "MessageId": "Base.1.18.1.Success", 41 "MessageSeverity": "OK", 42 "Resolution": "None." 43 } 44 ] 45 })"_json); 46 } 47 48 TEST(DbusUtils, AfterPropertySetInternalError) 49 { 50 std::shared_ptr<bmcweb::AsyncResp> asyncResp = 51 std::make_shared<bmcweb::AsyncResp>(); 52 53 boost::system::error_code ec = 54 boost::system::errc::make_error_code(boost::system::errc::timed_out); 55 sdbusplus::message_t msg; 56 afterSetProperty(asyncResp, "MyRedfishProperty", 57 nlohmann::json("MyRedfishValue"), ec, msg); 58 59 EXPECT_EQ(asyncResp->res.result(), 60 boost::beast::http::status::internal_server_error); 61 EXPECT_EQ(asyncResp->res.jsonValue.size(), 1); 62 using nlohmann::literals::operator""_json; 63 64 EXPECT_EQ(asyncResp->res.jsonValue, 65 R"({ 66 "error": { 67 "@Message.ExtendedInfo": [ 68 { 69 "@odata.type": "#Message.v1_1_1.Message", 70 "Message": "The request failed due to an internal service error. The service is still operational.", 71 "MessageArgs": [], 72 "MessageId": "Base.1.18.1.InternalError", 73 "MessageSeverity": "Critical", 74 "Resolution": "Resubmit the request. If the problem persists, consider resetting the service." 75 } 76 ], 77 "code": "Base.1.18.1.InternalError", 78 "message": "The request failed due to an internal service error. The service is still operational." 79 } 80 })"_json); 81 } 82 83 } // namespace 84 } // namespace redfish::details 85