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