Search in sources :

Example 66 with Vertex

use of com.tinkerpop.blueprints.Vertex in project blueprints by tinkerpop.

the class GMLReaderTest method exampleGMLGetsCorrectTopology.

@Test
public void exampleGMLGetsCorrectTopology() throws IOException {
    TinkerGraph graph = new TinkerGraph();
    GMLReader.inputGraph(graph, GMLReader.class.getResourceAsStream("example.gml"));
    Vertex v1 = graph.getVertex(1);
    Vertex v2 = graph.getVertex(2);
    Vertex v3 = graph.getVertex(3);
    Iterable<Edge> out1 = v1.getEdges(Direction.OUT);
    Edge e1 = out1.iterator().next();
    Assert.assertEquals(v2, e1.getVertex(Direction.IN));
    Iterable<Edge> out2 = v2.getEdges(Direction.OUT);
    Edge e2 = out2.iterator().next();
    Assert.assertEquals(v3, e2.getVertex(Direction.IN));
    Iterable<Edge> out3 = v3.getEdges(Direction.OUT);
    Edge e3 = out3.iterator().next();
    Assert.assertEquals(v1, e3.getVertex(Direction.IN));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Edge(com.tinkerpop.blueprints.Edge) Test(org.junit.Test)

Example 67 with Vertex

use of com.tinkerpop.blueprints.Vertex in project blueprints by tinkerpop.

the class GMLReaderTest method testIdGenerationInGML.

@Test
public void testIdGenerationInGML() throws IOException {
    TinkerGraph graph1 = new TinkerGraph();
    GMLReader.inputGraph(graph1, GMLReader.class.getResourceAsStream("simple.gml"));
    Vertex toRemove = graph1.getVertex("123");
    graph1.removeVertex(toRemove);
    String file = "/tmp/simple-" + UUID.randomUUID() + ".gml";
    GMLWriter.outputGraph(graph1, file);
    TinkerGraph graph2 = new TinkerGraph();
    GMLReader.inputGraph(graph2, file);
    String gml = new String(Files.readAllBytes(Paths.get(file)));
    String sep = "\r\n";
    String expected = "graph [" + sep + "\tnode [" + sep + "\t\tid 1" + sep + "\t\tblueprintsId \"456\"" + sep + "\t]" + sep + "]" + sep;
    Assert.assertEquals(expected, gml);
    Assert.assertEquals(1, getIterableCount(graph2.getVertices()));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Test(org.junit.Test)

Example 68 with Vertex

use of com.tinkerpop.blueprints.Vertex in project blueprints by tinkerpop.

the class GMLReaderTest method testEscapeQuotation.

@Test
public void testEscapeQuotation() throws Exception {
    TinkerGraph graph = new TinkerGraph();
    GMLReader.inputGraph(graph, GMLReader.class.getResourceAsStream("example.gml"));
    Vertex v3 = graph.getVertex(3);
    Object tempProperty = v3.getProperty("escape_property");
    Assert.assertNotNull(tempProperty);
    Assert.assertEquals("Node 3 \"with quote\"", tempProperty);
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Test(org.junit.Test)

Example 69 with Vertex

use of com.tinkerpop.blueprints.Vertex in project blueprints by tinkerpop.

the class GMLWriterTest method testEncoding.

// Note: this is only a very lightweight test of writer/reader encoding.
// It is known that there are characters which, when written by GMLWriter,
// cause parse errors for GraphMLReader.
// However, this happens uncommonly enough that is not yet known which characters those are.
public void testEncoding() throws Exception {
    Graph g = new TinkerGraph();
    Vertex v = g.addVertex(1);
    v.setProperty("text", "é");
    GMLWriter w = new GMLWriter(g);
    File f = File.createTempFile("test", "txt");
    f.deleteOnExit();
    OutputStream out = new FileOutputStream(f);
    w.outputGraph(out);
    out.close();
    Graph g2 = new TinkerGraph();
    GMLReader r = new GMLReader(g2);
    InputStream in = new FileInputStream(f);
    r.inputGraph(in);
    in.close();
    Vertex v2 = g2.getVertex(1);
    assertEquals("é", v2.getProperty("text"));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 70 with Vertex

use of com.tinkerpop.blueprints.Vertex in project blueprints by tinkerpop.

the class GMLWriterTest method testWriteStringPropertyWithQuotationMarks.

/**
     * This tests checks, if quotation marks (") are escaped correctly, before
     * they are written to the GML file.
     * @throws Exception if something fails
     */
public void testWriteStringPropertyWithQuotationMarks() throws Exception {
    TinkerGraph g1 = TinkerGraphFactory.createTinkerGraph();
    Vertex v = g1.getVertex(1);
    v.setProperty("escape_property", "quotation \"quote\" quotation end");
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    GMLWriter w = new GMLWriter(g1);
    w.setUseId(true);
    w.outputGraph(bos);
    String gmlOutput = bos.toString();
    Assert.assertNotNull(gmlOutput);
    String message = "escaped_property was not escaped properly";
    Assert.assertTrue(message, gmlOutput.contains("quotation \\\"quote\\\" quotation end"));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

Vertex (com.tinkerpop.blueprints.Vertex)406 Test (org.junit.Test)119 Edge (com.tinkerpop.blueprints.Edge)111 Graph (com.tinkerpop.blueprints.Graph)85 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)84 JSONObject (org.codehaus.jettison.json.JSONObject)51 HashSet (java.util.HashSet)49 ArrayList (java.util.ArrayList)40 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)37 GremlinPipeline (com.tinkerpop.gremlin.java.GremlinPipeline)28 HashMap (java.util.HashMap)25 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)22 JSONArray (org.codehaus.jettison.json.JSONArray)20 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)19 Test (org.testng.annotations.Test)16 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)15 Map (java.util.Map)15 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)14 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)13 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)11