Migrate power_test.cpp from Gerrit to Google3.

PiperOrigin-RevId: 967578190
Change-Id: I6be6ef429a52a01e557aa4b72215b6caffb29853
diff --git a/copy.bara.sky b/copy.bara.sky
index 1c18ce0..43944cf 100644
--- a/copy.bara.sky
+++ b/copy.bara.sky
@@ -291,6 +291,7 @@
     ("test/redfish_core/lib/ports_test.cc", "test/redfish-core/lib/ports_test.cpp"),
     ("test/redfish_core/lib/power_subsystem_test.cc", "test/redfish-core/lib/power_subsystem_test.cpp"),
     ("test/redfish_core/lib/power_supply_metrics_test.cc", "test/redfish-core/lib/power_supply_metrics_test.cpp"),
+    ("test/redfish_core/lib/power_test.cc", "test/redfish-core/lib/power_test.cpp"),
     ("test/redfish_core/lib/service_root_test.cc", "test/redfish-core/lib/service_root_test.cpp"),
     ("test/redfish_core/lib/snapshot_fixture.h", "test/redfish-core/lib/snapshot_fixture.hpp"),
     ("test/redfish_core/lib/snapshot_fixture_test.cc", "test/redfish-core/lib/snapshot_fixture_test.cpp"),
diff --git a/test/redfish-core/lib/power_test.cpp b/test/redfish-core/lib/power_test.cpp
index 0f976be..dd45b70 100644
--- a/test/redfish-core/lib/power_test.cpp
+++ b/test/redfish-core/lib/power_test.cpp
@@ -1,117 +1,114 @@
-#include "async_resp.hpp"
-#include "dbus_utility.hpp"
 #include "power.hpp"
-#include "snapshot_fixture.hpp"
-
-#include <nlohmann/json.hpp>
 
 #include <map>
+#include <string>
+#include <utility>
 #include <vector>
 
 #include <gtest/gtest.h>
+#include "boost/beast/http/status.hpp"  // NOLINT
+#include "dbus_utility.hpp"
+#include "snapshot_fixture.hpp"
+#include <nlohmann/json.hpp>
+#include "managed_store.hpp"
+#include "managed_store_types.hpp"
+#include "test/g3/mock_managed_store_test.hpp"
+#include "sdbusplus/message/native_types.hpp"
 
-namespace redfish
-{
-namespace
-{
+namespace redfish {
+namespace {
 
 using ::dbus::utility::MapperGetSubTreePathsResponse;
 using ::dbus::utility::MapperGetSubTreeResponse;
 using ::managedStore::KeyType;
 using ::managedStore::ManagedType;
-using ::managedStore::ValueType;
 
-TEST_F(SnapshotFixture, chassisPowerStateListTest)
-{
-    const std::string chassisId = "platform1";
-    const std::string powerStatePath =
-        "/xyz/openbmc_project/inventory/system/powerstate/";
-    const std::string powerStatePrefix = "PRSNT_";
-    const int numberOfPowerStates = 100;
+TEST_F(SnapshotFixture, ChassisPowerStateListTest) {
+  const std::string chassisId = "platform1";
+  const std::string powerStatePath =
+      "/xyz/openbmc_project/inventory/system/powerstate/";
+  const std::string powerStatePrefix = "PRSNT_";
+  const int numberOfPowerStates = 100;
 
-    std::vector<std::string> powerStates;
-    std::map<std::string, std::string> expectedState;
-    for (int i = 0; i < numberOfPowerStates; i++)
-    {
-        std::string powerStateName = powerStatePrefix + std::to_string(i);
-        std::string path = powerStatePath + powerStateName;
-        KeyType key(ManagedType::kManagedProperty,
-                    "xyz.openbmc_project.EntityManager",
-                    sdbusplus::message::object_path(path),
-                    "xyz.openbmc_project.Inventory.Item", "Present");
-        bool present = (i % 2 == 0);
-        ASSERT_TRUE(
-            dynamic_cast<managedStore::MockSerializedManagedObjectStore*>(
-                managedStore::GetManagedObjectStore())
-                ->upsertMockObjectIntoManagedStore(
-                    key, managedStore::MockManagedStoreTest::CreateValueType(
-                             present))
-                .ok());
-
-        expectedState.emplace(powerStateName, present ? "Enabled" : "Absent");
-        powerStates.push_back(path);
-    }
-    KeyType key(ManagedType::kManagedSubtreePaths,
-                "/xyz/openbmc_project/inventory", 0,
-                {"xyz.openbmc_project.Inventory.Item.PowerState"});
-
+  std::vector<std::string> powerStates;
+  std::map<std::string, std::string> expectedState;
+  for (int i = 0; i < numberOfPowerStates; i++) {
+    std::string powerStateName = powerStatePrefix + std::to_string(i);
+    std::string path = powerStatePath + powerStateName;
+    KeyType key(ManagedType::kManagedProperty,
+                "xyz.openbmc_project.EntityManager",
+                sdbusplus::message::object_path(path),
+                "xyz.openbmc_project.Inventory.Item", "Present");
+    bool present = (i % 2 == 0);
     ASSERT_TRUE(
         dynamic_cast<managedStore::MockSerializedManagedObjectStore*>(
             managedStore::GetManagedObjectStore())
             ->upsertMockObjectIntoManagedStore(
-                key, managedStore::MockManagedStoreTest::CreateValueType(
-                         std::move(powerStates)))
+                key,
+                managedStore::MockManagedStoreTest::CreateValueType(present))
             .ok());
 
-    KeyType subtree_key(ManagedType::kManagedSubtree, "/xyz/openbmc_project", 0,
-                        {"xyz.openbmc_project.Control.PowerSupplyAttributes"});
+    expectedState.emplace(powerStateName, present ? "Enabled" : "Absent");
+    powerStates.push_back(path);
+  }
+  KeyType key(ManagedType::kManagedSubtreePaths,
+              "/xyz/openbmc_project/inventory", 0,
+              {"xyz.openbmc_project.Inventory.Item.PowerState"});
 
-    MapperGetSubTreeResponse subtree_response = {};
+  ASSERT_TRUE(dynamic_cast<managedStore::MockSerializedManagedObjectStore*>(
+                  managedStore::GetManagedObjectStore())
+                  ->upsertMockObjectIntoManagedStore(
+                      key, managedStore::MockManagedStoreTest::CreateValueType(
+                               std::move(powerStates)))
+                  .ok());
 
-    ASSERT_TRUE(dynamic_cast<managedStore::MockSerializedManagedObjectStore*>(
-                    managedStore::GetManagedObjectStore())
-                    ->upsertMockObjectIntoManagedStore(
-                        subtree_key,
-                        managedStore::MockManagedStoreTest::CreateValueType(
-                            std::move(subtree_response)))
-                    .ok());
+  KeyType subtree_key(ManagedType::kManagedSubtree, "/xyz/openbmc_project", 0,
+                      {"xyz.openbmc_project.Control.PowerSupplyAttributes"});
 
-    handleChassisPowerGet(app_, CreateRequest(), share_async_resp_, chassisId);
+  MapperGetSubTreeResponse subtree_response = {};
 
-    RunIoUntilDone();
+  ASSERT_TRUE(
+      dynamic_cast<managedStore::MockSerializedManagedObjectStore*>(
+          managedStore::GetManagedObjectStore())
+          ->upsertMockObjectIntoManagedStore(
+              subtree_key, managedStore::MockManagedStoreTest::CreateValueType(
+                               std::move(subtree_response)))
+          .ok());
 
-    EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok);
+  handleChassisPowerGet(app_, CreateRequest(), share_async_resp_, chassisId);
 
-    nlohmann::json& jsonValue = share_async_resp_->res.jsonValue;
+  RunIoUntilDone();
 
-    EXPECT_TRUE(jsonValue.contains("Oem"));
-    EXPECT_TRUE(jsonValue["Oem"].contains("Google"));
-    EXPECT_EQ(jsonValue["Oem"]["Google"]["@odata.type"],
-              "#GooglePower.v1_0_0.GooglePower");
-    EXPECT_TRUE(jsonValue["Oem"]["Google"].contains("GooglePowerStates"));
-    EXPECT_EQ(jsonValue["Oem"]["Google"]["GooglePowerStates"].size(),
-              numberOfPowerStates);
+  EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok);
 
-    for (const nlohmann::json& powerState :
-         jsonValue["Oem"]["Google"]["GooglePowerStates"])
-    {
-        EXPECT_TRUE(powerState.contains("Id"));
-        std::string stateId = powerState["Id"];
-        EXPECT_EQ(powerState["@odata.id"],
-                  "/redfish/v1/Chassis/" + chassisId +
-                      "/Power/Oem/Google/PowerStates/" + stateId);
-        EXPECT_EQ(powerState["@odata.type"],
-                  "#GooglePowerState.GooglePowerState");
-        EXPECT_EQ(powerState["Name"], "Power");
-        EXPECT_TRUE(expectedState.contains(stateId));
-        EXPECT_TRUE(powerState.contains("Status"));
-        EXPECT_TRUE(powerState["Status"].contains("State"));
-        EXPECT_EQ(powerState["Status"]["State"], expectedState[stateId]);
-        expectedState.erase(stateId);
-    }
+  nlohmann::json& jsonValue = share_async_resp_->res.jsonValue;
 
-    EXPECT_EQ(expectedState.size(), 0);
+  EXPECT_TRUE(jsonValue.contains("Oem"));
+  EXPECT_TRUE(jsonValue["Oem"].contains("Google"));
+  EXPECT_EQ(jsonValue["Oem"]["Google"]["@odata.type"],
+            "#GooglePower.v1_0_0.GooglePower");
+  EXPECT_TRUE(jsonValue["Oem"]["Google"].contains("GooglePowerStates"));
+  EXPECT_EQ(jsonValue["Oem"]["Google"]["GooglePowerStates"].size(),
+            numberOfPowerStates);
+
+  for (const nlohmann::json& powerState :
+       jsonValue["Oem"]["Google"]["GooglePowerStates"]) {
+    EXPECT_TRUE(powerState.contains("Id"));
+    std::string stateId = powerState["Id"];
+    EXPECT_EQ(powerState["@odata.id"], "/redfish/v1/Chassis/" + chassisId +
+                                           "/Power/Oem/Google/PowerStates/" +
+                                           stateId);
+    EXPECT_EQ(powerState["@odata.type"], "#GooglePowerState.GooglePowerState");
+    EXPECT_EQ(powerState["Name"], "Power");
+    EXPECT_TRUE(expectedState.contains(stateId));
+    EXPECT_TRUE(powerState.contains("Status"));
+    EXPECT_TRUE(powerState["Status"].contains("State"));
+    EXPECT_EQ(powerState["Status"]["State"], expectedState[stateId]);
+    expectedState.erase(stateId);
+  }
+
+  EXPECT_EQ(expectedState.size(), 0);
 }
 
-} // namespace
-} // namespace redfish
+}  // namespace
+}  // namespace redfish