| #include "app.hpp" |
| #include "async_resp.hpp" |
| #include "dbus_utility.hpp" |
| #include "power_supply.hpp" |
| #include "power_supply_metrics.hpp" |
| #include "snapshot_fixture.hpp" |
| #include "test/g3/mock_managed_store_test.hpp" |
| |
| #include <nlohmann/json.hpp> |
| |
| #include <gmock/gmock.h> |
| #include <gtest/gtest.h> |
| |
| namespace redfish |
| { |
| namespace |
| { |
| |
| using ::managedStore::KeyType; |
| using ::managedStore::ManagedType; |
| using ::managedStore::ValueType; |
| |
| const std::string chassisId = "platform1"; |
| const std::string failChassisId = chassisId + "@"; |
| const std::string validChassisPath = |
| "/xyz/openbmc_project/inventory/system/board/platform1"; |
| const std::string powerSupplyId = "Bigchassis2_1"; |
| const std::string failPowerSupplyId = powerSupplyId + "@"; |
| const std::string powerSensorPath = |
| "/xyz/openbmc_project/sensors/power/powersensor"; |
| |
| TEST_F(SnapshotFixture_Platform11_Config4, handlePowerSupplyMetricsGetTest) |
| { |
| // insert the power sensor |
| KeyType key( |
| ManagedType::kManagedProperty, "xyz.openbmc_project.EntityManager", |
| sdbusplus::message::object_path( |
| "/xyz/openbmc_project/inventory/system/board/" + powerSupplyId), |
| "xyz.openbmc_project.Inventory.Item.PowerSupply", "Sensor"); |
| std::shared_ptr<ValueType> mockSensorPath = |
| managedStore::MockManagedStoreTest::CreateValueType( |
| std::string(powerSensorPath)); |
| |
| ASSERT_TRUE(managedStore::GetManagedObjectStore() |
| ->upsertMockObjectIntoManagedStore(key, mockSensorPath) |
| .ok()); |
| |
| // insert the power sensor value |
| const double sensorValue = 123.45; |
| KeyType key2(ManagedType::kManagedProperty, "xyz.openbmc_project.PSUSensor", |
| sdbusplus::message::object_path(powerSensorPath), |
| "xyz.openbmc_project.Sensor.Value", "Value"); |
| std::shared_ptr<ValueType> mockSensorValue = |
| managedStore::MockManagedStoreTest::CreateValueType(sensorValue); |
| ASSERT_TRUE(managedStore::GetManagedObjectStore() |
| ->upsertMockObjectIntoManagedStore(key2, mockSensorValue) |
| .ok()); |
| |
| handlePowerSupplyMetricsGet(app_, CreateRequest(), share_async_resp_, |
| chassisId, powerSupplyId); |
| |
| RunIoUntilDone(); |
| |
| nlohmann::json& json = share_async_resp_->res.jsonValue; |
| EXPECT_TRUE(json.contains("@odata.id")); |
| EXPECT_TRUE(json.contains("@odata.type")); |
| EXPECT_TRUE(json.contains("InputPowerWatts")); |
| EXPECT_TRUE(json["InputPowerWatts"].contains("DataSourceUri")); |
| EXPECT_TRUE(json["InputPowerWatts"].contains("Reading")); |
| EXPECT_EQ(json["InputPowerWatts"]["Reading"], sensorValue); |
| } |
| |
| TEST_F(SnapshotFixture_Platform11_Config4, handlePowerSupplyMetricsGetNotFound) |
| { |
| // insert the power sensor |
| KeyType key( |
| ManagedType::kManagedProperty, "xyz.openbmc_project.EntityManager", |
| sdbusplus::message::object_path( |
| "/xyz/openbmc_project/inventory/system/board/" + failPowerSupplyId), |
| "xyz.openbmc_project.Inventory.Item.PowerSupply", "Sensor"); |
| std::shared_ptr<ValueType> mockSensorPath = |
| managedStore::MockManagedStoreTest::CreateValueType( |
| std::string(powerSensorPath)); |
| |
| ASSERT_TRUE(managedStore::GetManagedObjectStore() |
| ->upsertMockObjectIntoManagedStore(key, mockSensorPath) |
| .ok()); |
| |
| // insert the power sensor value |
| const double sensorValue = 123.45; |
| KeyType key2(ManagedType::kManagedProperty, "xyz.openbmc_project.PSUSensor", |
| sdbusplus::message::object_path(powerSensorPath), |
| "xyz.openbmc_project.Sensor.Value", "Value"); |
| std::shared_ptr<ValueType> mockSensorValue = |
| managedStore::MockManagedStoreTest::CreateValueType(sensorValue); |
| ASSERT_TRUE(managedStore::GetManagedObjectStore() |
| ->upsertMockObjectIntoManagedStore(key2, mockSensorValue) |
| .ok()); |
| |
| handlePowerSupplyMetricsGet(app_, CreateRequest(), share_async_resp_, |
| failChassisId, powerSupplyId); |
| |
| RunIoUntilDone(); |
| |
| EXPECT_EQ(share_async_resp_->res.result(), |
| boost::beast::http::status::not_found); |
| } |
| |
| TEST_F(SnapshotFixture_Platform11_Config4, handlePowerSupplyMetricsHeadTest) |
| { |
| handlePowerSupplyMetricsHead(app_, CreateRequest(), share_async_resp_, |
| chassisId, powerSupplyId); |
| |
| RunIoUntilDone(); |
| |
| EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok); |
| } |
| |
| TEST_F(SnapshotFixture_Platform11_Config4, handlePowerSupplyMetricsHeadNotFound) |
| { |
| |
| handlePowerSupplyMetricsHead(app_, CreateRequest(), share_async_resp_, |
| failChassisId, powerSupplyId); |
| |
| RunIoUntilDone(); |
| |
| EXPECT_EQ(share_async_resp_->res.result(), |
| boost::beast::http::status::not_found); |
| } |
| |
| } // anonymous namespace |
| } // namespace redfish |