Fixed pre-delete warning check

This commit is contained in:
2023-05-08 15:14:03 -05:00
parent 265847e01a
commit db770c7e03
2 changed files with 26 additions and 1 deletions

View File

@ -151,7 +151,7 @@ public class DeleteAction
recordsWithValidationErrors.add(record);
primaryKeysToRemoveFromInput.add(record.getValue(primaryKeyField));
}
else
else if(CollectionUtils.nullSafeHasContents(record.getWarnings()))
{
recordsWithValidationWarnings.add(record);
}

View File

@ -86,6 +86,27 @@ class AbstractPreDeleteCustomizerTest extends BaseTest
getOutput = new GetAction().execute(getInput);
assertNull(getOutput.getRecord());
}
////////////////////////////////////////////////////////////
// try a delete that the pre-customizer should warn about //
////////////////////////////////////////////////////////////
{
DeleteInput deleteInput = new DeleteInput();
deleteInput.setTableName(TestUtils.TABLE_NAME_PERSON_MEMORY);
deleteInput.setPrimaryKeys(List.of(3));
DeleteOutput deleteOutput = new DeleteAction().execute(deleteInput);
assertEquals(0, deleteOutput.getRecordsWithErrors().size());
assertEquals(1, deleteOutput.getRecordsWithWarnings().size());
assertEquals(3, deleteOutput.getRecordsWithWarnings().get(0).getValue("id"));
assertEquals(1, deleteOutput.getDeletedRecordCount());
assertEquals("It was a bad idea to delete Bart", deleteOutput.getRecordsWithWarnings().get(0).getWarnings().get(0));
GetInput getInput = new GetInput();
getInput.setTableName(TestUtils.TABLE_NAME_PERSON_MEMORY);
getInput.setPrimaryKey(3);
GetOutput getOutput = new GetAction().execute(getInput);
assertNull(getOutput.getRecord());
}
}
@ -108,6 +129,10 @@ class AbstractPreDeleteCustomizerTest extends BaseTest
{
record.addError("You may not delete a Homer.");
}
else if(record.getValue("firstName").equals("Bart"))
{
record.addWarning("It was a bad idea to delete Bart");
}
}
return (records);