use of com.tinkerpop.blueprints.impls.tg.TinkerGraph 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.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class GraphMLWriterTest method testNormal.
public void testNormal() throws Exception {
TinkerGraph g = new TinkerGraph();
GraphMLReader.inputGraph(g, GraphMLReader.class.getResourceAsStream("graph-example-1.xml"));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
GraphMLWriter w = new GraphMLWriter(g);
w.setNormalize(true);
w.outputGraph(bos);
String expected = streamToString(GraphMLWriterTest.class.getResourceAsStream("graph-example-1-normalized.xml"));
// System.out.println(expected);
assertEquals(expected.replace("\n", "").replace("\r", ""), bos.toString().replace("\n", "").replace("\r", ""));
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class GraphSONReaderTest method inputGraphModeExtended.
@Test
public void inputGraphModeExtended() throws IOException {
TinkerGraph graph = new TinkerGraph();
String json = "{ \"mode\":\"EXTENDED\", \"vertices\": [ {\"_id\":1, \"_type\":\"vertex\", \"test\": { \"type\":\"string\", \"value\":\"please work\"}, \"testlist\":{\"type\":\"list\", \"value\":[{\"type\":\"int\", \"value\":1}, {\"type\":\"int\",\"value\":2}, {\"type\":\"int\",\"value\":3}]}, \"testmap\":{\"type\":\"map\", \"value\":{\"big\":{\"type\":\"long\", \"value\":10000000000}, \"small\":{\"type\":\"double\", \"value\":0.4954959595959}}}}, {\"_id\":2, \"_type\":\"vertex\", \"testagain\":{\"type\":\"string\", \"value\":\"please work again\"}}], \"edges\":[{\"_id\":100, \"_type\":\"edge\", \"_outV\":1, \"_inV\":2, \"_label\":\"works\", \"teste\": {\"type\":\"string\", \"value\":\"please worke\"}}]}";
byte[] bytes = json.getBytes();
InputStream inputStream = new ByteArrayInputStream(bytes);
GraphSONReader.inputGraph(graph, inputStream);
Assert.assertEquals(2, getIterableCount(graph.getVertices()));
Assert.assertEquals(1, getIterableCount(graph.getEdges()));
Vertex v1 = graph.getVertex(1);
Assert.assertNotNull(v1);
Assert.assertEquals("please work", v1.getProperty("test"));
Map map = (Map) v1.getProperty("testmap");
Assert.assertNotNull(map);
Assert.assertEquals(10000000000l, Long.parseLong(map.get("big").toString()));
Assert.assertEquals(0.4954959595959, Double.parseDouble(map.get("small").toString()), 0);
// Assert.assertNull(map.get("nullKey"));
List list = (List) v1.getProperty("testlist");
Assert.assertEquals(3, list.size());
boolean foundNull = false;
for (int ix = 0; ix < list.size(); ix++) {
if (list.get(ix) == null) {
foundNull = true;
break;
}
}
Assert.assertTrue(foundNull);
Vertex v2 = graph.getVertex(2);
Assert.assertNotNull(v2);
Assert.assertEquals("please work again", v2.getProperty("testagain"));
Edge e = graph.getEdge(100);
Assert.assertNotNull(e);
Assert.assertEquals("works", e.getLabel());
Assert.assertEquals(v1, e.getVertex(Direction.OUT));
Assert.assertEquals(v2, e.getVertex(Direction.IN));
Assert.assertEquals("please worke", e.getProperty("teste"));
// Assert.assertNull(e.getProperty("keyNull"));
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class IndexableGraphHelperTest method testAddUniqueVertex.
public void testAddUniqueVertex() {
IndexableGraph graph = new TinkerGraph();
Vertex marko = graph.addVertex(0);
marko.setProperty("name", "marko");
Index<Vertex> index = graph.createIndex("txIdx", Vertex.class);
index.put("name", "marko", marko);
Vertex vertex = IndexableGraphHelper.addUniqueVertex(graph, null, index, "name", "marko");
assertEquals(vertex.getProperty("name"), "marko");
assertEquals(vertex, graph.getVertex(0));
assertEquals(count(graph.getVertices()), 1);
assertEquals(count(graph.getEdges()), 0);
vertex = IndexableGraphHelper.addUniqueVertex(graph, null, index, "name", "darrick");
assertEquals(vertex.getProperty("name"), "darrick");
assertEquals(count(graph.getVertices()), 2);
assertEquals(vertex.getId(), "1");
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph 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