RemoveShapes { RemoveShapes(Collection<Shape> toRemove, List<ModelTransformerPlugin> plugins) { this.toRemove = toRemove; this.plugins = plugins; } RemoveShapes(Collection<Shape> toRemove, List<ModelTransformerPlugin> plugins);   }
@Test public void removesOperationsFromResourcesWhenOperationRemoved() { ResourceShape container = ResourceShape.builder() .id(ShapeId.from("ns.foo#Container")) .addOperation("ns.foo#A") .create(ShapeId.from("ns.foo#B")) .addOperation("ns.foo#C") .build(); OperationShape a = OperationShape.builder() .id("ns.foo#A") .addTrait(new ReadonlyTrait()) .build(); OperationShape b = OperationShape.builder().id("ns.foo#B").build(); OperationShape c = OperationShape.builder().id("ns.foo#C").build(); Model model = Model.builder().addShapes(container, a, b, c).build(); ModelTransformer transformer = ModelTransformer.create(); Model result = transformer.removeShapes(model, Arrays.asList(a, b)); assertThat(result.shapes().count(), Matchers.equalTo(2L)); assertThat(result.getShape(container.getId()), Matchers.not(Optional.empty())); assertThat(result.getShape(c.getId()), Matchers.not(Optional.empty())); assertThat(result.expectShape(container.getId()).asResourceShape().get().getOperations(), Matchers.contains(c.getId())); }
@Test public void removesTraitsFromAuthDefinitionWhenReferenceRemoved() { Model model = Model.assembler() .addImport(getClass().getResource("remove-shapes.json")) .assemble() .unwrap(); ShapeId removedId = ShapeId.from("ns.foo#bar"); Shape removedShape = model.expectShape(removedId); ModelTransformer transformer = ModelTransformer.create(); Model result = transformer.removeShapes(model, Collections.singletonList(removedShape)); ShapeId subjectId = ShapeId.from("ns.foo#auth"); Shape subject = result.expectShape(subjectId); AuthDefinitionTrait trait = subject.getTrait(AuthDefinitionTrait.class).get(); assertFalse(trait.getTraits().contains(removedId)); }
@Test public void removesTraitsFromProtocolDefinitionWhenReferenceRemoved() { Model model = Model.assembler() .addImport(getClass().getResource("remove-shapes.json")) .assemble() .unwrap(); ShapeId removedId = ShapeId.from("ns.foo#baz"); Shape removedShape = model.expectShape(removedId); ModelTransformer transformer = ModelTransformer.create(); Model result = transformer.removeShapes(model, Collections.singletonList(removedShape)); ShapeId subjectId = ShapeId.from("ns.foo#protocol"); Shape subject = result.expectShape(subjectId); ProtocolDefinitionTrait trait = subject.getTrait(ProtocolDefinitionTrait.class).get(); assertFalse(trait.getTraits().contains(removedId)); }