use of com.tinkerpop.frames.modules.AbstractModule in project frames by tinkerpop.
the class FrameInitializerTest method setup.
@Before
public void setup() {
Graph graph = TinkerGraphFactory.createTinkerGraph();
framedGraph = new FramedGraphFactory(new AbstractModule() {
@Override
protected void doConfigure(FramedGraphConfiguration config) {
config.addFrameInitializer(nameDefaulter);
config.addFrameInitializer(weightDefaulter);
}
}).create(graph);
}
use of com.tinkerpop.frames.modules.AbstractModule 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);
}
use of com.tinkerpop.frames.modules.AbstractModule 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));
}
use of com.tinkerpop.frames.modules.AbstractModule 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);
}
use of com.tinkerpop.frames.modules.AbstractModule 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);
}
Aggregations