SettingsRegistryAdapterTests.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/IO/SystemFile.h>
  9. #include <AzCore/Settings/SettingsRegistry.h>
  10. #include <AzCore/Settings/SettingsRegistryImpl.h>
  11. #include <AzCore/Settings/SettingsRegistryOriginTracker.h>
  12. #include <AzCore/Interface/Interface.h>
  13. #include <AzFramework/DocumentPropertyEditor/AdapterBuilder.h>
  14. #include <AzFramework/DocumentPropertyEditor/SettingsRegistryAdapter.h>
  15. #include <AzFramework/DocumentPropertyEditor/PropertyEditorNodes.h>
  16. #include <Tests/DocumentPropertyEditor/DocumentPropertyEditorFixture.h>
  17. #include <AzCore/JSON/document.h>
  18. #include <AzCore/JSON/writer.h>
  19. namespace AZ::DocumentPropertyEditor::Tests
  20. {
  21. class SettingsRegistryAdapterDpeFixture : public DocumentPropertyEditorTestFixture
  22. {
  23. public:
  24. void SetUp() override
  25. {
  26. DocumentPropertyEditorTestFixture::SetUp();
  27. m_settingsRegistry = AZStd::make_unique<SettingsRegistryImpl>();
  28. m_settingsRegistryOriginTracker = AZStd::make_unique<SettingsRegistryOriginTracker>(*m_settingsRegistry);
  29. AZ::Interface<AZ::SettingsRegistryOriginTracker>::Register(m_settingsRegistryOriginTracker.get());
  30. m_adapter = AZStd::make_unique<SettingsRegistryAdapter>();
  31. }
  32. void TearDown() override
  33. {
  34. m_adapter.reset();
  35. AZ::Interface<AZ::SettingsRegistryOriginTracker>::Unregister(m_settingsRegistryOriginTracker.get());
  36. m_settingsRegistryOriginTracker.reset();
  37. m_settingsRegistry.reset();
  38. DocumentPropertyEditorTestFixture::TearDown();
  39. }
  40. protected:
  41. AZStd::unique_ptr<AZ::SettingsRegistryInterface> m_settingsRegistry;
  42. AZStd::unique_ptr<AZ::SettingsRegistryOriginTracker> m_settingsRegistryOriginTracker;
  43. AZStd::unique_ptr<SettingsRegistryAdapter> m_adapter;
  44. AZ::Test::ScopedAutoTempDirectory m_testFolder;
  45. };
  46. TEST_F(SettingsRegistryAdapterDpeFixture, GenerateContent_MergedSettingsFiles_Displayed)
  47. {
  48. constexpr AZ::IO::PathView filePath1 = "folder1/file1.json";
  49. constexpr AZ::IO::PathView filePath2 = "folder2/file2.json";
  50. ASSERT_TRUE(AZ::Test::CreateTestFile(m_testFolder, filePath1, R"(
  51. {
  52. "O3DE": {
  53. "ArrayValue": [
  54. 3,
  55. 7,
  56. 4000
  57. ],
  58. "ObjectValue": {
  59. "StringKey1": "Hello",
  60. "BoolKey1": true
  61. }
  62. }
  63. }
  64. )"));
  65. ASSERT_TRUE(AZ::Test::CreateTestFile(m_testFolder, filePath2, R"(
  66. {
  67. "O3DE": {
  68. "ArrayValue": [
  69. 27,
  70. 39
  71. ],
  72. "ObjectValue": {
  73. "StringKey1": "Hi",
  74. "IntKey2": 9001,
  75. },
  76. "DoubleValue": 4.0
  77. }
  78. }
  79. )"));
  80. auto tempRootFolder = m_testFolder.GetDirectoryAsFixedMaxPath();
  81. m_settingsRegistry->MergeSettingsFile(
  82. (tempRootFolder / filePath1).Native(), AZ::SettingsRegistryInterface::Format::JsonMergePatch, "", nullptr);
  83. m_settingsRegistry->MergeSettingsFile(
  84. (tempRootFolder / filePath2).Native(), AZ::SettingsRegistryInterface::Format::JsonMergePatch, "", nullptr);
  85. Dom::Value result = m_adapter->GetContents();
  86. AZStd::string_view stringKey1Path = "/O3DE/ObjectValue/StringKey1";
  87. AZStd::string_view stringKey1NewValue = R"(Greetings)";
  88. ASSERT_TRUE(m_settingsRegistry->Set(stringKey1Path, stringKey1NewValue));
  89. result = m_adapter->GetContents();
  90. }
  91. }