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