use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class GraphSONUtilityTest method jsonFromElementNullsNoKeysNoTypes.
@Test
public void jsonFromElementNullsNoKeysNoTypes() throws JSONException {
Graph g = new TinkerGraph();
Vertex v = g.addVertex(1);
Map<String, Object> map = new HashMap<String, Object>();
map.put("innerkey", null);
List<String> innerList = new ArrayList<String>();
innerList.add(null);
innerList.add("innerstring");
map.put("list", innerList);
v.setProperty("keyMap", map);
List<String> list = new ArrayList<String>();
list.add(null);
list.add("string");
v.setProperty("keyList", list);
JSONObject json = GraphSONUtility.jsonFromElement(v, null, GraphSONMode.NORMAL);
Assert.assertNotNull(json);
Assert.assertTrue(json.isNull("key"));
JSONObject jsonMap = json.optJSONObject("keyMap");
Assert.assertNotNull(jsonMap);
Assert.assertTrue(jsonMap.isNull("innerkey"));
JSONArray jsonInnerArray = jsonMap.getJSONArray("list");
Assert.assertNotNull(jsonInnerArray);
Assert.assertTrue(jsonInnerArray.isNull(0));
Assert.assertEquals("innerstring", jsonInnerArray.get(1));
JSONArray jsonArray = json.getJSONArray("keyList");
Assert.assertNotNull(jsonArray);
Assert.assertTrue(jsonArray.isNull(0));
Assert.assertEquals("string", jsonArray.get(1));
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class GraphSONUtilityTest method vertexFromJsonExtendedTypesValid.
@Test
public void vertexFromJsonExtendedTypesValid() throws IOException, JSONException {
// need to test those data types that are not covered by the toy graphs
Graph g = new TinkerGraph();
ElementFactory factory = new GraphElementFactory(g);
Vertex v = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson3)), factory, GraphSONMode.EXTENDED, null);
Assert.assertSame(v, g.getVertex(1));
Assert.assertEquals((byte) 4, v.getProperty("byteValue"));
Assert.assertEquals(new Short("10"), v.getProperty("shortValue"));
Assert.assertEquals(true, v.getProperty("booleanValue"));
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class GMLReaderTest method exampleGMLGetsCorrectNumberOfElements.
@Test
public void exampleGMLGetsCorrectNumberOfElements() throws IOException {
TinkerGraph graph = new TinkerGraph();
GMLReader.inputGraph(graph, GMLReader.class.getResourceAsStream("example.gml"));
Assert.assertEquals(3, getIterableCount(graph.getVertices()));
Assert.assertEquals(3, getIterableCount(graph.getEdges()));
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph 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.impls.tg.TinkerGraph 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);
}
Aggregations