This project has retired. For details please refer to its Attic page.
RDFUtilsTest xref
View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *  http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.any23.rdf;
19  
20  import org.junit.Assert;
21  import org.junit.Test;
22  import org.eclipse.rdf4j.rio.RDFFormat;
23  
24  import javax.xml.datatype.DatatypeConfigurationException;
25  import java.io.ByteArrayOutputStream;
26  import java.io.OutputStreamWriter;
27  import java.io.UnsupportedEncodingException;
28  import java.net.URISyntaxException;
29  import java.nio.charset.StandardCharsets;
30  import java.text.ParseException;
31  
32  /**
33   * Reference test class for {@link RDFUtils}.
34   *
35   * @author Michele Mostarda (mostarda@fbk.eu)
36   * @author Davide Palmisano (palmisano@gmail.com)
37   */
38  public class RDFUtilsTest {
39  
40      @Test
41      public void testFixAbsoluteIRI() throws UnsupportedEncodingException, URISyntaxException {
42          Assert.assertEquals("Error: passed IRIs are not the same.", "http://example.com/resource/the%20godfather",
43                  RDFUtils.fixAbsoluteIRI("http://example.com/resource/the godfather"));
44  
45          Assert.assertEquals("Error: passed IRIs are not the same.", "http://dbpedia.org/",
46                  RDFUtils.fixAbsoluteIRI("http://dbpedia.org"));
47      }
48  
49      @Test
50      public void testGetXSDDate() throws DatatypeConfigurationException, ParseException {
51          Assert.assertEquals("1997-09-01T13:00:00.000Z", RDFUtils.getXSDDate("19970901T1300Z", "yyyyMMdd'T'HHmm'Z'"));
52      }
53  
54      /**
55       * Tests the extension support.
56       */
57      @Test
58      public void testGetRDFFormatByExtension() {
59          Assert.assertEquals(RDFFormat.NTRIPLES, RDFUtils.getFormatByExtension("nt").get());
60          Assert.assertEquals(RDFFormat.TURTLE, RDFUtils.getFormatByExtension("ttl").get());
61          Assert.assertEquals(RDFFormat.NQUADS, RDFUtils.getFormatByExtension("nq").get());
62          Assert.assertEquals(RDFFormat.NQUADS, RDFUtils.getFormatByExtension(".nq").get());
63      }
64  
65      /**
66       * Tests the <code>NQuads</code> format support.
67       */
68      @Test
69      public void testGetNQuadsFormat() {
70          RDFUtils.getFormats().contains(RDFFormat.NQUADS);
71      }
72  
73      /**
74       * Tests the <code>NQuads</code> parsing support.
75       */
76      @Test
77      public void testGetNQuadsParser() {
78          Assert.assertNotNull(RDFUtils.getParser(RDFFormat.NQUADS));
79      }
80  
81      /**
82       * Tests the <code>NQuads</code> writing support.
83       */
84      @Test
85      public void testGetNQuadsWriter() {
86          Assert.assertNotNull(RDFUtils.getWriter(RDFFormat.NQUADS,
87                  new OutputStreamWriter(new ByteArrayOutputStream(), StandardCharsets.UTF_8)));
88      }
89  
90  }