Search in sources :

Example 1 with FileManager

use of org.apache.jena.util.FileManager in project jena by apache.

the class TestFileManager method testFileManagerNoFile.

@Test
public void testFileManagerNoFile() {
    FileManager fileManager = FileManager.create();
    fileManager.addLocatorFile();
    try {
        // Tests either way round - exception or a null return.
        InputStream in = fileManager.open(filenameNonExistent);
        closeInputStream(in);
        assertNull("Found non-existant file: " + filenameNonExistent, in);
    } catch (NotFoundException ex) {
    }
}
Also used : InputStream(java.io.InputStream) NotFoundException(org.apache.jena.shared.NotFoundException) FileManager(org.apache.jena.util.FileManager) Test(org.junit.Test)

Example 2 with FileManager

use of org.apache.jena.util.FileManager in project jena by apache.

the class TestFileManager method testFileManagerLocatorZipNonFound.

@Test
public void testFileManagerLocatorZipNonFound() {
    FileManager fileManager = FileManager.create();
    try {
        fileManager.addLocatorZip(zipname);
    } catch (Exception ex) {
        fail("Failed to create a filemanager and add a zip locator");
    }
    try {
        InputStream in = fileManager.open(filenameNonExistent);
        closeInputStream(in);
        assertNull("Found non-existant zip file member", in);
    } catch (NotFoundException ex) {
    }
}
Also used : InputStream(java.io.InputStream) NotFoundException(org.apache.jena.shared.NotFoundException) FileManager(org.apache.jena.util.FileManager) NotFoundException(org.apache.jena.shared.NotFoundException) Test(org.junit.Test)

Example 3 with FileManager

use of org.apache.jena.util.FileManager in project jena by apache.

the class TestFileManager method testLocationMappingURLtoFileOpen.

@Test
public void testLocationMappingURLtoFileOpen() {
    LocationMapper locMap = new LocationMapper(TestLocationMapper.mapping);
    FileManager fileManager = FileManager.create(locMap);
    fileManager.addLocatorFile();
    InputStream in = fileManager.open("http://example.org/file");
    assertNotNull(in);
    closeInputStream(in);
}
Also used : InputStream(java.io.InputStream) LocationMapper(org.apache.jena.util.LocationMapper) TestLocationMapper(org.apache.jena.riot.stream.TestLocationMapper) FileManager(org.apache.jena.util.FileManager) Test(org.junit.Test)

Example 4 with FileManager

use of org.apache.jena.util.FileManager in project jena by apache.

the class TestFileManager method testCache3.

@Test
public void testCache3() {
    FileManager fileManager = FileManager.getInternal();
    fileManager.addLocatorFile(testingDir);
    fileManager.setModelCaching(true);
    Model m1 = fileManager.loadModelInternal(fileModel);
    Model m2 = fileManager.loadModelInternal(fileModel);
    assertSame(m1, m2);
    fileManager.removeCacheModel(fileModel);
    Model m3 = fileManager.loadModelInternal(fileModel);
    assertNotSame(m1, m3);
    fileManager.resetCache();
    Model m4 = fileManager.loadModelInternal(fileModel);
    Model m5 = fileManager.loadModelInternal(fileModel);
    assertSame(m4, m5);
    assertNotSame(m1, m4);
    assertNotSame(m3, m4);
}
Also used : OntModel(org.apache.jena.ontology.OntModel) Model(org.apache.jena.rdf.model.Model) FileManager(org.apache.jena.util.FileManager) Test(org.junit.Test)

Example 5 with FileManager

use of org.apache.jena.util.FileManager in project jena by apache.

the class TestFileManager method testFileManagerNoFile3.

@Test(expected = NotFoundException.class)
public void testFileManagerNoFile3() {
    FileManager fileManager = new AdapterFileManager(new StreamManager(), new org.apache.jena.riot.system.stream.LocationMapper());
    fileManager.addLocatorFile();
    fileManager.readModelInternal(ModelFactory.createDefaultModel(), filenameNonExistent);
}
Also used : StreamManager(org.apache.jena.riot.system.stream.StreamManager) FileManager(org.apache.jena.util.FileManager) Test(org.junit.Test)

Aggregations

FileManager (org.apache.jena.util.FileManager)24 Test (org.junit.Test)15 InputStream (java.io.InputStream)11 Model (org.apache.jena.rdf.model.Model)9 NotFoundException (org.apache.jena.shared.NotFoundException)6 OntModel (org.apache.jena.ontology.OntModel)3 TestLocationMapper (org.apache.jena.riot.stream.TestLocationMapper)2 LocationMapper (org.apache.jena.util.LocationMapper)2 File (java.io.File)1 DocumentManagerAssembler (org.apache.jena.assembler.assemblers.DocumentManagerAssembler)1 StreamManager (org.apache.jena.riot.system.stream.StreamManager)1 JenaException (org.apache.jena.shared.JenaException)1