From 5ee2e557d424a35f5625dac23ba2dc0e960dd9a0 Mon Sep 17 00:00:00 2001 From: Richard Chen Date: Fri, 2 Jun 2023 14:49:20 -0400 Subject: [PATCH] Extended RemovedEntityBinding events as well --- .../smithy/diff/evaluators/AddedEntityBinding.java | 4 ++-- .../diff/evaluators/RemovedEntityBinding.java | 14 +++++++++----- .../diff/evaluators/AddedEntityBindingTest.java | 8 ++++---- .../diff/evaluators/RemovedEntityBindingTest.java | 8 ++++---- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedEntityBinding.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedEntityBinding.java index 6b2028cce40..d366cba08b3 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedEntityBinding.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedEntityBinding.java @@ -38,8 +38,8 @@ public final class AddedEntityBinding extends AbstractDiffEvaluator { private static final String ADDED_RESOURCE = "AddedResourceBinding"; private static final String ADDED_OPERATION = "AddedOperationBinding"; - private static final String TO_RESOURCE = ".ToResourceShapeBound."; - private static final String TO_SERVICE = ".ToServiceShapeBound."; + private static final String TO_RESOURCE = ".ToResourceAdded."; + private static final String TO_SERVICE = ".ToServiceAdded."; @Override public List evaluate(Differences differences) { diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedEntityBinding.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedEntityBinding.java index 334f385a180..162309c4f30 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedEntityBinding.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedEntityBinding.java @@ -23,6 +23,7 @@ import software.amazon.smithy.diff.Differences; import software.amazon.smithy.model.shapes.EntityShape; import software.amazon.smithy.model.shapes.ShapeId; +import software.amazon.smithy.model.shapes.ShapeType; import software.amazon.smithy.model.validation.Severity; import software.amazon.smithy.model.validation.ValidationEvent; @@ -37,6 +38,8 @@ public final class RemovedEntityBinding extends AbstractDiffEvaluator { private static final String REMOVED_RESOURCE = "RemovedResourceBinding"; private static final String REMOVED_OPERATION = "RemovedOperationBinding"; + private static final String FROM_RESOURCE = ".FromResourceRemoved."; + private static final String FROM_SERVICE = ".FromServiceRemoved."; @Override public List evaluate(Differences differences) { @@ -59,15 +62,16 @@ private Set findRemoved(Set oldShapes, Set newShapes) return removed; } - private ValidationEvent createRemovedEvent(String eventId, EntityShape entity, ShapeId removedShape) { - String descriptor = eventId.equals(REMOVED_RESOURCE) ? "Resource" : "Operation"; + private ValidationEvent createRemovedEvent(String typeOfRemoval, EntityShape parentEntity, ShapeId childShape) { + String childType = typeOfRemoval.equals(REMOVED_RESOURCE) ? "Resource" : "Operation"; + String typeOfParentShape = ShapeType.RESOURCE.equals(parentEntity.getType()) ? FROM_RESOURCE : FROM_SERVICE; String message = String.format( "%s binding of `%s` was removed from %s shape, `%s`", - descriptor, removedShape, entity.getType(), entity.getId()); + childType, childShape, parentEntity.getType(), parentEntity.getId()); return ValidationEvent.builder() - .id(eventId) + .id(typeOfRemoval + typeOfParentShape + childShape) .severity(Severity.ERROR) - .shape(entity) + .shape(parentEntity) .message(message) .build(); } diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedEntityBindingTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedEntityBindingTest.java index 4cff8debe51..d9df9956d08 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedEntityBindingTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedEntityBindingTest.java @@ -41,7 +41,7 @@ public void detectsAddedOperationToService() { Model modelB = Model.assembler().addShapes(service1, o).assemble().unwrap(); List events = ModelDiff.compare(modelA, modelB); - assertThat(TestHelper.findEvents(events, "AddedOperationBinding.ToServiceShapeBound.foo.baz#Operation").size(), equalTo(1)); + assertThat(TestHelper.findEvents(events, "AddedOperationBinding.ToServiceAdded.foo.baz#Operation").size(), equalTo(1)); } @Test @@ -53,7 +53,7 @@ public void detectsAddedOperationToResource() { Model modelB = Model.assembler().addShapes(r1, o).assemble().unwrap(); List events = ModelDiff.compare(modelA, modelB); - assertThat(TestHelper.findEvents(events, "AddedOperationBinding.ToResourceShapeBound.foo.baz#Operation").size(), equalTo(1)); + assertThat(TestHelper.findEvents(events, "AddedOperationBinding.ToResourceAdded.foo.baz#Operation").size(), equalTo(1)); } @Test @@ -69,7 +69,7 @@ public void detectsAddedResourceToService() { Model modelB = Model.assembler().addShapes(service1, r).assemble().unwrap(); List events = ModelDiff.compare(modelA, modelB); - assertThat(TestHelper.findEvents(events, "AddedResourceBinding.ToServiceShapeBound.foo.baz#Resource").size(), equalTo(1)); + assertThat(TestHelper.findEvents(events, "AddedResourceBinding.ToServiceAdded.foo.baz#Resource").size(), equalTo(1)); } @Test @@ -81,6 +81,6 @@ public void detectsAddedResourceToResource() { Model modelB = Model.assembler().addShapes(p1, child).assemble().unwrap(); List events = ModelDiff.compare(modelA, modelB); - assertThat(TestHelper.findEvents(events, "AddedResourceBinding.ToResourceShapeBound.foo.baz#C").size(), equalTo(1)); + assertThat(TestHelper.findEvents(events, "AddedResourceBinding.ToResourceAdded.foo.baz#C").size(), equalTo(1)); } } diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedEntityBindingTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedEntityBindingTest.java index 8053f461753..94790b5c971 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedEntityBindingTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedEntityBindingTest.java @@ -41,7 +41,7 @@ public void detectsRemovedOperationFromService() { Model modelB = Model.assembler().addShapes(service2, o).assemble().unwrap(); List events = ModelDiff.compare(modelA, modelB); - assertThat(TestHelper.findEvents(events, "RemovedOperationBinding").size(), equalTo(1)); + assertThat(TestHelper.findEvents(events, "RemovedOperationBinding.FromServiceRemoved.foo.baz#Operation").size(), equalTo(1)); } @Test @@ -53,7 +53,7 @@ public void detectsRemovedOperationFromResource() { Model modelB = Model.assembler().addShapes(r2, o).assemble().unwrap(); List events = ModelDiff.compare(modelA, modelB); - assertThat(TestHelper.findEvents(events, "RemovedOperationBinding").size(), equalTo(1)); + assertThat(TestHelper.findEvents(events, "RemovedOperationBinding.FromResourceRemoved.foo.baz#Operation").size(), equalTo(1)); } @Test @@ -69,7 +69,7 @@ public void detectsRemovedResourceFromService() { Model modelB = Model.assembler().addShapes(service2, r).assemble().unwrap(); List events = ModelDiff.compare(modelA, modelB); - assertThat(TestHelper.findEvents(events, "RemovedResourceBinding").size(), equalTo(1)); + assertThat(TestHelper.findEvents(events, "RemovedResourceBinding.FromServiceRemoved.foo.baz#Resource").size(), equalTo(1)); } @Test @@ -81,6 +81,6 @@ public void detectsRemovedResourceFromResource() { Model modelB = Model.assembler().addShapes(p2, child).assemble().unwrap(); List events = ModelDiff.compare(modelA, modelB); - assertThat(TestHelper.findEvents(events, "RemovedResourceBinding").size(), equalTo(1)); + assertThat(TestHelper.findEvents(events, "RemovedResourceBinding.FromResourceRemoved.foo.baz#C").size(), equalTo(1)); } }