Search in sources :

Example 31 with TinkerGraph

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));
}
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) JSONObject(org.codehaus.jettison.json.JSONObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONArray(org.codehaus.jettison.json.JSONArray) JSONObject(org.codehaus.jettison.json.JSONObject) Test(org.junit.Test)

Example 32 with TinkerGraph

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"));
}
Also used : JSONTokener(org.codehaus.jettison.json.JSONTokener) Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) JSONObject(org.codehaus.jettison.json.JSONObject) Test(org.junit.Test)

Example 33 with TinkerGraph

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()));
}
Also used : TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Test(org.junit.Test)

Example 34 with TinkerGraph

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()));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Test(org.junit.Test)

Example 35 with TinkerGraph

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);
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Test(org.junit.Test)

Aggregations

TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)105 Vertex (com.tinkerpop.blueprints.Vertex)66 Graph (com.tinkerpop.blueprints.Graph)58 Test (org.junit.Test)42 Edge (com.tinkerpop.blueprints.Edge)33 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 JSONObject (org.codehaus.jettison.json.JSONObject)10 IMetaverseBuilder (org.pentaho.metaverse.api.IMetaverseBuilder)10 InputStream (java.io.InputStream)9 HashSet (java.util.HashSet)9 JSONTokener (org.codehaus.jettison.json.JSONTokener)8 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)7 Map (java.util.Map)6 MetaverseBuilder (org.pentaho.metaverse.impl.MetaverseBuilder)6 TypedGraphModuleBuilder (com.tinkerpop.frames.modules.typedgraph.TypedGraphModuleBuilder)5 HashMap (java.util.HashMap)5 Before (org.junit.Before)5 IndexableGraph (com.tinkerpop.blueprints.IndexableGraph)4 IgnoreIdTinkerGraph (com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph)4