Search in sources :

Example 86 with TinkerGraph

use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.

the class ReadOnlyGraphTest method testReadOnlyElement.

public void testReadOnlyElement() {
    Graph graph = new ReadOnlyGraph<TinkerGraph>(TinkerGraphFactory.createTinkerGraph());
    for (Vertex vertex : graph.getVertices()) {
        assertTrue(vertex instanceof ReadOnlyVertex);
        try {
            vertex.setProperty("name", "noname");
            assertTrue(false);
        } catch (UnsupportedOperationException e) {
            assertTrue(true);
        }
        vertex.getProperty("name");
        vertex.getPropertyKeys();
        assertTrue(vertex.getEdges(Direction.OUT) instanceof ReadOnlyEdgeIterable);
        assertTrue(vertex.getEdges(Direction.IN) instanceof ReadOnlyEdgeIterable);
        assertTrue(vertex.getEdges(Direction.OUT, "knows") instanceof ReadOnlyEdgeIterable);
        assertTrue(vertex.getEdges(Direction.IN, "created") instanceof ReadOnlyEdgeIterable);
    }
    for (Edge edge : graph.getEdges()) {
        assertTrue(edge instanceof ReadOnlyEdge);
        try {
            edge.removeProperty("weight");
            assertTrue(false);
        } catch (UnsupportedOperationException e) {
            assertTrue(true);
        }
        edge.getProperty("weight");
        edge.getPropertyKeys();
        assertTrue(edge.getVertex(Direction.OUT) instanceof ReadOnlyVertex);
        assertTrue(edge.getVertex(Direction.IN) instanceof ReadOnlyVertex);
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) WrapperGraph(com.tinkerpop.blueprints.util.wrappers.WrapperGraph) KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) IndexableGraph(com.tinkerpop.blueprints.IndexableGraph) Graph(com.tinkerpop.blueprints.Graph) Edge(com.tinkerpop.blueprints.Edge)

Example 87 with TinkerGraph

use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.

the class ReadOnlyGraphTest method testReadOnlyGraph.

public void testReadOnlyGraph() {
    Graph graph = new ReadOnlyGraph<TinkerGraph>(TinkerGraphFactory.createTinkerGraph());
    assertTrue(graph.getVertices() instanceof ReadOnlyVertexIterable);
    assertTrue(graph.getEdges() instanceof ReadOnlyEdgeIterable);
    assertEquals(count(graph.getVertices()), 6);
    assertEquals(count(graph.getEdges()), 6);
    try {
        graph.addVertex(null);
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    try {
        graph.addEdge(null, null, null, "knows");
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    try {
        graph.removeVertex(graph.getVertex(1));
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    try {
        graph.removeEdge(graph.getEdge(10));
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    try {
        graph.shutdown();
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
}
Also used : WrapperGraph(com.tinkerpop.blueprints.util.wrappers.WrapperGraph) KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) IndexableGraph(com.tinkerpop.blueprints.IndexableGraph) Graph(com.tinkerpop.blueprints.Graph)

Example 88 with TinkerGraph

use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.

the class GraphSONReaderTest method inputStreamIsNull.

@Test(expected = IllegalArgumentException.class)
public void inputStreamIsNull() throws IOException {
    TinkerGraph graph = new TinkerGraph();
    InputStream inputStream = null;
    GraphSONReader.inputGraph(graph, inputStream);
}
Also used : TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 89 with TinkerGraph

use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.

the class GraphSONReaderTest method inputGraphCompactFullCycleBroken.

@Test(expected = IllegalArgumentException.class)
public void inputGraphCompactFullCycleBroken() throws IOException {
    TinkerGraph graph = TinkerGraphFactory.createTinkerGraph();
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    Set<String> edgeKeys = new HashSet<String>();
    edgeKeys.add(GraphSONTokens._IN_V);
    edgeKeys.add(GraphSONTokens._OUT_V);
    edgeKeys.add(GraphSONTokens._LABEL);
    Set<String> vertexKeys = new HashSet<String>();
    GraphSONWriter writer = new GraphSONWriter(graph);
    writer.outputGraph(stream, vertexKeys, edgeKeys, GraphSONMode.COMPACT);
    stream.flush();
    stream.close();
    String jsonString = new String(stream.toByteArray());
    byte[] bytes = jsonString.getBytes();
    InputStream inputStream = new ByteArrayInputStream(bytes);
    TinkerGraph emptyGraph = new TinkerGraph();
    GraphSONReader.inputGraph(emptyGraph, inputStream);
}
Also used : TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 90 with TinkerGraph

use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.

the class GraphSONUtilityTest method edgeFromJsonInputStreamCompactLabelOrIdOnEdge.

@Test
public void edgeFromJsonInputStreamCompactLabelOrIdOnEdge() throws IOException, JSONException {
    Graph g = new TinkerGraph();
    ElementFactory factory = new GraphElementFactory(g);
    Vertex v1 = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)), factory, GraphSONMode.COMPACT, null);
    Vertex v2 = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson2)), factory, GraphSONMode.COMPACT, null);
    Edge e = GraphSONUtility.edgeFromJson(inputStreamEdgeJsonLight, v1, v2, factory, GraphSONMode.COMPACT, null);
    Assert.assertSame(v1, g.getVertex(1));
    Assert.assertSame(v2, g.getVertex(2));
    Assert.assertSame(e, g.getEdge(0));
}
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) Edge(com.tinkerpop.blueprints.Edge) 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