Search in sources :

Example 6 with AnalyzerFactory

use of org.opengrok.indexer.analysis.AnalyzerFactory in project OpenGrok by OpenGrok.

the class ZipAnalyzerFactoryTest method testZipWrtAnalyzerGuru.

/**
 * Tests a ZIP file.
 * @throws IOException I/O exception
 */
@Test
public void testZipWrtAnalyzerGuru() throws IOException {
    InputStream res = getClass().getClassLoader().getResourceAsStream("analysis/archive/zip.bin");
    assertNotNull(res, "zip.bin should be available,");
    // assert that it is matched
    AnalyzerFactory fac = AnalyzerGuru.find(res);
    assertNotNull(fac, "zip.bin should have factory");
    assertSame(fac.getClass(), ZipAnalyzerFactory.class, "should be ZipAnalyzerFactory");
}
Also used : InputStream(java.io.InputStream) AnalyzerFactory(org.opengrok.indexer.analysis.AnalyzerFactory) Test(org.junit.jupiter.api.Test)

Example 7 with AnalyzerFactory

use of org.opengrok.indexer.analysis.AnalyzerFactory in project OpenGrok by OpenGrok.

the class JarAnalyzerFactoryTest method testJarWrtAnalyzerGuru.

/**
 * Tests a JAR file.
 * @throws IOException
 */
@Test
public void testJarWrtAnalyzerGuru() throws IOException {
    InputStream res = getClass().getClassLoader().getResourceAsStream("analysis/executables/javajar.bin");
    assertNotNull(res, "javajar.bin should be available,");
    // assert that it is matched
    AnalyzerFactory fac = AnalyzerGuru.find(res);
    assertNotNull(fac, "javajar.bin should have factory");
    assertSame(fac.getClass(), JarAnalyzerFactory.class, "should be JarAnalyzerFactory");
}
Also used : InputStream(java.io.InputStream) AnalyzerFactory(org.opengrok.indexer.analysis.AnalyzerFactory) Test(org.junit.jupiter.api.Test)

Example 8 with AnalyzerFactory

use of org.opengrok.indexer.analysis.AnalyzerFactory in project OpenGrok by OpenGrok.

the class JavaClassAnalyzerFactoryTest method testJavaClassWrtAnalyzerGuru.

/**
 * Tests a Java .class file.
 * @throws IOException I/O exception
 */
@Test
public void testJavaClassWrtAnalyzerGuru() throws IOException {
    InputStream res = getClass().getClassLoader().getResourceAsStream("analysis/executables/javaclass.bin");
    assertNotNull(res, "despite inclusion locally,");
    // assert that it is matched
    AnalyzerFactory fac = AnalyzerGuru.find(res);
    assertNotNull(fac, "javaclass.bin should have factory");
    assertSame(fac.getClass(), JavaClassAnalyzerFactory.class, "should be JavaClassAnalyzerFactory");
}
Also used : InputStream(java.io.InputStream) AnalyzerFactory(org.opengrok.indexer.analysis.AnalyzerFactory) Test(org.junit.jupiter.api.Test)

Example 9 with AnalyzerFactory

use of org.opengrok.indexer.analysis.AnalyzerFactory in project OpenGrok by OpenGrok.

the class DocumentMatcherTest method testMandocBOMDocument.

/**
 * Tests a fake UTF-16LE mandoc(5)-style document to affirm that encoding
 * determination is valid.
 * @throws IOException I/O exception
 */
@Test
public void testMandocBOMDocument() throws IOException {
    InputStream res = getClass().getClassLoader().getResourceAsStream("analysis/document/utf16le.1m");
    assertNotNull(res, "despite inclusion locally,");
    byte[] buf = readSignature(res);
    AnalyzerFactory fac;
    // assert that it is mandoc-like
    fac = MandocAnalyzerFactory.MATCHER.isMagic(buf, res);
    assertNotNull(fac, "though utf16le.1m is mandoc(5),");
    assertSame(MandocAnalyzerFactory.DEFAULT_INSTANCE, fac, "though utf16le.1m is mandoc(5)");
}
Also used : InputStream(java.io.InputStream) AnalyzerFactory(org.opengrok.indexer.analysis.AnalyzerFactory) Test(org.junit.jupiter.api.Test)

Example 10 with AnalyzerFactory

use of org.opengrok.indexer.analysis.AnalyzerFactory in project OpenGrok by OpenGrok.

the class DocumentMatcherTest method testMdocDocument.

/**
 * Tests a mdoc(5)-style document.
 * @throws IOException I/O exception
 */
@Test
public void testMdocDocument() throws IOException {
    InputStream res = getClass().getClassLoader().getResourceAsStream("analysis/document/sync.1m");
    assertNotNull(res, "despite inclusion locally,");
    byte[] buf = readSignature(res);
    AnalyzerFactory fac;
    // assert that it is troff-like
    fac = TroffAnalyzerFactory.MATCHER.isMagic(buf, res);
    assertNotNull(fac, "though sync.1m is mdoc(5),");
    assertSame(TroffAnalyzerFactory.DEFAULT_INSTANCE, fac, "though sync.1m is troff-like mdoc(5)");
    // assert that it is not mandoc
    fac = MandocAnalyzerFactory.MATCHER.isMagic(buf, res);
    assertNull(fac, "though sync.1m is troff-like mdoc(5),");
}
Also used : InputStream(java.io.InputStream) AnalyzerFactory(org.opengrok.indexer.analysis.AnalyzerFactory) Test(org.junit.jupiter.api.Test)

Aggregations

AnalyzerFactory (org.opengrok.indexer.analysis.AnalyzerFactory)10 Test (org.junit.jupiter.api.Test)8 InputStream (java.io.InputStream)7 StringWriter (java.io.StringWriter)2 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileReader (java.io.FileReader)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1 Document (org.apache.lucene.document.Document)1 AbstractAnalyzer (org.opengrok.indexer.analysis.AbstractAnalyzer)1 OGKTextField (org.opengrok.indexer.analysis.OGKTextField)1 RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)1