Search in sources :

Example 11 with TinkerGraph

use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project pentaho-metaverse by pentaho.

the class DIRepositoryLocatorTest method testStopLocatorScan.

/**
 * Runs the spyLocator and checks the results
 *
 * @throws Exception When bad things happen
 */
@Test
public void testStopLocatorScan() throws Exception {
    TinkerGraph graph = new TinkerGraph();
    IMetaverseBuilder metaverseBuilder = new MetaverseBuilder(graph);
    spyLocator.setMetaverseBuilder(metaverseBuilder);
    spyLocator.addDocumentListener(this);
    spyLocator.setRepository(LocatorTestUtils.getFakeDiRepository());
    spyLocator.setUnifiedRepository(LocatorTestUtils.getMockIUnifiedRepository());
    LocatorTestUtils.delay = 300;
    assertNotNull("Indexer type is null", spyLocator.getLocatorType());
    events = Collections.synchronizedList(new ArrayList<IDocumentEvent>());
    System.out.println("call startScan");
    spyLocator.startScan();
    Thread.sleep(1000);
    System.out.println("call stopScan");
    spyLocator.stopScan();
    assertTrue("Event count is wrong", events.size() < 5);
    for (IDocumentEvent event : events) {
        System.out.println(event.getDocument().getStringID());
        assertNotNull(event.getDocument());
        MetaverseDocument document = (MetaverseDocument) event.getDocument();
        if (document.getExtension().equals("ktr")) {
            assertTrue(document.getContent() instanceof TransMeta);
        } else if (document.getExtension().equals("kjb")) {
            assertTrue(document.getContent() instanceof JobMeta);
        }
    }
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) IDocumentEvent(org.pentaho.metaverse.api.IDocumentEvent) ArrayList(java.util.ArrayList) TransMeta(org.pentaho.di.trans.TransMeta) MetaverseDocument(org.pentaho.metaverse.api.MetaverseDocument) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) MetaverseBuilder(org.pentaho.metaverse.impl.MetaverseBuilder) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) Test(org.junit.Test)

Example 12 with TinkerGraph

use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project pentaho-metaverse by pentaho.

the class FileSystemLocatorTest method testStartLocator.

/**
 * Runs the spyLocator and checks the results
 *
 * @throws Exception When bad things happen
 */
@Test
public void testStartLocator() throws Exception {
    TinkerGraph graph = new TinkerGraph();
    IMetaverseBuilder metaverseBuilder = new MetaverseBuilder(graph);
    spyLocator.setMetaverseBuilder(metaverseBuilder);
    spyLocator.setRepositoryId("testrepo");
    spyLocator.addDocumentListener(this);
    spyLocator.setRootFolder("src/test/resources/solution");
    assertEquals("Root folder is wrong", "src/test/resources/solution", spyLocator.getRootFolder());
    TestFileSystemLocator.delay = 0;
    spyLocator.setRootFolder("bogus");
    events = new ArrayList<IDocumentEvent>();
    try {
        spyLocator.startScan();
        MetaverseCompletionService.getInstance().waitTillEmpty();
        fail();
    } catch (MetaverseLocatorException e) {
        assertEquals("Event count is wrong", 0, events.size());
    }
    spyLocator.setRootFolder("src/test/resources/solution/folder 2/parse.ktr");
    events = new ArrayList<IDocumentEvent>();
    try {
        spyLocator.startScan();
        MetaverseCompletionService.getInstance().waitTillEmpty();
        fail();
    } catch (MetaverseLocatorException e) {
        assertEquals("Event count is wrong", 0, events.size());
    }
    spyLocator.setRootFolder("src/test/resources/solution");
    assertEquals("Repo id is wrong", "testrepo", spyLocator.getRepositoryId());
    assertNotNull("Indexer type is null", spyLocator.getLocatorType());
    events = new ArrayList<IDocumentEvent>();
    spyLocator.startScan();
    MetaverseCompletionService.getInstance().waitTillEmpty();
    assertEquals("Event count is wrong", 7, events.size());
    for (IDocumentEvent event : events) {
        System.out.println(event.getDocument().getStringID());
        assertNotNull(event.getDocument());
        MetaverseDocument document = (MetaverseDocument) event.getDocument();
        if (document.getExtension().equals("ktr")) {
            assertTrue(document.getContent() instanceof String);
        } else if (document.getExtension().equals("kjb")) {
            assertTrue(document.getContent() instanceof String);
        }
    }
    spyLocator.removeDocumentListener(this);
    events = new ArrayList<IDocumentEvent>();
    spyLocator.startScan();
    MetaverseCompletionService.getInstance().waitTillEmpty();
    assertEquals("Event count is wrong", 0, events.size());
    assertNotNull("Graph is null", graph);
    GraphMLWriter writer = new GraphMLWriter();
    writer.outputGraph(graph, new FileOutputStream(OUTPUT_FOLDER + "FileSystemLocatorTest.graphml"));
}
Also used : MetaverseLocatorException(org.pentaho.metaverse.api.MetaverseLocatorException) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) IDocumentEvent(org.pentaho.metaverse.api.IDocumentEvent) FileOutputStream(java.io.FileOutputStream) MetaverseDocument(org.pentaho.metaverse.api.MetaverseDocument) GraphMLWriter(org.pentaho.metaverse.graph.GraphMLWriter) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) MetaverseBuilder(org.pentaho.metaverse.impl.MetaverseBuilder) Test(org.junit.Test)

Example 13 with TinkerGraph

use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project pentaho-metaverse by pentaho.

the class MetaverseUtilTest method testAddLineageGraph.

@Test
public void testAddLineageGraph() throws Exception {
    IDocument document = mock(IDocument.class);
    when(document.getName()).thenReturn("myDoc");
    Object content = new Object();
    when(document.getContent()).thenReturn(content);
    IDocumentController documentController = mock(IDocumentController.class, withSettings().extraInterfaces(IRequiresMetaverseBuilder.class));
    List<IDocumentAnalyzer> analyzers = new ArrayList<IDocumentAnalyzer>();
    when(documentController.getDocumentAnalyzers(Mockito.anyString())).thenReturn(analyzers);
    MetaverseUtil.documentController = documentController;
    // Empty analyzer set
    MetaverseUtil.addLineageGraph(document, null);
    IDocumentAnalyzer<IMetaverseNode> documentAnalyzer = mock(IDocumentAnalyzer.class);
    when(documentAnalyzer.analyze(Mockito.any(IComponentDescriptor.class), Mockito.any(IDocument.class))).thenReturn(mock(IMetaverseNode.class));
    analyzers.add(documentAnalyzer);
    Graph graph = new TinkerGraph();
    MetaverseUtil.addLineageGraph(document, graph);
    MetaverseUtil.addLineageGraph(document, null);
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) IDocumentController(org.pentaho.metaverse.api.IDocumentController) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) IDocumentAnalyzer(org.pentaho.metaverse.api.IDocumentAnalyzer) ArrayList(java.util.ArrayList) IRequiresMetaverseBuilder(org.pentaho.metaverse.api.IRequiresMetaverseBuilder) IDocument(org.pentaho.metaverse.api.IDocument) Test(org.junit.Test)

Example 14 with TinkerGraph

use of com.tinkerpop.blueprints.impls.tg.TinkerGraph 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 15 with TinkerGraph

use of com.tinkerpop.blueprints.impls.tg.TinkerGraph 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)

Aggregations

TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)105 Vertex (com.tinkerpop.blueprints.Vertex)66 Graph (com.tinkerpop.blueprints.Graph)58 Test (org.junit.Test)42 Edge (com.tinkerpop.blueprints.Edge)33 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 JSONObject (org.codehaus.jettison.json.JSONObject)10 IMetaverseBuilder (org.pentaho.metaverse.api.IMetaverseBuilder)10 InputStream (java.io.InputStream)9 HashSet (java.util.HashSet)9 JSONTokener (org.codehaus.jettison.json.JSONTokener)8 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)7 Map (java.util.Map)6 MetaverseBuilder (org.pentaho.metaverse.impl.MetaverseBuilder)6 TypedGraphModuleBuilder (com.tinkerpop.frames.modules.typedgraph.TypedGraphModuleBuilder)5 HashMap (java.util.HashMap)5 Before (org.junit.Before)5 IndexableGraph (com.tinkerpop.blueprints.IndexableGraph)4 IgnoreIdTinkerGraph (com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph)4