Search in sources :

Example 1 with FramedGraphFactory

use of com.tinkerpop.frames.FramedGraphFactory in project pentaho-metaverse by pentaho.

the class MetaverseValidationIT method init.

@BeforeClass
public static void init() throws Exception {
    IntegrationTestUtil.initializePentahoSystem("src/it/resources/solution/system/pentahoObjects.spring.xml");
    // we only care about the demo folder
    FileSystemLocator fileSystemLocator = PentahoSystem.get(FileSystemLocator.class);
    IDocumentLocatorProvider provider = PentahoSystem.get(IDocumentLocatorProvider.class);
    // remove the original locator so we can set the modified one back on it
    provider.removeDocumentLocator(fileSystemLocator);
    fileSystemLocator.setRootFolder(ROOT_FOLDER);
    provider.addDocumentLocator(fileSystemLocator);
    MetaverseUtil.setDocumentController(PentahoSystem.get(IDocumentController.class));
    // build the graph using our updated locator/provider
    graph = IntegrationTestUtil.buildMetaverseGraph(provider);
    reader = PentahoSystem.get(IMetaverseReader.class);
    framedGraphFactory = new FramedGraphFactory(new GremlinGroovyModule());
    framedGraph = framedGraphFactory.create(graph);
    root = (RootNode) framedGraph.getVertex("entity", RootNode.class);
}
Also used : IMetaverseReader(org.pentaho.metaverse.api.IMetaverseReader) IDocumentLocatorProvider(org.pentaho.metaverse.api.IDocumentLocatorProvider) GremlinGroovyModule(com.tinkerpop.frames.modules.gremlingroovy.GremlinGroovyModule) IDocumentController(org.pentaho.metaverse.api.IDocumentController) FramedGraphFactory(com.tinkerpop.frames.FramedGraphFactory) FileSystemLocator(org.pentaho.metaverse.locator.FileSystemLocator) BeforeClass(org.junit.BeforeClass)

Example 2 with FramedGraphFactory

use of com.tinkerpop.frames.FramedGraphFactory 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)

Example 3 with FramedGraphFactory

use of com.tinkerpop.frames.FramedGraphFactory 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)

Example 4 with FramedGraphFactory

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

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

the class JavaHandlerTest method setup.

@Before
public void setup() {
    TinkerGraph base = TinkerGraphFactory.createTinkerGraph();
    g = new FramedGraphFactory(new JavaHandlerModule()).create(base);
}
Also used : TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) FramedGraphFactory(com.tinkerpop.frames.FramedGraphFactory) Before(org.junit.Before)

Aggregations

FramedGraphFactory (com.tinkerpop.frames.FramedGraphFactory)5 Edge (com.tinkerpop.blueprints.Edge)3 Vertex (com.tinkerpop.blueprints.Vertex)3 FramedGraph (com.tinkerpop.frames.FramedGraph)3 Person (com.tinkerpop.frames.domain.classes.Person)3 Test (org.junit.Test)3 Graph (com.tinkerpop.blueprints.Graph)2 TransactionalGraph (com.tinkerpop.blueprints.TransactionalGraph)2 FramedGraphConfiguration (com.tinkerpop.frames.FramedGraphConfiguration)2 Knows (com.tinkerpop.frames.domain.incidences.Knows)2 AbstractModule (com.tinkerpop.frames.modules.AbstractModule)2 TypeResolver (com.tinkerpop.frames.modules.TypeResolver)2 GraphQuery (com.tinkerpop.blueprints.GraphQuery)1 Predicate (com.tinkerpop.blueprints.Predicate)1 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)1 GremlinGroovyModule (com.tinkerpop.frames.modules.gremlingroovy.GremlinGroovyModule)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1 IDocumentController (org.pentaho.metaverse.api.IDocumentController)1