1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors 3 #include "file_test_utilities.hpp" 4 #include "metadata.hpp" 5 6 #include <filesystem> 7 #include <format> 8 #include <string_view> 9 10 #include <gtest/gtest.h> 11 12 namespace redfish 13 { 14 namespace 15 { 16 17 /* 18 Example from Redfish and OData whitepaper. 19 20 https://www.dmtf.org/sites/default/files/standards/documents/DSP2052_1.0.0.pdf 21 */ 22 constexpr std::string_view content = 23 "<edmx:Edmx xmlns:edms=\"http://docs.oasis-open.org/odata/ns/edmx\" Version=\"4.0\">\n" 24 " <edmx:Reference Uri=\"http://contoso.org/schemas/ExternalSchema.xml\">\n" 25 " <edmx:Include Namespace=\"ExternalNamespace\"/>\n" 26 " <edmx:Include Namespace=\"Other.Namespace\"/>\n" 27 " </edmx:Reference>\n" 28 " <edmx:DataServices>\n" 29 " <Schema xmlns=\"http://docs.oasis-open.org/odata/ns/edm\" Namespace=\"MyNewNamespace\">\n" 30 " <ComplexType Name=\"MyDataType\">\n" 31 " <Property Name=\"MyProperty\" Type=\"ExternalNamespace.ReferencedDataType\"/>\n" 32 " <Property Name=\"MyProperty2\" Type=\"Other.Namespace.OtherDataType\"/>\n" 33 " <Property Name=\"MyProperty3\" Type=\"Edm.Int64\"/>\n" 34 " </ComplexType>\n" 35 " </Schema>\n" 36 " </edmx:DataServices>\n" 37 "</edmx:Edmx>\n"; 38 TEST(MetadataGet,GetOneFile)39TEST(MetadataGet, GetOneFile) 40 { 41 TemporaryFileHandle file(content); 42 43 std::filesystem::path path{file.stringPath}; 44 EXPECT_EQ( 45 getMetadataPieceForFile(path), 46 std::format(" <edmx:Reference Uri=\"/redfish/v1/schema/{}\">\n" 47 " <edmx:Include Namespace=\"MyNewNamespace\"/>\n" 48 " </edmx:Reference>\n", 49 path.filename().string())); 50 51 EXPECT_EQ(getMetadataPieceForFile("DoesNotExist_v1.xml"), ""); 52 } 53 54 } // namespace 55 } // namespace redfish 56