PrefabBehaviorTests.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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 <PrefabBuilderTests.h>
  9. #include <PrefabGroup/tests/PrefabBehaviorTestMocks.h>
  10. #include <PrefabGroup/IPrefabGroup.h>
  11. #include <PrefabGroup/PrefabGroup.h>
  12. #include <PrefabGroup/PrefabGroupBehavior.h>
  13. #include <AzTest/Utils.h>
  14. #include <Tests/AssetSystemMocks.h>
  15. #include <AzCore/Serialization/Json/JsonSystemComponent.h>
  16. #include <AzCore/Serialization/SerializeContext.h>
  17. #include <AzCore/std/smart_ptr/make_shared.h>
  18. #include <AzToolsFramework/Asset/AssetSystemComponent.h>
  19. #include <AzToolsFramework/Prefab/Procedural/ProceduralPrefabAsset.h>
  20. #include <AzToolsFramework/Prefab/PrefabDomUtils.h>
  21. #include <AzToolsFramework/ToolsComponents/TransformComponent.h>
  22. #include <SceneAPI/SceneCore/Containers/Scene.h>
  23. #include <SceneAPI/SceneCore/DataTypes/GraphData/IMeshData.h>
  24. #include <SceneAPI/SceneCore/DataTypes/GraphData/ITransform.h>
  25. #include <SceneAPI/SceneCore/DataTypes/Groups/IMeshGroup.h>
  26. #include <SceneAPI/SceneCore/Events/AssetImportRequest.h>
  27. #include <SceneAPI/SceneCore/Events/CallProcessorBus.h>
  28. #include <SceneAPI/SceneCore/Events/ExportEventContext.h>
  29. #include <SceneAPI/SceneCore/Events/ExportProductList.h>
  30. #include <SceneAPI/SceneCore/Mocks/DataTypes/MockIGraphObject.h>
  31. #include <SceneAPI/SceneCore/Events/GraphMetaInfoBus.h>
  32. #include <SceneAPI/SceneData/GraphData/MeshData.h>
  33. #include <PrefabGroup/tests/PrefabBehaviorTests.inl>
  34. namespace UnitTest
  35. {
  36. class PrefabBehaviorTests
  37. : public PrefabBuilderTests
  38. {
  39. public:
  40. void SetUp() override
  41. {
  42. PrefabBuilderTests::SetUp();
  43. m_prefabGroupBehavior = AZStd::make_unique<AZ::SceneAPI::Behaviors::PrefabGroupBehavior>();
  44. m_prefabGroupBehavior->Activate();
  45. // Mocking the asset system replacing the AssetSystem::AssetSystemComponent
  46. AZ::Entity* systemEntity = m_app.FindEntity(AZ::SystemEntityId);
  47. systemEntity->FindComponent<AzToolsFramework::AssetSystem::AssetSystemComponent>()->Deactivate();
  48. using namespace testing;
  49. ON_CALL(m_assetSystemRequestMock, GetSourceInfoBySourcePath(_, _, _)).WillByDefault([](auto* path, auto& info, auto&)
  50. {
  51. return PrefabBehaviorTests::OnGetSourceInfoBySourcePath(path, info);
  52. });
  53. m_assetSystemRequestMock.BusConnect();
  54. m_componentDescriptorHelperEditorMeshComponent = AZStd::make_unique<AZ::Render::EditorMeshComponentHelper>();
  55. m_componentDescriptorHelperEditorMeshComponent->Reflect(m_app.GetSerializeContext());
  56. m_componentDescriptorHelperEditorMeshComponent->Reflect(m_app.GetBehaviorContext());
  57. }
  58. void TearDown() override
  59. {
  60. m_componentDescriptorHelperEditorMeshComponent.reset();
  61. m_assetSystemRequestMock.BusDisconnect();
  62. m_prefabGroupBehavior->Deactivate();
  63. m_prefabGroupBehavior.reset();
  64. PrefabBuilderTests::TearDown();
  65. }
  66. // mock classes and structures
  67. struct MockTransform : public AZ::SceneAPI::DataTypes::ITransform
  68. {
  69. AZ::Matrix3x4 m_matrix = AZ::Matrix3x4::CreateIdentity();
  70. AZ::Matrix3x4& GetMatrix() override
  71. {
  72. return m_matrix;
  73. }
  74. const AZ::Matrix3x4& GetMatrix() const
  75. {
  76. return m_matrix;
  77. }
  78. };
  79. struct TestPreExportEventContext
  80. {
  81. TestPreExportEventContext()
  82. : m_scene("test_context")
  83. {
  84. using namespace AZ::SceneAPI::Events;
  85. m_preExportEventContext = AZStd::make_unique<PreExportEventContext>(m_productList, m_outputDirectory, m_scene, "mock");
  86. }
  87. void SetOutputDirectory(AZStd::string outputDirectory)
  88. {
  89. using namespace AZ::SceneAPI::Events;
  90. m_outputDirectory = AZStd::move(outputDirectory);
  91. m_preExportEventContext = AZStd::make_unique<PreExportEventContext>(m_productList, m_outputDirectory, m_scene, "mock");
  92. }
  93. AZStd::unique_ptr<AZ::SceneAPI::Events::PreExportEventContext> m_preExportEventContext;
  94. AZ::SceneAPI::Events::ExportProductList m_productList;
  95. AZStd::string m_outputDirectory;
  96. AZ::SceneAPI::Containers::Scene m_scene;
  97. };
  98. class MockGraphMetaInfoBus
  99. : public AZ::SceneAPI::Events::GraphMetaInfoBus::Handler
  100. {
  101. public:
  102. MockGraphMetaInfoBus()
  103. {
  104. AZ::SceneAPI::Events::GraphMetaInfoBus::Handler::BusConnect();
  105. }
  106. ~MockGraphMetaInfoBus()
  107. {
  108. AZ::SceneAPI::Events::GraphMetaInfoBus::Handler::BusDisconnect();
  109. }
  110. MOCK_CONST_METHOD2(GetAppliedPolicyNames, void(AZStd::set<AZStd::string>&, const AZ::SceneAPI::Containers::Scene&));
  111. };
  112. // Helpers
  113. static bool OnGetSourceInfoBySourcePath(AZStd::string_view sourcePath, AZ::Data::AssetInfo& assetInfo)
  114. {
  115. if (sourcePath == AZStd::string_view("mock"))
  116. {
  117. assetInfo.m_assetId = AZ::Uuid::CreateRandom();
  118. assetInfo.m_assetType = azrtti_typeid<AZ::Prefab::ProceduralPrefabAsset>();
  119. assetInfo.m_relativePath = "mock/path";
  120. assetInfo.m_sizeBytes = 0;
  121. }
  122. return true;
  123. }
  124. const AZ::Entity* FindEntityByName(
  125. const AzToolsFramework::Prefab::Instance& instance,
  126. const AZStd::string& entityName)
  127. {
  128. const AZ::Entity* result = nullptr;
  129. instance.GetConstEntities(
  130. [&result, entityName](const AZ::Entity& entity)
  131. {
  132. if (entity.GetName() != entityName)
  133. {
  134. return true;
  135. }
  136. else
  137. {
  138. result = &entity;
  139. return false;
  140. }
  141. });
  142. return result;
  143. }
  144. AZStd::shared_ptr<MockTransform> CreateMockTransform(AZ::Matrix3x4& matrix)
  145. {
  146. AZStd::shared_ptr<MockTransform> mocTransform = AZStd::make_shared<MockTransform>();
  147. AZ::Matrix3x4& mocMatrix = mocTransform->GetMatrix();
  148. mocMatrix = matrix;
  149. return mocTransform;
  150. }
  151. bool IsChildOfParent(
  152. const AzToolsFramework::Prefab::Instance& instance,
  153. const AzToolsFramework::Prefab::EntityAlias& childName,
  154. const AzToolsFramework::Prefab::EntityAlias& parentName)
  155. {
  156. const AZ::Entity* childEntity = FindEntityByName(instance, childName);
  157. const AZ::Entity* parentEntity = FindEntityByName(instance, parentName);
  158. if (childEntity && parentEntity)
  159. {
  160. AzToolsFramework::Components::TransformComponent* childTransform =
  161. childEntity->FindComponent<AzToolsFramework::Components::TransformComponent>();
  162. if (childTransform)
  163. {
  164. return (childTransform->GetParentId() == parentEntity->GetId());
  165. }
  166. }
  167. return false;
  168. }
  169. AZStd::unique_ptr<AZ::SceneAPI::Behaviors::PrefabGroupBehavior> m_prefabGroupBehavior;
  170. testing::NiceMock<UnitTests::MockAssetSystemRequest> m_assetSystemRequestMock;
  171. AZStd::unique_ptr<AZ::Render::EditorMeshComponentHelper> m_componentDescriptorHelperEditorMeshComponent;
  172. };
  173. TEST_F(PrefabBehaviorTests, PrefabBehavior_EmptyContextIgnored_Works)
  174. {
  175. auto context = TestPreExportEventContext{};
  176. auto result = AZ::SceneAPI::Events::ProcessingResult::Failure;
  177. AZ::SceneAPI::Events::CallProcessorBus::BroadcastResult(
  178. result,
  179. &AZ::SceneAPI::Events::CallProcessorBus::Events::Process,
  180. context.m_preExportEventContext.get());
  181. EXPECT_EQ(result, AZ::SceneAPI::Events::ProcessingResult::Ignored);
  182. }
  183. TEST_F(PrefabBehaviorTests, PrefabBehavior_SimplePrefab_Works)
  184. {
  185. auto context = TestPreExportEventContext{};
  186. // check for the file at <temp_directory>/mock/fake_prefab.procprefab
  187. AZ::Test::ScopedAutoTempDirectory tempDir;
  188. context.SetOutputDirectory(tempDir.GetDirectory());
  189. auto jsonOutcome = AZ::JsonSerializationUtils::ReadJsonString(Data::jsonPrefab);
  190. ASSERT_TRUE(jsonOutcome);
  191. // Register the asset to generate an AssetId in the catalog
  192. AZ::Data::AssetId assetId;
  193. AZ::Data::AssetCatalogRequestBus::BroadcastResult(
  194. assetId, &AZ::Data::AssetCatalogRequestBus::Events::GetAssetIdByPath, "fake_prefab.procprefab",
  195. azrtti_typeid<AZ::Prefab::ProceduralPrefabAsset>(), true);
  196. auto prefabGroup = AZStd::make_shared<AZ::SceneAPI::SceneData::PrefabGroup>();
  197. prefabGroup.get()->SetId(AZ::Uuid::CreateRandom());
  198. prefabGroup.get()->SetName("fake_prefab");
  199. prefabGroup.get()->SetPrefabDom(AZStd::move(jsonOutcome.GetValue()));
  200. context.m_scene.GetManifest().AddEntry(prefabGroup);
  201. context.m_scene.SetSource("mock", AZ::Uuid::CreateRandom());
  202. auto result = AZ::SceneAPI::Events::ProcessingResult::Failure;
  203. AZ::SceneAPI::Events::CallProcessorBus::BroadcastResult(
  204. result,
  205. &AZ::SceneAPI::Events::CallProcessorBus::Events::Process,
  206. context.m_preExportEventContext.get());
  207. EXPECT_EQ(result, AZ::SceneAPI::Events::ProcessingResult::Success);
  208. AZStd::string pathStr;
  209. AzFramework::StringFunc::Path::ConstructFull(tempDir.GetDirectory(), "mock/fake_prefab.procprefab", pathStr, true);
  210. if (!AZ::IO::SystemFile::Exists(pathStr.c_str()))
  211. {
  212. AZ_Warning("testing", false, "The product asset (%s) is missing", pathStr.c_str());
  213. }
  214. }
  215. TEST_F(PrefabBehaviorTests, PrefabBehavior_UpdateManifestWithEmptyScene_DoesNotFail)
  216. {
  217. using namespace AZ::SceneAPI;
  218. using namespace AZ::SceneAPI::Events;
  219. Containers::Scene scene("empty_scene");
  220. AssetImportRequest::ManifestAction action = AssetImportRequest::ManifestAction::ConstructDefault;
  221. AssetImportRequest::RequestingApplication requester = {};
  222. ProcessingResult result = ProcessingResult::Failure;
  223. AssetImportRequestBus::BroadcastResult(result, &AssetImportRequestBus::Events::UpdateManifest, scene, action, requester);
  224. EXPECT_NE(result, ProcessingResult::Failure);
  225. }
  226. TEST_F(PrefabBehaviorTests, PrefabBehavior_UpdateManifestWithEmptyScene_Ignored)
  227. {
  228. using namespace AZ::SceneAPI;
  229. using namespace AZ::SceneAPI::Events;
  230. Containers::Scene scene("empty_scene");
  231. AssetImportRequest::ManifestAction action = AssetImportRequest::ManifestAction::Update;
  232. AssetImportRequest::RequestingApplication requester = {};
  233. Behaviors::PrefabGroupBehavior prefabGroupBehavior;
  234. ProcessingResult result = ProcessingResult::Failure;
  235. AssetImportRequestBus::BroadcastResult(result, &AssetImportRequestBus::Events::UpdateManifest, scene, action, requester);
  236. EXPECT_EQ(result, ProcessingResult::Ignored);
  237. }
  238. TEST_F(PrefabBehaviorTests, PrefabBehavior_UpdateManifestMockScene_CreatesPrefab)
  239. {
  240. using namespace AZ::SceneAPI;
  241. using namespace AZ::SceneAPI::Events;
  242. #if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS
  243. auto scene = CreateMockScene("Manifest", "C:/o3de/watch.folder/manifest_src_file.xml", "C:/o3de/watch.folder");
  244. #else
  245. auto scene = CreateMockScene("Manifest", "//o3de/watch.folder/manifest_src_file.xml", "//o3de/watch.folder");
  246. #endif
  247. AssetImportRequest::ManifestAction action = AssetImportRequest::ManifestAction::ConstructDefault;
  248. AssetImportRequest::RequestingApplication requester = {};
  249. Behaviors::PrefabGroupBehavior prefabGroupBehavior;
  250. ProcessingResult result = ProcessingResult::Failure;
  251. AssetImportRequestBus::BroadcastResult(result, &AssetImportRequestBus::Events::UpdateManifest, *scene, action, requester);
  252. EXPECT_EQ(result, ProcessingResult::Success);
  253. EXPECT_EQ(scene->GetManifest().GetEntryCount(), 3);
  254. EXPECT_TRUE(azrtti_istypeof<AZ::SceneAPI::DataTypes::IMeshGroup>(scene->GetManifest().GetValue(0).get()));
  255. EXPECT_TRUE(azrtti_istypeof<AZ::SceneAPI::DataTypes::IMeshGroup>(scene->GetManifest().GetValue(1).get()));
  256. EXPECT_TRUE(azrtti_istypeof<AZ::SceneAPI::DataTypes::IPrefabGroup>(scene->GetManifest().GetValue(2).get()));
  257. // The mesh group names are expected to be just the file name relative to the watch folder and not any absolute path
  258. for (size_t i = 0; i < scene->GetManifest().GetEntryCount(); i++)
  259. {
  260. if (azrtti_istypeof<AZ::SceneAPI::DataTypes::IMeshGroup>(scene->GetManifest().GetValue(i).get()))
  261. {
  262. AZ::SceneAPI::DataTypes::IMeshGroup* meshGroup = reinterpret_cast<AZ::SceneAPI::DataTypes::IMeshGroup*>(scene->GetManifest().GetValue(i).get());
  263. AZStd::string groupName = meshGroup->GetName();
  264. EXPECT_TRUE(groupName.starts_with("default_mock_"));
  265. }
  266. }
  267. }
  268. TEST_F(PrefabBehaviorTests, PrefabBehavior_EntityHierarchy_MatchesSceneNodeHierarchy)
  269. {
  270. using namespace AZ::SceneAPI;
  271. using namespace AZ::SceneAPI::Events;
  272. #if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS
  273. auto scene = CreateEmptyMockSceneWithRoot("Manifest", "C:/o3de/watch.folder/manifest_src_file.xml", "C:/o3de/watch.folder");
  274. #else
  275. auto scene = CreateEmptyMockSceneWithRoot("Manifest", "//o3de/watch.folder/manifest_src_file.xml", "//o3de/watch.folder");
  276. #endif
  277. /*---------------------------------------\
  278. Notes on the graph hierarchy:
  279. - 3m is a node with mesh data. Proc prefab builder will create an entity for this node
  280. - 4t contains the transform data for the mesh. It's a child of 3m because a node can only contain one data item.
  281. Proc prefab builder will apply the data of the first child transform to the mesh entity's transform component
  282. - 5t is a standalone child transform node of the mesh node. Proc prefab builder will create an entity for this node
  283. Root
  284. |
  285. 1
  286. |
  287. 2t
  288. / \
  289. 3m 6t
  290. / \
  291. 4t 5t
  292. \---------------------------------------*/
  293. AZ::Matrix3x4 nonIdentityMatrix = AZ::Matrix3x4::CreateScale(AZ::Vector3(10.0f));
  294. // Build up the graph
  295. auto root = scene->GetGraph().GetRoot();
  296. auto index1 = scene->GetGraph().AddChild(root, "1", AZStd::make_shared<DataTypes::MockIGraphObject>(1));
  297. auto index2 = scene->GetGraph().AddChild(index1, "2", CreateMockTransform(nonIdentityMatrix));
  298. auto index3 = scene->GetGraph().AddChild(index2, "3", AZStd::make_shared<AZ::SceneData::GraphData::MeshData>());
  299. auto index4 = scene->GetGraph().AddChild(index3, "4", CreateMockTransform(nonIdentityMatrix));
  300. auto index5 = scene->GetGraph().AddChild(index3, "5", CreateMockTransform(nonIdentityMatrix));
  301. auto index6 = scene->GetGraph().AddChild(index2, "6", CreateMockTransform(nonIdentityMatrix));
  302. scene->GetGraph().MakeEndPoint(index4);
  303. scene->GetGraph().MakeEndPoint(index5);
  304. scene->GetGraph().MakeEndPoint(index6);
  305. AssetImportRequest::ManifestAction action = AssetImportRequest::ManifestAction::ConstructDefault;
  306. AssetImportRequest::RequestingApplication requester = {};
  307. Behaviors::PrefabGroupBehavior prefabGroupBehavior;
  308. ProcessingResult result = ProcessingResult::Failure;
  309. AssetImportRequestBus::BroadcastResult(result, &AssetImportRequestBus::Events::UpdateManifest, *scene, action, requester);
  310. constexpr size_t expectedEntryCount = 2;
  311. EXPECT_EQ(result, ProcessingResult::Success);
  312. EXPECT_EQ(scene->GetManifest().GetEntryCount(), expectedEntryCount);
  313. EXPECT_TRUE(azrtti_istypeof<AZ::SceneAPI::DataTypes::IPrefabGroup>(scene->GetManifest().GetValue(expectedEntryCount - 1).get()));
  314. AZ::SceneAPI::DataTypes::IPrefabGroup* prefabGroup =
  315. reinterpret_cast<AZ::SceneAPI::DataTypes::IPrefabGroup*>(scene->GetManifest().GetValue(expectedEntryCount - 1).get());
  316. AzToolsFramework::Prefab::PrefabDomConstReference prefabDomRef = prefabGroup->GetPrefabDomRef();
  317. ASSERT_TRUE(prefabDomRef.has_value());
  318. // Check that the entity hierarchy of the prefab group is correct.
  319. // Each mesh and each transform not associated with any mesh should have a unique entity
  320. AzToolsFramework::Prefab::Instance instance;
  321. ASSERT_TRUE(AzToolsFramework::Prefab::PrefabDomUtils::LoadInstanceFromPrefabDom(instance, *prefabDomRef));
  322. EXPECT_TRUE(IsChildOfParent(instance, "3", "2")); // Mesh entity is child of a transform entity
  323. EXPECT_TRUE(IsChildOfParent(instance, "6", "2")); // Transform entity is child of another transform entity
  324. EXPECT_FALSE(IsChildOfParent(instance, "4", "3")); // First transform entity is not a child of the mesh entity
  325. EXPECT_TRUE(IsChildOfParent(instance, "5", "3")); // Second transform entity is child of the mesh entity
  326. }
  327. TEST_F(PrefabBehaviorTests, PrefabBehavior_UpdateManifest_ToggleWorks)
  328. {
  329. using namespace AZ::SceneAPI;
  330. using namespace AZ::SceneAPI::Events;
  331. ASSERT_TRUE(AZ::SettingsRegistry::Get());
  332. AZ::SettingsRegistry::Get()->Set("/O3DE/Preferences/Prefabs/CreateDefaults", false);
  333. auto scene = CreateMockScene();
  334. AssetImportRequest::ManifestAction action = AssetImportRequest::ManifestAction::ConstructDefault;
  335. AssetImportRequest::RequestingApplication requester = {};
  336. Behaviors::PrefabGroupBehavior prefabGroupBehavior;
  337. ProcessingResult result = ProcessingResult::Failure;
  338. AssetImportRequestBus::BroadcastResult(result, &AssetImportRequestBus::Events::UpdateManifest, *scene, action, requester);
  339. EXPECT_EQ(result, ProcessingResult::Ignored);
  340. EXPECT_EQ(scene->GetManifest().GetEntryCount(), 0);
  341. }
  342. TEST_F(PrefabBehaviorTests, PrefabBehavior_IgnoreActors_ToggleTrueReturnsIgnored)
  343. {
  344. using namespace AZ::SceneAPI;
  345. using namespace AZ::SceneAPI::Events;
  346. ::testing::NiceMock<MockGraphMetaInfoBus> mockGraphMetaInfoBus;
  347. ON_CALL(mockGraphMetaInfoBus, GetAppliedPolicyNames)
  348. .WillByDefault([](AZStd::set<AZStd::string>& appliedPolicies, const Containers::Scene&)
  349. {
  350. appliedPolicies.insert("ActorGroupBehavior");
  351. });
  352. ASSERT_TRUE(AZ::SettingsRegistry::Get());
  353. AZ::SettingsRegistry::Get()->Set("/O3DE/Preferences/Prefabs/IgnoreActors", true);
  354. auto scene = CreateMockScene();
  355. AssetImportRequest::ManifestAction action = AssetImportRequest::ManifestAction::ConstructDefault;
  356. AssetImportRequest::RequestingApplication requester = {};
  357. Behaviors::PrefabGroupBehavior prefabGroupBehavior;
  358. ProcessingResult result = ProcessingResult::Failure;
  359. AssetImportRequestBus::BroadcastResult(result, &AssetImportRequestBus::Events::UpdateManifest, *scene, action, requester);
  360. EXPECT_EQ(result, ProcessingResult::Ignored);
  361. EXPECT_EQ(scene->GetManifest().GetEntryCount(), 0);
  362. }
  363. TEST_F(PrefabBehaviorTests, PrefabBehavior_IgnoreActors_ToggleTrueReturnsSuccessWhenNoActorDetected)
  364. {
  365. using namespace AZ::SceneAPI;
  366. using namespace AZ::SceneAPI::Events;
  367. ::testing::NiceMock<MockGraphMetaInfoBus> mockGraphMetaInfoBus;
  368. ASSERT_TRUE(AZ::SettingsRegistry::Get());
  369. AZ::SettingsRegistry::Get()->Set("/O3DE/Preferences/Prefabs/IgnoreActors", true);
  370. auto scene = CreateMockScene();
  371. AssetImportRequest::ManifestAction action = AssetImportRequest::ManifestAction::ConstructDefault;
  372. AssetImportRequest::RequestingApplication requester = {};
  373. Behaviors::PrefabGroupBehavior prefabGroupBehavior;
  374. ProcessingResult result = ProcessingResult::Failure;
  375. AssetImportRequestBus::BroadcastResult(result, &AssetImportRequestBus::Events::UpdateManifest, *scene, action, requester);
  376. EXPECT_EQ(result, ProcessingResult::Success);
  377. EXPECT_EQ(scene->GetManifest().GetEntryCount(), 3);
  378. }
  379. TEST_F(PrefabBehaviorTests, PrefabBehavior_IgnoreActors_ToggleFalseReturnsSuccess)
  380. {
  381. using namespace AZ::SceneAPI;
  382. using namespace AZ::SceneAPI::Events;
  383. ::testing::NiceMock<MockGraphMetaInfoBus> mockGraphMetaInfoBus;
  384. ON_CALL(mockGraphMetaInfoBus, GetAppliedPolicyNames)
  385. .WillByDefault([](AZStd::set<AZStd::string>& appliedPolicies, const Containers::Scene&)
  386. {
  387. appliedPolicies.insert("ActorGroupBehavior");
  388. });
  389. ASSERT_TRUE(AZ::SettingsRegistry::Get());
  390. AZ::SettingsRegistry::Get()->Set("/O3DE/Preferences/Prefabs/IgnoreActors", false);
  391. auto scene = CreateMockScene();
  392. AssetImportRequest::ManifestAction action = AssetImportRequest::ManifestAction::ConstructDefault;
  393. AssetImportRequest::RequestingApplication requester = {};
  394. Behaviors::PrefabGroupBehavior prefabGroupBehavior;
  395. ProcessingResult result = ProcessingResult::Failure;
  396. AssetImportRequestBus::BroadcastResult(result, &AssetImportRequestBus::Events::UpdateManifest, *scene, action, requester);
  397. EXPECT_EQ(result, ProcessingResult::Success);
  398. EXPECT_EQ(scene->GetManifest().GetEntryCount(), 3);
  399. }
  400. }