Search in sources :

Example 1 with IDocumentEvent

use of org.pentaho.metaverse.api.IDocumentEvent 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 2 with IDocumentEvent

use of org.pentaho.metaverse.api.IDocumentEvent 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 3 with IDocumentEvent

use of org.pentaho.metaverse.api.IDocumentEvent in project pentaho-metaverse by pentaho.

the class DIRepositoryLocatorTest 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.addDocumentListener(this);
    spyLocator.setRepository(LocatorTestUtils.getFakeDiRepository());
    LocatorTestUtils.delay = 0;
    spyLocator.setRepositoryId("testrepo");
    assertEquals("Repo id is wrong", "testrepo", spyLocator.getRepositoryId());
    assertNotNull("Indexer type is null", spyLocator.getLocatorType());
    events = new ArrayList<IDocumentEvent>();
    spyLocator.startScan();
    spyLocator.futureTask.get();
    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 TransMeta);
        } else if (document.getExtension().equals("kjb")) {
            assertTrue(document.getContent() instanceof JobMeta);
        }
    }
    spyLocator.removeDocumentListener(this);
    events = new ArrayList<IDocumentEvent>();
    spyLocator.startScan();
    spyLocator.futureTask.get();
    assertEquals("Event count is wrong", 0, events.size());
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) IDocumentEvent(org.pentaho.metaverse.api.IDocumentEvent) 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 4 with IDocumentEvent

use of org.pentaho.metaverse.api.IDocumentEvent in project pentaho-metaverse by pentaho.

the class FileSystemLocatorTest 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.setRepositoryId("test_repo");
    spyLocator.setMetaverseBuilder(metaverseBuilder);
    spyLocator.addDocumentListener(this);
    spyLocator.setRootFolder("src/test/resources/solution");
    TestFileSystemLocator.delay = 300;
    assertNotNull("Indexer type is null", spyLocator.getLocatorType());
    events = 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);
    assertTrue("Event count is wrong", events.size() > 0);
    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);
        }
    }
}
Also used : TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) IDocumentEvent(org.pentaho.metaverse.api.IDocumentEvent) MetaverseDocument(org.pentaho.metaverse.api.MetaverseDocument) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) MetaverseBuilder(org.pentaho.metaverse.impl.MetaverseBuilder) Test(org.junit.Test)

Example 5 with IDocumentEvent

use of org.pentaho.metaverse.api.IDocumentEvent in project pentaho-metaverse by pentaho.

the class LocatorRunnerTest method testProcessFileTransformationExtension.

@Test
public void testProcessFileTransformationExtension() throws Exception {
    doAnswer(new Answer() {

        /**
         * @param invocation the invocation on the mock.
         * @return the value to be returned
         * @throws Throwable the throwable to be thrown
         */
        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            IDocumentEvent event = (IDocumentEvent) invocation.getArguments()[0];
            IDocument doc = event.getDocument();
            assertNotNull(doc);
            assertNull(doc.getMimeType());
            assertEquals(doc.getName(), "test.ktr");
            assertEquals(doc.getStringID(), "myKTR");
            return null;
        }
    }).when(baseLocator).notifyListeners(any(IDocumentEvent.class));
    stringLocatorRunner.setLocator(baseLocator);
    File file = new File("test.ktr");
    File spyFile = spy(file);
    stringLocatorRunner.processFile(namespace, "test.ktr", "myKTR", spyFile);
    when(baseLocator.getContents(any(Object.class))).thenThrow(MetaverseException.class);
    stringLocatorRunner.processFile(namespace, "test.ktr", "myKTR", spyFile);
}
Also used : Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IDocumentEvent(org.pentaho.metaverse.api.IDocumentEvent) File(java.io.File) IDocument(org.pentaho.metaverse.api.IDocument) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 IDocumentEvent (org.pentaho.metaverse.api.IDocumentEvent)5 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)4 IMetaverseBuilder (org.pentaho.metaverse.api.IMetaverseBuilder)4 MetaverseDocument (org.pentaho.metaverse.api.MetaverseDocument)4 MetaverseBuilder (org.pentaho.metaverse.impl.MetaverseBuilder)4 JobMeta (org.pentaho.di.job.JobMeta)2 TransMeta (org.pentaho.di.trans.TransMeta)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1 IDocument (org.pentaho.metaverse.api.IDocument)1 MetaverseLocatorException (org.pentaho.metaverse.api.MetaverseLocatorException)1 GraphMLWriter (org.pentaho.metaverse.graph.GraphMLWriter)1