Search in sources :

Example 11 with Edge

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

the class TypedGraphModuleTest method testDeserializeEdgeType.

public void testDeserializeEdgeType() {
    Graph graph = new TinkerGraph();
    FramedGraphFactory factory = new FramedGraphFactory(new TypedGraphModuleBuilder().withClass(A.class).withClass(B.class).withClass(C.class).build());
    FramedGraph<Graph> framedGraph = factory.create(graph);
    Vertex v1 = graph.addVertex(null);
    Vertex v2 = graph.addVertex(null);
    Edge cE = graph.addEdge(null, v1, v2, "label");
    cE.setProperty("type", "C");
    Base c = framedGraph.getEdge(cE.getId(), Direction.OUT, Base.class);
    assertTrue(c instanceof C);
}
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) TypedGraphModuleBuilder(com.tinkerpop.frames.modules.typedgraph.TypedGraphModuleBuilder) Edge(com.tinkerpop.blueprints.Edge)

Example 12 with Edge

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

the class TypedGraphModuleTest method testWildcard.

public void testWildcard() {
    Graph graph = new TinkerGraph();
    FramedGraphFactory factory = new FramedGraphFactory(new TypedGraphModuleBuilder().withClass(A.class).withClass(B.class).withClass(C.class).build());
    FramedGraph<Graph> framedGraph = factory.create(graph);
    Vertex v1 = graph.addVertex(null);
    Vertex v2 = graph.addVertex(null);
    v2.setProperty("type", "A");
    Edge cE = graph.addEdge(null, v1, v2, "label");
    cE.setProperty("type", "C");
    Base c = framedGraph.getEdge(cE.getId(), Direction.OUT, Base.class);
    assertTrue(c instanceof C);
    assertTrue(((C) c).getInVertex() instanceof A);
}
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) TypedGraphModuleBuilder(com.tinkerpop.frames.modules.typedgraph.TypedGraphModuleBuilder) Edge(com.tinkerpop.blueprints.Edge)

Example 13 with Edge

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

the class FramedGraphTest method testCreateFrameForNonexistantElements.

public void testCreateFrameForNonexistantElements() {
    Graph graph = new TinkerGraph();
    FramedGraph<Graph> framedGraph = new FramedGraphFactory().create(graph);
    Person vertex = framedGraph.getVertex(-1, Person.class);
    Assert.assertNull(vertex);
    vertex = framedGraph.frame((Vertex) null, Person.class);
    Assert.assertNull(vertex);
    Knows edge = framedGraph.getEdge(-1, Knows.class);
    Assert.assertNull(edge);
    edge = framedGraph.frame((Edge) null, Knows.class);
    Assert.assertNull(edge);
}
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) Knows(com.tinkerpop.frames.domain.incidences.Knows) Person(com.tinkerpop.frames.domain.classes.Person) Edge(com.tinkerpop.blueprints.Edge)

Example 14 with Edge

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

the class FramedGraphTest method testCreateFrame.

public void testCreateFrame() {
    Graph graph = new TinkerGraph();
    FramedGraph<Graph> framedGraph = new FramedGraphFactory().create(graph);
    Person person = framedGraph.addVertex(null, Person.class);
    assertEquals(person.asVertex(), graph.getVertices().iterator().next());
    int counter = 0;
    for (Vertex v : graph.getVertices()) {
        counter++;
    }
    assertEquals(counter, 1);
    counter = 0;
    for (Edge e : graph.getEdges()) {
        counter++;
    }
    assertEquals(counter, 0);
    Person person2 = framedGraph.addVertex("aPerson", Person.class);
    assertEquals(person2.asVertex().getId(), "aPerson");
    counter = 0;
    for (Vertex v : graph.getVertices()) {
        counter++;
    }
    assertEquals(counter, 2);
}
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) Person(com.tinkerpop.frames.domain.classes.Person) Edge(com.tinkerpop.blueprints.Edge)

Example 15 with Edge

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

the class FramedGraphQueryImplTest method testDelegation.

@Test
public void testDelegation() {
    GraphQuery mockGraphQuery = mock(GraphQuery.class);
    FramedGraph framedGraph = new FramedGraphFactory().create(null);
    FramedGraphQueryImpl query = new FramedGraphQueryImpl(framedGraph, mockGraphQuery);
    stub(mockGraphQuery.has("")).toReturn(mockGraphQuery);
    query.has("");
    verify(mockGraphQuery).has("");
    stub(mockGraphQuery.has("", "bar")).toReturn(mockGraphQuery);
    query.has("", "bar");
    verify(mockGraphQuery).has("", "bar");
    Predicate predicate = new Predicate() {

        @Override
        public boolean evaluate(Object first, Object second) {
            return false;
        }
    };
    stub(mockGraphQuery.has("", predicate, "bar")).toReturn(mockGraphQuery);
    query.has("", predicate, "bar");
    verify(mockGraphQuery).has(eq(""), same(predicate), eq("bar"));
    stub(mockGraphQuery.has("", 2, Compare.EQUAL)).toReturn(mockGraphQuery);
    query.has("", 2, Compare.EQUAL);
    verify(mockGraphQuery).has(eq(""), same(2), eq(Compare.EQUAL));
    stub(mockGraphQuery.hasNot("")).toReturn(mockGraphQuery);
    query.hasNot("");
    verify(mockGraphQuery).hasNot(eq(""));
    stub(mockGraphQuery.hasNot("", "bar")).toReturn(mockGraphQuery);
    query.hasNot("", "bar");
    verify(mockGraphQuery).hasNot(eq(""), eq("bar"));
    stub(mockGraphQuery.interval("", "bar", "bif")).toReturn(mockGraphQuery);
    query.interval("", "bar", "bif");
    verify(mockGraphQuery).interval(eq(""), eq("bar"), eq("bif"));
    stub(mockGraphQuery.limit(1)).toReturn(mockGraphQuery);
    query.limit(1);
    verify(mockGraphQuery).limit(1);
    List<Vertex> v = new ArrayList<Vertex>();
    stub(mockGraphQuery.vertices()).toReturn(v);
    query.vertices();
    verify(mockGraphQuery).vertices();
    Iterable<Person> people = query.vertices(Person.class);
    verify(mockGraphQuery, times(2)).vertices();
    assertFalse(people.iterator().hasNext());
    List<Edge> e = new ArrayList<Edge>();
    stub(mockGraphQuery.edges()).toReturn(e);
    query.edges();
    verify(mockGraphQuery).edges();
    Iterable<Knows> knows = query.edges(Knows.class);
    verify(mockGraphQuery, times(2)).edges();
    assertFalse(knows.iterator().hasNext());
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) ArrayList(java.util.ArrayList) Predicate(com.tinkerpop.blueprints.Predicate) FramedGraph(com.tinkerpop.frames.FramedGraph) FramedGraphFactory(com.tinkerpop.frames.FramedGraphFactory) Knows(com.tinkerpop.frames.domain.incidences.Knows) GraphQuery(com.tinkerpop.blueprints.GraphQuery) Person(com.tinkerpop.frames.domain.classes.Person) 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