View Javadoc
1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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  }