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