Search in sources :

Example 1 with FramedGraphConfiguration

use of com.tinkerpop.frames.FramedGraphConfiguration in project frames by tinkerpop.

the class AbstractModuleTest method testWrapping.

@Test
public void testWrapping() {
    Graph baseGraph = Mockito.mock(Graph.class);
    TransactionalGraph baseTransactionalGraph = Mockito.mock(TransactionalGraph.class);
    Graph wrappedGraph = Mockito.mock(Graph.class);
    TransactionalGraph wrappedTransactionalGraph = Mockito.mock(TransactionalGraph.class);
    FramedGraphConfiguration config = new FramedGraphConfiguration();
    AbstractModule module = Mockito.mock(AbstractModule.class);
    Mockito.when(module.doConfigure(Mockito.any(Graph.class), Mockito.any(FramedGraphConfiguration.class))).thenReturn(wrappedGraph);
    Graph configuredGraph = module.configure(baseGraph, config);
    Assert.assertEquals(wrappedGraph, configuredGraph);
    Mockito.reset(module);
    Mockito.when(module.doConfigure(Mockito.any(TransactionalGraph.class), Mockito.any(FramedGraphConfiguration.class))).thenReturn(wrappedTransactionalGraph);
    Graph configuredTransactionalGraph = module.configure(baseTransactionalGraph, config);
    Assert.assertEquals(wrappedTransactionalGraph, configuredTransactionalGraph);
}
Also used : Graph(com.tinkerpop.blueprints.Graph) TransactionalGraph(com.tinkerpop.blueprints.TransactionalGraph) TransactionalGraph(com.tinkerpop.blueprints.TransactionalGraph) FramedGraphConfiguration(com.tinkerpop.frames.FramedGraphConfiguration) AbstractModule(com.tinkerpop.frames.modules.AbstractModule) Test(org.junit.Test)

Example 2 with FramedGraphConfiguration

use of com.tinkerpop.frames.FramedGraphConfiguration in project frames by tinkerpop.

the class AbstractModuleTest method testNoWrapping.

@Test
public void testNoWrapping() {
    Graph baseGraph = Mockito.mock(Graph.class);
    TransactionalGraph baseTransactionalGraph = Mockito.mock(TransactionalGraph.class);
    FramedGraphConfiguration config = new FramedGraphConfiguration();
    AbstractModule module = Mockito.mock(AbstractModule.class);
    Mockito.when(module.doConfigure(Mockito.any(Graph.class), Mockito.any(FramedGraphConfiguration.class))).thenCallRealMethod();
    Graph configuredGraph = module.configure(baseGraph, config);
    Assert.assertEquals(baseGraph, configuredGraph);
    Mockito.verify(module).doConfigure(Mockito.any(Graph.class), Mockito.any(FramedGraphConfiguration.class));
    Mockito.verify(module).doConfigure(Mockito.any(FramedGraphConfiguration.class));
    Mockito.reset(module);
    Mockito.when(module.doConfigure(Mockito.any(TransactionalGraph.class), Mockito.any(FramedGraphConfiguration.class))).thenCallRealMethod();
    Graph configuredTransactionalGraph = module.configure(baseTransactionalGraph, config);
    Assert.assertEquals(baseTransactionalGraph, configuredTransactionalGraph);
    Mockito.verify(module).doConfigure(Mockito.any(TransactionalGraph.class), Mockito.any(FramedGraphConfiguration.class));
    Mockito.verify(module).doConfigure(Mockito.any(FramedGraphConfiguration.class));
}
Also used : Graph(com.tinkerpop.blueprints.Graph) TransactionalGraph(com.tinkerpop.blueprints.TransactionalGraph) TransactionalGraph(com.tinkerpop.blueprints.TransactionalGraph) FramedGraphConfiguration(com.tinkerpop.frames.FramedGraphConfiguration) AbstractModule(com.tinkerpop.frames.modules.AbstractModule) Test(org.junit.Test)

Example 3 with FramedGraphConfiguration

use of com.tinkerpop.frames.FramedGraphConfiguration in project frames by tinkerpop.

the class TypeResolverTest method testAdditionalTypes.

@Test
public void testAdditionalTypes() {
    Graph graph = TinkerGraphFactory.createTinkerGraph();
    FramedGraphFactory factory = new FramedGraphFactory(new AbstractModule() {

        @Override
        public void doConfigure(FramedGraphConfiguration config) {
            config.addTypeResolver(new TypeResolver() {

                @Override
                public Class<?>[] resolveTypes(Edge e, Class<?> defaultType) {
                    return new Class[] { AdditionalEdge.class };
                }

                @Override
                public Class<?>[] resolveTypes(Vertex v, Class<?> defaultType) {
                    return new Class[] { AdditionalVertex.class };
                }
            });
        }
    });
    framedGraph = factory.create(graph);
    Person marko = framedGraph.getVertex(1, Person.class);
    Assert.assertTrue(marko instanceof AdditionalVertex);
    Assert.assertFalse(marko instanceof AdditionalEdge);
    Knows knows = marko.getKnows().iterator().next();
    Assert.assertTrue(knows instanceof AdditionalEdge);
    Assert.assertFalse(knows instanceof AdditionalVertex);
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TypeResolver(com.tinkerpop.frames.modules.TypeResolver) AbstractModule(com.tinkerpop.frames.modules.AbstractModule) TransactionalGraph(com.tinkerpop.blueprints.TransactionalGraph) FramedGraph(com.tinkerpop.frames.FramedGraph) Graph(com.tinkerpop.blueprints.Graph) FramedGraphFactory(com.tinkerpop.frames.FramedGraphFactory) Knows(com.tinkerpop.frames.domain.incidences.Knows) Edge(com.tinkerpop.blueprints.Edge) Person(com.tinkerpop.frames.domain.classes.Person) FramedGraphConfiguration(com.tinkerpop.frames.FramedGraphConfiguration) Test(org.junit.Test)

Example 4 with FramedGraphConfiguration

use of com.tinkerpop.frames.FramedGraphConfiguration in project frames by tinkerpop.

the class TypeResolverTest method testExtendedTypes.

@Test
public void testExtendedTypes() {
    Graph graph = TinkerGraphFactory.createTinkerGraph();
    FramedGraphFactory factory = new FramedGraphFactory(new AbstractModule() {

        @Override
        public void doConfigure(FramedGraphConfiguration config) {
            config.addTypeResolver(new TypeResolver() {

                @Override
                public Class<?>[] resolveTypes(Edge e, Class<?> defaultType) {
                    return new Class[0];
                }

                @Override
                public Class<?>[] resolveTypes(Vertex v, Class<?> defaultType) {
                    return new Class[] { ExtendedPerson.class };
                }
            });
        }
    });
    framedGraph = factory.create(graph);
    Person marko = framedGraph.getVertex(1, Person.class);
    Assert.assertTrue(marko instanceof ExtendedPerson);
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TransactionalGraph(com.tinkerpop.blueprints.TransactionalGraph) FramedGraph(com.tinkerpop.frames.FramedGraph) Graph(com.tinkerpop.blueprints.Graph) FramedGraphFactory(com.tinkerpop.frames.FramedGraphFactory) TypeResolver(com.tinkerpop.frames.modules.TypeResolver) Edge(com.tinkerpop.blueprints.Edge) Person(com.tinkerpop.frames.domain.classes.Person) FramedGraphConfiguration(com.tinkerpop.frames.FramedGraphConfiguration) AbstractModule(com.tinkerpop.frames.modules.AbstractModule) Test(org.junit.Test)

Aggregations

Graph (com.tinkerpop.blueprints.Graph)4 TransactionalGraph (com.tinkerpop.blueprints.TransactionalGraph)4 FramedGraphConfiguration (com.tinkerpop.frames.FramedGraphConfiguration)4 AbstractModule (com.tinkerpop.frames.modules.AbstractModule)4 Test (org.junit.Test)4 Edge (com.tinkerpop.blueprints.Edge)2 Vertex (com.tinkerpop.blueprints.Vertex)2 FramedGraph (com.tinkerpop.frames.FramedGraph)2 FramedGraphFactory (com.tinkerpop.frames.FramedGraphFactory)2 Person (com.tinkerpop.frames.domain.classes.Person)2 TypeResolver (com.tinkerpop.frames.modules.TypeResolver)2 Knows (com.tinkerpop.frames.domain.incidences.Knows)1