Make prefab patch application use a best effort mechanism
Signed-off-by: srikappa <srikappa@amazon.com>
This commit is contained in:
@@ -110,7 +110,15 @@ namespace AZ
|
||||
|
||||
if (result.GetProcessing() == Processing::Halted)
|
||||
{
|
||||
return result;
|
||||
ResultCode reportedResult = settings.m_reporting(R"(One of the patches couldn't be applied correctly.)", result, element);
|
||||
if (reportedResult.GetOutcome() == Outcomes::PartialSkip)
|
||||
{
|
||||
result = reportedResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include <AzCore/Math/Vector3.h>
|
||||
#include <AzCore/Serialization/Json/JsonSerializationSettings.h>
|
||||
#include <AzCore/std/string/string_view.h>
|
||||
#include <Tests/Serialization/Json/JsonSerializationTests.h>
|
||||
|
||||
@@ -43,7 +44,9 @@ namespace JsonSerializationTests
|
||||
}
|
||||
|
||||
void CheckApplyPatchOutcome(const char* target, const char* patch,
|
||||
AZ::JsonSerializationResult::Outcomes outcome, AZ::JsonSerializationResult::Processing processing)
|
||||
AZ::JsonSerializationResult::Outcomes outcome,
|
||||
AZ::JsonSerializationResult::Processing processing,
|
||||
const AZ::JsonApplyPatchSettings& settings = AZ::JsonApplyPatchSettings{})
|
||||
{
|
||||
m_jsonDocument->Parse(target);
|
||||
ASSERT_FALSE(m_jsonDocument->HasParseError());
|
||||
@@ -53,12 +56,27 @@ namespace JsonSerializationTests
|
||||
ASSERT_FALSE(patchDocument.HasParseError());
|
||||
|
||||
AZ::JsonSerializationResult::ResultCode result = AZ::JsonSerialization::ApplyPatch(*m_jsonDocument,
|
||||
m_jsonDocument->GetAllocator(), patchDocument, AZ::JsonMergeApproach::JsonPatch);
|
||||
m_jsonDocument->GetAllocator(), patchDocument, AZ::JsonMergeApproach::JsonPatch, settings);
|
||||
EXPECT_EQ(result.GetTask(), AZ::JsonSerializationResult::Tasks::Merge);
|
||||
EXPECT_EQ(result.GetOutcome(), outcome);
|
||||
EXPECT_EQ(result.GetProcessing(), processing);
|
||||
}
|
||||
|
||||
void CheckApplyPatchOutcome(
|
||||
const char* target,
|
||||
const char* patch,
|
||||
const char* expectedPatchedResult,
|
||||
AZ::JsonSerializationResult::Outcomes outcome,
|
||||
AZ::JsonSerializationResult::Processing processing,
|
||||
const AZ::JsonApplyPatchSettings& settings = AZ::JsonApplyPatchSettings{})
|
||||
{
|
||||
CheckApplyPatchOutcome(target, patch, outcome, processing, settings);
|
||||
rapidjson::Document expectedPatchedDocument;
|
||||
expectedPatchedDocument.Parse(expectedPatchedResult);
|
||||
ASSERT_FALSE(expectedPatchedDocument.HasParseError());
|
||||
EXPECT_EQ(AZ::JsonSerialization::Compare(expectedPatchedDocument, *m_jsonDocument), AZ::JsonSerializerCompareResult::Equal);
|
||||
}
|
||||
|
||||
void CheckCreatePatch_Core(const char* source, AZStd::string_view patch, const char* target,
|
||||
AZ::JsonMergeApproach approach)
|
||||
{
|
||||
@@ -262,6 +280,36 @@ namespace JsonSerializationTests
|
||||
Outcomes::TypeMismatch, Processing::Halted);
|
||||
}
|
||||
|
||||
TEST_F(JsonPatchingSerializationTests, ApplyPatch_UseJsonPatchWithCustomReportingCallback_ReportPartialSkip)
|
||||
{
|
||||
using namespace AZ::JsonSerializationResult;
|
||||
auto issueReportingCallback = [](AZStd::string_view, AZ::JsonSerializationResult::ResultCode result,
|
||||
AZStd::string_view) -> AZ::JsonSerializationResult::ResultCode
|
||||
{
|
||||
using namespace AZ::JsonSerializationResult;
|
||||
if (result.GetProcessing() == Processing::Halted)
|
||||
{
|
||||
return ResultCode(result.GetTask(), Outcomes::PartialSkip);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
AZ::JsonApplyPatchSettings applyPatchSettings;
|
||||
applyPatchSettings.m_reporting = AZStd::move(issueReportingCallback);
|
||||
CheckApplyPatchOutcome(
|
||||
R"({})",
|
||||
R"([
|
||||
{ "op": "add", "path": "/nonexistent_key/new_member", "value": "someValue" },
|
||||
{ "op": "add", "path": "/test", "value": "someValue" }
|
||||
])",
|
||||
R"(
|
||||
{ "test": "someValue" }
|
||||
)",
|
||||
Outcomes::PartialSkip,
|
||||
Processing::Completed,
|
||||
AZStd::move(applyPatchSettings));
|
||||
}
|
||||
|
||||
TEST_F(JsonPatchingSerializationTests, ApplyPatch_UseJsonPatchAddUnnamedMember_ReportsSuccess)
|
||||
{
|
||||
CheckApplyPatch(
|
||||
|
||||
Reference in New Issue
Block a user