SpecificationReader { protected void parseLink(nu.xom.Element eLink, Architecture<Resource, Link> architecture) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { Link link = toEdge(eLink, null); String type = eLink.getAttributeValue("orientation"); EdgeType edgeType = EdgeType.UNDIRECTED; if (type != null) { edgeType = EdgeType.valueOf(type); } String srcName = eLink.getAttributeValue("source"); Resource source = architecture.getVertex(srcName); if (source == null) { throw new IllegalArgumentException("Source of link " + link + " not found: " + srcName); } String dstName = eLink.getAttributeValue("destination"); Resource destination = architecture.getVertex(dstName); if (destination == null) { throw new IllegalArgumentException("Destination of link " + link + " not found: " + dstName); } architecture.addEdge(link, source, destination, edgeType); }  Specification read(String filename); Specification read(File file); Specification read(InputStream in); Specification toSpecification(nu.xom.Element eSpecification);  }
@Test public void parseLinkTest() throws ValidityException, ParsingException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { nu.xom.Element eLink = new Builder() .build("<link id='l2' source='bus' destination='r2' orientation='UNDIRECTED'/>", "").getRootElement(); Architecture<Resource, Link> architecture = new Architecture<Resource, Link>(); Resource r1 = new Resource("bus"); Resource r2 = new Resource("r2"); architecture.addVertex(r1); architecture.addVertex(r2); SpecificationReader r = new SpecificationReader(); r.parseLink(eLink, architecture); Assert.assertTrue(architecture.isNeighbor(r1, r2)); }
@Test(expected = IllegalArgumentException.class) public void parseLinkMissingSrcResourceTest() throws ValidityException, ParsingException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { nu.xom.Element eLink = new Builder() .build("<link id='l2' source='bus' destination='r2' orientation='UNDIRECTED'/>", "").getRootElement(); Architecture<Resource, Link> architecture = new Architecture<Resource, Link>(); Resource r1 = new Resource("bus"); architecture.addVertex(r1); SpecificationReader r = new SpecificationReader(); r.parseLink(eLink, architecture); }
@Test(expected = IllegalArgumentException.class) public void parseLinkMissingDstResourceTest() throws ValidityException, ParsingException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { nu.xom.Element eLink = new Builder() .build("<link id='l2' source='bus' destination='r2' orientation='UNDIRECTED'/>", "").getRootElement(); Architecture<Resource, Link> architecture = new Architecture<Resource, Link>(); Resource r1 = new Resource("r2"); architecture.addVertex(r1); SpecificationReader r = new SpecificationReader(); r.parseLink(eLink, architecture); }