blob: df428a067f79f945ac85550fa70e4d5b49efc032 [file] [log] [blame]
#include "cable.hpp"
#include "nlohmann/json.hpp"
#include "snapshot_fixture.hpp"
#include <gtest/gtest.h>
namespace redfish
{
namespace
{
class SnapshotFixture_CableFru : public redfish::SnapshotFixture
{
protected:
SnapshotFixture_CableFru() : app_(false)
{
share_async_resp_ = std::make_shared<bmcweb::AsyncResp>();
};
static void SetUpTestSuite()
{
// Have to manually call this as defining this current function prevents
// its parent's Setup from being called
::managedStore::MockManagedStoreTest::SetUpTestSuite();
EXPECT_TRUE(managedStore::GetManagedObjectStore()->deserialize(
snapshotFilepath_cableFru));
}
// Use this to create a crow request for use in handlers
static crow::Request CreateRequest(const std::string& reqIn = "")
{
// Dont need this error code ever
std::error_code ec;
return crow::Request(reqIn, ec);
}
std::shared_ptr<bmcweb::AsyncResp> share_async_resp_;
App app_;
};
TEST_F(SnapshotFixture_CableFru, handleCableGetTest)
{
constexpr char kCable[] = "ioadapter_x16_1";
handleCableGet(app_, CreateRequest(), share_async_resp_, kCable);
RunIoUntilDone();
nlohmann::json& json = share_async_resp_->res.jsonValue;
EXPECT_EQ(json["@odata.type"], "#Cable.v1_0_0.Cable");
EXPECT_EQ(json["@odata.id"],
crow::utility::urlFromPieces("redfish", "v1", "Cables", kCable));
EXPECT_EQ(json["Id"], kCable);
EXPECT_EQ(json["Name"], "Cable");
EXPECT_EQ(json["Status"]["State"], "Enabled");
EXPECT_TRUE(json.contains("Model"));
EXPECT_TRUE(json.contains("Manufacturer"));
EXPECT_TRUE(json.contains("PartNumber"));
EXPECT_TRUE(json.contains("SerialNumber"));
}
TEST_F(SnapshotFixture_CableFru, getCableChassisAssociationTest)
{
constexpr char kCable[] = "NcsiCable";
handleCableGet(app_, CreateRequest(), share_async_resp_, kCable);
RunIoUntilDone();
nlohmann::json& json = share_async_resp_->res.jsonValue;
EXPECT_EQ(json["@odata.type"], "#Cable.v1_0_0.Cable");
EXPECT_EQ(json["@odata.id"],
crow::utility::urlFromPieces("redfish", "v1", "Cables", kCable));
EXPECT_EQ(json["Id"], kCable);
EXPECT_EQ(json["Links"]["DownstreamChassis"][0]["@odata.id"],
crow::utility::urlFromPieces("redfish", "v1", "Chassis", "chassis3_1"));
EXPECT_EQ(json["Links"]["UpstreamChassis"][0]["@odata.id"],
crow::utility::urlFromPieces("redfish", "v1", "Chassis", "platform5"));
EXPECT_EQ(json["Name"], "Cable");
EXPECT_EQ(json["Status"]["State"], "Enabled");
EXPECT_TRUE(json.contains("Model"));
}
} // namespace
} // namespace redfish