Search in sources :

Example 1 with TypedGraphModuleBuilder

use of com.tinkerpop.frames.modules.typedgraph.TypedGraphModuleBuilder in project frames by tinkerpop.

the class TypedGraphModuleTest method testSerializeEdgeType.

public void testSerializeEdgeType() {
    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);
    A a = framedGraph.addEdge(null, v1, v2, "label", Direction.OUT, A.class);
    C c = framedGraph.addEdge(null, v1, v2, "label", Direction.OUT, C.class);
    assertEquals("A", ((EdgeFrame) a).asEdge().getProperty("type"));
    assertEquals("C", ((EdgeFrame) c).asEdge().getProperty("type"));
}
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)

Example 2 with TypedGraphModuleBuilder

use of com.tinkerpop.frames.modules.typedgraph.TypedGraphModuleBuilder 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 3 with TypedGraphModuleBuilder

use of com.tinkerpop.frames.modules.typedgraph.TypedGraphModuleBuilder in project frames by tinkerpop.

the class TypedGraphModuleTest method testDeserializeVertexType.

public void testDeserializeVertexType() {
    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 cV = graph.addVertex(null);
    cV.setProperty("type", "C");
    cV.setProperty("label", "C Label");
    Base c = framedGraph.getVertex(cV.getId(), Base.class);
    assertTrue(c instanceof C);
    assertEquals("C Label", c.getLabel());
    ((C) c).setLabel("new label");
    assertEquals("new label", cV.getProperty("label"));
}
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)

Example 4 with TypedGraphModuleBuilder

use of com.tinkerpop.frames.modules.typedgraph.TypedGraphModuleBuilder 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 5 with TypedGraphModuleBuilder

use of com.tinkerpop.frames.modules.typedgraph.TypedGraphModuleBuilder in project frames by tinkerpop.

the class TypedGraphModuleTest method testSerializeVertexType.

public void testSerializeVertexType() {
    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);
    A a = framedGraph.addVertex(null, A.class);
    C c = framedGraph.addVertex(null, C.class);
    assertEquals("A", ((VertexFrame) a).asVertex().getProperty("type"));
    assertEquals("C", ((VertexFrame) c).asVertex().getProperty("type"));
}
Also used : 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)

Aggregations

Graph (com.tinkerpop.blueprints.Graph)5 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)5 TypedGraphModuleBuilder (com.tinkerpop.frames.modules.typedgraph.TypedGraphModuleBuilder)5 Vertex (com.tinkerpop.blueprints.Vertex)4 Edge (com.tinkerpop.blueprints.Edge)2