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));
}
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()));
}
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);
}
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"));
}
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"));
}
Aggregations