Search in sources :

Example 6 with ResourceLoader

use of org.apache.stanbol.entityhub.indexing.core.source.ResourceLoader in project stanbol by apache.

the class ResourceLoaderTest method isFailedOnError.

private boolean isFailedOnError(boolean failOnError) {
    String folder = rootDir + TEST_FOLDER_NAME;
    boolean failed = false;
    DummyResourceImporter importer = new DummyResourceImporter(Arrays.asList(folder + "errorFileInFolder.txt"));
    ResourceLoader loader = new ResourceLoader(importer, false, failOnError);
    loader.addResource(new File(folder, "errorFileInFolder.txt"));
    try {
        loader.loadResources();
    } catch (IllegalStateException ex) {
        failed = true;
    }
    return failed;
}
Also used : ResourceLoader(org.apache.stanbol.entityhub.indexing.core.source.ResourceLoader) File(java.io.File)

Example 7 with ResourceLoader

use of org.apache.stanbol.entityhub.indexing.core.source.ResourceLoader in project stanbol by apache.

the class ResourceLoaderTest method testFolderWithProcessingArchives.

@Test
public void testFolderWithProcessingArchives() {
    String folder = rootDir + TEST_FOLDER_NAME;
    Collection<String> expectedResources = new HashSet<String>(Arrays.asList(folder + "archiveInFolder.zip", folder + "archiveWithIgnore.zip", folder + "archiveWithError.zip", folder + "errorFileInFolder.txt", folder + "fileInFolder.txt", folder + "ignoreFileInFolder.txt", folder + "otherFileInFolder.txt"));
    //the resourceNames send to the importer are now different because the
    //archives are processed and the entries are sent to the  ResourceImporter
    Collection<String> expectedResourceNames = Arrays.asList(//part of archiveInFolder.zip
    "fileInArchive.txt", //part of archiveInFolder.zip
    "otherFileInArchive.txt", //part of archiveWithIgnore.zip
    "ignoreFileInArchive.txt", //part of archiveWithError.zip
    "errorFileInArchive.txt", "errorFileInFolder.txt", "fileInFolder.txt", "ignoreFileInFolder.txt", "otherFileInFolder.txt");
    DummyResourceImporter importer = new DummyResourceImporter(expectedResourceNames);
    ResourceLoader loader = new ResourceLoader(importer, true, false);
    loader.addResource(new File(rootDir, TEST_FOLDER_NAME));
    assertEquals(expectedResources, loader.getResources(ResourceState.REGISTERED));
    assertTrue(loader.getResources(ResourceState.ERROR).isEmpty());
    assertTrue(loader.getResources(ResourceState.LOADED).isEmpty());
    assertTrue(loader.getResources(ResourceState.IGNORED).isEmpty());
    loader.loadResources();
    assertEquals(new HashSet<String>(Arrays.asList(folder + "archiveInFolder.zip", //ignored files in archives are OK
    folder + "archiveWithIgnore.zip", folder + "fileInFolder.txt", folder + "otherFileInFolder.txt")), loader.getResources(ResourceState.LOADED));
    assertTrue(loader.getResources(ResourceState.REGISTERED).isEmpty());
    assertEquals(new HashSet<String>(Arrays.asList(folder + "errorFileInFolder.txt", //archive with errors MUST be ERROR
    folder + "archiveWithError.zip")), loader.getResources(ResourceState.ERROR));
    assertEquals(new HashSet<String>(Arrays.asList(folder + "ignoreFileInFolder.txt")), loader.getResources(ResourceState.IGNORED));
}
Also used : ResourceLoader(org.apache.stanbol.entityhub.indexing.core.source.ResourceLoader) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

File (java.io.File)7 ResourceLoader (org.apache.stanbol.entityhub.indexing.core.source.ResourceLoader)7 IndexingConfig (org.apache.stanbol.entityhub.indexing.core.config.IndexingConfig)3 Test (org.junit.Test)3 HashSet (java.util.HashSet)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 RepositoryException (org.openrdf.repository.RepositoryException)1 RepositoryConfigException (org.openrdf.repository.config.RepositoryConfigException)1 RepositoryFactory (org.openrdf.repository.config.RepositoryFactory)1