@Test public void serviceShape() { ServiceShape service = ServiceShape.builder() .id("ns.foo#Svc") .version("2017-01-17") .addOperation("ns.foo#Operation") .addResource("ns.foo#Resource") .build(); OperationShape operationShape = OperationShape.builder().id("ns.foo#Operation").build(); ResourceShape resourceShape = ResourceShape.builder().id("ns.foo#Resource").build(); Model model = Model.builder() .addShapes(service, resourceShape, operationShape) .build(); NeighborVisitor neighborVisitor = new NeighborVisitor(model); List<Relationship> relationships = service.accept(neighborVisitor); assertThat(relationships, containsInAnyOrder( Relationship.create(service, RelationshipType.RESOURCE, resourceShape), Relationship.create(service, RelationshipType.OPERATION, operationShape), Relationship.create(resourceShape, RelationshipType.BOUND, service), Relationship.create(operationShape, RelationshipType.BOUND, service))); }
@Override public List<Relationship> serviceShape(ServiceShape shape) { List<Relationship> result = new ArrayList<>(); shape.getOperations().forEach(id -> addBinding(result, shape, id, RelationshipType.OPERATION)); shape.getResources().forEach(id -> addBinding(result, shape, id, RelationshipType.RESOURCE)); return result; }
NeighborVisitor extends ShapeVisitor.Default<List<Relationship>> implements NeighborProvider { @Override public List<Relationship> serviceShape(ServiceShape shape) { List<Relationship> result = new ArrayList<>(); shape.getOperations().forEach(id -> addBinding(result, shape, id, RelationshipType.OPERATION)); shape.getResources().forEach(id -> addBinding(result, shape, id, RelationshipType.RESOURCE)); return result; } }
NeighborVisitor extends ShapeVisitor.Default<List<Relationship>> implements NeighborProvider { @Override public List<Relationship> serviceShape(ServiceShape shape) { List<Relationship> result = new ArrayList<>(); shape.getOperations().forEach(id -> addBinding(result, shape, id, RelationshipType.OPERATION)); shape.getResources().forEach(id -> addBinding(result, shape, id, RelationshipType.RESOURCE)); return result; } NeighborVisitor(Model model); }
NeighborVisitor extends ShapeVisitor.Default<List<Relationship>> implements NeighborProvider { @Override public List<Relationship> serviceShape(ServiceShape shape) { List<Relationship> result = new ArrayList<>(); shape.getOperations().forEach(id -> addBinding(result, shape, id, RelationshipType.OPERATION)); shape.getResources().forEach(id -> addBinding(result, shape, id, RelationshipType.RESOURCE)); return result; } NeighborVisitor(Model model); @Override List<Relationship> getNeighbors(Shape shape); @Override List<Relationship> getDefault(Shape shape); @Override List<Relationship> serviceShape(ServiceShape shape); @Override List<Relationship> resourceShape(ResourceShape shape); @Override List<Relationship> operationShape(OperationShape shape); @Override List<Relationship> memberShape(MemberShape shape); @Override List<Relationship> listShape(ListShape shape); @Override List<Relationship> setShape(SetShape shape); @Override List<Relationship> mapShape(MapShape shape); @Override List<Relationship> structureShape(StructureShape shape); @Override List<Relationship> unionShape(UnionShape shape); }
NeighborVisitor extends ShapeVisitor.Default<List<Relationship>> implements NeighborProvider { @Override public List<Relationship> serviceShape(ServiceShape shape) { List<Relationship> result = new ArrayList<>(); shape.getOperations().forEach(id -> addBinding(result, shape, id, RelationshipType.OPERATION)); shape.getResources().forEach(id -> addBinding(result, shape, id, RelationshipType.RESOURCE)); return result; } NeighborVisitor(Model model); @Override List<Relationship> getNeighbors(Shape shape); @Override List<Relationship> getDefault(Shape shape); @Override List<Relationship> serviceShape(ServiceShape shape); @Override List<Relationship> resourceShape(ResourceShape shape); @Override List<Relationship> operationShape(OperationShape shape); @Override List<Relationship> memberShape(MemberShape shape); @Override List<Relationship> listShape(ListShape shape); @Override List<Relationship> setShape(SetShape shape); @Override List<Relationship> mapShape(MapShape shape); @Override List<Relationship> structureShape(StructureShape shape); @Override List<Relationship> unionShape(UnionShape shape);  }