xref: /openbmc/bmcweb/test/redfish-core/lib/power_subsystem_test.cpp (revision 40e9b92ec19acffb46f83a6e55b18974da5d708e)
1 // SPDX-License-Identifier: Apache-2.0
2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors
3 #include "async_resp.hpp"
4 #include "http_response.hpp"
5 #include "power_subsystem.hpp"
6 
7 #include <nlohmann/json.hpp>
8 
9 #include <memory>
10 #include <optional>
11 #include <string>
12 
13 #include <gtest/gtest.h>
14 
15 namespace redfish
16 {
17 namespace
18 {
19 
20 constexpr const char* chassisId = "ChassisId";
21 constexpr const char* validChassisPath = "ChassisPath";
22 
assertPowerSubsystemCollectionGet(crow::Response & res)23 void assertPowerSubsystemCollectionGet(crow::Response& res)
24 {
25     nlohmann::json& json = res.jsonValue;
26     EXPECT_EQ(json["@odata.type"], "#PowerSubsystem.v1_1_0.PowerSubsystem");
27     EXPECT_EQ(json["Name"], "Power Subsystem");
28     EXPECT_EQ(json["Id"], "PowerSubsystem");
29     EXPECT_EQ(json["@odata.id"],
30               "/redfish/v1/Chassis/ChassisId/PowerSubsystem");
31     EXPECT_EQ(json["Status"]["State"], "Enabled");
32     EXPECT_EQ(json["Status"]["Health"], "OK");
33 }
34 
TEST(PowerSubsystemCollectionTest,PowerSubsystemCollectionStaticAttributesAreExpected)35 TEST(PowerSubsystemCollectionTest,
36      PowerSubsystemCollectionStaticAttributesAreExpected)
37 {
38     auto shareAsyncResp = std::make_shared<bmcweb::AsyncResp>();
39     shareAsyncResp->res.setCompleteRequestHandler(
40         assertPowerSubsystemCollectionGet);
41     doPowerSubsystemCollection(
42         shareAsyncResp, chassisId,
43         std::make_optional<std::string>(validChassisPath));
44 }
45 
46 } // namespace
47 } // namespace redfish
48