Search in sources :

Example 6 with Gexf

use of it.uniroma1.dis.wsngroup.gexf4j.core.Gexf in project gexf4j by francesco-ficarola.

the class GexfImplDefaultTest method testStaticGexfGraph.

/**
     * Test of getGraph method, of class GexfImpl.
     */
@Test
public void testStaticGexfGraph() throws IOException, SAXException {
    System.out.println("getGraph");
    Gexf gexf = new GexfImpl();
    Calendar date = Calendar.getInstance();
    date.set(2012, 4, 02);
    gexf.getMetadata().setLastModified(date.getTime()).setCreator("Gephi.org").setDescription("A Web network");
    Graph graph = gexf.getGraph();
    graph.setDefaultEdgeType(EdgeType.UNDIRECTED).setMode(Mode.STATIC);
    AttributeList attrList = new AttributeListImpl(AttributeClass.NODE);
    graph.getAttributeLists().add(attrList);
    Attribute attUrl = attrList.createAttribute("0", AttributeType.STRING, "url");
    Attribute attIndegree = attrList.createAttribute("1", AttributeType.FLOAT, "indegree");
    Attribute attFrog = attrList.createAttribute("2", AttributeType.BOOLEAN, "frog").setDefaultValue("true");
    Node gephi = graph.createNode("0");
    gephi.setLabel("Gephi").getAttributeValues().addValue(attUrl, "http://gephi.org").addValue(attIndegree, "1");
    Node webatlas = graph.createNode("1");
    webatlas.setLabel("Webatlas").getAttributeValues().addValue(attUrl, "http://webatlas.fr").addValue(attIndegree, "2");
    Node rtgi = graph.createNode("2");
    rtgi.setLabel("RTGI").getAttributeValues().addValue(attUrl, "http://rtgi.fr").addValue(attIndegree, "1");
    Node blab = graph.createNode("3");
    blab.setLabel("BarabasiLab").getAttributeValues().addValue(attUrl, "http://barabasilab.com").addValue(attIndegree, "1").addValue(attFrog, "false");
    gephi.connectTo("0", webatlas);
    gephi.connectTo("1", rtgi);
    webatlas.connectTo("2", gephi);
    rtgi.connectTo("3", webatlas);
    gephi.connectTo("4", blab);
    StaxGraphWriter graphWriter = new StaxGraphWriter();
    StringWriter stringWriter = new StringWriter();
    graphWriter.writeToStream(gexf, stringWriter, "UTF-8");
    String outputXml = stringWriter.toString();
    InputStream inputStream = GexfImplDefaultTest.class.getResourceAsStream("/staticGraph.gexf");
    String myControlXML = IOUtils.toString(inputStream, "UTF-8");
    System.out.println(outputXml);
    System.out.println(myControlXML);
    Diff myDiff = new Diff(myControlXML, outputXml);
    //        myDiff.overrideElementQualifier(new ElementNameAndTextQualifier());
    assertTrue("XML similar " + myDiff.toString(), myDiff.similar());
}
Also used : GexfImpl(it.uniroma1.dis.wsngroup.gexf4j.core.impl.GexfImpl) AttributeListImpl(it.uniroma1.dis.wsngroup.gexf4j.core.impl.data.AttributeListImpl) Attribute(it.uniroma1.dis.wsngroup.gexf4j.core.data.Attribute) Diff(org.custommonkey.xmlunit.Diff) AttributeList(it.uniroma1.dis.wsngroup.gexf4j.core.data.AttributeList) InputStream(java.io.InputStream) Calendar(java.util.Calendar) Node(it.uniroma1.dis.wsngroup.gexf4j.core.Node) Gexf(it.uniroma1.dis.wsngroup.gexf4j.core.Gexf) Graph(it.uniroma1.dis.wsngroup.gexf4j.core.Graph) StringWriter(java.io.StringWriter) StaxGraphWriter(it.uniroma1.dis.wsngroup.gexf4j.core.impl.StaxGraphWriter) Test(org.junit.Test)

Example 7 with Gexf

use of it.uniroma1.dis.wsngroup.gexf4j.core.Gexf in project gexf4j by francesco-ficarola.

the class GexfImplFileUtf8Test method testStaticGexfGraphStreams.

@Test
public void testStaticGexfGraphStreams() throws IOException, SAXException {
    System.out.println("testStaticGexfGraphStreams");
    StaxGraphWriter graphWriter = new StaxGraphWriter();
    StringWriter stringWriter = new StringWriter();
    graphWriter.writeToStream(gexf, new FileOutputStream("target/testStaticUtf2.gexf"), "UTF-8");
    graphWriter.writeToStream(gexf, stringWriter, "UTF-8");
    String found = IOUtils.toString(new InputStreamReader(new FileInputStream("target/testStaticUtf2.gexf"), "UTF-8"));
    String start = stringWriter.toString();
    InputStream inputStream = GexfImplFileUtf8Test.class.getResourceAsStream("/testStaticUtf.gexf");
    String control = IOUtils.toString(inputStream, "UTF-8");
    System.out.println(start);
    Diff myDiff = new Diff(found, start);
    //        myDiff.overrideElementQualifier(new ElementNameAndTextQualifier());
    assertTrue("XML similar " + myDiff.toString(), myDiff.similar());
    Diff secondDiff = new Diff(found, control);
    //        myDiff.overrideElementQualifier(new ElementNameAndTextQualifier());
    assertTrue("XML similar " + secondDiff.toString(), secondDiff.similar());
}
Also used : StringWriter(java.io.StringWriter) InputStreamReader(java.io.InputStreamReader) Diff(org.custommonkey.xmlunit.Diff) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) StaxGraphWriter(it.uniroma1.dis.wsngroup.gexf4j.core.impl.StaxGraphWriter) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 8 with Gexf

use of it.uniroma1.dis.wsngroup.gexf4j.core.Gexf in project gexf4j by francesco-ficarola.

the class GexfImplFileUtf8Test method testStaticGexfGraphAgaintControl.

@Test
public void testStaticGexfGraphAgaintControl() throws IOException, SAXException {
    System.out.println("testStaticGexfGraphAgaintControl");
    StaxGraphWriter graphWriter = new StaxGraphWriter();
    StringWriter stringWriter = new StringWriter();
    graphWriter.writeToStream(gexf, stringWriter, "UTF-8");
    String start = stringWriter.toString();
    assertTrue(start.contains("LONG utf string ĄČĘĖĮŠŲŪ() ąčęėįšųū90"));
    InputStream inputStream = GexfImplFileUtf8Test.class.getResourceAsStream("/testStaticUtf.gexf");
    String control = IOUtils.toString(inputStream, "UTF-8");
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("target/testStaticGexfGraphAgaintControl.gexf"), "UTF-8"));
    out.write(control);
    out.close();
    System.out.println(start);
    System.out.println(control);
    Diff myDiff = new Diff(control, start);
    //        myDiff.overrideElementQualifier(new ElementNameAndTextQualifier());
    assertTrue("XML similar " + myDiff.toString(), myDiff.similar());
}
Also used : StringWriter(java.io.StringWriter) Diff(org.custommonkey.xmlunit.Diff) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) StaxGraphWriter(it.uniroma1.dis.wsngroup.gexf4j.core.impl.StaxGraphWriter) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 9 with Gexf

use of it.uniroma1.dis.wsngroup.gexf4j.core.Gexf in project gexf4j by francesco-ficarola.

the class GexfImplFileWritingTest method testStaticGexfGraph.

/**
     * Test of getGraph method, of class GexfImpl.
     */
@Test
public void testStaticGexfGraph() throws IOException, SAXException {
    System.out.println("getGraph");
    Gexf gexf = new GexfImpl();
    Calendar date = Calendar.getInstance();
    date.set(2012, 4, 02);
    gexf.getMetadata().setLastModified(date.getTime()).setCreator("Gephi.org").setDescription("A Web network");
    Graph graph = gexf.getGraph();
    graph.setDefaultEdgeType(EdgeType.UNDIRECTED).setMode(Mode.STATIC);
    AttributeList attrList = new AttributeListImpl(AttributeClass.NODE);
    graph.getAttributeLists().add(attrList);
    Attribute attUrl = attrList.createAttribute("0", AttributeType.STRING, "url");
    Attribute attIndegree = attrList.createAttribute("1", AttributeType.FLOAT, "indegree");
    Attribute attFrog = attrList.createAttribute("2", AttributeType.BOOLEAN, "frog").setDefaultValue("true");
    Node gephi = graph.createNode("0");
    gephi.setLabel("Gephi").getAttributeValues().addValue(attUrl, "http://gephi.org").addValue(attIndegree, "1");
    Node webatlas = graph.createNode("1");
    webatlas.setLabel("Webatlas").getAttributeValues().addValue(attUrl, "http://webatlas.fr").addValue(attIndegree, "2");
    Node rtgi = graph.createNode("2");
    rtgi.setLabel("RTGI").getAttributeValues().addValue(attUrl, "http://rtgi.fr").addValue(attIndegree, "1");
    Node blab = graph.createNode("3");
    blab.setLabel("BarabasiLab").getAttributeValues().addValue(attUrl, "http://barabasilab.com").addValue(attIndegree, "1").addValue(attFrog, "false");
    gephi.connectTo("0", webatlas);
    gephi.connectTo("1", rtgi);
    webatlas.connectTo("2", gephi);
    rtgi.connectTo("3", webatlas);
    gephi.connectTo("4", blab);
    StaxGraphWriter graphWriter = new StaxGraphWriter();
    StringWriter stringWriter = new StringWriter();
    graphWriter.writeToStream(gexf, new FileWriter("target/testStatic.gexf"), "UTF-8");
    graphWriter.writeToStream(gexf, stringWriter, "UTF-8");
    String found = IOUtils.toString(new FileReader("target/testStatic.gexf"));
    String start = stringWriter.toString();
    Diff myDiff = new Diff(found, start);
    //        myDiff.overrideElementQualifier(new ElementNameAndTextQualifier());
    assertTrue("XML similar " + myDiff.toString(), myDiff.similar());
}
Also used : GexfImpl(it.uniroma1.dis.wsngroup.gexf4j.core.impl.GexfImpl) AttributeListImpl(it.uniroma1.dis.wsngroup.gexf4j.core.impl.data.AttributeListImpl) Attribute(it.uniroma1.dis.wsngroup.gexf4j.core.data.Attribute) Diff(org.custommonkey.xmlunit.Diff) AttributeList(it.uniroma1.dis.wsngroup.gexf4j.core.data.AttributeList) Calendar(java.util.Calendar) Node(it.uniroma1.dis.wsngroup.gexf4j.core.Node) FileWriter(java.io.FileWriter) Gexf(it.uniroma1.dis.wsngroup.gexf4j.core.Gexf) Graph(it.uniroma1.dis.wsngroup.gexf4j.core.Graph) StringWriter(java.io.StringWriter) FileReader(java.io.FileReader) StaxGraphWriter(it.uniroma1.dis.wsngroup.gexf4j.core.impl.StaxGraphWriter) Test(org.junit.Test)

Aggregations

StaxGraphWriter (it.uniroma1.dis.wsngroup.gexf4j.core.impl.StaxGraphWriter)8 StringWriter (java.io.StringWriter)6 Diff (org.custommonkey.xmlunit.Diff)6 Test (org.junit.Test)6 Gexf (it.uniroma1.dis.wsngroup.gexf4j.core.Gexf)5 Graph (it.uniroma1.dis.wsngroup.gexf4j.core.Graph)5 Node (it.uniroma1.dis.wsngroup.gexf4j.core.Node)5 Attribute (it.uniroma1.dis.wsngroup.gexf4j.core.data.Attribute)5 AttributeList (it.uniroma1.dis.wsngroup.gexf4j.core.data.AttributeList)5 GexfImpl (it.uniroma1.dis.wsngroup.gexf4j.core.impl.GexfImpl)5 AttributeListImpl (it.uniroma1.dis.wsngroup.gexf4j.core.impl.data.AttributeListImpl)5 Calendar (java.util.Calendar)5 FileWriter (java.io.FileWriter)4 InputStream (java.io.InputStream)4 IOException (java.io.IOException)3 Edge (it.uniroma1.dis.wsngroup.gexf4j.core.Edge)2 Spell (it.uniroma1.dis.wsngroup.gexf4j.core.dynamic.Spell)2 SpellImpl (it.uniroma1.dis.wsngroup.gexf4j.core.impl.SpellImpl)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2