Search in sources :

Example 1 with ResourceLoggingClassLoader

use of org.apache.tika.ResourceLoggingClassLoader in project tika by apache.

the class TikaConfigTest method ensureClassLoaderUsedEverywhere.

/**
     * TIKA-1145 If the TikaConfig has a ClassLoader set on it,
     * that should be used when loading the mimetypes and when
     * discovering services
     */
@Test
public void ensureClassLoaderUsedEverywhere() throws Exception {
    ResourceLoggingClassLoader customLoader = new ResourceLoggingClassLoader(getClass().getClassLoader());
    TikaConfig config;
    // Without a classloader set, normal one will be used
    config = new TikaConfig();
    config.getMediaTypeRegistry();
    config.getParser();
    assertEquals(0, customLoader.getLoadedResources().size());
    // With a classloader set, resources will come through it
    config = new TikaConfig(customLoader);
    config.getMediaTypeRegistry();
    config.getParser();
    Map<String, List<URL>> resources = customLoader.getLoadedResources();
    int resourcesCount = resources.size();
    assertTrue("Not enough things used the classloader, found only " + resourcesCount, resourcesCount > 3);
    // Ensure everything that should do, did use it
    // - Parsers
    assertNotNull(resources.get("META-INF/services/org.apache.tika.parser.Parser"));
    // - Detectors
    assertNotNull(resources.get("META-INF/services/org.apache.tika.detect.Detector"));
    // - Built-In Mimetypes
    assertNotNull(resources.get("org/apache/tika/mime/tika-mimetypes.xml"));
    // - Custom Mimetypes
    assertNotNull(resources.get("org/apache/tika/mime/custom-mimetypes.xml"));
}
Also used : ResourceLoggingClassLoader(org.apache.tika.ResourceLoggingClassLoader) TikaConfig(org.apache.tika.config.TikaConfig) List(java.util.List) Test(org.junit.Test) TikaConfigTest(org.apache.tika.config.TikaConfigTest)

Aggregations

List (java.util.List)1 ResourceLoggingClassLoader (org.apache.tika.ResourceLoggingClassLoader)1 TikaConfig (org.apache.tika.config.TikaConfig)1 TikaConfigTest (org.apache.tika.config.TikaConfigTest)1 Test (org.junit.Test)1