1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.commons.rdf.jena;
20
21 import static org.junit.Assert.assertEquals;
22
23 import java.io.IOException;
24 import java.nio.file.Files;
25 import java.nio.file.Path;
26 import java.nio.file.StandardCopyOption;
27 import java.util.concurrent.Future;
28 import java.util.concurrent.TimeUnit;
29
30 import org.apache.commons.rdf.api.Graph;
31 import org.apache.commons.rdf.api.RDFSyntax;
32 import org.apache.commons.rdf.experimental.RDFParser.ParseResult;
33 import org.apache.commons.rdf.jena.experimental.JenaRDFParser;
34 import org.junit.After;
35 import org.junit.Before;
36 import org.junit.Test;
37
38 public class TestRDFParserBuilder {
39
40 private Path turtleFile;
41
42 @Before
43 public void preparePath() throws IOException {
44 turtleFile = Files.createTempFile("commonsrdf", "test.ttl");
45 Files.copy(getClass().getResourceAsStream("/D.ttl"), turtleFile, StandardCopyOption.REPLACE_EXISTING);
46 }
47
48 @After
49 public void deletePath() throws IOException {
50 if (turtleFile != null) {
51 Files.deleteIfExists(turtleFile);
52 }
53 }
54
55 @Test
56 public void parseTurtle() throws Exception {
57 try (final Graph g = new JenaRDF().createGraph()) {
58 final Future<ParseResult> gFuture = new JenaRDFParser().contentType(RDFSyntax.TURTLE).source(turtleFile)
59 .target(g).parse();
60 gFuture.get(5, TimeUnit.SECONDS);
61 assertEquals(3, g.size());
62 }
63 }
64 }