Skip to content

Commit

Permalink
Extended RemovedEntityBinding events as well
Browse files Browse the repository at this point in the history
  • Loading branch information
rchache committed Jun 2, 2023
1 parent fb16e74 commit 5ee2e55
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ValidationEvent> evaluate(Differences differences) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<ValidationEvent> evaluate(Differences differences) {
Expand All @@ -59,15 +62,16 @@ private Set<ShapeId> findRemoved(Set<ShapeId> oldShapes, Set<ShapeId> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void detectsAddedOperationToService() {
Model modelB = Model.assembler().addShapes(service1, o).assemble().unwrap();
List<ValidationEvent> 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
Expand All @@ -53,7 +53,7 @@ public void detectsAddedOperationToResource() {
Model modelB = Model.assembler().addShapes(r1, o).assemble().unwrap();
List<ValidationEvent> 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
Expand All @@ -69,7 +69,7 @@ public void detectsAddedResourceToService() {
Model modelB = Model.assembler().addShapes(service1, r).assemble().unwrap();
List<ValidationEvent> 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
Expand All @@ -81,6 +81,6 @@ public void detectsAddedResourceToResource() {
Model modelB = Model.assembler().addShapes(p1, child).assemble().unwrap();
List<ValidationEvent> 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void detectsRemovedOperationFromService() {
Model modelB = Model.assembler().addShapes(service2, o).assemble().unwrap();
List<ValidationEvent> 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
Expand All @@ -53,7 +53,7 @@ public void detectsRemovedOperationFromResource() {
Model modelB = Model.assembler().addShapes(r2, o).assemble().unwrap();
List<ValidationEvent> 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
Expand All @@ -69,7 +69,7 @@ public void detectsRemovedResourceFromService() {
Model modelB = Model.assembler().addShapes(service2, r).assemble().unwrap();
List<ValidationEvent> 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
Expand All @@ -81,6 +81,6 @@ public void detectsRemovedResourceFromResource() {
Model modelB = Model.assembler().addShapes(p2, child).assemble().unwrap();
List<ValidationEvent> 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));
}
}

0 comments on commit 5ee2e55

Please sign in to comment.