Search in sources :

Example 1 with GraphChangedListener

use of com.tinkerpop.blueprints.util.wrappers.event.listener.GraphChangedListener in project blueprints by tinkerpop.

the class EventGraphTest method testFireEdgeRemovedAndValidateProperties.

public void testFireEdgeRemovedAndValidateProperties() {
    final List<Boolean> fired = new ArrayList<Boolean>();
    graph.addListener(new GraphChangedListener() {

        @Override
        public void vertexAdded(Vertex vertex) {
        //To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void vertexPropertyChanged(Vertex vertex, String key, Object oldValue, Object setValue) {
        //To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void vertexPropertyRemoved(Vertex vertex, String key, Object removedValue) {
        //To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void vertexRemoved(Vertex vertex, Map<String, Object> props) {
        //To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void edgeAdded(Edge edge) {
        //To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void edgePropertyChanged(Edge edge, String key, Object oldValue, Object setValue) {
        //To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void edgePropertyRemoved(Edge edge, String key, Object removedValue) {
        //To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void edgeRemoved(Edge edge, Map<String, Object> props) {
            assertTrue(props.containsKey("weight"));
            assertEquals(0.5f, props.get("weight"));
            fired.add(true);
        }
    });
    final Edge e = createEdge();
    e.setProperty("weight", 0.5f);
    graph.removeEdge(e);
    assertEquals(1, fired.size());
    assertTrue(fired.get(0));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) StubGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.StubGraphChangedListener) ConsoleGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener) GraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.GraphChangedListener) ArrayList(java.util.ArrayList) Edge(com.tinkerpop.blueprints.Edge)

Example 2 with GraphChangedListener

use of com.tinkerpop.blueprints.util.wrappers.event.listener.GraphChangedListener in project blueprints by tinkerpop.

the class EventGraphTest method testManageListeners.

public void testManageListeners() {
    EventGraph graph = this.graph;
    ConsoleGraphChangedListener listener1 = new ConsoleGraphChangedListener(graph);
    ConsoleGraphChangedListener listener2 = new ConsoleGraphChangedListener(graph);
    graph.addListener(listener1);
    graph.addListener(listener2);
    Iterator<GraphChangedListener> itty = graph.getListenerIterator();
    int counter = 0;
    while (itty.hasNext()) {
        itty.next();
        counter++;
    }
    assertEquals(2, counter);
    graph.removeListener(listener2);
    itty = graph.getListenerIterator();
    counter = 0;
    while (itty.hasNext()) {
        itty.next();
        counter++;
    }
    assertEquals(1, counter);
    graph.removeAllListeners();
    itty = graph.getListenerIterator();
    counter = 0;
    while (itty.hasNext()) {
        itty.next();
        counter++;
    }
    assertEquals(0, counter);
}
Also used : StubGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.StubGraphChangedListener) ConsoleGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener) GraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.GraphChangedListener) ConsoleGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener)

Example 3 with GraphChangedListener

use of com.tinkerpop.blueprints.util.wrappers.event.listener.GraphChangedListener in project blueprints by tinkerpop.

the class EventGraphTest method testFireVertexRemovedAndValidateProperties.

public void testFireVertexRemovedAndValidateProperties() {
    final List<Boolean> fired = new ArrayList<Boolean>();
    graph.addListener(new GraphChangedListener() {

        @Override
        public void vertexAdded(Vertex vertex) {
        //To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void vertexPropertyChanged(Vertex vertex, String key, Object oldValue, Object setValue) {
        //To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void vertexPropertyRemoved(Vertex vertex, String key, Object removedValue) {
        //To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void vertexRemoved(Vertex vertex, Map<String, Object> props) {
            assertTrue(props.containsKey("name"));
            assertEquals("marko", props.get("name"));
            fired.add(true);
        }

        @Override
        public void edgeAdded(Edge edge) {
        //To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void edgePropertyChanged(Edge edge, String key, Object oldValue, Object setValue) {
        //To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void edgePropertyRemoved(Edge edge, String key, Object removedValue) {
        //To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void edgeRemoved(Edge edge, Map<String, Object> props) {
        //To change body of implemented methods use File | Settings | File Templates.
        }
    });
    Vertex vertex = createVertex();
    vertex.setProperty("name", "marko");
    graph.removeVertex(vertex);
    assertEquals(1, fired.size());
    assertTrue(fired.get(0));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) StubGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.StubGraphChangedListener) ConsoleGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener) GraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.GraphChangedListener) ArrayList(java.util.ArrayList) Edge(com.tinkerpop.blueprints.Edge)

Example 4 with GraphChangedListener

use of com.tinkerpop.blueprints.util.wrappers.event.listener.GraphChangedListener in project blueprints by tinkerpop.

the class EventTransactionalGraphTest method testManageListeners.

public void testManageListeners() {
    EventGraph graph = this.graph;
    ConsoleGraphChangedListener listener1 = new ConsoleGraphChangedListener(graph);
    ConsoleGraphChangedListener listener2 = new ConsoleGraphChangedListener(graph);
    graph.addListener(listener1);
    graph.addListener(listener2);
    Iterator<GraphChangedListener> itty = graph.getListenerIterator();
    int counter = 0;
    while (itty.hasNext()) {
        itty.next();
        counter++;
    }
    assertEquals(2, counter);
    graph.removeListener(listener2);
    itty = graph.getListenerIterator();
    counter = 0;
    while (itty.hasNext()) {
        itty.next();
        counter++;
    }
    assertEquals(1, counter);
    graph.removeAllListeners();
    itty = graph.getListenerIterator();
    counter = 0;
    while (itty.hasNext()) {
        itty.next();
        counter++;
    }
    assertEquals(0, counter);
}
Also used : GraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.GraphChangedListener) StubGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.StubGraphChangedListener) ConsoleGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener) ConsoleGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener)

Aggregations

ConsoleGraphChangedListener (com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener)4 GraphChangedListener (com.tinkerpop.blueprints.util.wrappers.event.listener.GraphChangedListener)4 StubGraphChangedListener (com.tinkerpop.blueprints.util.wrappers.event.listener.StubGraphChangedListener)4 Edge (com.tinkerpop.blueprints.Edge)2 Vertex (com.tinkerpop.blueprints.Vertex)2 ArrayList (java.util.ArrayList)2