Search in sources :

Example 91 with Vertex

use of com.tinkerpop.blueprints.Vertex in project blueprints by tinkerpop.

the class EventTransactionalGraphTest method testWrappedElementUniqueness.

public void testWrappedElementUniqueness() {
    graph.addListener(new ConsoleGraphChangedListener(graph));
    assertEquals(graph.getVertex(1), graph.getVertex(1));
    Set<Vertex> set = new HashSet<Vertex>();
    set.add(graph.getVertex(2));
    set.add(graph.getVertex(2));
    assertEquals(set.size(), 1);
    assertEquals(graph.getEdge(7).hashCode(), graph.getEdge(7).hashCode());
    assertEquals(graph.getEdge(8), graph.getEdge(8));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) ConsoleGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener) HashSet(java.util.HashSet)

Example 92 with Vertex

use of com.tinkerpop.blueprints.Vertex in project blueprints by tinkerpop.

the class EventTransactionalGraphTest method testMutateInListener.

public void testMutateInListener() {
    StubGraphChangedListener listener = new StubGraphChangedListener() {

        @Override
        public void vertexPropertyChanged(Vertex vertex, String key, Object oldValue, Object setValue) {
            if (!"setInListener".equals(key)) {
                vertex.setProperty("setInListener", 12345);
            }
            super.vertexPropertyChanged(vertex, key, oldValue, setValue);
        }
    };
    graph.addListener(listener);
    Vertex vertex = createVertex();
    vertex.setProperty("test", 123);
    graph.commit();
    assertEquals(12345, vertex.getProperty("setInListener"));
    assertEquals(2, listener.vertexPropertyChangedEventRecorded());
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) StubGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.StubGraphChangedListener)

Example 93 with Vertex

use of com.tinkerpop.blueprints.Vertex in project blueprints by tinkerpop.

the class EventTransactionalGraphTest method testTransactionSeriesWithSuccess.

public void testTransactionSeriesWithSuccess() {
    graph.addListener(graphChangedListener);
    createEdge();
    Edge e = createEdge();
    e.setProperty("test", "it");
    e.setProperty("test", "that");
    Vertex v = createVertex();
    v.setProperty("test", "it");
    assertEquals(0, graphChangedListener.addEdgeEventRecorded());
    assertEquals(0, graphChangedListener.addVertexEventRecorded());
    assertEquals(0, graphChangedListener.edgePropertyChangedEventRecorded());
    assertEquals(0, graphChangedListener.vertexPropertyChangedEventRecorded());
    ((EventTransactionalGraph) graph).commit();
    assertEquals(2, graphChangedListener.addEdgeEventRecorded());
    assertEquals(5, graphChangedListener.addVertexEventRecorded());
    assertEquals(2, graphChangedListener.edgePropertyChangedEventRecorded());
    assertEquals(1, graphChangedListener.vertexPropertyChangedEventRecorded());
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) Edge(com.tinkerpop.blueprints.Edge)

Example 94 with Vertex

use of com.tinkerpop.blueprints.Vertex in project blueprints by tinkerpop.

the class EventTransactionalGraphTest method testFireVertexPropertyChanged.

public void testFireVertexPropertyChanged() {
    graph.addListener(graphChangedListener);
    Vertex vertex = createVertex();
    vertex.setProperty("name", "marko");
    assertEquals(0, graphChangedListener.vertexPropertyChangedEventRecorded());
    ((EventTransactionalGraph) graph).commit();
    assertEquals(1, graphChangedListener.vertexPropertyChangedEventRecorded());
    graphChangedListener.reset();
    vertex.getProperty("name");
    assertEquals(0, graphChangedListener.vertexPropertyChangedEventRecorded());
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex)

Example 95 with Vertex

use of com.tinkerpop.blueprints.Vertex in project blueprints by tinkerpop.

the class EventTransactionalGraphTest method testEventedElement.

public void testEventedElement() {
    graph.addListener(new ConsoleGraphChangedListener(graph));
    for (Vertex vertex : graph.getVertices()) {
        assertTrue(vertex instanceof EventVertex);
        vertex.setProperty("name", "noname");
        assertEquals("noname", vertex.getProperty("name"));
        assertTrue(vertex.getEdges(Direction.OUT) instanceof EventEdgeIterable);
        assertTrue(vertex.getEdges(Direction.IN) instanceof EventEdgeIterable);
        assertTrue(vertex.getEdges(Direction.OUT, "knows") instanceof EventEdgeIterable);
        assertTrue(vertex.getEdges(Direction.IN, "created") instanceof EventEdgeIterable);
    }
    for (Edge edge : graph.getEdges()) {
        assertTrue(edge instanceof EventEdge);
        edge.removeProperty("weight");
        assertNull(edge.getProperty("weight"));
        assertTrue(edge.getVertex(Direction.OUT) instanceof EventVertex);
        assertTrue(edge.getVertex(Direction.IN) instanceof EventVertex);
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) ConsoleGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener) Edge(com.tinkerpop.blueprints.Edge)

Aggregations

Vertex (com.tinkerpop.blueprints.Vertex)406 Test (org.junit.Test)119 Edge (com.tinkerpop.blueprints.Edge)111 Graph (com.tinkerpop.blueprints.Graph)85 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)84 JSONObject (org.codehaus.jettison.json.JSONObject)51 HashSet (java.util.HashSet)49 ArrayList (java.util.ArrayList)40 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)37 GremlinPipeline (com.tinkerpop.gremlin.java.GremlinPipeline)28 HashMap (java.util.HashMap)25 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)22 JSONArray (org.codehaus.jettison.json.JSONArray)20 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)19 Test (org.testng.annotations.Test)16 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)15 Map (java.util.Map)15 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)14 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)13 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)11