Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended AddedEntityBinding/RemovedEntityBinding event ids with granularity #1797

Merged
merged 2 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 AddedEntityBinding extends AbstractDiffEvaluator {
private static final String ADDED_RESOURCE = "AddedResourceBinding";
private static final String ADDED_OPERATION = "AddedOperationBinding";
private static final String TO_RESOURCE = ".ToResource.";
private static final String TO_SERVICE = ".ToService.";

@Override
public List<ValidationEvent> evaluate(Differences differences) {
Expand All @@ -59,15 +62,16 @@ private Set<ShapeId> findAdded(Set<ShapeId> oldShapes, Set<ShapeId> newShapes) {
return added;
}

private ValidationEvent createAddedEvent(String eventId, EntityShape entity, ShapeId addedShape) {
String descriptor = eventId.equals(ADDED_RESOURCE) ? "Resource" : "Operation";
private ValidationEvent createAddedEvent(String typeOfAddition, EntityShape parentEntity, ShapeId childShape) {
String childType = typeOfAddition.equals(ADDED_RESOURCE) ? "Resource" : "Operation";
String typeOfParentShape = ShapeType.RESOURCE.equals(parentEntity.getType()) ? TO_RESOURCE : TO_SERVICE;
String message = String.format(
"%s binding of `%s` was added to the %s shape, `%s`",
descriptor, addedShape, entity.getType(), entity.getId());
childType, childShape, parentEntity.getType(), parentEntity.getId());
return ValidationEvent.builder()
.id(eventId)
.id(typeOfAddition + typeOfParentShape + childShape.getName())
.severity(Severity.NOTE)
.shape(entity)
.shape(parentEntity)
.message(message)
.build();
}
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 = ".FromResource.";
private static final String FROM_SERVICE = ".FromService.";

@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.getName())
.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").size(), equalTo(1));
assertThat(TestHelper.findEvents(events, "AddedOperationBinding.ToService.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").size(), equalTo(1));
assertThat(TestHelper.findEvents(events, "AddedOperationBinding.ToResource.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").size(), equalTo(1));
assertThat(TestHelper.findEvents(events, "AddedResourceBinding.ToService.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").size(), equalTo(1));
assertThat(TestHelper.findEvents(events, "AddedResourceBinding.ToResource.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.FromService.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.FromResource.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.FromService.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.FromResource.C").size(), equalTo(1));
}
}