Search in sources :

Example 56 with Edge

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

the class EventGraphTest method testFireEdgePropertyChanged.

public void testFireEdgePropertyChanged() {
    graph.addListener(graphChangedListener);
    Edge edge = createEdge();
    edge.setProperty("weight", System.currentTimeMillis());
    assertEquals(1, graphChangedListener.edgePropertyChangedEventRecorded());
    graphChangedListener.reset();
    edge.getProperty("weight");
    assertEquals(0, graphChangedListener.edgePropertyChangedEventRecorded());
}
Also used : Edge(com.tinkerpop.blueprints.Edge)

Example 57 with Edge

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

the class EventGraphTest method testFireEdgeRemoved.

public void testFireEdgeRemoved() {
    graph.addListener(graphChangedListener);
    Edge edge = createEdge();
    graph.removeEdge(edge);
    assertEquals(1, graphChangedListener.edgeRemovedEventRecorded());
}
Also used : Edge(com.tinkerpop.blueprints.Edge)

Example 58 with Edge

use of com.tinkerpop.blueprints.Edge 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)

Example 59 with Edge

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

the class GraphSONUtilityTest method edgeFromJsonInputStreamCompactNoIdOnEdge.

@Test
public void edgeFromJsonInputStreamCompactNoIdOnEdge() throws IOException, JSONException {
    Graph g = new TinkerGraph();
    ElementFactory factory = new GraphElementFactory(g);
    Set<String> vertexKeys = new HashSet<String>() {

        {
            add(GraphSONTokens._ID);
        }
    };
    Set<String> edgeKeys = new HashSet<String>() {

        {
            add(GraphSONTokens._IN_V);
        }
    };
    GraphSONUtility graphson = new GraphSONUtility(GraphSONMode.COMPACT, factory, vertexKeys, edgeKeys);
    Vertex v1 = graphson.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)));
    Vertex v2 = graphson.vertexFromJson(new JSONObject(new JSONTokener(vertexJson2)));
    Edge e = graphson.edgeFromJson(inputStreamEdgeJsonLight, v1, v2);
    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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 60 with Edge

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

the class GraphSONUtilityTest method edgeFromJsonValid.

@Test
public void edgeFromJsonValid() throws IOException, JSONException {
    Graph g = new TinkerGraph();
    ElementFactory factory = new GraphElementFactory(g);
    Vertex v1 = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)), factory, GraphSONMode.NORMAL, null);
    Vertex v2 = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson2)), factory, GraphSONMode.NORMAL, null);
    Edge e = GraphSONUtility.edgeFromJson(new JSONObject(new JSONTokener(edgeJson)), v1, v2, factory, GraphSONMode.NORMAL, null);
    Assert.assertSame(v1, g.getVertex(1));
    Assert.assertSame(v2, g.getVertex(2));
    Assert.assertSame(e, g.getEdge(7));
    // tinkergraph converts id to string
    Assert.assertEquals("7", e.getId());
    Assert.assertEquals(0.5d, e.getProperty("weight"));
    Assert.assertEquals("knows", e.getLabel());
    Assert.assertEquals(v1, e.getVertex(Direction.OUT));
    Assert.assertEquals(v2, e.getVertex(Direction.IN));
}
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

Edge (com.tinkerpop.blueprints.Edge)214 Vertex (com.tinkerpop.blueprints.Vertex)141 Test (org.junit.Test)53 Graph (com.tinkerpop.blueprints.Graph)49 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)49 HashSet (java.util.HashSet)28 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)13 ArrayList (java.util.ArrayList)13 Collection (java.util.Collection)11 JSONObject (org.codehaus.jettison.json.JSONObject)11 HashMap (java.util.HashMap)10 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)9 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)8 Map (java.util.Map)8 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)7 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)6 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)6 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)6 URI (org.openrdf.model.URI)6