/** * */ package it.univr.di.cstnu.graph; import org.junit.Assert; import org.junit.Test; import org.xml.sax.SAXException; import javax.xml.parsers.ParserConfigurationException; import java.io.File; import java.io.IOException; import java.util.Objects; /** * Allows to read a tNGraph from a file written in GraphML format.
* GraphML format allows the definition of different attributes for the tNGraph, vertices and edges.
* All attributes are defined in the first part of a GraphML file. Examples of GraphML file that can read by this class are given in the Instances directory * under CstnuTool one. * * @author posenato * @version $Id: $Id */ public class CSTNUGraphMLReaderTest { /** * */ static File fileCSTNU = new File("src/test/resources/testGraphML.cstnu"); /** * */ static File fileSTN = new File("src/test/resources/testGraphML.stn"); /** * */ TNGraphMLReader readerCSTNU; /** * */ TNGraphMLReader readerSTN; /** * */ TNGraph cstnu; /** * */ TNGraph stn; /** * @throws IOException nope * @throws ParserConfigurationException nope * @throws SAXException nope */ @Test public void testCSTNU() throws Exception { this.readerCSTNU = new TNGraphMLReader<>(); this.cstnu = this.readerCSTNU.readGraph(fileCSTNU, CSTNUEdgePluggable.class); Assert.assertEquals(1, Objects.requireNonNull(this.cstnu.getEdge("YX")).upperCaseValueSize()); Assert.assertEquals(2, Objects.requireNonNull(this.cstnu.getEdge("XY")).getLowerCaseValue().getValue()); Assert.assertEquals(2, this.cstnu.getEdgeCount()); } /** * @throws IOException nope * @throws ParserConfigurationException nope * @throws SAXException nope */ @Test public void testSTN() throws Exception { this.readerSTN = new TNGraphMLReader<>(); this.stn = this.readerSTN.readGraph(fileSTN, STNEdgeInt.class); Assert.assertEquals(18, this.stn.getEdgeCount()); Assert.assertEquals(-1, Objects.requireNonNull(this.stn.getEdge("e7")).getValue()); Assert.assertEquals(0, Objects.requireNonNull(this.stn.findEdge("Z", "n5")).getValue()); } }