COMMONSRDF-63: parseFile fixes for OSX .. which uses /tmp symlinked to /private/tmp
Added explicit test of symlink following for base path. Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/8adf1762 Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/8adf1762 Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/8adf1762 Branch: refs/heads/master Commit: 8adf17623bff6e885e3bd1851e1ebefeb14a8050 Parents: 350cd26 Author: Stian Soiland-Reyes <st...@apache.org> Authored: Fri Sep 29 00:04:53 2017 +0100 Committer: Stian Soiland-Reyes <st...@apache.org> Committed: Fri Sep 29 00:04:53 2017 +0100 ---------------------------------------------------------------------- .../experimental/AbstractRDFParserTest.java | 33 +++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/8adf1762/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java ---------------------------------------------------------------------- diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java index 098b606..68f686b 100644 --- a/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java +++ b/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeNotNull; import static org.apache.commons.rdf.api.RDFSyntax.*; import java.io.ByteArrayInputStream; @@ -56,14 +57,24 @@ public class AbstractRDFParserTest { private Path testTtl; private Path testXml; + private Path symlink; + @Before public void createTempFile() throws IOException { testNt = Files.createTempFile("test", ".nt"); testTtl = Files.createTempFile("test", ".ttl"); testXml = Files.createTempFile("test", ".xml"); - // No need to populate the files as the dummy parser // doesn't actually read anything + + // If supported, we'll make a symbolic link + Path symlinks = Files.createTempDirectory("symlinked"); + try { + symlink = Files.createSymbolicLink( + symlinks.resolve("linked.ttl"), testNt); + } catch (IOException|UnsupportedOperationException ex) { + symlink = null; + } } @After @@ -117,8 +128,8 @@ public class AbstractRDFParserTest { // includes // international characters assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "source")); - // Should be set to the file path - assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "base")); + // Should be set to the file path - after following symlinks + assertEquals("<" + testNt.toRealPath().toUri().toString() + ">", firstPredicate(g, "base")); // Should NOT have guessed the content type assertNull(firstPredicate(g, "contentType")); @@ -126,6 +137,19 @@ public class AbstractRDFParserTest { } @Test + public void parseFileSymlink() throws Exception { + // This test will typically not work in Windows + // which requires system privileges to create symlinks + assumeNotNull(symlink); + final Graph g = factory.createGraph(); + final RDFParser parser = dummyParser.source(symlink).target(g); + parser.parse().get(5, TimeUnit.SECONDS); + checkGraph(g); + assertEquals("<" + symlink.toUri().toString() + ">", firstPredicate(g, "source")); + assertEquals("<" + testNt.toRealPath().toUri().toString() + ">", firstPredicate(g, "base")); + } + + @Test public void parseNoSource() throws Exception { thrown.expect(IllegalStateException.class); dummyParser.parse(); @@ -162,7 +186,8 @@ public class AbstractRDFParserTest { // includes // international characters assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "source")); - assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "base")); + // Should be set to the file path - after following symlinks + assertEquals("<" + testNt.toRealPath().toUri().toString() + ">", firstPredicate(g, "base")); assertEquals("\"" + RDFSyntax.NTRIPLES.name() + "\"", firstPredicate(g, "contentTypeSyntax")); assertEquals("\"application/n-triples\"", firstPredicate(g, "contentType"));